Skip to content

Commit f75cf95

Browse files
tausbnCopilot
andcommitted
Apply rustfmt
Format the touched Rust crates (shared/tree-sitter-extractor, shared/yeast, shared/yeast-macros, unified/extractor) so the tree-sitter-extractor CI fmt check passes. No functional changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 8a3bb91 commit f75cf95

12 files changed

Lines changed: 137 additions & 139 deletions

File tree

shared/tree-sitter-extractor/src/extractor/simple.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,19 @@ impl Extractor {
9595

9696
let mut schemas = vec![];
9797
for lang in &self.languages {
98-
let effective_node_types: String =
99-
match lang.desugar.as_ref().and_then(|d| d.output_node_types_yaml()) {
100-
Some(yaml) => yeast::node_types_yaml::convert(yaml).map_err(|e| {
101-
std::io::Error::other(format!(
102-
"Failed to convert YAML node-types to JSON for {}: {e}",
103-
lang.prefix
104-
))
105-
})?,
106-
None => lang.node_types.to_string(),
107-
};
98+
let effective_node_types: String = match lang
99+
.desugar
100+
.as_ref()
101+
.and_then(|d| d.output_node_types_yaml())
102+
{
103+
Some(yaml) => yeast::node_types_yaml::convert(yaml).map_err(|e| {
104+
std::io::Error::other(format!(
105+
"Failed to convert YAML node-types to JSON for {}: {e}",
106+
lang.prefix
107+
))
108+
})?,
109+
None => lang.node_types.to_string(),
110+
};
108111
let schema = node_types::read_node_types_str(lang.prefix, &effective_node_types)?;
109112
schemas.push(schema);
110113
}

shared/yeast-macros/src/parse.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ fn parse_query_fields(tokens: &mut Tokens) -> Result<Vec<TokenStream>> {
121121
std::collections::HashMap::new();
122122
let mut bare_children: Vec<TokenStream> = Vec::new();
123123
let push_field_elem = |order: &mut Vec<String>,
124-
map: &mut std::collections::HashMap<String, Vec<TokenStream>>,
125-
name: String,
126-
elem: TokenStream| {
124+
map: &mut std::collections::HashMap<String, Vec<TokenStream>>,
125+
name: String,
126+
elem: TokenStream| {
127127
if !map.contains_key(&name) {
128128
order.push(name.clone());
129129
map.insert(name, vec![elem]);
@@ -160,8 +160,7 @@ fn parse_query_fields(tokens: &mut Tokens) -> Result<Vec<TokenStream>> {
160160
} else {
161161
let child = if peek_is_at(tokens) {
162162
tokens.next();
163-
let capture_name =
164-
expect_ident(tokens, "expected capture name after @")?;
163+
let capture_name = expect_ident(tokens, "expected capture name after @")?;
165164
let name_str = capture_name.to_string();
166165
quote! {
167166
yeast::query::QueryNode::Capture {
@@ -420,7 +419,11 @@ fn parse_direct_node_inner(tokens: &mut Tokens, ctx: &Ident) -> Result<TokenStre
420419
// Named fields — compute each value into a temp, then reference it
421420
while peek_is_field(tokens) {
422421
let field_name = expect_ident(tokens, "expected field name")?;
423-
let field_str = field_name.to_string().strip_prefix("r#").unwrap_or(&field_name.to_string()).to_string();
422+
let field_str = field_name
423+
.to_string()
424+
.strip_prefix("r#")
425+
.unwrap_or(&field_name.to_string())
426+
.to_string();
424427
expect_punct(tokens, ':', "expected `:` after field name")?;
425428
let temp = Ident::new(
426429
&format!("__field_{field_str}_{field_counter}"),
@@ -438,7 +441,8 @@ fn parse_direct_node_inner(tokens: &mut Tokens, ctx: &Ident) -> Result<TokenStre
438441
// Determine if a chain (.map(..)) follows the `{}` group.
439442
let mut after = tokens.clone();
440443
after.next(); // skip the brace group
441-
let has_chain = matches!(after.peek(), Some(TokenTree::Punct(p)) if p.as_char() == '.');
444+
let has_chain =
445+
matches!(after.peek(), Some(TokenTree::Punct(p)) if p.as_char() == '.');
442446

443447
if is_splice || has_chain {
444448
let group = expect_group(tokens, Delimiter::Brace)?;
@@ -506,11 +510,7 @@ fn parse_direct_node_inner(tokens: &mut Tokens, ctx: &Ident) -> Result<TokenStre
506510
/// Each call expects the receiver to be an iterator. The `base` argument
507511
/// should therefore already be an iterator (use `.into_iter()` on it before
508512
/// calling this function).
509-
fn parse_chain_suffix(
510-
tokens: &mut Tokens,
511-
ctx: &Ident,
512-
base: TokenStream,
513-
) -> Result<TokenStream> {
513+
fn parse_chain_suffix(tokens: &mut Tokens, ctx: &Ident, base: TokenStream) -> Result<TokenStream> {
514514
let mut current = base;
515515
while matches!(tokens.peek(), Some(TokenTree::Punct(p)) if p.as_char() == '.') {
516516
tokens.next(); // consume .
@@ -608,7 +608,8 @@ fn parse_direct_list(tokens: &mut Tokens, ctx: &Ident) -> Result<Vec<TokenStream
608608
// {expr} or {..expr} (with optional .chain) — single node or splice
609609
if peek_is_group(tokens, Delimiter::Brace) {
610610
let group = expect_group(tokens, Delimiter::Brace)?;
611-
let has_chain = matches!(tokens.peek(), Some(TokenTree::Punct(p)) if p.as_char() == '.');
611+
let has_chain =
612+
matches!(tokens.peek(), Some(TokenTree::Punct(p)) if p.as_char() == '.');
612613
let mut inner = group.stream().into_iter().peekable();
613614
let is_splice = peek_is_dotdot(&inner);
614615
if is_splice || has_chain {

shared/yeast/src/build.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,7 @@ impl<C: Clone> BuildCtx<'_, C> {
197197
/// input, only the first is returned. For most use cases (e.g.
198198
/// translating a single type annotation) this is what you want; if
199199
/// you need all ids, use [`translate`] directly.
200-
pub fn translate_opt<I: Into<Id>>(
201-
&mut self,
202-
id: Option<I>,
203-
) -> Result<Option<Id>, String> {
200+
pub fn translate_opt<I: Into<Id>>(&mut self, id: Option<I>) -> Result<Option<Id>, String> {
204201
match id {
205202
Some(id) => Ok(self.translate(id)?.into_iter().next()),
206203
None => Ok(None),

shared/yeast/src/dump.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,7 @@ pub fn dump_ast_with_options(
5353
///
5454
/// Any node that does not match the expected type set for its parent field is
5555
/// rendered with a trailing `" <-- ERROR: ..."` annotation on the same line.
56-
pub fn dump_ast_with_type_errors(
57-
ast: &Ast,
58-
root: usize,
59-
source: &str,
60-
schema: &Schema,
61-
) -> String {
56+
pub fn dump_ast_with_type_errors(ast: &Ast, root: usize, source: &str, schema: &Schema) -> String {
6257
dump_ast_with_type_errors_and_options(ast, root, source, schema, &DumpOptions::default())
6358
}
6459

@@ -74,7 +69,15 @@ pub fn dump_ast_with_type_errors_and_options(
7469
options: &DumpOptions,
7570
) -> String {
7671
let mut out = String::new();
77-
dump_node(ast, root, source, options, 0, Some((schema, None, None)), &mut out);
72+
dump_node(
73+
ast,
74+
root,
75+
source,
76+
options,
77+
0,
78+
Some((schema, None, None)),
79+
&mut out,
80+
);
7881
out
7982
}
8083

@@ -232,8 +235,8 @@ fn dump_node(
232235
}
233236
let field_name = ast.field_name_for_id(field_id).unwrap_or("?");
234237
let child_type_check = type_check.map(|(schema, _, _)| {
235-
let expected = expected_for_field(schema, node.kind_name(), field_id)
236-
.or(Some(EMPTY_NODE_TYPES));
238+
let expected =
239+
expected_for_field(schema, node.kind_name(), field_id).or(Some(EMPTY_NODE_TYPES));
237240
let parent_field = Some((node.kind_name(), field_name));
238241
(schema, expected, parent_field)
239242
});

shared/yeast/src/lib.rs

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,9 @@ impl Ast {
297297
/// Returns the source text for `id`, resolving `NodeContent::Range`
298298
/// against the stored source bytes when available.
299299
pub fn source_text(&self, id: Id) -> String {
300-
let Some(node) = self.get_node(id) else { return String::new(); };
300+
let Some(node) = self.get_node(id) else {
301+
return String::new();
302+
};
301303
let read_range = |range: &tree_sitter::Range| {
302304
let start = range.start_byte;
303305
let end = range.end_byte;
@@ -488,7 +490,10 @@ impl Ast {
488490

489491
/// Prepend a child id to the given field of the given node.
490492
pub fn prepend_field_child(&mut self, node_id: Id, field_id: FieldId, value_id: Id) {
491-
let node = self.nodes.get_mut(node_id).expect("prepend_field_child: invalid node id");
493+
let node = self
494+
.nodes
495+
.get_mut(node_id)
496+
.expect("prepend_field_child: invalid node id");
492497
node.fields.entry(field_id).or_default().insert(0, value_id);
493498
}
494499

@@ -737,12 +742,7 @@ impl<'a, C: Clone> TranslatorHandle<'a, C> {
737742
/// Recursively apply OneShot rules to `id` and return the resulting
738743
/// node ids. Errors in a Repeating phase (where translation is not
739744
/// meaningful).
740-
pub fn translate(
741-
&self,
742-
ast: &mut Ast,
743-
user_ctx: &mut C,
744-
id: Id,
745-
) -> Result<Vec<Id>, String> {
745+
pub fn translate(&self, ast: &mut Ast, user_ctx: &mut C, id: Id) -> Result<Vec<Id>, String> {
746746
match &self.inner {
747747
TranslatorImpl::OneShot {
748748
index,
@@ -851,9 +851,9 @@ impl<C> Rule<C> {
851851
translator: TranslatorHandle<'_, C>,
852852
) -> Result<Option<Vec<Id>>, String> {
853853
match self.try_match(ast, node)? {
854-
Some(captures) => Ok(Some(self.run_transform(
855-
ast, captures, node, fresh, user_ctx, translator,
856-
)?)),
854+
Some(captures) => Ok(Some(
855+
self.run_transform(ast, captures, node, fresh, user_ctx, translator)?,
856+
)),
857857
None => Ok(None),
858858
}
859859
}
@@ -1004,7 +1004,15 @@ fn apply_repeating_rules_inner<C: Clone>(
10041004
for children in fields.values_mut() {
10051005
let mut new_children: Option<Vec<Id>> = None;
10061006
for (i, &child_id) in children.iter().enumerate() {
1007-
let result = apply_repeating_rules_inner(index, ast, user_ctx, child_id, fresh, rewrite_depth, None)?;
1007+
let result = apply_repeating_rules_inner(
1008+
index,
1009+
ast,
1010+
user_ctx,
1011+
child_id,
1012+
fresh,
1013+
rewrite_depth,
1014+
None,
1015+
)?;
10081016
let unchanged = result.len() == 1 && result[0] == child_id;
10091017
match (&mut new_children, unchanged) {
10101018
(None, true) => {} // unchanged so far, no allocation needed
@@ -1052,7 +1060,6 @@ fn apply_one_shot_rules_inner<C: Clone>(
10521060
fresh: &tree_builder::FreshScope,
10531061
rewrite_depth: usize,
10541062
) -> Result<Vec<Id>, String> {
1055-
10561063
if rewrite_depth > MAX_REWRITE_DEPTH {
10571064
return Err(format!(
10581065
"Desugaring exceeded maximum rewrite depth ({MAX_REWRITE_DEPTH}). \
@@ -1294,8 +1301,12 @@ impl<'a, C: Clone> Runner<'a, C> {
12941301
let mut root = ast.get_root();
12951302
for phase in self.phases {
12961303
let res = match phase.kind {
1297-
PhaseKind::Repeating => apply_repeating_rules(&phase.rules, ast, user_ctx, root, &fresh),
1298-
PhaseKind::OneShot => apply_one_shot_rules(&phase.rules, ast, user_ctx, root, &fresh),
1304+
PhaseKind::Repeating => {
1305+
apply_repeating_rules(&phase.rules, ast, user_ctx, root, &fresh)
1306+
}
1307+
PhaseKind::OneShot => {
1308+
apply_one_shot_rules(&phase.rules, ast, user_ctx, root, &fresh)
1309+
}
12991310
}
13001311
.map_err(|e| format!("Phase `{}`: {e}", phase.name))?;
13011312
if res.len() != 1 {
@@ -1315,11 +1326,7 @@ impl<'a, C: Clone> Runner<'a, C> {
13151326
impl<'a, C: Clone + Default> Runner<'a, C> {
13161327
/// Parse `tree` against `source` and run all phases, using the
13171328
/// default context (`C::default()`) as the initial context state.
1318-
pub fn run_from_tree(
1319-
&self,
1320-
tree: &tree_sitter::Tree,
1321-
source: &[u8],
1322-
) -> Result<Ast, String> {
1329+
pub fn run_from_tree(&self, tree: &tree_sitter::Tree, source: &[u8]) -> Result<Ast, String> {
13231330
let mut user_ctx = C::default();
13241331
self.run_from_tree_with_ctx(tree, source, &mut user_ctx)
13251332
}
@@ -1351,8 +1358,7 @@ pub trait Desugarer: Send + Sync {
13511358

13521359
/// Parse `tree` against `source` and run the desugaring pipeline.
13531360
/// Each call constructs a fresh default user context internally.
1354-
fn run_from_tree(&self, tree: &tree_sitter::Tree, source: &[u8])
1355-
-> Result<Ast, String>;
1361+
fn run_from_tree(&self, tree: &tree_sitter::Tree, source: &[u8]) -> Result<Ast, String>;
13561362
}
13571363

13581364
/// A concrete [`Desugarer`] backed by a [`DesugaringConfig<C>`] for a
@@ -1386,13 +1392,8 @@ impl<C: Default + Clone + Send + Sync + 'static> Desugarer for ConcreteDesugarer
13861392
self.config.output_node_types_yaml
13871393
}
13881394

1389-
fn run_from_tree(
1390-
&self,
1391-
tree: &tree_sitter::Tree,
1392-
source: &[u8],
1393-
) -> Result<Ast, String> {
1394-
let runner =
1395-
Runner::with_schema(self.language.clone(), &self.schema, &self.config.phases);
1395+
fn run_from_tree(&self, tree: &tree_sitter::Tree, source: &[u8]) -> Result<Ast, String> {
1396+
let runner = Runner::with_schema(self.language.clone(), &self.schema, &self.config.phases);
13961397
runner.run_from_tree(tree, source)
13971398
}
13981399
}

shared/yeast/src/node_types_yaml.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,7 @@ pub fn convert(yaml_input: &str) -> Result<String, String> {
242242

243243
/// Apply YAML node-type definitions to a mutable Schema.
244244
/// Registers all types, fields, and allowed types from the YAML into the schema.
245-
fn apply_yaml_to_schema(
246-
yaml: &YamlNodeTypes,
247-
schema: &mut crate::schema::Schema,
248-
) {
245+
fn apply_yaml_to_schema(yaml: &YamlNodeTypes, schema: &mut crate::schema::Schema) {
249246
// Register all supertypes as node kinds
250247
for name in yaml.supertypes.keys() {
251248
schema.register_kind(name);
@@ -307,7 +304,8 @@ fn apply_yaml_to_schema(
307304
.into_vec()
308305
.into_iter()
309306
.map(|type_ref| {
310-
let (kind, named) = resolve_type_ref_pair(&type_ref, &named_types, &unnamed_types);
307+
let (kind, named) =
308+
resolve_type_ref_pair(&type_ref, &named_types, &unnamed_types);
311309
crate::schema::NodeType { kind, named }
312310
})
313311
.collect::<Vec<_>>();

shared/yeast/src/schema.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,8 @@ impl Schema {
198198
.insert((parent_kind.to_string(), field_id), node_types);
199199
}
200200

201-
pub fn field_types(
202-
&self,
203-
parent_kind: &str,
204-
field_id: FieldId,
205-
) -> Option<&Vec<NodeType>> {
206-
self.field_types
207-
.get(&(parent_kind.to_string(), field_id))
201+
pub fn field_types(&self, parent_kind: &str, field_id: FieldId) -> Option<&Vec<NodeType>> {
202+
self.field_types.get(&(parent_kind.to_string(), field_id))
208203
}
209204

210205
pub fn set_field_cardinality(

0 commit comments

Comments
 (0)