diff --git a/crates/codegen/grammar/src/constructor.rs b/crates/codegen/grammar/src/constructor.rs index 333c54cc34..96cf095c2c 100644 --- a/crates/codegen/grammar/src/constructor.rs +++ b/crates/codegen/grammar/src/constructor.rs @@ -11,7 +11,7 @@ use indexmap::IndexMap; use crate::{ Grammar, GrammarElement, KeywordScannerDefinition, KeywordScannerDefinitionNode, - KeywordScannerDefinitionVersionedNode, Named, ParserDefinition, ParserDefinitionNode, + KeywordScannerDefinitionVersionedNode, Labeled, ParserDefinition, ParserDefinitionNode, PrecedenceOperatorModel, PrecedenceParserDefinition, PrecedenceParserDefinitionNode, ScannerDefinition, ScannerDefinitionNode, TriviaParserDefinition, VersionQuality, VersionQualityRange, @@ -513,23 +513,25 @@ fn resolve_trivia(parser: model::TriviaParser, ctx: &mut ResolveCtx<'_>) -> Pars ParserDefinitionNode::Optional(Box::new(resolve_trivia(*parser, ctx))) } model::TriviaParser::OneOrMore { parser } => ParserDefinitionNode::OneOrMore( - Named::anonymous(Box::new(resolve_trivia(*parser, ctx))), + Labeled::anonymous(Box::new(resolve_trivia(*parser, ctx))), ), model::TriviaParser::ZeroOrMore { parser } => ParserDefinitionNode::ZeroOrMore( - Named::anonymous(Box::new(resolve_trivia(*parser, ctx))), + Labeled::anonymous(Box::new(resolve_trivia(*parser, ctx))), ), model::TriviaParser::Sequence { parsers } => ParserDefinitionNode::Sequence( parsers .into_iter() - .map(|scanner| Named::anonymous(resolve_trivia(scanner, ctx))) + .map(|scanner| Labeled::anonymous(resolve_trivia(scanner, ctx))) .collect(), ), - model::TriviaParser::Choice { parsers } => ParserDefinitionNode::Choice(Named::anonymous( - parsers - .into_iter() - .map(|scanner| resolve_trivia(scanner, ctx)) - .collect(), - )), + model::TriviaParser::Choice { parsers } => { + ParserDefinitionNode::Choice(Labeled::anonymous( + parsers + .into_iter() + .map(|scanner| resolve_trivia(scanner, ctx)) + .collect(), + )) + } model::TriviaParser::Trivia { reference } => { match resolve_grammar_element(&reference, ctx) { GrammarElement::ScannerDefinition(parser) => { @@ -588,7 +590,7 @@ fn resolve_sequence_like( let delimited_body = ParserDefinitionNode::Sequence( fields .drain((open_idx + 1)..close_idx) - .map(|(name, field)| Named::with_ident_name(name, field)) + .map(|(name, field)| Labeled::with_ident_name(name, field)) .collect(), ); @@ -596,7 +598,7 @@ fn resolve_sequence_like( let delimited = { let mut delims = fields .drain(open_idx..=open_idx + 1) - .map(|(name, field)| Named::with_ident_name(name, Box::new(field))); + .map(|(name, field)| Labeled::with_ident_name(name, Box::new(field))); let open = delims.next().unwrap(); let close = delims.next().unwrap(); @@ -618,7 +620,7 @@ fn resolve_sequence_like( let (name, def) = fields.pop().unwrap(); assert_eq!(name, terminator); - Some(Named::with_ident_name(name, Box::new(def))) + Some(Labeled::with_ident_name(name, Box::new(def))) } None => None, }; @@ -626,7 +628,7 @@ fn resolve_sequence_like( let body = ParserDefinitionNode::Sequence( fields .into_iter() - .map(|(name, def)| Named::with_ident_name(name, def)) + .map(|(name, def)| Labeled::with_ident_name(name, def)) .collect(), ); @@ -649,17 +651,14 @@ fn resolve_choice(item: model::EnumItem, ctx: &mut ResolveCtx<'_>) -> ParserDefi }) .collect(); - ParserDefinitionNode::Choice(Named::with_builtin_name( - BuiltinFieldName::Variant, - variants, - )) - .versioned(item.enabled) + ParserDefinitionNode::Choice(Labeled::with_builtin_label(BuiltInLabel::Variant, variants)) + .versioned(item.enabled) } fn resolve_repeated(item: model::RepeatedItem, ctx: &mut ResolveCtx<'_>) -> ParserDefinitionNode { let reference = Box::new(resolve_grammar_element(&item.reference, ctx).into_parser_def_node()); - ParserDefinitionNode::OneOrMore(Named::with_builtin_name(BuiltinFieldName::Item, reference)) + ParserDefinitionNode::OneOrMore(Labeled::with_builtin_label(BuiltInLabel::Item, reference)) .versioned(item.enabled) } @@ -668,8 +667,8 @@ fn resolve_separated(item: model::SeparatedItem, ctx: &mut ResolveCtx<'_>) -> Pa let separator = resolve_grammar_element(&item.separator, ctx).into_parser_def_node(); ParserDefinitionNode::SeparatedBy( - Named::with_builtin_name(BuiltinFieldName::Item, Box::new(reference)), - Named::with_builtin_name(BuiltinFieldName::Separator, Box::new(separator)), + Labeled::with_builtin_label(BuiltInLabel::Item, Box::new(reference)), + Labeled::with_builtin_label(BuiltInLabel::Separator, Box::new(separator)), ) .versioned(item.enabled) } @@ -690,8 +689,8 @@ fn resolve_precedence( .collect(); let primary_expression = Box::new(match primaries.len() { 0 => panic!("Precedence operator has no primary expressions"), - _ => ParserDefinitionNode::Choice(Named::with_builtin_name( - BuiltinFieldName::Variant, + _ => ParserDefinitionNode::Choice(Labeled::with_builtin_label( + BuiltInLabel::Variant, primaries, )), }); @@ -748,11 +747,11 @@ fn resolve_precedence( // HACK: Despite it being a single definition, we still need to wrap a versioned // node around the choice for it to emit the version checks for the node. [ParserDefinitionNode::Versioned(..)] => { - ParserDefinitionNode::Choice(Named::anonymous(defs)) + ParserDefinitionNode::Choice(Labeled::anonymous(defs)) } [_] => defs.into_iter().next().unwrap(), // NOTE: We give empty names to not ovewrite the names of the flattened fields of the operators - _ => ParserDefinitionNode::Choice(Named::anonymous(defs)), + _ => ParserDefinitionNode::Choice(Labeled::anonymous(defs)), }; all_operators.push(def.clone()); @@ -763,7 +762,7 @@ fn resolve_precedence( // as reachable and ensure we emit a token kind for each thunk .def - .set(ParserDefinitionNode::Choice(Named::anonymous( + .set(ParserDefinitionNode::Choice(Labeled::anonymous( all_operators, ))) .unwrap(); @@ -835,41 +834,44 @@ impl VersionWrapped for ScannerDefinitionNode { } } -trait NamedExt { +trait LabeledExt { fn anonymous(node: T) -> Self; fn with_ident_name(name: Identifier, node: T) -> Self; - fn with_builtin_name(name: BuiltinFieldName, node: T) -> Self; + fn with_builtin_label(name: BuiltInLabel, node: T) -> Self; } -// Subset of _SLANG_INTERNAL_RESERVED_NODE_FIELD_NAMES_; we can't depend directly on -// the pre-expansion codegen_parser_runtime crate due to NAPI build issues. +#[allow(dead_code)] #[derive(strum_macros::AsRefStr)] #[strum(serialize_all = "snake_case")] -enum BuiltinFieldName { +enum BuiltInLabel { + // _SLANG_INTERNAL_RESERVED_NODE_LABELS_ (keep in sync) Item, Variant, Separator, + Operand, + LeftOperand, + RightOperand, } -impl NamedExt for Named { - fn anonymous(node: T) -> Self { +impl LabeledExt for Labeled { + fn anonymous(value: T) -> Self { Self { - name: String::new(), - node, + label: String::new(), + value, } } - fn with_ident_name(name: Identifier, node: T) -> Self { + fn with_ident_name(name: Identifier, value: T) -> Self { Self { - name: name.to_string(), - node, + label: name.to_string(), + value, } } - fn with_builtin_name(name: BuiltinFieldName, node: T) -> Self { + fn with_builtin_label(label: BuiltInLabel, value: T) -> Self { Self { - name: name.as_ref().to_owned(), - node, + label: label.as_ref().to_owned(), + value, } } } diff --git a/crates/codegen/grammar/src/parser_definition.rs b/crates/codegen/grammar/src/parser_definition.rs index bcb123f921..bc4da37edc 100644 --- a/crates/codegen/grammar/src/parser_definition.rs +++ b/crates/codegen/grammar/src/parser_definition.rs @@ -9,16 +9,16 @@ use crate::{ /// A named wrapper, used to give a name to a [`ParserDefinitionNode`]. #[derive(Clone, Debug)] -pub struct Named { - pub name: String, - pub node: T, +pub struct Labeled { + pub label: String, + pub value: T, } -impl std::ops::Deref for Named { +impl std::ops::Deref for Labeled { type Target = T; fn deref(&self) -> &Self::Target { - &self.node + &self.value } } @@ -57,18 +57,18 @@ impl Visitable for TriviaParserDefinitionRef { pub enum ParserDefinitionNode { Versioned(Box, Vec), Optional(Box), - ZeroOrMore(Named>), - OneOrMore(Named>), - Sequence(Vec>), - Choice(Named>), + ZeroOrMore(Labeled>), + OneOrMore(Labeled>), + Sequence(Vec>), + Choice(Labeled>), ScannerDefinition(ScannerDefinitionRef), KeywordScannerDefinition(KeywordScannerDefinitionRef), TriviaParserDefinition(TriviaParserDefinitionRef), ParserDefinition(ParserDefinitionRef), PrecedenceParserDefinition(PrecedenceParserDefinitionRef), - DelimitedBy(Named>, Box, Named>), - SeparatedBy(Named>, Named>), - TerminatedBy(Box, Named>), + DelimitedBy(Labeled>, Box, Labeled>), + SeparatedBy(Labeled>, Labeled>), + TerminatedBy(Box, Labeled>), } impl From for ParserDefinitionNode { @@ -99,17 +99,17 @@ impl Visitable for ParserDefinitionNode { fn accept_visitor(&self, visitor: &mut V) { visitor.parser_definition_node_enter(self); match self { - Self::Versioned(node, _) - | Self::Optional(node) - | Self::ZeroOrMore(Named { node, .. }) - | Self::OneOrMore(Named { node, .. }) => node.accept_visitor(visitor), + Self::Versioned(value, _) + | Self::Optional(value) + | Self::ZeroOrMore(Labeled { value, .. }) + | Self::OneOrMore(Labeled { value, .. }) => value.accept_visitor(visitor), Self::Sequence(nodes) => { for node in nodes { node.accept_visitor(visitor); } } - Self::Choice(Named { node: nodes, .. }) => { + Self::Choice(Labeled { value: nodes, .. }) => { for node in nodes { node.accept_visitor(visitor); } diff --git a/crates/codegen/parser/generator/src/parser_definition.rs b/crates/codegen/parser/generator/src/parser_definition.rs index 536f1abe6e..0fc1eac44a 100644 --- a/crates/codegen/parser/generator/src/parser_definition.rs +++ b/crates/codegen/parser/generator/src/parser_definition.rs @@ -1,5 +1,5 @@ use codegen_grammar::{ - Named, ParserDefinitionNode, ParserDefinitionRef, TriviaParserDefinitionRef, VersionQuality, + Labeled, ParserDefinitionNode, ParserDefinitionRef, TriviaParserDefinitionRef, VersionQuality, VersionQualityRange, }; use inflector::Inflector; @@ -47,16 +47,16 @@ impl ParserDefinitionNodeExtensions for ParserDefinitionNode { } } - Self::ZeroOrMore(Named { name, node }) => { - let parser = node.to_parser_code(context_name, is_trivia); + Self::ZeroOrMore(Labeled { label, value }) => { + let parser = value.to_parser_code(context_name, is_trivia); - let parser = if name.is_empty() { + let parser = if label.is_empty() { parser } else { - let name = format_ident!("{}", name.to_pascal_case()); + let name = format_ident!("{}", label.to_pascal_case()); quote! { - #parser.with_name(FieldName::#name) + #parser.with_label(NodeLabel::#name) } }; @@ -65,16 +65,16 @@ impl ParserDefinitionNodeExtensions for ParserDefinitionNode { } } - Self::OneOrMore(Named { name, node }) => { - let parser = node.to_parser_code(context_name, is_trivia); + Self::OneOrMore(Labeled { label, value }) => { + let parser = value.to_parser_code(context_name, is_trivia); - let parser = if name.is_empty() { + let parser = if label.is_empty() { parser } else { - let name = format_ident!("{}", name.to_pascal_case()); + let name = format_ident!("{}", label.to_pascal_case()); quote! { - #parser.with_name(FieldName::#name) + #parser.with_label(NodeLabel::#name) } }; @@ -84,43 +84,43 @@ impl ParserDefinitionNodeExtensions for ParserDefinitionNode { } Self::Sequence(nodes) => match &nodes[..] { - [Named { name, node }] => { - let parser = node.to_parser_code(context_name, is_trivia); + [Labeled { label, value }] => { + let parser = value.to_parser_code(context_name, is_trivia); - if name.is_empty() { + if label.is_empty() { parser } else { - let name = format_ident!("{}", name.to_pascal_case()); + let name = format_ident!("{}", label.to_pascal_case()); quote! { - #parser.with_name(FieldName::#name) + #parser.with_label(NodeLabel::#name) } } } - nodes => make_sequence_versioned(nodes.iter().map(|Named { name, node }| { + nodes => make_sequence_versioned(nodes.iter().map(|Labeled { label, value }| { ( - node.to_parser_code(context_name, is_trivia), - name.clone(), - node.applicable_version_quality_ranges(), + value.to_parser_code(context_name, is_trivia), + label.clone(), + value.applicable_version_quality_ranges(), ) })), }, - Self::Choice(Named { name, node: nodes }) => { - let parser = make_choice_versioned(nodes.iter().map(|node| { + Self::Choice(Labeled { label, value }) => { + let parser = make_choice_versioned(value.iter().map(|node| { ( node.to_parser_code(context_name, is_trivia), node.applicable_version_quality_ranges(), ) })); - if name.is_empty() { + if label.is_empty() { parser } else { - let name = format_ident!("{}", name.to_pascal_case()); + let name = format_ident!("{}", label.to_pascal_case()); quote! { - #parser.with_name(FieldName::#name) + #parser.with_label(NodeLabel::#name) } } } @@ -192,8 +192,8 @@ impl ParserDefinitionNodeExtensions for ParserDefinitionNode { } Self::DelimitedBy(open, body, close) => { - let open_field_name = format_ident!("{}", open.name.to_pascal_case()); - let close_field_name = format_ident!("{}", close.name.to_pascal_case()); + let open_label = format_ident!("{}", open.label.to_pascal_case()); + let close_label = format_ident!("{}", close.label.to_pascal_case()); let [open_delim, close_delim] = match (open.as_ref(), close.as_ref()) { ( ParserDefinitionNode::ScannerDefinition(open, ..), @@ -221,13 +221,13 @@ impl ParserDefinitionNodeExtensions for ParserDefinitionNode { let mut delim_guard = input.open_delim(TokenKind::#close_delim); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::#open_field_name, + seq.elem_labeled( + NodeLabel::#open_label, self.parse_token_with_trivia::<#lex_ctx>(input, TokenKind::#open_delim) )?; #body_parser - seq.elem_named( - FieldName::#close_field_name, + seq.elem_labeled( + NodeLabel::#close_label, self.parse_token_with_trivia::<#lex_ctx>(input, TokenKind::#close_delim) )?; seq.finish() @@ -236,7 +236,7 @@ impl ParserDefinitionNodeExtensions for ParserDefinitionNode { } Self::SeparatedBy(body, separator) => { - let separator_field_name = format_ident!("{}", separator.name.to_pascal_case()); + let separator_label = format_ident!("{}", separator.label.to_pascal_case()); let separator = match separator.as_ref() { ParserDefinitionNode::ScannerDefinition(scanner, ..) => { format_ident!("{name}", name = scanner.name()) @@ -244,21 +244,21 @@ impl ParserDefinitionNodeExtensions for ParserDefinitionNode { _ => unreachable!("Only tokens are permitted as separators"), }; - let body_field_name = format_ident!("{}", body.name.to_pascal_case()); + let body_label = format_ident!("{}", body.label.to_pascal_case()); let parser = body.to_parser_code(context_name, is_trivia); quote! { SeparatedHelper::run::<_, #lex_ctx>( input, self, - |input| #parser.with_name(FieldName::#body_field_name), + |input| #parser.with_label(NodeLabel::#body_label), TokenKind::#separator, - FieldName::#separator_field_name, + NodeLabel::#separator_label, ) } } Self::TerminatedBy(body, terminator) => { - let terminator_field_name = format_ident!("{}", terminator.name.to_pascal_case()); + let terminator_label = format_ident!("{}", terminator.label.to_pascal_case()); let terminator = match terminator.as_ref() { ParserDefinitionNode::ScannerDefinition(scanner, ..) => { @@ -285,8 +285,8 @@ impl ParserDefinitionNodeExtensions for ParserDefinitionNode { quote! { SequenceHelper::run(|mut seq| { #body_parser - seq.elem_named( - FieldName::#terminator_field_name, + seq.elem_labeled( + NodeLabel::#terminator_label, self.parse_token_with_trivia::<#lex_ctx>(input, TokenKind::#terminator) )?; seq.finish() @@ -302,10 +302,10 @@ impl ParserDefinitionNodeExtensions for ParserDefinitionNode { version_quality_ranges.clone() } - ParserDefinitionNode::Optional(node) - | ParserDefinitionNode::ZeroOrMore(Named { node, .. }) - | ParserDefinitionNode::OneOrMore(Named { node, .. }) => { - node.applicable_version_quality_ranges() + ParserDefinitionNode::Optional(value) + | ParserDefinitionNode::ZeroOrMore(Labeled { value, .. }) + | ParserDefinitionNode::OneOrMore(Labeled { value, .. }) => { + value.applicable_version_quality_ranges() } _ => vec![], @@ -377,9 +377,9 @@ pub fn make_sequence_versioned( let code = if name.is_empty() { quote! { seq.elem(#parser)?; } } else { - let field_name = format_ident!("{}", name.to_pascal_case()); + let label = format_ident!("{}", name.to_pascal_case()); - quote! { seq.elem_named(FieldName::#field_name, #parser)?; } + quote! { seq.elem_labeled(NodeLabel::#label, #parser)?; } }; versions.wrap_code(code, None) diff --git a/crates/codegen/parser/generator/src/precedence_parser_definition.rs b/crates/codegen/parser/generator/src/precedence_parser_definition.rs index aa00f2135a..91d0c01673 100644 --- a/crates/codegen/parser/generator/src/precedence_parser_definition.rs +++ b/crates/codegen/parser/generator/src/precedence_parser_definition.rs @@ -40,8 +40,8 @@ impl PrecedenceParserDefinitionExtensions for PrecedenceParserDefinitionRef { // If the result won't match exactly, we return a dummy `ParserResult::no_match`, since // can't precisely determine the expected tokens or completeness of the match otherwise. match &r#match.nodes[..] { - [cst::NamedNode { name: _, node: cst::Node::Rule(node), }] if node.kind == RuleKind::#rule_name => match &node.children[..] { - [inner @ cst::NamedNode { name: _, node: cst::Node::Rule(rule) }] if rule.kind == RuleKind::#op_rule_name => { + [cst::LabeledNode { label: _, node: cst::Node::Rule(node) }] if node.kind == RuleKind::#rule_name => match &node.children[..] { + [inner @ cst::LabeledNode { label: _, node: cst::Node::Rule(rule) }] if rule.kind == RuleKind::#op_rule_name => { ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) } _ => ParserResult::no_match(vec![]), diff --git a/crates/codegen/parser/generator/src/rust_generator.rs b/crates/codegen/parser/generator/src/rust_generator.rs index 3ecbe5842d..1b2b5b2f13 100644 --- a/crates/codegen/parser/generator/src/rust_generator.rs +++ b/crates/codegen/parser/generator/src/rust_generator.rs @@ -29,7 +29,7 @@ pub struct RustGenerator { rule_kinds: BTreeSet<&'static str>, token_kinds: BTreeSet<&'static str>, trivia_kinds: BTreeSet<&'static str>, - field_names: BTreeSet, + labels: BTreeSet, scanner_functions: BTreeMap<&'static str, String>, // (name of scanner, code) scanner_contexts: BTreeMap<&'static str, ScannerContext>, @@ -240,15 +240,15 @@ impl GrammarVisitor for RustGenerator { .collect(); // Make sure empty strings are not there - self.field_names.remove(""); + self.labels.remove(""); // These are built-in and already pre-defined - // _SLANG_INTERNAL_RESERVED_NODE_FIELD_NAMES_ (keep in sync) - self.field_names.remove("item"); - self.field_names.remove("variant"); - self.field_names.remove("separator"); - self.field_names.remove("operand"); - self.field_names.remove("left_operand"); - self.field_names.remove("right_operand"); + // _SLANG_INTERNAL_RESERVED_NODE_LABELS_ (keep in sync) + self.labels.remove("item"); + self.labels.remove("variant"); + self.labels.remove("separator"); + self.labels.remove("operand"); + self.labels.remove("left_operand"); + self.labels.remove("right_operand"); // Just being anal about tidying up :) self.all_scanners.clear(); @@ -362,25 +362,25 @@ impl GrammarVisitor for RustGenerator { // Collect field names ParserDefinitionNode::Choice(choice) => { - self.field_names.insert(choice.name.clone()); + self.labels.insert(choice.label.clone()); } ParserDefinitionNode::Sequence(sequence) => { for node in sequence { - self.field_names.insert(node.name.clone()); + self.labels.insert(node.label.clone()); } } ParserDefinitionNode::SeparatedBy(item, separator) => { - self.field_names.insert(item.name.clone()); - self.field_names.insert(separator.name.clone()); + self.labels.insert(item.label.clone()); + self.labels.insert(separator.label.clone()); } ParserDefinitionNode::TerminatedBy(_, terminator) => { - self.field_names.insert(terminator.name.clone()); + self.labels.insert(terminator.label.clone()); } // Collect delimiters for each context ParserDefinitionNode::DelimitedBy(open, _, close) => { - self.field_names.insert(open.name.clone()); - self.field_names.insert(close.name.clone()); + self.labels.insert(open.label.clone()); + self.labels.insert(close.label.clone()); let (open, close) = match (open.as_ref(), close.as_ref()) { ( diff --git a/crates/codegen/parser/runtime/src/cst.rs b/crates/codegen/parser/runtime/src/cst.rs index 4dccdf6190..d81a96b881 100644 --- a/crates/codegen/parser/runtime/src/cst.rs +++ b/crates/codegen/parser/runtime/src/cst.rs @@ -3,23 +3,23 @@ use std::rc::Rc; use serde::Serialize; use crate::cursor::Cursor; -use crate::kinds::{FieldName, RuleKind, TokenKind}; +use crate::kinds::{NodeLabel, RuleKind, TokenKind}; use crate::text_index::TextIndex; #[derive(Clone, Debug, PartialEq, Eq, Serialize)] -pub struct NamedNode { - pub name: Option, +pub struct LabeledNode { + pub label: Option, pub node: Node, } -impl NamedNode { - /// Creates an anonymous (nameless) node. +impl LabeledNode { + /// Creates an anonymous node (without a label). pub fn anonymous(node: Node) -> Self { - Self { name: None, node } + Self { label: None, node } } } -impl std::ops::Deref for NamedNode { +impl std::ops::Deref for LabeledNode { type Target = Node; fn deref(&self) -> &Self::Target { @@ -32,7 +32,7 @@ pub struct RuleNode { pub kind: RuleKind, pub text_len: TextIndex, #[serde(skip_serializing_if = "Vec::is_empty")] - pub children: Vec, + pub children: Vec, } #[derive(Clone, Debug, PartialEq, Eq, Serialize)] @@ -48,7 +48,7 @@ pub enum Node { } impl Node { - pub fn rule(kind: RuleKind, children: Vec) -> Self { + pub fn rule(kind: RuleKind, children: Vec) -> Self { let text_len = children.iter().map(|node| node.text_len()).sum(); Self::Rule(Rc::new(RuleNode { @@ -70,7 +70,7 @@ impl Node { } /// Returns a slice of the children (not all descendants) of this node. - pub fn children(&self) -> &[NamedNode] { + pub fn children(&self) -> &[LabeledNode] { match self { Self::Rule(node) => &node.children, Self::Token(_) => &[], diff --git a/crates/codegen/parser/runtime/src/cursor.rs b/crates/codegen/parser/runtime/src/cursor.rs index 429489e562..7e65004866 100644 --- a/crates/codegen/parser/runtime/src/cursor.rs +++ b/crates/codegen/parser/runtime/src/cursor.rs @@ -2,8 +2,8 @@ use std::rc::Rc; -use crate::cst::{NamedNode, Node, RuleNode}; -use crate::kinds::{FieldName, RuleKind, TokenKind}; +use crate::cst::{LabeledNode, Node, RuleNode}; +use crate::kinds::{NodeLabel, RuleKind, TokenKind}; use crate::text_index::{TextIndex, TextRange}; /// A node in the ancestor path of a [`Cursor`]. @@ -124,11 +124,11 @@ impl Cursor { self.node.clone() } - pub fn node_name(&self) -> Option { + pub fn label(&self) -> Option { self.parent.as_ref().and_then(|parent| { let this = &parent.rule_node.children[self.child_number]; - this.name + this.label }) } @@ -413,28 +413,28 @@ impl Cursor { } } -/// A [`Cursor`] that also keeps track of the names of the nodes it visits. -pub struct CursorWithNames { +/// A [`Cursor`] that also keeps track of the labels of the nodes it visits. +pub struct CursorWithLabels { cursor: Cursor, } -impl CursorWithNames { - pub fn without_names(self) -> Cursor { +impl CursorWithLabels { + pub fn without_labels(self) -> Cursor { self.cursor } } -impl Iterator for CursorWithNames { - type Item = NamedNode; +impl Iterator for CursorWithLabels { + type Item = LabeledNode; fn next(&mut self) -> Option { - let name = self.cursor.node_name(); + let label = self.cursor.label(); - self.cursor.next().map(|node| NamedNode { name, node }) + self.cursor.next().map(|node| LabeledNode { label, node }) } } -impl std::ops::Deref for CursorWithNames { +impl std::ops::Deref for CursorWithLabels { type Target = Cursor; fn deref(&self) -> &Self::Target { @@ -442,21 +442,21 @@ impl std::ops::Deref for CursorWithNames { } } -impl std::ops::DerefMut for CursorWithNames { +impl std::ops::DerefMut for CursorWithLabels { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.cursor } } impl Cursor { - /// Returns a [`CursorWithNames`] that wraps this cursor. - pub fn with_names(self) -> CursorWithNames { - CursorWithNames::from(self) + /// Returns a [`CursorWithLabels`] that wraps this cursor. + pub fn with_labels(self) -> CursorWithLabels { + CursorWithLabels::from(self) } } -impl From for CursorWithNames { +impl From for CursorWithLabels { fn from(cursor: Cursor) -> Self { - CursorWithNames { cursor } + CursorWithLabels { cursor } } } diff --git a/crates/codegen/parser/runtime/src/kinds.rs b/crates/codegen/parser/runtime/src/kinds.rs index 2d25729b69..1cce7d11b8 100644 --- a/crates/codegen/parser/runtime/src/kinds.rs +++ b/crates/codegen/parser/runtime/src/kinds.rs @@ -67,9 +67,9 @@ impl RuleKind { )] #[cfg_attr(feature = "slang_napi_interfaces", /* derives `Clone` and `Copy` */ napi(string_enum, namespace = "kinds"))] #[cfg_attr(not(feature = "slang_napi_interfaces"), derive(Clone, Copy))] -pub enum FieldName { - // Built-in fields - // _SLANG_INTERNAL_RESERVED_NODE_FIELD_NAMES_ (keep in sync) +pub enum NodeLabel { + // Built-in labels + // _SLANG_INTERNAL_RESERVED_NODE_LABELS_ (keep in sync) Item, Variant, Separator, @@ -77,9 +77,9 @@ pub enum FieldName { LeftOperand, RightOperand, // Used for testing this crate, this is generated in the client code - Name1, - Name2, - Name3, + Label1, + Label2, + Label3, } /// The lexical context of the scanner. diff --git a/crates/codegen/parser/runtime/src/lexer.rs b/crates/codegen/parser/runtime/src/lexer.rs index 3001d80371..3094fea736 100644 --- a/crates/codegen/parser/runtime/src/lexer.rs +++ b/crates/codegen/parser/runtime/src/lexer.rs @@ -1,4 +1,4 @@ -use crate::cst::{self, NamedNode}; +use crate::cst::{self, LabeledNode}; use crate::kinds::{IsLexicalContext, TokenKind}; use crate::parser_support::{ParserContext, ParserResult}; @@ -111,7 +111,7 @@ pub(crate) trait Lexer { let end = input.position(); ParserResult::r#match( - vec![NamedNode::anonymous(cst::Node::token( + vec![LabeledNode::anonymous(cst::Node::token( kind, input.content(start.utf8..end.utf8), ))], @@ -144,7 +144,7 @@ pub(crate) trait Lexer { return ParserResult::no_match(vec![kind]); } let end = input.position(); - children.push(NamedNode::anonymous(cst::Node::token( + children.push(LabeledNode::anonymous(cst::Node::token( kind, input.content(start.utf8..end.utf8), ))); diff --git a/crates/codegen/parser/runtime/src/napi_interface/cursor.rs b/crates/codegen/parser/runtime/src/napi_interface/cursor.rs index 32081f21dd..b1ffbdf2c4 100644 --- a/crates/codegen/parser/runtime/src/napi_interface/cursor.rs +++ b/crates/codegen/parser/runtime/src/napi_interface/cursor.rs @@ -9,7 +9,7 @@ use napi::JsObject; use napi_derive::napi; use text_index::{TextIndex, TextRange}; -use crate::napi_interface::{cst, text_index, FieldName, RuleKind, RustCursor, TokenKind}; +use crate::napi_interface::{cst, text_index, NodeLabel, RuleKind, RustCursor, TokenKind}; #[napi(namespace = "cursor")] pub struct Cursor(pub(super) RustCursor); @@ -57,9 +57,9 @@ impl Cursor { self.0.node().to_js(&env) } - #[napi(getter, ts_return_type = "kinds.FieldName", catch_unwind)] - pub fn node_name(&self) -> Option { - self.0.node_name() + #[napi(getter, ts_return_type = "kinds.NodeLabel", catch_unwind)] + pub fn label(&self) -> Option { + self.0.label() } #[napi(getter, ts_return_type = "text_index.TextIndex", catch_unwind)] diff --git a/crates/codegen/parser/runtime/src/napi_interface/mod.rs b/crates/codegen/parser/runtime/src/napi_interface/mod.rs index c36e1d7ac3..2a494b9869 100644 --- a/crates/codegen/parser/runtime/src/napi_interface/mod.rs +++ b/crates/codegen/parser/runtime/src/napi_interface/mod.rs @@ -7,7 +7,7 @@ pub mod query; pub mod text_index; type RustCursor = crate::cursor::Cursor; -type RustNamedNode = crate::cst::NamedNode; +type RustLabeledNode = crate::cst::LabeledNode; type RustNode = crate::cst::Node; type RustParseError = crate::parse_error::ParseError; type RustParseOutput = crate::parse_output::ParseOutput; @@ -21,4 +21,4 @@ type RustTokenNode = crate::cst::TokenNode; type RuleKind = crate::kinds::RuleKind; type TokenKind = crate::kinds::TokenKind; -type FieldName = crate::kinds::FieldName; +type NodeLabel = crate::kinds::NodeLabel; diff --git a/crates/codegen/parser/runtime/src/napi_interface/templates/ast_selectors.rs.jinja2 b/crates/codegen/parser/runtime/src/napi_interface/templates/ast_selectors.rs.jinja2 index 9903e787b5..68c809f870 100644 --- a/crates/codegen/parser/runtime/src/napi_interface/templates/ast_selectors.rs.jinja2 +++ b/crates/codegen/parser/runtime/src/napi_interface/templates/ast_selectors.rs.jinja2 @@ -6,7 +6,7 @@ use napi::{Env, JsObject}; use napi_derive::napi; use crate::napi_interface::cst::{RuleNode, ToJS}; -use crate::napi_interface::{RuleKind, RustNamedNode, RustNode, RustRuleNode, TokenKind}; +use crate::napi_interface::{RuleKind, RustLabeledNode, RustNode, RustRuleNode, TokenKind}; // // Sequences: @@ -275,16 +275,16 @@ impl Selector { fn try_select(&mut self, filter: impl FnOnce(&RustNode) -> bool) -> Result> { while let Some(child) = self.node.children.get(self.index) { match child { - RustNamedNode { - name: _, + RustLabeledNode { + label: _, node: RustNode::Rule(rule), } if rule.kind.is_trivia() => { // skip trivia, since it's not part of the AST self.index += 1; continue; } - RustNamedNode { - name: _, + RustLabeledNode { + label: _, node: RustNode::Token(token), } if matches!(token.kind, TokenKind::SKIPPED) => { return Error::SkippedToken(self.index).into(); diff --git a/crates/codegen/parser/runtime/src/parser_support/parser_function.rs b/crates/codegen/parser/runtime/src/parser_support/parser_function.rs index bd72bf5428..0cbb8ce679 100644 --- a/crates/codegen/parser/runtime/src/parser_support/parser_function.rs +++ b/crates/codegen/parser/runtime/src/parser_support/parser_function.rs @@ -1,6 +1,6 @@ use std::rc::Rc; -use crate::cst::{self, NamedNode}; +use crate::cst::{self, LabeledNode}; use crate::kinds::TokenKind; use crate::lexer::Lexer; use crate::parse_error::ParseError; @@ -84,7 +84,7 @@ where }; let topmost_rule = match &nodes[..] { - [NamedNode { node: cst::Node::Rule(rule), ..} ] => Rc::clone(rule), + [LabeledNode { node: cst::Node::Rule(rule), ..} ] => Rc::clone(rule), [_] => unreachable!( "(Incomplete)Match at the top level of a parser is not a Rule node" ), @@ -107,7 +107,7 @@ where let skipped_node = cst::Node::token(TokenKind::SKIPPED, input[start.utf8..].to_string()); let mut new_children = topmost_rule.children.clone(); - new_children.push(NamedNode::anonymous(skipped_node)); + new_children.push(LabeledNode::anonymous(skipped_node)); let mut errors = stream.into_errors(); errors.push(ParseError::new(start..input.into(), expected_tokens)); diff --git a/crates/codegen/parser/runtime/src/parser_support/parser_result.rs b/crates/codegen/parser/runtime/src/parser_support/parser_result.rs index b641d35172..e74efbea5b 100644 --- a/crates/codegen/parser/runtime/src/parser_support/parser_result.rs +++ b/crates/codegen/parser/runtime/src/parser_support/parser_result.rs @@ -1,7 +1,7 @@ use std::ops::ControlFlow; -use crate::cst::{self, NamedNode}; -use crate::kinds::{FieldName, RuleKind, TokenKind}; +use crate::cst::{self, LabeledNode}; +use crate::kinds::{NodeLabel, RuleKind, TokenKind}; use crate::text_index::TextIndex; #[derive(PartialEq, Eq, Clone, Debug)] @@ -22,7 +22,7 @@ impl Default for ParserResult { } impl ParserResult { - pub fn r#match(nodes: Vec, expected_tokens: Vec) -> Self { + pub fn r#match(nodes: Vec, expected_tokens: Vec) -> Self { ParserResult::Match(Match::new(nodes, expected_tokens)) } @@ -30,7 +30,7 @@ impl ParserResult { ParserResult::PrattOperatorMatch(PrattOperatorMatch::new(elements)) } - pub fn incomplete_match(nodes: Vec, expected_tokens: Vec) -> Self { + pub fn incomplete_match(nodes: Vec, expected_tokens: Vec) -> Self { ParserResult::IncompleteMatch(IncompleteMatch::new(nodes, expected_tokens)) } @@ -47,21 +47,21 @@ impl ParserResult { pub fn with_kind(self, new_kind: RuleKind) -> ParserResult { match self { ParserResult::Match(r#match) => ParserResult::r#match( - vec![NamedNode::anonymous(cst::Node::rule( + vec![LabeledNode::anonymous(cst::Node::rule( new_kind, r#match.nodes, ))], r#match.expected_tokens, ), ParserResult::IncompleteMatch(incomplete_match) => ParserResult::incomplete_match( - vec![NamedNode::anonymous(cst::Node::rule( + vec![LabeledNode::anonymous(cst::Node::rule( new_kind, incomplete_match.nodes, ))], incomplete_match.expected_tokens, ), ParserResult::SkippedUntil(skipped) => ParserResult::SkippedUntil(SkippedUntil { - nodes: vec![NamedNode::anonymous(cst::Node::rule( + nodes: vec![LabeledNode::anonymous(cst::Node::rule( new_kind, skipped.nodes, ))], @@ -75,21 +75,21 @@ impl ParserResult { } #[must_use] - pub fn with_name(mut self, name: FieldName) -> ParserResult { - if let Some(NamedNode { - name: prev_name, .. + pub fn with_label(mut self, label: NodeLabel) -> ParserResult { + if let Some(LabeledNode { + label: prev_label, .. }) = self.significant_node_mut() { - *prev_name = Some(name); + *prev_label = Some(label); } self } /// Returns a significant (non-trivia) node if there is exactly one. - pub(crate) fn significant_node_mut(&mut self) -> Option<&mut cst::NamedNode> { - fn is_significant(named: &cst::NamedNode) -> bool { - match &named.node { + pub(crate) fn significant_node_mut(&mut self) -> Option<&mut cst::LabeledNode> { + fn is_significant(labeled: &cst::LabeledNode) -> bool { + match &labeled.node { cst::Node::Rule(rule) => !rule.kind.is_trivia(), // FIXME: Some tokens are in fact trivia cst::Node::Token(_) => true, @@ -119,13 +119,13 @@ impl ParserResult { #[derive(PartialEq, Eq, Clone, Debug)] pub struct Match { - pub nodes: Vec, + pub nodes: Vec, /// Tokens that would have allowed for more progress. Collected for the purposes of error reporting. pub expected_tokens: Vec, } impl Match { - pub fn new(nodes: Vec, expected_tokens: Vec) -> Self { + pub fn new(nodes: Vec, expected_tokens: Vec) -> Self { Self { nodes, expected_tokens, @@ -143,34 +143,34 @@ impl Match { #[derive(PartialEq, Eq, Clone, Debug)] pub enum PrattElement { Expression { - nodes: Vec, + nodes: Vec, }, Prefix { kind: RuleKind, - nodes: Vec, + nodes: Vec, right: u8, }, Binary { kind: RuleKind, - nodes: Vec, + nodes: Vec, left: u8, right: u8, }, Postfix { kind: RuleKind, - nodes: Vec, + nodes: Vec, left: u8, }, } impl PrattElement { - pub fn into_nodes(self) -> Vec { + pub fn into_nodes(self) -> Vec { match self { Self::Expression { nodes } => nodes, Self::Binary { kind, nodes, .. } | Self::Prefix { kind, nodes, .. } | Self::Postfix { kind, nodes, .. } => { - vec![NamedNode::anonymous(cst::Node::rule(kind, nodes))] + vec![LabeledNode::anonymous(cst::Node::rule(kind, nodes))] } } } @@ -189,13 +189,13 @@ impl PrattOperatorMatch { #[derive(PartialEq, Eq, Clone, Debug)] pub struct IncompleteMatch { - pub nodes: Vec, + pub nodes: Vec, /// Tokens that would have allowed for more progress. Collected for the purposes of error reporting. pub expected_tokens: Vec, } impl IncompleteMatch { - pub fn new(nodes: Vec, expected_tokens: Vec) -> Self { + pub fn new(nodes: Vec, expected_tokens: Vec) -> Self { Self { nodes, expected_tokens, @@ -217,7 +217,7 @@ impl NoMatch { #[derive(PartialEq, Eq, Clone, Debug)] pub struct SkippedUntil { - pub nodes: Vec, + pub nodes: Vec, /// Skipped text following the last node pub skipped: String, /// At which token was the stream pointing at when we bailed diff --git a/crates/codegen/parser/runtime/src/parser_support/precedence_helper.rs b/crates/codegen/parser/runtime/src/parser_support/precedence_helper.rs index b65144e174..181f843dee 100644 --- a/crates/codegen/parser/runtime/src/parser_support/precedence_helper.rs +++ b/crates/codegen/parser/runtime/src/parser_support/precedence_helper.rs @@ -1,5 +1,5 @@ -use crate::cst::{self, NamedNode}; -use crate::kinds::{FieldName, RuleKind}; +use crate::cst::{self, LabeledNode}; +use crate::kinds::{NodeLabel, RuleKind}; use crate::parser_support::parser_result::PrattElement::{ self, Binary, Expression, Postfix, Prefix, }; @@ -150,21 +150,21 @@ impl PrecedenceHelper { let make_expression = |left: Option, kind: RuleKind, - nodes: Vec, + nodes: Vec, right: Option| { assert!(left.is_some() || right.is_some()); - let left_name = right + let left_label = right .as_ref() - .map_or(FieldName::Operand, |_| FieldName::LeftOperand); - let right_name = left + .map_or(NodeLabel::Operand, |_| NodeLabel::LeftOperand); + let right_label = left .as_ref() - .map_or(FieldName::Operand, |_| FieldName::RightOperand); + .map_or(NodeLabel::Operand, |_| NodeLabel::RightOperand); let left_nodes = match left { Some(Expression { nodes }) => { - vec![NamedNode { - name: Some(left_name), + vec![LabeledNode { + label: Some(left_label), node: cst::Node::rule(child_kind, nodes), }] } @@ -174,8 +174,8 @@ impl PrecedenceHelper { let right_nodes = match right { Some(Expression { nodes }) => { - vec![NamedNode { - name: Some(right_name), + vec![LabeledNode { + label: Some(right_label), node: cst::Node::rule(child_kind, nodes), }] } @@ -186,8 +186,8 @@ impl PrecedenceHelper { let children = [left_nodes, nodes, right_nodes].concat(); Expression { - nodes: vec![NamedNode { - name: Some(FieldName::Variant), + nodes: vec![LabeledNode { + label: Some(NodeLabel::Variant), node: cst::Node::rule(kind, children), }], } diff --git a/crates/codegen/parser/runtime/src/parser_support/recovery.rs b/crates/codegen/parser/runtime/src/parser_support/recovery.rs index 3c2cca5382..94b52036c9 100644 --- a/crates/codegen/parser/runtime/src/parser_support/recovery.rs +++ b/crates/codegen/parser/runtime/src/parser_support/recovery.rs @@ -23,7 +23,7 @@ impl RecoverFromNoMatch { fn opt_parse( input: &mut ParserContext<'_>, parse: impl Fn(&mut ParserContext<'_>) -> ParserResult, -) -> Vec { +) -> Vec { let start = input.position(); if let ParserResult::Match(r#match) = parse(input) { r#match.nodes diff --git a/crates/codegen/parser/runtime/src/parser_support/separated_helper.rs b/crates/codegen/parser/runtime/src/parser_support/separated_helper.rs index a9623a96c3..3982112a4e 100644 --- a/crates/codegen/parser/runtime/src/parser_support/separated_helper.rs +++ b/crates/codegen/parser/runtime/src/parser_support/separated_helper.rs @@ -1,5 +1,5 @@ -use crate::cst::{self, NamedNode}; -use crate::kinds::{FieldName, IsLexicalContext, TokenKind}; +use crate::cst::{self, LabeledNode}; +use crate::kinds::{IsLexicalContext, NodeLabel, TokenKind}; use crate::lexer::Lexer; use crate::parse_error::ParseError; use crate::parser_support::parser_result::{ParserResult, SkippedUntil}; @@ -15,7 +15,7 @@ impl SeparatedHelper { lexer: &L, body_parser: impl Fn(&mut ParserContext<'_>) -> ParserResult, separator: TokenKind, - separator_field_name: FieldName, + separator_label: NodeLabel, ) -> ParserResult { let mut accum = vec![]; loop { @@ -27,7 +27,7 @@ impl SeparatedHelper { Some(scanned) if scanned.accepted_as(separator) => { match lexer .parse_token_with_trivia::(input, separator) - .with_name(separator_field_name) + .with_label(separator_label) { ParserResult::Match(r#match) => { accum.extend(r#match.nodes); @@ -53,7 +53,7 @@ impl SeparatedHelper { match skip_until_with_nested_delims::<_, LexCtx>(input, lexer, separator) { // A separator was found, so we can recover the incomplete match Some((found, skipped_range)) if found == separator => { - accum.push(NamedNode::anonymous(cst::Node::token( + accum.push(LabeledNode::anonymous(cst::Node::token( TokenKind::SKIPPED, input.content(skipped_range.utf8()), ))); diff --git a/crates/codegen/parser/runtime/src/parser_support/sequence_helper.rs b/crates/codegen/parser/runtime/src/parser_support/sequence_helper.rs index 68c233773c..003d265eac 100644 --- a/crates/codegen/parser/runtime/src/parser_support/sequence_helper.rs +++ b/crates/codegen/parser/runtime/src/parser_support/sequence_helper.rs @@ -1,7 +1,7 @@ use std::ops::ControlFlow; -use crate::cst::{self, NamedNode}; -use crate::kinds::{FieldName, TokenKind}; +use crate::cst::{self, LabeledNode}; +use crate::kinds::{NodeLabel, TokenKind}; use crate::parser_support::parser_result::{Match, ParserResult, PrattElement, SkippedUntil}; /// Keeps accumulating parses sequentially until it hits an incomplete or no match. @@ -135,7 +135,7 @@ impl SequenceHelper { debug_assert!(is_single_token_with_trivia); debug_assert_eq!(next_token, Some(running.found)); - running.nodes.push(NamedNode::anonymous(cst::Node::token( + running.nodes.push(LabeledNode::anonymous(cst::Node::token( TokenKind::SKIPPED, std::mem::take(&mut running.skipped), ))); @@ -184,13 +184,13 @@ impl SequenceHelper { /// Aggregates a parse result into the sequence. If we cannot make progress, returns the accumulated match. /// - /// Shorthand for `self.elem(value.with_name(name))`. - pub fn elem_named( + /// Shorthand for `self.elem(value.with_label(label))`. + pub fn elem_labeled( &mut self, - name: FieldName, + label: NodeLabel, value: ParserResult, ) -> ControlFlow { - self.elem(value.with_name(name)) + self.elem(value.with_label(label)) } /// Finishes the sequence parse, returning the accumulated match. diff --git a/crates/codegen/parser/runtime/src/query/engine.rs b/crates/codegen/parser/runtime/src/query/engine.rs index 4e5bca3d48..cb41f382d4 100644 --- a/crates/codegen/parser/runtime/src/query/engine.rs +++ b/crates/codegen/parser/runtime/src/query/engine.rs @@ -31,23 +31,23 @@ impl Cursor { NodeSelector::Anonymous => true, NodeSelector::Kind { kind } => Kind::Rule(rule.kind) == *kind, NodeSelector::Text { .. } => false, - NodeSelector::FieldName { field_name } => Some(*field_name) == self.node_name(), - NodeSelector::FieldNameAndKind { field_name, kind } => { - Some(*field_name) == self.node_name() && Kind::Rule(rule.kind) == *kind + NodeSelector::Label { label } => Some(*label) == self.label(), + NodeSelector::LabelAndKind { label, kind } => { + Some(*label) == self.label() && Kind::Rule(rule.kind) == *kind } - NodeSelector::FieldNameAndText { .. } => false, + NodeSelector::LabelAndText { .. } => false, }, cst::Node::Token(token) => match node_selector { NodeSelector::Anonymous => true, NodeSelector::Kind { kind } => Kind::Token(token.kind) == *kind, NodeSelector::Text { text } => token.text == *text, - NodeSelector::FieldName { field_name } => Some(*field_name) == self.node_name(), - NodeSelector::FieldNameAndKind { field_name, kind } => { - Some(*field_name) == self.node_name() && Kind::Token(token.kind) == *kind + NodeSelector::Label { label } => Some(*label) == self.label(), + NodeSelector::LabelAndKind { label, kind } => { + Some(*label) == self.label() && Kind::Token(token.kind) == *kind } - NodeSelector::FieldNameAndText { field_name, text } => { - Some(*field_name) == self.node_name() && token.text == *text + NodeSelector::LabelAndText { label, text } => { + Some(*label) == self.label() && token.text == *text } }, } diff --git a/crates/codegen/parser/runtime/src/query/model.rs b/crates/codegen/parser/runtime/src/query/model.rs index e78ba1805e..4153cd58ab 100644 --- a/crates/codegen/parser/runtime/src/query/model.rs +++ b/crates/codegen/parser/runtime/src/query/model.rs @@ -2,7 +2,7 @@ use std::fmt; use std::rc::Rc; // This crate is copied to another crate, so all imports should be relative -use super::super::kinds::{FieldName, RuleKind, TokenKind}; +use super::super::kinds::{NodeLabel, RuleKind, TokenKind}; #[derive(Clone)] pub struct Query(pub(super) Matcher); @@ -106,9 +106,9 @@ pub(super) enum NodeSelector { Anonymous, Kind { kind: Kind }, Text { text: String }, - FieldName { field_name: FieldName }, - FieldNameAndKind { field_name: FieldName, kind: Kind }, - FieldNameAndText { field_name: FieldName, text: String }, + Label { label: NodeLabel }, + LabelAndKind { label: NodeLabel, kind: Kind }, + LabelAndText { label: NodeLabel, text: String }, } impl fmt::Display for NodeSelector { @@ -134,12 +134,12 @@ impl fmt::Display for NodeSelector { Self::Anonymous => write!(f, "_"), Self::Kind { kind } => kind.fmt(f), Self::Text { text } => write!(f, "\"{}\"", escape_string(text)), - Self::FieldName { field_name } => field_name.fmt(f), - Self::FieldNameAndKind { field_name, kind } => { - write!(f, "{field_name}; {kind}") + Self::Label { label } => label.fmt(f), + Self::LabelAndKind { label, kind } => { + write!(f, "{label}; {kind}") } - Self::FieldNameAndText { field_name, text } => { - write!(f, "{field_name}: \"{}\"", escape_string(text)) + Self::LabelAndText { label, text } => { + write!(f, "{label}: \"{}\"", escape_string(text)) } } } diff --git a/crates/codegen/parser/runtime/src/query/parser.rs b/crates/codegen/parser/runtime/src/query/parser.rs index 66823d20b4..47e8fe40e8 100644 --- a/crates/codegen/parser/runtime/src/query/parser.rs +++ b/crates/codegen/parser/runtime/src/query/parser.rs @@ -10,7 +10,7 @@ use nom::sequence::{delimited, pair, preceded, terminated}; use nom::{Finish, IResult, Parser}; // This crate is copied to another crate, so all imports should be relative -use super::super::kinds::{FieldName, RuleKind, TokenKind}; +use super::super::kinds::{NodeLabel, RuleKind, TokenKind}; use super::model::{ AlternativesMatcher, BindingMatcher, Kind, Matcher, NodeMatcher, NodeSelector, OneOrMoreMatcher, OptionalMatcher, SequenceMatcher, @@ -76,25 +76,19 @@ fn parse_node_selector(input: &str) -> IResult<&str, NodeSelector, VerboseError< Text(String), } - opt(field_name_token) + opt(label_token) .and(alt(( token('_').map(|_| Tail::Anonymous), kind_token.map(Tail::Kind), text_token.map(Tail::Text), ))) - .map(|(field_name, tail)| match (field_name, tail) { + .map(|(label, tail)| match (label, tail) { (None, Tail::Anonymous) => NodeSelector::Anonymous, (None, Tail::Kind(kind)) => NodeSelector::Kind { kind }, (None, Tail::Text(string)) => NodeSelector::Text { text: string }, - (Some(field), Tail::Anonymous) => NodeSelector::FieldName { field_name: field }, - (Some(field), Tail::Kind(kind)) => NodeSelector::FieldNameAndKind { - field_name: field, - kind, - }, - (Some(field), Tail::Text(string)) => NodeSelector::FieldNameAndText { - field_name: field, - text: string, - }, + (Some(label), Tail::Anonymous) => NodeSelector::Label { label }, + (Some(label), Tail::Kind(kind)) => NodeSelector::LabelAndKind { label, kind }, + (Some(label), Tail::Text(text)) => NodeSelector::LabelAndText { label, text }, }) .parse(input) } @@ -189,9 +183,9 @@ fn kind_token(i: &str) -> IResult<&str, Kind, VerboseError<&str>> { .parse(i) } -fn field_name_token(i: &str) -> IResult<&str, FieldName, VerboseError<&str>> { +fn label_token(i: &str) -> IResult<&str, NodeLabel, VerboseError<&str>> { terminated(raw_identifier, token(':')) - .map(|id| FieldName::try_from(id.as_str()).unwrap()) + .map(|id| NodeLabel::try_from(id.as_str()).unwrap()) .parse(i) } diff --git a/crates/codegen/parser/runtime/src/templates/kinds.rs.jinja2 b/crates/codegen/parser/runtime/src/templates/kinds.rs.jinja2 index c9aa935141..d635221808 100644 --- a/crates/codegen/parser/runtime/src/templates/kinds.rs.jinja2 +++ b/crates/codegen/parser/runtime/src/templates/kinds.rs.jinja2 @@ -49,9 +49,9 @@ impl RuleKind { #[strum(serialize_all = "snake_case")] #[cfg_attr(feature = "slang_napi_interfaces", /* derives `Clone` and `Copy` */ napi(string_enum, namespace = "kinds"))] #[cfg_attr(not(feature = "slang_napi_interfaces"), derive(Clone, Copy))] -pub enum FieldName { - // Built-in fields - {# _SLANG_INTERNAL_RESERVED_NODE_FIELD_NAMES_ (keep in sync) #} +pub enum NodeLabel { + // Built-in labels + {# _SLANG_INTERNAL_RESERVED_NODE_LABELS_ (keep in sync) #} Item, Variant, Separator, @@ -59,7 +59,7 @@ pub enum FieldName { LeftOperand, RightOperand, // Generated - {% for variant in generator.field_names -%} + {% for variant in generator.labels -%} {{ variant | pascal_case }}, {%- endfor -%} } diff --git a/crates/codegen/parser/runtime/src/templates/language.rs.jinja2 b/crates/codegen/parser/runtime/src/templates/language.rs.jinja2 index 601a0603cc..f597691060 100644 --- a/crates/codegen/parser/runtime/src/templates/language.rs.jinja2 +++ b/crates/codegen/parser/runtime/src/templates/language.rs.jinja2 @@ -14,7 +14,7 @@ use napi_derive::napi; use crate::cst; use crate::kinds::{ - FieldName, IsLexicalContext, LexicalContext, LexicalContextType, RuleKind, TokenKind, + NodeLabel, IsLexicalContext, LexicalContext, LexicalContextType, RuleKind, TokenKind, }; use crate::lexer::{KeywordScan, Lexer, ScannedToken}; #[cfg(feature = "slang_napi_interfaces")] diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/cst.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/cst.rs index 517ee94e51..9b4281aa40 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/cst.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/cst.rs @@ -5,23 +5,23 @@ use std::rc::Rc; use serde::Serialize; use crate::cursor::Cursor; -use crate::kinds::{FieldName, RuleKind, TokenKind}; +use crate::kinds::{NodeLabel, RuleKind, TokenKind}; use crate::text_index::TextIndex; #[derive(Clone, Debug, PartialEq, Eq, Serialize)] -pub struct NamedNode { - pub name: Option, +pub struct LabeledNode { + pub label: Option, pub node: Node, } -impl NamedNode { - /// Creates an anonymous (nameless) node. +impl LabeledNode { + /// Creates an anonymous node (without a label). pub fn anonymous(node: Node) -> Self { - Self { name: None, node } + Self { label: None, node } } } -impl std::ops::Deref for NamedNode { +impl std::ops::Deref for LabeledNode { type Target = Node; fn deref(&self) -> &Self::Target { @@ -34,7 +34,7 @@ pub struct RuleNode { pub kind: RuleKind, pub text_len: TextIndex, #[serde(skip_serializing_if = "Vec::is_empty")] - pub children: Vec, + pub children: Vec, } #[derive(Clone, Debug, PartialEq, Eq, Serialize)] @@ -50,7 +50,7 @@ pub enum Node { } impl Node { - pub fn rule(kind: RuleKind, children: Vec) -> Self { + pub fn rule(kind: RuleKind, children: Vec) -> Self { let text_len = children.iter().map(|node| node.text_len()).sum(); Self::Rule(Rc::new(RuleNode { @@ -72,7 +72,7 @@ impl Node { } /// Returns a slice of the children (not all descendants) of this node. - pub fn children(&self) -> &[NamedNode] { + pub fn children(&self) -> &[LabeledNode] { match self { Self::Rule(node) => &node.children, Self::Token(_) => &[], diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/cursor.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/cursor.rs index dba7bb2924..ddfe224e76 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/cursor.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/cursor.rs @@ -4,8 +4,8 @@ use std::rc::Rc; -use crate::cst::{NamedNode, Node, RuleNode}; -use crate::kinds::{FieldName, RuleKind, TokenKind}; +use crate::cst::{LabeledNode, Node, RuleNode}; +use crate::kinds::{NodeLabel, RuleKind, TokenKind}; use crate::text_index::{TextIndex, TextRange}; /// A node in the ancestor path of a [`Cursor`]. @@ -126,11 +126,11 @@ impl Cursor { self.node.clone() } - pub fn node_name(&self) -> Option { + pub fn label(&self) -> Option { self.parent.as_ref().and_then(|parent| { let this = &parent.rule_node.children[self.child_number]; - this.name + this.label }) } @@ -415,28 +415,28 @@ impl Cursor { } } -/// A [`Cursor`] that also keeps track of the names of the nodes it visits. -pub struct CursorWithNames { +/// A [`Cursor`] that also keeps track of the labels of the nodes it visits. +pub struct CursorWithLabels { cursor: Cursor, } -impl CursorWithNames { - pub fn without_names(self) -> Cursor { +impl CursorWithLabels { + pub fn without_labels(self) -> Cursor { self.cursor } } -impl Iterator for CursorWithNames { - type Item = NamedNode; +impl Iterator for CursorWithLabels { + type Item = LabeledNode; fn next(&mut self) -> Option { - let name = self.cursor.node_name(); + let label = self.cursor.label(); - self.cursor.next().map(|node| NamedNode { name, node }) + self.cursor.next().map(|node| LabeledNode { label, node }) } } -impl std::ops::Deref for CursorWithNames { +impl std::ops::Deref for CursorWithLabels { type Target = Cursor; fn deref(&self) -> &Self::Target { @@ -444,21 +444,21 @@ impl std::ops::Deref for CursorWithNames { } } -impl std::ops::DerefMut for CursorWithNames { +impl std::ops::DerefMut for CursorWithLabels { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.cursor } } impl Cursor { - /// Returns a [`CursorWithNames`] that wraps this cursor. - pub fn with_names(self) -> CursorWithNames { - CursorWithNames::from(self) + /// Returns a [`CursorWithLabels`] that wraps this cursor. + pub fn with_labels(self) -> CursorWithLabels { + CursorWithLabels::from(self) } } -impl From for CursorWithNames { +impl From for CursorWithLabels { fn from(cursor: Cursor) -> Self { - CursorWithNames { cursor } + CursorWithLabels { cursor } } } diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/kinds.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/kinds.rs index 40dcfad4ab..ec7d7e15ef 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/kinds.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/kinds.rs @@ -260,8 +260,8 @@ impl RuleKind { #[strum(serialize_all = "snake_case")] #[cfg_attr(feature = "slang_napi_interfaces", /* derives `Clone` and `Copy` */ napi(string_enum, namespace = "kinds"))] #[cfg_attr(not(feature = "slang_napi_interfaces"), derive(Clone, Copy))] -pub enum FieldName { - // Built-in fields +pub enum NodeLabel { + // Built-in labels Item, Variant, Separator, diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/language.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/language.rs index a115a3726d..4d53e18c4f 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/language.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/language.rs @@ -16,7 +16,7 @@ use semver::Version; use crate::cst; use crate::kinds::{ - FieldName, IsLexicalContext, LexicalContext, LexicalContextType, RuleKind, TokenKind, + IsLexicalContext, LexicalContext, LexicalContextType, NodeLabel, RuleKind, TokenKind, }; use crate::lexer::{KeywordScan, Lexer, ScannedToken}; #[cfg(feature = "slang_napi_interfaces")] @@ -204,15 +204,15 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn abi_coder_pragma(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::AbicoderKeyword, + seq.elem_labeled( + NodeLabel::AbicoderKeyword, self.parse_token_with_trivia::( input, TokenKind::AbicoderKeyword, ), )?; - seq.elem_named( - FieldName::Version, + seq.elem_labeled( + NodeLabel::Version, self.parse_token_with_trivia::( input, TokenKind::Identifier, @@ -230,12 +230,12 @@ impl Language { return result; }; match &r#match.nodes[..] { - [cst::NamedNode { - name: _, + [cst::LabeledNode { + label: _, node: cst::Node::Rule(node), }] if node.kind == RuleKind::Expression => match &node.children[..] { - [inner @ cst::NamedNode { - name: _, + [inner @ cst::LabeledNode { + label: _, node: cst::Node::Rule(rule), }] if rule.kind == RuleKind::AdditiveExpression => { ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) @@ -249,15 +249,15 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn address_type(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::AddressKeyword, + seq.elem_labeled( + NodeLabel::AddressKeyword, self.parse_token_with_trivia::( input, TokenKind::AddressKeyword, ), )?; - seq.elem_named( - FieldName::PayableKeyword, + seq.elem_labeled( + NodeLabel::PayableKeyword, OptionalHelper::transform( self.parse_token_with_trivia::( input, @@ -277,12 +277,12 @@ impl Language { return result; }; match &r#match.nodes[..] { - [cst::NamedNode { - name: _, + [cst::LabeledNode { + label: _, node: cst::Node::Rule(node), }] if node.kind == RuleKind::Expression => match &node.children[..] { - [inner @ cst::NamedNode { - name: _, + [inner @ cst::LabeledNode { + label: _, node: cst::Node::Rule(rule), }] if rule.kind == RuleKind::AndExpression => { ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) @@ -302,7 +302,7 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::ArgumentsDeclaration) } @@ -311,8 +311,8 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBracket); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenBracket, + seq.elem_labeled( + NodeLabel::OpenBracket, self.parse_token_with_trivia::( input, TokenKind::OpenBracket, @@ -320,7 +320,7 @@ impl Language { )?; seq.elem( self.array_values(input) - .with_name(FieldName::Items) + .with_label(NodeLabel::Items) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -328,8 +328,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseBracket, + seq.elem_labeled( + NodeLabel::CloseBracket, self.parse_token_with_trivia::( input, TokenKind::CloseBracket, @@ -347,12 +347,12 @@ impl Language { return result; }; match &r#match.nodes[..] { - [cst::NamedNode { - name: _, + [cst::LabeledNode { + label: _, node: cst::Node::Rule(node), }] if node.kind == RuleKind::TypeName => match &node.children[..] { - [inner @ cst::NamedNode { - name: _, + [inner @ cst::LabeledNode { + label: _, node: cst::Node::Rule(rule), }] if rule.kind == RuleKind::ArrayTypeName => { ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) @@ -368,9 +368,9 @@ impl Language { SeparatedHelper::run::<_, LexicalContextType::Default>( input, self, - |input| self.expression(input).with_name(FieldName::Item), + |input| self.expression(input).with_label(NodeLabel::Item), TokenKind::Comma, - FieldName::Separator, + NodeLabel::Separator, ) .with_kind(RuleKind::ArrayValues) } @@ -380,9 +380,9 @@ impl Language { SeparatedHelper::run::<_, LexicalContextType::Default>( input, self, - |input| self.string_literal(input).with_name(FieldName::Item), + |input| self.string_literal(input).with_label(NodeLabel::Item), TokenKind::Comma, - FieldName::Separator, + NodeLabel::Separator, ) .with_kind(RuleKind::AssemblyFlags) } @@ -392,8 +392,8 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenParen, + seq.elem_labeled( + NodeLabel::OpenParen, self.parse_token_with_trivia::( input, TokenKind::OpenParen, @@ -401,7 +401,7 @@ impl Language { )?; seq.elem( self.assembly_flags(input) - .with_name(FieldName::Flags) + .with_label(NodeLabel::Flags) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -409,8 +409,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseParen, + seq.elem_labeled( + NodeLabel::CloseParen, self.parse_token_with_trivia::( input, TokenKind::CloseParen, @@ -424,22 +424,22 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn assembly_statement(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::AssemblyKeyword, + seq.elem_labeled( + NodeLabel::AssemblyKeyword, self.parse_token_with_trivia::( input, TokenKind::AssemblyKeyword, ), )?; - seq.elem_named( - FieldName::Label, + seq.elem_labeled( + NodeLabel::Label, OptionalHelper::transform(self.string_literal(input)), )?; - seq.elem_named( - FieldName::Flags, + seq.elem_labeled( + NodeLabel::Flags, OptionalHelper::transform(self.assembly_flags_declaration(input)), )?; - seq.elem_named(FieldName::Body, self.yul_block(input))?; + seq.elem_labeled(NodeLabel::Body, self.yul_block(input))?; seq.finish() }) .with_kind(RuleKind::AssemblyStatement) @@ -452,12 +452,12 @@ impl Language { return result; }; match &r#match.nodes[..] { - [cst::NamedNode { - name: _, + [cst::LabeledNode { + label: _, node: cst::Node::Rule(node), }] if node.kind == RuleKind::Expression => match &node.children[..] { - [inner @ cst::NamedNode { - name: _, + [inner @ cst::LabeledNode { + label: _, node: cst::Node::Rule(rule), }] if rule.kind == RuleKind::AssignmentExpression => { ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) @@ -475,12 +475,12 @@ impl Language { return result; }; match &r#match.nodes[..] { - [cst::NamedNode { - name: _, + [cst::LabeledNode { + label: _, node: cst::Node::Rule(node), }] if node.kind == RuleKind::Expression => match &node.children[..] { - [inner @ cst::NamedNode { - name: _, + [inner @ cst::LabeledNode { + label: _, node: cst::Node::Rule(rule), }] if rule.kind == RuleKind::BitwiseAndExpression => { ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) @@ -498,12 +498,12 @@ impl Language { return result; }; match &r#match.nodes[..] { - [cst::NamedNode { - name: _, + [cst::LabeledNode { + label: _, node: cst::Node::Rule(node), }] if node.kind == RuleKind::Expression => match &node.children[..] { - [inner @ cst::NamedNode { - name: _, + [inner @ cst::LabeledNode { + label: _, node: cst::Node::Rule(rule), }] if rule.kind == RuleKind::BitwiseOrExpression => { ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) @@ -521,12 +521,12 @@ impl Language { return result; }; match &r#match.nodes[..] { - [cst::NamedNode { - name: _, + [cst::LabeledNode { + label: _, node: cst::Node::Rule(node), }] if node.kind == RuleKind::Expression => match &node.children[..] { - [inner @ cst::NamedNode { - name: _, + [inner @ cst::LabeledNode { + label: _, node: cst::Node::Rule(rule), }] if rule.kind == RuleKind::BitwiseXorExpression => { ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) @@ -542,8 +542,8 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenBrace, + seq.elem_labeled( + NodeLabel::OpenBrace, self.parse_token_with_trivia::( input, TokenKind::OpenBrace, @@ -551,7 +551,7 @@ impl Language { )?; seq.elem( OptionalHelper::transform(self.statements(input)) - .with_name(FieldName::Statements) + .with_label(NodeLabel::Statements) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -559,8 +559,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseBrace, + seq.elem_labeled( + NodeLabel::CloseBrace, self.parse_token_with_trivia::( input, TokenKind::CloseBrace, @@ -579,7 +579,7 @@ impl Language { input, TokenKind::BreakKeyword, ) - .with_name(FieldName::BreakKeyword) + .with_label(NodeLabel::BreakKeyword) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -587,8 +587,8 @@ impl Language { RecoverFromNoMatch::No, ), )?; - seq.elem_named( - FieldName::Semicolon, + seq.elem_labeled( + NodeLabel::Semicolon, self.parse_token_with_trivia::( input, TokenKind::Semicolon, @@ -603,18 +603,18 @@ impl Language { fn catch_clause(&self, input: &mut ParserContext<'_>) -> ParserResult { if self.version_is_at_least_0_6_0 { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::CatchKeyword, + seq.elem_labeled( + NodeLabel::CatchKeyword, self.parse_token_with_trivia::( input, TokenKind::CatchKeyword, ), )?; - seq.elem_named( - FieldName::Error, + seq.elem_labeled( + NodeLabel::Error, OptionalHelper::transform(self.catch_clause_error(input)), )?; - seq.elem_named(FieldName::Body, self.block(input))?; + seq.elem_labeled(NodeLabel::Body, self.block(input))?; seq.finish() }) } else { @@ -627,8 +627,8 @@ impl Language { fn catch_clause_error(&self, input: &mut ParserContext<'_>) -> ParserResult { if self.version_is_at_least_0_6_0 { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::Name, + seq.elem_labeled( + NodeLabel::Name, OptionalHelper::transform( self.parse_token_with_trivia::( input, @@ -636,7 +636,7 @@ impl Language { ), ), )?; - seq.elem_named(FieldName::Parameters, self.parameters_declaration(input))?; + seq.elem_labeled(NodeLabel::Parameters, self.parameters_declaration(input))?; seq.finish() }) } else { @@ -649,7 +649,7 @@ impl Language { fn catch_clauses(&self, input: &mut ParserContext<'_>) -> ParserResult { if self.version_is_at_least_0_6_0 { OneOrMoreHelper::run(input, |input| { - self.catch_clause(input).with_name(FieldName::Item) + self.catch_clause(input).with_label(NodeLabel::Item) }) } else { ParserResult::disabled() @@ -664,12 +664,12 @@ impl Language { return result; }; match &r#match.nodes[..] { - [cst::NamedNode { - name: _, + [cst::LabeledNode { + label: _, node: cst::Node::Rule(node), }] if node.kind == RuleKind::Expression => match &node.children[..] { - [inner @ cst::NamedNode { - name: _, + [inner @ cst::LabeledNode { + label: _, node: cst::Node::Rule(rule), }] if rule.kind == RuleKind::ComparisonExpression => { ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) @@ -687,12 +687,12 @@ impl Language { return result; }; match &r#match.nodes[..] { - [cst::NamedNode { - name: _, + [cst::LabeledNode { + label: _, node: cst::Node::Rule(node), }] if node.kind == RuleKind::Expression => match &node.children[..] { - [inner @ cst::NamedNode { - name: _, + [inner @ cst::LabeledNode { + label: _, node: cst::Node::Rule(rule), }] if rule.kind == RuleKind::ConditionalExpression => { ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) @@ -709,29 +709,29 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem_named(FieldName::TypeName, self.type_name(input))?; - seq.elem_named( - FieldName::ConstantKeyword, + seq.elem_labeled(NodeLabel::TypeName, self.type_name(input))?; + seq.elem_labeled( + NodeLabel::ConstantKeyword, self.parse_token_with_trivia::( input, TokenKind::ConstantKeyword, ), )?; - seq.elem_named( - FieldName::Name, + seq.elem_labeled( + NodeLabel::Name, self.parse_token_with_trivia::( input, TokenKind::Identifier, ), )?; - seq.elem_named( - FieldName::Equal, + seq.elem_labeled( + NodeLabel::Equal, self.parse_token_with_trivia::( input, TokenKind::Equal, ), )?; - seq.elem_named(FieldName::Value, self.expression(input))?; + seq.elem_labeled(NodeLabel::Value, self.expression(input))?; seq.finish() }) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( @@ -741,8 +741,8 @@ impl Language { RecoverFromNoMatch::No, ), )?; - seq.elem_named( - FieldName::Semicolon, + seq.elem_labeled( + NodeLabel::Semicolon, self.parse_token_with_trivia::( input, TokenKind::Semicolon, @@ -793,7 +793,7 @@ impl Language { } choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) } else { ParserResult::disabled() } @@ -804,7 +804,8 @@ impl Language { fn constructor_attributes(&self, input: &mut ParserContext<'_>) -> ParserResult { if self.version_is_at_least_0_4_22 { OneOrMoreHelper::run(input, |input| { - self.constructor_attribute(input).with_name(FieldName::Item) + self.constructor_attribute(input) + .with_label(NodeLabel::Item) }) } else { ParserResult::disabled() @@ -816,19 +817,19 @@ impl Language { fn constructor_definition(&self, input: &mut ParserContext<'_>) -> ParserResult { if self.version_is_at_least_0_4_22 { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::ConstructorKeyword, + seq.elem_labeled( + NodeLabel::ConstructorKeyword, self.parse_token_with_trivia::( input, TokenKind::ConstructorKeyword, ), )?; - seq.elem_named(FieldName::Parameters, self.parameters_declaration(input))?; - seq.elem_named( - FieldName::Attributes, + seq.elem_labeled(NodeLabel::Parameters, self.parameters_declaration(input))?; + seq.elem_labeled( + NodeLabel::Attributes, OptionalHelper::transform(self.constructor_attributes(input)), )?; - seq.elem_named(FieldName::Body, self.block(input))?; + seq.elem_labeled(NodeLabel::Body, self.block(input))?; seq.finish() }) } else { @@ -845,7 +846,7 @@ impl Language { input, TokenKind::ContinueKeyword, ) - .with_name(FieldName::ContinueKeyword) + .with_label(NodeLabel::ContinueKeyword) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -853,8 +854,8 @@ impl Language { RecoverFromNoMatch::No, ), )?; - seq.elem_named( - FieldName::Semicolon, + seq.elem_labeled( + NodeLabel::Semicolon, self.parse_token_with_trivia::( input, TokenKind::Semicolon, @@ -869,8 +870,8 @@ impl Language { fn contract_definition(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { if self.version_is_at_least_0_6_0 { - seq.elem_named( - FieldName::AbstractKeyword, + seq.elem_labeled( + NodeLabel::AbstractKeyword, OptionalHelper::transform( self.parse_token_with_trivia::( input, @@ -879,29 +880,29 @@ impl Language { ), )?; } - seq.elem_named( - FieldName::ContractKeyword, + seq.elem_labeled( + NodeLabel::ContractKeyword, self.parse_token_with_trivia::( input, TokenKind::ContractKeyword, ), )?; - seq.elem_named( - FieldName::Name, + seq.elem_labeled( + NodeLabel::Name, self.parse_token_with_trivia::( input, TokenKind::Identifier, ), )?; - seq.elem_named( - FieldName::Inheritence, + seq.elem_labeled( + NodeLabel::Inheritence, OptionalHelper::transform(self.inheritance_specifier(input)), )?; seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenBrace, + seq.elem_labeled( + NodeLabel::OpenBrace, self.parse_token_with_trivia::( input, TokenKind::OpenBrace, @@ -909,7 +910,7 @@ impl Language { )?; seq.elem( OptionalHelper::transform(self.contract_members(input)) - .with_name(FieldName::Members) + .with_label(NodeLabel::Members) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -917,8 +918,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseBrace, + seq.elem_labeled( + NodeLabel::CloseBrace, self.parse_token_with_trivia::( input, TokenKind::CloseBrace, @@ -974,14 +975,14 @@ impl Language { } choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::ContractMember) } #[allow(unused_assignments, unused_parens)] fn contract_members(&self, input: &mut ParserContext<'_>) -> ParserResult { OneOrMoreHelper::run(input, |input| { - self.contract_member(input).with_name(FieldName::Item) + self.contract_member(input).with_label(NodeLabel::Item) }) .with_kind(RuleKind::ContractMembers) } @@ -989,15 +990,15 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn decimal_number_expression(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::Literal, + seq.elem_labeled( + NodeLabel::Literal, self.parse_token_with_trivia::( input, TokenKind::DecimalLiteral, ), )?; - seq.elem_named( - FieldName::Unit, + seq.elem_labeled( + NodeLabel::Unit, OptionalHelper::transform(self.number_unit(input)), )?; seq.finish() @@ -1010,14 +1011,14 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::DeleteKeyword, + seq.elem_labeled( + NodeLabel::DeleteKeyword, self.parse_token_with_trivia::( input, TokenKind::DeleteKeyword, ), )?; - seq.elem_named(FieldName::Expression, self.expression(input))?; + seq.elem_labeled(NodeLabel::Expression, self.expression(input))?; seq.finish() }) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( @@ -1027,8 +1028,8 @@ impl Language { RecoverFromNoMatch::No, ), )?; - seq.elem_named( - FieldName::Semicolon, + seq.elem_labeled( + NodeLabel::Semicolon, self.parse_token_with_trivia::( input, TokenKind::Semicolon, @@ -1044,16 +1045,16 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::DoKeyword, + seq.elem_labeled( + NodeLabel::DoKeyword, self.parse_token_with_trivia::( input, TokenKind::DoKeyword, ), )?; - seq.elem_named(FieldName::Body, self.statement(input))?; - seq.elem_named( - FieldName::WhileKeyword, + seq.elem_labeled(NodeLabel::Body, self.statement(input))?; + seq.elem_labeled( + NodeLabel::WhileKeyword, self.parse_token_with_trivia::( input, TokenKind::WhileKeyword, @@ -1062,8 +1063,8 @@ impl Language { seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenParen, + seq.elem_labeled( + NodeLabel::OpenParen, self.parse_token_with_trivia::( input, TokenKind::OpenParen, @@ -1071,7 +1072,7 @@ impl Language { )?; seq.elem( self.expression(input) - .with_name(FieldName::Condition) + .with_label(NodeLabel::Condition) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -1079,8 +1080,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseParen, + seq.elem_labeled( + NodeLabel::CloseParen, self.parse_token_with_trivia::( input, TokenKind::CloseParen, @@ -1097,8 +1098,8 @@ impl Language { RecoverFromNoMatch::No, ), )?; - seq.elem_named( - FieldName::Semicolon, + seq.elem_labeled( + NodeLabel::Semicolon, self.parse_token_with_trivia::( input, TokenKind::Semicolon, @@ -1158,21 +1159,21 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::ElementaryType) } #[allow(unused_assignments, unused_parens)] fn else_branch(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::ElseKeyword, + seq.elem_labeled( + NodeLabel::ElseKeyword, self.parse_token_with_trivia::( input, TokenKind::ElseKeyword, ), )?; - seq.elem_named(FieldName::Body, self.statement(input))?; + seq.elem_labeled(NodeLabel::Body, self.statement(input))?; seq.finish() }) .with_kind(RuleKind::ElseBranch) @@ -1184,15 +1185,15 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::EmitKeyword, + seq.elem_labeled( + NodeLabel::EmitKeyword, self.parse_token_with_trivia::( input, TokenKind::EmitKeyword, ), )?; - seq.elem_named(FieldName::Event, self.identifier_path(input))?; - seq.elem_named(FieldName::Arguments, self.arguments_declaration(input))?; + seq.elem_labeled(NodeLabel::Event, self.identifier_path(input))?; + seq.elem_labeled(NodeLabel::Arguments, self.arguments_declaration(input))?; seq.finish() }) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( @@ -1202,8 +1203,8 @@ impl Language { RecoverFromNoMatch::No, ), )?; - seq.elem_named( - FieldName::Semicolon, + seq.elem_labeled( + NodeLabel::Semicolon, self.parse_token_with_trivia::( input, TokenKind::Semicolon, @@ -1220,15 +1221,15 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn enum_definition(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::EnumKeyword, + seq.elem_labeled( + NodeLabel::EnumKeyword, self.parse_token_with_trivia::( input, TokenKind::EnumKeyword, ), )?; - seq.elem_named( - FieldName::Name, + seq.elem_labeled( + NodeLabel::Name, self.parse_token_with_trivia::( input, TokenKind::Identifier, @@ -1237,8 +1238,8 @@ impl Language { seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenBrace, + seq.elem_labeled( + NodeLabel::OpenBrace, self.parse_token_with_trivia::( input, TokenKind::OpenBrace, @@ -1246,7 +1247,7 @@ impl Language { )?; seq.elem( OptionalHelper::transform(self.enum_members(input)) - .with_name(FieldName::Members) + .with_label(NodeLabel::Members) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -1254,8 +1255,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseBrace, + seq.elem_labeled( + NodeLabel::CloseBrace, self.parse_token_with_trivia::( input, TokenKind::CloseBrace, @@ -1278,10 +1279,10 @@ impl Language { input, TokenKind::Identifier, ) - .with_name(FieldName::Item) + .with_label(NodeLabel::Item) }, TokenKind::Comma, - FieldName::Separator, + NodeLabel::Separator, ) .with_kind(RuleKind::EnumMembers) } @@ -1293,12 +1294,12 @@ impl Language { return result; }; match &r#match.nodes[..] { - [cst::NamedNode { - name: _, + [cst::LabeledNode { + label: _, node: cst::Node::Rule(node), }] if node.kind == RuleKind::Expression => match &node.children[..] { - [inner @ cst::NamedNode { - name: _, + [inner @ cst::LabeledNode { + label: _, node: cst::Node::Rule(rule), }] if rule.kind == RuleKind::EqualityExpression => { ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) @@ -1315,22 +1316,22 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::ErrorKeyword, + seq.elem_labeled( + NodeLabel::ErrorKeyword, self.parse_token_with_trivia::( input, TokenKind::ErrorKeyword, ), )?; - seq.elem_named( - FieldName::Name, + seq.elem_labeled( + NodeLabel::Name, self.parse_token_with_trivia::( input, TokenKind::Identifier, ), )?; - seq.elem_named( - FieldName::Members, + seq.elem_labeled( + NodeLabel::Members, self.error_parameters_declaration(input), )?; seq.finish() @@ -1342,8 +1343,8 @@ impl Language { RecoverFromNoMatch::No, ), )?; - seq.elem_named( - FieldName::Semicolon, + seq.elem_labeled( + NodeLabel::Semicolon, self.parse_token_with_trivia::( input, TokenKind::Semicolon, @@ -1361,9 +1362,9 @@ impl Language { fn error_parameter(&self, input: &mut ParserContext<'_>) -> ParserResult { if self.version_is_at_least_0_8_4 { SequenceHelper::run(|mut seq| { - seq.elem_named(FieldName::TypeName, self.type_name(input))?; - seq.elem_named( - FieldName::Name, + seq.elem_labeled(NodeLabel::TypeName, self.type_name(input))?; + seq.elem_labeled( + NodeLabel::Name, OptionalHelper::transform( self.parse_token_with_trivia::( input, @@ -1385,9 +1386,9 @@ impl Language { SeparatedHelper::run::<_, LexicalContextType::Default>( input, self, - |input| self.error_parameter(input).with_name(FieldName::Item), + |input| self.error_parameter(input).with_label(NodeLabel::Item), TokenKind::Comma, - FieldName::Separator, + NodeLabel::Separator, ) } else { ParserResult::disabled() @@ -1401,8 +1402,8 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenParen, + seq.elem_labeled( + NodeLabel::OpenParen, self.parse_token_with_trivia::( input, TokenKind::OpenParen, @@ -1410,7 +1411,7 @@ impl Language { )?; seq.elem( OptionalHelper::transform(self.error_parameters(input)) - .with_name(FieldName::Parameters) + .with_label(NodeLabel::Parameters) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -1418,8 +1419,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseParen, + seq.elem_labeled( + NodeLabel::CloseParen, self.parse_token_with_trivia::( input, TokenKind::CloseParen, @@ -1438,26 +1439,26 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::EventKeyword, + seq.elem_labeled( + NodeLabel::EventKeyword, self.parse_token_with_trivia::( input, TokenKind::EventKeyword, ), )?; - seq.elem_named( - FieldName::Name, + seq.elem_labeled( + NodeLabel::Name, self.parse_token_with_trivia::( input, TokenKind::Identifier, ), )?; - seq.elem_named( - FieldName::Parameters, + seq.elem_labeled( + NodeLabel::Parameters, self.event_parameters_declaration(input), )?; - seq.elem_named( - FieldName::AnonymousKeyword, + seq.elem_labeled( + NodeLabel::AnonymousKeyword, OptionalHelper::transform( self.parse_token_with_trivia::( input, @@ -1474,8 +1475,8 @@ impl Language { RecoverFromNoMatch::No, ), )?; - seq.elem_named( - FieldName::Semicolon, + seq.elem_labeled( + NodeLabel::Semicolon, self.parse_token_with_trivia::( input, TokenKind::Semicolon, @@ -1489,9 +1490,9 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn event_parameter(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named(FieldName::TypeName, self.type_name(input))?; - seq.elem_named( - FieldName::IndexedKeyword, + seq.elem_labeled(NodeLabel::TypeName, self.type_name(input))?; + seq.elem_labeled( + NodeLabel::IndexedKeyword, OptionalHelper::transform( self.parse_token_with_trivia::( input, @@ -1499,8 +1500,8 @@ impl Language { ), ), )?; - seq.elem_named( - FieldName::Name, + seq.elem_labeled( + NodeLabel::Name, OptionalHelper::transform( self.parse_token_with_trivia::( input, @@ -1518,9 +1519,9 @@ impl Language { SeparatedHelper::run::<_, LexicalContextType::Default>( input, self, - |input| self.event_parameter(input).with_name(FieldName::Item), + |input| self.event_parameter(input).with_label(NodeLabel::Item), TokenKind::Comma, - FieldName::Separator, + NodeLabel::Separator, ) .with_kind(RuleKind::EventParameters) } @@ -1530,8 +1531,8 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenParen, + seq.elem_labeled( + NodeLabel::OpenParen, self.parse_token_with_trivia::( input, TokenKind::OpenParen, @@ -1539,7 +1540,7 @@ impl Language { )?; seq.elem( OptionalHelper::transform(self.event_parameters(input)) - .with_name(FieldName::Parameters) + .with_label(NodeLabel::Parameters) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -1547,8 +1548,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseParen, + seq.elem_labeled( + NodeLabel::CloseParen, self.parse_token_with_trivia::( input, TokenKind::CloseParen, @@ -1571,21 +1572,21 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::ExperimentalFeature) } #[allow(unused_assignments, unused_parens)] fn experimental_pragma(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::ExperimentalKeyword, + seq.elem_labeled( + NodeLabel::ExperimentalKeyword, self.parse_token_with_trivia::( input, TokenKind::ExperimentalKeyword, ), )?; - seq.elem_named(FieldName::Feature, self.experimental_feature(input))?; + seq.elem_labeled(NodeLabel::Feature, self.experimental_feature(input))?; seq.finish() }) .with_kind(RuleKind::ExperimentalPragma) @@ -1598,12 +1599,12 @@ impl Language { return result; }; match &r#match.nodes[..] { - [cst::NamedNode { - name: _, + [cst::LabeledNode { + label: _, node: cst::Node::Rule(node), }] if node.kind == RuleKind::Expression => match &node.children[..] { - [inner @ cst::NamedNode { - name: _, + [inner @ cst::LabeledNode { + label: _, node: cst::Node::Rule(rule), }] if rule.kind == RuleKind::ExponentiationExpression => { ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) @@ -1627,84 +1628,84 @@ impl Language { input, TokenKind::Equal, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::BarEqual, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::PlusEqual, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::MinusEqual, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::CaretEqual, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::SlashEqual, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::PercentEqual, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::AsteriskEqual, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::AmpersandEqual, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::LessThanLessThanEqual, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::GreaterThanGreaterThanEqual, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::GreaterThanGreaterThanGreaterThanEqual, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; choice.finish(input) }), @@ -1715,22 +1716,22 @@ impl Language { RuleKind::ConditionalExpression, 3u8, SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::QuestionMark, + seq.elem_labeled( + NodeLabel::QuestionMark, self.parse_token_with_trivia::( input, TokenKind::QuestionMark, ), )?; - seq.elem_named(FieldName::TrueExpression, self.expression(input))?; - seq.elem_named( - FieldName::Colon, + seq.elem_labeled(NodeLabel::TrueExpression, self.expression(input))?; + seq.elem_labeled( + NodeLabel::Colon, self.parse_token_with_trivia::( input, TokenKind::Colon, ), )?; - seq.elem_named(FieldName::FalseExpression, self.expression(input))?; + seq.elem_labeled(NodeLabel::FalseExpression, self.expression(input))?; seq.finish() }), ) @@ -1744,7 +1745,7 @@ impl Language { input, TokenKind::BarBar, ) - .with_name(FieldName::Operator), + .with_label(NodeLabel::Operator), ) }; let parse_left_and_expression = |input: &mut ParserContext<'_>| { @@ -1756,7 +1757,7 @@ impl Language { input, TokenKind::AmpersandAmpersand, ) - .with_name(FieldName::Operator), + .with_label(NodeLabel::Operator), ) }; let parse_left_equality_expression = |input: &mut ParserContext<'_>| { @@ -1770,14 +1771,14 @@ impl Language { input, TokenKind::EqualEqual, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::BangEqual, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; choice.finish(input) }), @@ -1794,28 +1795,28 @@ impl Language { input, TokenKind::LessThan, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::GreaterThan, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::LessThanEqual, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::GreaterThanEqual, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; choice.finish(input) }), @@ -1827,7 +1828,7 @@ impl Language { 13u8, 13u8 + 1, self.parse_token_with_trivia::(input, TokenKind::Bar) - .with_name(FieldName::Operator), + .with_label(NodeLabel::Operator), ) }; let parse_left_bitwise_xor_expression = |input: &mut ParserContext<'_>| { @@ -1839,7 +1840,7 @@ impl Language { input, TokenKind::Caret, ) - .with_name(FieldName::Operator), + .with_label(NodeLabel::Operator), ) }; let parse_left_bitwise_and_expression = |input: &mut ParserContext<'_>| { @@ -1851,7 +1852,7 @@ impl Language { input, TokenKind::Ampersand, ) - .with_name(FieldName::Operator), + .with_label(NodeLabel::Operator), ) }; let parse_left_shift_expression = |input: &mut ParserContext<'_>| { @@ -1865,21 +1866,21 @@ impl Language { input, TokenKind::LessThanLessThan, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::GreaterThanGreaterThan, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::GreaterThanGreaterThanGreaterThan, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; choice.finish(input) }), @@ -1896,14 +1897,14 @@ impl Language { input, TokenKind::Plus, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::Minus, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; choice.finish(input) }), @@ -1920,21 +1921,21 @@ impl Language { input, TokenKind::Asterisk, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::Slash, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::Percent, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; choice.finish(input) }), @@ -1952,7 +1953,7 @@ impl Language { input, TokenKind::AsteriskAsterisk, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; } choice.finish(input) @@ -1971,7 +1972,7 @@ impl Language { input, TokenKind::AsteriskAsterisk, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; } choice.finish(input) @@ -1988,14 +1989,14 @@ impl Language { input, TokenKind::PlusPlus, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::MinusMinus, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; choice.finish(input) }), @@ -2011,35 +2012,35 @@ impl Language { input, TokenKind::PlusPlus, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::MinusMinus, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::Tilde, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::Bang, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::Minus, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; if !self.version_is_at_least_0_5_0 { let result = self @@ -2047,7 +2048,7 @@ impl Language { input, TokenKind::Plus, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; } choice.finish(input) @@ -2060,12 +2061,12 @@ impl Language { 33u8, SequenceHelper::run(|mut seq| { if self.version_is_at_least_0_6_2 { - seq.elem_named( - FieldName::Options, + seq.elem_labeled( + NodeLabel::Options, OptionalHelper::transform(self.function_call_options(input)), )?; } - seq.elem_named(FieldName::Arguments, self.arguments_declaration(input))?; + seq.elem_labeled(NodeLabel::Arguments, self.arguments_declaration(input))?; seq.finish() }), ) @@ -2075,14 +2076,14 @@ impl Language { RuleKind::MemberAccessExpression, 35u8, SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::Period, + seq.elem_labeled( + NodeLabel::Period, self.parse_token_with_trivia::( input, TokenKind::Period, ), )?; - seq.elem_named(FieldName::Member, self.member_access(input))?; + seq.elem_labeled(NodeLabel::Member, self.member_access(input))?; seq.finish() }), ) @@ -2094,8 +2095,8 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBracket); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenBracket, + seq.elem_labeled( + NodeLabel::OpenBracket, self.parse_token_with_trivia::( input, TokenKind::OpenBracket, @@ -2103,12 +2104,12 @@ impl Language { )?; seq.elem( SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::Start, + seq.elem_labeled( + NodeLabel::Start, OptionalHelper::transform(self.expression(input)), )?; - seq.elem_named( - FieldName::End, + seq.elem_labeled( + NodeLabel::End, OptionalHelper::transform(self.index_access_end(input)), )?; seq.finish() @@ -2120,8 +2121,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseBracket, + seq.elem_labeled( + NodeLabel::CloseBracket, self.parse_token_with_trivia::( input, TokenKind::CloseBracket, @@ -2182,7 +2183,7 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) }; let postfix_operator_parser = |input: &mut ParserContext<'_>| { ChoiceHelper::run(input, |mut choice, input| { @@ -2263,7 +2264,7 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( self.expression(input) - .with_name(FieldName::Expression) + .with_label(NodeLabel::Expression) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -2271,8 +2272,8 @@ impl Language { RecoverFromNoMatch::No, ), )?; - seq.elem_named( - FieldName::Semicolon, + seq.elem_labeled( + NodeLabel::Semicolon, self.parse_token_with_trivia::( input, TokenKind::Semicolon, @@ -2318,7 +2319,7 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) } else { ParserResult::disabled() } @@ -2330,7 +2331,7 @@ impl Language { if self.version_is_at_least_0_6_0 { OneOrMoreHelper::run(input, |input| { self.fallback_function_attribute(input) - .with_name(FieldName::Item) + .with_label(NodeLabel::Item) }) } else { ParserResult::disabled() @@ -2342,23 +2343,23 @@ impl Language { fn fallback_function_definition(&self, input: &mut ParserContext<'_>) -> ParserResult { if self.version_is_at_least_0_6_0 { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::FallbackKeyword, + seq.elem_labeled( + NodeLabel::FallbackKeyword, self.parse_token_with_trivia::( input, TokenKind::FallbackKeyword, ), )?; - seq.elem_named(FieldName::Parameters, self.parameters_declaration(input))?; - seq.elem_named( - FieldName::Attributes, + seq.elem_labeled(NodeLabel::Parameters, self.parameters_declaration(input))?; + seq.elem_labeled( + NodeLabel::Attributes, OptionalHelper::transform(self.fallback_function_attributes(input)), )?; - seq.elem_named( - FieldName::Returns, + seq.elem_labeled( + NodeLabel::Returns, OptionalHelper::transform(self.returns_declaration(input)), )?; - seq.elem_named(FieldName::Body, self.function_body(input))?; + seq.elem_labeled(NodeLabel::Body, self.function_body(input))?; seq.finish() }) } else { @@ -2370,8 +2371,8 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn for_statement(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::ForKeyword, + seq.elem_labeled( + NodeLabel::ForKeyword, self.parse_token_with_trivia::( input, TokenKind::ForKeyword, @@ -2380,8 +2381,8 @@ impl Language { seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenParen, + seq.elem_labeled( + NodeLabel::OpenParen, self.parse_token_with_trivia::( input, TokenKind::OpenParen, @@ -2389,13 +2390,16 @@ impl Language { )?; seq.elem( SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::Initialization, + seq.elem_labeled( + NodeLabel::Initialization, self.for_statement_initialization(input), )?; - seq.elem_named(FieldName::Condition, self.for_statement_condition(input))?; - seq.elem_named( - FieldName::Iterator, + seq.elem_labeled( + NodeLabel::Condition, + self.for_statement_condition(input), + )?; + seq.elem_labeled( + NodeLabel::Iterator, OptionalHelper::transform(self.expression(input)), )?; seq.finish() @@ -2407,8 +2411,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseParen, + seq.elem_labeled( + NodeLabel::CloseParen, self.parse_token_with_trivia::( input, TokenKind::CloseParen, @@ -2416,7 +2420,7 @@ impl Language { )?; seq.finish() }))?; - seq.elem_named(FieldName::Body, self.statement(input))?; + seq.elem_labeled(NodeLabel::Body, self.statement(input))?; seq.finish() }) .with_kind(RuleKind::ForStatement) @@ -2434,7 +2438,7 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::ForStatementCondition) } @@ -2454,7 +2458,7 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::ForStatementInitialization) } @@ -2516,14 +2520,14 @@ impl Language { } choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::FunctionAttribute) } #[allow(unused_assignments, unused_parens)] fn function_attributes(&self, input: &mut ParserContext<'_>) -> ParserResult { OneOrMoreHelper::run(input, |input| { - self.function_attribute(input).with_name(FieldName::Item) + self.function_attribute(input).with_label(NodeLabel::Item) }) .with_kind(RuleKind::FunctionAttributes) } @@ -2540,7 +2544,7 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::FunctionBody) } @@ -2551,12 +2555,12 @@ impl Language { return result; }; match &r#match.nodes[..] { - [cst::NamedNode { - name: _, + [cst::LabeledNode { + label: _, node: cst::Node::Rule(node), }] if node.kind == RuleKind::Expression => match &node.children[..] { - [inner @ cst::NamedNode { - name: _, + [inner @ cst::LabeledNode { + label: _, node: cst::Node::Rule(rule), }] if rule.kind == RuleKind::FunctionCallExpression => { ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) @@ -2581,7 +2585,7 @@ impl Language { } choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) } else { ParserResult::disabled() } @@ -2591,24 +2595,24 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn function_definition(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::FunctionKeyword, + seq.elem_labeled( + NodeLabel::FunctionKeyword, self.parse_token_with_trivia::( input, TokenKind::FunctionKeyword, ), )?; - seq.elem_named(FieldName::Name, self.function_name(input))?; - seq.elem_named(FieldName::Parameters, self.parameters_declaration(input))?; - seq.elem_named( - FieldName::Attributes, + seq.elem_labeled(NodeLabel::Name, self.function_name(input))?; + seq.elem_labeled(NodeLabel::Parameters, self.parameters_declaration(input))?; + seq.elem_labeled( + NodeLabel::Attributes, OptionalHelper::transform(self.function_attributes(input)), )?; - seq.elem_named( - FieldName::Returns, + seq.elem_labeled( + NodeLabel::Returns, OptionalHelper::transform(self.returns_declaration(input)), )?; - seq.elem_named(FieldName::Body, self.function_body(input))?; + seq.elem_labeled(NodeLabel::Body, self.function_body(input))?; seq.finish() }) .with_kind(RuleKind::FunctionDefinition) @@ -2634,27 +2638,27 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::FunctionName) } #[allow(unused_assignments, unused_parens)] fn function_type(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::FunctionKeyword, + seq.elem_labeled( + NodeLabel::FunctionKeyword, self.parse_token_with_trivia::( input, TokenKind::FunctionKeyword, ), )?; - seq.elem_named(FieldName::Parameters, self.parameters_declaration(input))?; - seq.elem_named( - FieldName::Attributes, + seq.elem_labeled(NodeLabel::Parameters, self.parameters_declaration(input))?; + seq.elem_labeled( + NodeLabel::Attributes, OptionalHelper::transform(self.function_type_attributes(input)), )?; - seq.elem_named( - FieldName::Returns, + seq.elem_labeled( + NodeLabel::Returns, OptionalHelper::transform(self.returns_declaration(input)), )?; seq.finish() @@ -2702,7 +2706,7 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::FunctionTypeAttribute) } @@ -2710,7 +2714,7 @@ impl Language { fn function_type_attributes(&self, input: &mut ParserContext<'_>) -> ParserResult { OneOrMoreHelper::run(input, |input| { self.function_type_attribute(input) - .with_name(FieldName::Item) + .with_label(NodeLabel::Item) }) .with_kind(RuleKind::FunctionTypeAttributes) } @@ -2718,16 +2722,16 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn hex_number_expression(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::Literal, + seq.elem_labeled( + NodeLabel::Literal, self.parse_token_with_trivia::( input, TokenKind::HexLiteral, ), )?; if !self.version_is_at_least_0_5_0 { - seq.elem_named( - FieldName::Unit, + seq.elem_labeled( + NodeLabel::Unit, OptionalHelper::transform(self.number_unit(input)), )?; } @@ -2751,7 +2755,7 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::HexStringLiteral) } @@ -2759,7 +2763,7 @@ impl Language { fn hex_string_literals(&self, input: &mut ParserContext<'_>) -> ParserResult { if self.version_is_at_least_0_5_14 { OneOrMoreHelper::run(input, |input| { - self.hex_string_literal(input).with_name(FieldName::Item) + self.hex_string_literal(input).with_label(NodeLabel::Item) }) } else { ParserResult::disabled() @@ -2777,10 +2781,10 @@ impl Language { input, TokenKind::Identifier, ) - .with_name(FieldName::Item) + .with_label(NodeLabel::Item) }, TokenKind::Period, - FieldName::Separator, + NodeLabel::Separator, ) .with_kind(RuleKind::IdentifierPath) } @@ -2788,8 +2792,8 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn if_statement(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::IfKeyword, + seq.elem_labeled( + NodeLabel::IfKeyword, self.parse_token_with_trivia::( input, TokenKind::IfKeyword, @@ -2798,8 +2802,8 @@ impl Language { seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenParen, + seq.elem_labeled( + NodeLabel::OpenParen, self.parse_token_with_trivia::( input, TokenKind::OpenParen, @@ -2807,7 +2811,7 @@ impl Language { )?; seq.elem( self.expression(input) - .with_name(FieldName::Condition) + .with_label(NodeLabel::Condition) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -2815,8 +2819,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseParen, + seq.elem_labeled( + NodeLabel::CloseParen, self.parse_token_with_trivia::( input, TokenKind::CloseParen, @@ -2824,9 +2828,9 @@ impl Language { )?; seq.finish() }))?; - seq.elem_named(FieldName::Body, self.statement(input))?; - seq.elem_named( - FieldName::ElseBranch, + seq.elem_labeled(NodeLabel::Body, self.statement(input))?; + seq.elem_labeled( + NodeLabel::ElseBranch, OptionalHelper::transform(self.else_branch(input)), )?; seq.finish() @@ -2837,15 +2841,15 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn import_alias(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::AsKeyword, + seq.elem_labeled( + NodeLabel::AsKeyword, self.parse_token_with_trivia::( input, TokenKind::AsKeyword, ), )?; - seq.elem_named( - FieldName::Identifier, + seq.elem_labeled( + NodeLabel::Identifier, self.parse_token_with_trivia::( input, TokenKind::Identifier, @@ -2867,7 +2871,7 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::ImportClause) } @@ -2877,8 +2881,8 @@ impl Language { seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenBrace, + seq.elem_labeled( + NodeLabel::OpenBrace, self.parse_token_with_trivia::( input, TokenKind::OpenBrace, @@ -2886,7 +2890,7 @@ impl Language { )?; seq.elem( self.import_deconstruction_symbols(input) - .with_name(FieldName::Symbols) + .with_label(NodeLabel::Symbols) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -2894,8 +2898,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseBrace, + seq.elem_labeled( + NodeLabel::CloseBrace, self.parse_token_with_trivia::( input, TokenKind::CloseBrace, @@ -2903,14 +2907,14 @@ impl Language { )?; seq.finish() }))?; - seq.elem_named( - FieldName::FromKeyword, + seq.elem_labeled( + NodeLabel::FromKeyword, self.parse_token_with_trivia::( input, TokenKind::FromKeyword, ), )?; - seq.elem_named(FieldName::Path, self.string_literal(input))?; + seq.elem_labeled(NodeLabel::Path, self.string_literal(input))?; seq.finish() }) .with_kind(RuleKind::ImportDeconstruction) @@ -2919,15 +2923,15 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn import_deconstruction_symbol(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::Name, + seq.elem_labeled( + NodeLabel::Name, self.parse_token_with_trivia::( input, TokenKind::Identifier, ), )?; - seq.elem_named( - FieldName::Alias, + seq.elem_labeled( + NodeLabel::Alias, OptionalHelper::transform(self.import_alias(input)), )?; seq.finish() @@ -2942,10 +2946,10 @@ impl Language { self, |input| { self.import_deconstruction_symbol(input) - .with_name(FieldName::Item) + .with_label(NodeLabel::Item) }, TokenKind::Comma, - FieldName::Separator, + NodeLabel::Separator, ) .with_kind(RuleKind::ImportDeconstructionSymbols) } @@ -2955,14 +2959,14 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::ImportKeyword, + seq.elem_labeled( + NodeLabel::ImportKeyword, self.parse_token_with_trivia::( input, TokenKind::ImportKeyword, ), )?; - seq.elem_named(FieldName::Clause, self.import_clause(input))?; + seq.elem_labeled(NodeLabel::Clause, self.import_clause(input))?; seq.finish() }) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( @@ -2972,8 +2976,8 @@ impl Language { RecoverFromNoMatch::No, ), )?; - seq.elem_named( - FieldName::Semicolon, + seq.elem_labeled( + NodeLabel::Semicolon, self.parse_token_with_trivia::( input, TokenKind::Semicolon, @@ -2987,15 +2991,15 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn index_access_end(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::Colon, + seq.elem_labeled( + NodeLabel::Colon, self.parse_token_with_trivia::( input, TokenKind::Colon, ), )?; - seq.elem_named( - FieldName::End, + seq.elem_labeled( + NodeLabel::End, OptionalHelper::transform(self.expression(input)), )?; seq.finish() @@ -3010,12 +3014,12 @@ impl Language { return result; }; match &r#match.nodes[..] { - [cst::NamedNode { - name: _, + [cst::LabeledNode { + label: _, node: cst::Node::Rule(node), }] if node.kind == RuleKind::Expression => match &node.children[..] { - [inner @ cst::NamedNode { - name: _, + [inner @ cst::LabeledNode { + label: _, node: cst::Node::Rule(rule), }] if rule.kind == RuleKind::IndexAccessExpression => { ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) @@ -3029,14 +3033,14 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn inheritance_specifier(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::IsKeyword, + seq.elem_labeled( + NodeLabel::IsKeyword, self.parse_token_with_trivia::( input, TokenKind::IsKeyword, ), )?; - seq.elem_named(FieldName::Types, self.inheritance_types(input))?; + seq.elem_labeled(NodeLabel::Types, self.inheritance_types(input))?; seq.finish() }) .with_kind(RuleKind::InheritanceSpecifier) @@ -3045,9 +3049,9 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn inheritance_type(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named(FieldName::TypeName, self.identifier_path(input))?; - seq.elem_named( - FieldName::Arguments, + seq.elem_labeled(NodeLabel::TypeName, self.identifier_path(input))?; + seq.elem_labeled( + NodeLabel::Arguments, OptionalHelper::transform(self.arguments_declaration(input)), )?; seq.finish() @@ -3060,9 +3064,9 @@ impl Language { SeparatedHelper::run::<_, LexicalContextType::Default>( input, self, - |input| self.inheritance_type(input).with_name(FieldName::Item), + |input| self.inheritance_type(input).with_label(NodeLabel::Item), TokenKind::Comma, - FieldName::Separator, + NodeLabel::Separator, ) .with_kind(RuleKind::InheritanceTypes) } @@ -3070,29 +3074,29 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn interface_definition(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::InterfaceKeyword, + seq.elem_labeled( + NodeLabel::InterfaceKeyword, self.parse_token_with_trivia::( input, TokenKind::InterfaceKeyword, ), )?; - seq.elem_named( - FieldName::Name, + seq.elem_labeled( + NodeLabel::Name, self.parse_token_with_trivia::( input, TokenKind::Identifier, ), )?; - seq.elem_named( - FieldName::Inheritence, + seq.elem_labeled( + NodeLabel::Inheritence, OptionalHelper::transform(self.inheritance_specifier(input)), )?; seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenBrace, + seq.elem_labeled( + NodeLabel::OpenBrace, self.parse_token_with_trivia::( input, TokenKind::OpenBrace, @@ -3100,7 +3104,7 @@ impl Language { )?; seq.elem( OptionalHelper::transform(self.interface_members(input)) - .with_name(FieldName::Members) + .with_label(NodeLabel::Members) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -3108,8 +3112,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseBrace, + seq.elem_labeled( + NodeLabel::CloseBrace, self.parse_token_with_trivia::( input, TokenKind::CloseBrace, @@ -3125,7 +3129,7 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn interface_members(&self, input: &mut ParserContext<'_>) -> ParserResult { OneOrMoreHelper::run(input, |input| { - self.contract_member(input).with_name(FieldName::Item) + self.contract_member(input).with_label(NodeLabel::Item) }) .with_kind(RuleKind::InterfaceMembers) } @@ -3167,15 +3171,15 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn library_definition(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::LibraryKeyword, + seq.elem_labeled( + NodeLabel::LibraryKeyword, self.parse_token_with_trivia::( input, TokenKind::LibraryKeyword, ), )?; - seq.elem_named( - FieldName::Name, + seq.elem_labeled( + NodeLabel::Name, self.parse_token_with_trivia::( input, TokenKind::Identifier, @@ -3184,8 +3188,8 @@ impl Language { seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenBrace, + seq.elem_labeled( + NodeLabel::OpenBrace, self.parse_token_with_trivia::( input, TokenKind::OpenBrace, @@ -3193,7 +3197,7 @@ impl Language { )?; seq.elem( OptionalHelper::transform(self.library_members(input)) - .with_name(FieldName::Members) + .with_label(NodeLabel::Members) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -3201,8 +3205,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseBrace, + seq.elem_labeled( + NodeLabel::CloseBrace, self.parse_token_with_trivia::( input, TokenKind::CloseBrace, @@ -3218,7 +3222,7 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn library_members(&self, input: &mut ParserContext<'_>) -> ParserResult { OneOrMoreHelper::run(input, |input| { - self.contract_member(input).with_name(FieldName::Item) + self.contract_member(input).with_label(NodeLabel::Item) }) .with_kind(RuleKind::LibraryMembers) } @@ -3226,10 +3230,10 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn mapping_key(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named(FieldName::KeyType, self.mapping_key_type(input))?; + seq.elem_labeled(NodeLabel::KeyType, self.mapping_key_type(input))?; if self.version_is_at_least_0_8_18 { - seq.elem_named( - FieldName::Name, + seq.elem_labeled( + NodeLabel::Name, OptionalHelper::transform( self.parse_token_with_trivia::( input, @@ -3252,15 +3256,15 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::MappingKeyType) } #[allow(unused_assignments, unused_parens)] fn mapping_type(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::MappingKeyword, + seq.elem_labeled( + NodeLabel::MappingKeyword, self.parse_token_with_trivia::( input, TokenKind::MappingKeyword, @@ -3269,8 +3273,8 @@ impl Language { seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenParen, + seq.elem_labeled( + NodeLabel::OpenParen, self.parse_token_with_trivia::( input, TokenKind::OpenParen, @@ -3278,15 +3282,15 @@ impl Language { )?; seq.elem( SequenceHelper::run(|mut seq| { - seq.elem_named(FieldName::KeyType, self.mapping_key(input))?; - seq.elem_named( - FieldName::EqualGreaterThan, + seq.elem_labeled(NodeLabel::KeyType, self.mapping_key(input))?; + seq.elem_labeled( + NodeLabel::EqualGreaterThan, self.parse_token_with_trivia::( input, TokenKind::EqualGreaterThan, ), )?; - seq.elem_named(FieldName::ValueType, self.mapping_value(input))?; + seq.elem_labeled(NodeLabel::ValueType, self.mapping_value(input))?; seq.finish() }) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( @@ -3296,8 +3300,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseParen, + seq.elem_labeled( + NodeLabel::CloseParen, self.parse_token_with_trivia::( input, TokenKind::CloseParen, @@ -3313,10 +3317,10 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn mapping_value(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named(FieldName::TypeName, self.type_name(input))?; + seq.elem_labeled(NodeLabel::TypeName, self.type_name(input))?; if self.version_is_at_least_0_8_18 { - seq.elem_named( - FieldName::Name, + seq.elem_labeled( + NodeLabel::Name, OptionalHelper::transform( self.parse_token_with_trivia::( input, @@ -3345,7 +3349,7 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::MemberAccess) } @@ -3356,12 +3360,12 @@ impl Language { return result; }; match &r#match.nodes[..] { - [cst::NamedNode { - name: _, + [cst::LabeledNode { + label: _, node: cst::Node::Rule(node), }] if node.kind == RuleKind::Expression => match &node.children[..] { - [inner @ cst::NamedNode { - name: _, + [inner @ cst::LabeledNode { + label: _, node: cst::Node::Rule(rule), }] if rule.kind == RuleKind::MemberAccessExpression => { ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) @@ -3386,14 +3390,14 @@ impl Language { } choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::ModifierAttribute) } #[allow(unused_assignments, unused_parens)] fn modifier_attributes(&self, input: &mut ParserContext<'_>) -> ParserResult { OneOrMoreHelper::run(input, |input| { - self.modifier_attribute(input).with_name(FieldName::Item) + self.modifier_attribute(input).with_label(NodeLabel::Item) }) .with_kind(RuleKind::ModifierAttributes) } @@ -3401,29 +3405,29 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn modifier_definition(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::ModifierKeyword, + seq.elem_labeled( + NodeLabel::ModifierKeyword, self.parse_token_with_trivia::( input, TokenKind::ModifierKeyword, ), )?; - seq.elem_named( - FieldName::Name, + seq.elem_labeled( + NodeLabel::Name, self.parse_token_with_trivia::( input, TokenKind::Identifier, ), )?; - seq.elem_named( - FieldName::Parameters, + seq.elem_labeled( + NodeLabel::Parameters, OptionalHelper::transform(self.parameters_declaration(input)), )?; - seq.elem_named( - FieldName::Attributes, + seq.elem_labeled( + NodeLabel::Attributes, OptionalHelper::transform(self.modifier_attributes(input)), )?; - seq.elem_named(FieldName::Body, self.function_body(input))?; + seq.elem_labeled(NodeLabel::Body, self.function_body(input))?; seq.finish() }) .with_kind(RuleKind::ModifierDefinition) @@ -3432,9 +3436,9 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn modifier_invocation(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named(FieldName::Name, self.identifier_path(input))?; - seq.elem_named( - FieldName::Arguments, + seq.elem_labeled(NodeLabel::Name, self.identifier_path(input))?; + seq.elem_labeled( + NodeLabel::Arguments, OptionalHelper::transform(self.arguments_declaration(input)), )?; seq.finish() @@ -3449,12 +3453,12 @@ impl Language { return result; }; match &r#match.nodes[..] { - [cst::NamedNode { - name: _, + [cst::LabeledNode { + label: _, node: cst::Node::Rule(node), }] if node.kind == RuleKind::Expression => match &node.children[..] { - [inner @ cst::NamedNode { - name: _, + [inner @ cst::LabeledNode { + label: _, node: cst::Node::Rule(rule), }] if rule.kind == RuleKind::MultiplicativeExpression => { ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) @@ -3468,21 +3472,21 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn named_argument(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::Name, + seq.elem_labeled( + NodeLabel::Name, self.parse_token_with_trivia::( input, TokenKind::Identifier, ), )?; - seq.elem_named( - FieldName::Colon, + seq.elem_labeled( + NodeLabel::Colon, self.parse_token_with_trivia::( input, TokenKind::Colon, ), )?; - seq.elem_named(FieldName::Value, self.expression(input))?; + seq.elem_labeled(NodeLabel::Value, self.expression(input))?; seq.finish() }) .with_kind(RuleKind::NamedArgument) @@ -3493,8 +3497,8 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenBrace, + seq.elem_labeled( + NodeLabel::OpenBrace, self.parse_token_with_trivia::( input, TokenKind::OpenBrace, @@ -3502,7 +3506,7 @@ impl Language { )?; seq.elem( OptionalHelper::transform(self.named_arguments(input)) - .with_name(FieldName::Arguments) + .with_label(NodeLabel::Arguments) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -3510,8 +3514,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseBrace, + seq.elem_labeled( + NodeLabel::CloseBrace, self.parse_token_with_trivia::( input, TokenKind::CloseBrace, @@ -3526,7 +3530,7 @@ impl Language { fn named_argument_groups(&self, input: &mut ParserContext<'_>) -> ParserResult { if self.version_is_at_least_0_6_2 && !self.version_is_at_least_0_8_0 { OneOrMoreHelper::run(input, |input| { - self.named_argument_group(input).with_name(FieldName::Item) + self.named_argument_group(input).with_label(NodeLabel::Item) }) } else { ParserResult::disabled() @@ -3539,9 +3543,9 @@ impl Language { SeparatedHelper::run::<_, LexicalContextType::Default>( input, self, - |input| self.named_argument(input).with_name(FieldName::Item), + |input| self.named_argument(input).with_label(NodeLabel::Item), TokenKind::Comma, - FieldName::Separator, + NodeLabel::Separator, ) .with_kind(RuleKind::NamedArguments) } @@ -3551,8 +3555,8 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenParen, + seq.elem_labeled( + NodeLabel::OpenParen, self.parse_token_with_trivia::( input, TokenKind::OpenParen, @@ -3560,7 +3564,7 @@ impl Language { )?; seq.elem( OptionalHelper::transform(self.named_argument_group(input)) - .with_name(FieldName::Arguments) + .with_label(NodeLabel::Arguments) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -3568,8 +3572,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseParen, + seq.elem_labeled( + NodeLabel::CloseParen, self.parse_token_with_trivia::( input, TokenKind::CloseParen, @@ -3583,22 +3587,22 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn named_import(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::Asterisk, + seq.elem_labeled( + NodeLabel::Asterisk, self.parse_token_with_trivia::( input, TokenKind::Asterisk, ), )?; - seq.elem_named(FieldName::Alias, self.import_alias(input))?; - seq.elem_named( - FieldName::FromKeyword, + seq.elem_labeled(NodeLabel::Alias, self.import_alias(input))?; + seq.elem_labeled( + NodeLabel::FromKeyword, self.parse_token_with_trivia::( input, TokenKind::FromKeyword, ), )?; - seq.elem_named(FieldName::Path, self.string_literal(input))?; + seq.elem_labeled(NodeLabel::Path, self.string_literal(input))?; seq.finish() }) .with_kind(RuleKind::NamedImport) @@ -3607,14 +3611,14 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn new_expression(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::NewKeyword, + seq.elem_labeled( + NodeLabel::NewKeyword, self.parse_token_with_trivia::( input, TokenKind::NewKeyword, ), )?; - seq.elem_named(FieldName::TypeName, self.type_name(input))?; + seq.elem_labeled(NodeLabel::TypeName, self.type_name(input))?; seq.finish() }) .with_kind(RuleKind::NewExpression) @@ -3688,7 +3692,7 @@ impl Language { } choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::NumberUnit) } @@ -3699,12 +3703,12 @@ impl Language { return result; }; match &r#match.nodes[..] { - [cst::NamedNode { - name: _, + [cst::LabeledNode { + label: _, node: cst::Node::Rule(node), }] if node.kind == RuleKind::Expression => match &node.children[..] { - [inner @ cst::NamedNode { - name: _, + [inner @ cst::LabeledNode { + label: _, node: cst::Node::Rule(rule), }] if rule.kind == RuleKind::OrExpression => { ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) @@ -3720,9 +3724,9 @@ impl Language { SeparatedHelper::run::<_, LexicalContextType::Default>( input, self, - |input| self.identifier_path(input).with_name(FieldName::Item), + |input| self.identifier_path(input).with_label(NodeLabel::Item), TokenKind::Comma, - FieldName::Separator, + NodeLabel::Separator, ) .with_kind(RuleKind::OverridePaths) } @@ -3732,8 +3736,8 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenParen, + seq.elem_labeled( + NodeLabel::OpenParen, self.parse_token_with_trivia::( input, TokenKind::OpenParen, @@ -3741,7 +3745,7 @@ impl Language { )?; seq.elem( self.override_paths(input) - .with_name(FieldName::Paths) + .with_label(NodeLabel::Paths) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -3749,8 +3753,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseParen, + seq.elem_labeled( + NodeLabel::CloseParen, self.parse_token_with_trivia::( input, TokenKind::CloseParen, @@ -3764,15 +3768,15 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn override_specifier(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::OverrideKeyword, + seq.elem_labeled( + NodeLabel::OverrideKeyword, self.parse_token_with_trivia::( input, TokenKind::OverrideKeyword, ), )?; - seq.elem_named( - FieldName::Overridden, + seq.elem_labeled( + NodeLabel::Overridden, OptionalHelper::transform(self.override_paths_declaration(input)), )?; seq.finish() @@ -3783,13 +3787,13 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn parameter(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named(FieldName::TypeName, self.type_name(input))?; - seq.elem_named( - FieldName::StorageLocation, + seq.elem_labeled(NodeLabel::TypeName, self.type_name(input))?; + seq.elem_labeled( + NodeLabel::StorageLocation, OptionalHelper::transform(self.storage_location(input)), )?; - seq.elem_named( - FieldName::Name, + seq.elem_labeled( + NodeLabel::Name, OptionalHelper::transform( self.parse_token_with_trivia::( input, @@ -3807,9 +3811,9 @@ impl Language { SeparatedHelper::run::<_, LexicalContextType::Default>( input, self, - |input| self.parameter(input).with_name(FieldName::Item), + |input| self.parameter(input).with_label(NodeLabel::Item), TokenKind::Comma, - FieldName::Separator, + NodeLabel::Separator, ) .with_kind(RuleKind::Parameters) } @@ -3819,8 +3823,8 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenParen, + seq.elem_labeled( + NodeLabel::OpenParen, self.parse_token_with_trivia::( input, TokenKind::OpenParen, @@ -3828,7 +3832,7 @@ impl Language { )?; seq.elem( OptionalHelper::transform(self.parameters(input)) - .with_name(FieldName::Parameters) + .with_label(NodeLabel::Parameters) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -3836,8 +3840,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseParen, + seq.elem_labeled( + NodeLabel::CloseParen, self.parse_token_with_trivia::( input, TokenKind::CloseParen, @@ -3851,9 +3855,9 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn path_import(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named(FieldName::Path, self.string_literal(input))?; - seq.elem_named( - FieldName::Alias, + seq.elem_labeled(NodeLabel::Path, self.string_literal(input))?; + seq.elem_labeled( + NodeLabel::Alias, OptionalHelper::transform(self.import_alias(input)), )?; seq.finish() @@ -3866,9 +3870,9 @@ impl Language { SeparatedHelper::run::<_, LexicalContextType::Default>( input, self, - |input| self.expression(input).with_name(FieldName::Item), + |input| self.expression(input).with_label(NodeLabel::Item), TokenKind::Comma, - FieldName::Separator, + NodeLabel::Separator, ) .with_kind(RuleKind::PositionalArguments) } @@ -3878,8 +3882,8 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenParen, + seq.elem_labeled( + NodeLabel::OpenParen, self.parse_token_with_trivia::( input, TokenKind::OpenParen, @@ -3887,7 +3891,7 @@ impl Language { )?; seq.elem( OptionalHelper::transform(self.positional_arguments(input)) - .with_name(FieldName::Arguments) + .with_label(NodeLabel::Arguments) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -3895,8 +3899,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseParen, + seq.elem_labeled( + NodeLabel::CloseParen, self.parse_token_with_trivia::( input, TokenKind::CloseParen, @@ -3914,12 +3918,12 @@ impl Language { return result; }; match &r#match.nodes[..] { - [cst::NamedNode { - name: _, + [cst::LabeledNode { + label: _, node: cst::Node::Rule(node), }] if node.kind == RuleKind::Expression => match &node.children[..] { - [inner @ cst::NamedNode { - name: _, + [inner @ cst::LabeledNode { + label: _, node: cst::Node::Rule(rule), }] if rule.kind == RuleKind::PostfixExpression => { ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) @@ -3941,7 +3945,7 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::Pragma) } @@ -3950,14 +3954,14 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::PragmaKeyword, + seq.elem_labeled( + NodeLabel::PragmaKeyword, self.parse_token_with_trivia::( input, TokenKind::PragmaKeyword, ), )?; - seq.elem_named(FieldName::Pragma, self.pragma(input))?; + seq.elem_labeled(NodeLabel::Pragma, self.pragma(input))?; seq.finish() }) .recover_until_with_nested_delims::<_, LexicalContextType::Pragma>( @@ -3967,8 +3971,8 @@ impl Language { RecoverFromNoMatch::No, ), )?; - seq.elem_named( - FieldName::Semicolon, + seq.elem_labeled( + NodeLabel::Semicolon, self.parse_token_with_trivia::( input, TokenKind::Semicolon, @@ -3986,12 +3990,12 @@ impl Language { return result; }; match &r#match.nodes[..] { - [cst::NamedNode { - name: _, + [cst::LabeledNode { + label: _, node: cst::Node::Rule(node), }] if node.kind == RuleKind::Expression => match &node.children[..] { - [inner @ cst::NamedNode { - name: _, + [inner @ cst::LabeledNode { + label: _, node: cst::Node::Rule(rule), }] if rule.kind == RuleKind::PrefixExpression => { ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) @@ -4027,7 +4031,7 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) } else { ParserResult::disabled() } @@ -4039,7 +4043,7 @@ impl Language { if self.version_is_at_least_0_6_0 { OneOrMoreHelper::run(input, |input| { self.receive_function_attribute(input) - .with_name(FieldName::Item) + .with_label(NodeLabel::Item) }) } else { ParserResult::disabled() @@ -4051,19 +4055,19 @@ impl Language { fn receive_function_definition(&self, input: &mut ParserContext<'_>) -> ParserResult { if self.version_is_at_least_0_6_0 { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::ReceiveKeyword, + seq.elem_labeled( + NodeLabel::ReceiveKeyword, self.parse_token_with_trivia::( input, TokenKind::ReceiveKeyword, ), )?; - seq.elem_named(FieldName::Parameters, self.parameters_declaration(input))?; - seq.elem_named( - FieldName::Attributes, + seq.elem_labeled(NodeLabel::Parameters, self.parameters_declaration(input))?; + seq.elem_labeled( + NodeLabel::Attributes, OptionalHelper::transform(self.receive_function_attributes(input)), )?; - seq.elem_named(FieldName::Body, self.function_body(input))?; + seq.elem_labeled(NodeLabel::Body, self.function_body(input))?; seq.finish() }) } else { @@ -4077,15 +4081,15 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::ReturnKeyword, + seq.elem_labeled( + NodeLabel::ReturnKeyword, self.parse_token_with_trivia::( input, TokenKind::ReturnKeyword, ), )?; - seq.elem_named( - FieldName::Expression, + seq.elem_labeled( + NodeLabel::Expression, OptionalHelper::transform(self.expression(input)), )?; seq.finish() @@ -4097,8 +4101,8 @@ impl Language { RecoverFromNoMatch::No, ), )?; - seq.elem_named( - FieldName::Semicolon, + seq.elem_labeled( + NodeLabel::Semicolon, self.parse_token_with_trivia::( input, TokenKind::Semicolon, @@ -4112,14 +4116,14 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn returns_declaration(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::ReturnsKeyword, + seq.elem_labeled( + NodeLabel::ReturnsKeyword, self.parse_token_with_trivia::( input, TokenKind::ReturnsKeyword, ), )?; - seq.elem_named(FieldName::Variables, self.parameters_declaration(input))?; + seq.elem_labeled(NodeLabel::Variables, self.parameters_declaration(input))?; seq.finish() }) .with_kind(RuleKind::ReturnsDeclaration) @@ -4131,18 +4135,18 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::RevertKeyword, + seq.elem_labeled( + NodeLabel::RevertKeyword, self.parse_token_with_trivia::( input, TokenKind::RevertKeyword, ), )?; - seq.elem_named( - FieldName::Error, + seq.elem_labeled( + NodeLabel::Error, OptionalHelper::transform(self.identifier_path(input)), )?; - seq.elem_named(FieldName::Arguments, self.arguments_declaration(input))?; + seq.elem_labeled(NodeLabel::Arguments, self.arguments_declaration(input))?; seq.finish() }) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( @@ -4152,8 +4156,8 @@ impl Language { RecoverFromNoMatch::No, ), )?; - seq.elem_named( - FieldName::Semicolon, + seq.elem_labeled( + NodeLabel::Semicolon, self.parse_token_with_trivia::( input, TokenKind::Semicolon, @@ -4174,12 +4178,12 @@ impl Language { return result; }; match &r#match.nodes[..] { - [cst::NamedNode { - name: _, + [cst::LabeledNode { + label: _, node: cst::Node::Rule(node), }] if node.kind == RuleKind::Expression => match &node.children[..] { - [inner @ cst::NamedNode { - name: _, + [inner @ cst::LabeledNode { + label: _, node: cst::Node::Rule(rule), }] if rule.kind == RuleKind::ShiftExpression => { ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) @@ -4193,7 +4197,7 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn source_unit(&self, input: &mut ParserContext<'_>) -> ParserResult { OptionalHelper::transform(self.source_unit_members(input)) - .with_name(FieldName::Members) + .with_label(NodeLabel::Members) .with_kind(RuleKind::SourceUnit) } @@ -4244,14 +4248,14 @@ impl Language { } choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::SourceUnitMember) } #[allow(unused_assignments, unused_parens)] fn source_unit_members(&self, input: &mut ParserContext<'_>) -> ParserResult { OneOrMoreHelper::run(input, |input| { - self.source_unit_member(input).with_name(FieldName::Item) + self.source_unit_member(input).with_label(NodeLabel::Item) }) .with_kind(RuleKind::SourceUnitMembers) } @@ -4290,7 +4294,7 @@ impl Language { } choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::StateVariableAttribute) } @@ -4298,7 +4302,7 @@ impl Language { fn state_variable_attributes(&self, input: &mut ParserContext<'_>) -> ParserResult { OneOrMoreHelper::run(input, |input| { self.state_variable_attribute(input) - .with_name(FieldName::Item) + .with_label(NodeLabel::Item) }) .with_kind(RuleKind::StateVariableAttributes) } @@ -4308,20 +4312,20 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem_named(FieldName::TypeName, self.type_name(input))?; - seq.elem_named( - FieldName::Attributes, + seq.elem_labeled(NodeLabel::TypeName, self.type_name(input))?; + seq.elem_labeled( + NodeLabel::Attributes, OptionalHelper::transform(self.state_variable_attributes(input)), )?; - seq.elem_named( - FieldName::Name, + seq.elem_labeled( + NodeLabel::Name, self.parse_token_with_trivia::( input, TokenKind::Identifier, ), )?; - seq.elem_named( - FieldName::Value, + seq.elem_labeled( + NodeLabel::Value, OptionalHelper::transform(self.state_variable_definition_value(input)), )?; seq.finish() @@ -4333,8 +4337,8 @@ impl Language { RecoverFromNoMatch::No, ), )?; - seq.elem_named( - FieldName::Semicolon, + seq.elem_labeled( + NodeLabel::Semicolon, self.parse_token_with_trivia::( input, TokenKind::Semicolon, @@ -4348,14 +4352,14 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn state_variable_definition_value(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::Equal, + seq.elem_labeled( + NodeLabel::Equal, self.parse_token_with_trivia::( input, TokenKind::Equal, ), )?; - seq.elem_named(FieldName::Value, self.expression(input))?; + seq.elem_labeled(NodeLabel::Value, self.expression(input))?; seq.finish() }) .with_kind(RuleKind::StateVariableDefinitionValue) @@ -4412,14 +4416,14 @@ impl Language { } choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::Statement) } #[allow(unused_assignments, unused_parens)] fn statements(&self, input: &mut ParserContext<'_>) -> ParserResult { OneOrMoreHelper::run(input, |input| { - self.statement(input).with_name(FieldName::Item) + self.statement(input).with_label(NodeLabel::Item) }) .with_kind(RuleKind::Statements) } @@ -4446,7 +4450,7 @@ impl Language { } choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::StorageLocation) } @@ -4475,7 +4479,7 @@ impl Language { } choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::StringExpression) } @@ -4494,7 +4498,7 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::StringLiteral) } @@ -4502,7 +4506,7 @@ impl Language { fn string_literals(&self, input: &mut ParserContext<'_>) -> ParserResult { if self.version_is_at_least_0_5_14 { OneOrMoreHelper::run(input, |input| { - self.string_literal(input).with_name(FieldName::Item) + self.string_literal(input).with_label(NodeLabel::Item) }) } else { ParserResult::disabled() @@ -4513,15 +4517,15 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn struct_definition(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::StructKeyword, + seq.elem_labeled( + NodeLabel::StructKeyword, self.parse_token_with_trivia::( input, TokenKind::StructKeyword, ), )?; - seq.elem_named( - FieldName::Name, + seq.elem_labeled( + NodeLabel::Name, self.parse_token_with_trivia::( input, TokenKind::Identifier, @@ -4530,8 +4534,8 @@ impl Language { seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenBrace, + seq.elem_labeled( + NodeLabel::OpenBrace, self.parse_token_with_trivia::( input, TokenKind::OpenBrace, @@ -4539,7 +4543,7 @@ impl Language { )?; seq.elem( OptionalHelper::transform(self.struct_members(input)) - .with_name(FieldName::Members) + .with_label(NodeLabel::Members) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -4547,8 +4551,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseBrace, + seq.elem_labeled( + NodeLabel::CloseBrace, self.parse_token_with_trivia::( input, TokenKind::CloseBrace, @@ -4566,9 +4570,9 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem_named(FieldName::TypeName, self.type_name(input))?; - seq.elem_named( - FieldName::Name, + seq.elem_labeled(NodeLabel::TypeName, self.type_name(input))?; + seq.elem_labeled( + NodeLabel::Name, self.parse_token_with_trivia::( input, TokenKind::Identifier, @@ -4583,8 +4587,8 @@ impl Language { RecoverFromNoMatch::No, ), )?; - seq.elem_named( - FieldName::Semicolon, + seq.elem_labeled( + NodeLabel::Semicolon, self.parse_token_with_trivia::( input, TokenKind::Semicolon, @@ -4598,7 +4602,7 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn struct_members(&self, input: &mut ParserContext<'_>) -> ParserResult { OneOrMoreHelper::run(input, |input| { - self.struct_member(input).with_name(FieldName::Item) + self.struct_member(input).with_label(NodeLabel::Item) }) .with_kind(RuleKind::StructMembers) } @@ -4612,7 +4616,7 @@ impl Language { input, TokenKind::ThrowKeyword, ) - .with_name(FieldName::ThrowKeyword) + .with_label(NodeLabel::ThrowKeyword) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -4620,8 +4624,8 @@ impl Language { RecoverFromNoMatch::No, ), )?; - seq.elem_named( - FieldName::Semicolon, + seq.elem_labeled( + NodeLabel::Semicolon, self.parse_token_with_trivia::( input, TokenKind::Semicolon, @@ -4657,20 +4661,20 @@ impl Language { fn try_statement(&self, input: &mut ParserContext<'_>) -> ParserResult { if self.version_is_at_least_0_6_0 { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::TryKeyword, + seq.elem_labeled( + NodeLabel::TryKeyword, self.parse_token_with_trivia::( input, TokenKind::TryKeyword, ), )?; - seq.elem_named(FieldName::Expression, self.expression(input))?; - seq.elem_named( - FieldName::Returns, + seq.elem_labeled(NodeLabel::Expression, self.expression(input))?; + seq.elem_labeled( + NodeLabel::Returns, OptionalHelper::transform(self.returns_declaration(input)), )?; - seq.elem_named(FieldName::Body, self.block(input))?; - seq.elem_named(FieldName::CatchClauses, self.catch_clauses(input))?; + seq.elem_labeled(NodeLabel::Body, self.block(input))?; + seq.elem_labeled(NodeLabel::CatchClauses, self.catch_clauses(input))?; seq.finish() }) } else { @@ -4682,7 +4686,7 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn tuple_deconstruction_element(&self, input: &mut ParserContext<'_>) -> ParserResult { OptionalHelper::transform(self.tuple_member(input)) - .with_name(FieldName::Member) + .with_label(NodeLabel::Member) .with_kind(RuleKind::TupleDeconstructionElement) } @@ -4693,10 +4697,10 @@ impl Language { self, |input| { self.tuple_deconstruction_element(input) - .with_name(FieldName::Item) + .with_label(NodeLabel::Item) }, TokenKind::Comma, - FieldName::Separator, + NodeLabel::Separator, ) .with_kind(RuleKind::TupleDeconstructionElements) } @@ -4707,8 +4711,8 @@ impl Language { seq.elem( SequenceHelper::run(|mut seq| { if !self.version_is_at_least_0_5_0 { - seq.elem_named( - FieldName::VarKeyword, + seq.elem_labeled( + NodeLabel::VarKeyword, OptionalHelper::transform( self.parse_token_with_trivia::( input, @@ -4720,8 +4724,8 @@ impl Language { seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenParen, + seq.elem_labeled( + NodeLabel::OpenParen, self.parse_token_with_trivia::( input, TokenKind::OpenParen, @@ -4729,7 +4733,7 @@ impl Language { )?; seq.elem( self.tuple_deconstruction_elements(input) - .with_name(FieldName::Elements) + .with_label(NodeLabel::Elements) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -4737,8 +4741,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseParen, + seq.elem_labeled( + NodeLabel::CloseParen, self.parse_token_with_trivia::( input, TokenKind::CloseParen, @@ -4746,14 +4750,14 @@ impl Language { )?; seq.finish() }))?; - seq.elem_named( - FieldName::Equal, + seq.elem_labeled( + NodeLabel::Equal, self.parse_token_with_trivia::( input, TokenKind::Equal, ), )?; - seq.elem_named(FieldName::Expression, self.expression(input))?; + seq.elem_labeled(NodeLabel::Expression, self.expression(input))?; seq.finish() }) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( @@ -4763,8 +4767,8 @@ impl Language { RecoverFromNoMatch::No, ), )?; - seq.elem_named( - FieldName::Semicolon, + seq.elem_labeled( + NodeLabel::Semicolon, self.parse_token_with_trivia::( input, TokenKind::Semicolon, @@ -4780,8 +4784,8 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenParen, + seq.elem_labeled( + NodeLabel::OpenParen, self.parse_token_with_trivia::( input, TokenKind::OpenParen, @@ -4789,7 +4793,7 @@ impl Language { )?; seq.elem( self.tuple_values(input) - .with_name(FieldName::Items) + .with_label(NodeLabel::Items) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -4797,8 +4801,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseParen, + seq.elem_labeled( + NodeLabel::CloseParen, self.parse_token_with_trivia::( input, TokenKind::CloseParen, @@ -4818,14 +4822,14 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::TupleMember) } #[allow(unused_assignments, unused_parens)] fn tuple_value(&self, input: &mut ParserContext<'_>) -> ParserResult { OptionalHelper::transform(self.expression(input)) - .with_name(FieldName::Expression) + .with_label(NodeLabel::Expression) .with_kind(RuleKind::TupleValue) } @@ -4834,9 +4838,9 @@ impl Language { SeparatedHelper::run::<_, LexicalContextType::Default>( input, self, - |input| self.tuple_value(input).with_name(FieldName::Item), + |input| self.tuple_value(input).with_label(NodeLabel::Item), TokenKind::Comma, - FieldName::Separator, + NodeLabel::Separator, ) .with_kind(RuleKind::TupleValues) } @@ -4845,8 +4849,8 @@ impl Language { fn type_expression(&self, input: &mut ParserContext<'_>) -> ParserResult { if self.version_is_at_least_0_5_3 { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::TypeKeyword, + seq.elem_labeled( + NodeLabel::TypeKeyword, self.parse_token_with_trivia::( input, TokenKind::TypeKeyword, @@ -4855,8 +4859,8 @@ impl Language { seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenParen, + seq.elem_labeled( + NodeLabel::OpenParen, self.parse_token_with_trivia::( input, TokenKind::OpenParen, @@ -4864,7 +4868,7 @@ impl Language { )?; seq.elem( self.type_name(input) - .with_name(FieldName::TypeName) + .with_label(NodeLabel::TypeName) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -4872,8 +4876,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseParen, + seq.elem_labeled( + NodeLabel::CloseParen, self.parse_token_with_trivia::( input, TokenKind::CloseParen, @@ -4898,8 +4902,8 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBracket); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenBracket, + seq.elem_labeled( + NodeLabel::OpenBracket, self.parse_token_with_trivia::( input, TokenKind::OpenBracket, @@ -4907,7 +4911,7 @@ impl Language { )?; seq.elem( OptionalHelper::transform(self.expression(input)) - .with_name(FieldName::Index) + .with_label(NodeLabel::Index) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -4915,8 +4919,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseBracket, + seq.elem_labeled( + NodeLabel::CloseBracket, self.parse_token_with_trivia::( input, TokenKind::CloseBracket, @@ -4938,7 +4942,7 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) }; let postfix_operator_parser = |input: &mut ParserContext<'_>| { ChoiceHelper::run(input, |mut choice, input| { @@ -4964,13 +4968,13 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn typed_tuple_member(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named(FieldName::TypeName, self.type_name(input))?; - seq.elem_named( - FieldName::StorageLocation, + seq.elem_labeled(NodeLabel::TypeName, self.type_name(input))?; + seq.elem_labeled( + NodeLabel::StorageLocation, OptionalHelper::transform(self.storage_location(input)), )?; - seq.elem_named( - FieldName::Name, + seq.elem_labeled( + NodeLabel::Name, self.parse_token_with_trivia::( input, TokenKind::Identifier, @@ -4985,14 +4989,14 @@ impl Language { fn unchecked_block(&self, input: &mut ParserContext<'_>) -> ParserResult { if self.version_is_at_least_0_8_0 { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::UncheckedKeyword, + seq.elem_labeled( + NodeLabel::UncheckedKeyword, self.parse_token_with_trivia::( input, TokenKind::UncheckedKeyword, ), )?; - seq.elem_named(FieldName::Block, self.block(input))?; + seq.elem_labeled(NodeLabel::Block, self.block(input))?; seq.finish() }) } else { @@ -5017,7 +5021,7 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) } else { ParserResult::disabled() } @@ -5029,7 +5033,7 @@ impl Language { if self.version_is_at_least_0_7_0 { OneOrMoreHelper::run(input, |input| { self.unicode_string_literal(input) - .with_name(FieldName::Item) + .with_label(NodeLabel::Item) }) } else { ParserResult::disabled() @@ -5088,7 +5092,7 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) } else { ParserResult::disabled() } @@ -5100,7 +5104,7 @@ impl Language { if !self.version_is_at_least_0_6_0 { OneOrMoreHelper::run(input, |input| { self.unnamed_function_attribute(input) - .with_name(FieldName::Item) + .with_label(NodeLabel::Item) }) } else { ParserResult::disabled() @@ -5112,19 +5116,19 @@ impl Language { fn unnamed_function_definition(&self, input: &mut ParserContext<'_>) -> ParserResult { if !self.version_is_at_least_0_6_0 { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::FunctionKeyword, + seq.elem_labeled( + NodeLabel::FunctionKeyword, self.parse_token_with_trivia::( input, TokenKind::FunctionKeyword, ), )?; - seq.elem_named(FieldName::Parameters, self.parameters_declaration(input))?; - seq.elem_named( - FieldName::Attributes, + seq.elem_labeled(NodeLabel::Parameters, self.parameters_declaration(input))?; + seq.elem_labeled( + NodeLabel::Attributes, OptionalHelper::transform(self.unnamed_function_attributes(input)), )?; - seq.elem_named(FieldName::Body, self.function_body(input))?; + seq.elem_labeled(NodeLabel::Body, self.function_body(input))?; seq.finish() }) } else { @@ -5136,12 +5140,12 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn untyped_tuple_member(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::StorageLocation, + seq.elem_labeled( + NodeLabel::StorageLocation, OptionalHelper::transform(self.storage_location(input)), )?; - seq.elem_named( - FieldName::Name, + seq.elem_labeled( + NodeLabel::Name, self.parse_token_with_trivia::( input, TokenKind::Identifier, @@ -5158,28 +5162,28 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::TypeKeyword, + seq.elem_labeled( + NodeLabel::TypeKeyword, self.parse_token_with_trivia::( input, TokenKind::TypeKeyword, ), )?; - seq.elem_named( - FieldName::Name, + seq.elem_labeled( + NodeLabel::Name, self.parse_token_with_trivia::( input, TokenKind::Identifier, ), )?; - seq.elem_named( - FieldName::IsKeyword, + seq.elem_labeled( + NodeLabel::IsKeyword, self.parse_token_with_trivia::( input, TokenKind::IsKeyword, ), )?; - seq.elem_named(FieldName::ValueType, self.elementary_type(input))?; + seq.elem_labeled(NodeLabel::ValueType, self.elementary_type(input))?; seq.finish() }) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( @@ -5189,8 +5193,8 @@ impl Language { RecoverFromNoMatch::No, ), )?; - seq.elem_named( - FieldName::Semicolon, + seq.elem_labeled( + NodeLabel::Semicolon, self.parse_token_with_trivia::( input, TokenKind::Semicolon, @@ -5208,14 +5212,14 @@ impl Language { fn using_alias(&self, input: &mut ParserContext<'_>) -> ParserResult { if self.version_is_at_least_0_8_19 { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::AsKeyword, + seq.elem_labeled( + NodeLabel::AsKeyword, self.parse_token_with_trivia::( input, TokenKind::AsKeyword, ), )?; - seq.elem_named(FieldName::Operator, self.using_operator(input))?; + seq.elem_labeled(NodeLabel::Operator, self.using_operator(input))?; seq.finish() }) } else { @@ -5235,7 +5239,7 @@ impl Language { } choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::UsingClause) } @@ -5245,8 +5249,8 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenBrace, + seq.elem_labeled( + NodeLabel::OpenBrace, self.parse_token_with_trivia::( input, TokenKind::OpenBrace, @@ -5254,7 +5258,7 @@ impl Language { )?; seq.elem( self.using_deconstruction_symbols(input) - .with_name(FieldName::Symbols) + .with_label(NodeLabel::Symbols) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -5262,8 +5266,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseBrace, + seq.elem_labeled( + NodeLabel::CloseBrace, self.parse_token_with_trivia::( input, TokenKind::CloseBrace, @@ -5281,10 +5285,10 @@ impl Language { fn using_deconstruction_symbol(&self, input: &mut ParserContext<'_>) -> ParserResult { if self.version_is_at_least_0_8_13 { SequenceHelper::run(|mut seq| { - seq.elem_named(FieldName::Name, self.identifier_path(input))?; + seq.elem_labeled(NodeLabel::Name, self.identifier_path(input))?; if self.version_is_at_least_0_8_19 { - seq.elem_named( - FieldName::Alias, + seq.elem_labeled( + NodeLabel::Alias, OptionalHelper::transform(self.using_alias(input)), )?; } @@ -5304,10 +5308,10 @@ impl Language { self, |input| { self.using_deconstruction_symbol(input) - .with_name(FieldName::Item) + .with_label(NodeLabel::Item) }, TokenKind::Comma, - FieldName::Separator, + NodeLabel::Separator, ) } else { ParserResult::disabled() @@ -5320,25 +5324,25 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::UsingKeyword, + seq.elem_labeled( + NodeLabel::UsingKeyword, self.parse_token_with_trivia::( input, TokenKind::UsingKeyword, ), )?; - seq.elem_named(FieldName::Clause, self.using_clause(input))?; - seq.elem_named( - FieldName::ForKeyword, + seq.elem_labeled(NodeLabel::Clause, self.using_clause(input))?; + seq.elem_labeled( + NodeLabel::ForKeyword, self.parse_token_with_trivia::( input, TokenKind::ForKeyword, ), )?; - seq.elem_named(FieldName::Target, self.using_target(input))?; + seq.elem_labeled(NodeLabel::Target, self.using_target(input))?; if self.version_is_at_least_0_8_13 { - seq.elem_named( - FieldName::GlobalKeyword, + seq.elem_labeled( + NodeLabel::GlobalKeyword, OptionalHelper::transform( self.parse_token_with_trivia::( input, @@ -5356,8 +5360,8 @@ impl Language { RecoverFromNoMatch::No, ), )?; - seq.elem_named( - FieldName::Semicolon, + seq.elem_labeled( + NodeLabel::Semicolon, self.parse_token_with_trivia::( input, TokenKind::Semicolon, @@ -5445,7 +5449,7 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) } else { ParserResult::disabled() } @@ -5462,7 +5466,7 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::UsingTarget) } @@ -5471,23 +5475,23 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::VariableType, + seq.elem_labeled( + NodeLabel::VariableType, self.variable_declaration_type(input), )?; - seq.elem_named( - FieldName::StorageLocation, + seq.elem_labeled( + NodeLabel::StorageLocation, OptionalHelper::transform(self.storage_location(input)), )?; - seq.elem_named( - FieldName::Name, + seq.elem_labeled( + NodeLabel::Name, self.parse_token_with_trivia::( input, TokenKind::Identifier, ), )?; - seq.elem_named( - FieldName::Value, + seq.elem_labeled( + NodeLabel::Value, OptionalHelper::transform(self.variable_declaration_value(input)), )?; seq.finish() @@ -5499,8 +5503,8 @@ impl Language { RecoverFromNoMatch::No, ), )?; - seq.elem_named( - FieldName::Semicolon, + seq.elem_labeled( + NodeLabel::Semicolon, self.parse_token_with_trivia::( input, TokenKind::Semicolon, @@ -5525,21 +5529,21 @@ impl Language { } choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::VariableDeclarationType) } #[allow(unused_assignments, unused_parens)] fn variable_declaration_value(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::Equal, + seq.elem_labeled( + NodeLabel::Equal, self.parse_token_with_trivia::( input, TokenKind::Equal, ), )?; - seq.elem_named(FieldName::Expression, self.expression(input))?; + seq.elem_labeled(NodeLabel::Expression, self.expression(input))?; seq.finish() }) .with_kind(RuleKind::VariableDeclarationValue) @@ -5548,15 +5552,15 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn version_pragma(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::SolidityKeyword, + seq.elem_labeled( + NodeLabel::SolidityKeyword, self.parse_token_with_trivia::( input, TokenKind::SolidityKeyword, ), )?; - seq.elem_named( - FieldName::Expressions, + seq.elem_labeled( + NodeLabel::Expressions, self.version_pragma_expressions(input), )?; seq.finish() @@ -5575,7 +5579,7 @@ impl Language { input, TokenKind::BarBar, ) - .with_name(FieldName::Operator), + .with_label(NodeLabel::Operator), ) }; let parse_left_version_pragma_range_expression = |input: &mut ParserContext<'_>| { @@ -5584,7 +5588,7 @@ impl Language { 3u8, 3u8 + 1, self.parse_token_with_trivia::(input, TokenKind::Minus) - .with_name(FieldName::Operator), + .with_label(NodeLabel::Operator), ) }; let parse_prefix_version_pragma_prefix_expression = |input: &mut ParserContext<'_>| { @@ -5597,49 +5601,49 @@ impl Language { input, TokenKind::Caret, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::Tilde, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::Equal, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::LessThan, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::GreaterThan, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::LessThanEqual, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; let result = self .parse_token_with_trivia::( input, TokenKind::GreaterThanEqual, ) - .with_name(FieldName::Operator); + .with_label(NodeLabel::Operator); choice.consider(input, result)?; choice.finish(input) }), @@ -5658,7 +5662,7 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) }; let binary_operand_parser = |input: &mut ParserContext<'_>| { SequenceHelper::run(|mut seq| { @@ -5700,7 +5704,7 @@ impl Language { fn version_pragma_expressions(&self, input: &mut ParserContext<'_>) -> ParserResult { OneOrMoreHelper::run(input, |input| { self.version_pragma_expression(input) - .with_name(FieldName::Item) + .with_label(NodeLabel::Item) }) .with_kind(RuleKind::VersionPragmaExpressions) } @@ -5712,12 +5716,12 @@ impl Language { return result; }; match &r#match.nodes[..] { - [cst::NamedNode { - name: _, + [cst::LabeledNode { + label: _, node: cst::Node::Rule(node), }] if node.kind == RuleKind::VersionPragmaExpression => match &node.children[..] { - [inner @ cst::NamedNode { - name: _, + [inner @ cst::LabeledNode { + label: _, node: cst::Node::Rule(rule), }] if rule.kind == RuleKind::VersionPragmaOrExpression => { ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) @@ -5735,12 +5739,12 @@ impl Language { return result; }; match &r#match.nodes[..] { - [cst::NamedNode { - name: _, + [cst::LabeledNode { + label: _, node: cst::Node::Rule(node), }] if node.kind == RuleKind::VersionPragmaExpression => match &node.children[..] { - [inner @ cst::NamedNode { - name: _, + [inner @ cst::LabeledNode { + label: _, node: cst::Node::Rule(rule), }] if rule.kind == RuleKind::VersionPragmaPrefixExpression => { ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) @@ -5758,12 +5762,12 @@ impl Language { return result; }; match &r#match.nodes[..] { - [cst::NamedNode { - name: _, + [cst::LabeledNode { + label: _, node: cst::Node::Rule(node), }] if node.kind == RuleKind::VersionPragmaExpression => match &node.children[..] { - [inner @ cst::NamedNode { - name: _, + [inner @ cst::LabeledNode { + label: _, node: cst::Node::Rule(rule), }] if rule.kind == RuleKind::VersionPragmaRangeExpression => { ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) @@ -5784,10 +5788,10 @@ impl Language { input, TokenKind::VersionPragmaValue, ) - .with_name(FieldName::Item) + .with_label(NodeLabel::Item) }, TokenKind::Period, - FieldName::Separator, + NodeLabel::Separator, ) .with_kind(RuleKind::VersionPragmaSpecifier) } @@ -5795,8 +5799,8 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn while_statement(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::WhileKeyword, + seq.elem_labeled( + NodeLabel::WhileKeyword, self.parse_token_with_trivia::( input, TokenKind::WhileKeyword, @@ -5805,8 +5809,8 @@ impl Language { seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenParen, + seq.elem_labeled( + NodeLabel::OpenParen, self.parse_token_with_trivia::( input, TokenKind::OpenParen, @@ -5814,7 +5818,7 @@ impl Language { )?; seq.elem( self.expression(input) - .with_name(FieldName::Condition) + .with_label(NodeLabel::Condition) .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, self, @@ -5822,8 +5826,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseParen, + seq.elem_labeled( + NodeLabel::CloseParen, self.parse_token_with_trivia::( input, TokenKind::CloseParen, @@ -5831,7 +5835,7 @@ impl Language { )?; seq.finish() }))?; - seq.elem_named(FieldName::Body, self.statement(input))?; + seq.elem_labeled(NodeLabel::Body, self.statement(input))?; seq.finish() }) .with_kind(RuleKind::WhileStatement) @@ -5842,9 +5846,9 @@ impl Language { SeparatedHelper::run::<_, LexicalContextType::Yul>( input, self, - |input| self.yul_expression(input).with_name(FieldName::Item), + |input| self.yul_expression(input).with_label(NodeLabel::Item), TokenKind::Comma, - FieldName::Separator, + NodeLabel::Separator, ) .with_kind(RuleKind::YulArguments) } @@ -5852,15 +5856,15 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_assignment_statement(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named(FieldName::Names, self.yul_identifier_paths(input))?; - seq.elem_named( - FieldName::ColonEqual, + seq.elem_labeled(NodeLabel::Names, self.yul_identifier_paths(input))?; + seq.elem_labeled( + NodeLabel::ColonEqual, self.parse_token_with_trivia::( input, TokenKind::ColonEqual, ), )?; - seq.elem_named(FieldName::Expression, self.yul_expression(input))?; + seq.elem_labeled(NodeLabel::Expression, self.yul_expression(input))?; seq.finish() }) .with_kind(RuleKind::YulAssignmentStatement) @@ -5871,8 +5875,8 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenBrace, + seq.elem_labeled( + NodeLabel::OpenBrace, self.parse_token_with_trivia::( input, TokenKind::OpenBrace, @@ -5880,7 +5884,7 @@ impl Language { )?; seq.elem( OptionalHelper::transform(self.yul_statements(input)) - .with_name(FieldName::Statements) + .with_label(NodeLabel::Statements) .recover_until_with_nested_delims::<_, LexicalContextType::Yul>( input, self, @@ -5888,8 +5892,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseBrace, + seq.elem_labeled( + NodeLabel::CloseBrace, self.parse_token_with_trivia::( input, TokenKind::CloseBrace, @@ -5903,7 +5907,7 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_break_statement(&self, input: &mut ParserContext<'_>) -> ParserResult { self.parse_token_with_trivia::(input, TokenKind::YulBreakKeyword) - .with_name(FieldName::BreakKeyword) + .with_label(NodeLabel::BreakKeyword) .with_kind(RuleKind::YulBreakStatement) } @@ -6306,7 +6310,7 @@ impl Language { } choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::YulBuiltInFunction) } @@ -6316,21 +6320,21 @@ impl Language { input, TokenKind::YulContinueKeyword, ) - .with_name(FieldName::ContinueKeyword) + .with_label(NodeLabel::ContinueKeyword) .with_kind(RuleKind::YulContinueStatement) } #[allow(unused_assignments, unused_parens)] fn yul_default_case(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::DefaultKeyword, + seq.elem_labeled( + NodeLabel::DefaultKeyword, self.parse_token_with_trivia::( input, TokenKind::YulDefaultKeyword, ), )?; - seq.elem_named(FieldName::Body, self.yul_block(input))?; + seq.elem_labeled(NodeLabel::Body, self.yul_block(input))?; seq.finish() }) .with_kind(RuleKind::YulDefaultCase) @@ -6345,8 +6349,8 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenParen, + seq.elem_labeled( + NodeLabel::OpenParen, self.parse_token_with_trivia::( input, TokenKind::OpenParen, @@ -6354,7 +6358,7 @@ impl Language { )?; seq.elem( OptionalHelper::transform(self.yul_arguments(input)) - .with_name(FieldName::Arguments) + .with_label(NodeLabel::Arguments) .recover_until_with_nested_delims::<_, LexicalContextType::Yul>( input, self, @@ -6362,8 +6366,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseParen, + seq.elem_labeled( + NodeLabel::CloseParen, self.parse_token_with_trivia::( input, TokenKind::CloseParen, @@ -6383,7 +6387,7 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) }; let postfix_operator_parser = |input: &mut ParserContext<'_>| { ChoiceHelper::run(input, |mut choice, input| { @@ -6409,17 +6413,17 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_for_statement(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::ForKeyword, + seq.elem_labeled( + NodeLabel::ForKeyword, self.parse_token_with_trivia::( input, TokenKind::YulForKeyword, ), )?; - seq.elem_named(FieldName::Initialization, self.yul_block(input))?; - seq.elem_named(FieldName::Condition, self.yul_expression(input))?; - seq.elem_named(FieldName::Iterator, self.yul_block(input))?; - seq.elem_named(FieldName::Body, self.yul_block(input))?; + seq.elem_labeled(NodeLabel::Initialization, self.yul_block(input))?; + seq.elem_labeled(NodeLabel::Condition, self.yul_expression(input))?; + seq.elem_labeled(NodeLabel::Iterator, self.yul_block(input))?; + seq.elem_labeled(NodeLabel::Body, self.yul_block(input))?; seq.finish() }) .with_kind(RuleKind::YulForStatement) @@ -6432,12 +6436,12 @@ impl Language { return result; }; match &r#match.nodes[..] { - [cst::NamedNode { - name: _, + [cst::LabeledNode { + label: _, node: cst::Node::Rule(node), }] if node.kind == RuleKind::YulExpression => match &node.children[..] { - [inner @ cst::NamedNode { - name: _, + [inner @ cst::LabeledNode { + label: _, node: cst::Node::Rule(rule), }] if rule.kind == RuleKind::YulFunctionCallExpression => { ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) @@ -6451,29 +6455,29 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_function_definition(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::FunctionKeyword, + seq.elem_labeled( + NodeLabel::FunctionKeyword, self.parse_token_with_trivia::( input, TokenKind::YulFunctionKeyword, ), )?; - seq.elem_named( - FieldName::Name, + seq.elem_labeled( + NodeLabel::Name, self.parse_token_with_trivia::( input, TokenKind::YulIdentifier, ), )?; - seq.elem_named( - FieldName::Parameters, + seq.elem_labeled( + NodeLabel::Parameters, self.yul_parameters_declaration(input), )?; - seq.elem_named( - FieldName::Returns, + seq.elem_labeled( + NodeLabel::Returns, OptionalHelper::transform(self.yul_returns_declaration(input)), )?; - seq.elem_named(FieldName::Body, self.yul_block(input))?; + seq.elem_labeled(NodeLabel::Body, self.yul_block(input))?; seq.finish() }) .with_kind(RuleKind::YulFunctionDefinition) @@ -6489,10 +6493,10 @@ impl Language { input, TokenKind::YulIdentifier, ) - .with_name(FieldName::Item) + .with_label(NodeLabel::Item) }, TokenKind::Period, - FieldName::Separator, + NodeLabel::Separator, ) .with_kind(RuleKind::YulIdentifierPath) } @@ -6502,9 +6506,9 @@ impl Language { SeparatedHelper::run::<_, LexicalContextType::Yul>( input, self, - |input| self.yul_identifier_path(input).with_name(FieldName::Item), + |input| self.yul_identifier_path(input).with_label(NodeLabel::Item), TokenKind::Comma, - FieldName::Separator, + NodeLabel::Separator, ) .with_kind(RuleKind::YulIdentifierPaths) } @@ -6512,15 +6516,15 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_if_statement(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::IfKeyword, + seq.elem_labeled( + NodeLabel::IfKeyword, self.parse_token_with_trivia::( input, TokenKind::YulIfKeyword, ), )?; - seq.elem_named(FieldName::Condition, self.yul_expression(input))?; - seq.elem_named(FieldName::Body, self.yul_block(input))?; + seq.elem_labeled(NodeLabel::Condition, self.yul_expression(input))?; + seq.elem_labeled(NodeLabel::Body, self.yul_block(input))?; seq.finish() }) .with_kind(RuleKind::YulIfStatement) @@ -6530,15 +6534,15 @@ impl Language { fn yul_label(&self, input: &mut ParserContext<'_>) -> ParserResult { if !self.version_is_at_least_0_5_0 { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::Label, + seq.elem_labeled( + NodeLabel::Label, self.parse_token_with_trivia::( input, TokenKind::YulIdentifier, ), )?; - seq.elem_named( - FieldName::Colon, + seq.elem_labeled( + NodeLabel::Colon, self.parse_token_with_trivia::( input, TokenKind::Colon, @@ -6559,7 +6563,7 @@ impl Language { input, TokenKind::YulLeaveKeyword, ) - .with_name(FieldName::LeaveKeyword) + .with_label(NodeLabel::LeaveKeyword) } else { ParserResult::disabled() } @@ -6595,7 +6599,7 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::YulLiteral) } @@ -6609,10 +6613,10 @@ impl Language { input, TokenKind::YulIdentifier, ) - .with_name(FieldName::Item) + .with_label(NodeLabel::Item) }, TokenKind::Comma, - FieldName::Separator, + NodeLabel::Separator, ) .with_kind(RuleKind::YulParameters) } @@ -6622,8 +6626,8 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenParen, + seq.elem_labeled( + NodeLabel::OpenParen, self.parse_token_with_trivia::( input, TokenKind::OpenParen, @@ -6631,7 +6635,7 @@ impl Language { )?; seq.elem( OptionalHelper::transform(self.yul_parameters(input)) - .with_name(FieldName::Parameters) + .with_label(NodeLabel::Parameters) .recover_until_with_nested_delims::<_, LexicalContextType::Yul>( input, self, @@ -6639,8 +6643,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseParen, + seq.elem_labeled( + NodeLabel::CloseParen, self.parse_token_with_trivia::( input, TokenKind::CloseParen, @@ -6661,10 +6665,10 @@ impl Language { input, TokenKind::YulIdentifier, ) - .with_name(FieldName::Item) + .with_label(NodeLabel::Item) }, TokenKind::Comma, - FieldName::Separator, + NodeLabel::Separator, ) .with_kind(RuleKind::YulReturnVariables) } @@ -6672,14 +6676,14 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_returns_declaration(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::MinusGreaterThan, + seq.elem_labeled( + NodeLabel::MinusGreaterThan, self.parse_token_with_trivia::( input, TokenKind::MinusGreaterThan, ), )?; - seq.elem_named(FieldName::Variables, self.yul_return_variables(input))?; + seq.elem_labeled(NodeLabel::Variables, self.yul_return_variables(input))?; seq.finish() }) .with_kind(RuleKind::YulReturnsDeclaration) @@ -6718,14 +6722,14 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::YulStatement) } #[allow(unused_assignments, unused_parens)] fn yul_statements(&self, input: &mut ParserContext<'_>) -> ParserResult { OneOrMoreHelper::run(input, |input| { - self.yul_statement(input).with_name(FieldName::Item) + self.yul_statement(input).with_label(NodeLabel::Item) }) .with_kind(RuleKind::YulStatements) } @@ -6739,14 +6743,14 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::YulSwitchCase) } #[allow(unused_assignments, unused_parens)] fn yul_switch_cases(&self, input: &mut ParserContext<'_>) -> ParserResult { OneOrMoreHelper::run(input, |input| { - self.yul_switch_case(input).with_name(FieldName::Item) + self.yul_switch_case(input).with_label(NodeLabel::Item) }) .with_kind(RuleKind::YulSwitchCases) } @@ -6754,15 +6758,15 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_switch_statement(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::SwitchKeyword, + seq.elem_labeled( + NodeLabel::SwitchKeyword, self.parse_token_with_trivia::( input, TokenKind::YulSwitchKeyword, ), )?; - seq.elem_named(FieldName::Expression, self.yul_expression(input))?; - seq.elem_named(FieldName::Cases, self.yul_switch_cases(input))?; + seq.elem_labeled(NodeLabel::Expression, self.yul_expression(input))?; + seq.elem_labeled(NodeLabel::Cases, self.yul_switch_cases(input))?; seq.finish() }) .with_kind(RuleKind::YulSwitchStatement) @@ -6771,15 +6775,15 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_value_case(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::CaseKeyword, + seq.elem_labeled( + NodeLabel::CaseKeyword, self.parse_token_with_trivia::( input, TokenKind::YulCaseKeyword, ), )?; - seq.elem_named(FieldName::Value, self.yul_literal(input))?; - seq.elem_named(FieldName::Body, self.yul_block(input))?; + seq.elem_labeled(NodeLabel::Value, self.yul_literal(input))?; + seq.elem_labeled(NodeLabel::Body, self.yul_block(input))?; seq.finish() }) .with_kind(RuleKind::YulValueCase) @@ -6788,16 +6792,16 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_variable_declaration_statement(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::LetKeyword, + seq.elem_labeled( + NodeLabel::LetKeyword, self.parse_token_with_trivia::( input, TokenKind::YulLetKeyword, ), )?; - seq.elem_named(FieldName::Names, self.yul_identifier_paths(input))?; - seq.elem_named( - FieldName::Value, + seq.elem_labeled(NodeLabel::Names, self.yul_identifier_paths(input))?; + seq.elem_labeled( + NodeLabel::Value, OptionalHelper::transform(self.yul_variable_declaration_value(input)), )?; seq.finish() @@ -6808,14 +6812,14 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_variable_declaration_value(&self, input: &mut ParserContext<'_>) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::ColonEqual, + seq.elem_labeled( + NodeLabel::ColonEqual, self.parse_token_with_trivia::( input, TokenKind::ColonEqual, ), )?; - seq.elem_named(FieldName::Expression, self.yul_expression(input))?; + seq.elem_labeled(NodeLabel::Expression, self.yul_expression(input))?; seq.finish() }) .with_kind(RuleKind::YulVariableDeclarationValue) diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/lexer.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/lexer.rs index 1a6ee00e0f..f11acf2d23 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/lexer.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/lexer.rs @@ -1,6 +1,6 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. -use crate::cst::{self, NamedNode}; +use crate::cst::{self, LabeledNode}; use crate::kinds::{IsLexicalContext, TokenKind}; use crate::parser_support::{ParserContext, ParserResult}; @@ -113,7 +113,7 @@ pub(crate) trait Lexer { let end = input.position(); ParserResult::r#match( - vec![NamedNode::anonymous(cst::Node::token( + vec![LabeledNode::anonymous(cst::Node::token( kind, input.content(start.utf8..end.utf8), ))], @@ -146,7 +146,7 @@ pub(crate) trait Lexer { return ParserResult::no_match(vec![kind]); } let end = input.position(); - children.push(NamedNode::anonymous(cst::Node::token( + children.push(LabeledNode::anonymous(cst::Node::token( kind, input.content(start.utf8..end.utf8), ))); diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/ast_selectors.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/ast_selectors.rs index f03bf2b708..8007395209 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/ast_selectors.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/ast_selectors.rs @@ -8,7 +8,7 @@ use napi::{Env, JsObject}; use napi_derive::napi; use crate::napi_interface::cst::{RuleNode, ToJS}; -use crate::napi_interface::{RuleKind, RustNamedNode, RustNode, RustRuleNode, TokenKind}; +use crate::napi_interface::{RuleKind, RustLabeledNode, RustNode, RustRuleNode, TokenKind}; // // Sequences: @@ -3035,16 +3035,16 @@ impl Selector { fn try_select(&mut self, filter: impl FnOnce(&RustNode) -> bool) -> Result> { while let Some(child) = self.node.children.get(self.index) { match child { - RustNamedNode { - name: _, + RustLabeledNode { + label: _, node: RustNode::Rule(rule), } if rule.kind.is_trivia() => { // skip trivia, since it's not part of the AST self.index += 1; continue; } - RustNamedNode { - name: _, + RustLabeledNode { + label: _, node: RustNode::Token(token), } if matches!(token.kind, TokenKind::SKIPPED) => { return Error::SkippedToken(self.index).into(); diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cursor.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cursor.rs index ead1ce0faf..4455978600 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cursor.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cursor.rs @@ -11,7 +11,7 @@ use napi::JsObject; use napi_derive::napi; use text_index::{TextIndex, TextRange}; -use crate::napi_interface::{cst, text_index, FieldName, RuleKind, RustCursor, TokenKind}; +use crate::napi_interface::{cst, text_index, NodeLabel, RuleKind, RustCursor, TokenKind}; #[napi(namespace = "cursor")] pub struct Cursor(pub(super) RustCursor); @@ -59,9 +59,9 @@ impl Cursor { self.0.node().to_js(&env) } - #[napi(getter, ts_return_type = "kinds.FieldName", catch_unwind)] - pub fn node_name(&self) -> Option { - self.0.node_name() + #[napi(getter, ts_return_type = "kinds.NodeLabel", catch_unwind)] + pub fn label(&self) -> Option { + self.0.label() } #[napi(getter, ts_return_type = "text_index.TextIndex", catch_unwind)] diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/mod.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/mod.rs index dba74b99c6..521b5429d7 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/mod.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/mod.rs @@ -9,7 +9,7 @@ pub mod query; pub mod text_index; type RustCursor = crate::cursor::Cursor; -type RustNamedNode = crate::cst::NamedNode; +type RustLabeledNode = crate::cst::LabeledNode; type RustNode = crate::cst::Node; type RustParseError = crate::parse_error::ParseError; type RustParseOutput = crate::parse_output::ParseOutput; @@ -23,4 +23,4 @@ type RustTokenNode = crate::cst::TokenNode; type RuleKind = crate::kinds::RuleKind; type TokenKind = crate::kinds::TokenKind; -type FieldName = crate::kinds::FieldName; +type NodeLabel = crate::kinds::NodeLabel; diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/parser_support/parser_function.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/parser_support/parser_function.rs index 03b55bec84..fffdf93c8f 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/parser_support/parser_function.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/parser_support/parser_function.rs @@ -2,7 +2,7 @@ use std::rc::Rc; -use crate::cst::{self, NamedNode}; +use crate::cst::{self, LabeledNode}; use crate::kinds::TokenKind; use crate::lexer::Lexer; use crate::parse_error::ParseError; @@ -86,7 +86,7 @@ where }; let topmost_rule = match &nodes[..] { - [NamedNode { node: cst::Node::Rule(rule), ..} ] => Rc::clone(rule), + [LabeledNode { node: cst::Node::Rule(rule), ..} ] => Rc::clone(rule), [_] => unreachable!( "(Incomplete)Match at the top level of a parser is not a Rule node" ), @@ -109,7 +109,7 @@ where let skipped_node = cst::Node::token(TokenKind::SKIPPED, input[start.utf8..].to_string()); let mut new_children = topmost_rule.children.clone(); - new_children.push(NamedNode::anonymous(skipped_node)); + new_children.push(LabeledNode::anonymous(skipped_node)); let mut errors = stream.into_errors(); errors.push(ParseError::new(start..input.into(), expected_tokens)); diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/parser_support/parser_result.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/parser_support/parser_result.rs index 056ad458d8..138ba829a5 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/parser_support/parser_result.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/parser_support/parser_result.rs @@ -2,8 +2,8 @@ use std::ops::ControlFlow; -use crate::cst::{self, NamedNode}; -use crate::kinds::{FieldName, RuleKind, TokenKind}; +use crate::cst::{self, LabeledNode}; +use crate::kinds::{NodeLabel, RuleKind, TokenKind}; use crate::text_index::TextIndex; #[derive(PartialEq, Eq, Clone, Debug)] @@ -24,7 +24,7 @@ impl Default for ParserResult { } impl ParserResult { - pub fn r#match(nodes: Vec, expected_tokens: Vec) -> Self { + pub fn r#match(nodes: Vec, expected_tokens: Vec) -> Self { ParserResult::Match(Match::new(nodes, expected_tokens)) } @@ -32,7 +32,7 @@ impl ParserResult { ParserResult::PrattOperatorMatch(PrattOperatorMatch::new(elements)) } - pub fn incomplete_match(nodes: Vec, expected_tokens: Vec) -> Self { + pub fn incomplete_match(nodes: Vec, expected_tokens: Vec) -> Self { ParserResult::IncompleteMatch(IncompleteMatch::new(nodes, expected_tokens)) } @@ -49,21 +49,21 @@ impl ParserResult { pub fn with_kind(self, new_kind: RuleKind) -> ParserResult { match self { ParserResult::Match(r#match) => ParserResult::r#match( - vec![NamedNode::anonymous(cst::Node::rule( + vec![LabeledNode::anonymous(cst::Node::rule( new_kind, r#match.nodes, ))], r#match.expected_tokens, ), ParserResult::IncompleteMatch(incomplete_match) => ParserResult::incomplete_match( - vec![NamedNode::anonymous(cst::Node::rule( + vec![LabeledNode::anonymous(cst::Node::rule( new_kind, incomplete_match.nodes, ))], incomplete_match.expected_tokens, ), ParserResult::SkippedUntil(skipped) => ParserResult::SkippedUntil(SkippedUntil { - nodes: vec![NamedNode::anonymous(cst::Node::rule( + nodes: vec![LabeledNode::anonymous(cst::Node::rule( new_kind, skipped.nodes, ))], @@ -77,21 +77,21 @@ impl ParserResult { } #[must_use] - pub fn with_name(mut self, name: FieldName) -> ParserResult { - if let Some(NamedNode { - name: prev_name, .. + pub fn with_label(mut self, label: NodeLabel) -> ParserResult { + if let Some(LabeledNode { + label: prev_label, .. }) = self.significant_node_mut() { - *prev_name = Some(name); + *prev_label = Some(label); } self } /// Returns a significant (non-trivia) node if there is exactly one. - pub(crate) fn significant_node_mut(&mut self) -> Option<&mut cst::NamedNode> { - fn is_significant(named: &cst::NamedNode) -> bool { - match &named.node { + pub(crate) fn significant_node_mut(&mut self) -> Option<&mut cst::LabeledNode> { + fn is_significant(labeled: &cst::LabeledNode) -> bool { + match &labeled.node { cst::Node::Rule(rule) => !rule.kind.is_trivia(), // FIXME: Some tokens are in fact trivia cst::Node::Token(_) => true, @@ -121,13 +121,13 @@ impl ParserResult { #[derive(PartialEq, Eq, Clone, Debug)] pub struct Match { - pub nodes: Vec, + pub nodes: Vec, /// Tokens that would have allowed for more progress. Collected for the purposes of error reporting. pub expected_tokens: Vec, } impl Match { - pub fn new(nodes: Vec, expected_tokens: Vec) -> Self { + pub fn new(nodes: Vec, expected_tokens: Vec) -> Self { Self { nodes, expected_tokens, @@ -145,34 +145,34 @@ impl Match { #[derive(PartialEq, Eq, Clone, Debug)] pub enum PrattElement { Expression { - nodes: Vec, + nodes: Vec, }, Prefix { kind: RuleKind, - nodes: Vec, + nodes: Vec, right: u8, }, Binary { kind: RuleKind, - nodes: Vec, + nodes: Vec, left: u8, right: u8, }, Postfix { kind: RuleKind, - nodes: Vec, + nodes: Vec, left: u8, }, } impl PrattElement { - pub fn into_nodes(self) -> Vec { + pub fn into_nodes(self) -> Vec { match self { Self::Expression { nodes } => nodes, Self::Binary { kind, nodes, .. } | Self::Prefix { kind, nodes, .. } | Self::Postfix { kind, nodes, .. } => { - vec![NamedNode::anonymous(cst::Node::rule(kind, nodes))] + vec![LabeledNode::anonymous(cst::Node::rule(kind, nodes))] } } } @@ -191,13 +191,13 @@ impl PrattOperatorMatch { #[derive(PartialEq, Eq, Clone, Debug)] pub struct IncompleteMatch { - pub nodes: Vec, + pub nodes: Vec, /// Tokens that would have allowed for more progress. Collected for the purposes of error reporting. pub expected_tokens: Vec, } impl IncompleteMatch { - pub fn new(nodes: Vec, expected_tokens: Vec) -> Self { + pub fn new(nodes: Vec, expected_tokens: Vec) -> Self { Self { nodes, expected_tokens, @@ -219,7 +219,7 @@ impl NoMatch { #[derive(PartialEq, Eq, Clone, Debug)] pub struct SkippedUntil { - pub nodes: Vec, + pub nodes: Vec, /// Skipped text following the last node pub skipped: String, /// At which token was the stream pointing at when we bailed diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/parser_support/precedence_helper.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/parser_support/precedence_helper.rs index 9a7ff657e8..eee625e583 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/parser_support/precedence_helper.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/parser_support/precedence_helper.rs @@ -1,7 +1,7 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. -use crate::cst::{self, NamedNode}; -use crate::kinds::{FieldName, RuleKind}; +use crate::cst::{self, LabeledNode}; +use crate::kinds::{NodeLabel, RuleKind}; use crate::parser_support::parser_result::PrattElement::{ self, Binary, Expression, Postfix, Prefix, }; @@ -152,21 +152,21 @@ impl PrecedenceHelper { let make_expression = |left: Option, kind: RuleKind, - nodes: Vec, + nodes: Vec, right: Option| { assert!(left.is_some() || right.is_some()); - let left_name = right + let left_label = right .as_ref() - .map_or(FieldName::Operand, |_| FieldName::LeftOperand); - let right_name = left + .map_or(NodeLabel::Operand, |_| NodeLabel::LeftOperand); + let right_label = left .as_ref() - .map_or(FieldName::Operand, |_| FieldName::RightOperand); + .map_or(NodeLabel::Operand, |_| NodeLabel::RightOperand); let left_nodes = match left { Some(Expression { nodes }) => { - vec![NamedNode { - name: Some(left_name), + vec![LabeledNode { + label: Some(left_label), node: cst::Node::rule(child_kind, nodes), }] } @@ -176,8 +176,8 @@ impl PrecedenceHelper { let right_nodes = match right { Some(Expression { nodes }) => { - vec![NamedNode { - name: Some(right_name), + vec![LabeledNode { + label: Some(right_label), node: cst::Node::rule(child_kind, nodes), }] } @@ -188,8 +188,8 @@ impl PrecedenceHelper { let children = [left_nodes, nodes, right_nodes].concat(); Expression { - nodes: vec![NamedNode { - name: Some(FieldName::Variant), + nodes: vec![LabeledNode { + label: Some(NodeLabel::Variant), node: cst::Node::rule(kind, children), }], } diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/parser_support/recovery.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/parser_support/recovery.rs index 2584e20915..563d3a60bf 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/parser_support/recovery.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/parser_support/recovery.rs @@ -25,7 +25,7 @@ impl RecoverFromNoMatch { fn opt_parse( input: &mut ParserContext<'_>, parse: impl Fn(&mut ParserContext<'_>) -> ParserResult, -) -> Vec { +) -> Vec { let start = input.position(); if let ParserResult::Match(r#match) = parse(input) { r#match.nodes diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/parser_support/separated_helper.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/parser_support/separated_helper.rs index b1fdee1954..f107fd0cef 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/parser_support/separated_helper.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/parser_support/separated_helper.rs @@ -1,7 +1,7 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. -use crate::cst::{self, NamedNode}; -use crate::kinds::{FieldName, IsLexicalContext, TokenKind}; +use crate::cst::{self, LabeledNode}; +use crate::kinds::{IsLexicalContext, NodeLabel, TokenKind}; use crate::lexer::Lexer; use crate::parse_error::ParseError; use crate::parser_support::parser_result::{ParserResult, SkippedUntil}; @@ -17,7 +17,7 @@ impl SeparatedHelper { lexer: &L, body_parser: impl Fn(&mut ParserContext<'_>) -> ParserResult, separator: TokenKind, - separator_field_name: FieldName, + separator_label: NodeLabel, ) -> ParserResult { let mut accum = vec![]; loop { @@ -29,7 +29,7 @@ impl SeparatedHelper { Some(scanned) if scanned.accepted_as(separator) => { match lexer .parse_token_with_trivia::(input, separator) - .with_name(separator_field_name) + .with_label(separator_label) { ParserResult::Match(r#match) => { accum.extend(r#match.nodes); @@ -55,7 +55,7 @@ impl SeparatedHelper { match skip_until_with_nested_delims::<_, LexCtx>(input, lexer, separator) { // A separator was found, so we can recover the incomplete match Some((found, skipped_range)) if found == separator => { - accum.push(NamedNode::anonymous(cst::Node::token( + accum.push(LabeledNode::anonymous(cst::Node::token( TokenKind::SKIPPED, input.content(skipped_range.utf8()), ))); diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/parser_support/sequence_helper.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/parser_support/sequence_helper.rs index 4050cdf757..1d5b1b4596 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/parser_support/sequence_helper.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/parser_support/sequence_helper.rs @@ -2,8 +2,8 @@ use std::ops::ControlFlow; -use crate::cst::{self, NamedNode}; -use crate::kinds::{FieldName, TokenKind}; +use crate::cst::{self, LabeledNode}; +use crate::kinds::{NodeLabel, TokenKind}; use crate::parser_support::parser_result::{Match, ParserResult, PrattElement, SkippedUntil}; /// Keeps accumulating parses sequentially until it hits an incomplete or no match. @@ -137,7 +137,7 @@ impl SequenceHelper { debug_assert!(is_single_token_with_trivia); debug_assert_eq!(next_token, Some(running.found)); - running.nodes.push(NamedNode::anonymous(cst::Node::token( + running.nodes.push(LabeledNode::anonymous(cst::Node::token( TokenKind::SKIPPED, std::mem::take(&mut running.skipped), ))); @@ -186,13 +186,13 @@ impl SequenceHelper { /// Aggregates a parse result into the sequence. If we cannot make progress, returns the accumulated match. /// - /// Shorthand for `self.elem(value.with_name(name))`. - pub fn elem_named( + /// Shorthand for `self.elem(value.with_label(label))`. + pub fn elem_labeled( &mut self, - name: FieldName, + label: NodeLabel, value: ParserResult, ) -> ControlFlow { - self.elem(value.with_name(name)) + self.elem(value.with_label(label)) } /// Finishes the sequence parse, returning the accumulated match. diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/query/engine.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/query/engine.rs index 82fa136c78..6cdb482c51 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/query/engine.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/query/engine.rs @@ -33,23 +33,23 @@ impl Cursor { NodeSelector::Anonymous => true, NodeSelector::Kind { kind } => Kind::Rule(rule.kind) == *kind, NodeSelector::Text { .. } => false, - NodeSelector::FieldName { field_name } => Some(*field_name) == self.node_name(), - NodeSelector::FieldNameAndKind { field_name, kind } => { - Some(*field_name) == self.node_name() && Kind::Rule(rule.kind) == *kind + NodeSelector::Label { label } => Some(*label) == self.label(), + NodeSelector::LabelAndKind { label, kind } => { + Some(*label) == self.label() && Kind::Rule(rule.kind) == *kind } - NodeSelector::FieldNameAndText { .. } => false, + NodeSelector::LabelAndText { .. } => false, }, cst::Node::Token(token) => match node_selector { NodeSelector::Anonymous => true, NodeSelector::Kind { kind } => Kind::Token(token.kind) == *kind, NodeSelector::Text { text } => token.text == *text, - NodeSelector::FieldName { field_name } => Some(*field_name) == self.node_name(), - NodeSelector::FieldNameAndKind { field_name, kind } => { - Some(*field_name) == self.node_name() && Kind::Token(token.kind) == *kind + NodeSelector::Label { label } => Some(*label) == self.label(), + NodeSelector::LabelAndKind { label, kind } => { + Some(*label) == self.label() && Kind::Token(token.kind) == *kind } - NodeSelector::FieldNameAndText { field_name, text } => { - Some(*field_name) == self.node_name() && token.text == *text + NodeSelector::LabelAndText { label, text } => { + Some(*label) == self.label() && token.text == *text } }, } diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/query/model.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/query/model.rs index c3bfed9170..50f270ab71 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/query/model.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/query/model.rs @@ -4,7 +4,7 @@ use std::fmt; use std::rc::Rc; // This crate is copied to another crate, so all imports should be relative -use super::super::kinds::{FieldName, RuleKind, TokenKind}; +use super::super::kinds::{NodeLabel, RuleKind, TokenKind}; #[derive(Clone)] pub struct Query(pub(super) Matcher); @@ -108,9 +108,9 @@ pub(super) enum NodeSelector { Anonymous, Kind { kind: Kind }, Text { text: String }, - FieldName { field_name: FieldName }, - FieldNameAndKind { field_name: FieldName, kind: Kind }, - FieldNameAndText { field_name: FieldName, text: String }, + Label { label: NodeLabel }, + LabelAndKind { label: NodeLabel, kind: Kind }, + LabelAndText { label: NodeLabel, text: String }, } impl fmt::Display for NodeSelector { @@ -136,12 +136,12 @@ impl fmt::Display for NodeSelector { Self::Anonymous => write!(f, "_"), Self::Kind { kind } => kind.fmt(f), Self::Text { text } => write!(f, "\"{}\"", escape_string(text)), - Self::FieldName { field_name } => field_name.fmt(f), - Self::FieldNameAndKind { field_name, kind } => { - write!(f, "{field_name}; {kind}") + Self::Label { label } => label.fmt(f), + Self::LabelAndKind { label, kind } => { + write!(f, "{label}; {kind}") } - Self::FieldNameAndText { field_name, text } => { - write!(f, "{field_name}: \"{}\"", escape_string(text)) + Self::LabelAndText { label, text } => { + write!(f, "{label}: \"{}\"", escape_string(text)) } } } diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/query/parser.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/query/parser.rs index cb867fb2a3..cdc0a09d5c 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/query/parser.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/query/parser.rs @@ -12,7 +12,7 @@ use nom::sequence::{delimited, pair, preceded, terminated}; use nom::{Finish, IResult, Parser}; // This crate is copied to another crate, so all imports should be relative -use super::super::kinds::{FieldName, RuleKind, TokenKind}; +use super::super::kinds::{NodeLabel, RuleKind, TokenKind}; use super::model::{ AlternativesMatcher, BindingMatcher, Kind, Matcher, NodeMatcher, NodeSelector, OneOrMoreMatcher, OptionalMatcher, SequenceMatcher, @@ -78,25 +78,19 @@ fn parse_node_selector(input: &str) -> IResult<&str, NodeSelector, VerboseError< Text(String), } - opt(field_name_token) + opt(label_token) .and(alt(( token('_').map(|_| Tail::Anonymous), kind_token.map(Tail::Kind), text_token.map(Tail::Text), ))) - .map(|(field_name, tail)| match (field_name, tail) { + .map(|(label, tail)| match (label, tail) { (None, Tail::Anonymous) => NodeSelector::Anonymous, (None, Tail::Kind(kind)) => NodeSelector::Kind { kind }, (None, Tail::Text(string)) => NodeSelector::Text { text: string }, - (Some(field), Tail::Anonymous) => NodeSelector::FieldName { field_name: field }, - (Some(field), Tail::Kind(kind)) => NodeSelector::FieldNameAndKind { - field_name: field, - kind, - }, - (Some(field), Tail::Text(string)) => NodeSelector::FieldNameAndText { - field_name: field, - text: string, - }, + (Some(label), Tail::Anonymous) => NodeSelector::Label { label }, + (Some(label), Tail::Kind(kind)) => NodeSelector::LabelAndKind { label, kind }, + (Some(label), Tail::Text(text)) => NodeSelector::LabelAndText { label, text }, }) .parse(input) } @@ -191,9 +185,9 @@ fn kind_token(i: &str) -> IResult<&str, Kind, VerboseError<&str>> { .parse(i) } -fn field_name_token(i: &str) -> IResult<&str, FieldName, VerboseError<&str>> { +fn label_token(i: &str) -> IResult<&str, NodeLabel, VerboseError<&str>> { terminated(raw_identifier, token(':')) - .map(|id| FieldName::try_from(id.as_str()).unwrap()) + .map(|id| NodeLabel::try_from(id.as_str()).unwrap()) .parse(i) } diff --git a/crates/solidity/outputs/cargo/tests/src/cst_output/runner.rs b/crates/solidity/outputs/cargo/tests/src/cst_output/runner.rs index 2a54f9743f..185399caff 100644 --- a/crates/solidity/outputs/cargo/tests/src/cst_output/runner.rs +++ b/crates/solidity/outputs/cargo/tests/src/cst_output/runner.rs @@ -52,7 +52,7 @@ pub fn run(parser_name: &str, test_name: &str) -> Result<()> { .map(|error| error.to_error_report(source_id, &source, /* with_color */ false)) .collect(); - let cursor = output.create_tree_cursor().with_names(); + let cursor = output.create_tree_cursor().with_labels(); let status = if output.is_valid() { TestStatus::Success diff --git a/crates/solidity/outputs/cargo/tests/src/doc_examples/using_the_cursor.rs b/crates/solidity/outputs/cargo/tests/src/doc_examples/using_the_cursor.rs index 7ecfbce150..89c7132127 100644 --- a/crates/solidity/outputs/cargo/tests/src/doc_examples/using_the_cursor.rs +++ b/crates/solidity/outputs/cargo/tests/src/doc_examples/using_the_cursor.rs @@ -7,7 +7,7 @@ use infra_utils::paths::PathExtensions; fn using_the_cursor() -> Result<()> { // --8<-- [start:imports] use semver::Version; - use slang_solidity::kinds::{FieldName, RuleKind, TokenKind}; + use slang_solidity::kinds::{NodeLabel, RuleKind, TokenKind}; use slang_solidity::language::Language; use slang_solidity::text_index::TextRangeExtensions; // --8<-- [end:imports] @@ -101,18 +101,18 @@ fn using_the_cursor() -> Result<()> { } { - // --8<-- [start:using-named-cursors] + // --8<-- [start:using-labeled-cursors] let cursor = parse_output.create_tree_cursor(); let identifiers: Vec<_> = cursor - .with_names() - .filter(|node| node.name == Some(FieldName::Name)) + .with_labels() + .filter(|node| node.label == Some(NodeLabel::Name)) .filter_map(|node| node.as_token_with_kind(TokenKind::Identifier).cloned()) .map(|identifier| identifier.text.clone()) .collect(); assert_eq!(identifiers, &["Foo", "Bar", "Baz"]); - // --8<-- [end:using-named-cursors] + // --8<-- [end:using-labeled-cursors] } Ok(()) diff --git a/crates/solidity/outputs/npm/package/src/generated/index.d.ts b/crates/solidity/outputs/npm/package/src/generated/index.d.ts index b8563ea40d..ef654fc12c 100644 --- a/crates/solidity/outputs/npm/package/src/generated/index.d.ts +++ b/crates/solidity/outputs/npm/package/src/generated/index.d.ts @@ -225,7 +225,7 @@ export namespace kinds { YulVariableDeclarationStatement = "YulVariableDeclarationStatement", YulVariableDeclarationValue = "YulVariableDeclarationValue", } - export enum FieldName { + export enum NodeLabel { Item = "Item", Variant = "Variant", Separator = "Separator", @@ -764,7 +764,7 @@ export namespace cursor { spawn(): Cursor; get isCompleted(): boolean; node(): cst.Node; - get nodeName(): kinds.FieldName; + get label(): kinds.NodeLabel; get textOffset(): text_index.TextIndex; get textRange(): text_index.TextRange; get depth(): number; diff --git a/crates/solidity/outputs/npm/package/src/kinds/index.ts b/crates/solidity/outputs/npm/package/src/kinds/index.ts index 9061014c27..0c1d84aa75 100644 --- a/crates/solidity/outputs/npm/package/src/kinds/index.ts +++ b/crates/solidity/outputs/npm/package/src/kinds/index.ts @@ -6,5 +6,5 @@ export type RuleKind = generated.kinds.RuleKind; export const TokenKind = generated.kinds.TokenKind; export type TokenKind = generated.kinds.TokenKind; -export const FieldName = generated.kinds.FieldName; -export type FieldName = generated.kinds.FieldName; +export const NodeLabel = generated.kinds.NodeLabel; +export type NodeLabel = generated.kinds.NodeLabel; diff --git a/crates/solidity/testing/utils/src/cst_snapshots/mod.rs b/crates/solidity/testing/utils/src/cst_snapshots/mod.rs index 2feb2ff10d..bcc4d84283 100644 --- a/crates/solidity/testing/utils/src/cst_snapshots/mod.rs +++ b/crates/solidity/testing/utils/src/cst_snapshots/mod.rs @@ -8,7 +8,7 @@ use codegen_language_definition::model::Item; use inflector::Inflector; use once_cell::sync::Lazy; use slang_solidity::cst::Node; -use slang_solidity::cursor::CursorWithNames; +use slang_solidity::cursor::CursorWithLabels; use slang_solidity::kinds::RuleKind; use slang_solidity::text_index::TextRangeExtensions; use solidity_language::SolidityDefinition; @@ -16,7 +16,7 @@ use solidity_language::SolidityDefinition; pub struct CstSnapshots; impl CstSnapshots { - pub fn render(source: &str, errors: &Vec, cursor: CursorWithNames) -> Result { + pub fn render(source: &str, errors: &Vec, cursor: CursorWithLabels) -> Result { let mut w = String::new(); write_source(&mut w, source)?; @@ -89,7 +89,7 @@ fn write_errors(w: &mut String, errors: &Vec) -> Result<()> { Ok(()) } -fn write_tree(w: &mut String, mut cursor: CursorWithNames, source: &str) -> Result<()> { +fn write_tree(w: &mut String, mut cursor: CursorWithLabels, source: &str) -> Result<()> { writeln!(w, "Tree:")?; write_node(w, &mut cursor, source, 0)?; @@ -99,7 +99,7 @@ fn write_tree(w: &mut String, mut cursor: CursorWithNames, source: &str) -> Resu fn write_node( w: &mut String, - cursor: &mut CursorWithNames, + cursor: &mut CursorWithLabels, source: &str, depth: usize, ) -> Result<()> { @@ -135,20 +135,20 @@ fn write_node( Ok(()) } -fn render_key(cursor: &mut CursorWithNames) -> String { +fn render_key(cursor: &mut CursorWithLabels) -> String { let kind = match cursor.node() { Node::Rule(rule) => rule.kind.to_string(), Node::Token(token) => token.kind.to_string(), }; - if let Some(name) = cursor.node_name() { - format!("({name}꞉ {kind})", name = name.as_ref().to_snake_case()) + if let Some(label) = cursor.label() { + format!("({label}꞉ {kind})", label = label.as_ref().to_snake_case()) } else { format!("({kind})") } } -fn render_value(cursor: &mut CursorWithNames, source: &str) -> String { +fn render_value(cursor: &mut CursorWithLabels, source: &str) -> String { let utf8_range = cursor.text_range().utf8(); let char_range = cursor.text_range().char(); let preview = render_preview(source, &char_range); diff --git a/crates/solidity/testing/utils/src/version_pragmas/mod.rs b/crates/solidity/testing/utils/src/version_pragmas/mod.rs index 9d520cd4f3..d06309eff9 100644 --- a/crates/solidity/testing/utils/src/version_pragmas/mod.rs +++ b/crates/solidity/testing/utils/src/version_pragmas/mod.rs @@ -5,7 +5,7 @@ use std::str::FromStr; use anyhow::{bail, ensure, Context, Result}; use semver::{Comparator, Op, Version}; -use slang_solidity::cst::{NamedNode, Node}; +use slang_solidity::cst::{LabeledNode, Node}; use slang_solidity::kinds::RuleKind; use slang_solidity::language::Language; @@ -54,13 +54,13 @@ fn extract_pragma(expression_node: &Node) -> Result { ); let inner_expression = match &expression_rule.children[..] { - [NamedNode { + [LabeledNode { + label: _, node: Node::Rule(rule), - .. }] => rule, - [NamedNode { + [LabeledNode { + label: _, node: Node::Token(token), - .. }] => bail!("Expected rule: {token:?}"), _ => unreachable!("Expected single child: {expression_rule:?}"), }; @@ -73,24 +73,17 @@ fn extract_pragma(expression_node: &Node) -> Result { match inner_expression.kind { RuleKind::VersionPragmaOrExpression => { - let [left, NamedNode { - name: _, - node: Node::Token(_op), - }, right] = &inner_children[..] - else { + let [left, _, right] = &inner_children[..] else { bail!("Expected 3 children: {inner_expression:?}"); }; + let left = extract_pragma(left)?; let right = extract_pragma(right)?; Ok(VersionPragma::or(left, right)) } RuleKind::VersionPragmaRangeExpression => { - let [left, NamedNode { - name: _, - node: Node::Token(_op), - }, right] = &inner_children[..] - else { + let [left, _, right] = &inner_children[..] else { bail!("Expected 3 children: {inner_expression:?}"); }; diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/cst.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/cst.rs index 517ee94e51..9b4281aa40 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/cst.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/cst.rs @@ -5,23 +5,23 @@ use std::rc::Rc; use serde::Serialize; use crate::cursor::Cursor; -use crate::kinds::{FieldName, RuleKind, TokenKind}; +use crate::kinds::{NodeLabel, RuleKind, TokenKind}; use crate::text_index::TextIndex; #[derive(Clone, Debug, PartialEq, Eq, Serialize)] -pub struct NamedNode { - pub name: Option, +pub struct LabeledNode { + pub label: Option, pub node: Node, } -impl NamedNode { - /// Creates an anonymous (nameless) node. +impl LabeledNode { + /// Creates an anonymous node (without a label). pub fn anonymous(node: Node) -> Self { - Self { name: None, node } + Self { label: None, node } } } -impl std::ops::Deref for NamedNode { +impl std::ops::Deref for LabeledNode { type Target = Node; fn deref(&self) -> &Self::Target { @@ -34,7 +34,7 @@ pub struct RuleNode { pub kind: RuleKind, pub text_len: TextIndex, #[serde(skip_serializing_if = "Vec::is_empty")] - pub children: Vec, + pub children: Vec, } #[derive(Clone, Debug, PartialEq, Eq, Serialize)] @@ -50,7 +50,7 @@ pub enum Node { } impl Node { - pub fn rule(kind: RuleKind, children: Vec) -> Self { + pub fn rule(kind: RuleKind, children: Vec) -> Self { let text_len = children.iter().map(|node| node.text_len()).sum(); Self::Rule(Rc::new(RuleNode { @@ -72,7 +72,7 @@ impl Node { } /// Returns a slice of the children (not all descendants) of this node. - pub fn children(&self) -> &[NamedNode] { + pub fn children(&self) -> &[LabeledNode] { match self { Self::Rule(node) => &node.children, Self::Token(_) => &[], diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/cursor.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/cursor.rs index dba7bb2924..ddfe224e76 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/cursor.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/cursor.rs @@ -4,8 +4,8 @@ use std::rc::Rc; -use crate::cst::{NamedNode, Node, RuleNode}; -use crate::kinds::{FieldName, RuleKind, TokenKind}; +use crate::cst::{LabeledNode, Node, RuleNode}; +use crate::kinds::{NodeLabel, RuleKind, TokenKind}; use crate::text_index::{TextIndex, TextRange}; /// A node in the ancestor path of a [`Cursor`]. @@ -126,11 +126,11 @@ impl Cursor { self.node.clone() } - pub fn node_name(&self) -> Option { + pub fn label(&self) -> Option { self.parent.as_ref().and_then(|parent| { let this = &parent.rule_node.children[self.child_number]; - this.name + this.label }) } @@ -415,28 +415,28 @@ impl Cursor { } } -/// A [`Cursor`] that also keeps track of the names of the nodes it visits. -pub struct CursorWithNames { +/// A [`Cursor`] that also keeps track of the labels of the nodes it visits. +pub struct CursorWithLabels { cursor: Cursor, } -impl CursorWithNames { - pub fn without_names(self) -> Cursor { +impl CursorWithLabels { + pub fn without_labels(self) -> Cursor { self.cursor } } -impl Iterator for CursorWithNames { - type Item = NamedNode; +impl Iterator for CursorWithLabels { + type Item = LabeledNode; fn next(&mut self) -> Option { - let name = self.cursor.node_name(); + let label = self.cursor.label(); - self.cursor.next().map(|node| NamedNode { name, node }) + self.cursor.next().map(|node| LabeledNode { label, node }) } } -impl std::ops::Deref for CursorWithNames { +impl std::ops::Deref for CursorWithLabels { type Target = Cursor; fn deref(&self) -> &Self::Target { @@ -444,21 +444,21 @@ impl std::ops::Deref for CursorWithNames { } } -impl std::ops::DerefMut for CursorWithNames { +impl std::ops::DerefMut for CursorWithLabels { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.cursor } } impl Cursor { - /// Returns a [`CursorWithNames`] that wraps this cursor. - pub fn with_names(self) -> CursorWithNames { - CursorWithNames::from(self) + /// Returns a [`CursorWithLabels`] that wraps this cursor. + pub fn with_labels(self) -> CursorWithLabels { + CursorWithLabels::from(self) } } -impl From for CursorWithNames { +impl From for CursorWithLabels { fn from(cursor: Cursor) -> Self { - CursorWithNames { cursor } + CursorWithLabels { cursor } } } diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/kinds.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/kinds.rs index 3c10aea217..d76a067c52 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/kinds.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/kinds.rs @@ -57,8 +57,8 @@ impl RuleKind { #[strum(serialize_all = "snake_case")] #[cfg_attr(feature = "slang_napi_interfaces", /* derives `Clone` and `Copy` */ napi(string_enum, namespace = "kinds"))] #[cfg_attr(not(feature = "slang_napi_interfaces"), derive(Clone, Copy))] -pub enum FieldName { - // Built-in fields +pub enum NodeLabel { + // Built-in labels Item, Variant, Separator, diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/language.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/language.rs index 841e174945..9f9e9632ba 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/language.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/language.rs @@ -16,7 +16,7 @@ use semver::Version; use crate::cst; use crate::kinds::{ - FieldName, IsLexicalContext, LexicalContext, LexicalContextType, RuleKind, TokenKind, + IsLexicalContext, LexicalContext, LexicalContextType, NodeLabel, RuleKind, TokenKind, }; use crate::lexer::{KeywordScan, Lexer, ScannedToken}; #[cfg(feature = "slang_napi_interfaces")] @@ -108,7 +108,7 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::Literal) } @@ -122,10 +122,10 @@ impl Language { input, TokenKind::Identifier, ) - .with_name(FieldName::Item) + .with_label(NodeLabel::Item) }, TokenKind::Period, - FieldName::Separator, + NodeLabel::Separator, ) .with_kind(RuleKind::SeparatedIdentifiers) } @@ -133,7 +133,7 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn source_unit(&self, input: &mut ParserContext<'_>) -> ParserResult { self.source_unit_members(input) - .with_name(FieldName::Members) + .with_label(NodeLabel::Members) .with_kind(RuleKind::SourceUnit) } @@ -148,14 +148,14 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::SourceUnitMember) } #[allow(unused_assignments, unused_parens)] fn source_unit_members(&self, input: &mut ParserContext<'_>) -> ParserResult { OneOrMoreHelper::run(input, |input| { - self.source_unit_member(input).with_name(FieldName::Item) + self.source_unit_member(input).with_label(NodeLabel::Item) }) .with_kind(RuleKind::SourceUnitMembers) } @@ -183,15 +183,15 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem_named( - FieldName::Keyword, + seq.elem_labeled( + NodeLabel::Keyword, self.parse_token_with_trivia::( input, TokenKind::TreeKeyword, ), )?; - seq.elem_named( - FieldName::Name, + seq.elem_labeled( + NodeLabel::Name, OptionalHelper::transform( self.parse_token_with_trivia::( input, @@ -199,7 +199,7 @@ impl Language { ), ), )?; - seq.elem_named(FieldName::Node, self.tree_node(input))?; + seq.elem_labeled(NodeLabel::Node, self.tree_node(input))?; seq.finish() }) .recover_until_with_nested_delims::<_, LexicalContextType::Tree>( @@ -209,8 +209,8 @@ impl Language { RecoverFromNoMatch::No, ), )?; - seq.elem_named( - FieldName::Semicolon, + seq.elem_labeled( + NodeLabel::Semicolon, self.parse_token_with_trivia::( input, TokenKind::Semicolon, @@ -226,8 +226,8 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBracket); let input = delim_guard.ctx(); - seq.elem_named( - FieldName::OpenBracket, + seq.elem_labeled( + NodeLabel::OpenBracket, self.parse_token_with_trivia::( input, TokenKind::OpenBracket, @@ -235,7 +235,7 @@ impl Language { )?; seq.elem( self.tree_node_children(input) - .with_name(FieldName::Members) + .with_label(NodeLabel::Members) .recover_until_with_nested_delims::<_, LexicalContextType::Tree>( input, self, @@ -243,8 +243,8 @@ impl Language { RecoverFromNoMatch::Yes, ), )?; - seq.elem_named( - FieldName::CloseBracket, + seq.elem_labeled( + NodeLabel::CloseBracket, self.parse_token_with_trivia::( input, TokenKind::CloseBracket, @@ -267,14 +267,14 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }) - .with_name(FieldName::Variant) + .with_label(NodeLabel::Variant) .with_kind(RuleKind::TreeNodeChild) } #[allow(unused_assignments, unused_parens)] fn tree_node_children(&self, input: &mut ParserContext<'_>) -> ParserResult { OneOrMoreHelper::run(input, |input| { - self.tree_node_child(input).with_name(FieldName::Item) + self.tree_node_child(input).with_label(NodeLabel::Item) }) .with_kind(RuleKind::TreeNodeChildren) } diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/lexer.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/lexer.rs index 1a6ee00e0f..f11acf2d23 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/lexer.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/lexer.rs @@ -1,6 +1,6 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. -use crate::cst::{self, NamedNode}; +use crate::cst::{self, LabeledNode}; use crate::kinds::{IsLexicalContext, TokenKind}; use crate::parser_support::{ParserContext, ParserResult}; @@ -113,7 +113,7 @@ pub(crate) trait Lexer { let end = input.position(); ParserResult::r#match( - vec![NamedNode::anonymous(cst::Node::token( + vec![LabeledNode::anonymous(cst::Node::token( kind, input.content(start.utf8..end.utf8), ))], @@ -146,7 +146,7 @@ pub(crate) trait Lexer { return ParserResult::no_match(vec![kind]); } let end = input.position(); - children.push(NamedNode::anonymous(cst::Node::token( + children.push(LabeledNode::anonymous(cst::Node::token( kind, input.content(start.utf8..end.utf8), ))); diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/ast_selectors.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/ast_selectors.rs index 1751307f54..4d5d225937 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/ast_selectors.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/ast_selectors.rs @@ -8,7 +8,7 @@ use napi::{Env, JsObject}; use napi_derive::napi; use crate::napi_interface::cst::{RuleNode, ToJS}; -use crate::napi_interface::{RuleKind, RustNamedNode, RustNode, RustRuleNode, TokenKind}; +use crate::napi_interface::{RuleKind, RustLabeledNode, RustNode, RustRuleNode, TokenKind}; // // Sequences: @@ -247,16 +247,16 @@ impl Selector { fn try_select(&mut self, filter: impl FnOnce(&RustNode) -> bool) -> Result> { while let Some(child) = self.node.children.get(self.index) { match child { - RustNamedNode { - name: _, + RustLabeledNode { + label: _, node: RustNode::Rule(rule), } if rule.kind.is_trivia() => { // skip trivia, since it's not part of the AST self.index += 1; continue; } - RustNamedNode { - name: _, + RustLabeledNode { + label: _, node: RustNode::Token(token), } if matches!(token.kind, TokenKind::SKIPPED) => { return Error::SkippedToken(self.index).into(); diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cursor.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cursor.rs index ead1ce0faf..4455978600 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cursor.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cursor.rs @@ -11,7 +11,7 @@ use napi::JsObject; use napi_derive::napi; use text_index::{TextIndex, TextRange}; -use crate::napi_interface::{cst, text_index, FieldName, RuleKind, RustCursor, TokenKind}; +use crate::napi_interface::{cst, text_index, NodeLabel, RuleKind, RustCursor, TokenKind}; #[napi(namespace = "cursor")] pub struct Cursor(pub(super) RustCursor); @@ -59,9 +59,9 @@ impl Cursor { self.0.node().to_js(&env) } - #[napi(getter, ts_return_type = "kinds.FieldName", catch_unwind)] - pub fn node_name(&self) -> Option { - self.0.node_name() + #[napi(getter, ts_return_type = "kinds.NodeLabel", catch_unwind)] + pub fn label(&self) -> Option { + self.0.label() } #[napi(getter, ts_return_type = "text_index.TextIndex", catch_unwind)] diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/mod.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/mod.rs index dba74b99c6..521b5429d7 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/mod.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/mod.rs @@ -9,7 +9,7 @@ pub mod query; pub mod text_index; type RustCursor = crate::cursor::Cursor; -type RustNamedNode = crate::cst::NamedNode; +type RustLabeledNode = crate::cst::LabeledNode; type RustNode = crate::cst::Node; type RustParseError = crate::parse_error::ParseError; type RustParseOutput = crate::parse_output::ParseOutput; @@ -23,4 +23,4 @@ type RustTokenNode = crate::cst::TokenNode; type RuleKind = crate::kinds::RuleKind; type TokenKind = crate::kinds::TokenKind; -type FieldName = crate::kinds::FieldName; +type NodeLabel = crate::kinds::NodeLabel; diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/parser_support/parser_function.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/parser_support/parser_function.rs index 03b55bec84..fffdf93c8f 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/parser_support/parser_function.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/parser_support/parser_function.rs @@ -2,7 +2,7 @@ use std::rc::Rc; -use crate::cst::{self, NamedNode}; +use crate::cst::{self, LabeledNode}; use crate::kinds::TokenKind; use crate::lexer::Lexer; use crate::parse_error::ParseError; @@ -86,7 +86,7 @@ where }; let topmost_rule = match &nodes[..] { - [NamedNode { node: cst::Node::Rule(rule), ..} ] => Rc::clone(rule), + [LabeledNode { node: cst::Node::Rule(rule), ..} ] => Rc::clone(rule), [_] => unreachable!( "(Incomplete)Match at the top level of a parser is not a Rule node" ), @@ -109,7 +109,7 @@ where let skipped_node = cst::Node::token(TokenKind::SKIPPED, input[start.utf8..].to_string()); let mut new_children = topmost_rule.children.clone(); - new_children.push(NamedNode::anonymous(skipped_node)); + new_children.push(LabeledNode::anonymous(skipped_node)); let mut errors = stream.into_errors(); errors.push(ParseError::new(start..input.into(), expected_tokens)); diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/parser_support/parser_result.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/parser_support/parser_result.rs index 056ad458d8..138ba829a5 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/parser_support/parser_result.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/parser_support/parser_result.rs @@ -2,8 +2,8 @@ use std::ops::ControlFlow; -use crate::cst::{self, NamedNode}; -use crate::kinds::{FieldName, RuleKind, TokenKind}; +use crate::cst::{self, LabeledNode}; +use crate::kinds::{NodeLabel, RuleKind, TokenKind}; use crate::text_index::TextIndex; #[derive(PartialEq, Eq, Clone, Debug)] @@ -24,7 +24,7 @@ impl Default for ParserResult { } impl ParserResult { - pub fn r#match(nodes: Vec, expected_tokens: Vec) -> Self { + pub fn r#match(nodes: Vec, expected_tokens: Vec) -> Self { ParserResult::Match(Match::new(nodes, expected_tokens)) } @@ -32,7 +32,7 @@ impl ParserResult { ParserResult::PrattOperatorMatch(PrattOperatorMatch::new(elements)) } - pub fn incomplete_match(nodes: Vec, expected_tokens: Vec) -> Self { + pub fn incomplete_match(nodes: Vec, expected_tokens: Vec) -> Self { ParserResult::IncompleteMatch(IncompleteMatch::new(nodes, expected_tokens)) } @@ -49,21 +49,21 @@ impl ParserResult { pub fn with_kind(self, new_kind: RuleKind) -> ParserResult { match self { ParserResult::Match(r#match) => ParserResult::r#match( - vec![NamedNode::anonymous(cst::Node::rule( + vec![LabeledNode::anonymous(cst::Node::rule( new_kind, r#match.nodes, ))], r#match.expected_tokens, ), ParserResult::IncompleteMatch(incomplete_match) => ParserResult::incomplete_match( - vec![NamedNode::anonymous(cst::Node::rule( + vec![LabeledNode::anonymous(cst::Node::rule( new_kind, incomplete_match.nodes, ))], incomplete_match.expected_tokens, ), ParserResult::SkippedUntil(skipped) => ParserResult::SkippedUntil(SkippedUntil { - nodes: vec![NamedNode::anonymous(cst::Node::rule( + nodes: vec![LabeledNode::anonymous(cst::Node::rule( new_kind, skipped.nodes, ))], @@ -77,21 +77,21 @@ impl ParserResult { } #[must_use] - pub fn with_name(mut self, name: FieldName) -> ParserResult { - if let Some(NamedNode { - name: prev_name, .. + pub fn with_label(mut self, label: NodeLabel) -> ParserResult { + if let Some(LabeledNode { + label: prev_label, .. }) = self.significant_node_mut() { - *prev_name = Some(name); + *prev_label = Some(label); } self } /// Returns a significant (non-trivia) node if there is exactly one. - pub(crate) fn significant_node_mut(&mut self) -> Option<&mut cst::NamedNode> { - fn is_significant(named: &cst::NamedNode) -> bool { - match &named.node { + pub(crate) fn significant_node_mut(&mut self) -> Option<&mut cst::LabeledNode> { + fn is_significant(labeled: &cst::LabeledNode) -> bool { + match &labeled.node { cst::Node::Rule(rule) => !rule.kind.is_trivia(), // FIXME: Some tokens are in fact trivia cst::Node::Token(_) => true, @@ -121,13 +121,13 @@ impl ParserResult { #[derive(PartialEq, Eq, Clone, Debug)] pub struct Match { - pub nodes: Vec, + pub nodes: Vec, /// Tokens that would have allowed for more progress. Collected for the purposes of error reporting. pub expected_tokens: Vec, } impl Match { - pub fn new(nodes: Vec, expected_tokens: Vec) -> Self { + pub fn new(nodes: Vec, expected_tokens: Vec) -> Self { Self { nodes, expected_tokens, @@ -145,34 +145,34 @@ impl Match { #[derive(PartialEq, Eq, Clone, Debug)] pub enum PrattElement { Expression { - nodes: Vec, + nodes: Vec, }, Prefix { kind: RuleKind, - nodes: Vec, + nodes: Vec, right: u8, }, Binary { kind: RuleKind, - nodes: Vec, + nodes: Vec, left: u8, right: u8, }, Postfix { kind: RuleKind, - nodes: Vec, + nodes: Vec, left: u8, }, } impl PrattElement { - pub fn into_nodes(self) -> Vec { + pub fn into_nodes(self) -> Vec { match self { Self::Expression { nodes } => nodes, Self::Binary { kind, nodes, .. } | Self::Prefix { kind, nodes, .. } | Self::Postfix { kind, nodes, .. } => { - vec![NamedNode::anonymous(cst::Node::rule(kind, nodes))] + vec![LabeledNode::anonymous(cst::Node::rule(kind, nodes))] } } } @@ -191,13 +191,13 @@ impl PrattOperatorMatch { #[derive(PartialEq, Eq, Clone, Debug)] pub struct IncompleteMatch { - pub nodes: Vec, + pub nodes: Vec, /// Tokens that would have allowed for more progress. Collected for the purposes of error reporting. pub expected_tokens: Vec, } impl IncompleteMatch { - pub fn new(nodes: Vec, expected_tokens: Vec) -> Self { + pub fn new(nodes: Vec, expected_tokens: Vec) -> Self { Self { nodes, expected_tokens, @@ -219,7 +219,7 @@ impl NoMatch { #[derive(PartialEq, Eq, Clone, Debug)] pub struct SkippedUntil { - pub nodes: Vec, + pub nodes: Vec, /// Skipped text following the last node pub skipped: String, /// At which token was the stream pointing at when we bailed diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/parser_support/precedence_helper.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/parser_support/precedence_helper.rs index 9a7ff657e8..eee625e583 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/parser_support/precedence_helper.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/parser_support/precedence_helper.rs @@ -1,7 +1,7 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. -use crate::cst::{self, NamedNode}; -use crate::kinds::{FieldName, RuleKind}; +use crate::cst::{self, LabeledNode}; +use crate::kinds::{NodeLabel, RuleKind}; use crate::parser_support::parser_result::PrattElement::{ self, Binary, Expression, Postfix, Prefix, }; @@ -152,21 +152,21 @@ impl PrecedenceHelper { let make_expression = |left: Option, kind: RuleKind, - nodes: Vec, + nodes: Vec, right: Option| { assert!(left.is_some() || right.is_some()); - let left_name = right + let left_label = right .as_ref() - .map_or(FieldName::Operand, |_| FieldName::LeftOperand); - let right_name = left + .map_or(NodeLabel::Operand, |_| NodeLabel::LeftOperand); + let right_label = left .as_ref() - .map_or(FieldName::Operand, |_| FieldName::RightOperand); + .map_or(NodeLabel::Operand, |_| NodeLabel::RightOperand); let left_nodes = match left { Some(Expression { nodes }) => { - vec![NamedNode { - name: Some(left_name), + vec![LabeledNode { + label: Some(left_label), node: cst::Node::rule(child_kind, nodes), }] } @@ -176,8 +176,8 @@ impl PrecedenceHelper { let right_nodes = match right { Some(Expression { nodes }) => { - vec![NamedNode { - name: Some(right_name), + vec![LabeledNode { + label: Some(right_label), node: cst::Node::rule(child_kind, nodes), }] } @@ -188,8 +188,8 @@ impl PrecedenceHelper { let children = [left_nodes, nodes, right_nodes].concat(); Expression { - nodes: vec![NamedNode { - name: Some(FieldName::Variant), + nodes: vec![LabeledNode { + label: Some(NodeLabel::Variant), node: cst::Node::rule(kind, children), }], } diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/parser_support/recovery.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/parser_support/recovery.rs index 2584e20915..563d3a60bf 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/parser_support/recovery.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/parser_support/recovery.rs @@ -25,7 +25,7 @@ impl RecoverFromNoMatch { fn opt_parse( input: &mut ParserContext<'_>, parse: impl Fn(&mut ParserContext<'_>) -> ParserResult, -) -> Vec { +) -> Vec { let start = input.position(); if let ParserResult::Match(r#match) = parse(input) { r#match.nodes diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/parser_support/separated_helper.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/parser_support/separated_helper.rs index b1fdee1954..f107fd0cef 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/parser_support/separated_helper.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/parser_support/separated_helper.rs @@ -1,7 +1,7 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. -use crate::cst::{self, NamedNode}; -use crate::kinds::{FieldName, IsLexicalContext, TokenKind}; +use crate::cst::{self, LabeledNode}; +use crate::kinds::{IsLexicalContext, NodeLabel, TokenKind}; use crate::lexer::Lexer; use crate::parse_error::ParseError; use crate::parser_support::parser_result::{ParserResult, SkippedUntil}; @@ -17,7 +17,7 @@ impl SeparatedHelper { lexer: &L, body_parser: impl Fn(&mut ParserContext<'_>) -> ParserResult, separator: TokenKind, - separator_field_name: FieldName, + separator_label: NodeLabel, ) -> ParserResult { let mut accum = vec![]; loop { @@ -29,7 +29,7 @@ impl SeparatedHelper { Some(scanned) if scanned.accepted_as(separator) => { match lexer .parse_token_with_trivia::(input, separator) - .with_name(separator_field_name) + .with_label(separator_label) { ParserResult::Match(r#match) => { accum.extend(r#match.nodes); @@ -55,7 +55,7 @@ impl SeparatedHelper { match skip_until_with_nested_delims::<_, LexCtx>(input, lexer, separator) { // A separator was found, so we can recover the incomplete match Some((found, skipped_range)) if found == separator => { - accum.push(NamedNode::anonymous(cst::Node::token( + accum.push(LabeledNode::anonymous(cst::Node::token( TokenKind::SKIPPED, input.content(skipped_range.utf8()), ))); diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/parser_support/sequence_helper.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/parser_support/sequence_helper.rs index 4050cdf757..1d5b1b4596 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/parser_support/sequence_helper.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/parser_support/sequence_helper.rs @@ -2,8 +2,8 @@ use std::ops::ControlFlow; -use crate::cst::{self, NamedNode}; -use crate::kinds::{FieldName, TokenKind}; +use crate::cst::{self, LabeledNode}; +use crate::kinds::{NodeLabel, TokenKind}; use crate::parser_support::parser_result::{Match, ParserResult, PrattElement, SkippedUntil}; /// Keeps accumulating parses sequentially until it hits an incomplete or no match. @@ -137,7 +137,7 @@ impl SequenceHelper { debug_assert!(is_single_token_with_trivia); debug_assert_eq!(next_token, Some(running.found)); - running.nodes.push(NamedNode::anonymous(cst::Node::token( + running.nodes.push(LabeledNode::anonymous(cst::Node::token( TokenKind::SKIPPED, std::mem::take(&mut running.skipped), ))); @@ -186,13 +186,13 @@ impl SequenceHelper { /// Aggregates a parse result into the sequence. If we cannot make progress, returns the accumulated match. /// - /// Shorthand for `self.elem(value.with_name(name))`. - pub fn elem_named( + /// Shorthand for `self.elem(value.with_label(label))`. + pub fn elem_labeled( &mut self, - name: FieldName, + label: NodeLabel, value: ParserResult, ) -> ControlFlow { - self.elem(value.with_name(name)) + self.elem(value.with_label(label)) } /// Finishes the sequence parse, returning the accumulated match. diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/query/engine.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/query/engine.rs index 82fa136c78..6cdb482c51 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/query/engine.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/query/engine.rs @@ -33,23 +33,23 @@ impl Cursor { NodeSelector::Anonymous => true, NodeSelector::Kind { kind } => Kind::Rule(rule.kind) == *kind, NodeSelector::Text { .. } => false, - NodeSelector::FieldName { field_name } => Some(*field_name) == self.node_name(), - NodeSelector::FieldNameAndKind { field_name, kind } => { - Some(*field_name) == self.node_name() && Kind::Rule(rule.kind) == *kind + NodeSelector::Label { label } => Some(*label) == self.label(), + NodeSelector::LabelAndKind { label, kind } => { + Some(*label) == self.label() && Kind::Rule(rule.kind) == *kind } - NodeSelector::FieldNameAndText { .. } => false, + NodeSelector::LabelAndText { .. } => false, }, cst::Node::Token(token) => match node_selector { NodeSelector::Anonymous => true, NodeSelector::Kind { kind } => Kind::Token(token.kind) == *kind, NodeSelector::Text { text } => token.text == *text, - NodeSelector::FieldName { field_name } => Some(*field_name) == self.node_name(), - NodeSelector::FieldNameAndKind { field_name, kind } => { - Some(*field_name) == self.node_name() && Kind::Token(token.kind) == *kind + NodeSelector::Label { label } => Some(*label) == self.label(), + NodeSelector::LabelAndKind { label, kind } => { + Some(*label) == self.label() && Kind::Token(token.kind) == *kind } - NodeSelector::FieldNameAndText { field_name, text } => { - Some(*field_name) == self.node_name() && token.text == *text + NodeSelector::LabelAndText { label, text } => { + Some(*label) == self.label() && token.text == *text } }, } diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/query/model.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/query/model.rs index c3bfed9170..50f270ab71 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/query/model.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/query/model.rs @@ -4,7 +4,7 @@ use std::fmt; use std::rc::Rc; // This crate is copied to another crate, so all imports should be relative -use super::super::kinds::{FieldName, RuleKind, TokenKind}; +use super::super::kinds::{NodeLabel, RuleKind, TokenKind}; #[derive(Clone)] pub struct Query(pub(super) Matcher); @@ -108,9 +108,9 @@ pub(super) enum NodeSelector { Anonymous, Kind { kind: Kind }, Text { text: String }, - FieldName { field_name: FieldName }, - FieldNameAndKind { field_name: FieldName, kind: Kind }, - FieldNameAndText { field_name: FieldName, text: String }, + Label { label: NodeLabel }, + LabelAndKind { label: NodeLabel, kind: Kind }, + LabelAndText { label: NodeLabel, text: String }, } impl fmt::Display for NodeSelector { @@ -136,12 +136,12 @@ impl fmt::Display for NodeSelector { Self::Anonymous => write!(f, "_"), Self::Kind { kind } => kind.fmt(f), Self::Text { text } => write!(f, "\"{}\"", escape_string(text)), - Self::FieldName { field_name } => field_name.fmt(f), - Self::FieldNameAndKind { field_name, kind } => { - write!(f, "{field_name}; {kind}") + Self::Label { label } => label.fmt(f), + Self::LabelAndKind { label, kind } => { + write!(f, "{label}; {kind}") } - Self::FieldNameAndText { field_name, text } => { - write!(f, "{field_name}: \"{}\"", escape_string(text)) + Self::LabelAndText { label, text } => { + write!(f, "{label}: \"{}\"", escape_string(text)) } } } diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/query/parser.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/query/parser.rs index cb867fb2a3..cdc0a09d5c 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/query/parser.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/query/parser.rs @@ -12,7 +12,7 @@ use nom::sequence::{delimited, pair, preceded, terminated}; use nom::{Finish, IResult, Parser}; // This crate is copied to another crate, so all imports should be relative -use super::super::kinds::{FieldName, RuleKind, TokenKind}; +use super::super::kinds::{NodeLabel, RuleKind, TokenKind}; use super::model::{ AlternativesMatcher, BindingMatcher, Kind, Matcher, NodeMatcher, NodeSelector, OneOrMoreMatcher, OptionalMatcher, SequenceMatcher, @@ -78,25 +78,19 @@ fn parse_node_selector(input: &str) -> IResult<&str, NodeSelector, VerboseError< Text(String), } - opt(field_name_token) + opt(label_token) .and(alt(( token('_').map(|_| Tail::Anonymous), kind_token.map(Tail::Kind), text_token.map(Tail::Text), ))) - .map(|(field_name, tail)| match (field_name, tail) { + .map(|(label, tail)| match (label, tail) { (None, Tail::Anonymous) => NodeSelector::Anonymous, (None, Tail::Kind(kind)) => NodeSelector::Kind { kind }, (None, Tail::Text(string)) => NodeSelector::Text { text: string }, - (Some(field), Tail::Anonymous) => NodeSelector::FieldName { field_name: field }, - (Some(field), Tail::Kind(kind)) => NodeSelector::FieldNameAndKind { - field_name: field, - kind, - }, - (Some(field), Tail::Text(string)) => NodeSelector::FieldNameAndText { - field_name: field, - text: string, - }, + (Some(label), Tail::Anonymous) => NodeSelector::Label { label }, + (Some(label), Tail::Kind(kind)) => NodeSelector::LabelAndKind { label, kind }, + (Some(label), Tail::Text(text)) => NodeSelector::LabelAndText { label, text }, }) .parse(input) } @@ -191,9 +185,9 @@ fn kind_token(i: &str) -> IResult<&str, Kind, VerboseError<&str>> { .parse(i) } -fn field_name_token(i: &str) -> IResult<&str, FieldName, VerboseError<&str>> { +fn label_token(i: &str) -> IResult<&str, NodeLabel, VerboseError<&str>> { terminated(raw_identifier, token(':')) - .map(|id| FieldName::try_from(id.as_str()).unwrap()) + .map(|id| NodeLabel::try_from(id.as_str()).unwrap()) .parse(i) } diff --git a/crates/testlang/outputs/cargo/tests/src/query/engine_tests.rs b/crates/testlang/outputs/cargo/tests/src/query/engine_tests.rs index cc6445764b..2d406bf0da 100644 --- a/crates/testlang/outputs/cargo/tests/src/query/engine_tests.rs +++ b/crates/testlang/outputs/cargo/tests/src/query/engine_tests.rs @@ -1,26 +1,26 @@ use std::collections::{BTreeMap, HashMap}; // This crate is copied to another crate, so all imports should be relative -use slang_testlang::cst::{NamedNode, Node}; +use slang_testlang::cst::{LabeledNode, Node}; use slang_testlang::cursor::Cursor; -use slang_testlang::kinds::{FieldName, RuleKind, TokenKind}; +use slang_testlang::kinds::{NodeLabel, RuleKind, TokenKind}; use slang_testlang::query::{Query, QueryResult}; use slang_testlang::text_index::TextIndex; -fn token(name: Option, kind: TokenKind, text: &str) -> NamedNode { - NamedNode { - name, +fn token(label: Option, kind: TokenKind, text: &str) -> LabeledNode { + LabeledNode { + label, node: Node::token(kind, text.to_string()), } } fn rule( - name: Option, + label: Option, kind: RuleKind, - children: [NamedNode; N], -) -> NamedNode { - NamedNode { - name, + children: [LabeledNode; N], +) -> LabeledNode { + LabeledNode { + label, node: Node::rule(kind, children.into_iter().collect()), } } @@ -46,16 +46,16 @@ fn binding_cursors_to_strings( macro_rules! cst_tree { ( @inner [ $($child:expr)* ]) => { [ $($child),* ] }; - ( @inner [ $($child:expr)* ] $field_name:ident : $token_kind:ident $text:literal $(, $($rest:tt)*)? ) => { - cst_tree!(@inner [ $($child)* token(Some(FieldName::$field_name), TokenKind::$token_kind, $text) ] $($($rest)*)?) + ( @inner [ $($child:expr)* ] $label:ident : $token_kind:ident $text:literal $(, $($rest:tt)*)? ) => { + cst_tree!(@inner [ $($child)* token(Some(NodeLabel::$label), TokenKind::$token_kind, $text) ] $($($rest)*)?) }; ( @inner [ $($child:expr)* ] $token_kind:ident $text:literal $(, $($rest:tt)*)? ) => { cst_tree!(@inner [ $($child)* token(None, TokenKind::$token_kind, $text) ] $($($rest)*)?) }; - ( @inner [ $($child:expr)* ] $field_name:ident : $rule_kind:ident [ $($children:tt)* ] $(, $($rest:tt)*)? ) => { - cst_tree!(@inner [ $($child)* rule(Some(FieldName::$field_name), RuleKind::$rule_kind, cst_tree!(@inner [] $($children)*)) ] $($($rest)*)?) + ( @inner [ $($child:expr)* ] $label:ident : $rule_kind:ident [ $($children:tt)* ] $(, $($rest:tt)*)? ) => { + cst_tree!(@inner [ $($child)* rule(Some(NodeLabel::$label), RuleKind::$rule_kind, cst_tree!(@inner [] $($children)*)) ] $($($rest)*)?) }; ( @inner [ $($child:expr)* ] $rule_kind:ident [ $($children:tt)* ] $(, $($rest:tt)*)? ) => { @@ -63,8 +63,8 @@ macro_rules! cst_tree { }; // Start with a rule - ( $field_name:ident : $rule_kind:ident [ $($children:tt)* ] ) => { - rule(Some(FieldName::$field_name), RuleKind::$rule_kind, cst_tree!(@inner [] $($children)*)) + ( $label:ident : $rule_kind:ident [ $($children:tt)* ] ) => { + rule(Some(NodeLabel::$label), RuleKind::$rule_kind, cst_tree!(@inner [] $($children)*)) }; ( $rule_kind:ident [ $($children:tt)* ] ) => { @@ -85,7 +85,7 @@ macro_rules! query_results { } -fn run_query_test(tree: &NamedNode, query: &str, results: Vec>>) { +fn run_query_test(tree: &LabeledNode, query: &str, results: Vec>>) { let cursor = tree.cursor_with_offset(TextIndex::ZERO); let query = vec![Query::parse(query).unwrap()]; let mut results = results.into_iter(); @@ -102,7 +102,7 @@ fn run_query_test(tree: &NamedNode, query: &str, results: Vec NamedNode { +fn common_test_tree() -> LabeledNode { cst_tree!( TreeNode [ Node: DelimitedIdentifier "A", diff --git a/crates/testlang/outputs/npm/package/src/generated/index.d.ts b/crates/testlang/outputs/npm/package/src/generated/index.d.ts index 8c382e05bc..b12ac51fd2 100644 --- a/crates/testlang/outputs/npm/package/src/generated/index.d.ts +++ b/crates/testlang/outputs/npm/package/src/generated/index.d.ts @@ -22,7 +22,7 @@ export namespace kinds { TreeNodeChild = "TreeNodeChild", TreeNodeChildren = "TreeNodeChildren", } - export enum FieldName { + export enum NodeLabel { Item = "Item", Variant = "Variant", Separator = "Separator", @@ -96,7 +96,7 @@ export namespace cursor { spawn(): Cursor; get isCompleted(): boolean; node(): cst.Node; - get nodeName(): kinds.FieldName; + get label(): kinds.NodeLabel; get textOffset(): text_index.TextIndex; get textRange(): text_index.TextRange; get depth(): number; diff --git a/crates/testlang/outputs/npm/package/src/kinds/index.ts b/crates/testlang/outputs/npm/package/src/kinds/index.ts index 9061014c27..0c1d84aa75 100644 --- a/crates/testlang/outputs/npm/package/src/kinds/index.ts +++ b/crates/testlang/outputs/npm/package/src/kinds/index.ts @@ -6,5 +6,5 @@ export type RuleKind = generated.kinds.RuleKind; export const TokenKind = generated.kinds.TokenKind; export type TokenKind = generated.kinds.TokenKind; -export const FieldName = generated.kinds.FieldName; -export type FieldName = generated.kinds.FieldName; +export const NodeLabel = generated.kinds.NodeLabel; +export type NodeLabel = generated.kinds.NodeLabel; diff --git a/crates/testlang/outputs/npm/tests/src/tests/cst-cursor.ts b/crates/testlang/outputs/npm/tests/src/tests/cst-cursor.ts index fdf4d937f3..8526ddeb7e 100644 --- a/crates/testlang/outputs/npm/tests/src/tests/cst-cursor.ts +++ b/crates/testlang/outputs/npm/tests/src/tests/cst-cursor.ts @@ -1,5 +1,5 @@ import { Language } from "@slang-private/slang-testlang/language"; -import { FieldName, RuleKind, TokenKind } from "@slang-private/slang-testlang/kinds"; +import { NodeLabel, RuleKind, TokenKind } from "@slang-private/slang-testlang/kinds"; import { Cursor } from "@slang-private/slang-testlang/cursor"; import { expectRule, expectToken } from "../utils/cst-helpers"; import { NodeType } from "@slang-private/slang-testlang/cst"; @@ -117,9 +117,9 @@ test("access the node using its name", () => { const innerCursor = cursor.spawn(); while (innerCursor.goToNext()) { const node = innerCursor.node(); - const nodeName = innerCursor.nodeName; + const label = innerCursor.label; - if (node.type == NodeType.Token && (nodeName == FieldName.OpenBracket || nodeName == FieldName.CloseBracket)) { + if (node.type == NodeType.Token && (label == NodeLabel.OpenBracket || label == NodeLabel.CloseBracket)) { names.push(node.text); } } diff --git a/documentation/public/user-guide/rust-crate/using-the-cursor.md b/documentation/public/user-guide/rust-crate/using-the-cursor.md index 3482e59ba4..2f6dd2dc7a 100644 --- a/documentation/public/user-guide/rust-crate/using-the-cursor.md +++ b/documentation/public/user-guide/rust-crate/using-the-cursor.md @@ -64,12 +64,12 @@ Let's use that to extract all `Identifier` nodes from the source text using that ## Using a Cursor with Names -In addition to the basic `Cursor`, there's also a `CursorWithNames` type +In addition to the basic `Cursor`, there's also a `CursorWithLabels` type that keeps track of the names of the nodes it visits. -You can create a `CursorWithNames` from a `Cursor` by using the `with_names()` API. +You can create a `CursorWithLabels` from a `Cursor` by using the `with_labels()` API. -Let's use that to extract all nodes that are named `Name`: +Let's use that to extract all nodes that are labeled `Name`: ```{ .rust } ---8<-- "crates/solidity/outputs/cargo/tests/src/doc_examples/using_the_cursor.rs:using-named-cursors" +--8<-- "crates/solidity/outputs/cargo/tests/src/doc_examples/using_the_cursor.rs:using-labeled-cursors" ```