From 5706ae9cad7d728d3be4bb99c927289ea0762a53 Mon Sep 17 00:00:00 2001 From: "Arend van Beelen jr." Date: Wed, 21 Feb 2024 08:28:10 +0100 Subject: [PATCH 01/12] WIP: GritQL parser --- Cargo.lock | 82 + Cargo.toml | 4 + crates/biome_grit_factory/Cargo.toml | 18 + crates/biome_grit_factory/src/generated.rs | 6 + .../src/generated/node_factory.rs | 2240 +++ .../src/generated/syntax_factory.rs | 3582 +++++ crates/biome_grit_factory/src/lib.rs | 11 + crates/biome_grit_formatter/Cargo.toml | 56 + crates/biome_grit_formatter/src/lib.rs | 0 crates/biome_grit_parser/Cargo.toml | 49 + crates/biome_grit_parser/src/lib.rs | 0 crates/biome_grit_syntax/Cargo.toml | 28 + crates/biome_grit_syntax/src/generated.rs | 11 + .../biome_grit_syntax/src/generated/kind.rs | 387 + .../biome_grit_syntax/src/generated/macros.rs | 481 + .../biome_grit_syntax/src/generated/nodes.rs | 12249 ++++++++++++++++ .../src/generated/nodes_mut.rs | 2200 +++ crates/biome_grit_syntax/src/lib.rs | 110 + crates/biome_grit_syntax/src/syntax_node.rs | 28 + xtask/codegen/gritql.ungram | 554 + xtask/codegen/src/ast.rs | 25 +- xtask/codegen/src/formatter.rs | 17 + xtask/codegen/src/generate_nodes.rs | 4 +- xtask/codegen/src/generate_syntax_factory.rs | 5 + xtask/codegen/src/generate_syntax_kinds.rs | 15 +- xtask/codegen/src/grit_kinds_src.rs | 226 + xtask/codegen/src/js_kinds_src.rs | 2 + xtask/codegen/src/lib.rs | 19 +- 28 files changed, 22401 insertions(+), 8 deletions(-) create mode 100644 crates/biome_grit_factory/Cargo.toml create mode 100644 crates/biome_grit_factory/src/generated.rs create mode 100644 crates/biome_grit_factory/src/generated/node_factory.rs create mode 100644 crates/biome_grit_factory/src/generated/syntax_factory.rs create mode 100644 crates/biome_grit_factory/src/lib.rs create mode 100644 crates/biome_grit_formatter/Cargo.toml create mode 100644 crates/biome_grit_formatter/src/lib.rs create mode 100644 crates/biome_grit_parser/Cargo.toml create mode 100644 crates/biome_grit_parser/src/lib.rs create mode 100644 crates/biome_grit_syntax/Cargo.toml create mode 100644 crates/biome_grit_syntax/src/generated.rs create mode 100644 crates/biome_grit_syntax/src/generated/kind.rs create mode 100644 crates/biome_grit_syntax/src/generated/macros.rs create mode 100644 crates/biome_grit_syntax/src/generated/nodes.rs create mode 100644 crates/biome_grit_syntax/src/generated/nodes_mut.rs create mode 100644 crates/biome_grit_syntax/src/lib.rs create mode 100644 crates/biome_grit_syntax/src/syntax_node.rs create mode 100644 xtask/codegen/gritql.ungram create mode 100644 xtask/codegen/src/grit_kinds_src.rs diff --git a/Cargo.lock b/Cargo.lock index 77f2c425e5e..df328bec650 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -435,6 +435,88 @@ dependencies = [ "tracing", ] +[[package]] +name = "biome_grit_factory" +version = "0.4.0" +dependencies = [ + "biome_grit_syntax", + "biome_rowan", +] + +[[package]] +name = "biome_grit_formatter" +version = "0.4.0" +dependencies = [ + "biome_console", + "biome_deserialize", + "biome_deserialize_macros", + "biome_diagnostics", + "biome_diagnostics_categories", + "biome_formatter", + "biome_formatter_test", + "biome_fs", + "biome_grit_factory", + "biome_grit_parser", + "biome_grit_syntax", + "biome_parser", + "biome_rowan", + "biome_text_size", + "biome_unicode_table", + "cfg-if", + "countme", + "insta", + "quickcheck", + "quickcheck_macros", + "schemars", + "serde", + "serde_json", + "smallvec", + "tests_macros", + "tracing", + "unicode-width", +] + +[[package]] +name = "biome_grit_parser" +version = "0.4.0" +dependencies = [ + "biome_console", + "biome_diagnostics", + "biome_grit_factory", + "biome_grit_syntax", + "biome_parser", + "biome_rowan", + "biome_unicode_table", + "bitflags 2.3.1", + "cfg-if", + "drop_bomb", + "expect-test", + "indexmap 1.9.3", + "quickcheck", + "quickcheck_macros", + "rustc-hash", + "schemars", + "serde", + "serde_json", + "smallvec", + "tests_macros", + "tracing", + "unicode-bom", +] + +[[package]] +name = "biome_grit_syntax" +version = "0.4.0" +dependencies = [ + "biome_console", + "biome_diagnostics", + "biome_grit_factory", + "biome_grit_parser", + "biome_rowan", + "schemars", + "serde", +] + [[package]] name = "biome_html_factory" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index 4070eea8c1f..01018bd6774 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -87,6 +87,10 @@ biome_diagnostics_categories = { version = "0.4.0", path = "./crates/biome_diagn biome_diagnostics_macros = { version = "0.4.0", path = "./crates/biome_diagnostics_macros" } biome_formatter = { version = "0.4.0", path = "./crates/biome_formatter" } biome_fs = { version = "0.4.0", path = "./crates/biome_fs" } +biome_grit_factory = { version = "0.4.0", path = "./crates/biome_grit_factory" } +biome_grit_formatter = { version = "0.4.0", path = "./crates/biome_grit_formatter" } +biome_grit_parser = { version = "0.4.0", path = "./crates/biome_grit_parser" } +biome_grit_syntax = { version = "0.4.0", path = "./crates/biome_grit_syntax" } biome_html_factory = { version = "0.4.0", path = "./crates/biome_html_factory" } biome_html_syntax = { version = "0.4.0", path = "./crates/biome_html_syntax" } biome_js_analyze = { version = "0.4.0", path = "./crates/biome_js_analyze" } diff --git a/crates/biome_grit_factory/Cargo.toml b/crates/biome_grit_factory/Cargo.toml new file mode 100644 index 00000000000..c1b8f7e2918 --- /dev/null +++ b/crates/biome_grit_factory/Cargo.toml @@ -0,0 +1,18 @@ +[package] +authors.workspace = true +description = "Utilities to create GritQL AST for biome_grit_parser" +documentation = "https://docs.rs/biome_grit_factory" +edition.workspace = true +license.workspace = true +name = "biome_grit_factory" +repository.workspace = true +version = "0.4.0" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +biome_grit_syntax = { workspace = true } +biome_rowan = { workspace = true } + +[lints] +workspace = true diff --git a/crates/biome_grit_factory/src/generated.rs b/crates/biome_grit_factory/src/generated.rs new file mode 100644 index 00000000000..32cee4d7753 --- /dev/null +++ b/crates/biome_grit_factory/src/generated.rs @@ -0,0 +1,6 @@ +#[rustfmt::skip] +pub(super) mod syntax_factory; +#[rustfmt::skip] +pub(crate) mod node_factory; + +pub use syntax_factory::GritSyntaxFactory; diff --git a/crates/biome_grit_factory/src/generated/node_factory.rs b/crates/biome_grit_factory/src/generated/node_factory.rs new file mode 100644 index 00000000000..3b1959d7f2e --- /dev/null +++ b/crates/biome_grit_factory/src/generated/node_factory.rs @@ -0,0 +1,2240 @@ +//! Generated file, do not edit by hand, see `xtask/codegen` + +#![allow(clippy::redundant_closure)] +#![allow(clippy::too_many_arguments)] +use biome_grit_syntax::{ + GritSyntaxElement as SyntaxElement, GritSyntaxNode as SyntaxNode, + GritSyntaxToken as SyntaxToken, *, +}; +use biome_rowan::AstNode; +pub fn any_grit_pattern( + any_grit_literal: AnyGritLiteral, + grit_pattern_not: GritPatternNot, + grit_pattern_or: GritPatternOr, + grit_pattern_or_else: GritPatternOrElse, + grit_pattern_any: GritPatternAny, + grit_pattern_and: GritPatternAnd, + grit_pattern_maybe: GritPatternMaybe, + grit_pattern_if_else: GritPatternIfElse, + grit_pattern_contains: GritPatternContains, + grit_pattern_includes: GritPatternIncludes, + grit_pattern_after: GritPatternAfter, + grit_pattern_before: GritPatternBefore, + grit_within: GritWithin, + grit_bubble: GritBubble, + grit_node_like: GritNodeLike, + grit_map_accessor: GritMapAccessor, + grit_list_accessor: GritListAccessor, + grit_dot: GritDot, + grit_some: GritSome, + grit_every: GritEvery, + grit_underscore: GritUnderscore, + grit_variable: GritVariable, + grit_regex_pattern: GritRegexPattern, + grit_pattern_as: GritPatternAs, + grit_pattern_limit: GritPatternLimit, + grit_assignment_as_pattern: GritAssignmentAsPattern, + grit_pattern_accumulate: GritPatternAccumulate, + grit_rewrite: GritRewrite, + grit_like: GritLike, + grit_pattern_where: GritPatternWhere, + grit_mul_operation: GritMulOperation, + grit_div_operation: GritDivOperation, + grit_mod_operation: GritModOperation, + grit_add_operation: GritAddOperation, + grit_sub_operation: GritSubOperation, + grit_sequential: GritSequential, + grit_files: GritFiles, + l_paren_token: SyntaxToken, + any_grit_pattern: AnyGritPattern, + r_paren_token: SyntaxToken, + grit_bogus_pattern: GritBogusPattern, +) -> AnyGritPattern { + AnyGritPattern::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::ANY_GRIT_PATTERN, + [ + Some(SyntaxElement::Node(any_grit_literal.into_syntax())), + Some(SyntaxElement::Node(grit_pattern_not.into_syntax())), + Some(SyntaxElement::Node(grit_pattern_or.into_syntax())), + Some(SyntaxElement::Node(grit_pattern_or_else.into_syntax())), + Some(SyntaxElement::Node(grit_pattern_any.into_syntax())), + Some(SyntaxElement::Node(grit_pattern_and.into_syntax())), + Some(SyntaxElement::Node(grit_pattern_maybe.into_syntax())), + Some(SyntaxElement::Node(grit_pattern_if_else.into_syntax())), + Some(SyntaxElement::Node(grit_pattern_contains.into_syntax())), + Some(SyntaxElement::Node(grit_pattern_includes.into_syntax())), + Some(SyntaxElement::Node(grit_pattern_after.into_syntax())), + Some(SyntaxElement::Node(grit_pattern_before.into_syntax())), + Some(SyntaxElement::Node(grit_within.into_syntax())), + Some(SyntaxElement::Node(grit_bubble.into_syntax())), + Some(SyntaxElement::Node(grit_node_like.into_syntax())), + Some(SyntaxElement::Node(grit_map_accessor.into_syntax())), + Some(SyntaxElement::Node(grit_list_accessor.into_syntax())), + Some(SyntaxElement::Node(grit_dot.into_syntax())), + Some(SyntaxElement::Node(grit_some.into_syntax())), + Some(SyntaxElement::Node(grit_every.into_syntax())), + Some(SyntaxElement::Node(grit_underscore.into_syntax())), + Some(SyntaxElement::Node(grit_variable.into_syntax())), + Some(SyntaxElement::Node(grit_regex_pattern.into_syntax())), + Some(SyntaxElement::Node(grit_pattern_as.into_syntax())), + Some(SyntaxElement::Node(grit_pattern_limit.into_syntax())), + Some(SyntaxElement::Node( + grit_assignment_as_pattern.into_syntax(), + )), + Some(SyntaxElement::Node(grit_pattern_accumulate.into_syntax())), + Some(SyntaxElement::Node(grit_rewrite.into_syntax())), + Some(SyntaxElement::Node(grit_like.into_syntax())), + Some(SyntaxElement::Node(grit_pattern_where.into_syntax())), + Some(SyntaxElement::Node(grit_mul_operation.into_syntax())), + Some(SyntaxElement::Node(grit_div_operation.into_syntax())), + Some(SyntaxElement::Node(grit_mod_operation.into_syntax())), + Some(SyntaxElement::Node(grit_add_operation.into_syntax())), + Some(SyntaxElement::Node(grit_sub_operation.into_syntax())), + Some(SyntaxElement::Node(grit_sequential.into_syntax())), + Some(SyntaxElement::Node(grit_files.into_syntax())), + Some(SyntaxElement::Token(l_paren_token)), + Some(SyntaxElement::Node(any_grit_pattern.into_syntax())), + Some(SyntaxElement::Token(r_paren_token)), + Some(SyntaxElement::Node(grit_bogus_pattern.into_syntax())), + ], + )) +} +pub fn any_grit_predicate( + grit_predicate_not: GritPredicateNot, + grit_predicate_maybe: GritPredicateMaybe, + grit_predicate_and: GritPredicateAnd, + grit_predicate_or: GritPredicateOr, + grit_predicate_any: GritPredicateAny, + grit_predicate_if_else: GritPredicateIfElse, + grit_predicate_assignment: GritPredicateAssignment, + grit_predicate_accumulate: GritPredicateAccumulate, + grit_predicate_rewrite: GritPredicateRewrite, + grit_predicate_greater: GritPredicateGreater, + grit_predicate_less: GritPredicateLess, + grit_predicate_greater_equal: GritPredicateGreaterEqual, + grit_predicate_less_equal: GritPredicateLessEqual, + grit_predicate_not_equal: GritPredicateNotEqual, + grit_predicate_equal: GritPredicateEqual, + grit_predicate_match: GritPredicateMatch, + grit_predicate_call: GritPredicateCall, + l_paren_token: SyntaxToken, + any_grit_predicate: AnyGritPredicate, + r_paren_token: SyntaxToken, + grit_boolean_literal: GritBooleanLiteral, + grit_predicate_return: GritPredicateReturn, + grit_bogus_predicate: GritBogusPredicate, +) -> AnyGritPredicate { + AnyGritPredicate::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::ANY_GRIT_PREDICATE, + [ + Some(SyntaxElement::Node(grit_predicate_not.into_syntax())), + Some(SyntaxElement::Node(grit_predicate_maybe.into_syntax())), + Some(SyntaxElement::Node(grit_predicate_and.into_syntax())), + Some(SyntaxElement::Node(grit_predicate_or.into_syntax())), + Some(SyntaxElement::Node(grit_predicate_any.into_syntax())), + Some(SyntaxElement::Node(grit_predicate_if_else.into_syntax())), + Some(SyntaxElement::Node(grit_predicate_assignment.into_syntax())), + Some(SyntaxElement::Node(grit_predicate_accumulate.into_syntax())), + Some(SyntaxElement::Node(grit_predicate_rewrite.into_syntax())), + Some(SyntaxElement::Node(grit_predicate_greater.into_syntax())), + Some(SyntaxElement::Node(grit_predicate_less.into_syntax())), + Some(SyntaxElement::Node( + grit_predicate_greater_equal.into_syntax(), + )), + Some(SyntaxElement::Node(grit_predicate_less_equal.into_syntax())), + Some(SyntaxElement::Node(grit_predicate_not_equal.into_syntax())), + Some(SyntaxElement::Node(grit_predicate_equal.into_syntax())), + Some(SyntaxElement::Node(grit_predicate_match.into_syntax())), + Some(SyntaxElement::Node(grit_predicate_call.into_syntax())), + Some(SyntaxElement::Token(l_paren_token)), + Some(SyntaxElement::Node(any_grit_predicate.into_syntax())), + Some(SyntaxElement::Token(r_paren_token)), + Some(SyntaxElement::Node(grit_boolean_literal.into_syntax())), + Some(SyntaxElement::Node(grit_predicate_return.into_syntax())), + Some(SyntaxElement::Node(grit_bogus_predicate.into_syntax())), + ], + )) +} +pub fn curly_grit_pattern( + l_curly_token: SyntaxToken, + any_grit_pattern: AnyGritPattern, + r_curly_token: SyntaxToken, +) -> CurlyGritPattern { + CurlyGritPattern::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::CURLY_GRIT_PATTERN, + [ + Some(SyntaxElement::Token(l_curly_token)), + Some(SyntaxElement::Node(any_grit_pattern.into_syntax())), + Some(SyntaxElement::Token(r_curly_token)), + ], + )) +} +pub fn grit_add_operation( + left: AnyGritPattern, + plus_token: SyntaxToken, + right: AnyGritPattern, +) -> GritAddOperation { + GritAddOperation::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_ADD_OPERATION, + [ + Some(SyntaxElement::Node(left.into_syntax())), + Some(SyntaxElement::Token(plus_token)), + Some(SyntaxElement::Node(right.into_syntax())), + ], + )) +} +pub fn grit_annotation(grit_annotation_token: SyntaxToken) -> GritAnnotation { + GritAnnotation::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_ANNOTATION, + [Some(SyntaxElement::Token(grit_annotation_token))], + )) +} +pub fn grit_assignment_as_pattern( + container: AnyGritContainer, + eq_token: SyntaxToken, + pattern: AnyGritPattern, +) -> GritAssignmentAsPattern { + GritAssignmentAsPattern::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_ASSIGNMENT_AS_PATTERN, + [ + Some(SyntaxElement::Node(container.into_syntax())), + Some(SyntaxElement::Token(eq_token)), + Some(SyntaxElement::Node(pattern.into_syntax())), + ], + )) +} +pub fn grit_backtick_snippet(value_token: SyntaxToken) -> GritBacktickSnippet { + GritBacktickSnippet::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_BACKTICK_SNIPPET, + [Some(SyntaxElement::Token(value_token))], + )) +} +pub fn grit_boolean_literal( + true_token: SyntaxToken, + false_token: SyntaxToken, +) -> GritBooleanLiteral { + GritBooleanLiteral::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_BOOLEAN_LITERAL, + [ + Some(SyntaxElement::Token(true_token)), + Some(SyntaxElement::Token(false_token)), + ], + )) +} +pub fn grit_bubble(bubble_token: SyntaxToken, pattern: MaybeCurlyGritPattern) -> GritBubbleBuilder { + GritBubbleBuilder { + bubble_token, + pattern, + variables: None, + } +} +pub struct GritBubbleBuilder { + bubble_token: SyntaxToken, + pattern: MaybeCurlyGritPattern, + variables: Option, +} +impl GritBubbleBuilder { + pub fn with_variables(mut self, variables: GritBubbleScope) -> Self { + self.variables = Some(variables); + self + } + pub fn build(self) -> GritBubble { + GritBubble::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_BUBBLE, + [ + Some(SyntaxElement::Token(self.bubble_token)), + self.variables + .map(|token| SyntaxElement::Node(token.into_syntax())), + Some(SyntaxElement::Node(self.pattern.into_syntax())), + ], + )) + } +} +pub fn grit_bubble_scope( + l_paren_token: SyntaxToken, + r_paren_token: SyntaxToken, +) -> GritBubbleScopeBuilder { + GritBubbleScopeBuilder { + l_paren_token, + r_paren_token, + grit_variable_list: None, + } +} +pub struct GritBubbleScopeBuilder { + l_paren_token: SyntaxToken, + r_paren_token: SyntaxToken, + grit_variable_list: Option, +} +impl GritBubbleScopeBuilder { + pub fn with_grit_variable_list(mut self, grit_variable_list: GritVariableList) -> Self { + self.grit_variable_list = Some(grit_variable_list); + self + } + pub fn build(self) -> GritBubbleScope { + GritBubbleScope::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_BUBBLE_SCOPE, + [ + Some(SyntaxElement::Token(self.l_paren_token)), + self.grit_variable_list + .map(|token| SyntaxElement::Node(token.into_syntax())), + Some(SyntaxElement::Token(self.r_paren_token)), + ], + )) + } +} +pub fn grit_code_snippet(source: GritCodeSnippetSource) -> GritCodeSnippet { + GritCodeSnippet::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_CODE_SNIPPET, + [Some(SyntaxElement::Node(source.into_syntax()))], + )) +} +pub fn grit_curly_predicate_list( + l_curly_token: SyntaxToken, + r_curly_token: SyntaxToken, +) -> GritCurlyPredicateListBuilder { + GritCurlyPredicateListBuilder { + l_curly_token, + r_curly_token, + predicates: None, + } +} +pub struct GritCurlyPredicateListBuilder { + l_curly_token: SyntaxToken, + r_curly_token: SyntaxToken, + predicates: Option, +} +impl GritCurlyPredicateListBuilder { + pub fn with_predicates(mut self, predicates: GritPredicateList) -> Self { + self.predicates = Some(predicates); + self + } + pub fn build(self) -> GritCurlyPredicateList { + GritCurlyPredicateList::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_CURLY_PREDICATE_LIST, + [ + Some(SyntaxElement::Token(self.l_curly_token)), + self.predicates + .map(|token| SyntaxElement::Node(token.into_syntax())), + Some(SyntaxElement::Token(self.r_curly_token)), + ], + )) + } +} +pub fn grit_div_operation( + left: AnyGritPattern, + slash_token: SyntaxToken, + right: AnyGritPattern, +) -> GritDivOperation { + GritDivOperation::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_DIV_OPERATION, + [ + Some(SyntaxElement::Node(left.into_syntax())), + Some(SyntaxElement::Token(slash_token)), + Some(SyntaxElement::Node(right.into_syntax())), + ], + )) +} +pub fn grit_dot(dot_token: SyntaxToken) -> GritDot { + GritDot::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_DOT, + [Some(SyntaxElement::Token(dot_token))], + )) +} +pub fn grit_dotdotdot(dollar_dotdotdot_token: SyntaxToken) -> GritDotdotdotBuilder { + GritDotdotdotBuilder { + dollar_dotdotdot_token, + maybe_curly_grit_pattern: None, + } +} +pub struct GritDotdotdotBuilder { + dollar_dotdotdot_token: SyntaxToken, + maybe_curly_grit_pattern: Option, +} +impl GritDotdotdotBuilder { + pub fn with_maybe_curly_grit_pattern( + mut self, + maybe_curly_grit_pattern: MaybeCurlyGritPattern, + ) -> Self { + self.maybe_curly_grit_pattern = Some(maybe_curly_grit_pattern); + self + } + pub fn build(self) -> GritDotdotdot { + GritDotdotdot::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_DOTDOTDOT, + [ + Some(SyntaxElement::Token(self.dollar_dotdotdot_token)), + self.maybe_curly_grit_pattern + .map(|token| SyntaxElement::Node(token.into_syntax())), + ], + )) + } +} +pub fn grit_double_literal(value_token: SyntaxToken) -> GritDoubleLiteral { + GritDoubleLiteral::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_DOUBLE_LITERAL, + [Some(SyntaxElement::Token(value_token))], + )) +} +pub fn grit_double_quote_snippet(value_token: SyntaxToken) -> GritDoubleQuoteSnippet { + GritDoubleQuoteSnippet::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_DOUBLE_QUOTE_SNIPPET, + [Some(SyntaxElement::Token(value_token))], + )) +} +pub fn grit_every(every_token: SyntaxToken, pattern: MaybeCurlyGritPattern) -> GritEvery { + GritEvery::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_EVERY, + [ + Some(SyntaxElement::Token(every_token)), + Some(SyntaxElement::Node(pattern.into_syntax())), + ], + )) +} +pub fn grit_files( + multifile_token: SyntaxToken, + l_curly_token: SyntaxToken, + files: GritFilesList, + r_curly_token: SyntaxToken, +) -> GritFiles { + GritFiles::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_FILES, + [ + Some(SyntaxElement::Token(multifile_token)), + Some(SyntaxElement::Token(l_curly_token)), + Some(SyntaxElement::Node(files.into_syntax())), + Some(SyntaxElement::Token(r_curly_token)), + ], + )) +} +pub fn grit_function_definition( + function_token: SyntaxToken, + name: GritName, + l_paren_token: SyntaxToken, + r_paren_token: SyntaxToken, + body: GritCurlyPredicateList, +) -> GritFunctionDefinitionBuilder { + GritFunctionDefinitionBuilder { + function_token, + name, + l_paren_token, + r_paren_token, + body, + args: None, + } +} +pub struct GritFunctionDefinitionBuilder { + function_token: SyntaxToken, + name: GritName, + l_paren_token: SyntaxToken, + r_paren_token: SyntaxToken, + body: GritCurlyPredicateList, + args: Option, +} +impl GritFunctionDefinitionBuilder { + pub fn with_args(mut self, args: GritVariableList) -> Self { + self.args = Some(args); + self + } + pub fn build(self) -> GritFunctionDefinition { + GritFunctionDefinition::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_FUNCTION_DEFINITION, + [ + Some(SyntaxElement::Token(self.function_token)), + Some(SyntaxElement::Node(self.name.into_syntax())), + Some(SyntaxElement::Token(self.l_paren_token)), + self.args + .map(|token| SyntaxElement::Node(token.into_syntax())), + Some(SyntaxElement::Token(self.r_paren_token)), + Some(SyntaxElement::Node(self.body.into_syntax())), + ], + )) + } +} +pub fn grit_int_literal(value_token: SyntaxToken) -> GritIntLiteral { + GritIntLiteral::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_INT_LITERAL, + [Some(SyntaxElement::Token(value_token))], + )) +} +pub fn grit_language_declaration( + language_token: SyntaxToken, + name: GritLanguageName, +) -> GritLanguageDeclarationBuilder { + GritLanguageDeclarationBuilder { + language_token, + name, + flavor: None, + } +} +pub struct GritLanguageDeclarationBuilder { + language_token: SyntaxToken, + name: GritLanguageName, + flavor: Option, +} +impl GritLanguageDeclarationBuilder { + pub fn with_flavor(mut self, flavor: GritLanguageFlavor) -> Self { + self.flavor = Some(flavor); + self + } + pub fn build(self) -> GritLanguageDeclaration { + GritLanguageDeclaration::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_LANGUAGE_DECLARATION, + [ + Some(SyntaxElement::Token(self.language_token)), + Some(SyntaxElement::Node(self.name.into_syntax())), + self.flavor + .map(|token| SyntaxElement::Node(token.into_syntax())), + ], + )) + } +} +pub fn grit_language_flavor( + l_paren_token: SyntaxToken, + grit_language_flavor_list: GritLanguageFlavorList, + r_paren_token: SyntaxToken, +) -> GritLanguageFlavorBuilder { + GritLanguageFlavorBuilder { + l_paren_token, + grit_language_flavor_list, + r_paren_token, + semicolon_token: None, + } +} +pub struct GritLanguageFlavorBuilder { + l_paren_token: SyntaxToken, + grit_language_flavor_list: GritLanguageFlavorList, + r_paren_token: SyntaxToken, + semicolon_token: Option, +} +impl GritLanguageFlavorBuilder { + pub fn with_semicolon_token(mut self, semicolon_token: SyntaxToken) -> Self { + self.semicolon_token = Some(semicolon_token); + self + } + pub fn build(self) -> GritLanguageFlavor { + GritLanguageFlavor::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_LANGUAGE_FLAVOR, + [ + Some(SyntaxElement::Token(self.l_paren_token)), + Some(SyntaxElement::Node( + self.grit_language_flavor_list.into_syntax(), + )), + Some(SyntaxElement::Token(self.r_paren_token)), + self.semicolon_token + .map(|token| SyntaxElement::Token(token)), + ], + )) + } +} +pub fn grit_language_flavor_kind(flavor_kind_token: SyntaxToken) -> GritLanguageFlavorKind { + GritLanguageFlavorKind::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_LANGUAGE_FLAVOR_KIND, + [Some(SyntaxElement::Token(flavor_kind_token))], + )) +} +pub fn grit_language_name( + js_token: SyntaxToken, + css_token: SyntaxToken, + json_token: SyntaxToken, + grit_token: SyntaxToken, + html_token: SyntaxToken, +) -> GritLanguageName { + GritLanguageName::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_LANGUAGE_NAME, + [ + Some(SyntaxElement::Token(js_token)), + Some(SyntaxElement::Token(css_token)), + Some(SyntaxElement::Token(json_token)), + Some(SyntaxElement::Token(grit_token)), + Some(SyntaxElement::Token(html_token)), + ], + )) +} +pub fn grit_language_specific_snippet( + language: GritLanguageName, + snippet: GritDoubleQuoteSnippet, +) -> GritLanguageSpecificSnippet { + GritLanguageSpecificSnippet::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_LANGUAGE_SPECIFIC_SNIPPET, + [ + Some(SyntaxElement::Node(language.into_syntax())), + Some(SyntaxElement::Node(snippet.into_syntax())), + ], + )) +} +pub fn grit_like( + like_token: SyntaxToken, + l_curly_token: SyntaxToken, + example: AnyGritPattern, + r_curly_token: SyntaxToken, +) -> GritLikeBuilder { + GritLikeBuilder { + like_token, + l_curly_token, + example, + r_curly_token, + grit_like_threshold: None, + } +} +pub struct GritLikeBuilder { + like_token: SyntaxToken, + l_curly_token: SyntaxToken, + example: AnyGritPattern, + r_curly_token: SyntaxToken, + grit_like_threshold: Option, +} +impl GritLikeBuilder { + pub fn with_grit_like_threshold(mut self, grit_like_threshold: GritLikeThreshold) -> Self { + self.grit_like_threshold = Some(grit_like_threshold); + self + } + pub fn build(self) -> GritLike { + GritLike::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_LIKE, + [ + Some(SyntaxElement::Token(self.like_token)), + self.grit_like_threshold + .map(|token| SyntaxElement::Node(token.into_syntax())), + Some(SyntaxElement::Token(self.l_curly_token)), + Some(SyntaxElement::Node(self.example.into_syntax())), + Some(SyntaxElement::Token(self.r_curly_token)), + ], + )) + } +} +pub fn grit_like_threshold( + l_paren_token: SyntaxToken, + threshold: AnyGritPattern, + r_paren_token: SyntaxToken, +) -> GritLikeThreshold { + GritLikeThreshold::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_LIKE_THRESHOLD, + [ + Some(SyntaxElement::Token(l_paren_token)), + Some(SyntaxElement::Node(threshold.into_syntax())), + Some(SyntaxElement::Token(r_paren_token)), + ], + )) +} +pub fn grit_list(l_brack_token: SyntaxToken, r_brack_token: SyntaxToken) -> GritListBuilder { + GritListBuilder { + l_brack_token, + r_brack_token, + grit_name: None, + patterns: None, + } +} +pub struct GritListBuilder { + l_brack_token: SyntaxToken, + r_brack_token: SyntaxToken, + grit_name: Option, + patterns: Option, +} +impl GritListBuilder { + pub fn with_grit_name(mut self, grit_name: GritName) -> Self { + self.grit_name = Some(grit_name); + self + } + pub fn with_patterns(mut self, patterns: GritListPatternList) -> Self { + self.patterns = Some(patterns); + self + } + pub fn build(self) -> GritList { + GritList::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_LIST, + [ + self.grit_name + .map(|token| SyntaxElement::Node(token.into_syntax())), + Some(SyntaxElement::Token(self.l_brack_token)), + self.patterns + .map(|token| SyntaxElement::Node(token.into_syntax())), + Some(SyntaxElement::Token(self.r_brack_token)), + ], + )) + } +} +pub fn grit_list_accessor( + list: GritListAccessorSubject, + l_brack_token: SyntaxToken, + index: GritListIndex, + r_brack_token: SyntaxToken, +) -> GritListAccessor { + GritListAccessor::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_LIST_ACCESSOR, + [ + Some(SyntaxElement::Node(list.into_syntax())), + Some(SyntaxElement::Token(l_brack_token)), + Some(SyntaxElement::Node(index.into_syntax())), + Some(SyntaxElement::Token(r_brack_token)), + ], + )) +} +pub fn grit_map(l_curly_token: SyntaxToken, r_curly_token: SyntaxToken) -> GritMapBuilder { + GritMapBuilder { + l_curly_token, + r_curly_token, + elements: None, + } +} +pub struct GritMapBuilder { + l_curly_token: SyntaxToken, + r_curly_token: SyntaxToken, + elements: Option, +} +impl GritMapBuilder { + pub fn with_elements(mut self, elements: GritMapElementList) -> Self { + self.elements = Some(elements); + self + } + pub fn build(self) -> GritMap { + GritMap::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_MAP, + [ + Some(SyntaxElement::Token(self.l_curly_token)), + self.elements + .map(|token| SyntaxElement::Node(token.into_syntax())), + Some(SyntaxElement::Token(self.r_curly_token)), + ], + )) + } +} +pub fn grit_map_accessor( + map: GritMapAccessorSubject, + dot_token: SyntaxToken, + key: GritMapKey, +) -> GritMapAccessor { + GritMapAccessor::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_MAP_ACCESSOR, + [ + Some(SyntaxElement::Node(map.into_syntax())), + Some(SyntaxElement::Token(dot_token)), + Some(SyntaxElement::Node(key.into_syntax())), + ], + )) +} +pub fn grit_map_element( + key: GritName, + colon_token: SyntaxToken, + value: AnyGritPattern, +) -> GritMapElement { + GritMapElement::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_MAP_ELEMENT, + [ + Some(SyntaxElement::Node(key.into_syntax())), + Some(SyntaxElement::Token(colon_token)), + Some(SyntaxElement::Node(value.into_syntax())), + ], + )) +} +pub fn grit_mod_operation( + left: AnyGritPattern, + remainder_token: SyntaxToken, + right: AnyGritPattern, +) -> GritModOperation { + GritModOperation::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_MOD_OPERATION, + [ + Some(SyntaxElement::Node(left.into_syntax())), + Some(SyntaxElement::Token(remainder_token)), + Some(SyntaxElement::Node(right.into_syntax())), + ], + )) +} +pub fn grit_mul_operation( + left: AnyGritPattern, + star_token: SyntaxToken, + right: AnyGritPattern, +) -> GritMulOperation { + GritMulOperation::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_MUL_OPERATION, + [ + Some(SyntaxElement::Node(left.into_syntax())), + Some(SyntaxElement::Token(star_token)), + Some(SyntaxElement::Node(right.into_syntax())), + ], + )) +} +pub fn grit_name(grit_name_token: SyntaxToken) -> GritName { + GritName::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_NAME, + [Some(SyntaxElement::Token(grit_name_token))], + )) +} +pub fn grit_named_arg(name: GritName) -> GritNamedArg { + GritNamedArg::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_NAMED_ARG, + [Some(SyntaxElement::Node(name.into_syntax()))], + )) +} +pub fn grit_named_arg_with_default( + name: GritName, + eq_token: SyntaxToken, + pattern: AnyGritPattern, +) -> GritNamedArgWithDefault { + GritNamedArgWithDefault::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_NAMED_ARG_WITH_DEFAULT, + [ + Some(SyntaxElement::Node(name.into_syntax())), + Some(SyntaxElement::Token(eq_token)), + Some(SyntaxElement::Node(pattern.into_syntax())), + ], + )) +} +pub fn grit_node_like( + name: GritName, + l_paren_token: SyntaxToken, + r_paren_token: SyntaxToken, +) -> GritNodeLikeBuilder { + GritNodeLikeBuilder { + name, + l_paren_token, + r_paren_token, + named_args: None, + } +} +pub struct GritNodeLikeBuilder { + name: GritName, + l_paren_token: SyntaxToken, + r_paren_token: SyntaxToken, + named_args: Option, +} +impl GritNodeLikeBuilder { + pub fn with_named_args(mut self, named_args: GritNamedArgList) -> Self { + self.named_args = Some(named_args); + self + } + pub fn build(self) -> GritNodeLike { + GritNodeLike::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_NODE_LIKE, + [ + Some(SyntaxElement::Node(self.name.into_syntax())), + Some(SyntaxElement::Token(self.l_paren_token)), + self.named_args + .map(|token| SyntaxElement::Node(token.into_syntax())), + Some(SyntaxElement::Token(self.r_paren_token)), + ], + )) + } +} +pub fn grit_not(not_token: SyntaxToken, excl_token: SyntaxToken) -> GritNot { + GritNot::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_NOT, + [ + Some(SyntaxElement::Token(not_token)), + Some(SyntaxElement::Token(excl_token)), + ], + )) +} +pub fn grit_pattern_accumulate( + left: AnyGritPattern, + add_assign_token: SyntaxToken, + right: AnyGritPattern, +) -> GritPatternAccumulate { + GritPatternAccumulate::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PATTERN_ACCUMULATE, + [ + Some(SyntaxElement::Node(left.into_syntax())), + Some(SyntaxElement::Token(add_assign_token)), + Some(SyntaxElement::Node(right.into_syntax())), + ], + )) +} +pub fn grit_pattern_after(after_token: SyntaxToken, pattern: AnyGritPattern) -> GritPatternAfter { + GritPatternAfter::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PATTERN_AFTER, + [ + Some(SyntaxElement::Token(after_token)), + Some(SyntaxElement::Node(pattern.into_syntax())), + ], + )) +} +pub fn grit_pattern_and( + and_token: SyntaxToken, + l_curly_token: SyntaxToken, + r_curly_token: SyntaxToken, +) -> GritPatternAndBuilder { + GritPatternAndBuilder { + and_token, + l_curly_token, + r_curly_token, + patterns: None, + } +} +pub struct GritPatternAndBuilder { + and_token: SyntaxToken, + l_curly_token: SyntaxToken, + r_curly_token: SyntaxToken, + patterns: Option, +} +impl GritPatternAndBuilder { + pub fn with_patterns(mut self, patterns: GritPatternList) -> Self { + self.patterns = Some(patterns); + self + } + pub fn build(self) -> GritPatternAnd { + GritPatternAnd::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PATTERN_AND, + [ + Some(SyntaxElement::Token(self.and_token)), + Some(SyntaxElement::Token(self.l_curly_token)), + self.patterns + .map(|token| SyntaxElement::Node(token.into_syntax())), + Some(SyntaxElement::Token(self.r_curly_token)), + ], + )) + } +} +pub fn grit_pattern_any( + any_token: SyntaxToken, + l_curly_token: SyntaxToken, + r_curly_token: SyntaxToken, +) -> GritPatternAnyBuilder { + GritPatternAnyBuilder { + any_token, + l_curly_token, + r_curly_token, + patterns: None, + } +} +pub struct GritPatternAnyBuilder { + any_token: SyntaxToken, + l_curly_token: SyntaxToken, + r_curly_token: SyntaxToken, + patterns: Option, +} +impl GritPatternAnyBuilder { + pub fn with_patterns(mut self, patterns: GritPatternList) -> Self { + self.patterns = Some(patterns); + self + } + pub fn build(self) -> GritPatternAny { + GritPatternAny::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PATTERN_ANY, + [ + Some(SyntaxElement::Token(self.any_token)), + Some(SyntaxElement::Token(self.l_curly_token)), + self.patterns + .map(|token| SyntaxElement::Node(token.into_syntax())), + Some(SyntaxElement::Token(self.r_curly_token)), + ], + )) + } +} +pub fn grit_pattern_arg_list(grit_variable_list: GritVariableList) -> GritPatternArgList { + GritPatternArgList::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PATTERN_ARG_LIST, + [Some(SyntaxElement::Node(grit_variable_list.into_syntax()))], + )) +} +pub fn grit_pattern_as( + pattern: AnyGritPattern, + as_token: SyntaxToken, + variable: GritVariable, +) -> GritPatternAs { + GritPatternAs::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PATTERN_AS, + [ + Some(SyntaxElement::Node(pattern.into_syntax())), + Some(SyntaxElement::Token(as_token)), + Some(SyntaxElement::Node(variable.into_syntax())), + ], + )) +} +pub fn grit_pattern_before( + before_token: SyntaxToken, + pattern: AnyGritPattern, +) -> GritPatternBefore { + GritPatternBefore::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PATTERN_BEFORE, + [ + Some(SyntaxElement::Token(before_token)), + Some(SyntaxElement::Node(pattern.into_syntax())), + ], + )) +} +pub fn grit_pattern_contains( + contains_token: SyntaxToken, + contains: MaybeCurlyGritPattern, +) -> GritPatternContainsBuilder { + GritPatternContainsBuilder { + contains_token, + contains, + grit_pattern_contains_until_clause: None, + } +} +pub struct GritPatternContainsBuilder { + contains_token: SyntaxToken, + contains: MaybeCurlyGritPattern, + grit_pattern_contains_until_clause: Option, +} +impl GritPatternContainsBuilder { + pub fn with_grit_pattern_contains_until_clause( + mut self, + grit_pattern_contains_until_clause: GritPatternContainsUntilClause, + ) -> Self { + self.grit_pattern_contains_until_clause = Some(grit_pattern_contains_until_clause); + self + } + pub fn build(self) -> GritPatternContains { + GritPatternContains::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PATTERN_CONTAINS, + [ + Some(SyntaxElement::Token(self.contains_token)), + Some(SyntaxElement::Node(self.contains.into_syntax())), + self.grit_pattern_contains_until_clause + .map(|token| SyntaxElement::Node(token.into_syntax())), + ], + )) + } +} +pub fn grit_pattern_contains_until_clause( + until_token: SyntaxToken, + until: AnyGritPattern, +) -> GritPatternContainsUntilClause { + GritPatternContainsUntilClause::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PATTERN_CONTAINS_UNTIL_CLAUSE, + [ + Some(SyntaxElement::Token(until_token)), + Some(SyntaxElement::Node(until.into_syntax())), + ], + )) +} +pub fn grit_pattern_definition( + pattern_token: SyntaxToken, + name: GritName, + l_paren_token: SyntaxToken, + r_paren_token: SyntaxToken, + body: GritPatternDefinitionBody, +) -> GritPatternDefinitionBuilder { + GritPatternDefinitionBuilder { + pattern_token, + name, + l_paren_token, + r_paren_token, + body, + visibility_token: None, + args: None, + language: None, + } +} +pub struct GritPatternDefinitionBuilder { + pattern_token: SyntaxToken, + name: GritName, + l_paren_token: SyntaxToken, + r_paren_token: SyntaxToken, + body: GritPatternDefinitionBody, + visibility_token: Option, + args: Option, + language: Option, +} +impl GritPatternDefinitionBuilder { + pub fn with_visibility_token(mut self, visibility_token: SyntaxToken) -> Self { + self.visibility_token = Some(visibility_token); + self + } + pub fn with_args(mut self, args: GritPatternArgList) -> Self { + self.args = Some(args); + self + } + pub fn with_language(mut self, language: GritLanguageDeclaration) -> Self { + self.language = Some(language); + self + } + pub fn build(self) -> GritPatternDefinition { + GritPatternDefinition::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PATTERN_DEFINITION, + [ + self.visibility_token + .map(|token| SyntaxElement::Token(token)), + Some(SyntaxElement::Token(self.pattern_token)), + Some(SyntaxElement::Node(self.name.into_syntax())), + Some(SyntaxElement::Token(self.l_paren_token)), + self.args + .map(|token| SyntaxElement::Node(token.into_syntax())), + Some(SyntaxElement::Token(self.r_paren_token)), + self.language + .map(|token| SyntaxElement::Node(token.into_syntax())), + Some(SyntaxElement::Node(self.body.into_syntax())), + ], + )) + } +} +pub fn grit_pattern_definition_body( + l_curly_token: SyntaxToken, + r_curly_token: SyntaxToken, +) -> GritPatternDefinitionBodyBuilder { + GritPatternDefinitionBodyBuilder { + l_curly_token, + r_curly_token, + patterns: None, + } +} +pub struct GritPatternDefinitionBodyBuilder { + l_curly_token: SyntaxToken, + r_curly_token: SyntaxToken, + patterns: Option, +} +impl GritPatternDefinitionBodyBuilder { + pub fn with_patterns(mut self, patterns: GritPatternList) -> Self { + self.patterns = Some(patterns); + self + } + pub fn build(self) -> GritPatternDefinitionBody { + GritPatternDefinitionBody::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PATTERN_DEFINITION_BODY, + [ + Some(SyntaxElement::Token(self.l_curly_token)), + self.patterns + .map(|token| SyntaxElement::Node(token.into_syntax())), + Some(SyntaxElement::Token(self.r_curly_token)), + ], + )) + } +} +pub fn grit_pattern_else_clause( + else_token: SyntaxToken, + else_pattern: MaybeCurlyGritPattern, +) -> GritPatternElseClause { + GritPatternElseClause::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PATTERN_ELSE_CLAUSE, + [ + Some(SyntaxElement::Token(else_token)), + Some(SyntaxElement::Node(else_pattern.into_syntax())), + ], + )) +} +pub fn grit_pattern_if_else( + if_token: SyntaxToken, + l_paren_token: SyntaxToken, + if_predicate: AnyGritPredicate, + r_paren_token: SyntaxToken, + then_pattern: MaybeCurlyGritPattern, +) -> GritPatternIfElseBuilder { + GritPatternIfElseBuilder { + if_token, + l_paren_token, + if_predicate, + r_paren_token, + then_pattern, + grit_pattern_else_clause: None, + } +} +pub struct GritPatternIfElseBuilder { + if_token: SyntaxToken, + l_paren_token: SyntaxToken, + if_predicate: AnyGritPredicate, + r_paren_token: SyntaxToken, + then_pattern: MaybeCurlyGritPattern, + grit_pattern_else_clause: Option, +} +impl GritPatternIfElseBuilder { + pub fn with_grit_pattern_else_clause( + mut self, + grit_pattern_else_clause: GritPatternElseClause, + ) -> Self { + self.grit_pattern_else_clause = Some(grit_pattern_else_clause); + self + } + pub fn build(self) -> GritPatternIfElse { + GritPatternIfElse::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PATTERN_IF_ELSE, + [ + Some(SyntaxElement::Token(self.if_token)), + Some(SyntaxElement::Token(self.l_paren_token)), + Some(SyntaxElement::Node(self.if_predicate.into_syntax())), + Some(SyntaxElement::Token(self.r_paren_token)), + Some(SyntaxElement::Node(self.then_pattern.into_syntax())), + self.grit_pattern_else_clause + .map(|token| SyntaxElement::Node(token.into_syntax())), + ], + )) + } +} +pub fn grit_pattern_includes( + includes_token: SyntaxToken, + includes: MaybeCurlyGritPattern, +) -> GritPatternIncludes { + GritPatternIncludes::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PATTERN_INCLUDES, + [ + Some(SyntaxElement::Token(includes_token)), + Some(SyntaxElement::Node(includes.into_syntax())), + ], + )) +} +pub fn grit_pattern_limit( + pattern: AnyGritPattern, + limit_token: SyntaxToken, + limit: GritIntLiteral, +) -> GritPatternLimit { + GritPatternLimit::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PATTERN_LIMIT, + [ + Some(SyntaxElement::Node(pattern.into_syntax())), + Some(SyntaxElement::Token(limit_token)), + Some(SyntaxElement::Node(limit.into_syntax())), + ], + )) +} +pub fn grit_pattern_maybe( + maybe_token: SyntaxToken, + pattern: MaybeCurlyGritPattern, +) -> GritPatternMaybe { + GritPatternMaybe::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PATTERN_MAYBE, + [ + Some(SyntaxElement::Token(maybe_token)), + Some(SyntaxElement::Node(pattern.into_syntax())), + ], + )) +} +pub fn grit_pattern_not(grit_not: GritNot, pattern: AnyGritPattern) -> GritPatternNot { + GritPatternNot::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PATTERN_NOT, + [ + Some(SyntaxElement::Node(grit_not.into_syntax())), + Some(SyntaxElement::Node(pattern.into_syntax())), + ], + )) +} +pub fn grit_pattern_or( + or_token: SyntaxToken, + l_curly_token: SyntaxToken, + patterns: GritPatternList, + r_curly_token: SyntaxToken, +) -> GritPatternOr { + GritPatternOr::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PATTERN_OR, + [ + Some(SyntaxElement::Token(or_token)), + Some(SyntaxElement::Token(l_curly_token)), + Some(SyntaxElement::Node(patterns.into_syntax())), + Some(SyntaxElement::Token(r_curly_token)), + ], + )) +} +pub fn grit_pattern_or_else( + orelse_token: SyntaxToken, + l_curly_token: SyntaxToken, + r_curly_token: SyntaxToken, +) -> GritPatternOrElseBuilder { + GritPatternOrElseBuilder { + orelse_token, + l_curly_token, + r_curly_token, + patterns: None, + } +} +pub struct GritPatternOrElseBuilder { + orelse_token: SyntaxToken, + l_curly_token: SyntaxToken, + r_curly_token: SyntaxToken, + patterns: Option, +} +impl GritPatternOrElseBuilder { + pub fn with_patterns(mut self, patterns: GritPatternList) -> Self { + self.patterns = Some(patterns); + self + } + pub fn build(self) -> GritPatternOrElse { + GritPatternOrElse::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PATTERN_OR_ELSE, + [ + Some(SyntaxElement::Token(self.orelse_token)), + Some(SyntaxElement::Token(self.l_curly_token)), + self.patterns + .map(|token| SyntaxElement::Node(token.into_syntax())), + Some(SyntaxElement::Token(self.r_curly_token)), + ], + )) + } +} +pub fn grit_pattern_where( + pattern: AnyGritPattern, + where_token: SyntaxToken, + side_condition: AnyGritPredicate, +) -> GritPatternWhere { + GritPatternWhere::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PATTERN_WHERE, + [ + Some(SyntaxElement::Node(pattern.into_syntax())), + Some(SyntaxElement::Token(where_token)), + Some(SyntaxElement::Node(side_condition.into_syntax())), + ], + )) +} +pub fn grit_predicate_accumulate( + left: GritVariable, + add_assign_token: SyntaxToken, + right: AnyGritPattern, +) -> GritPredicateAccumulate { + GritPredicateAccumulate::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PREDICATE_ACCUMULATE, + [ + Some(SyntaxElement::Node(left.into_syntax())), + Some(SyntaxElement::Token(add_assign_token)), + Some(SyntaxElement::Node(right.into_syntax())), + ], + )) +} +pub fn grit_predicate_and( + l_curly_token: SyntaxToken, + r_curly_token: SyntaxToken, +) -> GritPredicateAndBuilder { + GritPredicateAndBuilder { + l_curly_token, + r_curly_token, + and_token: None, + predicates: None, + } +} +pub struct GritPredicateAndBuilder { + l_curly_token: SyntaxToken, + r_curly_token: SyntaxToken, + and_token: Option, + predicates: Option, +} +impl GritPredicateAndBuilder { + pub fn with_and_token(mut self, and_token: SyntaxToken) -> Self { + self.and_token = Some(and_token); + self + } + pub fn with_predicates(mut self, predicates: GritPredicateList) -> Self { + self.predicates = Some(predicates); + self + } + pub fn build(self) -> GritPredicateAnd { + GritPredicateAnd::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PREDICATE_AND, + [ + self.and_token.map(|token| SyntaxElement::Token(token)), + Some(SyntaxElement::Token(self.l_curly_token)), + self.predicates + .map(|token| SyntaxElement::Node(token.into_syntax())), + Some(SyntaxElement::Token(self.r_curly_token)), + ], + )) + } +} +pub fn grit_predicate_any( + any_token: SyntaxToken, + l_curly_token: SyntaxToken, + r_curly_token: SyntaxToken, +) -> GritPredicateAnyBuilder { + GritPredicateAnyBuilder { + any_token, + l_curly_token, + r_curly_token, + predicates: None, + } +} +pub struct GritPredicateAnyBuilder { + any_token: SyntaxToken, + l_curly_token: SyntaxToken, + r_curly_token: SyntaxToken, + predicates: Option, +} +impl GritPredicateAnyBuilder { + pub fn with_predicates(mut self, predicates: GritPredicateList) -> Self { + self.predicates = Some(predicates); + self + } + pub fn build(self) -> GritPredicateAny { + GritPredicateAny::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PREDICATE_ANY, + [ + Some(SyntaxElement::Token(self.any_token)), + Some(SyntaxElement::Token(self.l_curly_token)), + self.predicates + .map(|token| SyntaxElement::Node(token.into_syntax())), + Some(SyntaxElement::Token(self.r_curly_token)), + ], + )) + } +} +pub fn grit_predicate_assignment( + container: AnyGritContainer, + eq_token: SyntaxToken, + pattern: AnyGritPattern, +) -> GritPredicateAssignment { + GritPredicateAssignment::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PREDICATE_ASSIGNMENT, + [ + Some(SyntaxElement::Node(container.into_syntax())), + Some(SyntaxElement::Token(eq_token)), + Some(SyntaxElement::Node(pattern.into_syntax())), + ], + )) +} +pub fn grit_predicate_call( + name: GritName, + l_paren_token: SyntaxToken, + r_paren_token: SyntaxToken, +) -> GritPredicateCallBuilder { + GritPredicateCallBuilder { + name, + l_paren_token, + r_paren_token, + named_args: None, + } +} +pub struct GritPredicateCallBuilder { + name: GritName, + l_paren_token: SyntaxToken, + r_paren_token: SyntaxToken, + named_args: Option, +} +impl GritPredicateCallBuilder { + pub fn with_named_args(mut self, named_args: GritNamedArgList) -> Self { + self.named_args = Some(named_args); + self + } + pub fn build(self) -> GritPredicateCall { + GritPredicateCall::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PREDICATE_CALL, + [ + Some(SyntaxElement::Node(self.name.into_syntax())), + Some(SyntaxElement::Token(self.l_paren_token)), + self.named_args + .map(|token| SyntaxElement::Node(token.into_syntax())), + Some(SyntaxElement::Token(self.r_paren_token)), + ], + )) + } +} +pub fn grit_predicate_definition( + predicate_token: SyntaxToken, + name: GritName, + l_paren_token: SyntaxToken, + r_paren_token: SyntaxToken, + body: GritCurlyPredicateList, +) -> GritPredicateDefinitionBuilder { + GritPredicateDefinitionBuilder { + predicate_token, + name, + l_paren_token, + r_paren_token, + body, + args: None, + } +} +pub struct GritPredicateDefinitionBuilder { + predicate_token: SyntaxToken, + name: GritName, + l_paren_token: SyntaxToken, + r_paren_token: SyntaxToken, + body: GritCurlyPredicateList, + args: Option, +} +impl GritPredicateDefinitionBuilder { + pub fn with_args(mut self, args: GritPatternArgList) -> Self { + self.args = Some(args); + self + } + pub fn build(self) -> GritPredicateDefinition { + GritPredicateDefinition::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PREDICATE_DEFINITION, + [ + Some(SyntaxElement::Token(self.predicate_token)), + Some(SyntaxElement::Node(self.name.into_syntax())), + Some(SyntaxElement::Token(self.l_paren_token)), + self.args + .map(|token| SyntaxElement::Node(token.into_syntax())), + Some(SyntaxElement::Token(self.r_paren_token)), + Some(SyntaxElement::Node(self.body.into_syntax())), + ], + )) + } +} +pub fn grit_predicate_else_clause( + else_token: SyntaxToken, + else_predicate: AnyGritPredicate, +) -> GritPredicateElseClause { + GritPredicateElseClause::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PREDICATE_ELSE_CLAUSE, + [ + Some(SyntaxElement::Token(else_token)), + Some(SyntaxElement::Node(else_predicate.into_syntax())), + ], + )) +} +pub fn grit_predicate_equal( + left: GritVariable, + equality_token: SyntaxToken, + right: AnyGritPattern, +) -> GritPredicateEqual { + GritPredicateEqual::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PREDICATE_EQUAL, + [ + Some(SyntaxElement::Node(left.into_syntax())), + Some(SyntaxElement::Token(equality_token)), + Some(SyntaxElement::Node(right.into_syntax())), + ], + )) +} +pub fn grit_predicate_greater( + left: GritVariable, + r_angle_token: SyntaxToken, + right: AnyGritPattern, +) -> GritPredicateGreater { + GritPredicateGreater::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PREDICATE_GREATER, + [ + Some(SyntaxElement::Node(left.into_syntax())), + Some(SyntaxElement::Token(r_angle_token)), + Some(SyntaxElement::Node(right.into_syntax())), + ], + )) +} +pub fn grit_predicate_greater_equal( + left: GritVariable, + greater_than_equal_token: SyntaxToken, + right: AnyGritPattern, +) -> GritPredicateGreaterEqual { + GritPredicateGreaterEqual::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PREDICATE_GREATER_EQUAL, + [ + Some(SyntaxElement::Node(left.into_syntax())), + Some(SyntaxElement::Token(greater_than_equal_token)), + Some(SyntaxElement::Node(right.into_syntax())), + ], + )) +} +pub fn grit_predicate_if_else( + if_token: SyntaxToken, + l_paren_token: SyntaxToken, + if_predicate: AnyGritPredicate, + r_paren_token: SyntaxToken, + then_predicate: AnyGritPredicate, +) -> GritPredicateIfElseBuilder { + GritPredicateIfElseBuilder { + if_token, + l_paren_token, + if_predicate, + r_paren_token, + then_predicate, + grit_predicate_else_clause: None, + } +} +pub struct GritPredicateIfElseBuilder { + if_token: SyntaxToken, + l_paren_token: SyntaxToken, + if_predicate: AnyGritPredicate, + r_paren_token: SyntaxToken, + then_predicate: AnyGritPredicate, + grit_predicate_else_clause: Option, +} +impl GritPredicateIfElseBuilder { + pub fn with_grit_predicate_else_clause( + mut self, + grit_predicate_else_clause: GritPredicateElseClause, + ) -> Self { + self.grit_predicate_else_clause = Some(grit_predicate_else_clause); + self + } + pub fn build(self) -> GritPredicateIfElse { + GritPredicateIfElse::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PREDICATE_IF_ELSE, + [ + Some(SyntaxElement::Token(self.if_token)), + Some(SyntaxElement::Token(self.l_paren_token)), + Some(SyntaxElement::Node(self.if_predicate.into_syntax())), + Some(SyntaxElement::Token(self.r_paren_token)), + Some(SyntaxElement::Node(self.then_predicate.into_syntax())), + self.grit_predicate_else_clause + .map(|token| SyntaxElement::Node(token.into_syntax())), + ], + )) + } +} +pub fn grit_predicate_less( + left: GritVariable, + l_angle_token: SyntaxToken, + right: AnyGritPattern, +) -> GritPredicateLess { + GritPredicateLess::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PREDICATE_LESS, + [ + Some(SyntaxElement::Node(left.into_syntax())), + Some(SyntaxElement::Token(l_angle_token)), + Some(SyntaxElement::Node(right.into_syntax())), + ], + )) +} +pub fn grit_predicate_less_equal( + left: GritVariable, + less_than_equal_token: SyntaxToken, + right: AnyGritPattern, +) -> GritPredicateLessEqual { + GritPredicateLessEqual::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PREDICATE_LESS_EQUAL, + [ + Some(SyntaxElement::Node(left.into_syntax())), + Some(SyntaxElement::Token(less_than_equal_token)), + Some(SyntaxElement::Node(right.into_syntax())), + ], + )) +} +pub fn grit_predicate_match( + left: GritPredicateMatchSubject, + match_token: SyntaxToken, + right: AnyGritPattern, +) -> GritPredicateMatch { + GritPredicateMatch::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PREDICATE_MATCH, + [ + Some(SyntaxElement::Node(left.into_syntax())), + Some(SyntaxElement::Token(match_token)), + Some(SyntaxElement::Node(right.into_syntax())), + ], + )) +} +pub fn grit_predicate_maybe( + maybe_token: SyntaxToken, + predicate: AnyGritPredicate, +) -> GritPredicateMaybe { + GritPredicateMaybe::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PREDICATE_MAYBE, + [ + Some(SyntaxElement::Token(maybe_token)), + Some(SyntaxElement::Node(predicate.into_syntax())), + ], + )) +} +pub fn grit_predicate_not(grit_not: GritNot, predicate: AnyGritPredicate) -> GritPredicateNot { + GritPredicateNot::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PREDICATE_NOT, + [ + Some(SyntaxElement::Node(grit_not.into_syntax())), + Some(SyntaxElement::Node(predicate.into_syntax())), + ], + )) +} +pub fn grit_predicate_not_equal( + left: GritVariable, + inequality_token: SyntaxToken, + right: AnyGritPattern, +) -> GritPredicateNotEqual { + GritPredicateNotEqual::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PREDICATE_NOT_EQUAL, + [ + Some(SyntaxElement::Node(left.into_syntax())), + Some(SyntaxElement::Token(inequality_token)), + Some(SyntaxElement::Node(right.into_syntax())), + ], + )) +} +pub fn grit_predicate_or( + or_token: SyntaxToken, + l_curly_token: SyntaxToken, + r_curly_token: SyntaxToken, +) -> GritPredicateOrBuilder { + GritPredicateOrBuilder { + or_token, + l_curly_token, + r_curly_token, + predicates: None, + } +} +pub struct GritPredicateOrBuilder { + or_token: SyntaxToken, + l_curly_token: SyntaxToken, + r_curly_token: SyntaxToken, + predicates: Option, +} +impl GritPredicateOrBuilder { + pub fn with_predicates(mut self, predicates: GritPredicateList) -> Self { + self.predicates = Some(predicates); + self + } + pub fn build(self) -> GritPredicateOr { + GritPredicateOr::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PREDICATE_OR, + [ + Some(SyntaxElement::Token(self.or_token)), + Some(SyntaxElement::Token(self.l_curly_token)), + self.predicates + .map(|token| SyntaxElement::Node(token.into_syntax())), + Some(SyntaxElement::Token(self.r_curly_token)), + ], + )) + } +} +pub fn grit_predicate_return( + return_token: SyntaxToken, + pattern: AnyGritPattern, +) -> GritPredicateReturn { + GritPredicateReturn::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PREDICATE_RETURN, + [ + Some(SyntaxElement::Token(return_token)), + Some(SyntaxElement::Node(pattern.into_syntax())), + ], + )) +} +pub fn grit_predicate_rewrite( + left: GritVariable, + fat_arrow_token: SyntaxToken, + right: AnyGritPattern, +) -> GritPredicateRewriteBuilder { + GritPredicateRewriteBuilder { + left, + fat_arrow_token, + right, + annotation: None, + } +} +pub struct GritPredicateRewriteBuilder { + left: GritVariable, + fat_arrow_token: SyntaxToken, + right: AnyGritPattern, + annotation: Option, +} +impl GritPredicateRewriteBuilder { + pub fn with_annotation(mut self, annotation: GritAnnotation) -> Self { + self.annotation = Some(annotation); + self + } + pub fn build(self) -> GritPredicateRewrite { + GritPredicateRewrite::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PREDICATE_REWRITE, + [ + Some(SyntaxElement::Node(self.left.into_syntax())), + self.annotation + .map(|token| SyntaxElement::Node(token.into_syntax())), + Some(SyntaxElement::Token(self.fat_arrow_token)), + Some(SyntaxElement::Node(self.right.into_syntax())), + ], + )) + } +} +pub fn grit_raw_backtick_snippet(value_token: SyntaxToken) -> GritRawBacktickSnippet { + GritRawBacktickSnippet::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_RAW_BACKTICK_SNIPPET, + [Some(SyntaxElement::Token(value_token))], + )) +} +pub fn grit_regex_literal(value_token: SyntaxToken) -> GritRegexLiteral { + GritRegexLiteral::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_REGEX_LITERAL, + [Some(SyntaxElement::Token(value_token))], + )) +} +pub fn grit_regex_pattern(regex: GritRegex) -> GritRegexPatternBuilder { + GritRegexPatternBuilder { + regex, + variables: None, + } +} +pub struct GritRegexPatternBuilder { + regex: GritRegex, + variables: Option, +} +impl GritRegexPatternBuilder { + pub fn with_variables(mut self, variables: GritRegexPatternVariables) -> Self { + self.variables = Some(variables); + self + } + pub fn build(self) -> GritRegexPattern { + GritRegexPattern::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_REGEX_PATTERN, + [ + Some(SyntaxElement::Node(self.regex.into_syntax())), + self.variables + .map(|token| SyntaxElement::Node(token.into_syntax())), + ], + )) + } +} +pub fn grit_regex_pattern_variables( + l_paren_token: SyntaxToken, + r_paren_token: SyntaxToken, +) -> GritRegexPatternVariablesBuilder { + GritRegexPatternVariablesBuilder { + l_paren_token, + r_paren_token, + grit_pattern_arg_list: None, + } +} +pub struct GritRegexPatternVariablesBuilder { + l_paren_token: SyntaxToken, + r_paren_token: SyntaxToken, + grit_pattern_arg_list: Option, +} +impl GritRegexPatternVariablesBuilder { + pub fn with_grit_pattern_arg_list(mut self, grit_pattern_arg_list: GritPatternArgList) -> Self { + self.grit_pattern_arg_list = Some(grit_pattern_arg_list); + self + } + pub fn build(self) -> GritRegexPatternVariables { + GritRegexPatternVariables::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_REGEX_PATTERN_VARIABLES, + [ + Some(SyntaxElement::Token(self.l_paren_token)), + self.grit_pattern_arg_list + .map(|token| SyntaxElement::Node(token.into_syntax())), + Some(SyntaxElement::Token(self.r_paren_token)), + ], + )) + } +} +pub fn grit_rewrite( + left: AnyGritPattern, + fat_arrow_token: SyntaxToken, + right: AnyGritPattern, +) -> GritRewriteBuilder { + GritRewriteBuilder { + left, + fat_arrow_token, + right, + annotation: None, + } +} +pub struct GritRewriteBuilder { + left: AnyGritPattern, + fat_arrow_token: SyntaxToken, + right: AnyGritPattern, + annotation: Option, +} +impl GritRewriteBuilder { + pub fn with_annotation(mut self, annotation: GritAnnotation) -> Self { + self.annotation = Some(annotation); + self + } + pub fn build(self) -> GritRewrite { + GritRewrite::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_REWRITE, + [ + Some(SyntaxElement::Node(self.left.into_syntax())), + self.annotation + .map(|token| SyntaxElement::Node(token.into_syntax())), + Some(SyntaxElement::Token(self.fat_arrow_token)), + Some(SyntaxElement::Node(self.right.into_syntax())), + ], + )) + } +} +pub fn grit_root() -> GritRootBuilder { + GritRootBuilder { + version: None, + language: None, + definitions: None, + pattern: None, + definitions_continued: None, + } +} +pub struct GritRootBuilder { + version: Option, + language: Option, + definitions: Option, + pattern: Option, + definitions_continued: Option, +} +impl GritRootBuilder { + pub fn with_version(mut self, version: GritVersion) -> Self { + self.version = Some(version); + self + } + pub fn with_language(mut self, language: GritLanguageDeclaration) -> Self { + self.language = Some(language); + self + } + pub fn with_definitions(mut self, definitions: GritDefinitionList) -> Self { + self.definitions = Some(definitions); + self + } + pub fn with_pattern(mut self, pattern: AnyGritPattern) -> Self { + self.pattern = Some(pattern); + self + } + pub fn with_definitions_continued(mut self, definitions_continued: GritDefinitionList) -> Self { + self.definitions_continued = Some(definitions_continued); + self + } + pub fn build(self) -> GritRoot { + GritRoot::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_ROOT, + [ + self.version + .map(|token| SyntaxElement::Node(token.into_syntax())), + self.language + .map(|token| SyntaxElement::Node(token.into_syntax())), + self.definitions + .map(|token| SyntaxElement::Node(token.into_syntax())), + self.pattern + .map(|token| SyntaxElement::Node(token.into_syntax())), + self.definitions_continued + .map(|token| SyntaxElement::Node(token.into_syntax())), + ], + )) + } +} +pub fn grit_sequential( + sequential_token: SyntaxToken, + l_curly_token: SyntaxToken, + sequential: GritSequentialList, + r_curly_token: SyntaxToken, +) -> GritSequential { + GritSequential::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_SEQUENTIAL, + [ + Some(SyntaxElement::Token(sequential_token)), + Some(SyntaxElement::Token(l_curly_token)), + Some(SyntaxElement::Node(sequential.into_syntax())), + Some(SyntaxElement::Token(r_curly_token)), + ], + )) +} +pub fn grit_signed_int_literal(value_token: SyntaxToken) -> GritSignedIntLiteral { + GritSignedIntLiteral::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_SIGNED_INT_LITERAL, + [Some(SyntaxElement::Token(value_token))], + )) +} +pub fn grit_snippet_regex(value_token: SyntaxToken) -> GritSnippetRegex { + GritSnippetRegex::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_SNIPPET_REGEX, + [Some(SyntaxElement::Token(value_token))], + )) +} +pub fn grit_some(some_token: SyntaxToken, pattern: MaybeCurlyGritPattern) -> GritSome { + GritSome::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_SOME, + [ + Some(SyntaxElement::Token(some_token)), + Some(SyntaxElement::Node(pattern.into_syntax())), + ], + )) +} +pub fn grit_string_literal(value_token: SyntaxToken) -> GritStringLiteral { + GritStringLiteral::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_STRING_LITERAL, + [Some(SyntaxElement::Token(value_token))], + )) +} +pub fn grit_sub_operation( + left: AnyGritPattern, + minus_token: SyntaxToken, + right: AnyGritPattern, +) -> GritSubOperation { + GritSubOperation::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_SUB_OPERATION, + [ + Some(SyntaxElement::Node(left.into_syntax())), + Some(SyntaxElement::Token(minus_token)), + Some(SyntaxElement::Node(right.into_syntax())), + ], + )) +} +pub fn grit_undefined(undefined_token: SyntaxToken) -> GritUndefined { + GritUndefined::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_UNDEFINED, + [Some(SyntaxElement::Token(undefined_token))], + )) +} +pub fn grit_underscore(dollar_underscore_token: SyntaxToken) -> GritUnderscore { + GritUnderscore::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_UNDERSCORE, + [Some(SyntaxElement::Token(dollar_underscore_token))], + )) +} +pub fn grit_variable(grit_variable_token: SyntaxToken) -> GritVariable { + GritVariable::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_VARIABLE, + [Some(SyntaxElement::Token(grit_variable_token))], + )) +} +pub fn grit_version( + engine_token: SyntaxToken, + biome_token: SyntaxToken, + l_paren_token: SyntaxToken, + grit_double_literal: GritDoubleLiteral, + r_paren_token: SyntaxToken, +) -> GritVersion { + GritVersion::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_VERSION, + [ + Some(SyntaxElement::Token(engine_token)), + Some(SyntaxElement::Token(biome_token)), + Some(SyntaxElement::Token(l_paren_token)), + Some(SyntaxElement::Node(grit_double_literal.into_syntax())), + Some(SyntaxElement::Token(r_paren_token)), + ], + )) +} +pub fn grit_within(within_token: SyntaxToken, pattern: MaybeCurlyGritPattern) -> GritWithin { + GritWithin::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_WITHIN, + [ + Some(SyntaxElement::Token(within_token)), + Some(SyntaxElement::Node(pattern.into_syntax())), + ], + )) +} +pub fn grit_definition_list(items: I, separators: S) -> GritDefinitionList +where + I: IntoIterator, + I::IntoIter: ExactSizeIterator, + S: IntoIterator, + S::IntoIter: ExactSizeIterator, +{ + let mut items = items.into_iter(); + let mut separators = separators.into_iter(); + let length = items.len() + separators.len(); + GritDefinitionList::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_DEFINITION_LIST, + (0..length).map(|index| { + if index % 2 == 0 { + Some(items.next()?.into_syntax().into()) + } else { + Some(separators.next()?.into()) + } + }), + )) +} +pub fn grit_files_list(items: I, separators: S) -> GritFilesList +where + I: IntoIterator, + I::IntoIter: ExactSizeIterator, + S: IntoIterator, + S::IntoIter: ExactSizeIterator, +{ + let mut items = items.into_iter(); + let mut separators = separators.into_iter(); + let length = items.len() + separators.len(); + GritFilesList::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_FILES_LIST, + (0..length).map(|index| { + if index % 2 == 0 { + Some(items.next()?.into_syntax().into()) + } else { + Some(separators.next()?.into()) + } + }), + )) +} +pub fn grit_language_flavor_list(items: I, separators: S) -> GritLanguageFlavorList +where + I: IntoIterator, + I::IntoIter: ExactSizeIterator, + S: IntoIterator, + S::IntoIter: ExactSizeIterator, +{ + let mut items = items.into_iter(); + let mut separators = separators.into_iter(); + let length = items.len() + separators.len(); + GritLanguageFlavorList::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_LANGUAGE_FLAVOR_LIST, + (0..length).map(|index| { + if index % 2 == 0 { + Some(items.next()?.into_syntax().into()) + } else { + Some(separators.next()?.into()) + } + }), + )) +} +pub fn grit_list_pattern_list(items: I, separators: S) -> GritListPatternList +where + I: IntoIterator, + I::IntoIter: ExactSizeIterator, + S: IntoIterator, + S::IntoIter: ExactSizeIterator, +{ + let mut items = items.into_iter(); + let mut separators = separators.into_iter(); + let length = items.len() + separators.len(); + GritListPatternList::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_LIST_PATTERN_LIST, + (0..length).map(|index| { + if index % 2 == 0 { + Some(items.next()?.into_syntax().into()) + } else { + Some(separators.next()?.into()) + } + }), + )) +} +pub fn grit_map_element_list(items: I, separators: S) -> GritMapElementList +where + I: IntoIterator, + I::IntoIter: ExactSizeIterator, + S: IntoIterator, + S::IntoIter: ExactSizeIterator, +{ + let mut items = items.into_iter(); + let mut separators = separators.into_iter(); + let length = items.len() + separators.len(); + GritMapElementList::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_MAP_ELEMENT_LIST, + (0..length).map(|index| { + if index % 2 == 0 { + Some(items.next()?.into_syntax().into()) + } else { + Some(separators.next()?.into()) + } + }), + )) +} +pub fn grit_named_arg_list(items: I, separators: S) -> GritNamedArgList +where + I: IntoIterator, + I::IntoIter: ExactSizeIterator, + S: IntoIterator, + S::IntoIter: ExactSizeIterator, +{ + let mut items = items.into_iter(); + let mut separators = separators.into_iter(); + let length = items.len() + separators.len(); + GritNamedArgList::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_NAMED_ARG_LIST, + (0..length).map(|index| { + if index % 2 == 0 { + Some(items.next()?.into_syntax().into()) + } else { + Some(separators.next()?.into()) + } + }), + )) +} +pub fn grit_pattern_list(items: I, separators: S) -> GritPatternList +where + I: IntoIterator, + I::IntoIter: ExactSizeIterator, + S: IntoIterator, + S::IntoIter: ExactSizeIterator, +{ + let mut items = items.into_iter(); + let mut separators = separators.into_iter(); + let length = items.len() + separators.len(); + GritPatternList::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PATTERN_LIST, + (0..length).map(|index| { + if index % 2 == 0 { + Some(items.next()?.into_syntax().into()) + } else { + Some(separators.next()?.into()) + } + }), + )) +} +pub fn grit_predicate_list(items: I, separators: S) -> GritPredicateList +where + I: IntoIterator, + I::IntoIter: ExactSizeIterator, + S: IntoIterator, + S::IntoIter: ExactSizeIterator, +{ + let mut items = items.into_iter(); + let mut separators = separators.into_iter(); + let length = items.len() + separators.len(); + GritPredicateList::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PREDICATE_LIST, + (0..length).map(|index| { + if index % 2 == 0 { + Some(items.next()?.into_syntax().into()) + } else { + Some(separators.next()?.into()) + } + }), + )) +} +pub fn grit_sequential_list(items: I, separators: S) -> GritSequentialList +where + I: IntoIterator, + I::IntoIter: ExactSizeIterator, + S: IntoIterator, + S::IntoIter: ExactSizeIterator, +{ + let mut items = items.into_iter(); + let mut separators = separators.into_iter(); + let length = items.len() + separators.len(); + GritSequentialList::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_SEQUENTIAL_LIST, + (0..length).map(|index| { + if index % 2 == 0 { + Some(items.next()?.into_syntax().into()) + } else { + Some(separators.next()?.into()) + } + }), + )) +} +pub fn grit_variable_list(items: I, separators: S) -> GritVariableList +where + I: IntoIterator, + I::IntoIter: ExactSizeIterator, + S: IntoIterator, + S::IntoIter: ExactSizeIterator, +{ + let mut items = items.into_iter(); + let mut separators = separators.into_iter(); + let length = items.len() + separators.len(); + GritVariableList::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_VARIABLE_LIST, + (0..length).map(|index| { + if index % 2 == 0 { + Some(items.next()?.into_syntax().into()) + } else { + Some(separators.next()?.into()) + } + }), + )) +} +pub fn grit_bogus(slots: I) -> GritBogus +where + I: IntoIterator>, + I::IntoIter: ExactSizeIterator, +{ + GritBogus::unwrap_cast(SyntaxNode::new_detached(GritSyntaxKind::GRIT_BOGUS, slots)) +} +pub fn grit_bogus_definition(slots: I) -> GritBogusDefinition +where + I: IntoIterator>, + I::IntoIter: ExactSizeIterator, +{ + GritBogusDefinition::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_BOGUS_DEFINITION, + slots, + )) +} +pub fn grit_bogus_literal(slots: I) -> GritBogusLiteral +where + I: IntoIterator>, + I::IntoIter: ExactSizeIterator, +{ + GritBogusLiteral::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_BOGUS_LITERAL, + slots, + )) +} +pub fn grit_bogus_named_arg(slots: I) -> GritBogusNamedArg +where + I: IntoIterator>, + I::IntoIter: ExactSizeIterator, +{ + GritBogusNamedArg::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_BOGUS_NAMED_ARG, + slots, + )) +} +pub fn grit_bogus_pattern(slots: I) -> GritBogusPattern +where + I: IntoIterator>, + I::IntoIter: ExactSizeIterator, +{ + GritBogusPattern::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_BOGUS_PATTERN, + slots, + )) +} +pub fn grit_bogus_predicate(slots: I) -> GritBogusPredicate +where + I: IntoIterator>, + I::IntoIter: ExactSizeIterator, +{ + GritBogusPredicate::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_BOGUS_PREDICATE, + slots, + )) +} diff --git a/crates/biome_grit_factory/src/generated/syntax_factory.rs b/crates/biome_grit_factory/src/generated/syntax_factory.rs new file mode 100644 index 00000000000..b15a1684a05 --- /dev/null +++ b/crates/biome_grit_factory/src/generated/syntax_factory.rs @@ -0,0 +1,3582 @@ +//! Generated file, do not edit by hand, see `xtask/codegen` + +use biome_grit_syntax::{GritSyntaxKind, GritSyntaxKind::*, T, *}; +use biome_rowan::{ + AstNode, ParsedChildren, RawNodeSlots, RawSyntaxNode, SyntaxFactory, SyntaxKind, +}; +#[derive(Debug)] +pub struct GritSyntaxFactory; +impl SyntaxFactory for GritSyntaxFactory { + type Kind = GritSyntaxKind; + #[allow(unused_mut)] + fn make_syntax( + kind: Self::Kind, + children: ParsedChildren, + ) -> RawSyntaxNode { + match kind { + GRIT_BOGUS + | GRIT_BOGUS_DEFINITION + | GRIT_BOGUS_LITERAL + | GRIT_BOGUS_NAMED_ARG + | GRIT_BOGUS_PATTERN + | GRIT_BOGUS_PREDICATE => RawSyntaxNode::new(kind, children.into_iter().map(Some)), + ANY_GRIT_PATTERN => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<41usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if AnyGritLiteral::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPatternNot::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPatternOr::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPatternOrElse::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPatternAny::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPatternAnd::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPatternMaybe::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPatternIfElse::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPatternContains::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPatternIncludes::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPatternAfter::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPatternBefore::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritWithin::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritBubble::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritNodeLike::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritMapAccessor::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritListAccessor::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritDot::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritSome::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritEvery::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritUnderscore::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritVariable::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritRegexPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPatternAs::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPatternLimit::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritAssignmentAsPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPatternAccumulate::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritRewrite::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritLike::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPatternWhere::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritMulOperation::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritDivOperation::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritModOperation::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritAddOperation::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritSubOperation::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritSequential::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritFiles::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['('] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![')'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritBogusPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + ANY_GRIT_PATTERN.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(ANY_GRIT_PATTERN, children) + } + ANY_GRIT_PREDICATE => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<23usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if GritPredicateNot::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPredicateMaybe::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPredicateAnd::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPredicateOr::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPredicateAny::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPredicateIfElse::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPredicateAssignment::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPredicateAccumulate::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPredicateRewrite::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPredicateGreater::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPredicateLess::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPredicateGreaterEqual::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPredicateLessEqual::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPredicateNotEqual::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPredicateEqual::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPredicateMatch::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPredicateCall::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['('] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPredicate::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![')'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritBooleanLiteral::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPredicateReturn::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritBogusPredicate::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + ANY_GRIT_PREDICATE.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(ANY_GRIT_PREDICATE, children) + } + CURLY_GRIT_PATTERN => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T!['{'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['}'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + CURLY_GRIT_PATTERN.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(CURLY_GRIT_PATTERN, children) + } + GRIT_ADD_OPERATION => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [+] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_ADD_OPERATION.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_ADD_OPERATION, children) + } + GRIT_ANNOTATION => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == GRIT_ANNOTATION { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_ANNOTATION.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_ANNOTATION, children) + } + GRIT_ASSIGNMENT_AS_PATTERN => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if AnyGritContainer::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [=] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_ASSIGNMENT_AS_PATTERN.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_ASSIGNMENT_AS_PATTERN, children) + } + GRIT_BACKTICK_SNIPPET => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == GRIT_BACKTICK_SNIPPET { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_BACKTICK_SNIPPET.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_BACKTICK_SNIPPET, children) + } + GRIT_BOOLEAN_LITERAL => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![true] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![false] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_BOOLEAN_LITERAL.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_BOOLEAN_LITERAL, children) + } + GRIT_BUBBLE => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![bubble] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritBubbleScope::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if MaybeCurlyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_BUBBLE.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_BUBBLE, children) + } + GRIT_BUBBLE_SCOPE => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T!['('] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritVariableList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![')'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_BUBBLE_SCOPE.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_BUBBLE_SCOPE, children) + } + GRIT_CODE_SNIPPET => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if GritCodeSnippetSource::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_CODE_SNIPPET.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_CODE_SNIPPET, children) + } + GRIT_CURLY_PREDICATE_LIST => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T!['{'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPredicateList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['}'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_CURLY_PREDICATE_LIST.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_CURLY_PREDICATE_LIST, children) + } + GRIT_DIV_OPERATION => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [/] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_DIV_OPERATION.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_DIV_OPERATION, children) + } + GRIT_DOT => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [.] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new(GRIT_DOT.to_bogus(), children.into_iter().map(Some)); + } + slots.into_node(GRIT_DOT, children) + } + GRIT_DOTDOTDOT => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T!["$..."] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if MaybeCurlyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_DOTDOTDOT.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_DOTDOTDOT, children) + } + GRIT_DOUBLE_LITERAL => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == GRIT_DOUBLE_LITERAL { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_DOUBLE_LITERAL.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_DOUBLE_LITERAL, children) + } + GRIT_DOUBLE_QUOTE_SNIPPET => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == GRIT_DOUBLE_QUOTE_SNIPPET { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_DOUBLE_QUOTE_SNIPPET.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_DOUBLE_QUOTE_SNIPPET, children) + } + GRIT_EVERY => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![every] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if MaybeCurlyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_EVERY.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_EVERY, children) + } + GRIT_FILES => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![multifile] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['{'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritFilesList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['}'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_FILES.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_FILES, children) + } + GRIT_FUNCTION_DEFINITION => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<6usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![function] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritName::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['('] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritVariableList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![')'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritCurlyPredicateList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_FUNCTION_DEFINITION.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_FUNCTION_DEFINITION, children) + } + GRIT_INT_LITERAL => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == GRIT_INT_LITERAL { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_INT_LITERAL.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_INT_LITERAL, children) + } + GRIT_LANGUAGE_DECLARATION => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![language] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritLanguageName::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritLanguageFlavor::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_LANGUAGE_DECLARATION.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_LANGUAGE_DECLARATION, children) + } + GRIT_LANGUAGE_FLAVOR => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T!['('] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritLanguageFlavorList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![')'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [;] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_LANGUAGE_FLAVOR.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_LANGUAGE_FLAVOR, children) + } + GRIT_LANGUAGE_FLAVOR_KIND => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if matches!(element.kind(), T![typescript] | T![jsx] | T![js_do_not_use]) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_LANGUAGE_FLAVOR_KIND.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_LANGUAGE_FLAVOR_KIND, children) + } + GRIT_LANGUAGE_NAME => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<5usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![js] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![css] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![json] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![grit] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![html] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_LANGUAGE_NAME.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_LANGUAGE_NAME, children) + } + GRIT_LANGUAGE_SPECIFIC_SNIPPET => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if GritLanguageName::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritDoubleQuoteSnippet::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_LANGUAGE_SPECIFIC_SNIPPET.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_LANGUAGE_SPECIFIC_SNIPPET, children) + } + GRIT_LIKE => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<5usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![like] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritLikeThreshold::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['{'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['}'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_LIKE.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_LIKE, children) + } + GRIT_LIKE_THRESHOLD => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T!['('] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![')'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_LIKE_THRESHOLD.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_LIKE_THRESHOLD, children) + } + GRIT_LIST => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if GritName::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['['] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritListPatternList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![']'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_LIST.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_LIST, children) + } + GRIT_LIST_ACCESSOR => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if GritListAccessorSubject::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['['] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritListIndex::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![']'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_LIST_ACCESSOR.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_LIST_ACCESSOR, children) + } + GRIT_MAP => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T!['{'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritMapElementList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['}'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new(GRIT_MAP.to_bogus(), children.into_iter().map(Some)); + } + slots.into_node(GRIT_MAP, children) + } + GRIT_MAP_ACCESSOR => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if GritMapAccessorSubject::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [.] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritMapKey::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_MAP_ACCESSOR.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_MAP_ACCESSOR, children) + } + GRIT_MAP_ELEMENT => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if GritName::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [:] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_MAP_ELEMENT.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_MAP_ELEMENT, children) + } + GRIT_MOD_OPERATION => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [%] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_MOD_OPERATION.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_MOD_OPERATION, children) + } + GRIT_MUL_OPERATION => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [*] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_MUL_OPERATION.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_MUL_OPERATION, children) + } + GRIT_NAME => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == GRIT_NAME { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_NAME.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_NAME, children) + } + GRIT_NAMED_ARG => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if GritName::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_NAMED_ARG.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_NAMED_ARG, children) + } + GRIT_NAMED_ARG_WITH_DEFAULT => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if GritName::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [=] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_NAMED_ARG_WITH_DEFAULT.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_NAMED_ARG_WITH_DEFAULT, children) + } + GRIT_NODE_LIKE => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if GritName::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['('] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritNamedArgList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![')'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_NODE_LIKE.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_NODE_LIKE, children) + } + GRIT_NOT => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![not] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![!] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new(GRIT_NOT.to_bogus(), children.into_iter().map(Some)); + } + slots.into_node(GRIT_NOT, children) + } + GRIT_PATTERN_ACCUMULATE => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [+=] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PATTERN_ACCUMULATE.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PATTERN_ACCUMULATE, children) + } + GRIT_PATTERN_AFTER => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![after] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PATTERN_AFTER.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PATTERN_AFTER, children) + } + GRIT_PATTERN_AND => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![and] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['{'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPatternList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['}'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PATTERN_AND.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PATTERN_AND, children) + } + GRIT_PATTERN_ANY => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![any] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['{'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPatternList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['}'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PATTERN_ANY.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PATTERN_ANY, children) + } + GRIT_PATTERN_ARG_LIST => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if GritVariableList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PATTERN_ARG_LIST.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PATTERN_ARG_LIST, children) + } + GRIT_PATTERN_AS => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![as] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritVariable::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PATTERN_AS.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PATTERN_AS, children) + } + GRIT_PATTERN_BEFORE => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![before] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PATTERN_BEFORE.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PATTERN_BEFORE, children) + } + GRIT_PATTERN_CONTAINS => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![contains] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if MaybeCurlyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPatternContainsUntilClause::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PATTERN_CONTAINS.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PATTERN_CONTAINS, children) + } + GRIT_PATTERN_CONTAINS_UNTIL_CLAUSE => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![until] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PATTERN_CONTAINS_UNTIL_CLAUSE.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PATTERN_CONTAINS_UNTIL_CLAUSE, children) + } + GRIT_PATTERN_DEFINITION => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<8usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![private] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![pattern] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritName::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['('] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPatternArgList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![')'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritLanguageDeclaration::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPatternDefinitionBody::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PATTERN_DEFINITION.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PATTERN_DEFINITION, children) + } + GRIT_PATTERN_DEFINITION_BODY => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T!['{'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPatternList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['}'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PATTERN_DEFINITION_BODY.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PATTERN_DEFINITION_BODY, children) + } + GRIT_PATTERN_ELSE_CLAUSE => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![else] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if MaybeCurlyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PATTERN_ELSE_CLAUSE.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PATTERN_ELSE_CLAUSE, children) + } + GRIT_PATTERN_IF_ELSE => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<6usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![if] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['('] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPredicate::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![')'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if MaybeCurlyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPatternElseClause::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PATTERN_IF_ELSE.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PATTERN_IF_ELSE, children) + } + GRIT_PATTERN_INCLUDES => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![includes] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if MaybeCurlyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PATTERN_INCLUDES.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PATTERN_INCLUDES, children) + } + GRIT_PATTERN_LIMIT => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![limit] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritIntLiteral::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PATTERN_LIMIT.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PATTERN_LIMIT, children) + } + GRIT_PATTERN_MAYBE => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![maybe] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if MaybeCurlyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PATTERN_MAYBE.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PATTERN_MAYBE, children) + } + GRIT_PATTERN_NOT => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if GritNot::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PATTERN_NOT.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PATTERN_NOT, children) + } + GRIT_PATTERN_OR => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![or] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['{'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPatternList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['}'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PATTERN_OR.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PATTERN_OR, children) + } + GRIT_PATTERN_OR_ELSE => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![orelse] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['{'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPatternList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['}'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PATTERN_OR_ELSE.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PATTERN_OR_ELSE, children) + } + GRIT_PATTERN_WHERE => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![where] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPredicate::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PATTERN_WHERE.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PATTERN_WHERE, children) + } + GRIT_PREDICATE_ACCUMULATE => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if GritVariable::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [+=] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PREDICATE_ACCUMULATE.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PREDICATE_ACCUMULATE, children) + } + GRIT_PREDICATE_AND => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![and] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['{'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPredicateList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['}'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PREDICATE_AND.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PREDICATE_AND, children) + } + GRIT_PREDICATE_ANY => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![any] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['{'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPredicateList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['}'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PREDICATE_ANY.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PREDICATE_ANY, children) + } + GRIT_PREDICATE_ASSIGNMENT => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if AnyGritContainer::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [=] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PREDICATE_ASSIGNMENT.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PREDICATE_ASSIGNMENT, children) + } + GRIT_PREDICATE_CALL => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if GritName::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['('] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritNamedArgList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![')'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PREDICATE_CALL.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PREDICATE_CALL, children) + } + GRIT_PREDICATE_DEFINITION => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<6usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![predicate] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritName::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['('] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPatternArgList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![')'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritCurlyPredicateList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PREDICATE_DEFINITION.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PREDICATE_DEFINITION, children) + } + GRIT_PREDICATE_ELSE_CLAUSE => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![else] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPredicate::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PREDICATE_ELSE_CLAUSE.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PREDICATE_ELSE_CLAUSE, children) + } + GRIT_PREDICATE_EQUAL => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if GritVariable::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [==] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PREDICATE_EQUAL.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PREDICATE_EQUAL, children) + } + GRIT_PREDICATE_GREATER => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if GritVariable::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [>] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PREDICATE_GREATER.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PREDICATE_GREATER, children) + } + GRIT_PREDICATE_GREATER_EQUAL => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if GritVariable::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [>=] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PREDICATE_GREATER_EQUAL.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PREDICATE_GREATER_EQUAL, children) + } + GRIT_PREDICATE_IF_ELSE => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<6usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![if] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['('] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPredicate::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![')'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPredicate::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPredicateElseClause::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PREDICATE_IF_ELSE.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PREDICATE_IF_ELSE, children) + } + GRIT_PREDICATE_LESS => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if GritVariable::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [<] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PREDICATE_LESS.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PREDICATE_LESS, children) + } + GRIT_PREDICATE_LESS_EQUAL => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if GritVariable::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [<=] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PREDICATE_LESS_EQUAL.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PREDICATE_LESS_EQUAL, children) + } + GRIT_PREDICATE_MATCH => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if GritPredicateMatchSubject::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [<:] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PREDICATE_MATCH.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PREDICATE_MATCH, children) + } + GRIT_PREDICATE_MAYBE => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![maybe] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPredicate::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PREDICATE_MAYBE.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PREDICATE_MAYBE, children) + } + GRIT_PREDICATE_NOT => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if GritNot::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPredicate::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PREDICATE_NOT.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PREDICATE_NOT, children) + } + GRIT_PREDICATE_NOT_EQUAL => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if GritVariable::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [!=] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PREDICATE_NOT_EQUAL.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PREDICATE_NOT_EQUAL, children) + } + GRIT_PREDICATE_OR => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![or] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['{'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPredicateList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['}'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PREDICATE_OR.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PREDICATE_OR, children) + } + GRIT_PREDICATE_RETURN => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![return] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PREDICATE_RETURN.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PREDICATE_RETURN, children) + } + GRIT_PREDICATE_REWRITE => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if GritVariable::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritAnnotation::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [=>] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_PREDICATE_REWRITE.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_PREDICATE_REWRITE, children) + } + GRIT_RAW_BACKTICK_SNIPPET => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == GRIT_RAW_BACKTICK_SNIPPET { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_RAW_BACKTICK_SNIPPET.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_RAW_BACKTICK_SNIPPET, children) + } + GRIT_REGEX_LITERAL => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == GRIT_REGEX_LITERAL { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_REGEX_LITERAL.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_REGEX_LITERAL, children) + } + GRIT_REGEX_PATTERN => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if GritRegex::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritRegexPatternVariables::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_REGEX_PATTERN.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_REGEX_PATTERN, children) + } + GRIT_REGEX_PATTERN_VARIABLES => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T!['('] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritPatternArgList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![')'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_REGEX_PATTERN_VARIABLES.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_REGEX_PATTERN_VARIABLES, children) + } + GRIT_REWRITE => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritAnnotation::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [=>] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_REWRITE.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_REWRITE, children) + } + GRIT_ROOT => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<5usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if GritVersion::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritLanguageDeclaration::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritDefinitionList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritDefinitionList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_ROOT.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_ROOT, children) + } + GRIT_SEQUENTIAL => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![sequential] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['{'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritSequentialList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['}'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_SEQUENTIAL.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_SEQUENTIAL, children) + } + GRIT_SIGNED_INT_LITERAL => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == GRIT_SIGNED_INT_LITERAL { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_SIGNED_INT_LITERAL.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_SIGNED_INT_LITERAL, children) + } + GRIT_SNIPPET_REGEX => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == GRIT_SNIPPET_REGEX_LITERAL { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_SNIPPET_REGEX.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_SNIPPET_REGEX, children) + } + GRIT_SOME => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![some] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if MaybeCurlyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_SOME.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_SOME, children) + } + GRIT_STRING_LITERAL => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == GRIT_STRING_LITERAL { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_STRING_LITERAL.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_STRING_LITERAL, children) + } + GRIT_SUB_OPERATION => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [-] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_SUB_OPERATION.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_SUB_OPERATION, children) + } + GRIT_UNDEFINED => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![undefined] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_UNDEFINED.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_UNDEFINED, children) + } + GRIT_UNDERSCORE => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T!["$_"] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_UNDERSCORE.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_UNDERSCORE, children) + } + GRIT_VARIABLE => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == GRIT_VARIABLE { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_VARIABLE.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_VARIABLE, children) + } + GRIT_VERSION => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<5usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![engine] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![biome] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T!['('] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if GritDoubleLiteral::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![')'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_VERSION.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_VERSION, children) + } + GRIT_WITHIN => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![within] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if MaybeCurlyGritPattern::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_WITHIN.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_WITHIN, children) + } + GRIT_DEFINITION_LIST => Self::make_separated_list_syntax( + kind, + children, + AnyGritDefinition::can_cast, + NEWLINE, + true, + ), + GRIT_FILES_LIST => Self::make_separated_list_syntax( + kind, + children, + AnyGritPattern::can_cast, + T ! [,], + true, + ), + GRIT_LANGUAGE_FLAVOR_LIST => Self::make_separated_list_syntax( + kind, + children, + GritLanguageFlavorKind::can_cast, + T ! [,], + true, + ), + GRIT_LIST_PATTERN_LIST => Self::make_separated_list_syntax( + kind, + children, + AnyGritListPattern::can_cast, + T ! [,], + true, + ), + GRIT_MAP_ELEMENT_LIST => Self::make_separated_list_syntax( + kind, + children, + GritMapElement::can_cast, + T ! [,], + true, + ), + GRIT_NAMED_ARG_LIST => Self::make_separated_list_syntax( + kind, + children, + GritNamedArg::can_cast, + T ! [,], + true, + ), + GRIT_PATTERN_LIST => Self::make_separated_list_syntax( + kind, + children, + AnyGritPattern::can_cast, + T ! [,], + true, + ), + GRIT_PREDICATE_LIST => Self::make_separated_list_syntax( + kind, + children, + AnyGritPredicate::can_cast, + T ! [,], + true, + ), + GRIT_SEQUENTIAL_LIST => Self::make_separated_list_syntax( + kind, + children, + AnyGritPattern::can_cast, + T ! [,], + true, + ), + GRIT_VARIABLE_LIST => Self::make_separated_list_syntax( + kind, + children, + GritVariable::can_cast, + T ! [,], + true, + ), + _ => unreachable!("Is {:?} a token?", kind), + } + } +} diff --git a/crates/biome_grit_factory/src/lib.rs b/crates/biome_grit_factory/src/lib.rs new file mode 100644 index 00000000000..4eb787ecb1d --- /dev/null +++ b/crates/biome_grit_factory/src/lib.rs @@ -0,0 +1,11 @@ +use biome_grit_syntax::GritLanguage; +use biome_rowan::TreeBuilder; + +mod generated; +pub use crate::generated::GritSyntaxFactory; + +// Re-exported for tests +#[doc(hidden)] +pub use biome_grit_syntax as syntax; + +pub type GritSyntaxTreeBuilder = TreeBuilder<'static, GritLanguage, GritSyntaxFactory>; diff --git a/crates/biome_grit_formatter/Cargo.toml b/crates/biome_grit_formatter/Cargo.toml new file mode 100644 index 00000000000..f3333f4fc8e --- /dev/null +++ b/crates/biome_grit_formatter/Cargo.toml @@ -0,0 +1,56 @@ +[package] +authors.workspace = true +categories.workspace = true +description = "Biome's GritQL formatter" +edition.workspace = true +homepage.workspace = true +keywords.workspace = true +license.workspace = true +name = "biome_grit_formatter" +repository.workspace = true +version = "0.4.0" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +biome_console = { workspace = true } +biome_deserialize = { workspace = true } +biome_deserialize_macros = { workspace = true } +biome_diagnostics_categories = { workspace = true } +biome_formatter = { workspace = true } +biome_grit_factory = { workspace = true } +biome_grit_syntax = { workspace = true } +biome_rowan = { workspace = true } +biome_text_size = { workspace = true } +biome_unicode_table = { workspace = true } +cfg-if = "1.0.0" +schemars = { workspace = true, optional = true } +serde = { workspace = true, features = ["derive"], optional = true } +smallvec = { workspace = true } +tracing = { workspace = true } +unicode-width = "0.1.9" + +[dev-dependencies] +biome_diagnostics = { path = "../biome_diagnostics" } +biome_formatter_test = { path = "../biome_formatter_test" } +biome_fs = { path = "../biome_fs" } +biome_grit_factory = { path = "../biome_grit_factory" } +biome_grit_parser = { path = "../biome_grit_parser" } +biome_parser = { path = "../biome_parser" } +countme = { workspace = true, features = ["enable"] } +insta = { workspace = true, features = ["glob"] } +quickcheck = { workspace = true } +quickcheck_macros = { workspace = true } +serde = { version = "1", features = ["derive"] } +serde_json = { workspace = true } +tests_macros = { path = "../tests_macros" } + +[features] +serde = ["dep:serde", "schemars"] + +# cargo-workspaces metadata +[package.metadata.workspaces] +independent = true + +[lints] +workspace = true diff --git a/crates/biome_grit_formatter/src/lib.rs b/crates/biome_grit_formatter/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/biome_grit_parser/Cargo.toml b/crates/biome_grit_parser/Cargo.toml new file mode 100644 index 00000000000..d636d9d8771 --- /dev/null +++ b/crates/biome_grit_parser/Cargo.toml @@ -0,0 +1,49 @@ +[package] +authors.workspace = true +categories.workspace = true +description = "Biome's GritQL parser" +edition.workspace = true +homepage.workspace = true +keywords.workspace = true +license.workspace = true +name = "biome_grit_parser" +repository.workspace = true +version = "0.4.0" + +[dependencies] +biome_console = { workspace = true } +biome_diagnostics = { workspace = true } +biome_grit_factory = { workspace = true } +biome_grit_syntax = { workspace = true } +biome_parser = { workspace = true } +biome_rowan = { workspace = true } +biome_unicode_table = { workspace = true } +bitflags = { workspace = true } +cfg-if = "1.0.0" +drop_bomb = "0.1.5" +indexmap = { workspace = true } +rustc-hash = { workspace = true } +schemars = { workspace = true, optional = true } +serde = { workspace = true, features = ["derive"] } +serde_json = { workspace = true } +smallvec = { workspace = true } +tracing = { workspace = true } +unicode-bom = { workspace = true } + +[dev-dependencies] +expect-test = "1.2.2" +quickcheck = { workspace = true } +quickcheck_macros = { workspace = true } +tests_macros = { workspace = true } + +[features] +schemars = ["dep:schemars"] +serde = ["biome_grit_syntax/serde"] +tests = [] + +# cargo-workspaces metadata +[package.metadata.workspaces] +independent = true + +[lints] +workspace = true diff --git a/crates/biome_grit_parser/src/lib.rs b/crates/biome_grit_parser/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/biome_grit_syntax/Cargo.toml b/crates/biome_grit_syntax/Cargo.toml new file mode 100644 index 00000000000..838765a4039 --- /dev/null +++ b/crates/biome_grit_syntax/Cargo.toml @@ -0,0 +1,28 @@ +[package] +authors.workspace = true +categories.workspace = true +description = "SyntaxKind and common rowan definitions for biome_grit_parser" +edition.workspace = true +homepage.workspace = true +keywords.workspace = true +license.workspace = true +name = "biome_grit_syntax" +repository.workspace = true +version = "0.4.0" + +[dependencies] +biome_console = { workspace = true } +biome_diagnostics = { workspace = true } +biome_rowan = { workspace = true } +schemars = { version = "0.8.10", optional = true } +serde = { version = "1.0.136", features = ["derive"], optional = true } + +[dev-dependencies] +biome_grit_factory = { path = "../biome_grit_factory" } +biome_grit_parser = { path = "../biome_grit_parser" } + +[features] +serde = ["dep:serde", "schemars", "biome_rowan/serde"] + +[lints] +workspace = true diff --git a/crates/biome_grit_syntax/src/generated.rs b/crates/biome_grit_syntax/src/generated.rs new file mode 100644 index 00000000000..0ba57175a3b --- /dev/null +++ b/crates/biome_grit_syntax/src/generated.rs @@ -0,0 +1,11 @@ +#[rustfmt::skip] +pub(super) mod nodes; +#[rustfmt::skip] +pub(super) mod nodes_mut; +#[rustfmt::skip] +pub mod macros; +#[macro_use] +pub mod kind; + +pub use kind::*; +pub use nodes::*; diff --git a/crates/biome_grit_syntax/src/generated/kind.rs b/crates/biome_grit_syntax/src/generated/kind.rs new file mode 100644 index 00000000000..83739673982 --- /dev/null +++ b/crates/biome_grit_syntax/src/generated/kind.rs @@ -0,0 +1,387 @@ +//! Generated file, do not edit by hand, see `xtask/codegen` + +#![allow(clippy::all)] +#![allow(bad_style, missing_docs, unreachable_pub)] +#[doc = r" The kind of syntax node, e.g. `IDENT`, `FUNCTION_KW`, or `FOR_STMT`."] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[repr(u16)] +pub enum GritSyntaxKind { + #[doc(hidden)] + TOMBSTONE, + #[doc = r" Marks the end of the file. May have trivia attached"] + EOF, + #[doc = r" Any Unicode BOM character that may be present at the start of"] + #[doc = r" a file."] + UNICODE_BOM, + DOLLAR_DOT3, + DOLLAR_UNDERSCORE, + MATCH, + SEMICOLON, + COMMA, + L_PAREN, + R_PAREN, + L_CURLY, + R_CURLY, + L_BRACK, + R_BRACK, + L_ANGLE, + R_ANGLE, + PLUS, + STAR, + SLASH, + PERCENT, + DOT, + COLON, + EQ, + EQ2, + FAT_ARROW, + BANG, + NEQ, + MINUS, + LTEQ, + GTEQ, + PLUSEQ, + BACKTICK, + SEQUENTIAL_KW, + MULTIFILE_KW, + ENGINE_KW, + BIOME_KW, + LANGUAGE_KW, + JS_KW, + CSS_KW, + JSON_KW, + GRIT_KW, + HTML_KW, + TYPESCRIPT_KW, + JSX_KW, + JS_DO_NOT_USE_KW, + AS_KW, + LIMIT_KW, + WHERE_KW, + ORELSE_KW, + MAYBE_KW, + AFTER_KW, + BEFORE_KW, + CONTAINS_KW, + UNTIL_KW, + INCLUDES_KW, + IF_KW, + ELSE_KW, + WITHIN_KW, + BUBBLE_KW, + NOT_KW, + OR_KW, + AND_KW, + ANY_KW, + SOME_KW, + EVERY_KW, + PRIVATE_KW, + PATTERN_KW, + PREDICATE_KW, + FUNCTION_KW, + TRUE_KW, + FALSE_KW, + UNDEFINED_KW, + LIKE_KW, + RETURN_KW, + GRIT_INT_LITERAL, + GRIT_SIGNED_INT_LITERAL, + GRIT_DOUBLE_LITERAL, + GRIT_STRING_LITERAL, + GRIT_REGEX_LITERAL, + GRIT_SNIPPET_REGEX_LITERAL, + NEWLINE, + WHITESPACE, + COMMENT, + GRIT_ANNOTATION, + GRIT_BACKTICK_SNIPPET, + GRIT_RAW_BACKTICK_SNIPPET, + GRIT_DOUBLE_QUOTE_SNIPPET, + GRIT_NAME, + GRIT_VARIABLE, + ANY_GRIT_CONTAINER, + ANY_GRIT_DEFINITION, + ANY_GRIT_LIST_PATTERN, + ANY_GRIT_LITERAL, + ANY_GRIT_NAMED_ARG, + ANY_GRIT_PATTERN, + ANY_GRIT_PREDICATE, + CURLY_GRIT_PATTERN, + GRIT_ROOT, + GRIT_SEQUENTIAL, + GRIT_SEQUENTIAL_LIST, + GRIT_FILES, + GRIT_FILES_LIST, + GRIT_DEFINITION_LIST, + GRIT_VERSION, + GRIT_LANGUAGE_DECLARATION, + GRIT_LANGUAGE_FLAVOR, + GRIT_LANGUAGE_FLAVOR_LIST, + GRIT_LANGUAGE_FLAVOR_KIND, + GRIT_PATTERN_LIST, + GRIT_MUL_OPERATION, + GRIT_DIV_OPERATION, + GRIT_MOD_OPERATION, + GRIT_ADD_OPERATION, + GRIT_SUB_OPERATION, + GRIT_PATTERN_AS, + GRIT_PATTERN_LIMIT, + GRIT_ASSIGNMENT_AS_PATTERN, + GRIT_PATTERN_ACCUMULATE, + GRIT_PATTERN_WHERE, + GRIT_PATTERN_NOT, + GRIT_PATTERN_OR, + GRIT_PATTERN_OR_ELSE, + GRIT_PATTERN_ANY, + GRIT_PATTERN_AND, + GRIT_PATTERN_MAYBE, + GRIT_PATTERN_AFTER, + GRIT_PATTERN_BEFORE, + GRIT_PATTERN_CONTAINS, + GRIT_PATTERN_CONTAINS_UNTIL_CLAUSE, + GRIT_PATTERN_INCLUDES, + GRIT_REWRITE, + GRIT_PATTERN_IF_ELSE, + GRIT_PATTERN_ELSE_CLAUSE, + GRIT_WITHIN, + GRIT_BUBBLE_SCOPE, + GRIT_BUBBLE, + GRIT_NAMED_ARG, + GRIT_NAMED_ARG_WITH_DEFAULT, + GRIT_NAMED_ARG_LIST, + GRIT_NODE_LIKE, + GRIT_LIKE, + GRIT_LIKE_THRESHOLD, + GRIT_MAP, + GRIT_MAP_ELEMENT_LIST, + GRIT_MAP_ELEMENT, + GRIT_MAP_ACCESSOR, + GRIT_MAP_ACCESSOR_SUBJECT, + GRIT_MAP_KEY, + GRIT_LIST, + GRIT_LIST_PATTERN_LIST, + GRIT_LIST_ACCESSOR, + GRIT_LIST_ACCESSOR_SUBJECT, + GRIT_LIST_INDEX, + GRIT_DOT, + GRIT_DOTDOTDOT, + GRIT_SOME, + GRIT_EVERY, + GRIT_REGEX_PATTERN, + GRIT_REGEX_PATTERN_VARIABLES, + GRIT_PATTERN_DEFINITION_BODY, + GRIT_PATTERN_DEFINITION, + GRIT_PATTERN_ARG_LIST, + GRIT_PREDICATE_LIST, + GRIT_CURLY_PREDICATE_LIST, + GRIT_PREDICATE_DEFINITION, + GRIT_FUNCTION_DEFINITION, + GRIT_PREDICATE_NOT, + GRIT_PREDICATE_MAYBE, + GRIT_PREDICATE_AND, + GRIT_PREDICATE_OR, + GRIT_PREDICATE_ANY, + GRIT_PREDICATE_IF_ELSE, + GRIT_PREDICATE_ELSE_CLAUSE, + GRIT_PREDICATE_REWRITE, + GRIT_PREDICATE_ASSIGNMENT, + GRIT_PREDICATE_ACCUMULATE, + GRIT_PREDICATE_GREATER, + GRIT_PREDICATE_LESS, + GRIT_PREDICATE_GREATER_EQUAL, + GRIT_PREDICATE_LESS_EQUAL, + GRIT_PREDICATE_NOT_EQUAL, + GRIT_PREDICATE_EQUAL, + GRIT_PREDICATE_MATCH, + GRIT_PREDICATE_MATCH_SUBJECT, + GRIT_PREDICATE_CALL, + GRIT_PREDICATE_RETURN, + GRIT_BOOLEAN_LITERAL, + GRIT_VARIABLE_LIST, + GRIT_LANGUAGE_NAME, + GRIT_LANGUAGE_SPECIFIC_SNIPPET, + GRIT_CODE_SNIPPET, + GRIT_NOT, + GRIT_SNIPPET_REGEX, + GRIT_UNDEFINED, + GRIT_UNDERSCORE, + MAYBE_CURLY_GRIT_PATTERN, + GRIT_BOGUS, + GRIT_BOGUS_DEFINITION, + GRIT_BOGUS_PATTERN, + GRIT_BOGUS_LITERAL, + GRIT_BOGUS_NAMED_ARG, + GRIT_BOGUS_PREDICATE, + #[doc(hidden)] + __LAST, +} +use self::GritSyntaxKind::*; +impl GritSyntaxKind { + pub const fn is_punct(self) -> bool { + match self { + DOLLAR_DOT3 | DOLLAR_UNDERSCORE | MATCH | SEMICOLON | COMMA | L_PAREN | R_PAREN + | L_CURLY | R_CURLY | L_BRACK | R_BRACK | L_ANGLE | R_ANGLE | PLUS | STAR | SLASH + | PERCENT | DOT | COLON | EQ | EQ2 | FAT_ARROW | BANG | NEQ | MINUS | LTEQ | GTEQ + | PLUSEQ | BACKTICK => true, + _ => false, + } + } + pub const fn is_literal(self) -> bool { + match self { + GRIT_INT_LITERAL + | GRIT_SIGNED_INT_LITERAL + | GRIT_DOUBLE_LITERAL + | GRIT_STRING_LITERAL + | GRIT_REGEX_LITERAL + | GRIT_SNIPPET_REGEX_LITERAL => true, + _ => false, + } + } + pub const fn is_list(self) -> bool { + match self { + GRIT_SEQUENTIAL_LIST + | GRIT_FILES_LIST + | GRIT_DEFINITION_LIST + | GRIT_LANGUAGE_FLAVOR_LIST + | GRIT_PATTERN_LIST + | GRIT_NAMED_ARG_LIST + | GRIT_MAP_ELEMENT_LIST + | GRIT_LIST + | GRIT_LIST_PATTERN_LIST + | GRIT_PATTERN_ARG_LIST + | GRIT_PREDICATE_LIST + | GRIT_CURLY_PREDICATE_LIST + | GRIT_VARIABLE_LIST => true, + _ => false, + } + } + pub fn from_keyword(ident: &str) -> Option { + let kw = match ident { + "sequential" => SEQUENTIAL_KW, + "multifile" => MULTIFILE_KW, + "engine" => ENGINE_KW, + "biome" => BIOME_KW, + "language" => LANGUAGE_KW, + "js" => JS_KW, + "css" => CSS_KW, + "json" => JSON_KW, + "grit" => GRIT_KW, + "html" => HTML_KW, + "typescript" => TYPESCRIPT_KW, + "jsx" => JSX_KW, + "js_do_not_use" => JS_DO_NOT_USE_KW, + "as" => AS_KW, + "limit" => LIMIT_KW, + "where" => WHERE_KW, + "orelse" => ORELSE_KW, + "maybe" => MAYBE_KW, + "after" => AFTER_KW, + "before" => BEFORE_KW, + "contains" => CONTAINS_KW, + "until" => UNTIL_KW, + "includes" => INCLUDES_KW, + "if" => IF_KW, + "else" => ELSE_KW, + "within" => WITHIN_KW, + "bubble" => BUBBLE_KW, + "not" => NOT_KW, + "or" => OR_KW, + "and" => AND_KW, + "any" => ANY_KW, + "some" => SOME_KW, + "every" => EVERY_KW, + "private" => PRIVATE_KW, + "pattern" => PATTERN_KW, + "predicate" => PREDICATE_KW, + "function" => FUNCTION_KW, + "true" => TRUE_KW, + "false" => FALSE_KW, + "undefined" => UNDEFINED_KW, + "like" => LIKE_KW, + "return" => RETURN_KW, + _ => return None, + }; + Some(kw) + } + pub const fn to_string(&self) -> Option<&'static str> { + let tok = match self { + DOLLAR_DOT3 => "$...", + DOLLAR_UNDERSCORE => "$_", + MATCH => "<:", + SEMICOLON => ";", + COMMA => ",", + L_PAREN => "(", + R_PAREN => ")", + L_CURLY => "{", + R_CURLY => "}", + L_BRACK => "[", + R_BRACK => "]", + L_ANGLE => "<", + R_ANGLE => ">", + PLUS => "+", + STAR => "*", + SLASH => "/", + PERCENT => "%", + DOT => ".", + COLON => ":", + EQ => "=", + EQ2 => "==", + FAT_ARROW => "=>", + BANG => "!", + NEQ => "!=", + MINUS => "-", + LTEQ => "<=", + GTEQ => ">=", + PLUSEQ => "+=", + BACKTICK => "`", + SEQUENTIAL_KW => "sequential", + MULTIFILE_KW => "multifile", + ENGINE_KW => "engine", + BIOME_KW => "biome", + LANGUAGE_KW => "language", + JS_KW => "js", + CSS_KW => "css", + JSON_KW => "json", + GRIT_KW => "grit", + HTML_KW => "html", + TYPESCRIPT_KW => "typescript", + JSX_KW => "jsx", + JS_DO_NOT_USE_KW => "js_do_not_use", + AS_KW => "as", + LIMIT_KW => "limit", + WHERE_KW => "where", + ORELSE_KW => "orelse", + MAYBE_KW => "maybe", + AFTER_KW => "after", + BEFORE_KW => "before", + CONTAINS_KW => "contains", + UNTIL_KW => "until", + INCLUDES_KW => "includes", + IF_KW => "if", + ELSE_KW => "else", + WITHIN_KW => "within", + BUBBLE_KW => "bubble", + NOT_KW => "not", + OR_KW => "or", + AND_KW => "and", + ANY_KW => "any", + SOME_KW => "some", + EVERY_KW => "every", + PRIVATE_KW => "private", + PATTERN_KW => "pattern", + PREDICATE_KW => "predicate", + FUNCTION_KW => "function", + TRUE_KW => "true", + FALSE_KW => "false", + UNDEFINED_KW => "undefined", + LIKE_KW => "like", + RETURN_KW => "return", + GRIT_STRING_LITERAL => "string literal", + _ => return None, + }; + Some(tok) + } +} +#[doc = r" Utility macro for creating a SyntaxKind through simple macro syntax"] +#[macro_export] +macro_rules ! T { ["$..."] => { $ crate :: GritSyntaxKind :: DOLLAR_DOT3 } ; ["$_"] => { $ crate :: GritSyntaxKind :: DOLLAR_UNDERSCORE } ; [<:] => { $ crate :: GritSyntaxKind :: MATCH } ; [;] => { $ crate :: GritSyntaxKind :: SEMICOLON } ; [,] => { $ crate :: GritSyntaxKind :: COMMA } ; ['('] => { $ crate :: GritSyntaxKind :: L_PAREN } ; [')'] => { $ crate :: GritSyntaxKind :: R_PAREN } ; ['{'] => { $ crate :: GritSyntaxKind :: L_CURLY } ; ['}'] => { $ crate :: GritSyntaxKind :: R_CURLY } ; ['['] => { $ crate :: GritSyntaxKind :: L_BRACK } ; [']'] => { $ crate :: GritSyntaxKind :: R_BRACK } ; [<] => { $ crate :: GritSyntaxKind :: L_ANGLE } ; [>] => { $ crate :: GritSyntaxKind :: R_ANGLE } ; [+] => { $ crate :: GritSyntaxKind :: PLUS } ; [*] => { $ crate :: GritSyntaxKind :: STAR } ; [/] => { $ crate :: GritSyntaxKind :: SLASH } ; [%] => { $ crate :: GritSyntaxKind :: PERCENT } ; [.] => { $ crate :: GritSyntaxKind :: DOT } ; [:] => { $ crate :: GritSyntaxKind :: COLON } ; [=] => { $ crate :: GritSyntaxKind :: EQ } ; [==] => { $ crate :: GritSyntaxKind :: EQ2 } ; [=>] => { $ crate :: GritSyntaxKind :: FAT_ARROW } ; [!] => { $ crate :: GritSyntaxKind :: BANG } ; [!=] => { $ crate :: GritSyntaxKind :: NEQ } ; [-] => { $ crate :: GritSyntaxKind :: MINUS } ; [<=] => { $ crate :: GritSyntaxKind :: LTEQ } ; [>=] => { $ crate :: GritSyntaxKind :: GTEQ } ; [+=] => { $ crate :: GritSyntaxKind :: PLUSEQ } ; ['`'] => { $ crate :: GritSyntaxKind :: BACKTICK } ; [sequential] => { $ crate :: GritSyntaxKind :: SEQUENTIAL_KW } ; [multifile] => { $ crate :: GritSyntaxKind :: MULTIFILE_KW } ; [engine] => { $ crate :: GritSyntaxKind :: ENGINE_KW } ; [biome] => { $ crate :: GritSyntaxKind :: BIOME_KW } ; [language] => { $ crate :: GritSyntaxKind :: LANGUAGE_KW } ; [js] => { $ crate :: GritSyntaxKind :: JS_KW } ; [css] => { $ crate :: GritSyntaxKind :: CSS_KW } ; [json] => { $ crate :: GritSyntaxKind :: JSON_KW } ; [grit] => { $ crate :: GritSyntaxKind :: GRIT_KW } ; [html] => { $ crate :: GritSyntaxKind :: HTML_KW } ; [typescript] => { $ crate :: GritSyntaxKind :: TYPESCRIPT_KW } ; [jsx] => { $ crate :: GritSyntaxKind :: JSX_KW } ; [js_do_not_use] => { $ crate :: GritSyntaxKind :: JS_DO_NOT_USE_KW } ; [as] => { $ crate :: GritSyntaxKind :: AS_KW } ; [limit] => { $ crate :: GritSyntaxKind :: LIMIT_KW } ; [where] => { $ crate :: GritSyntaxKind :: WHERE_KW } ; [orelse] => { $ crate :: GritSyntaxKind :: ORELSE_KW } ; [maybe] => { $ crate :: GritSyntaxKind :: MAYBE_KW } ; [after] => { $ crate :: GritSyntaxKind :: AFTER_KW } ; [before] => { $ crate :: GritSyntaxKind :: BEFORE_KW } ; [contains] => { $ crate :: GritSyntaxKind :: CONTAINS_KW } ; [until] => { $ crate :: GritSyntaxKind :: UNTIL_KW } ; [includes] => { $ crate :: GritSyntaxKind :: INCLUDES_KW } ; [if] => { $ crate :: GritSyntaxKind :: IF_KW } ; [else] => { $ crate :: GritSyntaxKind :: ELSE_KW } ; [within] => { $ crate :: GritSyntaxKind :: WITHIN_KW } ; [bubble] => { $ crate :: GritSyntaxKind :: BUBBLE_KW } ; [not] => { $ crate :: GritSyntaxKind :: NOT_KW } ; [or] => { $ crate :: GritSyntaxKind :: OR_KW } ; [and] => { $ crate :: GritSyntaxKind :: AND_KW } ; [any] => { $ crate :: GritSyntaxKind :: ANY_KW } ; [some] => { $ crate :: GritSyntaxKind :: SOME_KW } ; [every] => { $ crate :: GritSyntaxKind :: EVERY_KW } ; [private] => { $ crate :: GritSyntaxKind :: PRIVATE_KW } ; [pattern] => { $ crate :: GritSyntaxKind :: PATTERN_KW } ; [predicate] => { $ crate :: GritSyntaxKind :: PREDICATE_KW } ; [function] => { $ crate :: GritSyntaxKind :: FUNCTION_KW } ; [true] => { $ crate :: GritSyntaxKind :: TRUE_KW } ; [false] => { $ crate :: GritSyntaxKind :: FALSE_KW } ; [undefined] => { $ crate :: GritSyntaxKind :: UNDEFINED_KW } ; [like] => { $ crate :: GritSyntaxKind :: LIKE_KW } ; [return] => { $ crate :: GritSyntaxKind :: RETURN_KW } ; [ident] => { $ crate :: GritSyntaxKind :: IDENT } ; [EOF] => { $ crate :: GritSyntaxKind :: EOF } ; [UNICODE_BOM] => { $ crate :: GritSyntaxKind :: UNICODE_BOM } ; [#] => { $ crate :: GritSyntaxKind :: HASH } ; } diff --git a/crates/biome_grit_syntax/src/generated/macros.rs b/crates/biome_grit_syntax/src/generated/macros.rs new file mode 100644 index 00000000000..95578e19a05 --- /dev/null +++ b/crates/biome_grit_syntax/src/generated/macros.rs @@ -0,0 +1,481 @@ +//! Generated file, do not edit by hand, see `xtask/codegen` + +#[doc = r" Reconstruct an AstNode from a SyntaxNode"] +#[doc = r""] +#[doc = r" This macros performs a match over the [kind](biome_rowan::SyntaxNode::kind)"] +#[doc = r" of the provided [biome_rowan::SyntaxNode] and constructs the appropriate"] +#[doc = r" AstNode type for it, then execute the provided expression over it."] +#[doc = r""] +#[doc = r" # Examples"] +#[doc = r""] +#[doc = r" ```ignore"] +#[doc = r" map_syntax_node!(syntax_node, node => node.format())"] +#[doc = r" ```"] +#[macro_export] +macro_rules! map_syntax_node { + ($ node : expr , $ pattern : pat => $ body : expr) => { + match $node { + node => match $crate::GritSyntaxNode::kind(&node) { + $crate::GritSyntaxKind::ANY_GRIT_PATTERN => { + let $pattern = unsafe { $crate::AnyGritPattern::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::ANY_GRIT_PREDICATE => { + let $pattern = unsafe { $crate::AnyGritPredicate::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::CURLY_GRIT_PATTERN => { + let $pattern = unsafe { $crate::CurlyGritPattern::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_ADD_OPERATION => { + let $pattern = unsafe { $crate::GritAddOperation::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_ANNOTATION => { + let $pattern = unsafe { $crate::GritAnnotation::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_ASSIGNMENT_AS_PATTERN => { + let $pattern = unsafe { $crate::GritAssignmentAsPattern::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_BACKTICK_SNIPPET => { + let $pattern = unsafe { $crate::GritBacktickSnippet::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_BOOLEAN_LITERAL => { + let $pattern = unsafe { $crate::GritBooleanLiteral::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_BUBBLE => { + let $pattern = unsafe { $crate::GritBubble::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_BUBBLE_SCOPE => { + let $pattern = unsafe { $crate::GritBubbleScope::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_CODE_SNIPPET => { + let $pattern = unsafe { $crate::GritCodeSnippet::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_CURLY_PREDICATE_LIST => { + let $pattern = unsafe { $crate::GritCurlyPredicateList::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_DIV_OPERATION => { + let $pattern = unsafe { $crate::GritDivOperation::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_DOT => { + let $pattern = unsafe { $crate::GritDot::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_DOTDOTDOT => { + let $pattern = unsafe { $crate::GritDotdotdot::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_DOUBLE_LITERAL => { + let $pattern = unsafe { $crate::GritDoubleLiteral::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_DOUBLE_QUOTE_SNIPPET => { + let $pattern = unsafe { $crate::GritDoubleQuoteSnippet::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_EVERY => { + let $pattern = unsafe { $crate::GritEvery::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_FILES => { + let $pattern = unsafe { $crate::GritFiles::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_FUNCTION_DEFINITION => { + let $pattern = unsafe { $crate::GritFunctionDefinition::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_INT_LITERAL => { + let $pattern = unsafe { $crate::GritIntLiteral::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_LANGUAGE_DECLARATION => { + let $pattern = unsafe { $crate::GritLanguageDeclaration::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_LANGUAGE_FLAVOR => { + let $pattern = unsafe { $crate::GritLanguageFlavor::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_LANGUAGE_FLAVOR_KIND => { + let $pattern = unsafe { $crate::GritLanguageFlavorKind::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_LANGUAGE_NAME => { + let $pattern = unsafe { $crate::GritLanguageName::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_LANGUAGE_SPECIFIC_SNIPPET => { + let $pattern = + unsafe { $crate::GritLanguageSpecificSnippet::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_LIKE => { + let $pattern = unsafe { $crate::GritLike::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_LIKE_THRESHOLD => { + let $pattern = unsafe { $crate::GritLikeThreshold::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_LIST => { + let $pattern = unsafe { $crate::GritList::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_LIST_ACCESSOR => { + let $pattern = unsafe { $crate::GritListAccessor::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_MAP => { + let $pattern = unsafe { $crate::GritMap::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_MAP_ACCESSOR => { + let $pattern = unsafe { $crate::GritMapAccessor::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_MAP_ELEMENT => { + let $pattern = unsafe { $crate::GritMapElement::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_MOD_OPERATION => { + let $pattern = unsafe { $crate::GritModOperation::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_MUL_OPERATION => { + let $pattern = unsafe { $crate::GritMulOperation::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_NAME => { + let $pattern = unsafe { $crate::GritName::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_NAMED_ARG => { + let $pattern = unsafe { $crate::GritNamedArg::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_NAMED_ARG_WITH_DEFAULT => { + let $pattern = unsafe { $crate::GritNamedArgWithDefault::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_NODE_LIKE => { + let $pattern = unsafe { $crate::GritNodeLike::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_NOT => { + let $pattern = unsafe { $crate::GritNot::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PATTERN_ACCUMULATE => { + let $pattern = unsafe { $crate::GritPatternAccumulate::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PATTERN_AFTER => { + let $pattern = unsafe { $crate::GritPatternAfter::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PATTERN_AND => { + let $pattern = unsafe { $crate::GritPatternAnd::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PATTERN_ANY => { + let $pattern = unsafe { $crate::GritPatternAny::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PATTERN_ARG_LIST => { + let $pattern = unsafe { $crate::GritPatternArgList::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PATTERN_AS => { + let $pattern = unsafe { $crate::GritPatternAs::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PATTERN_BEFORE => { + let $pattern = unsafe { $crate::GritPatternBefore::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PATTERN_CONTAINS => { + let $pattern = unsafe { $crate::GritPatternContains::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PATTERN_CONTAINS_UNTIL_CLAUSE => { + let $pattern = + unsafe { $crate::GritPatternContainsUntilClause::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PATTERN_DEFINITION => { + let $pattern = unsafe { $crate::GritPatternDefinition::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PATTERN_DEFINITION_BODY => { + let $pattern = + unsafe { $crate::GritPatternDefinitionBody::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PATTERN_ELSE_CLAUSE => { + let $pattern = unsafe { $crate::GritPatternElseClause::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PATTERN_IF_ELSE => { + let $pattern = unsafe { $crate::GritPatternIfElse::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PATTERN_INCLUDES => { + let $pattern = unsafe { $crate::GritPatternIncludes::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PATTERN_LIMIT => { + let $pattern = unsafe { $crate::GritPatternLimit::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PATTERN_MAYBE => { + let $pattern = unsafe { $crate::GritPatternMaybe::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PATTERN_NOT => { + let $pattern = unsafe { $crate::GritPatternNot::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PATTERN_OR => { + let $pattern = unsafe { $crate::GritPatternOr::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PATTERN_OR_ELSE => { + let $pattern = unsafe { $crate::GritPatternOrElse::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PATTERN_WHERE => { + let $pattern = unsafe { $crate::GritPatternWhere::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PREDICATE_ACCUMULATE => { + let $pattern = unsafe { $crate::GritPredicateAccumulate::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PREDICATE_AND => { + let $pattern = unsafe { $crate::GritPredicateAnd::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PREDICATE_ANY => { + let $pattern = unsafe { $crate::GritPredicateAny::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PREDICATE_ASSIGNMENT => { + let $pattern = unsafe { $crate::GritPredicateAssignment::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PREDICATE_CALL => { + let $pattern = unsafe { $crate::GritPredicateCall::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PREDICATE_DEFINITION => { + let $pattern = unsafe { $crate::GritPredicateDefinition::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PREDICATE_ELSE_CLAUSE => { + let $pattern = unsafe { $crate::GritPredicateElseClause::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PREDICATE_EQUAL => { + let $pattern = unsafe { $crate::GritPredicateEqual::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PREDICATE_GREATER => { + let $pattern = unsafe { $crate::GritPredicateGreater::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PREDICATE_GREATER_EQUAL => { + let $pattern = + unsafe { $crate::GritPredicateGreaterEqual::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PREDICATE_IF_ELSE => { + let $pattern = unsafe { $crate::GritPredicateIfElse::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PREDICATE_LESS => { + let $pattern = unsafe { $crate::GritPredicateLess::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PREDICATE_LESS_EQUAL => { + let $pattern = unsafe { $crate::GritPredicateLessEqual::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PREDICATE_MATCH => { + let $pattern = unsafe { $crate::GritPredicateMatch::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PREDICATE_MAYBE => { + let $pattern = unsafe { $crate::GritPredicateMaybe::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PREDICATE_NOT => { + let $pattern = unsafe { $crate::GritPredicateNot::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PREDICATE_NOT_EQUAL => { + let $pattern = unsafe { $crate::GritPredicateNotEqual::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PREDICATE_OR => { + let $pattern = unsafe { $crate::GritPredicateOr::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PREDICATE_RETURN => { + let $pattern = unsafe { $crate::GritPredicateReturn::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PREDICATE_REWRITE => { + let $pattern = unsafe { $crate::GritPredicateRewrite::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_RAW_BACKTICK_SNIPPET => { + let $pattern = unsafe { $crate::GritRawBacktickSnippet::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_REGEX_LITERAL => { + let $pattern = unsafe { $crate::GritRegexLiteral::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_REGEX_PATTERN => { + let $pattern = unsafe { $crate::GritRegexPattern::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_REGEX_PATTERN_VARIABLES => { + let $pattern = + unsafe { $crate::GritRegexPatternVariables::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_REWRITE => { + let $pattern = unsafe { $crate::GritRewrite::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_ROOT => { + let $pattern = unsafe { $crate::GritRoot::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_SEQUENTIAL => { + let $pattern = unsafe { $crate::GritSequential::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_SIGNED_INT_LITERAL => { + let $pattern = unsafe { $crate::GritSignedIntLiteral::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_SNIPPET_REGEX => { + let $pattern = unsafe { $crate::GritSnippetRegex::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_SOME => { + let $pattern = unsafe { $crate::GritSome::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_STRING_LITERAL => { + let $pattern = unsafe { $crate::GritStringLiteral::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_SUB_OPERATION => { + let $pattern = unsafe { $crate::GritSubOperation::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_UNDEFINED => { + let $pattern = unsafe { $crate::GritUndefined::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_UNDERSCORE => { + let $pattern = unsafe { $crate::GritUnderscore::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_VARIABLE => { + let $pattern = unsafe { $crate::GritVariable::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_VERSION => { + let $pattern = unsafe { $crate::GritVersion::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_WITHIN => { + let $pattern = unsafe { $crate::GritWithin::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_BOGUS => { + let $pattern = unsafe { $crate::GritBogus::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_BOGUS_DEFINITION => { + let $pattern = unsafe { $crate::GritBogusDefinition::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_BOGUS_LITERAL => { + let $pattern = unsafe { $crate::GritBogusLiteral::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_BOGUS_NAMED_ARG => { + let $pattern = unsafe { $crate::GritBogusNamedArg::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_BOGUS_PATTERN => { + let $pattern = unsafe { $crate::GritBogusPattern::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_BOGUS_PREDICATE => { + let $pattern = unsafe { $crate::GritBogusPredicate::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_DEFINITION_LIST => { + let $pattern = unsafe { $crate::GritDefinitionList::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_FILES_LIST => { + let $pattern = unsafe { $crate::GritFilesList::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_LANGUAGE_FLAVOR_LIST => { + let $pattern = unsafe { $crate::GritLanguageFlavorList::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_LIST_PATTERN_LIST => { + let $pattern = unsafe { $crate::GritListPatternList::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_MAP_ELEMENT_LIST => { + let $pattern = unsafe { $crate::GritMapElementList::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_NAMED_ARG_LIST => { + let $pattern = unsafe { $crate::GritNamedArgList::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PATTERN_LIST => { + let $pattern = unsafe { $crate::GritPatternList::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_PREDICATE_LIST => { + let $pattern = unsafe { $crate::GritPredicateList::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_SEQUENTIAL_LIST => { + let $pattern = unsafe { $crate::GritSequentialList::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_VARIABLE_LIST => { + let $pattern = unsafe { $crate::GritVariableList::new_unchecked(node) }; + $body + } + _ => unreachable!(), + }, + } + }; +} +pub(crate) use map_syntax_node; diff --git a/crates/biome_grit_syntax/src/generated/nodes.rs b/crates/biome_grit_syntax/src/generated/nodes.rs new file mode 100644 index 00000000000..40bbbb3fe13 --- /dev/null +++ b/crates/biome_grit_syntax/src/generated/nodes.rs @@ -0,0 +1,12249 @@ +//! Generated file, do not edit by hand, see `xtask/codegen` + +#![allow(clippy::enum_variant_names)] +#![allow(clippy::match_like_matches_macro)] +use crate::{ + macros::map_syntax_node, + GritLanguage as Language, GritSyntaxElement as SyntaxElement, + GritSyntaxElementChildren as SyntaxElementChildren, + GritSyntaxKind::{self as SyntaxKind, *}, + GritSyntaxList as SyntaxList, GritSyntaxNode as SyntaxNode, GritSyntaxToken as SyntaxToken, +}; +use biome_rowan::{support, AstNode, RawSyntaxKind, SyntaxKindSet, SyntaxResult}; +#[allow(unused)] +use biome_rowan::{ + AstNodeList, AstNodeListIterator, AstNodeSlotMap, AstSeparatedList, + AstSeparatedListNodesIterator, +}; +#[cfg(feature = "serde")] +use serde::ser::SerializeSeq; +#[cfg(feature = "serde")] +use serde::{Serialize, Serializer}; +use std::fmt::{Debug, Formatter}; +#[doc = r" Sentinel value indicating a missing element in a dynamic node, where"] +#[doc = r" the slots are not statically known."] +#[allow(dead_code)] +pub(crate) const SLOT_MAP_EMPTY_VALUE: u8 = u8::MAX; +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct AnyGritPattern { + pub(crate) syntax: SyntaxNode, +} +impl AnyGritPattern { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> AnyGritPatternFields { + AnyGritPatternFields { + any_grit_literal: self.any_grit_literal(), + grit_pattern_not: self.grit_pattern_not(), + grit_pattern_or: self.grit_pattern_or(), + grit_pattern_or_else: self.grit_pattern_or_else(), + grit_pattern_any: self.grit_pattern_any(), + grit_pattern_and: self.grit_pattern_and(), + grit_pattern_maybe: self.grit_pattern_maybe(), + grit_pattern_if_else: self.grit_pattern_if_else(), + grit_pattern_contains: self.grit_pattern_contains(), + grit_pattern_includes: self.grit_pattern_includes(), + grit_pattern_after: self.grit_pattern_after(), + grit_pattern_before: self.grit_pattern_before(), + grit_within: self.grit_within(), + grit_bubble: self.grit_bubble(), + grit_node_like: self.grit_node_like(), + grit_map_accessor: self.grit_map_accessor(), + grit_list_accessor: self.grit_list_accessor(), + grit_dot: self.grit_dot(), + grit_some: self.grit_some(), + grit_every: self.grit_every(), + grit_underscore: self.grit_underscore(), + grit_variable: self.grit_variable(), + grit_regex_pattern: self.grit_regex_pattern(), + grit_pattern_as: self.grit_pattern_as(), + grit_pattern_limit: self.grit_pattern_limit(), + grit_assignment_as_pattern: self.grit_assignment_as_pattern(), + grit_pattern_accumulate: self.grit_pattern_accumulate(), + grit_rewrite: self.grit_rewrite(), + grit_like: self.grit_like(), + grit_pattern_where: self.grit_pattern_where(), + grit_mul_operation: self.grit_mul_operation(), + grit_div_operation: self.grit_div_operation(), + grit_mod_operation: self.grit_mod_operation(), + grit_add_operation: self.grit_add_operation(), + grit_sub_operation: self.grit_sub_operation(), + grit_sequential: self.grit_sequential(), + grit_files: self.grit_files(), + l_paren_token: self.l_paren_token(), + any_grit_pattern: self.any_grit_pattern(), + r_paren_token: self.r_paren_token(), + grit_bogus_pattern: self.grit_bogus_pattern(), + } + } + pub fn any_grit_literal(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn grit_pattern_not(&self) -> SyntaxResult { + support::required_node(&self.syntax, 1usize) + } + pub fn grit_pattern_or(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } + pub fn grit_pattern_or_else(&self) -> SyntaxResult { + support::required_node(&self.syntax, 3usize) + } + pub fn grit_pattern_any(&self) -> SyntaxResult { + support::required_node(&self.syntax, 4usize) + } + pub fn grit_pattern_and(&self) -> SyntaxResult { + support::required_node(&self.syntax, 5usize) + } + pub fn grit_pattern_maybe(&self) -> SyntaxResult { + support::required_node(&self.syntax, 6usize) + } + pub fn grit_pattern_if_else(&self) -> SyntaxResult { + support::required_node(&self.syntax, 7usize) + } + pub fn grit_pattern_contains(&self) -> SyntaxResult { + support::required_node(&self.syntax, 8usize) + } + pub fn grit_pattern_includes(&self) -> SyntaxResult { + support::required_node(&self.syntax, 9usize) + } + pub fn grit_pattern_after(&self) -> SyntaxResult { + support::required_node(&self.syntax, 10usize) + } + pub fn grit_pattern_before(&self) -> SyntaxResult { + support::required_node(&self.syntax, 11usize) + } + pub fn grit_within(&self) -> SyntaxResult { + support::required_node(&self.syntax, 12usize) + } + pub fn grit_bubble(&self) -> SyntaxResult { + support::required_node(&self.syntax, 13usize) + } + pub fn grit_node_like(&self) -> SyntaxResult { + support::required_node(&self.syntax, 14usize) + } + pub fn grit_map_accessor(&self) -> SyntaxResult { + support::required_node(&self.syntax, 15usize) + } + pub fn grit_list_accessor(&self) -> SyntaxResult { + support::required_node(&self.syntax, 16usize) + } + pub fn grit_dot(&self) -> SyntaxResult { + support::required_node(&self.syntax, 17usize) + } + pub fn grit_some(&self) -> SyntaxResult { + support::required_node(&self.syntax, 18usize) + } + pub fn grit_every(&self) -> SyntaxResult { + support::required_node(&self.syntax, 19usize) + } + pub fn grit_underscore(&self) -> SyntaxResult { + support::required_node(&self.syntax, 20usize) + } + pub fn grit_variable(&self) -> SyntaxResult { + support::required_node(&self.syntax, 21usize) + } + pub fn grit_regex_pattern(&self) -> SyntaxResult { + support::required_node(&self.syntax, 22usize) + } + pub fn grit_pattern_as(&self) -> SyntaxResult { + support::required_node(&self.syntax, 23usize) + } + pub fn grit_pattern_limit(&self) -> SyntaxResult { + support::required_node(&self.syntax, 24usize) + } + pub fn grit_assignment_as_pattern(&self) -> SyntaxResult { + support::required_node(&self.syntax, 25usize) + } + pub fn grit_pattern_accumulate(&self) -> SyntaxResult { + support::required_node(&self.syntax, 26usize) + } + pub fn grit_rewrite(&self) -> SyntaxResult { + support::required_node(&self.syntax, 27usize) + } + pub fn grit_like(&self) -> SyntaxResult { + support::required_node(&self.syntax, 28usize) + } + pub fn grit_pattern_where(&self) -> SyntaxResult { + support::required_node(&self.syntax, 29usize) + } + pub fn grit_mul_operation(&self) -> SyntaxResult { + support::required_node(&self.syntax, 30usize) + } + pub fn grit_div_operation(&self) -> SyntaxResult { + support::required_node(&self.syntax, 31usize) + } + pub fn grit_mod_operation(&self) -> SyntaxResult { + support::required_node(&self.syntax, 32usize) + } + pub fn grit_add_operation(&self) -> SyntaxResult { + support::required_node(&self.syntax, 33usize) + } + pub fn grit_sub_operation(&self) -> SyntaxResult { + support::required_node(&self.syntax, 34usize) + } + pub fn grit_sequential(&self) -> SyntaxResult { + support::required_node(&self.syntax, 35usize) + } + pub fn grit_files(&self) -> SyntaxResult { + support::required_node(&self.syntax, 36usize) + } + pub fn l_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 37usize) + } + pub fn any_grit_pattern(&self) -> SyntaxResult { + support::required_node(&self.syntax, 38usize) + } + pub fn r_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 39usize) + } + pub fn grit_bogus_pattern(&self) -> SyntaxResult { + support::required_node(&self.syntax, 40usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for AnyGritPattern { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct AnyGritPatternFields { + pub any_grit_literal: SyntaxResult, + pub grit_pattern_not: SyntaxResult, + pub grit_pattern_or: SyntaxResult, + pub grit_pattern_or_else: SyntaxResult, + pub grit_pattern_any: SyntaxResult, + pub grit_pattern_and: SyntaxResult, + pub grit_pattern_maybe: SyntaxResult, + pub grit_pattern_if_else: SyntaxResult, + pub grit_pattern_contains: SyntaxResult, + pub grit_pattern_includes: SyntaxResult, + pub grit_pattern_after: SyntaxResult, + pub grit_pattern_before: SyntaxResult, + pub grit_within: SyntaxResult, + pub grit_bubble: SyntaxResult, + pub grit_node_like: SyntaxResult, + pub grit_map_accessor: SyntaxResult, + pub grit_list_accessor: SyntaxResult, + pub grit_dot: SyntaxResult, + pub grit_some: SyntaxResult, + pub grit_every: SyntaxResult, + pub grit_underscore: SyntaxResult, + pub grit_variable: SyntaxResult, + pub grit_regex_pattern: SyntaxResult, + pub grit_pattern_as: SyntaxResult, + pub grit_pattern_limit: SyntaxResult, + pub grit_assignment_as_pattern: SyntaxResult, + pub grit_pattern_accumulate: SyntaxResult, + pub grit_rewrite: SyntaxResult, + pub grit_like: SyntaxResult, + pub grit_pattern_where: SyntaxResult, + pub grit_mul_operation: SyntaxResult, + pub grit_div_operation: SyntaxResult, + pub grit_mod_operation: SyntaxResult, + pub grit_add_operation: SyntaxResult, + pub grit_sub_operation: SyntaxResult, + pub grit_sequential: SyntaxResult, + pub grit_files: SyntaxResult, + pub l_paren_token: SyntaxResult, + pub any_grit_pattern: SyntaxResult, + pub r_paren_token: SyntaxResult, + pub grit_bogus_pattern: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct AnyGritPredicate { + pub(crate) syntax: SyntaxNode, +} +impl AnyGritPredicate { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> AnyGritPredicateFields { + AnyGritPredicateFields { + grit_predicate_not: self.grit_predicate_not(), + grit_predicate_maybe: self.grit_predicate_maybe(), + grit_predicate_and: self.grit_predicate_and(), + grit_predicate_or: self.grit_predicate_or(), + grit_predicate_any: self.grit_predicate_any(), + grit_predicate_if_else: self.grit_predicate_if_else(), + grit_predicate_assignment: self.grit_predicate_assignment(), + grit_predicate_accumulate: self.grit_predicate_accumulate(), + grit_predicate_rewrite: self.grit_predicate_rewrite(), + grit_predicate_greater: self.grit_predicate_greater(), + grit_predicate_less: self.grit_predicate_less(), + grit_predicate_greater_equal: self.grit_predicate_greater_equal(), + grit_predicate_less_equal: self.grit_predicate_less_equal(), + grit_predicate_not_equal: self.grit_predicate_not_equal(), + grit_predicate_equal: self.grit_predicate_equal(), + grit_predicate_match: self.grit_predicate_match(), + grit_predicate_call: self.grit_predicate_call(), + l_paren_token: self.l_paren_token(), + any_grit_predicate: self.any_grit_predicate(), + r_paren_token: self.r_paren_token(), + grit_boolean_literal: self.grit_boolean_literal(), + grit_predicate_return: self.grit_predicate_return(), + grit_bogus_predicate: self.grit_bogus_predicate(), + } + } + pub fn grit_predicate_not(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn grit_predicate_maybe(&self) -> SyntaxResult { + support::required_node(&self.syntax, 1usize) + } + pub fn grit_predicate_and(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } + pub fn grit_predicate_or(&self) -> SyntaxResult { + support::required_node(&self.syntax, 3usize) + } + pub fn grit_predicate_any(&self) -> SyntaxResult { + support::required_node(&self.syntax, 4usize) + } + pub fn grit_predicate_if_else(&self) -> SyntaxResult { + support::required_node(&self.syntax, 5usize) + } + pub fn grit_predicate_assignment(&self) -> SyntaxResult { + support::required_node(&self.syntax, 6usize) + } + pub fn grit_predicate_accumulate(&self) -> SyntaxResult { + support::required_node(&self.syntax, 7usize) + } + pub fn grit_predicate_rewrite(&self) -> SyntaxResult { + support::required_node(&self.syntax, 8usize) + } + pub fn grit_predicate_greater(&self) -> SyntaxResult { + support::required_node(&self.syntax, 9usize) + } + pub fn grit_predicate_less(&self) -> SyntaxResult { + support::required_node(&self.syntax, 10usize) + } + pub fn grit_predicate_greater_equal(&self) -> SyntaxResult { + support::required_node(&self.syntax, 11usize) + } + pub fn grit_predicate_less_equal(&self) -> SyntaxResult { + support::required_node(&self.syntax, 12usize) + } + pub fn grit_predicate_not_equal(&self) -> SyntaxResult { + support::required_node(&self.syntax, 13usize) + } + pub fn grit_predicate_equal(&self) -> SyntaxResult { + support::required_node(&self.syntax, 14usize) + } + pub fn grit_predicate_match(&self) -> SyntaxResult { + support::required_node(&self.syntax, 15usize) + } + pub fn grit_predicate_call(&self) -> SyntaxResult { + support::required_node(&self.syntax, 16usize) + } + pub fn l_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 17usize) + } + pub fn any_grit_predicate(&self) -> SyntaxResult { + support::required_node(&self.syntax, 18usize) + } + pub fn r_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 19usize) + } + pub fn grit_boolean_literal(&self) -> SyntaxResult { + support::required_node(&self.syntax, 20usize) + } + pub fn grit_predicate_return(&self) -> SyntaxResult { + support::required_node(&self.syntax, 21usize) + } + pub fn grit_bogus_predicate(&self) -> SyntaxResult { + support::required_node(&self.syntax, 22usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for AnyGritPredicate { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct AnyGritPredicateFields { + pub grit_predicate_not: SyntaxResult, + pub grit_predicate_maybe: SyntaxResult, + pub grit_predicate_and: SyntaxResult, + pub grit_predicate_or: SyntaxResult, + pub grit_predicate_any: SyntaxResult, + pub grit_predicate_if_else: SyntaxResult, + pub grit_predicate_assignment: SyntaxResult, + pub grit_predicate_accumulate: SyntaxResult, + pub grit_predicate_rewrite: SyntaxResult, + pub grit_predicate_greater: SyntaxResult, + pub grit_predicate_less: SyntaxResult, + pub grit_predicate_greater_equal: SyntaxResult, + pub grit_predicate_less_equal: SyntaxResult, + pub grit_predicate_not_equal: SyntaxResult, + pub grit_predicate_equal: SyntaxResult, + pub grit_predicate_match: SyntaxResult, + pub grit_predicate_call: SyntaxResult, + pub l_paren_token: SyntaxResult, + pub any_grit_predicate: SyntaxResult, + pub r_paren_token: SyntaxResult, + pub grit_boolean_literal: SyntaxResult, + pub grit_predicate_return: SyntaxResult, + pub grit_bogus_predicate: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct CurlyGritPattern { + pub(crate) syntax: SyntaxNode, +} +impl CurlyGritPattern { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> CurlyGritPatternFields { + CurlyGritPatternFields { + l_curly_token: self.l_curly_token(), + any_grit_pattern: self.any_grit_pattern(), + r_curly_token: self.r_curly_token(), + } + } + pub fn l_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn any_grit_pattern(&self) -> SyntaxResult { + support::required_node(&self.syntax, 1usize) + } + pub fn r_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for CurlyGritPattern { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct CurlyGritPatternFields { + pub l_curly_token: SyntaxResult, + pub any_grit_pattern: SyntaxResult, + pub r_curly_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritAddOperation { + pub(crate) syntax: SyntaxNode, +} +impl GritAddOperation { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritAddOperationFields { + GritAddOperationFields { + left: self.left(), + plus_token: self.plus_token(), + right: self.right(), + } + } + pub fn left(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn plus_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn right(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritAddOperation { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritAddOperationFields { + pub left: SyntaxResult, + pub plus_token: SyntaxResult, + pub right: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritAnnotation { + pub(crate) syntax: SyntaxNode, +} +impl GritAnnotation { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritAnnotationFields { + GritAnnotationFields { + grit_annotation_token: self.grit_annotation_token(), + } + } + pub fn grit_annotation_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritAnnotation { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritAnnotationFields { + pub grit_annotation_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritAssignmentAsPattern { + pub(crate) syntax: SyntaxNode, +} +impl GritAssignmentAsPattern { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritAssignmentAsPatternFields { + GritAssignmentAsPatternFields { + container: self.container(), + eq_token: self.eq_token(), + pattern: self.pattern(), + } + } + pub fn container(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn eq_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn pattern(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritAssignmentAsPattern { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritAssignmentAsPatternFields { + pub container: SyntaxResult, + pub eq_token: SyntaxResult, + pub pattern: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritBacktickSnippet { + pub(crate) syntax: SyntaxNode, +} +impl GritBacktickSnippet { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritBacktickSnippetFields { + GritBacktickSnippetFields { + value_token: self.value_token(), + } + } + pub fn value_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritBacktickSnippet { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritBacktickSnippetFields { + pub value_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritBooleanLiteral { + pub(crate) syntax: SyntaxNode, +} +impl GritBooleanLiteral { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritBooleanLiteralFields { + GritBooleanLiteralFields { + true_token: self.true_token(), + false_token: self.false_token(), + } + } + pub fn true_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn false_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritBooleanLiteral { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritBooleanLiteralFields { + pub true_token: SyntaxResult, + pub false_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritBubble { + pub(crate) syntax: SyntaxNode, +} +impl GritBubble { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritBubbleFields { + GritBubbleFields { + bubble_token: self.bubble_token(), + variables: self.variables(), + pattern: self.pattern(), + } + } + pub fn bubble_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn variables(&self) -> Option { + support::node(&self.syntax, 1usize) + } + pub fn pattern(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritBubble { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritBubbleFields { + pub bubble_token: SyntaxResult, + pub variables: Option, + pub pattern: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritBubbleScope { + pub(crate) syntax: SyntaxNode, +} +impl GritBubbleScope { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritBubbleScopeFields { + GritBubbleScopeFields { + l_paren_token: self.l_paren_token(), + grit_variable_list: self.grit_variable_list(), + r_paren_token: self.r_paren_token(), + } + } + pub fn l_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn grit_variable_list(&self) -> GritVariableList { + support::list(&self.syntax, 1usize) + } + pub fn r_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritBubbleScope { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritBubbleScopeFields { + pub l_paren_token: SyntaxResult, + pub grit_variable_list: GritVariableList, + pub r_paren_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritCodeSnippet { + pub(crate) syntax: SyntaxNode, +} +impl GritCodeSnippet { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritCodeSnippetFields { + GritCodeSnippetFields { + source: self.source(), + } + } + pub fn source(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritCodeSnippet { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritCodeSnippetFields { + pub source: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritCurlyPredicateList { + pub(crate) syntax: SyntaxNode, +} +impl GritCurlyPredicateList { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritCurlyPredicateListFields { + GritCurlyPredicateListFields { + l_curly_token: self.l_curly_token(), + predicates: self.predicates(), + r_curly_token: self.r_curly_token(), + } + } + pub fn l_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn predicates(&self) -> GritPredicateList { + support::list(&self.syntax, 1usize) + } + pub fn r_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritCurlyPredicateList { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritCurlyPredicateListFields { + pub l_curly_token: SyntaxResult, + pub predicates: GritPredicateList, + pub r_curly_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritDivOperation { + pub(crate) syntax: SyntaxNode, +} +impl GritDivOperation { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritDivOperationFields { + GritDivOperationFields { + left: self.left(), + slash_token: self.slash_token(), + right: self.right(), + } + } + pub fn left(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn slash_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn right(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritDivOperation { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritDivOperationFields { + pub left: SyntaxResult, + pub slash_token: SyntaxResult, + pub right: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritDot { + pub(crate) syntax: SyntaxNode, +} +impl GritDot { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritDotFields { + GritDotFields { + dot_token: self.dot_token(), + } + } + pub fn dot_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritDot { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritDotFields { + pub dot_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritDotdotdot { + pub(crate) syntax: SyntaxNode, +} +impl GritDotdotdot { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritDotdotdotFields { + GritDotdotdotFields { + dollar_dotdotdot_token: self.dollar_dotdotdot_token(), + maybe_curly_grit_pattern: self.maybe_curly_grit_pattern(), + } + } + pub fn dollar_dotdotdot_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn maybe_curly_grit_pattern(&self) -> Option { + support::node(&self.syntax, 1usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritDotdotdot { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritDotdotdotFields { + pub dollar_dotdotdot_token: SyntaxResult, + pub maybe_curly_grit_pattern: Option, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritDoubleLiteral { + pub(crate) syntax: SyntaxNode, +} +impl GritDoubleLiteral { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritDoubleLiteralFields { + GritDoubleLiteralFields { + value_token: self.value_token(), + } + } + pub fn value_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritDoubleLiteral { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritDoubleLiteralFields { + pub value_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritDoubleQuoteSnippet { + pub(crate) syntax: SyntaxNode, +} +impl GritDoubleQuoteSnippet { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritDoubleQuoteSnippetFields { + GritDoubleQuoteSnippetFields { + value_token: self.value_token(), + } + } + pub fn value_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritDoubleQuoteSnippet { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritDoubleQuoteSnippetFields { + pub value_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritEvery { + pub(crate) syntax: SyntaxNode, +} +impl GritEvery { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritEveryFields { + GritEveryFields { + every_token: self.every_token(), + pattern: self.pattern(), + } + } + pub fn every_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn pattern(&self) -> SyntaxResult { + support::required_node(&self.syntax, 1usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritEvery { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritEveryFields { + pub every_token: SyntaxResult, + pub pattern: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritFiles { + pub(crate) syntax: SyntaxNode, +} +impl GritFiles { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritFilesFields { + GritFilesFields { + multifile_token: self.multifile_token(), + l_curly_token: self.l_curly_token(), + files: self.files(), + r_curly_token: self.r_curly_token(), + } + } + pub fn multifile_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn l_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn files(&self) -> GritFilesList { + support::list(&self.syntax, 2usize) + } + pub fn r_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 3usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritFiles { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritFilesFields { + pub multifile_token: SyntaxResult, + pub l_curly_token: SyntaxResult, + pub files: GritFilesList, + pub r_curly_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritFunctionDefinition { + pub(crate) syntax: SyntaxNode, +} +impl GritFunctionDefinition { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritFunctionDefinitionFields { + GritFunctionDefinitionFields { + function_token: self.function_token(), + name: self.name(), + l_paren_token: self.l_paren_token(), + args: self.args(), + r_paren_token: self.r_paren_token(), + body: self.body(), + } + } + pub fn function_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn name(&self) -> SyntaxResult { + support::required_node(&self.syntax, 1usize) + } + pub fn l_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 2usize) + } + pub fn args(&self) -> GritVariableList { + support::list(&self.syntax, 3usize) + } + pub fn r_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 4usize) + } + pub fn body(&self) -> SyntaxResult { + support::required_node(&self.syntax, 5usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritFunctionDefinition { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritFunctionDefinitionFields { + pub function_token: SyntaxResult, + pub name: SyntaxResult, + pub l_paren_token: SyntaxResult, + pub args: GritVariableList, + pub r_paren_token: SyntaxResult, + pub body: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritIntLiteral { + pub(crate) syntax: SyntaxNode, +} +impl GritIntLiteral { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritIntLiteralFields { + GritIntLiteralFields { + value_token: self.value_token(), + } + } + pub fn value_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritIntLiteral { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritIntLiteralFields { + pub value_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritLanguageDeclaration { + pub(crate) syntax: SyntaxNode, +} +impl GritLanguageDeclaration { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritLanguageDeclarationFields { + GritLanguageDeclarationFields { + language_token: self.language_token(), + name: self.name(), + flavor: self.flavor(), + } + } + pub fn language_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn name(&self) -> SyntaxResult { + support::required_node(&self.syntax, 1usize) + } + pub fn flavor(&self) -> Option { + support::node(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritLanguageDeclaration { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritLanguageDeclarationFields { + pub language_token: SyntaxResult, + pub name: SyntaxResult, + pub flavor: Option, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritLanguageFlavor { + pub(crate) syntax: SyntaxNode, +} +impl GritLanguageFlavor { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritLanguageFlavorFields { + GritLanguageFlavorFields { + l_paren_token: self.l_paren_token(), + grit_language_flavor_list: self.grit_language_flavor_list(), + r_paren_token: self.r_paren_token(), + semicolon_token: self.semicolon_token(), + } + } + pub fn l_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn grit_language_flavor_list(&self) -> GritLanguageFlavorList { + support::list(&self.syntax, 1usize) + } + pub fn r_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 2usize) + } + pub fn semicolon_token(&self) -> Option { + support::token(&self.syntax, 3usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritLanguageFlavor { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritLanguageFlavorFields { + pub l_paren_token: SyntaxResult, + pub grit_language_flavor_list: GritLanguageFlavorList, + pub r_paren_token: SyntaxResult, + pub semicolon_token: Option, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritLanguageFlavorKind { + pub(crate) syntax: SyntaxNode, +} +impl GritLanguageFlavorKind { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritLanguageFlavorKindFields { + GritLanguageFlavorKindFields { + flavor_kind: self.flavor_kind(), + } + } + pub fn flavor_kind(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritLanguageFlavorKind { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritLanguageFlavorKindFields { + pub flavor_kind: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritLanguageName { + pub(crate) syntax: SyntaxNode, +} +impl GritLanguageName { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritLanguageNameFields { + GritLanguageNameFields { + js_token: self.js_token(), + css_token: self.css_token(), + json_token: self.json_token(), + grit_token: self.grit_token(), + html_token: self.html_token(), + } + } + pub fn js_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn css_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn json_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 2usize) + } + pub fn grit_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 3usize) + } + pub fn html_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 4usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritLanguageName { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritLanguageNameFields { + pub js_token: SyntaxResult, + pub css_token: SyntaxResult, + pub json_token: SyntaxResult, + pub grit_token: SyntaxResult, + pub html_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritLanguageSpecificSnippet { + pub(crate) syntax: SyntaxNode, +} +impl GritLanguageSpecificSnippet { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritLanguageSpecificSnippetFields { + GritLanguageSpecificSnippetFields { + language: self.language(), + snippet: self.snippet(), + } + } + pub fn language(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn snippet(&self) -> SyntaxResult { + support::required_node(&self.syntax, 1usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritLanguageSpecificSnippet { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritLanguageSpecificSnippetFields { + pub language: SyntaxResult, + pub snippet: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritLike { + pub(crate) syntax: SyntaxNode, +} +impl GritLike { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritLikeFields { + GritLikeFields { + like_token: self.like_token(), + grit_like_threshold: self.grit_like_threshold(), + l_curly_token: self.l_curly_token(), + example: self.example(), + r_curly_token: self.r_curly_token(), + } + } + pub fn like_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn grit_like_threshold(&self) -> Option { + support::node(&self.syntax, 1usize) + } + pub fn l_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 2usize) + } + pub fn example(&self) -> SyntaxResult { + support::required_node(&self.syntax, 3usize) + } + pub fn r_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 4usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritLike { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritLikeFields { + pub like_token: SyntaxResult, + pub grit_like_threshold: Option, + pub l_curly_token: SyntaxResult, + pub example: SyntaxResult, + pub r_curly_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritLikeThreshold { + pub(crate) syntax: SyntaxNode, +} +impl GritLikeThreshold { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritLikeThresholdFields { + GritLikeThresholdFields { + l_paren_token: self.l_paren_token(), + threshold: self.threshold(), + r_paren_token: self.r_paren_token(), + } + } + pub fn l_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn threshold(&self) -> SyntaxResult { + support::required_node(&self.syntax, 1usize) + } + pub fn r_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritLikeThreshold { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritLikeThresholdFields { + pub l_paren_token: SyntaxResult, + pub threshold: SyntaxResult, + pub r_paren_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritList { + pub(crate) syntax: SyntaxNode, +} +impl GritList { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritListFields { + GritListFields { + grit_name: self.grit_name(), + l_brack_token: self.l_brack_token(), + patterns: self.patterns(), + r_brack_token: self.r_brack_token(), + } + } + pub fn grit_name(&self) -> Option { + support::node(&self.syntax, 0usize) + } + pub fn l_brack_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn patterns(&self) -> GritListPatternList { + support::list(&self.syntax, 2usize) + } + pub fn r_brack_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 3usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritList { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritListFields { + pub grit_name: Option, + pub l_brack_token: SyntaxResult, + pub patterns: GritListPatternList, + pub r_brack_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritListAccessor { + pub(crate) syntax: SyntaxNode, +} +impl GritListAccessor { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritListAccessorFields { + GritListAccessorFields { + list: self.list(), + l_brack_token: self.l_brack_token(), + index: self.index(), + r_brack_token: self.r_brack_token(), + } + } + pub fn list(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn l_brack_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn index(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } + pub fn r_brack_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 3usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritListAccessor { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritListAccessorFields { + pub list: SyntaxResult, + pub l_brack_token: SyntaxResult, + pub index: SyntaxResult, + pub r_brack_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritMap { + pub(crate) syntax: SyntaxNode, +} +impl GritMap { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritMapFields { + GritMapFields { + l_curly_token: self.l_curly_token(), + elements: self.elements(), + r_curly_token: self.r_curly_token(), + } + } + pub fn l_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn elements(&self) -> GritMapElementList { + support::list(&self.syntax, 1usize) + } + pub fn r_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritMap { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritMapFields { + pub l_curly_token: SyntaxResult, + pub elements: GritMapElementList, + pub r_curly_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritMapAccessor { + pub(crate) syntax: SyntaxNode, +} +impl GritMapAccessor { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritMapAccessorFields { + GritMapAccessorFields { + map: self.map(), + dot_token: self.dot_token(), + key: self.key(), + } + } + pub fn map(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn dot_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn key(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritMapAccessor { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritMapAccessorFields { + pub map: SyntaxResult, + pub dot_token: SyntaxResult, + pub key: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritMapElement { + pub(crate) syntax: SyntaxNode, +} +impl GritMapElement { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritMapElementFields { + GritMapElementFields { + key: self.key(), + colon_token: self.colon_token(), + value: self.value(), + } + } + pub fn key(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn colon_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn value(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritMapElement { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritMapElementFields { + pub key: SyntaxResult, + pub colon_token: SyntaxResult, + pub value: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritModOperation { + pub(crate) syntax: SyntaxNode, +} +impl GritModOperation { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritModOperationFields { + GritModOperationFields { + left: self.left(), + remainder_token: self.remainder_token(), + right: self.right(), + } + } + pub fn left(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn remainder_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn right(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritModOperation { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritModOperationFields { + pub left: SyntaxResult, + pub remainder_token: SyntaxResult, + pub right: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritMulOperation { + pub(crate) syntax: SyntaxNode, +} +impl GritMulOperation { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritMulOperationFields { + GritMulOperationFields { + left: self.left(), + star_token: self.star_token(), + right: self.right(), + } + } + pub fn left(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn star_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn right(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritMulOperation { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritMulOperationFields { + pub left: SyntaxResult, + pub star_token: SyntaxResult, + pub right: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritName { + pub(crate) syntax: SyntaxNode, +} +impl GritName { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritNameFields { + GritNameFields { + grit_name_token: self.grit_name_token(), + } + } + pub fn grit_name_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritName { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritNameFields { + pub grit_name_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritNamedArg { + pub(crate) syntax: SyntaxNode, +} +impl GritNamedArg { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritNamedArgFields { + GritNamedArgFields { name: self.name() } + } + pub fn name(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritNamedArg { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritNamedArgFields { + pub name: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritNamedArgWithDefault { + pub(crate) syntax: SyntaxNode, +} +impl GritNamedArgWithDefault { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritNamedArgWithDefaultFields { + GritNamedArgWithDefaultFields { + name: self.name(), + eq_token: self.eq_token(), + pattern: self.pattern(), + } + } + pub fn name(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn eq_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn pattern(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritNamedArgWithDefault { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritNamedArgWithDefaultFields { + pub name: SyntaxResult, + pub eq_token: SyntaxResult, + pub pattern: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritNodeLike { + pub(crate) syntax: SyntaxNode, +} +impl GritNodeLike { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritNodeLikeFields { + GritNodeLikeFields { + name: self.name(), + l_paren_token: self.l_paren_token(), + named_args: self.named_args(), + r_paren_token: self.r_paren_token(), + } + } + pub fn name(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn l_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn named_args(&self) -> GritNamedArgList { + support::list(&self.syntax, 2usize) + } + pub fn r_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 3usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritNodeLike { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritNodeLikeFields { + pub name: SyntaxResult, + pub l_paren_token: SyntaxResult, + pub named_args: GritNamedArgList, + pub r_paren_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritNot { + pub(crate) syntax: SyntaxNode, +} +impl GritNot { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritNotFields { + GritNotFields { + not_token: self.not_token(), + excl_token: self.excl_token(), + } + } + pub fn not_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn excl_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritNot { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritNotFields { + pub not_token: SyntaxResult, + pub excl_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPatternAccumulate { + pub(crate) syntax: SyntaxNode, +} +impl GritPatternAccumulate { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPatternAccumulateFields { + GritPatternAccumulateFields { + left: self.left(), + add_assign_token: self.add_assign_token(), + right: self.right(), + } + } + pub fn left(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn add_assign_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn right(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPatternAccumulate { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPatternAccumulateFields { + pub left: SyntaxResult, + pub add_assign_token: SyntaxResult, + pub right: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPatternAfter { + pub(crate) syntax: SyntaxNode, +} +impl GritPatternAfter { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPatternAfterFields { + GritPatternAfterFields { + after_token: self.after_token(), + pattern: self.pattern(), + } + } + pub fn after_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn pattern(&self) -> SyntaxResult { + support::required_node(&self.syntax, 1usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPatternAfter { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPatternAfterFields { + pub after_token: SyntaxResult, + pub pattern: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPatternAnd { + pub(crate) syntax: SyntaxNode, +} +impl GritPatternAnd { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPatternAndFields { + GritPatternAndFields { + and_token: self.and_token(), + l_curly_token: self.l_curly_token(), + patterns: self.patterns(), + r_curly_token: self.r_curly_token(), + } + } + pub fn and_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn l_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn patterns(&self) -> GritPatternList { + support::list(&self.syntax, 2usize) + } + pub fn r_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 3usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPatternAnd { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPatternAndFields { + pub and_token: SyntaxResult, + pub l_curly_token: SyntaxResult, + pub patterns: GritPatternList, + pub r_curly_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPatternAny { + pub(crate) syntax: SyntaxNode, +} +impl GritPatternAny { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPatternAnyFields { + GritPatternAnyFields { + any_token: self.any_token(), + l_curly_token: self.l_curly_token(), + patterns: self.patterns(), + r_curly_token: self.r_curly_token(), + } + } + pub fn any_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn l_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn patterns(&self) -> GritPatternList { + support::list(&self.syntax, 2usize) + } + pub fn r_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 3usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPatternAny { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPatternAnyFields { + pub any_token: SyntaxResult, + pub l_curly_token: SyntaxResult, + pub patterns: GritPatternList, + pub r_curly_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPatternArgList { + pub(crate) syntax: SyntaxNode, +} +impl GritPatternArgList { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPatternArgListFields { + GritPatternArgListFields { + grit_variable_list: self.grit_variable_list(), + } + } + pub fn grit_variable_list(&self) -> GritVariableList { + support::list(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPatternArgList { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPatternArgListFields { + pub grit_variable_list: GritVariableList, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPatternAs { + pub(crate) syntax: SyntaxNode, +} +impl GritPatternAs { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPatternAsFields { + GritPatternAsFields { + pattern: self.pattern(), + as_token: self.as_token(), + variable: self.variable(), + } + } + pub fn pattern(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn as_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn variable(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPatternAs { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPatternAsFields { + pub pattern: SyntaxResult, + pub as_token: SyntaxResult, + pub variable: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPatternBefore { + pub(crate) syntax: SyntaxNode, +} +impl GritPatternBefore { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPatternBeforeFields { + GritPatternBeforeFields { + before_token: self.before_token(), + pattern: self.pattern(), + } + } + pub fn before_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn pattern(&self) -> SyntaxResult { + support::required_node(&self.syntax, 1usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPatternBefore { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPatternBeforeFields { + pub before_token: SyntaxResult, + pub pattern: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPatternContains { + pub(crate) syntax: SyntaxNode, +} +impl GritPatternContains { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPatternContainsFields { + GritPatternContainsFields { + contains_token: self.contains_token(), + contains: self.contains(), + grit_pattern_contains_until_clause: self.grit_pattern_contains_until_clause(), + } + } + pub fn contains_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn contains(&self) -> SyntaxResult { + support::required_node(&self.syntax, 1usize) + } + pub fn grit_pattern_contains_until_clause(&self) -> Option { + support::node(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPatternContains { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPatternContainsFields { + pub contains_token: SyntaxResult, + pub contains: SyntaxResult, + pub grit_pattern_contains_until_clause: Option, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPatternContainsUntilClause { + pub(crate) syntax: SyntaxNode, +} +impl GritPatternContainsUntilClause { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPatternContainsUntilClauseFields { + GritPatternContainsUntilClauseFields { + until_token: self.until_token(), + until: self.until(), + } + } + pub fn until_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn until(&self) -> SyntaxResult { + support::required_node(&self.syntax, 1usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPatternContainsUntilClause { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPatternContainsUntilClauseFields { + pub until_token: SyntaxResult, + pub until: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPatternDefinition { + pub(crate) syntax: SyntaxNode, +} +impl GritPatternDefinition { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPatternDefinitionFields { + GritPatternDefinitionFields { + visibility_token: self.visibility_token(), + pattern_token: self.pattern_token(), + name: self.name(), + l_paren_token: self.l_paren_token(), + args: self.args(), + r_paren_token: self.r_paren_token(), + language: self.language(), + body: self.body(), + } + } + pub fn visibility_token(&self) -> Option { + support::token(&self.syntax, 0usize) + } + pub fn pattern_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn name(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } + pub fn l_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 3usize) + } + pub fn args(&self) -> Option { + support::node(&self.syntax, 4usize) + } + pub fn r_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 5usize) + } + pub fn language(&self) -> Option { + support::node(&self.syntax, 6usize) + } + pub fn body(&self) -> SyntaxResult { + support::required_node(&self.syntax, 7usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPatternDefinition { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPatternDefinitionFields { + pub visibility_token: Option, + pub pattern_token: SyntaxResult, + pub name: SyntaxResult, + pub l_paren_token: SyntaxResult, + pub args: Option, + pub r_paren_token: SyntaxResult, + pub language: Option, + pub body: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPatternDefinitionBody { + pub(crate) syntax: SyntaxNode, +} +impl GritPatternDefinitionBody { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPatternDefinitionBodyFields { + GritPatternDefinitionBodyFields { + l_curly_token: self.l_curly_token(), + patterns: self.patterns(), + r_curly_token: self.r_curly_token(), + } + } + pub fn l_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn patterns(&self) -> GritPatternList { + support::list(&self.syntax, 1usize) + } + pub fn r_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPatternDefinitionBody { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPatternDefinitionBodyFields { + pub l_curly_token: SyntaxResult, + pub patterns: GritPatternList, + pub r_curly_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPatternElseClause { + pub(crate) syntax: SyntaxNode, +} +impl GritPatternElseClause { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPatternElseClauseFields { + GritPatternElseClauseFields { + else_token: self.else_token(), + else_pattern: self.else_pattern(), + } + } + pub fn else_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn else_pattern(&self) -> SyntaxResult { + support::required_node(&self.syntax, 1usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPatternElseClause { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPatternElseClauseFields { + pub else_token: SyntaxResult, + pub else_pattern: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPatternIfElse { + pub(crate) syntax: SyntaxNode, +} +impl GritPatternIfElse { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPatternIfElseFields { + GritPatternIfElseFields { + if_token: self.if_token(), + l_paren_token: self.l_paren_token(), + if_predicate: self.if_predicate(), + r_paren_token: self.r_paren_token(), + then_pattern: self.then_pattern(), + grit_pattern_else_clause: self.grit_pattern_else_clause(), + } + } + pub fn if_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn l_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn if_predicate(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } + pub fn r_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 3usize) + } + pub fn then_pattern(&self) -> SyntaxResult { + support::required_node(&self.syntax, 4usize) + } + pub fn grit_pattern_else_clause(&self) -> Option { + support::node(&self.syntax, 5usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPatternIfElse { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPatternIfElseFields { + pub if_token: SyntaxResult, + pub l_paren_token: SyntaxResult, + pub if_predicate: SyntaxResult, + pub r_paren_token: SyntaxResult, + pub then_pattern: SyntaxResult, + pub grit_pattern_else_clause: Option, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPatternIncludes { + pub(crate) syntax: SyntaxNode, +} +impl GritPatternIncludes { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPatternIncludesFields { + GritPatternIncludesFields { + includes_token: self.includes_token(), + includes: self.includes(), + } + } + pub fn includes_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn includes(&self) -> SyntaxResult { + support::required_node(&self.syntax, 1usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPatternIncludes { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPatternIncludesFields { + pub includes_token: SyntaxResult, + pub includes: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPatternLimit { + pub(crate) syntax: SyntaxNode, +} +impl GritPatternLimit { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPatternLimitFields { + GritPatternLimitFields { + pattern: self.pattern(), + limit_token: self.limit_token(), + limit: self.limit(), + } + } + pub fn pattern(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn limit_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn limit(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPatternLimit { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPatternLimitFields { + pub pattern: SyntaxResult, + pub limit_token: SyntaxResult, + pub limit: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPatternMaybe { + pub(crate) syntax: SyntaxNode, +} +impl GritPatternMaybe { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPatternMaybeFields { + GritPatternMaybeFields { + maybe_token: self.maybe_token(), + pattern: self.pattern(), + } + } + pub fn maybe_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn pattern(&self) -> SyntaxResult { + support::required_node(&self.syntax, 1usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPatternMaybe { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPatternMaybeFields { + pub maybe_token: SyntaxResult, + pub pattern: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPatternNot { + pub(crate) syntax: SyntaxNode, +} +impl GritPatternNot { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPatternNotFields { + GritPatternNotFields { + grit_not: self.grit_not(), + pattern: self.pattern(), + } + } + pub fn grit_not(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn pattern(&self) -> SyntaxResult { + support::required_node(&self.syntax, 1usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPatternNot { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPatternNotFields { + pub grit_not: SyntaxResult, + pub pattern: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPatternOr { + pub(crate) syntax: SyntaxNode, +} +impl GritPatternOr { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPatternOrFields { + GritPatternOrFields { + or_token: self.or_token(), + l_curly_token: self.l_curly_token(), + patterns: self.patterns(), + r_curly_token: self.r_curly_token(), + } + } + pub fn or_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn l_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn patterns(&self) -> GritPatternList { + support::list(&self.syntax, 2usize) + } + pub fn r_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 3usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPatternOr { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPatternOrFields { + pub or_token: SyntaxResult, + pub l_curly_token: SyntaxResult, + pub patterns: GritPatternList, + pub r_curly_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPatternOrElse { + pub(crate) syntax: SyntaxNode, +} +impl GritPatternOrElse { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPatternOrElseFields { + GritPatternOrElseFields { + orelse_token: self.orelse_token(), + l_curly_token: self.l_curly_token(), + patterns: self.patterns(), + r_curly_token: self.r_curly_token(), + } + } + pub fn orelse_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn l_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn patterns(&self) -> GritPatternList { + support::list(&self.syntax, 2usize) + } + pub fn r_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 3usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPatternOrElse { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPatternOrElseFields { + pub orelse_token: SyntaxResult, + pub l_curly_token: SyntaxResult, + pub patterns: GritPatternList, + pub r_curly_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPatternWhere { + pub(crate) syntax: SyntaxNode, +} +impl GritPatternWhere { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPatternWhereFields { + GritPatternWhereFields { + pattern: self.pattern(), + where_token: self.where_token(), + side_condition: self.side_condition(), + } + } + pub fn pattern(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn where_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn side_condition(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPatternWhere { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPatternWhereFields { + pub pattern: SyntaxResult, + pub where_token: SyntaxResult, + pub side_condition: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPredicateAccumulate { + pub(crate) syntax: SyntaxNode, +} +impl GritPredicateAccumulate { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPredicateAccumulateFields { + GritPredicateAccumulateFields { + left: self.left(), + add_assign_token: self.add_assign_token(), + right: self.right(), + } + } + pub fn left(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn add_assign_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn right(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPredicateAccumulate { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPredicateAccumulateFields { + pub left: SyntaxResult, + pub add_assign_token: SyntaxResult, + pub right: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPredicateAnd { + pub(crate) syntax: SyntaxNode, +} +impl GritPredicateAnd { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPredicateAndFields { + GritPredicateAndFields { + and_token: self.and_token(), + l_curly_token: self.l_curly_token(), + predicates: self.predicates(), + r_curly_token: self.r_curly_token(), + } + } + pub fn and_token(&self) -> Option { + support::token(&self.syntax, 0usize) + } + pub fn l_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn predicates(&self) -> GritPredicateList { + support::list(&self.syntax, 2usize) + } + pub fn r_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 3usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPredicateAnd { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPredicateAndFields { + pub and_token: Option, + pub l_curly_token: SyntaxResult, + pub predicates: GritPredicateList, + pub r_curly_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPredicateAny { + pub(crate) syntax: SyntaxNode, +} +impl GritPredicateAny { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPredicateAnyFields { + GritPredicateAnyFields { + any_token: self.any_token(), + l_curly_token: self.l_curly_token(), + predicates: self.predicates(), + r_curly_token: self.r_curly_token(), + } + } + pub fn any_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn l_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn predicates(&self) -> GritPredicateList { + support::list(&self.syntax, 2usize) + } + pub fn r_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 3usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPredicateAny { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPredicateAnyFields { + pub any_token: SyntaxResult, + pub l_curly_token: SyntaxResult, + pub predicates: GritPredicateList, + pub r_curly_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPredicateAssignment { + pub(crate) syntax: SyntaxNode, +} +impl GritPredicateAssignment { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPredicateAssignmentFields { + GritPredicateAssignmentFields { + container: self.container(), + eq_token: self.eq_token(), + pattern: self.pattern(), + } + } + pub fn container(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn eq_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn pattern(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPredicateAssignment { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPredicateAssignmentFields { + pub container: SyntaxResult, + pub eq_token: SyntaxResult, + pub pattern: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPredicateCall { + pub(crate) syntax: SyntaxNode, +} +impl GritPredicateCall { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPredicateCallFields { + GritPredicateCallFields { + name: self.name(), + l_paren_token: self.l_paren_token(), + named_args: self.named_args(), + r_paren_token: self.r_paren_token(), + } + } + pub fn name(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn l_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn named_args(&self) -> GritNamedArgList { + support::list(&self.syntax, 2usize) + } + pub fn r_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 3usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPredicateCall { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPredicateCallFields { + pub name: SyntaxResult, + pub l_paren_token: SyntaxResult, + pub named_args: GritNamedArgList, + pub r_paren_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPredicateDefinition { + pub(crate) syntax: SyntaxNode, +} +impl GritPredicateDefinition { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPredicateDefinitionFields { + GritPredicateDefinitionFields { + predicate_token: self.predicate_token(), + name: self.name(), + l_paren_token: self.l_paren_token(), + args: self.args(), + r_paren_token: self.r_paren_token(), + body: self.body(), + } + } + pub fn predicate_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn name(&self) -> SyntaxResult { + support::required_node(&self.syntax, 1usize) + } + pub fn l_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 2usize) + } + pub fn args(&self) -> Option { + support::node(&self.syntax, 3usize) + } + pub fn r_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 4usize) + } + pub fn body(&self) -> SyntaxResult { + support::required_node(&self.syntax, 5usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPredicateDefinition { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPredicateDefinitionFields { + pub predicate_token: SyntaxResult, + pub name: SyntaxResult, + pub l_paren_token: SyntaxResult, + pub args: Option, + pub r_paren_token: SyntaxResult, + pub body: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPredicateElseClause { + pub(crate) syntax: SyntaxNode, +} +impl GritPredicateElseClause { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPredicateElseClauseFields { + GritPredicateElseClauseFields { + else_token: self.else_token(), + else_predicate: self.else_predicate(), + } + } + pub fn else_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn else_predicate(&self) -> SyntaxResult { + support::required_node(&self.syntax, 1usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPredicateElseClause { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPredicateElseClauseFields { + pub else_token: SyntaxResult, + pub else_predicate: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPredicateEqual { + pub(crate) syntax: SyntaxNode, +} +impl GritPredicateEqual { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPredicateEqualFields { + GritPredicateEqualFields { + left: self.left(), + equality_token: self.equality_token(), + right: self.right(), + } + } + pub fn left(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn equality_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn right(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPredicateEqual { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPredicateEqualFields { + pub left: SyntaxResult, + pub equality_token: SyntaxResult, + pub right: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPredicateGreater { + pub(crate) syntax: SyntaxNode, +} +impl GritPredicateGreater { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPredicateGreaterFields { + GritPredicateGreaterFields { + left: self.left(), + r_angle_token: self.r_angle_token(), + right: self.right(), + } + } + pub fn left(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn r_angle_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn right(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPredicateGreater { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPredicateGreaterFields { + pub left: SyntaxResult, + pub r_angle_token: SyntaxResult, + pub right: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPredicateGreaterEqual { + pub(crate) syntax: SyntaxNode, +} +impl GritPredicateGreaterEqual { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPredicateGreaterEqualFields { + GritPredicateGreaterEqualFields { + left: self.left(), + greater_than_equal_token: self.greater_than_equal_token(), + right: self.right(), + } + } + pub fn left(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn greater_than_equal_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn right(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPredicateGreaterEqual { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPredicateGreaterEqualFields { + pub left: SyntaxResult, + pub greater_than_equal_token: SyntaxResult, + pub right: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPredicateIfElse { + pub(crate) syntax: SyntaxNode, +} +impl GritPredicateIfElse { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPredicateIfElseFields { + GritPredicateIfElseFields { + if_token: self.if_token(), + l_paren_token: self.l_paren_token(), + if_predicate: self.if_predicate(), + r_paren_token: self.r_paren_token(), + then_predicate: self.then_predicate(), + grit_predicate_else_clause: self.grit_predicate_else_clause(), + } + } + pub fn if_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn l_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn if_predicate(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } + pub fn r_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 3usize) + } + pub fn then_predicate(&self) -> SyntaxResult { + support::required_node(&self.syntax, 4usize) + } + pub fn grit_predicate_else_clause(&self) -> Option { + support::node(&self.syntax, 5usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPredicateIfElse { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPredicateIfElseFields { + pub if_token: SyntaxResult, + pub l_paren_token: SyntaxResult, + pub if_predicate: SyntaxResult, + pub r_paren_token: SyntaxResult, + pub then_predicate: SyntaxResult, + pub grit_predicate_else_clause: Option, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPredicateLess { + pub(crate) syntax: SyntaxNode, +} +impl GritPredicateLess { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPredicateLessFields { + GritPredicateLessFields { + left: self.left(), + l_angle_token: self.l_angle_token(), + right: self.right(), + } + } + pub fn left(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn l_angle_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn right(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPredicateLess { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPredicateLessFields { + pub left: SyntaxResult, + pub l_angle_token: SyntaxResult, + pub right: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPredicateLessEqual { + pub(crate) syntax: SyntaxNode, +} +impl GritPredicateLessEqual { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPredicateLessEqualFields { + GritPredicateLessEqualFields { + left: self.left(), + less_than_equal_token: self.less_than_equal_token(), + right: self.right(), + } + } + pub fn left(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn less_than_equal_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn right(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPredicateLessEqual { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPredicateLessEqualFields { + pub left: SyntaxResult, + pub less_than_equal_token: SyntaxResult, + pub right: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPredicateMatch { + pub(crate) syntax: SyntaxNode, +} +impl GritPredicateMatch { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPredicateMatchFields { + GritPredicateMatchFields { + left: self.left(), + match_token: self.match_token(), + right: self.right(), + } + } + pub fn left(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn match_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn right(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPredicateMatch { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPredicateMatchFields { + pub left: SyntaxResult, + pub match_token: SyntaxResult, + pub right: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPredicateMaybe { + pub(crate) syntax: SyntaxNode, +} +impl GritPredicateMaybe { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPredicateMaybeFields { + GritPredicateMaybeFields { + maybe_token: self.maybe_token(), + predicate: self.predicate(), + } + } + pub fn maybe_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn predicate(&self) -> SyntaxResult { + support::required_node(&self.syntax, 1usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPredicateMaybe { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPredicateMaybeFields { + pub maybe_token: SyntaxResult, + pub predicate: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPredicateNot { + pub(crate) syntax: SyntaxNode, +} +impl GritPredicateNot { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPredicateNotFields { + GritPredicateNotFields { + grit_not: self.grit_not(), + predicate: self.predicate(), + } + } + pub fn grit_not(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn predicate(&self) -> SyntaxResult { + support::required_node(&self.syntax, 1usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPredicateNot { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPredicateNotFields { + pub grit_not: SyntaxResult, + pub predicate: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPredicateNotEqual { + pub(crate) syntax: SyntaxNode, +} +impl GritPredicateNotEqual { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPredicateNotEqualFields { + GritPredicateNotEqualFields { + left: self.left(), + inequality_token: self.inequality_token(), + right: self.right(), + } + } + pub fn left(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn inequality_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn right(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPredicateNotEqual { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPredicateNotEqualFields { + pub left: SyntaxResult, + pub inequality_token: SyntaxResult, + pub right: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPredicateOr { + pub(crate) syntax: SyntaxNode, +} +impl GritPredicateOr { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPredicateOrFields { + GritPredicateOrFields { + or_token: self.or_token(), + l_curly_token: self.l_curly_token(), + predicates: self.predicates(), + r_curly_token: self.r_curly_token(), + } + } + pub fn or_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn l_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn predicates(&self) -> GritPredicateList { + support::list(&self.syntax, 2usize) + } + pub fn r_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 3usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPredicateOr { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPredicateOrFields { + pub or_token: SyntaxResult, + pub l_curly_token: SyntaxResult, + pub predicates: GritPredicateList, + pub r_curly_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPredicateReturn { + pub(crate) syntax: SyntaxNode, +} +impl GritPredicateReturn { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPredicateReturnFields { + GritPredicateReturnFields { + return_token: self.return_token(), + pattern: self.pattern(), + } + } + pub fn return_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn pattern(&self) -> SyntaxResult { + support::required_node(&self.syntax, 1usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPredicateReturn { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPredicateReturnFields { + pub return_token: SyntaxResult, + pub pattern: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritPredicateRewrite { + pub(crate) syntax: SyntaxNode, +} +impl GritPredicateRewrite { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritPredicateRewriteFields { + GritPredicateRewriteFields { + left: self.left(), + annotation: self.annotation(), + fat_arrow_token: self.fat_arrow_token(), + right: self.right(), + } + } + pub fn left(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn annotation(&self) -> Option { + support::node(&self.syntax, 1usize) + } + pub fn fat_arrow_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 2usize) + } + pub fn right(&self) -> SyntaxResult { + support::required_node(&self.syntax, 3usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPredicateRewrite { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritPredicateRewriteFields { + pub left: SyntaxResult, + pub annotation: Option, + pub fat_arrow_token: SyntaxResult, + pub right: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritRawBacktickSnippet { + pub(crate) syntax: SyntaxNode, +} +impl GritRawBacktickSnippet { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritRawBacktickSnippetFields { + GritRawBacktickSnippetFields { + value_token: self.value_token(), + } + } + pub fn value_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritRawBacktickSnippet { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritRawBacktickSnippetFields { + pub value_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritRegexLiteral { + pub(crate) syntax: SyntaxNode, +} +impl GritRegexLiteral { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritRegexLiteralFields { + GritRegexLiteralFields { + value_token: self.value_token(), + } + } + pub fn value_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritRegexLiteral { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritRegexLiteralFields { + pub value_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritRegexPattern { + pub(crate) syntax: SyntaxNode, +} +impl GritRegexPattern { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritRegexPatternFields { + GritRegexPatternFields { + regex: self.regex(), + variables: self.variables(), + } + } + pub fn regex(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn variables(&self) -> Option { + support::node(&self.syntax, 1usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritRegexPattern { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritRegexPatternFields { + pub regex: SyntaxResult, + pub variables: Option, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritRegexPatternVariables { + pub(crate) syntax: SyntaxNode, +} +impl GritRegexPatternVariables { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritRegexPatternVariablesFields { + GritRegexPatternVariablesFields { + l_paren_token: self.l_paren_token(), + grit_pattern_arg_list: self.grit_pattern_arg_list(), + r_paren_token: self.r_paren_token(), + } + } + pub fn l_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn grit_pattern_arg_list(&self) -> Option { + support::node(&self.syntax, 1usize) + } + pub fn r_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritRegexPatternVariables { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritRegexPatternVariablesFields { + pub l_paren_token: SyntaxResult, + pub grit_pattern_arg_list: Option, + pub r_paren_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritRewrite { + pub(crate) syntax: SyntaxNode, +} +impl GritRewrite { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritRewriteFields { + GritRewriteFields { + left: self.left(), + annotation: self.annotation(), + fat_arrow_token: self.fat_arrow_token(), + right: self.right(), + } + } + pub fn left(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn annotation(&self) -> Option { + support::node(&self.syntax, 1usize) + } + pub fn fat_arrow_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 2usize) + } + pub fn right(&self) -> SyntaxResult { + support::required_node(&self.syntax, 3usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritRewrite { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritRewriteFields { + pub left: SyntaxResult, + pub annotation: Option, + pub fat_arrow_token: SyntaxResult, + pub right: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritRoot { + pub(crate) syntax: SyntaxNode, +} +impl GritRoot { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritRootFields { + GritRootFields { + version: self.version(), + language: self.language(), + definitions: self.definitions(), + pattern: self.pattern(), + definitions_continued: self.definitions_continued(), + } + } + pub fn version(&self) -> Option { + support::node(&self.syntax, 0usize) + } + pub fn language(&self) -> Option { + support::node(&self.syntax, 1usize) + } + pub fn definitions(&self) -> GritDefinitionList { + support::list(&self.syntax, 2usize) + } + pub fn pattern(&self) -> Option { + support::node(&self.syntax, 3usize) + } + pub fn definitions_continued(&self) -> GritDefinitionList { + support::list(&self.syntax, 4usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritRoot { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritRootFields { + pub version: Option, + pub language: Option, + pub definitions: GritDefinitionList, + pub pattern: Option, + pub definitions_continued: GritDefinitionList, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritSequential { + pub(crate) syntax: SyntaxNode, +} +impl GritSequential { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritSequentialFields { + GritSequentialFields { + sequential_token: self.sequential_token(), + l_curly_token: self.l_curly_token(), + sequential: self.sequential(), + r_curly_token: self.r_curly_token(), + } + } + pub fn sequential_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn l_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn sequential(&self) -> GritSequentialList { + support::list(&self.syntax, 2usize) + } + pub fn r_curly_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 3usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritSequential { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritSequentialFields { + pub sequential_token: SyntaxResult, + pub l_curly_token: SyntaxResult, + pub sequential: GritSequentialList, + pub r_curly_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritSignedIntLiteral { + pub(crate) syntax: SyntaxNode, +} +impl GritSignedIntLiteral { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritSignedIntLiteralFields { + GritSignedIntLiteralFields { + value_token: self.value_token(), + } + } + pub fn value_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritSignedIntLiteral { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritSignedIntLiteralFields { + pub value_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritSnippetRegex { + pub(crate) syntax: SyntaxNode, +} +impl GritSnippetRegex { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritSnippetRegexFields { + GritSnippetRegexFields { + value_token: self.value_token(), + } + } + pub fn value_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritSnippetRegex { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritSnippetRegexFields { + pub value_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritSome { + pub(crate) syntax: SyntaxNode, +} +impl GritSome { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritSomeFields { + GritSomeFields { + some_token: self.some_token(), + pattern: self.pattern(), + } + } + pub fn some_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn pattern(&self) -> SyntaxResult { + support::required_node(&self.syntax, 1usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritSome { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritSomeFields { + pub some_token: SyntaxResult, + pub pattern: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritStringLiteral { + pub(crate) syntax: SyntaxNode, +} +impl GritStringLiteral { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritStringLiteralFields { + GritStringLiteralFields { + value_token: self.value_token(), + } + } + pub fn value_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritStringLiteral { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritStringLiteralFields { + pub value_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritSubOperation { + pub(crate) syntax: SyntaxNode, +} +impl GritSubOperation { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritSubOperationFields { + GritSubOperationFields { + left: self.left(), + minus_token: self.minus_token(), + right: self.right(), + } + } + pub fn left(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn minus_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn right(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritSubOperation { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritSubOperationFields { + pub left: SyntaxResult, + pub minus_token: SyntaxResult, + pub right: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritUndefined { + pub(crate) syntax: SyntaxNode, +} +impl GritUndefined { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritUndefinedFields { + GritUndefinedFields { + undefined_token: self.undefined_token(), + } + } + pub fn undefined_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritUndefined { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritUndefinedFields { + pub undefined_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritUnderscore { + pub(crate) syntax: SyntaxNode, +} +impl GritUnderscore { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritUnderscoreFields { + GritUnderscoreFields { + dollar_underscore_token: self.dollar_underscore_token(), + } + } + pub fn dollar_underscore_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritUnderscore { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritUnderscoreFields { + pub dollar_underscore_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritVariable { + pub(crate) syntax: SyntaxNode, +} +impl GritVariable { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritVariableFields { + GritVariableFields { + grit_variable_token: self.grit_variable_token(), + } + } + pub fn grit_variable_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritVariable { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritVariableFields { + pub grit_variable_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritVersion { + pub(crate) syntax: SyntaxNode, +} +impl GritVersion { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritVersionFields { + GritVersionFields { + engine_token: self.engine_token(), + biome_token: self.biome_token(), + l_paren_token: self.l_paren_token(), + grit_double_literal: self.grit_double_literal(), + r_paren_token: self.r_paren_token(), + } + } + pub fn engine_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn biome_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn l_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 2usize) + } + pub fn grit_double_literal(&self) -> SyntaxResult { + support::required_node(&self.syntax, 3usize) + } + pub fn r_paren_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 4usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritVersion { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritVersionFields { + pub engine_token: SyntaxResult, + pub biome_token: SyntaxResult, + pub l_paren_token: SyntaxResult, + pub grit_double_literal: SyntaxResult, + pub r_paren_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritWithin { + pub(crate) syntax: SyntaxNode, +} +impl GritWithin { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritWithinFields { + GritWithinFields { + within_token: self.within_token(), + pattern: self.pattern(), + } + } + pub fn within_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn pattern(&self) -> SyntaxResult { + support::required_node(&self.syntax, 1usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritWithin { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritWithinFields { + pub within_token: SyntaxResult, + pub pattern: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub enum AnyGritContainer { + GritListAccessor(GritListAccessor), + GritMapAccessor(GritMapAccessor), + GritVariable(GritVariable), +} +impl AnyGritContainer { + pub fn as_grit_list_accessor(&self) -> Option<&GritListAccessor> { + match &self { + AnyGritContainer::GritListAccessor(item) => Some(item), + _ => None, + } + } + pub fn as_grit_map_accessor(&self) -> Option<&GritMapAccessor> { + match &self { + AnyGritContainer::GritMapAccessor(item) => Some(item), + _ => None, + } + } + pub fn as_grit_variable(&self) -> Option<&GritVariable> { + match &self { + AnyGritContainer::GritVariable(item) => Some(item), + _ => None, + } + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub enum AnyGritDefinition { + GritBogusDefinition(GritBogusDefinition), + GritFunctionDefinition(GritFunctionDefinition), + GritPatternDefinition(GritPatternDefinition), + GritPredicateDefinition(GritPredicateDefinition), +} +impl AnyGritDefinition { + pub fn as_grit_bogus_definition(&self) -> Option<&GritBogusDefinition> { + match &self { + AnyGritDefinition::GritBogusDefinition(item) => Some(item), + _ => None, + } + } + pub fn as_grit_function_definition(&self) -> Option<&GritFunctionDefinition> { + match &self { + AnyGritDefinition::GritFunctionDefinition(item) => Some(item), + _ => None, + } + } + pub fn as_grit_pattern_definition(&self) -> Option<&GritPatternDefinition> { + match &self { + AnyGritDefinition::GritPatternDefinition(item) => Some(item), + _ => None, + } + } + pub fn as_grit_predicate_definition(&self) -> Option<&GritPredicateDefinition> { + match &self { + AnyGritDefinition::GritPredicateDefinition(item) => Some(item), + _ => None, + } + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub enum AnyGritListPattern { + AnyGritPattern(AnyGritPattern), + GritDotdotdot(GritDotdotdot), +} +impl AnyGritListPattern { + pub fn as_any_grit_pattern(&self) -> Option<&AnyGritPattern> { + match &self { + AnyGritListPattern::AnyGritPattern(item) => Some(item), + _ => None, + } + } + pub fn as_grit_dotdotdot(&self) -> Option<&GritDotdotdot> { + match &self { + AnyGritListPattern::GritDotdotdot(item) => Some(item), + _ => None, + } + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub enum AnyGritLiteral { + GritBogusLiteral(GritBogusLiteral), + GritBooleanLiteral(GritBooleanLiteral), + GritCodeSnippet(GritCodeSnippet), + GritDoubleLiteral(GritDoubleLiteral), + GritIntLiteral(GritIntLiteral), + GritList(GritList), + GritMap(GritMap), + GritStringLiteral(GritStringLiteral), + GritUndefined(GritUndefined), +} +impl AnyGritLiteral { + pub fn as_grit_bogus_literal(&self) -> Option<&GritBogusLiteral> { + match &self { + AnyGritLiteral::GritBogusLiteral(item) => Some(item), + _ => None, + } + } + pub fn as_grit_boolean_literal(&self) -> Option<&GritBooleanLiteral> { + match &self { + AnyGritLiteral::GritBooleanLiteral(item) => Some(item), + _ => None, + } + } + pub fn as_grit_code_snippet(&self) -> Option<&GritCodeSnippet> { + match &self { + AnyGritLiteral::GritCodeSnippet(item) => Some(item), + _ => None, + } + } + pub fn as_grit_double_literal(&self) -> Option<&GritDoubleLiteral> { + match &self { + AnyGritLiteral::GritDoubleLiteral(item) => Some(item), + _ => None, + } + } + pub fn as_grit_int_literal(&self) -> Option<&GritIntLiteral> { + match &self { + AnyGritLiteral::GritIntLiteral(item) => Some(item), + _ => None, + } + } + pub fn as_grit_list(&self) -> Option<&GritList> { + match &self { + AnyGritLiteral::GritList(item) => Some(item), + _ => None, + } + } + pub fn as_grit_map(&self) -> Option<&GritMap> { + match &self { + AnyGritLiteral::GritMap(item) => Some(item), + _ => None, + } + } + pub fn as_grit_string_literal(&self) -> Option<&GritStringLiteral> { + match &self { + AnyGritLiteral::GritStringLiteral(item) => Some(item), + _ => None, + } + } + pub fn as_grit_undefined(&self) -> Option<&GritUndefined> { + match &self { + AnyGritLiteral::GritUndefined(item) => Some(item), + _ => None, + } + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub enum AnyGritNamedArg { + GritBogusNamedArg(GritBogusNamedArg), + GritNamedArg(GritNamedArg), + GritNamedArgWithDefault(GritNamedArgWithDefault), +} +impl AnyGritNamedArg { + pub fn as_grit_bogus_named_arg(&self) -> Option<&GritBogusNamedArg> { + match &self { + AnyGritNamedArg::GritBogusNamedArg(item) => Some(item), + _ => None, + } + } + pub fn as_grit_named_arg(&self) -> Option<&GritNamedArg> { + match &self { + AnyGritNamedArg::GritNamedArg(item) => Some(item), + _ => None, + } + } + pub fn as_grit_named_arg_with_default(&self) -> Option<&GritNamedArgWithDefault> { + match &self { + AnyGritNamedArg::GritNamedArgWithDefault(item) => Some(item), + _ => None, + } + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub enum GritCodeSnippetSource { + GritBacktickSnippet(GritBacktickSnippet), + GritLanguageSpecificSnippet(GritLanguageSpecificSnippet), + GritRawBacktickSnippet(GritRawBacktickSnippet), +} +impl GritCodeSnippetSource { + pub fn as_grit_backtick_snippet(&self) -> Option<&GritBacktickSnippet> { + match &self { + GritCodeSnippetSource::GritBacktickSnippet(item) => Some(item), + _ => None, + } + } + pub fn as_grit_language_specific_snippet(&self) -> Option<&GritLanguageSpecificSnippet> { + match &self { + GritCodeSnippetSource::GritLanguageSpecificSnippet(item) => Some(item), + _ => None, + } + } + pub fn as_grit_raw_backtick_snippet(&self) -> Option<&GritRawBacktickSnippet> { + match &self { + GritCodeSnippetSource::GritRawBacktickSnippet(item) => Some(item), + _ => None, + } + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub enum GritListAccessorSubject { + AnyGritContainer(AnyGritContainer), + GritList(GritList), +} +impl GritListAccessorSubject { + pub fn as_any_grit_container(&self) -> Option<&AnyGritContainer> { + match &self { + GritListAccessorSubject::AnyGritContainer(item) => Some(item), + _ => None, + } + } + pub fn as_grit_list(&self) -> Option<&GritList> { + match &self { + GritListAccessorSubject::GritList(item) => Some(item), + _ => None, + } + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub enum GritListIndex { + AnyGritContainer(AnyGritContainer), + GritSignedIntLiteral(GritSignedIntLiteral), +} +impl GritListIndex { + pub fn as_any_grit_container(&self) -> Option<&AnyGritContainer> { + match &self { + GritListIndex::AnyGritContainer(item) => Some(item), + _ => None, + } + } + pub fn as_grit_signed_int_literal(&self) -> Option<&GritSignedIntLiteral> { + match &self { + GritListIndex::GritSignedIntLiteral(item) => Some(item), + _ => None, + } + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub enum GritMapAccessorSubject { + AnyGritContainer(AnyGritContainer), + GritMap(GritMap), +} +impl GritMapAccessorSubject { + pub fn as_any_grit_container(&self) -> Option<&AnyGritContainer> { + match &self { + GritMapAccessorSubject::AnyGritContainer(item) => Some(item), + _ => None, + } + } + pub fn as_grit_map(&self) -> Option<&GritMap> { + match &self { + GritMapAccessorSubject::GritMap(item) => Some(item), + _ => None, + } + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub enum GritMapKey { + GritName(GritName), + GritVariable(GritVariable), +} +impl GritMapKey { + pub fn as_grit_name(&self) -> Option<&GritName> { + match &self { + GritMapKey::GritName(item) => Some(item), + _ => None, + } + } + pub fn as_grit_variable(&self) -> Option<&GritVariable> { + match &self { + GritMapKey::GritVariable(item) => Some(item), + _ => None, + } + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub enum GritPredicateMatchSubject { + AnyGritContainer(AnyGritContainer), + AnyGritLiteral(AnyGritLiteral), +} +impl GritPredicateMatchSubject { + pub fn as_any_grit_container(&self) -> Option<&AnyGritContainer> { + match &self { + GritPredicateMatchSubject::AnyGritContainer(item) => Some(item), + _ => None, + } + } + pub fn as_any_grit_literal(&self) -> Option<&AnyGritLiteral> { + match &self { + GritPredicateMatchSubject::AnyGritLiteral(item) => Some(item), + _ => None, + } + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub enum GritRegex { + GritRegexLiteral(GritRegexLiteral), + GritSnippetRegex(GritSnippetRegex), +} +impl GritRegex { + pub fn as_grit_regex_literal(&self) -> Option<&GritRegexLiteral> { + match &self { + GritRegex::GritRegexLiteral(item) => Some(item), + _ => None, + } + } + pub fn as_grit_snippet_regex(&self) -> Option<&GritSnippetRegex> { + match &self { + GritRegex::GritSnippetRegex(item) => Some(item), + _ => None, + } + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub enum MaybeCurlyGritPattern { + AnyGritPattern(AnyGritPattern), + CurlyGritPattern(CurlyGritPattern), +} +impl MaybeCurlyGritPattern { + pub fn as_any_grit_pattern(&self) -> Option<&AnyGritPattern> { + match &self { + MaybeCurlyGritPattern::AnyGritPattern(item) => Some(item), + _ => None, + } + } + pub fn as_curly_grit_pattern(&self) -> Option<&CurlyGritPattern> { + match &self { + MaybeCurlyGritPattern::CurlyGritPattern(item) => Some(item), + _ => None, + } + } +} +impl AstNode for AnyGritPattern { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(ANY_GRIT_PATTERN as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == ANY_GRIT_PATTERN + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for AnyGritPattern { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("AnyGritPattern") + .field( + "any_grit_literal", + &support::DebugSyntaxResult(self.any_grit_literal()), + ) + .field( + "grit_pattern_not", + &support::DebugSyntaxResult(self.grit_pattern_not()), + ) + .field( + "grit_pattern_or", + &support::DebugSyntaxResult(self.grit_pattern_or()), + ) + .field( + "grit_pattern_or_else", + &support::DebugSyntaxResult(self.grit_pattern_or_else()), + ) + .field( + "grit_pattern_any", + &support::DebugSyntaxResult(self.grit_pattern_any()), + ) + .field( + "grit_pattern_and", + &support::DebugSyntaxResult(self.grit_pattern_and()), + ) + .field( + "grit_pattern_maybe", + &support::DebugSyntaxResult(self.grit_pattern_maybe()), + ) + .field( + "grit_pattern_if_else", + &support::DebugSyntaxResult(self.grit_pattern_if_else()), + ) + .field( + "grit_pattern_contains", + &support::DebugSyntaxResult(self.grit_pattern_contains()), + ) + .field( + "grit_pattern_includes", + &support::DebugSyntaxResult(self.grit_pattern_includes()), + ) + .field( + "grit_pattern_after", + &support::DebugSyntaxResult(self.grit_pattern_after()), + ) + .field( + "grit_pattern_before", + &support::DebugSyntaxResult(self.grit_pattern_before()), + ) + .field( + "grit_within", + &support::DebugSyntaxResult(self.grit_within()), + ) + .field( + "grit_bubble", + &support::DebugSyntaxResult(self.grit_bubble()), + ) + .field( + "grit_node_like", + &support::DebugSyntaxResult(self.grit_node_like()), + ) + .field( + "grit_map_accessor", + &support::DebugSyntaxResult(self.grit_map_accessor()), + ) + .field( + "grit_list_accessor", + &support::DebugSyntaxResult(self.grit_list_accessor()), + ) + .field("grit_dot", &support::DebugSyntaxResult(self.grit_dot())) + .field("grit_some", &support::DebugSyntaxResult(self.grit_some())) + .field("grit_every", &support::DebugSyntaxResult(self.grit_every())) + .field( + "grit_underscore", + &support::DebugSyntaxResult(self.grit_underscore()), + ) + .field( + "grit_variable", + &support::DebugSyntaxResult(self.grit_variable()), + ) + .field( + "grit_regex_pattern", + &support::DebugSyntaxResult(self.grit_regex_pattern()), + ) + .field( + "grit_pattern_as", + &support::DebugSyntaxResult(self.grit_pattern_as()), + ) + .field( + "grit_pattern_limit", + &support::DebugSyntaxResult(self.grit_pattern_limit()), + ) + .field( + "grit_assignment_as_pattern", + &support::DebugSyntaxResult(self.grit_assignment_as_pattern()), + ) + .field( + "grit_pattern_accumulate", + &support::DebugSyntaxResult(self.grit_pattern_accumulate()), + ) + .field( + "grit_rewrite", + &support::DebugSyntaxResult(self.grit_rewrite()), + ) + .field("grit_like", &support::DebugSyntaxResult(self.grit_like())) + .field( + "grit_pattern_where", + &support::DebugSyntaxResult(self.grit_pattern_where()), + ) + .field( + "grit_mul_operation", + &support::DebugSyntaxResult(self.grit_mul_operation()), + ) + .field( + "grit_div_operation", + &support::DebugSyntaxResult(self.grit_div_operation()), + ) + .field( + "grit_mod_operation", + &support::DebugSyntaxResult(self.grit_mod_operation()), + ) + .field( + "grit_add_operation", + &support::DebugSyntaxResult(self.grit_add_operation()), + ) + .field( + "grit_sub_operation", + &support::DebugSyntaxResult(self.grit_sub_operation()), + ) + .field( + "grit_sequential", + &support::DebugSyntaxResult(self.grit_sequential()), + ) + .field("grit_files", &support::DebugSyntaxResult(self.grit_files())) + .field( + "l_paren_token", + &support::DebugSyntaxResult(self.l_paren_token()), + ) + .field( + "any_grit_pattern", + &support::DebugSyntaxResult(self.any_grit_pattern()), + ) + .field( + "r_paren_token", + &support::DebugSyntaxResult(self.r_paren_token()), + ) + .field( + "grit_bogus_pattern", + &support::DebugSyntaxResult(self.grit_bogus_pattern()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: AnyGritPattern) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: AnyGritPattern) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for AnyGritPredicate { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(ANY_GRIT_PREDICATE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == ANY_GRIT_PREDICATE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for AnyGritPredicate { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("AnyGritPredicate") + .field( + "grit_predicate_not", + &support::DebugSyntaxResult(self.grit_predicate_not()), + ) + .field( + "grit_predicate_maybe", + &support::DebugSyntaxResult(self.grit_predicate_maybe()), + ) + .field( + "grit_predicate_and", + &support::DebugSyntaxResult(self.grit_predicate_and()), + ) + .field( + "grit_predicate_or", + &support::DebugSyntaxResult(self.grit_predicate_or()), + ) + .field( + "grit_predicate_any", + &support::DebugSyntaxResult(self.grit_predicate_any()), + ) + .field( + "grit_predicate_if_else", + &support::DebugSyntaxResult(self.grit_predicate_if_else()), + ) + .field( + "grit_predicate_assignment", + &support::DebugSyntaxResult(self.grit_predicate_assignment()), + ) + .field( + "grit_predicate_accumulate", + &support::DebugSyntaxResult(self.grit_predicate_accumulate()), + ) + .field( + "grit_predicate_rewrite", + &support::DebugSyntaxResult(self.grit_predicate_rewrite()), + ) + .field( + "grit_predicate_greater", + &support::DebugSyntaxResult(self.grit_predicate_greater()), + ) + .field( + "grit_predicate_less", + &support::DebugSyntaxResult(self.grit_predicate_less()), + ) + .field( + "grit_predicate_greater_equal", + &support::DebugSyntaxResult(self.grit_predicate_greater_equal()), + ) + .field( + "grit_predicate_less_equal", + &support::DebugSyntaxResult(self.grit_predicate_less_equal()), + ) + .field( + "grit_predicate_not_equal", + &support::DebugSyntaxResult(self.grit_predicate_not_equal()), + ) + .field( + "grit_predicate_equal", + &support::DebugSyntaxResult(self.grit_predicate_equal()), + ) + .field( + "grit_predicate_match", + &support::DebugSyntaxResult(self.grit_predicate_match()), + ) + .field( + "grit_predicate_call", + &support::DebugSyntaxResult(self.grit_predicate_call()), + ) + .field( + "l_paren_token", + &support::DebugSyntaxResult(self.l_paren_token()), + ) + .field( + "any_grit_predicate", + &support::DebugSyntaxResult(self.any_grit_predicate()), + ) + .field( + "r_paren_token", + &support::DebugSyntaxResult(self.r_paren_token()), + ) + .field( + "grit_boolean_literal", + &support::DebugSyntaxResult(self.grit_boolean_literal()), + ) + .field( + "grit_predicate_return", + &support::DebugSyntaxResult(self.grit_predicate_return()), + ) + .field( + "grit_bogus_predicate", + &support::DebugSyntaxResult(self.grit_bogus_predicate()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: AnyGritPredicate) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: AnyGritPredicate) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for CurlyGritPattern { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(CURLY_GRIT_PATTERN as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == CURLY_GRIT_PATTERN + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for CurlyGritPattern { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("CurlyGritPattern") + .field( + "l_curly_token", + &support::DebugSyntaxResult(self.l_curly_token()), + ) + .field( + "any_grit_pattern", + &support::DebugSyntaxResult(self.any_grit_pattern()), + ) + .field( + "r_curly_token", + &support::DebugSyntaxResult(self.r_curly_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: CurlyGritPattern) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: CurlyGritPattern) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritAddOperation { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_ADD_OPERATION as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_ADD_OPERATION + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritAddOperation { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritAddOperation") + .field("left", &support::DebugSyntaxResult(self.left())) + .field("plus_token", &support::DebugSyntaxResult(self.plus_token())) + .field("right", &support::DebugSyntaxResult(self.right())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritAddOperation) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritAddOperation) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritAnnotation { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_ANNOTATION as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_ANNOTATION + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritAnnotation { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritAnnotation") + .field( + "grit_annotation_token", + &support::DebugSyntaxResult(self.grit_annotation_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritAnnotation) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritAnnotation) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritAssignmentAsPattern { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_ASSIGNMENT_AS_PATTERN as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_ASSIGNMENT_AS_PATTERN + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritAssignmentAsPattern { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritAssignmentAsPattern") + .field("container", &support::DebugSyntaxResult(self.container())) + .field("eq_token", &support::DebugSyntaxResult(self.eq_token())) + .field("pattern", &support::DebugSyntaxResult(self.pattern())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritAssignmentAsPattern) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritAssignmentAsPattern) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritBacktickSnippet { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_BACKTICK_SNIPPET as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_BACKTICK_SNIPPET + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritBacktickSnippet { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritBacktickSnippet") + .field( + "value_token", + &support::DebugSyntaxResult(self.value_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritBacktickSnippet) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritBacktickSnippet) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritBooleanLiteral { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_BOOLEAN_LITERAL as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_BOOLEAN_LITERAL + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritBooleanLiteral { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritBooleanLiteral") + .field("true_token", &support::DebugSyntaxResult(self.true_token())) + .field( + "false_token", + &support::DebugSyntaxResult(self.false_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritBooleanLiteral) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritBooleanLiteral) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritBubble { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_BUBBLE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_BUBBLE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritBubble { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritBubble") + .field( + "bubble_token", + &support::DebugSyntaxResult(self.bubble_token()), + ) + .field( + "variables", + &support::DebugOptionalElement(self.variables()), + ) + .field("pattern", &support::DebugSyntaxResult(self.pattern())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritBubble) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritBubble) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritBubbleScope { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_BUBBLE_SCOPE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_BUBBLE_SCOPE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritBubbleScope { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritBubbleScope") + .field( + "l_paren_token", + &support::DebugSyntaxResult(self.l_paren_token()), + ) + .field("grit_variable_list", &self.grit_variable_list()) + .field( + "r_paren_token", + &support::DebugSyntaxResult(self.r_paren_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritBubbleScope) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritBubbleScope) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritCodeSnippet { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_CODE_SNIPPET as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_CODE_SNIPPET + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritCodeSnippet { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritCodeSnippet") + .field("source", &support::DebugSyntaxResult(self.source())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritCodeSnippet) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritCodeSnippet) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritCurlyPredicateList { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_CURLY_PREDICATE_LIST as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_CURLY_PREDICATE_LIST + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritCurlyPredicateList { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritCurlyPredicateList") + .field( + "l_curly_token", + &support::DebugSyntaxResult(self.l_curly_token()), + ) + .field("predicates", &self.predicates()) + .field( + "r_curly_token", + &support::DebugSyntaxResult(self.r_curly_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritCurlyPredicateList) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritCurlyPredicateList) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritDivOperation { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_DIV_OPERATION as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_DIV_OPERATION + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritDivOperation { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritDivOperation") + .field("left", &support::DebugSyntaxResult(self.left())) + .field( + "slash_token", + &support::DebugSyntaxResult(self.slash_token()), + ) + .field("right", &support::DebugSyntaxResult(self.right())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritDivOperation) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritDivOperation) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritDot { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_DOT as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_DOT + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritDot { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritDot") + .field("dot_token", &support::DebugSyntaxResult(self.dot_token())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritDot) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritDot) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritDotdotdot { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_DOTDOTDOT as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_DOTDOTDOT + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritDotdotdot { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritDotdotdot") + .field( + "dollar_dotdotdot_token", + &support::DebugSyntaxResult(self.dollar_dotdotdot_token()), + ) + .field( + "maybe_curly_grit_pattern", + &support::DebugOptionalElement(self.maybe_curly_grit_pattern()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritDotdotdot) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritDotdotdot) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritDoubleLiteral { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_DOUBLE_LITERAL as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_DOUBLE_LITERAL + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritDoubleLiteral { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritDoubleLiteral") + .field( + "value_token", + &support::DebugSyntaxResult(self.value_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritDoubleLiteral) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritDoubleLiteral) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritDoubleQuoteSnippet { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_DOUBLE_QUOTE_SNIPPET as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_DOUBLE_QUOTE_SNIPPET + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritDoubleQuoteSnippet { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritDoubleQuoteSnippet") + .field( + "value_token", + &support::DebugSyntaxResult(self.value_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritDoubleQuoteSnippet) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritDoubleQuoteSnippet) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritEvery { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_EVERY as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_EVERY + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritEvery { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritEvery") + .field( + "every_token", + &support::DebugSyntaxResult(self.every_token()), + ) + .field("pattern", &support::DebugSyntaxResult(self.pattern())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritEvery) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritEvery) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritFiles { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_FILES as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_FILES + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritFiles { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritFiles") + .field( + "multifile_token", + &support::DebugSyntaxResult(self.multifile_token()), + ) + .field( + "l_curly_token", + &support::DebugSyntaxResult(self.l_curly_token()), + ) + .field("files", &self.files()) + .field( + "r_curly_token", + &support::DebugSyntaxResult(self.r_curly_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritFiles) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritFiles) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritFunctionDefinition { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_FUNCTION_DEFINITION as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_FUNCTION_DEFINITION + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritFunctionDefinition { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritFunctionDefinition") + .field( + "function_token", + &support::DebugSyntaxResult(self.function_token()), + ) + .field("name", &support::DebugSyntaxResult(self.name())) + .field( + "l_paren_token", + &support::DebugSyntaxResult(self.l_paren_token()), + ) + .field("args", &self.args()) + .field( + "r_paren_token", + &support::DebugSyntaxResult(self.r_paren_token()), + ) + .field("body", &support::DebugSyntaxResult(self.body())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritFunctionDefinition) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritFunctionDefinition) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritIntLiteral { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_INT_LITERAL as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_INT_LITERAL + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritIntLiteral { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritIntLiteral") + .field( + "value_token", + &support::DebugSyntaxResult(self.value_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritIntLiteral) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritIntLiteral) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritLanguageDeclaration { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_LANGUAGE_DECLARATION as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_LANGUAGE_DECLARATION + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritLanguageDeclaration { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritLanguageDeclaration") + .field( + "language_token", + &support::DebugSyntaxResult(self.language_token()), + ) + .field("name", &support::DebugSyntaxResult(self.name())) + .field("flavor", &support::DebugOptionalElement(self.flavor())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritLanguageDeclaration) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritLanguageDeclaration) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritLanguageFlavor { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_LANGUAGE_FLAVOR as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_LANGUAGE_FLAVOR + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritLanguageFlavor { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritLanguageFlavor") + .field( + "l_paren_token", + &support::DebugSyntaxResult(self.l_paren_token()), + ) + .field( + "grit_language_flavor_list", + &self.grit_language_flavor_list(), + ) + .field( + "r_paren_token", + &support::DebugSyntaxResult(self.r_paren_token()), + ) + .field( + "semicolon_token", + &support::DebugOptionalElement(self.semicolon_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritLanguageFlavor) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritLanguageFlavor) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritLanguageFlavorKind { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_LANGUAGE_FLAVOR_KIND as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_LANGUAGE_FLAVOR_KIND + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritLanguageFlavorKind { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritLanguageFlavorKind") + .field( + "flavor_kind", + &support::DebugSyntaxResult(self.flavor_kind()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritLanguageFlavorKind) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritLanguageFlavorKind) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritLanguageName { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_LANGUAGE_NAME as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_LANGUAGE_NAME + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritLanguageName { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritLanguageName") + .field("js_token", &support::DebugSyntaxResult(self.js_token())) + .field("css_token", &support::DebugSyntaxResult(self.css_token())) + .field("json_token", &support::DebugSyntaxResult(self.json_token())) + .field("grit_token", &support::DebugSyntaxResult(self.grit_token())) + .field("html_token", &support::DebugSyntaxResult(self.html_token())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritLanguageName) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritLanguageName) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritLanguageSpecificSnippet { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_LANGUAGE_SPECIFIC_SNIPPET as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_LANGUAGE_SPECIFIC_SNIPPET + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritLanguageSpecificSnippet { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritLanguageSpecificSnippet") + .field("language", &support::DebugSyntaxResult(self.language())) + .field("snippet", &support::DebugSyntaxResult(self.snippet())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritLanguageSpecificSnippet) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritLanguageSpecificSnippet) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritLike { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_LIKE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_LIKE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritLike { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritLike") + .field("like_token", &support::DebugSyntaxResult(self.like_token())) + .field( + "grit_like_threshold", + &support::DebugOptionalElement(self.grit_like_threshold()), + ) + .field( + "l_curly_token", + &support::DebugSyntaxResult(self.l_curly_token()), + ) + .field("example", &support::DebugSyntaxResult(self.example())) + .field( + "r_curly_token", + &support::DebugSyntaxResult(self.r_curly_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritLike) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritLike) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritLikeThreshold { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_LIKE_THRESHOLD as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_LIKE_THRESHOLD + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritLikeThreshold { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritLikeThreshold") + .field( + "l_paren_token", + &support::DebugSyntaxResult(self.l_paren_token()), + ) + .field("threshold", &support::DebugSyntaxResult(self.threshold())) + .field( + "r_paren_token", + &support::DebugSyntaxResult(self.r_paren_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritLikeThreshold) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritLikeThreshold) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritList { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_LIST as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_LIST + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritList { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritList") + .field( + "grit_name", + &support::DebugOptionalElement(self.grit_name()), + ) + .field( + "l_brack_token", + &support::DebugSyntaxResult(self.l_brack_token()), + ) + .field("patterns", &self.patterns()) + .field( + "r_brack_token", + &support::DebugSyntaxResult(self.r_brack_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritList) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritList) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritListAccessor { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_LIST_ACCESSOR as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_LIST_ACCESSOR + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritListAccessor { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritListAccessor") + .field("list", &support::DebugSyntaxResult(self.list())) + .field( + "l_brack_token", + &support::DebugSyntaxResult(self.l_brack_token()), + ) + .field("index", &support::DebugSyntaxResult(self.index())) + .field( + "r_brack_token", + &support::DebugSyntaxResult(self.r_brack_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritListAccessor) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritListAccessor) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritMap { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_MAP as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_MAP + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritMap { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritMap") + .field( + "l_curly_token", + &support::DebugSyntaxResult(self.l_curly_token()), + ) + .field("elements", &self.elements()) + .field( + "r_curly_token", + &support::DebugSyntaxResult(self.r_curly_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritMap) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritMap) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritMapAccessor { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_MAP_ACCESSOR as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_MAP_ACCESSOR + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritMapAccessor { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritMapAccessor") + .field("map", &support::DebugSyntaxResult(self.map())) + .field("dot_token", &support::DebugSyntaxResult(self.dot_token())) + .field("key", &support::DebugSyntaxResult(self.key())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritMapAccessor) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritMapAccessor) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritMapElement { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_MAP_ELEMENT as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_MAP_ELEMENT + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritMapElement { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritMapElement") + .field("key", &support::DebugSyntaxResult(self.key())) + .field( + "colon_token", + &support::DebugSyntaxResult(self.colon_token()), + ) + .field("value", &support::DebugSyntaxResult(self.value())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritMapElement) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritMapElement) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritModOperation { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_MOD_OPERATION as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_MOD_OPERATION + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritModOperation { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritModOperation") + .field("left", &support::DebugSyntaxResult(self.left())) + .field( + "remainder_token", + &support::DebugSyntaxResult(self.remainder_token()), + ) + .field("right", &support::DebugSyntaxResult(self.right())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritModOperation) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritModOperation) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritMulOperation { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_MUL_OPERATION as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_MUL_OPERATION + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritMulOperation { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritMulOperation") + .field("left", &support::DebugSyntaxResult(self.left())) + .field("star_token", &support::DebugSyntaxResult(self.star_token())) + .field("right", &support::DebugSyntaxResult(self.right())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritMulOperation) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritMulOperation) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritName { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_NAME as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_NAME + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritName { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritName") + .field( + "grit_name_token", + &support::DebugSyntaxResult(self.grit_name_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritName) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritName) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritNamedArg { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_NAMED_ARG as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_NAMED_ARG + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritNamedArg { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritNamedArg") + .field("name", &support::DebugSyntaxResult(self.name())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritNamedArg) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritNamedArg) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritNamedArgWithDefault { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_NAMED_ARG_WITH_DEFAULT as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_NAMED_ARG_WITH_DEFAULT + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritNamedArgWithDefault { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritNamedArgWithDefault") + .field("name", &support::DebugSyntaxResult(self.name())) + .field("eq_token", &support::DebugSyntaxResult(self.eq_token())) + .field("pattern", &support::DebugSyntaxResult(self.pattern())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritNamedArgWithDefault) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritNamedArgWithDefault) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritNodeLike { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_NODE_LIKE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_NODE_LIKE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritNodeLike { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritNodeLike") + .field("name", &support::DebugSyntaxResult(self.name())) + .field( + "l_paren_token", + &support::DebugSyntaxResult(self.l_paren_token()), + ) + .field("named_args", &self.named_args()) + .field( + "r_paren_token", + &support::DebugSyntaxResult(self.r_paren_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritNodeLike) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritNodeLike) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritNot { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_NOT as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_NOT + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritNot { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritNot") + .field("not_token", &support::DebugSyntaxResult(self.not_token())) + .field("excl_token", &support::DebugSyntaxResult(self.excl_token())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritNot) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritNot) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPatternAccumulate { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PATTERN_ACCUMULATE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PATTERN_ACCUMULATE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPatternAccumulate { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPatternAccumulate") + .field("left", &support::DebugSyntaxResult(self.left())) + .field( + "add_assign_token", + &support::DebugSyntaxResult(self.add_assign_token()), + ) + .field("right", &support::DebugSyntaxResult(self.right())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPatternAccumulate) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPatternAccumulate) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPatternAfter { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PATTERN_AFTER as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PATTERN_AFTER + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPatternAfter { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPatternAfter") + .field( + "after_token", + &support::DebugSyntaxResult(self.after_token()), + ) + .field("pattern", &support::DebugSyntaxResult(self.pattern())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPatternAfter) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPatternAfter) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPatternAnd { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PATTERN_AND as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PATTERN_AND + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPatternAnd { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPatternAnd") + .field("and_token", &support::DebugSyntaxResult(self.and_token())) + .field( + "l_curly_token", + &support::DebugSyntaxResult(self.l_curly_token()), + ) + .field("patterns", &self.patterns()) + .field( + "r_curly_token", + &support::DebugSyntaxResult(self.r_curly_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPatternAnd) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPatternAnd) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPatternAny { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PATTERN_ANY as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PATTERN_ANY + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPatternAny { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPatternAny") + .field("any_token", &support::DebugSyntaxResult(self.any_token())) + .field( + "l_curly_token", + &support::DebugSyntaxResult(self.l_curly_token()), + ) + .field("patterns", &self.patterns()) + .field( + "r_curly_token", + &support::DebugSyntaxResult(self.r_curly_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPatternAny) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPatternAny) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPatternArgList { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PATTERN_ARG_LIST as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PATTERN_ARG_LIST + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPatternArgList { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPatternArgList") + .field("grit_variable_list", &self.grit_variable_list()) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPatternArgList) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPatternArgList) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPatternAs { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PATTERN_AS as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PATTERN_AS + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPatternAs { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPatternAs") + .field("pattern", &support::DebugSyntaxResult(self.pattern())) + .field("as_token", &support::DebugSyntaxResult(self.as_token())) + .field("variable", &support::DebugSyntaxResult(self.variable())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPatternAs) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPatternAs) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPatternBefore { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PATTERN_BEFORE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PATTERN_BEFORE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPatternBefore { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPatternBefore") + .field( + "before_token", + &support::DebugSyntaxResult(self.before_token()), + ) + .field("pattern", &support::DebugSyntaxResult(self.pattern())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPatternBefore) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPatternBefore) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPatternContains { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PATTERN_CONTAINS as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PATTERN_CONTAINS + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPatternContains { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPatternContains") + .field( + "contains_token", + &support::DebugSyntaxResult(self.contains_token()), + ) + .field("contains", &support::DebugSyntaxResult(self.contains())) + .field( + "grit_pattern_contains_until_clause", + &support::DebugOptionalElement(self.grit_pattern_contains_until_clause()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPatternContains) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPatternContains) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPatternContainsUntilClause { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PATTERN_CONTAINS_UNTIL_CLAUSE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PATTERN_CONTAINS_UNTIL_CLAUSE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPatternContainsUntilClause { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPatternContainsUntilClause") + .field( + "until_token", + &support::DebugSyntaxResult(self.until_token()), + ) + .field("until", &support::DebugSyntaxResult(self.until())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPatternContainsUntilClause) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPatternContainsUntilClause) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPatternDefinition { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PATTERN_DEFINITION as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PATTERN_DEFINITION + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPatternDefinition { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPatternDefinition") + .field( + "visibility_token", + &support::DebugOptionalElement(self.visibility_token()), + ) + .field( + "pattern_token", + &support::DebugSyntaxResult(self.pattern_token()), + ) + .field("name", &support::DebugSyntaxResult(self.name())) + .field( + "l_paren_token", + &support::DebugSyntaxResult(self.l_paren_token()), + ) + .field("args", &support::DebugOptionalElement(self.args())) + .field( + "r_paren_token", + &support::DebugSyntaxResult(self.r_paren_token()), + ) + .field("language", &support::DebugOptionalElement(self.language())) + .field("body", &support::DebugSyntaxResult(self.body())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPatternDefinition) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPatternDefinition) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPatternDefinitionBody { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PATTERN_DEFINITION_BODY as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PATTERN_DEFINITION_BODY + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPatternDefinitionBody { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPatternDefinitionBody") + .field( + "l_curly_token", + &support::DebugSyntaxResult(self.l_curly_token()), + ) + .field("patterns", &self.patterns()) + .field( + "r_curly_token", + &support::DebugSyntaxResult(self.r_curly_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPatternDefinitionBody) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPatternDefinitionBody) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPatternElseClause { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PATTERN_ELSE_CLAUSE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PATTERN_ELSE_CLAUSE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPatternElseClause { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPatternElseClause") + .field("else_token", &support::DebugSyntaxResult(self.else_token())) + .field( + "else_pattern", + &support::DebugSyntaxResult(self.else_pattern()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPatternElseClause) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPatternElseClause) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPatternIfElse { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PATTERN_IF_ELSE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PATTERN_IF_ELSE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPatternIfElse { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPatternIfElse") + .field("if_token", &support::DebugSyntaxResult(self.if_token())) + .field( + "l_paren_token", + &support::DebugSyntaxResult(self.l_paren_token()), + ) + .field( + "if_predicate", + &support::DebugSyntaxResult(self.if_predicate()), + ) + .field( + "r_paren_token", + &support::DebugSyntaxResult(self.r_paren_token()), + ) + .field( + "then_pattern", + &support::DebugSyntaxResult(self.then_pattern()), + ) + .field( + "grit_pattern_else_clause", + &support::DebugOptionalElement(self.grit_pattern_else_clause()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPatternIfElse) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPatternIfElse) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPatternIncludes { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PATTERN_INCLUDES as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PATTERN_INCLUDES + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPatternIncludes { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPatternIncludes") + .field( + "includes_token", + &support::DebugSyntaxResult(self.includes_token()), + ) + .field("includes", &support::DebugSyntaxResult(self.includes())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPatternIncludes) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPatternIncludes) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPatternLimit { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PATTERN_LIMIT as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PATTERN_LIMIT + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPatternLimit { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPatternLimit") + .field("pattern", &support::DebugSyntaxResult(self.pattern())) + .field( + "limit_token", + &support::DebugSyntaxResult(self.limit_token()), + ) + .field("limit", &support::DebugSyntaxResult(self.limit())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPatternLimit) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPatternLimit) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPatternMaybe { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PATTERN_MAYBE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PATTERN_MAYBE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPatternMaybe { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPatternMaybe") + .field( + "maybe_token", + &support::DebugSyntaxResult(self.maybe_token()), + ) + .field("pattern", &support::DebugSyntaxResult(self.pattern())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPatternMaybe) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPatternMaybe) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPatternNot { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PATTERN_NOT as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PATTERN_NOT + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPatternNot { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPatternNot") + .field("grit_not", &support::DebugSyntaxResult(self.grit_not())) + .field("pattern", &support::DebugSyntaxResult(self.pattern())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPatternNot) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPatternNot) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPatternOr { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PATTERN_OR as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PATTERN_OR + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPatternOr { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPatternOr") + .field("or_token", &support::DebugSyntaxResult(self.or_token())) + .field( + "l_curly_token", + &support::DebugSyntaxResult(self.l_curly_token()), + ) + .field("patterns", &self.patterns()) + .field( + "r_curly_token", + &support::DebugSyntaxResult(self.r_curly_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPatternOr) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPatternOr) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPatternOrElse { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PATTERN_OR_ELSE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PATTERN_OR_ELSE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPatternOrElse { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPatternOrElse") + .field( + "orelse_token", + &support::DebugSyntaxResult(self.orelse_token()), + ) + .field( + "l_curly_token", + &support::DebugSyntaxResult(self.l_curly_token()), + ) + .field("patterns", &self.patterns()) + .field( + "r_curly_token", + &support::DebugSyntaxResult(self.r_curly_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPatternOrElse) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPatternOrElse) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPatternWhere { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PATTERN_WHERE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PATTERN_WHERE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPatternWhere { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPatternWhere") + .field("pattern", &support::DebugSyntaxResult(self.pattern())) + .field( + "where_token", + &support::DebugSyntaxResult(self.where_token()), + ) + .field( + "side_condition", + &support::DebugSyntaxResult(self.side_condition()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPatternWhere) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPatternWhere) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPredicateAccumulate { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PREDICATE_ACCUMULATE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PREDICATE_ACCUMULATE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPredicateAccumulate { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPredicateAccumulate") + .field("left", &support::DebugSyntaxResult(self.left())) + .field( + "add_assign_token", + &support::DebugSyntaxResult(self.add_assign_token()), + ) + .field("right", &support::DebugSyntaxResult(self.right())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPredicateAccumulate) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPredicateAccumulate) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPredicateAnd { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PREDICATE_AND as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PREDICATE_AND + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPredicateAnd { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPredicateAnd") + .field( + "and_token", + &support::DebugOptionalElement(self.and_token()), + ) + .field( + "l_curly_token", + &support::DebugSyntaxResult(self.l_curly_token()), + ) + .field("predicates", &self.predicates()) + .field( + "r_curly_token", + &support::DebugSyntaxResult(self.r_curly_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPredicateAnd) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPredicateAnd) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPredicateAny { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PREDICATE_ANY as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PREDICATE_ANY + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPredicateAny { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPredicateAny") + .field("any_token", &support::DebugSyntaxResult(self.any_token())) + .field( + "l_curly_token", + &support::DebugSyntaxResult(self.l_curly_token()), + ) + .field("predicates", &self.predicates()) + .field( + "r_curly_token", + &support::DebugSyntaxResult(self.r_curly_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPredicateAny) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPredicateAny) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPredicateAssignment { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PREDICATE_ASSIGNMENT as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PREDICATE_ASSIGNMENT + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPredicateAssignment { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPredicateAssignment") + .field("container", &support::DebugSyntaxResult(self.container())) + .field("eq_token", &support::DebugSyntaxResult(self.eq_token())) + .field("pattern", &support::DebugSyntaxResult(self.pattern())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPredicateAssignment) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPredicateAssignment) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPredicateCall { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PREDICATE_CALL as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PREDICATE_CALL + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPredicateCall { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPredicateCall") + .field("name", &support::DebugSyntaxResult(self.name())) + .field( + "l_paren_token", + &support::DebugSyntaxResult(self.l_paren_token()), + ) + .field("named_args", &self.named_args()) + .field( + "r_paren_token", + &support::DebugSyntaxResult(self.r_paren_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPredicateCall) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPredicateCall) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPredicateDefinition { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PREDICATE_DEFINITION as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PREDICATE_DEFINITION + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPredicateDefinition { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPredicateDefinition") + .field( + "predicate_token", + &support::DebugSyntaxResult(self.predicate_token()), + ) + .field("name", &support::DebugSyntaxResult(self.name())) + .field( + "l_paren_token", + &support::DebugSyntaxResult(self.l_paren_token()), + ) + .field("args", &support::DebugOptionalElement(self.args())) + .field( + "r_paren_token", + &support::DebugSyntaxResult(self.r_paren_token()), + ) + .field("body", &support::DebugSyntaxResult(self.body())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPredicateDefinition) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPredicateDefinition) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPredicateElseClause { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PREDICATE_ELSE_CLAUSE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PREDICATE_ELSE_CLAUSE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPredicateElseClause { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPredicateElseClause") + .field("else_token", &support::DebugSyntaxResult(self.else_token())) + .field( + "else_predicate", + &support::DebugSyntaxResult(self.else_predicate()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPredicateElseClause) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPredicateElseClause) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPredicateEqual { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PREDICATE_EQUAL as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PREDICATE_EQUAL + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPredicateEqual { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPredicateEqual") + .field("left", &support::DebugSyntaxResult(self.left())) + .field( + "equality_token", + &support::DebugSyntaxResult(self.equality_token()), + ) + .field("right", &support::DebugSyntaxResult(self.right())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPredicateEqual) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPredicateEqual) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPredicateGreater { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PREDICATE_GREATER as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PREDICATE_GREATER + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPredicateGreater { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPredicateGreater") + .field("left", &support::DebugSyntaxResult(self.left())) + .field( + "r_angle_token", + &support::DebugSyntaxResult(self.r_angle_token()), + ) + .field("right", &support::DebugSyntaxResult(self.right())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPredicateGreater) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPredicateGreater) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPredicateGreaterEqual { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PREDICATE_GREATER_EQUAL as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PREDICATE_GREATER_EQUAL + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPredicateGreaterEqual { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPredicateGreaterEqual") + .field("left", &support::DebugSyntaxResult(self.left())) + .field( + "greater_than_equal_token", + &support::DebugSyntaxResult(self.greater_than_equal_token()), + ) + .field("right", &support::DebugSyntaxResult(self.right())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPredicateGreaterEqual) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPredicateGreaterEqual) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPredicateIfElse { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PREDICATE_IF_ELSE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PREDICATE_IF_ELSE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPredicateIfElse { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPredicateIfElse") + .field("if_token", &support::DebugSyntaxResult(self.if_token())) + .field( + "l_paren_token", + &support::DebugSyntaxResult(self.l_paren_token()), + ) + .field( + "if_predicate", + &support::DebugSyntaxResult(self.if_predicate()), + ) + .field( + "r_paren_token", + &support::DebugSyntaxResult(self.r_paren_token()), + ) + .field( + "then_predicate", + &support::DebugSyntaxResult(self.then_predicate()), + ) + .field( + "grit_predicate_else_clause", + &support::DebugOptionalElement(self.grit_predicate_else_clause()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPredicateIfElse) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPredicateIfElse) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPredicateLess { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PREDICATE_LESS as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PREDICATE_LESS + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPredicateLess { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPredicateLess") + .field("left", &support::DebugSyntaxResult(self.left())) + .field( + "l_angle_token", + &support::DebugSyntaxResult(self.l_angle_token()), + ) + .field("right", &support::DebugSyntaxResult(self.right())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPredicateLess) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPredicateLess) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPredicateLessEqual { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PREDICATE_LESS_EQUAL as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PREDICATE_LESS_EQUAL + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPredicateLessEqual { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPredicateLessEqual") + .field("left", &support::DebugSyntaxResult(self.left())) + .field( + "less_than_equal_token", + &support::DebugSyntaxResult(self.less_than_equal_token()), + ) + .field("right", &support::DebugSyntaxResult(self.right())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPredicateLessEqual) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPredicateLessEqual) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPredicateMatch { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PREDICATE_MATCH as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PREDICATE_MATCH + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPredicateMatch { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPredicateMatch") + .field("left", &support::DebugSyntaxResult(self.left())) + .field( + "match_token", + &support::DebugSyntaxResult(self.match_token()), + ) + .field("right", &support::DebugSyntaxResult(self.right())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPredicateMatch) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPredicateMatch) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPredicateMaybe { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PREDICATE_MAYBE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PREDICATE_MAYBE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPredicateMaybe { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPredicateMaybe") + .field( + "maybe_token", + &support::DebugSyntaxResult(self.maybe_token()), + ) + .field("predicate", &support::DebugSyntaxResult(self.predicate())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPredicateMaybe) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPredicateMaybe) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPredicateNot { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PREDICATE_NOT as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PREDICATE_NOT + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPredicateNot { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPredicateNot") + .field("grit_not", &support::DebugSyntaxResult(self.grit_not())) + .field("predicate", &support::DebugSyntaxResult(self.predicate())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPredicateNot) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPredicateNot) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPredicateNotEqual { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PREDICATE_NOT_EQUAL as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PREDICATE_NOT_EQUAL + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPredicateNotEqual { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPredicateNotEqual") + .field("left", &support::DebugSyntaxResult(self.left())) + .field( + "inequality_token", + &support::DebugSyntaxResult(self.inequality_token()), + ) + .field("right", &support::DebugSyntaxResult(self.right())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPredicateNotEqual) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPredicateNotEqual) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPredicateOr { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PREDICATE_OR as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PREDICATE_OR + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPredicateOr { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPredicateOr") + .field("or_token", &support::DebugSyntaxResult(self.or_token())) + .field( + "l_curly_token", + &support::DebugSyntaxResult(self.l_curly_token()), + ) + .field("predicates", &self.predicates()) + .field( + "r_curly_token", + &support::DebugSyntaxResult(self.r_curly_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPredicateOr) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPredicateOr) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPredicateReturn { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PREDICATE_RETURN as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PREDICATE_RETURN + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPredicateReturn { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPredicateReturn") + .field( + "return_token", + &support::DebugSyntaxResult(self.return_token()), + ) + .field("pattern", &support::DebugSyntaxResult(self.pattern())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPredicateReturn) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPredicateReturn) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritPredicateRewrite { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PREDICATE_REWRITE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PREDICATE_REWRITE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritPredicateRewrite { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritPredicateRewrite") + .field("left", &support::DebugSyntaxResult(self.left())) + .field( + "annotation", + &support::DebugOptionalElement(self.annotation()), + ) + .field( + "fat_arrow_token", + &support::DebugSyntaxResult(self.fat_arrow_token()), + ) + .field("right", &support::DebugSyntaxResult(self.right())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritPredicateRewrite) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritPredicateRewrite) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritRawBacktickSnippet { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_RAW_BACKTICK_SNIPPET as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_RAW_BACKTICK_SNIPPET + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritRawBacktickSnippet { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritRawBacktickSnippet") + .field( + "value_token", + &support::DebugSyntaxResult(self.value_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritRawBacktickSnippet) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritRawBacktickSnippet) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritRegexLiteral { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_REGEX_LITERAL as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_REGEX_LITERAL + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritRegexLiteral { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritRegexLiteral") + .field( + "value_token", + &support::DebugSyntaxResult(self.value_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritRegexLiteral) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritRegexLiteral) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritRegexPattern { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_REGEX_PATTERN as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_REGEX_PATTERN + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritRegexPattern { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritRegexPattern") + .field("regex", &support::DebugSyntaxResult(self.regex())) + .field( + "variables", + &support::DebugOptionalElement(self.variables()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritRegexPattern) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritRegexPattern) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritRegexPatternVariables { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_REGEX_PATTERN_VARIABLES as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_REGEX_PATTERN_VARIABLES + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritRegexPatternVariables { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritRegexPatternVariables") + .field( + "l_paren_token", + &support::DebugSyntaxResult(self.l_paren_token()), + ) + .field( + "grit_pattern_arg_list", + &support::DebugOptionalElement(self.grit_pattern_arg_list()), + ) + .field( + "r_paren_token", + &support::DebugSyntaxResult(self.r_paren_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritRegexPatternVariables) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritRegexPatternVariables) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritRewrite { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_REWRITE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_REWRITE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritRewrite { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritRewrite") + .field("left", &support::DebugSyntaxResult(self.left())) + .field( + "annotation", + &support::DebugOptionalElement(self.annotation()), + ) + .field( + "fat_arrow_token", + &support::DebugSyntaxResult(self.fat_arrow_token()), + ) + .field("right", &support::DebugSyntaxResult(self.right())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritRewrite) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritRewrite) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritRoot { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_ROOT as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_ROOT + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritRoot { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritRoot") + .field("version", &support::DebugOptionalElement(self.version())) + .field("language", &support::DebugOptionalElement(self.language())) + .field("definitions", &self.definitions()) + .field("pattern", &support::DebugOptionalElement(self.pattern())) + .field("definitions_continued", &self.definitions_continued()) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritRoot) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritRoot) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritSequential { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_SEQUENTIAL as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_SEQUENTIAL + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritSequential { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritSequential") + .field( + "sequential_token", + &support::DebugSyntaxResult(self.sequential_token()), + ) + .field( + "l_curly_token", + &support::DebugSyntaxResult(self.l_curly_token()), + ) + .field("sequential", &self.sequential()) + .field( + "r_curly_token", + &support::DebugSyntaxResult(self.r_curly_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritSequential) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritSequential) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritSignedIntLiteral { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_SIGNED_INT_LITERAL as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_SIGNED_INT_LITERAL + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritSignedIntLiteral { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritSignedIntLiteral") + .field( + "value_token", + &support::DebugSyntaxResult(self.value_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritSignedIntLiteral) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritSignedIntLiteral) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritSnippetRegex { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_SNIPPET_REGEX as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_SNIPPET_REGEX + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritSnippetRegex { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritSnippetRegex") + .field( + "value_token", + &support::DebugSyntaxResult(self.value_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritSnippetRegex) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritSnippetRegex) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritSome { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_SOME as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_SOME + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritSome { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritSome") + .field("some_token", &support::DebugSyntaxResult(self.some_token())) + .field("pattern", &support::DebugSyntaxResult(self.pattern())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritSome) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritSome) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritStringLiteral { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_STRING_LITERAL as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_STRING_LITERAL + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritStringLiteral { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritStringLiteral") + .field( + "value_token", + &support::DebugSyntaxResult(self.value_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritStringLiteral) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritStringLiteral) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritSubOperation { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_SUB_OPERATION as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_SUB_OPERATION + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritSubOperation { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritSubOperation") + .field("left", &support::DebugSyntaxResult(self.left())) + .field( + "minus_token", + &support::DebugSyntaxResult(self.minus_token()), + ) + .field("right", &support::DebugSyntaxResult(self.right())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritSubOperation) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritSubOperation) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritUndefined { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_UNDEFINED as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_UNDEFINED + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritUndefined { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritUndefined") + .field( + "undefined_token", + &support::DebugSyntaxResult(self.undefined_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritUndefined) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritUndefined) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritUnderscore { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_UNDERSCORE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_UNDERSCORE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritUnderscore { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritUnderscore") + .field( + "dollar_underscore_token", + &support::DebugSyntaxResult(self.dollar_underscore_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritUnderscore) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritUnderscore) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritVariable { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_VARIABLE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_VARIABLE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritVariable { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritVariable") + .field( + "grit_variable_token", + &support::DebugSyntaxResult(self.grit_variable_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritVariable) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritVariable) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritVersion { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_VERSION as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_VERSION + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritVersion { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritVersion") + .field( + "engine_token", + &support::DebugSyntaxResult(self.engine_token()), + ) + .field( + "biome_token", + &support::DebugSyntaxResult(self.biome_token()), + ) + .field( + "l_paren_token", + &support::DebugSyntaxResult(self.l_paren_token()), + ) + .field( + "grit_double_literal", + &support::DebugSyntaxResult(self.grit_double_literal()), + ) + .field( + "r_paren_token", + &support::DebugSyntaxResult(self.r_paren_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritVersion) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritVersion) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for GritWithin { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_WITHIN as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_WITHIN + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritWithin { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritWithin") + .field( + "within_token", + &support::DebugSyntaxResult(self.within_token()), + ) + .field("pattern", &support::DebugSyntaxResult(self.pattern())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritWithin) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritWithin) -> SyntaxElement { + n.syntax.into() + } +} +impl From for AnyGritContainer { + fn from(node: GritListAccessor) -> AnyGritContainer { + AnyGritContainer::GritListAccessor(node) + } +} +impl From for AnyGritContainer { + fn from(node: GritMapAccessor) -> AnyGritContainer { + AnyGritContainer::GritMapAccessor(node) + } +} +impl From for AnyGritContainer { + fn from(node: GritVariable) -> AnyGritContainer { + AnyGritContainer::GritVariable(node) + } +} +impl AstNode for AnyGritContainer { + type Language = Language; + const KIND_SET: SyntaxKindSet = GritListAccessor::KIND_SET + .union(GritMapAccessor::KIND_SET) + .union(GritVariable::KIND_SET); + fn can_cast(kind: SyntaxKind) -> bool { + matches!(kind, GRIT_LIST_ACCESSOR | GRIT_MAP_ACCESSOR | GRIT_VARIABLE) + } + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + GRIT_LIST_ACCESSOR => AnyGritContainer::GritListAccessor(GritListAccessor { syntax }), + GRIT_MAP_ACCESSOR => AnyGritContainer::GritMapAccessor(GritMapAccessor { syntax }), + GRIT_VARIABLE => AnyGritContainer::GritVariable(GritVariable { syntax }), + _ => return None, + }; + Some(res) + } + fn syntax(&self) -> &SyntaxNode { + match self { + AnyGritContainer::GritListAccessor(it) => &it.syntax, + AnyGritContainer::GritMapAccessor(it) => &it.syntax, + AnyGritContainer::GritVariable(it) => &it.syntax, + } + } + fn into_syntax(self) -> SyntaxNode { + match self { + AnyGritContainer::GritListAccessor(it) => it.syntax, + AnyGritContainer::GritMapAccessor(it) => it.syntax, + AnyGritContainer::GritVariable(it) => it.syntax, + } + } +} +impl std::fmt::Debug for AnyGritContainer { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + AnyGritContainer::GritListAccessor(it) => std::fmt::Debug::fmt(it, f), + AnyGritContainer::GritMapAccessor(it) => std::fmt::Debug::fmt(it, f), + AnyGritContainer::GritVariable(it) => std::fmt::Debug::fmt(it, f), + } + } +} +impl From for SyntaxNode { + fn from(n: AnyGritContainer) -> SyntaxNode { + match n { + AnyGritContainer::GritListAccessor(it) => it.into(), + AnyGritContainer::GritMapAccessor(it) => it.into(), + AnyGritContainer::GritVariable(it) => it.into(), + } + } +} +impl From for SyntaxElement { + fn from(n: AnyGritContainer) -> SyntaxElement { + let node: SyntaxNode = n.into(); + node.into() + } +} +impl From for AnyGritDefinition { + fn from(node: GritBogusDefinition) -> AnyGritDefinition { + AnyGritDefinition::GritBogusDefinition(node) + } +} +impl From for AnyGritDefinition { + fn from(node: GritFunctionDefinition) -> AnyGritDefinition { + AnyGritDefinition::GritFunctionDefinition(node) + } +} +impl From for AnyGritDefinition { + fn from(node: GritPatternDefinition) -> AnyGritDefinition { + AnyGritDefinition::GritPatternDefinition(node) + } +} +impl From for AnyGritDefinition { + fn from(node: GritPredicateDefinition) -> AnyGritDefinition { + AnyGritDefinition::GritPredicateDefinition(node) + } +} +impl AstNode for AnyGritDefinition { + type Language = Language; + const KIND_SET: SyntaxKindSet = GritBogusDefinition::KIND_SET + .union(GritFunctionDefinition::KIND_SET) + .union(GritPatternDefinition::KIND_SET) + .union(GritPredicateDefinition::KIND_SET); + fn can_cast(kind: SyntaxKind) -> bool { + matches!( + kind, + GRIT_BOGUS_DEFINITION + | GRIT_FUNCTION_DEFINITION + | GRIT_PATTERN_DEFINITION + | GRIT_PREDICATE_DEFINITION + ) + } + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + GRIT_BOGUS_DEFINITION => { + AnyGritDefinition::GritBogusDefinition(GritBogusDefinition { syntax }) + } + GRIT_FUNCTION_DEFINITION => { + AnyGritDefinition::GritFunctionDefinition(GritFunctionDefinition { syntax }) + } + GRIT_PATTERN_DEFINITION => { + AnyGritDefinition::GritPatternDefinition(GritPatternDefinition { syntax }) + } + GRIT_PREDICATE_DEFINITION => { + AnyGritDefinition::GritPredicateDefinition(GritPredicateDefinition { syntax }) + } + _ => return None, + }; + Some(res) + } + fn syntax(&self) -> &SyntaxNode { + match self { + AnyGritDefinition::GritBogusDefinition(it) => &it.syntax, + AnyGritDefinition::GritFunctionDefinition(it) => &it.syntax, + AnyGritDefinition::GritPatternDefinition(it) => &it.syntax, + AnyGritDefinition::GritPredicateDefinition(it) => &it.syntax, + } + } + fn into_syntax(self) -> SyntaxNode { + match self { + AnyGritDefinition::GritBogusDefinition(it) => it.syntax, + AnyGritDefinition::GritFunctionDefinition(it) => it.syntax, + AnyGritDefinition::GritPatternDefinition(it) => it.syntax, + AnyGritDefinition::GritPredicateDefinition(it) => it.syntax, + } + } +} +impl std::fmt::Debug for AnyGritDefinition { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + AnyGritDefinition::GritBogusDefinition(it) => std::fmt::Debug::fmt(it, f), + AnyGritDefinition::GritFunctionDefinition(it) => std::fmt::Debug::fmt(it, f), + AnyGritDefinition::GritPatternDefinition(it) => std::fmt::Debug::fmt(it, f), + AnyGritDefinition::GritPredicateDefinition(it) => std::fmt::Debug::fmt(it, f), + } + } +} +impl From for SyntaxNode { + fn from(n: AnyGritDefinition) -> SyntaxNode { + match n { + AnyGritDefinition::GritBogusDefinition(it) => it.into(), + AnyGritDefinition::GritFunctionDefinition(it) => it.into(), + AnyGritDefinition::GritPatternDefinition(it) => it.into(), + AnyGritDefinition::GritPredicateDefinition(it) => it.into(), + } + } +} +impl From for SyntaxElement { + fn from(n: AnyGritDefinition) -> SyntaxElement { + let node: SyntaxNode = n.into(); + node.into() + } +} +impl From for AnyGritListPattern { + fn from(node: AnyGritPattern) -> AnyGritListPattern { + AnyGritListPattern::AnyGritPattern(node) + } +} +impl From for AnyGritListPattern { + fn from(node: GritDotdotdot) -> AnyGritListPattern { + AnyGritListPattern::GritDotdotdot(node) + } +} +impl AstNode for AnyGritListPattern { + type Language = Language; + const KIND_SET: SyntaxKindSet = + AnyGritPattern::KIND_SET.union(GritDotdotdot::KIND_SET); + fn can_cast(kind: SyntaxKind) -> bool { + matches!(kind, ANY_GRIT_PATTERN | GRIT_DOTDOTDOT) + } + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + ANY_GRIT_PATTERN => AnyGritListPattern::AnyGritPattern(AnyGritPattern { syntax }), + GRIT_DOTDOTDOT => AnyGritListPattern::GritDotdotdot(GritDotdotdot { syntax }), + _ => return None, + }; + Some(res) + } + fn syntax(&self) -> &SyntaxNode { + match self { + AnyGritListPattern::AnyGritPattern(it) => &it.syntax, + AnyGritListPattern::GritDotdotdot(it) => &it.syntax, + } + } + fn into_syntax(self) -> SyntaxNode { + match self { + AnyGritListPattern::AnyGritPattern(it) => it.syntax, + AnyGritListPattern::GritDotdotdot(it) => it.syntax, + } + } +} +impl std::fmt::Debug for AnyGritListPattern { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + AnyGritListPattern::AnyGritPattern(it) => std::fmt::Debug::fmt(it, f), + AnyGritListPattern::GritDotdotdot(it) => std::fmt::Debug::fmt(it, f), + } + } +} +impl From for SyntaxNode { + fn from(n: AnyGritListPattern) -> SyntaxNode { + match n { + AnyGritListPattern::AnyGritPattern(it) => it.into(), + AnyGritListPattern::GritDotdotdot(it) => it.into(), + } + } +} +impl From for SyntaxElement { + fn from(n: AnyGritListPattern) -> SyntaxElement { + let node: SyntaxNode = n.into(); + node.into() + } +} +impl From for AnyGritLiteral { + fn from(node: GritBogusLiteral) -> AnyGritLiteral { + AnyGritLiteral::GritBogusLiteral(node) + } +} +impl From for AnyGritLiteral { + fn from(node: GritBooleanLiteral) -> AnyGritLiteral { + AnyGritLiteral::GritBooleanLiteral(node) + } +} +impl From for AnyGritLiteral { + fn from(node: GritCodeSnippet) -> AnyGritLiteral { + AnyGritLiteral::GritCodeSnippet(node) + } +} +impl From for AnyGritLiteral { + fn from(node: GritDoubleLiteral) -> AnyGritLiteral { + AnyGritLiteral::GritDoubleLiteral(node) + } +} +impl From for AnyGritLiteral { + fn from(node: GritIntLiteral) -> AnyGritLiteral { + AnyGritLiteral::GritIntLiteral(node) + } +} +impl From for AnyGritLiteral { + fn from(node: GritList) -> AnyGritLiteral { + AnyGritLiteral::GritList(node) + } +} +impl From for AnyGritLiteral { + fn from(node: GritMap) -> AnyGritLiteral { + AnyGritLiteral::GritMap(node) + } +} +impl From for AnyGritLiteral { + fn from(node: GritStringLiteral) -> AnyGritLiteral { + AnyGritLiteral::GritStringLiteral(node) + } +} +impl From for AnyGritLiteral { + fn from(node: GritUndefined) -> AnyGritLiteral { + AnyGritLiteral::GritUndefined(node) + } +} +impl AstNode for AnyGritLiteral { + type Language = Language; + const KIND_SET: SyntaxKindSet = GritBogusLiteral::KIND_SET + .union(GritBooleanLiteral::KIND_SET) + .union(GritCodeSnippet::KIND_SET) + .union(GritDoubleLiteral::KIND_SET) + .union(GritIntLiteral::KIND_SET) + .union(GritList::KIND_SET) + .union(GritMap::KIND_SET) + .union(GritStringLiteral::KIND_SET) + .union(GritUndefined::KIND_SET); + fn can_cast(kind: SyntaxKind) -> bool { + matches!( + kind, + GRIT_BOGUS_LITERAL + | GRIT_BOOLEAN_LITERAL + | GRIT_CODE_SNIPPET + | GRIT_DOUBLE_LITERAL + | GRIT_INT_LITERAL + | GRIT_LIST + | GRIT_MAP + | GRIT_STRING_LITERAL + | GRIT_UNDEFINED + ) + } + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + GRIT_BOGUS_LITERAL => AnyGritLiteral::GritBogusLiteral(GritBogusLiteral { syntax }), + GRIT_BOOLEAN_LITERAL => { + AnyGritLiteral::GritBooleanLiteral(GritBooleanLiteral { syntax }) + } + GRIT_CODE_SNIPPET => AnyGritLiteral::GritCodeSnippet(GritCodeSnippet { syntax }), + GRIT_DOUBLE_LITERAL => AnyGritLiteral::GritDoubleLiteral(GritDoubleLiteral { syntax }), + GRIT_INT_LITERAL => AnyGritLiteral::GritIntLiteral(GritIntLiteral { syntax }), + GRIT_LIST => AnyGritLiteral::GritList(GritList { syntax }), + GRIT_MAP => AnyGritLiteral::GritMap(GritMap { syntax }), + GRIT_STRING_LITERAL => AnyGritLiteral::GritStringLiteral(GritStringLiteral { syntax }), + GRIT_UNDEFINED => AnyGritLiteral::GritUndefined(GritUndefined { syntax }), + _ => return None, + }; + Some(res) + } + fn syntax(&self) -> &SyntaxNode { + match self { + AnyGritLiteral::GritBogusLiteral(it) => &it.syntax, + AnyGritLiteral::GritBooleanLiteral(it) => &it.syntax, + AnyGritLiteral::GritCodeSnippet(it) => &it.syntax, + AnyGritLiteral::GritDoubleLiteral(it) => &it.syntax, + AnyGritLiteral::GritIntLiteral(it) => &it.syntax, + AnyGritLiteral::GritList(it) => &it.syntax, + AnyGritLiteral::GritMap(it) => &it.syntax, + AnyGritLiteral::GritStringLiteral(it) => &it.syntax, + AnyGritLiteral::GritUndefined(it) => &it.syntax, + } + } + fn into_syntax(self) -> SyntaxNode { + match self { + AnyGritLiteral::GritBogusLiteral(it) => it.syntax, + AnyGritLiteral::GritBooleanLiteral(it) => it.syntax, + AnyGritLiteral::GritCodeSnippet(it) => it.syntax, + AnyGritLiteral::GritDoubleLiteral(it) => it.syntax, + AnyGritLiteral::GritIntLiteral(it) => it.syntax, + AnyGritLiteral::GritList(it) => it.syntax, + AnyGritLiteral::GritMap(it) => it.syntax, + AnyGritLiteral::GritStringLiteral(it) => it.syntax, + AnyGritLiteral::GritUndefined(it) => it.syntax, + } + } +} +impl std::fmt::Debug for AnyGritLiteral { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + AnyGritLiteral::GritBogusLiteral(it) => std::fmt::Debug::fmt(it, f), + AnyGritLiteral::GritBooleanLiteral(it) => std::fmt::Debug::fmt(it, f), + AnyGritLiteral::GritCodeSnippet(it) => std::fmt::Debug::fmt(it, f), + AnyGritLiteral::GritDoubleLiteral(it) => std::fmt::Debug::fmt(it, f), + AnyGritLiteral::GritIntLiteral(it) => std::fmt::Debug::fmt(it, f), + AnyGritLiteral::GritList(it) => std::fmt::Debug::fmt(it, f), + AnyGritLiteral::GritMap(it) => std::fmt::Debug::fmt(it, f), + AnyGritLiteral::GritStringLiteral(it) => std::fmt::Debug::fmt(it, f), + AnyGritLiteral::GritUndefined(it) => std::fmt::Debug::fmt(it, f), + } + } +} +impl From for SyntaxNode { + fn from(n: AnyGritLiteral) -> SyntaxNode { + match n { + AnyGritLiteral::GritBogusLiteral(it) => it.into(), + AnyGritLiteral::GritBooleanLiteral(it) => it.into(), + AnyGritLiteral::GritCodeSnippet(it) => it.into(), + AnyGritLiteral::GritDoubleLiteral(it) => it.into(), + AnyGritLiteral::GritIntLiteral(it) => it.into(), + AnyGritLiteral::GritList(it) => it.into(), + AnyGritLiteral::GritMap(it) => it.into(), + AnyGritLiteral::GritStringLiteral(it) => it.into(), + AnyGritLiteral::GritUndefined(it) => it.into(), + } + } +} +impl From for SyntaxElement { + fn from(n: AnyGritLiteral) -> SyntaxElement { + let node: SyntaxNode = n.into(); + node.into() + } +} +impl From for AnyGritNamedArg { + fn from(node: GritBogusNamedArg) -> AnyGritNamedArg { + AnyGritNamedArg::GritBogusNamedArg(node) + } +} +impl From for AnyGritNamedArg { + fn from(node: GritNamedArg) -> AnyGritNamedArg { + AnyGritNamedArg::GritNamedArg(node) + } +} +impl From for AnyGritNamedArg { + fn from(node: GritNamedArgWithDefault) -> AnyGritNamedArg { + AnyGritNamedArg::GritNamedArgWithDefault(node) + } +} +impl AstNode for AnyGritNamedArg { + type Language = Language; + const KIND_SET: SyntaxKindSet = GritBogusNamedArg::KIND_SET + .union(GritNamedArg::KIND_SET) + .union(GritNamedArgWithDefault::KIND_SET); + fn can_cast(kind: SyntaxKind) -> bool { + matches!( + kind, + GRIT_BOGUS_NAMED_ARG | GRIT_NAMED_ARG | GRIT_NAMED_ARG_WITH_DEFAULT + ) + } + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + GRIT_BOGUS_NAMED_ARG => { + AnyGritNamedArg::GritBogusNamedArg(GritBogusNamedArg { syntax }) + } + GRIT_NAMED_ARG => AnyGritNamedArg::GritNamedArg(GritNamedArg { syntax }), + GRIT_NAMED_ARG_WITH_DEFAULT => { + AnyGritNamedArg::GritNamedArgWithDefault(GritNamedArgWithDefault { syntax }) + } + _ => return None, + }; + Some(res) + } + fn syntax(&self) -> &SyntaxNode { + match self { + AnyGritNamedArg::GritBogusNamedArg(it) => &it.syntax, + AnyGritNamedArg::GritNamedArg(it) => &it.syntax, + AnyGritNamedArg::GritNamedArgWithDefault(it) => &it.syntax, + } + } + fn into_syntax(self) -> SyntaxNode { + match self { + AnyGritNamedArg::GritBogusNamedArg(it) => it.syntax, + AnyGritNamedArg::GritNamedArg(it) => it.syntax, + AnyGritNamedArg::GritNamedArgWithDefault(it) => it.syntax, + } + } +} +impl std::fmt::Debug for AnyGritNamedArg { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + AnyGritNamedArg::GritBogusNamedArg(it) => std::fmt::Debug::fmt(it, f), + AnyGritNamedArg::GritNamedArg(it) => std::fmt::Debug::fmt(it, f), + AnyGritNamedArg::GritNamedArgWithDefault(it) => std::fmt::Debug::fmt(it, f), + } + } +} +impl From for SyntaxNode { + fn from(n: AnyGritNamedArg) -> SyntaxNode { + match n { + AnyGritNamedArg::GritBogusNamedArg(it) => it.into(), + AnyGritNamedArg::GritNamedArg(it) => it.into(), + AnyGritNamedArg::GritNamedArgWithDefault(it) => it.into(), + } + } +} +impl From for SyntaxElement { + fn from(n: AnyGritNamedArg) -> SyntaxElement { + let node: SyntaxNode = n.into(); + node.into() + } +} +impl From for GritCodeSnippetSource { + fn from(node: GritBacktickSnippet) -> GritCodeSnippetSource { + GritCodeSnippetSource::GritBacktickSnippet(node) + } +} +impl From for GritCodeSnippetSource { + fn from(node: GritLanguageSpecificSnippet) -> GritCodeSnippetSource { + GritCodeSnippetSource::GritLanguageSpecificSnippet(node) + } +} +impl From for GritCodeSnippetSource { + fn from(node: GritRawBacktickSnippet) -> GritCodeSnippetSource { + GritCodeSnippetSource::GritRawBacktickSnippet(node) + } +} +impl AstNode for GritCodeSnippetSource { + type Language = Language; + const KIND_SET: SyntaxKindSet = GritBacktickSnippet::KIND_SET + .union(GritLanguageSpecificSnippet::KIND_SET) + .union(GritRawBacktickSnippet::KIND_SET); + fn can_cast(kind: SyntaxKind) -> bool { + matches!( + kind, + GRIT_BACKTICK_SNIPPET | GRIT_LANGUAGE_SPECIFIC_SNIPPET | GRIT_RAW_BACKTICK_SNIPPET + ) + } + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + GRIT_BACKTICK_SNIPPET => { + GritCodeSnippetSource::GritBacktickSnippet(GritBacktickSnippet { syntax }) + } + GRIT_LANGUAGE_SPECIFIC_SNIPPET => { + GritCodeSnippetSource::GritLanguageSpecificSnippet(GritLanguageSpecificSnippet { + syntax, + }) + } + GRIT_RAW_BACKTICK_SNIPPET => { + GritCodeSnippetSource::GritRawBacktickSnippet(GritRawBacktickSnippet { syntax }) + } + _ => return None, + }; + Some(res) + } + fn syntax(&self) -> &SyntaxNode { + match self { + GritCodeSnippetSource::GritBacktickSnippet(it) => &it.syntax, + GritCodeSnippetSource::GritLanguageSpecificSnippet(it) => &it.syntax, + GritCodeSnippetSource::GritRawBacktickSnippet(it) => &it.syntax, + } + } + fn into_syntax(self) -> SyntaxNode { + match self { + GritCodeSnippetSource::GritBacktickSnippet(it) => it.syntax, + GritCodeSnippetSource::GritLanguageSpecificSnippet(it) => it.syntax, + GritCodeSnippetSource::GritRawBacktickSnippet(it) => it.syntax, + } + } +} +impl std::fmt::Debug for GritCodeSnippetSource { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + GritCodeSnippetSource::GritBacktickSnippet(it) => std::fmt::Debug::fmt(it, f), + GritCodeSnippetSource::GritLanguageSpecificSnippet(it) => std::fmt::Debug::fmt(it, f), + GritCodeSnippetSource::GritRawBacktickSnippet(it) => std::fmt::Debug::fmt(it, f), + } + } +} +impl From for SyntaxNode { + fn from(n: GritCodeSnippetSource) -> SyntaxNode { + match n { + GritCodeSnippetSource::GritBacktickSnippet(it) => it.into(), + GritCodeSnippetSource::GritLanguageSpecificSnippet(it) => it.into(), + GritCodeSnippetSource::GritRawBacktickSnippet(it) => it.into(), + } + } +} +impl From for SyntaxElement { + fn from(n: GritCodeSnippetSource) -> SyntaxElement { + let node: SyntaxNode = n.into(); + node.into() + } +} +impl From for GritListAccessorSubject { + fn from(node: GritList) -> GritListAccessorSubject { + GritListAccessorSubject::GritList(node) + } +} +impl AstNode for GritListAccessorSubject { + type Language = Language; + const KIND_SET: SyntaxKindSet = AnyGritContainer::KIND_SET.union(GritList::KIND_SET); + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + GRIT_LIST => true, + k if AnyGritContainer::can_cast(k) => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + GRIT_LIST => GritListAccessorSubject::GritList(GritList { syntax }), + _ => { + if let Some(any_grit_container) = AnyGritContainer::cast(syntax) { + return Some(GritListAccessorSubject::AnyGritContainer( + any_grit_container, + )); + } + return None; + } + }; + Some(res) + } + fn syntax(&self) -> &SyntaxNode { + match self { + GritListAccessorSubject::GritList(it) => &it.syntax, + GritListAccessorSubject::AnyGritContainer(it) => it.syntax(), + } + } + fn into_syntax(self) -> SyntaxNode { + match self { + GritListAccessorSubject::GritList(it) => it.syntax, + GritListAccessorSubject::AnyGritContainer(it) => it.into_syntax(), + } + } +} +impl std::fmt::Debug for GritListAccessorSubject { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + GritListAccessorSubject::AnyGritContainer(it) => std::fmt::Debug::fmt(it, f), + GritListAccessorSubject::GritList(it) => std::fmt::Debug::fmt(it, f), + } + } +} +impl From for SyntaxNode { + fn from(n: GritListAccessorSubject) -> SyntaxNode { + match n { + GritListAccessorSubject::AnyGritContainer(it) => it.into(), + GritListAccessorSubject::GritList(it) => it.into(), + } + } +} +impl From for SyntaxElement { + fn from(n: GritListAccessorSubject) -> SyntaxElement { + let node: SyntaxNode = n.into(); + node.into() + } +} +impl From for GritListIndex { + fn from(node: GritSignedIntLiteral) -> GritListIndex { + GritListIndex::GritSignedIntLiteral(node) + } +} +impl AstNode for GritListIndex { + type Language = Language; + const KIND_SET: SyntaxKindSet = + AnyGritContainer::KIND_SET.union(GritSignedIntLiteral::KIND_SET); + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + GRIT_SIGNED_INT_LITERAL => true, + k if AnyGritContainer::can_cast(k) => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + GRIT_SIGNED_INT_LITERAL => { + GritListIndex::GritSignedIntLiteral(GritSignedIntLiteral { syntax }) + } + _ => { + if let Some(any_grit_container) = AnyGritContainer::cast(syntax) { + return Some(GritListIndex::AnyGritContainer(any_grit_container)); + } + return None; + } + }; + Some(res) + } + fn syntax(&self) -> &SyntaxNode { + match self { + GritListIndex::GritSignedIntLiteral(it) => &it.syntax, + GritListIndex::AnyGritContainer(it) => it.syntax(), + } + } + fn into_syntax(self) -> SyntaxNode { + match self { + GritListIndex::GritSignedIntLiteral(it) => it.syntax, + GritListIndex::AnyGritContainer(it) => it.into_syntax(), + } + } +} +impl std::fmt::Debug for GritListIndex { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + GritListIndex::AnyGritContainer(it) => std::fmt::Debug::fmt(it, f), + GritListIndex::GritSignedIntLiteral(it) => std::fmt::Debug::fmt(it, f), + } + } +} +impl From for SyntaxNode { + fn from(n: GritListIndex) -> SyntaxNode { + match n { + GritListIndex::AnyGritContainer(it) => it.into(), + GritListIndex::GritSignedIntLiteral(it) => it.into(), + } + } +} +impl From for SyntaxElement { + fn from(n: GritListIndex) -> SyntaxElement { + let node: SyntaxNode = n.into(); + node.into() + } +} +impl From for GritMapAccessorSubject { + fn from(node: GritMap) -> GritMapAccessorSubject { + GritMapAccessorSubject::GritMap(node) + } +} +impl AstNode for GritMapAccessorSubject { + type Language = Language; + const KIND_SET: SyntaxKindSet = AnyGritContainer::KIND_SET.union(GritMap::KIND_SET); + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + GRIT_MAP => true, + k if AnyGritContainer::can_cast(k) => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + GRIT_MAP => GritMapAccessorSubject::GritMap(GritMap { syntax }), + _ => { + if let Some(any_grit_container) = AnyGritContainer::cast(syntax) { + return Some(GritMapAccessorSubject::AnyGritContainer(any_grit_container)); + } + return None; + } + }; + Some(res) + } + fn syntax(&self) -> &SyntaxNode { + match self { + GritMapAccessorSubject::GritMap(it) => &it.syntax, + GritMapAccessorSubject::AnyGritContainer(it) => it.syntax(), + } + } + fn into_syntax(self) -> SyntaxNode { + match self { + GritMapAccessorSubject::GritMap(it) => it.syntax, + GritMapAccessorSubject::AnyGritContainer(it) => it.into_syntax(), + } + } +} +impl std::fmt::Debug for GritMapAccessorSubject { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + GritMapAccessorSubject::AnyGritContainer(it) => std::fmt::Debug::fmt(it, f), + GritMapAccessorSubject::GritMap(it) => std::fmt::Debug::fmt(it, f), + } + } +} +impl From for SyntaxNode { + fn from(n: GritMapAccessorSubject) -> SyntaxNode { + match n { + GritMapAccessorSubject::AnyGritContainer(it) => it.into(), + GritMapAccessorSubject::GritMap(it) => it.into(), + } + } +} +impl From for SyntaxElement { + fn from(n: GritMapAccessorSubject) -> SyntaxElement { + let node: SyntaxNode = n.into(); + node.into() + } +} +impl From for GritMapKey { + fn from(node: GritName) -> GritMapKey { + GritMapKey::GritName(node) + } +} +impl From for GritMapKey { + fn from(node: GritVariable) -> GritMapKey { + GritMapKey::GritVariable(node) + } +} +impl AstNode for GritMapKey { + type Language = Language; + const KIND_SET: SyntaxKindSet = GritName::KIND_SET.union(GritVariable::KIND_SET); + fn can_cast(kind: SyntaxKind) -> bool { + matches!(kind, GRIT_NAME | GRIT_VARIABLE) + } + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + GRIT_NAME => GritMapKey::GritName(GritName { syntax }), + GRIT_VARIABLE => GritMapKey::GritVariable(GritVariable { syntax }), + _ => return None, + }; + Some(res) + } + fn syntax(&self) -> &SyntaxNode { + match self { + GritMapKey::GritName(it) => &it.syntax, + GritMapKey::GritVariable(it) => &it.syntax, + } + } + fn into_syntax(self) -> SyntaxNode { + match self { + GritMapKey::GritName(it) => it.syntax, + GritMapKey::GritVariable(it) => it.syntax, + } + } +} +impl std::fmt::Debug for GritMapKey { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + GritMapKey::GritName(it) => std::fmt::Debug::fmt(it, f), + GritMapKey::GritVariable(it) => std::fmt::Debug::fmt(it, f), + } + } +} +impl From for SyntaxNode { + fn from(n: GritMapKey) -> SyntaxNode { + match n { + GritMapKey::GritName(it) => it.into(), + GritMapKey::GritVariable(it) => it.into(), + } + } +} +impl From for SyntaxElement { + fn from(n: GritMapKey) -> SyntaxElement { + let node: SyntaxNode = n.into(); + node.into() + } +} +impl AstNode for GritPredicateMatchSubject { + type Language = Language; + const KIND_SET: SyntaxKindSet = + AnyGritContainer::KIND_SET.union(AnyGritLiteral::KIND_SET); + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + k if AnyGritContainer::can_cast(k) => true, + k if AnyGritLiteral::can_cast(k) => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + if let Some(any_grit_container) = AnyGritContainer::cast(syntax.clone()) { + return Some(GritPredicateMatchSubject::AnyGritContainer( + any_grit_container, + )); + } + if let Some(any_grit_literal) = AnyGritLiteral::cast(syntax) { + return Some(GritPredicateMatchSubject::AnyGritLiteral(any_grit_literal)); + } + None + } + fn syntax(&self) -> &SyntaxNode { + match self { + GritPredicateMatchSubject::AnyGritContainer(it) => it.syntax(), + GritPredicateMatchSubject::AnyGritLiteral(it) => it.syntax(), + } + } + fn into_syntax(self) -> SyntaxNode { + match self { + GritPredicateMatchSubject::AnyGritContainer(it) => it.into_syntax(), + GritPredicateMatchSubject::AnyGritLiteral(it) => it.into_syntax(), + } + } +} +impl std::fmt::Debug for GritPredicateMatchSubject { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + GritPredicateMatchSubject::AnyGritContainer(it) => std::fmt::Debug::fmt(it, f), + GritPredicateMatchSubject::AnyGritLiteral(it) => std::fmt::Debug::fmt(it, f), + } + } +} +impl From for SyntaxNode { + fn from(n: GritPredicateMatchSubject) -> SyntaxNode { + match n { + GritPredicateMatchSubject::AnyGritContainer(it) => it.into(), + GritPredicateMatchSubject::AnyGritLiteral(it) => it.into(), + } + } +} +impl From for SyntaxElement { + fn from(n: GritPredicateMatchSubject) -> SyntaxElement { + let node: SyntaxNode = n.into(); + node.into() + } +} +impl From for GritRegex { + fn from(node: GritRegexLiteral) -> GritRegex { + GritRegex::GritRegexLiteral(node) + } +} +impl From for GritRegex { + fn from(node: GritSnippetRegex) -> GritRegex { + GritRegex::GritSnippetRegex(node) + } +} +impl AstNode for GritRegex { + type Language = Language; + const KIND_SET: SyntaxKindSet = + GritRegexLiteral::KIND_SET.union(GritSnippetRegex::KIND_SET); + fn can_cast(kind: SyntaxKind) -> bool { + matches!(kind, GRIT_REGEX_LITERAL | GRIT_SNIPPET_REGEX) + } + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + GRIT_REGEX_LITERAL => GritRegex::GritRegexLiteral(GritRegexLiteral { syntax }), + GRIT_SNIPPET_REGEX => GritRegex::GritSnippetRegex(GritSnippetRegex { syntax }), + _ => return None, + }; + Some(res) + } + fn syntax(&self) -> &SyntaxNode { + match self { + GritRegex::GritRegexLiteral(it) => &it.syntax, + GritRegex::GritSnippetRegex(it) => &it.syntax, + } + } + fn into_syntax(self) -> SyntaxNode { + match self { + GritRegex::GritRegexLiteral(it) => it.syntax, + GritRegex::GritSnippetRegex(it) => it.syntax, + } + } +} +impl std::fmt::Debug for GritRegex { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + GritRegex::GritRegexLiteral(it) => std::fmt::Debug::fmt(it, f), + GritRegex::GritSnippetRegex(it) => std::fmt::Debug::fmt(it, f), + } + } +} +impl From for SyntaxNode { + fn from(n: GritRegex) -> SyntaxNode { + match n { + GritRegex::GritRegexLiteral(it) => it.into(), + GritRegex::GritSnippetRegex(it) => it.into(), + } + } +} +impl From for SyntaxElement { + fn from(n: GritRegex) -> SyntaxElement { + let node: SyntaxNode = n.into(); + node.into() + } +} +impl From for MaybeCurlyGritPattern { + fn from(node: AnyGritPattern) -> MaybeCurlyGritPattern { + MaybeCurlyGritPattern::AnyGritPattern(node) + } +} +impl From for MaybeCurlyGritPattern { + fn from(node: CurlyGritPattern) -> MaybeCurlyGritPattern { + MaybeCurlyGritPattern::CurlyGritPattern(node) + } +} +impl AstNode for MaybeCurlyGritPattern { + type Language = Language; + const KIND_SET: SyntaxKindSet = + AnyGritPattern::KIND_SET.union(CurlyGritPattern::KIND_SET); + fn can_cast(kind: SyntaxKind) -> bool { + matches!(kind, ANY_GRIT_PATTERN | CURLY_GRIT_PATTERN) + } + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + ANY_GRIT_PATTERN => MaybeCurlyGritPattern::AnyGritPattern(AnyGritPattern { syntax }), + CURLY_GRIT_PATTERN => { + MaybeCurlyGritPattern::CurlyGritPattern(CurlyGritPattern { syntax }) + } + _ => return None, + }; + Some(res) + } + fn syntax(&self) -> &SyntaxNode { + match self { + MaybeCurlyGritPattern::AnyGritPattern(it) => &it.syntax, + MaybeCurlyGritPattern::CurlyGritPattern(it) => &it.syntax, + } + } + fn into_syntax(self) -> SyntaxNode { + match self { + MaybeCurlyGritPattern::AnyGritPattern(it) => it.syntax, + MaybeCurlyGritPattern::CurlyGritPattern(it) => it.syntax, + } + } +} +impl std::fmt::Debug for MaybeCurlyGritPattern { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + MaybeCurlyGritPattern::AnyGritPattern(it) => std::fmt::Debug::fmt(it, f), + MaybeCurlyGritPattern::CurlyGritPattern(it) => std::fmt::Debug::fmt(it, f), + } + } +} +impl From for SyntaxNode { + fn from(n: MaybeCurlyGritPattern) -> SyntaxNode { + match n { + MaybeCurlyGritPattern::AnyGritPattern(it) => it.into(), + MaybeCurlyGritPattern::CurlyGritPattern(it) => it.into(), + } + } +} +impl From for SyntaxElement { + fn from(n: MaybeCurlyGritPattern) -> SyntaxElement { + let node: SyntaxNode = n.into(); + node.into() + } +} +impl std::fmt::Display for AnyGritContainer { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for AnyGritDefinition { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for AnyGritListPattern { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for AnyGritLiteral { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for AnyGritNamedArg { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritCodeSnippetSource { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritListAccessorSubject { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritListIndex { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritMapAccessorSubject { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritMapKey { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPredicateMatchSubject { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritRegex { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for MaybeCurlyGritPattern { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for AnyGritPattern { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for AnyGritPredicate { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for CurlyGritPattern { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritAddOperation { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritAnnotation { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritAssignmentAsPattern { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritBacktickSnippet { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritBooleanLiteral { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritBubble { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritBubbleScope { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritCodeSnippet { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritCurlyPredicateList { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritDivOperation { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritDot { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritDotdotdot { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritDoubleLiteral { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritDoubleQuoteSnippet { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritEvery { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritFiles { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritFunctionDefinition { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritIntLiteral { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritLanguageDeclaration { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritLanguageFlavor { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritLanguageFlavorKind { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritLanguageName { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritLanguageSpecificSnippet { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritLike { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritLikeThreshold { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritList { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritListAccessor { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritMap { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritMapAccessor { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritMapElement { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritModOperation { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritMulOperation { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritName { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritNamedArg { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritNamedArgWithDefault { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritNodeLike { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritNot { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPatternAccumulate { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPatternAfter { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPatternAnd { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPatternAny { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPatternArgList { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPatternAs { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPatternBefore { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPatternContains { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPatternContainsUntilClause { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPatternDefinition { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPatternDefinitionBody { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPatternElseClause { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPatternIfElse { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPatternIncludes { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPatternLimit { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPatternMaybe { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPatternNot { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPatternOr { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPatternOrElse { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPatternWhere { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPredicateAccumulate { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPredicateAnd { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPredicateAny { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPredicateAssignment { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPredicateCall { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPredicateDefinition { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPredicateElseClause { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPredicateEqual { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPredicateGreater { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPredicateGreaterEqual { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPredicateIfElse { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPredicateLess { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPredicateLessEqual { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPredicateMatch { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPredicateMaybe { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPredicateNot { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPredicateNotEqual { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPredicateOr { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPredicateReturn { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritPredicateRewrite { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritRawBacktickSnippet { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritRegexLiteral { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritRegexPattern { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritRegexPatternVariables { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritRewrite { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritRoot { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritSequential { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritSignedIntLiteral { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritSnippetRegex { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritSome { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritStringLiteral { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritSubOperation { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritUndefined { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritUnderscore { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritVariable { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritVersion { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for GritWithin { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritBogus { + syntax: SyntaxNode, +} +impl GritBogus { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn items(&self) -> SyntaxElementChildren { + support::elements(&self.syntax) + } +} +impl AstNode for GritBogus { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_BOGUS as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_BOGUS + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritBogus { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritBogus") + .field("items", &DebugSyntaxElementChildren(self.items())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritBogus) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritBogus) -> SyntaxElement { + n.syntax.into() + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritBogusDefinition { + syntax: SyntaxNode, +} +impl GritBogusDefinition { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn items(&self) -> SyntaxElementChildren { + support::elements(&self.syntax) + } +} +impl AstNode for GritBogusDefinition { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_BOGUS_DEFINITION as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_BOGUS_DEFINITION + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritBogusDefinition { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritBogusDefinition") + .field("items", &DebugSyntaxElementChildren(self.items())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritBogusDefinition) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritBogusDefinition) -> SyntaxElement { + n.syntax.into() + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritBogusLiteral { + syntax: SyntaxNode, +} +impl GritBogusLiteral { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn items(&self) -> SyntaxElementChildren { + support::elements(&self.syntax) + } +} +impl AstNode for GritBogusLiteral { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_BOGUS_LITERAL as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_BOGUS_LITERAL + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritBogusLiteral { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritBogusLiteral") + .field("items", &DebugSyntaxElementChildren(self.items())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritBogusLiteral) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritBogusLiteral) -> SyntaxElement { + n.syntax.into() + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritBogusNamedArg { + syntax: SyntaxNode, +} +impl GritBogusNamedArg { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn items(&self) -> SyntaxElementChildren { + support::elements(&self.syntax) + } +} +impl AstNode for GritBogusNamedArg { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_BOGUS_NAMED_ARG as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_BOGUS_NAMED_ARG + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritBogusNamedArg { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritBogusNamedArg") + .field("items", &DebugSyntaxElementChildren(self.items())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritBogusNamedArg) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritBogusNamedArg) -> SyntaxElement { + n.syntax.into() + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritBogusPattern { + syntax: SyntaxNode, +} +impl GritBogusPattern { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn items(&self) -> SyntaxElementChildren { + support::elements(&self.syntax) + } +} +impl AstNode for GritBogusPattern { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_BOGUS_PATTERN as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_BOGUS_PATTERN + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritBogusPattern { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritBogusPattern") + .field("items", &DebugSyntaxElementChildren(self.items())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritBogusPattern) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritBogusPattern) -> SyntaxElement { + n.syntax.into() + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritBogusPredicate { + syntax: SyntaxNode, +} +impl GritBogusPredicate { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn items(&self) -> SyntaxElementChildren { + support::elements(&self.syntax) + } +} +impl AstNode for GritBogusPredicate { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_BOGUS_PREDICATE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_BOGUS_PREDICATE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritBogusPredicate { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritBogusPredicate") + .field("items", &DebugSyntaxElementChildren(self.items())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritBogusPredicate) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritBogusPredicate) -> SyntaxElement { + n.syntax.into() + } +} +#[derive(Clone, Eq, PartialEq, Hash)] +pub struct GritDefinitionList { + syntax_list: SyntaxList, +} +impl GritDefinitionList { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { + syntax_list: syntax.into_list(), + } + } +} +impl AstNode for GritDefinitionList { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_DEFINITION_LIST as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_DEFINITION_LIST + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(GritDefinitionList { + syntax_list: syntax.into_list(), + }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + self.syntax_list.node() + } + fn into_syntax(self) -> SyntaxNode { + self.syntax_list.into_node() + } +} +#[cfg(feature = "serde")] +impl Serialize for GritDefinitionList { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let mut seq = serializer.serialize_seq(Some(self.len()))?; + for e in self.iter() { + seq.serialize_element(&e)?; + } + seq.end() + } +} +impl AstSeparatedList for GritDefinitionList { + type Language = Language; + type Node = AnyGritDefinition; + fn syntax_list(&self) -> &SyntaxList { + &self.syntax_list + } + fn into_syntax_list(self) -> SyntaxList { + self.syntax_list + } +} +impl Debug for GritDefinitionList { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + f.write_str("GritDefinitionList ")?; + f.debug_list().entries(self.elements()).finish() + } +} +impl IntoIterator for GritDefinitionList { + type Item = SyntaxResult; + type IntoIter = AstSeparatedListNodesIterator; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} +impl IntoIterator for &GritDefinitionList { + type Item = SyntaxResult; + type IntoIter = AstSeparatedListNodesIterator; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} +#[derive(Clone, Eq, PartialEq, Hash)] +pub struct GritFilesList { + syntax_list: SyntaxList, +} +impl GritFilesList { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { + syntax_list: syntax.into_list(), + } + } +} +impl AstNode for GritFilesList { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_FILES_LIST as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_FILES_LIST + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(GritFilesList { + syntax_list: syntax.into_list(), + }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + self.syntax_list.node() + } + fn into_syntax(self) -> SyntaxNode { + self.syntax_list.into_node() + } +} +#[cfg(feature = "serde")] +impl Serialize for GritFilesList { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let mut seq = serializer.serialize_seq(Some(self.len()))?; + for e in self.iter() { + seq.serialize_element(&e)?; + } + seq.end() + } +} +impl AstSeparatedList for GritFilesList { + type Language = Language; + type Node = AnyGritPattern; + fn syntax_list(&self) -> &SyntaxList { + &self.syntax_list + } + fn into_syntax_list(self) -> SyntaxList { + self.syntax_list + } +} +impl Debug for GritFilesList { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + f.write_str("GritFilesList ")?; + f.debug_list().entries(self.elements()).finish() + } +} +impl IntoIterator for GritFilesList { + type Item = SyntaxResult; + type IntoIter = AstSeparatedListNodesIterator; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} +impl IntoIterator for &GritFilesList { + type Item = SyntaxResult; + type IntoIter = AstSeparatedListNodesIterator; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} +#[derive(Clone, Eq, PartialEq, Hash)] +pub struct GritLanguageFlavorList { + syntax_list: SyntaxList, +} +impl GritLanguageFlavorList { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { + syntax_list: syntax.into_list(), + } + } +} +impl AstNode for GritLanguageFlavorList { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_LANGUAGE_FLAVOR_LIST as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_LANGUAGE_FLAVOR_LIST + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(GritLanguageFlavorList { + syntax_list: syntax.into_list(), + }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + self.syntax_list.node() + } + fn into_syntax(self) -> SyntaxNode { + self.syntax_list.into_node() + } +} +#[cfg(feature = "serde")] +impl Serialize for GritLanguageFlavorList { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let mut seq = serializer.serialize_seq(Some(self.len()))?; + for e in self.iter() { + seq.serialize_element(&e)?; + } + seq.end() + } +} +impl AstSeparatedList for GritLanguageFlavorList { + type Language = Language; + type Node = GritLanguageFlavorKind; + fn syntax_list(&self) -> &SyntaxList { + &self.syntax_list + } + fn into_syntax_list(self) -> SyntaxList { + self.syntax_list + } +} +impl Debug for GritLanguageFlavorList { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + f.write_str("GritLanguageFlavorList ")?; + f.debug_list().entries(self.elements()).finish() + } +} +impl IntoIterator for GritLanguageFlavorList { + type Item = SyntaxResult; + type IntoIter = AstSeparatedListNodesIterator; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} +impl IntoIterator for &GritLanguageFlavorList { + type Item = SyntaxResult; + type IntoIter = AstSeparatedListNodesIterator; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} +#[derive(Clone, Eq, PartialEq, Hash)] +pub struct GritListPatternList { + syntax_list: SyntaxList, +} +impl GritListPatternList { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { + syntax_list: syntax.into_list(), + } + } +} +impl AstNode for GritListPatternList { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_LIST_PATTERN_LIST as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_LIST_PATTERN_LIST + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(GritListPatternList { + syntax_list: syntax.into_list(), + }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + self.syntax_list.node() + } + fn into_syntax(self) -> SyntaxNode { + self.syntax_list.into_node() + } +} +#[cfg(feature = "serde")] +impl Serialize for GritListPatternList { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let mut seq = serializer.serialize_seq(Some(self.len()))?; + for e in self.iter() { + seq.serialize_element(&e)?; + } + seq.end() + } +} +impl AstSeparatedList for GritListPatternList { + type Language = Language; + type Node = AnyGritListPattern; + fn syntax_list(&self) -> &SyntaxList { + &self.syntax_list + } + fn into_syntax_list(self) -> SyntaxList { + self.syntax_list + } +} +impl Debug for GritListPatternList { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + f.write_str("GritListPatternList ")?; + f.debug_list().entries(self.elements()).finish() + } +} +impl IntoIterator for GritListPatternList { + type Item = SyntaxResult; + type IntoIter = AstSeparatedListNodesIterator; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} +impl IntoIterator for &GritListPatternList { + type Item = SyntaxResult; + type IntoIter = AstSeparatedListNodesIterator; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} +#[derive(Clone, Eq, PartialEq, Hash)] +pub struct GritMapElementList { + syntax_list: SyntaxList, +} +impl GritMapElementList { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { + syntax_list: syntax.into_list(), + } + } +} +impl AstNode for GritMapElementList { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_MAP_ELEMENT_LIST as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_MAP_ELEMENT_LIST + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(GritMapElementList { + syntax_list: syntax.into_list(), + }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + self.syntax_list.node() + } + fn into_syntax(self) -> SyntaxNode { + self.syntax_list.into_node() + } +} +#[cfg(feature = "serde")] +impl Serialize for GritMapElementList { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let mut seq = serializer.serialize_seq(Some(self.len()))?; + for e in self.iter() { + seq.serialize_element(&e)?; + } + seq.end() + } +} +impl AstSeparatedList for GritMapElementList { + type Language = Language; + type Node = GritMapElement; + fn syntax_list(&self) -> &SyntaxList { + &self.syntax_list + } + fn into_syntax_list(self) -> SyntaxList { + self.syntax_list + } +} +impl Debug for GritMapElementList { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + f.write_str("GritMapElementList ")?; + f.debug_list().entries(self.elements()).finish() + } +} +impl IntoIterator for GritMapElementList { + type Item = SyntaxResult; + type IntoIter = AstSeparatedListNodesIterator; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} +impl IntoIterator for &GritMapElementList { + type Item = SyntaxResult; + type IntoIter = AstSeparatedListNodesIterator; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} +#[derive(Clone, Eq, PartialEq, Hash)] +pub struct GritNamedArgList { + syntax_list: SyntaxList, +} +impl GritNamedArgList { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { + syntax_list: syntax.into_list(), + } + } +} +impl AstNode for GritNamedArgList { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_NAMED_ARG_LIST as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_NAMED_ARG_LIST + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(GritNamedArgList { + syntax_list: syntax.into_list(), + }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + self.syntax_list.node() + } + fn into_syntax(self) -> SyntaxNode { + self.syntax_list.into_node() + } +} +#[cfg(feature = "serde")] +impl Serialize for GritNamedArgList { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let mut seq = serializer.serialize_seq(Some(self.len()))?; + for e in self.iter() { + seq.serialize_element(&e)?; + } + seq.end() + } +} +impl AstSeparatedList for GritNamedArgList { + type Language = Language; + type Node = GritNamedArg; + fn syntax_list(&self) -> &SyntaxList { + &self.syntax_list + } + fn into_syntax_list(self) -> SyntaxList { + self.syntax_list + } +} +impl Debug for GritNamedArgList { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + f.write_str("GritNamedArgList ")?; + f.debug_list().entries(self.elements()).finish() + } +} +impl IntoIterator for GritNamedArgList { + type Item = SyntaxResult; + type IntoIter = AstSeparatedListNodesIterator; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} +impl IntoIterator for &GritNamedArgList { + type Item = SyntaxResult; + type IntoIter = AstSeparatedListNodesIterator; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} +#[derive(Clone, Eq, PartialEq, Hash)] +pub struct GritPatternList { + syntax_list: SyntaxList, +} +impl GritPatternList { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { + syntax_list: syntax.into_list(), + } + } +} +impl AstNode for GritPatternList { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PATTERN_LIST as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PATTERN_LIST + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(GritPatternList { + syntax_list: syntax.into_list(), + }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + self.syntax_list.node() + } + fn into_syntax(self) -> SyntaxNode { + self.syntax_list.into_node() + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPatternList { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let mut seq = serializer.serialize_seq(Some(self.len()))?; + for e in self.iter() { + seq.serialize_element(&e)?; + } + seq.end() + } +} +impl AstSeparatedList for GritPatternList { + type Language = Language; + type Node = AnyGritPattern; + fn syntax_list(&self) -> &SyntaxList { + &self.syntax_list + } + fn into_syntax_list(self) -> SyntaxList { + self.syntax_list + } +} +impl Debug for GritPatternList { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + f.write_str("GritPatternList ")?; + f.debug_list().entries(self.elements()).finish() + } +} +impl IntoIterator for GritPatternList { + type Item = SyntaxResult; + type IntoIter = AstSeparatedListNodesIterator; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} +impl IntoIterator for &GritPatternList { + type Item = SyntaxResult; + type IntoIter = AstSeparatedListNodesIterator; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} +#[derive(Clone, Eq, PartialEq, Hash)] +pub struct GritPredicateList { + syntax_list: SyntaxList, +} +impl GritPredicateList { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { + syntax_list: syntax.into_list(), + } + } +} +impl AstNode for GritPredicateList { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_PREDICATE_LIST as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_PREDICATE_LIST + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(GritPredicateList { + syntax_list: syntax.into_list(), + }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + self.syntax_list.node() + } + fn into_syntax(self) -> SyntaxNode { + self.syntax_list.into_node() + } +} +#[cfg(feature = "serde")] +impl Serialize for GritPredicateList { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let mut seq = serializer.serialize_seq(Some(self.len()))?; + for e in self.iter() { + seq.serialize_element(&e)?; + } + seq.end() + } +} +impl AstSeparatedList for GritPredicateList { + type Language = Language; + type Node = AnyGritPredicate; + fn syntax_list(&self) -> &SyntaxList { + &self.syntax_list + } + fn into_syntax_list(self) -> SyntaxList { + self.syntax_list + } +} +impl Debug for GritPredicateList { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + f.write_str("GritPredicateList ")?; + f.debug_list().entries(self.elements()).finish() + } +} +impl IntoIterator for GritPredicateList { + type Item = SyntaxResult; + type IntoIter = AstSeparatedListNodesIterator; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} +impl IntoIterator for &GritPredicateList { + type Item = SyntaxResult; + type IntoIter = AstSeparatedListNodesIterator; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} +#[derive(Clone, Eq, PartialEq, Hash)] +pub struct GritSequentialList { + syntax_list: SyntaxList, +} +impl GritSequentialList { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { + syntax_list: syntax.into_list(), + } + } +} +impl AstNode for GritSequentialList { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_SEQUENTIAL_LIST as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_SEQUENTIAL_LIST + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(GritSequentialList { + syntax_list: syntax.into_list(), + }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + self.syntax_list.node() + } + fn into_syntax(self) -> SyntaxNode { + self.syntax_list.into_node() + } +} +#[cfg(feature = "serde")] +impl Serialize for GritSequentialList { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let mut seq = serializer.serialize_seq(Some(self.len()))?; + for e in self.iter() { + seq.serialize_element(&e)?; + } + seq.end() + } +} +impl AstSeparatedList for GritSequentialList { + type Language = Language; + type Node = AnyGritPattern; + fn syntax_list(&self) -> &SyntaxList { + &self.syntax_list + } + fn into_syntax_list(self) -> SyntaxList { + self.syntax_list + } +} +impl Debug for GritSequentialList { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + f.write_str("GritSequentialList ")?; + f.debug_list().entries(self.elements()).finish() + } +} +impl IntoIterator for GritSequentialList { + type Item = SyntaxResult; + type IntoIter = AstSeparatedListNodesIterator; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} +impl IntoIterator for &GritSequentialList { + type Item = SyntaxResult; + type IntoIter = AstSeparatedListNodesIterator; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} +#[derive(Clone, Eq, PartialEq, Hash)] +pub struct GritVariableList { + syntax_list: SyntaxList, +} +impl GritVariableList { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { + syntax_list: syntax.into_list(), + } + } +} +impl AstNode for GritVariableList { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_VARIABLE_LIST as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_VARIABLE_LIST + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(GritVariableList { + syntax_list: syntax.into_list(), + }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + self.syntax_list.node() + } + fn into_syntax(self) -> SyntaxNode { + self.syntax_list.into_node() + } +} +#[cfg(feature = "serde")] +impl Serialize for GritVariableList { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let mut seq = serializer.serialize_seq(Some(self.len()))?; + for e in self.iter() { + seq.serialize_element(&e)?; + } + seq.end() + } +} +impl AstSeparatedList for GritVariableList { + type Language = Language; + type Node = GritVariable; + fn syntax_list(&self) -> &SyntaxList { + &self.syntax_list + } + fn into_syntax_list(self) -> SyntaxList { + self.syntax_list + } +} +impl Debug for GritVariableList { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + f.write_str("GritVariableList ")?; + f.debug_list().entries(self.elements()).finish() + } +} +impl IntoIterator for GritVariableList { + type Item = SyntaxResult; + type IntoIter = AstSeparatedListNodesIterator; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} +impl IntoIterator for &GritVariableList { + type Item = SyntaxResult; + type IntoIter = AstSeparatedListNodesIterator; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} +#[derive(Clone)] +pub struct DebugSyntaxElementChildren(pub SyntaxElementChildren); +impl Debug for DebugSyntaxElementChildren { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + f.debug_list() + .entries(self.clone().0.map(DebugSyntaxElement)) + .finish() + } +} +struct DebugSyntaxElement(SyntaxElement); +impl Debug for DebugSyntaxElement { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match &self.0 { + SyntaxElement::Node(node) => { + map_syntax_node ! (node . clone () , node => std :: fmt :: Debug :: fmt (& node , f)) + } + SyntaxElement::Token(token) => Debug::fmt(token, f), + } + } +} diff --git a/crates/biome_grit_syntax/src/generated/nodes_mut.rs b/crates/biome_grit_syntax/src/generated/nodes_mut.rs new file mode 100644 index 00000000000..f81caa8979a --- /dev/null +++ b/crates/biome_grit_syntax/src/generated/nodes_mut.rs @@ -0,0 +1,2200 @@ +//! Generated file, do not edit by hand, see `xtask/codegen` + +use crate::{generated::nodes::*, GritSyntaxToken as SyntaxToken}; +use biome_rowan::AstNode; +use std::iter::once; +impl AnyGritPattern { + pub fn with_any_grit_literal(self, element: AnyGritLiteral) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_pattern_not(self, element: GritPatternNot) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_pattern_or(self, element: GritPatternOr) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_pattern_or_else(self, element: GritPatternOrElse) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(3usize..=3usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_pattern_any(self, element: GritPatternAny) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(4usize..=4usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_pattern_and(self, element: GritPatternAnd) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(5usize..=5usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_pattern_maybe(self, element: GritPatternMaybe) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(6usize..=6usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_pattern_if_else(self, element: GritPatternIfElse) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(7usize..=7usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_pattern_contains(self, element: GritPatternContains) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(8usize..=8usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_pattern_includes(self, element: GritPatternIncludes) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(9usize..=9usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_pattern_after(self, element: GritPatternAfter) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(10usize..=10usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_pattern_before(self, element: GritPatternBefore) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(11usize..=11usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_within(self, element: GritWithin) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(12usize..=12usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_bubble(self, element: GritBubble) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(13usize..=13usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_node_like(self, element: GritNodeLike) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(14usize..=14usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_map_accessor(self, element: GritMapAccessor) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(15usize..=15usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_list_accessor(self, element: GritListAccessor) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(16usize..=16usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_dot(self, element: GritDot) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(17usize..=17usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_some(self, element: GritSome) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(18usize..=18usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_every(self, element: GritEvery) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(19usize..=19usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_underscore(self, element: GritUnderscore) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(20usize..=20usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_variable(self, element: GritVariable) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(21usize..=21usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_regex_pattern(self, element: GritRegexPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(22usize..=22usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_pattern_as(self, element: GritPatternAs) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(23usize..=23usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_pattern_limit(self, element: GritPatternLimit) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(24usize..=24usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_assignment_as_pattern(self, element: GritAssignmentAsPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(25usize..=25usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_pattern_accumulate(self, element: GritPatternAccumulate) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(26usize..=26usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_rewrite(self, element: GritRewrite) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(27usize..=27usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_like(self, element: GritLike) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(28usize..=28usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_pattern_where(self, element: GritPatternWhere) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(29usize..=29usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_mul_operation(self, element: GritMulOperation) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(30usize..=30usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_div_operation(self, element: GritDivOperation) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(31usize..=31usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_mod_operation(self, element: GritModOperation) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(32usize..=32usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_add_operation(self, element: GritAddOperation) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(33usize..=33usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_sub_operation(self, element: GritSubOperation) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(34usize..=34usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_sequential(self, element: GritSequential) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(35usize..=35usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_files(self, element: GritFiles) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(36usize..=36usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_l_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(37usize..=37usize, once(Some(element.into()))), + ) + } + pub fn with_any_grit_pattern(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(38usize..=38usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_r_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(39usize..=39usize, once(Some(element.into()))), + ) + } + pub fn with_grit_bogus_pattern(self, element: GritBogusPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(40usize..=40usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl AnyGritPredicate { + pub fn with_grit_predicate_not(self, element: GritPredicateNot) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_predicate_maybe(self, element: GritPredicateMaybe) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_predicate_and(self, element: GritPredicateAnd) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_predicate_or(self, element: GritPredicateOr) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(3usize..=3usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_predicate_any(self, element: GritPredicateAny) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(4usize..=4usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_predicate_if_else(self, element: GritPredicateIfElse) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(5usize..=5usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_predicate_assignment(self, element: GritPredicateAssignment) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(6usize..=6usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_predicate_accumulate(self, element: GritPredicateAccumulate) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(7usize..=7usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_predicate_rewrite(self, element: GritPredicateRewrite) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(8usize..=8usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_predicate_greater(self, element: GritPredicateGreater) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(9usize..=9usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_predicate_less(self, element: GritPredicateLess) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(10usize..=10usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_predicate_greater_equal(self, element: GritPredicateGreaterEqual) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(11usize..=11usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_predicate_less_equal(self, element: GritPredicateLessEqual) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(12usize..=12usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_predicate_not_equal(self, element: GritPredicateNotEqual) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(13usize..=13usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_predicate_equal(self, element: GritPredicateEqual) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(14usize..=14usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_predicate_match(self, element: GritPredicateMatch) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(15usize..=15usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_predicate_call(self, element: GritPredicateCall) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(16usize..=16usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_l_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(17usize..=17usize, once(Some(element.into()))), + ) + } + pub fn with_any_grit_predicate(self, element: AnyGritPredicate) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(18usize..=18usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_r_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(19usize..=19usize, once(Some(element.into()))), + ) + } + pub fn with_grit_boolean_literal(self, element: GritBooleanLiteral) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(20usize..=20usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_predicate_return(self, element: GritPredicateReturn) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(21usize..=21usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_bogus_predicate(self, element: GritBogusPredicate) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(22usize..=22usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl CurlyGritPattern { + pub fn with_l_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_any_grit_pattern(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_r_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into()))), + ) + } +} +impl GritAddOperation { + pub fn with_left(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_plus_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_right(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritAnnotation { + pub fn with_grit_annotation_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } +} +impl GritAssignmentAsPattern { + pub fn with_container(self, element: AnyGritContainer) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_eq_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_pattern(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritBacktickSnippet { + pub fn with_value_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } +} +impl GritBooleanLiteral { + pub fn with_true_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_false_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } +} +impl GritBubble { + pub fn with_bubble_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_variables(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 1usize..=1usize, + once(element.map(|element| element.into_syntax().into())), + )) + } + pub fn with_pattern(self, element: MaybeCurlyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritBubbleScope { + pub fn with_l_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_grit_variable_list(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 1usize..=1usize, + once(element.map(|element| element.into_syntax().into())), + )) + } + pub fn with_r_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into()))), + ) + } +} +impl GritCodeSnippet { + pub fn with_source(self, element: GritCodeSnippetSource) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritCurlyPredicateList { + pub fn with_l_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_predicates(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 1usize..=1usize, + once(element.map(|element| element.into_syntax().into())), + )) + } + pub fn with_r_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into()))), + ) + } +} +impl GritDivOperation { + pub fn with_left(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_slash_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_right(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritDot { + pub fn with_dot_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } +} +impl GritDotdotdot { + pub fn with_dollar_dotdotdot_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_maybe_curly_grit_pattern(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 1usize..=1usize, + once(element.map(|element| element.into_syntax().into())), + )) + } +} +impl GritDoubleLiteral { + pub fn with_value_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } +} +impl GritDoubleQuoteSnippet { + pub fn with_value_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } +} +impl GritEvery { + pub fn with_every_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_pattern(self, element: MaybeCurlyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritFiles { + pub fn with_multifile_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_l_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_files(self, element: GritFilesList) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_r_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(3usize..=3usize, once(Some(element.into()))), + ) + } +} +impl GritFunctionDefinition { + pub fn with_function_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_name(self, element: GritName) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_l_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into()))), + ) + } + pub fn with_args(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 3usize..=3usize, + once(element.map(|element| element.into_syntax().into())), + )) + } + pub fn with_r_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(4usize..=4usize, once(Some(element.into()))), + ) + } + pub fn with_body(self, element: GritCurlyPredicateList) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(5usize..=5usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritIntLiteral { + pub fn with_value_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } +} +impl GritLanguageDeclaration { + pub fn with_language_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_name(self, element: GritLanguageName) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_flavor(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 2usize..=2usize, + once(element.map(|element| element.into_syntax().into())), + )) + } +} +impl GritLanguageFlavor { + pub fn with_l_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_grit_language_flavor_list(self, element: GritLanguageFlavorList) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_r_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into()))), + ) + } + pub fn with_semicolon_token(self, element: Option) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(3usize..=3usize, once(element.map(|element| element.into()))), + ) + } +} +impl GritLanguageFlavorKind { + pub fn with_flavor_kind_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } +} +impl GritLanguageName { + pub fn with_js_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_css_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_json_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into()))), + ) + } + pub fn with_grit_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(3usize..=3usize, once(Some(element.into()))), + ) + } + pub fn with_html_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(4usize..=4usize, once(Some(element.into()))), + ) + } +} +impl GritLanguageSpecificSnippet { + pub fn with_language(self, element: GritLanguageName) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_snippet(self, element: GritDoubleQuoteSnippet) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritLike { + pub fn with_like_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_grit_like_threshold(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 1usize..=1usize, + once(element.map(|element| element.into_syntax().into())), + )) + } + pub fn with_l_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into()))), + ) + } + pub fn with_example(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(3usize..=3usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_r_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(4usize..=4usize, once(Some(element.into()))), + ) + } +} +impl GritLikeThreshold { + pub fn with_l_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_threshold(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_r_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into()))), + ) + } +} +impl GritList { + pub fn with_grit_name(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 0usize..=0usize, + once(element.map(|element| element.into_syntax().into())), + )) + } + pub fn with_l_brack_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_patterns(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 2usize..=2usize, + once(element.map(|element| element.into_syntax().into())), + )) + } + pub fn with_r_brack_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(3usize..=3usize, once(Some(element.into()))), + ) + } +} +impl GritListAccessor { + pub fn with_list(self, element: GritListAccessorSubject) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_l_brack_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_index(self, element: GritListIndex) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_r_brack_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(3usize..=3usize, once(Some(element.into()))), + ) + } +} +impl GritMap { + pub fn with_l_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_elements(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 1usize..=1usize, + once(element.map(|element| element.into_syntax().into())), + )) + } + pub fn with_r_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into()))), + ) + } +} +impl GritMapAccessor { + pub fn with_map(self, element: GritMapAccessorSubject) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_dot_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_key(self, element: GritMapKey) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritMapElement { + pub fn with_key(self, element: GritName) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_colon_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_value(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritModOperation { + pub fn with_left(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_remainder_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_right(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritMulOperation { + pub fn with_left(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_star_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_right(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritName { + pub fn with_grit_name_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } +} +impl GritNamedArg { + pub fn with_name(self, element: GritName) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritNamedArgWithDefault { + pub fn with_name(self, element: GritName) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_eq_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_pattern(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritNodeLike { + pub fn with_name(self, element: GritName) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_l_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_named_args(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 2usize..=2usize, + once(element.map(|element| element.into_syntax().into())), + )) + } + pub fn with_r_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(3usize..=3usize, once(Some(element.into()))), + ) + } +} +impl GritNot { + pub fn with_not_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_excl_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } +} +impl GritPatternAccumulate { + pub fn with_left(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_add_assign_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_right(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritPatternAfter { + pub fn with_after_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_pattern(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritPatternAnd { + pub fn with_and_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_l_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_patterns(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 2usize..=2usize, + once(element.map(|element| element.into_syntax().into())), + )) + } + pub fn with_r_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(3usize..=3usize, once(Some(element.into()))), + ) + } +} +impl GritPatternAny { + pub fn with_any_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_l_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_patterns(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 2usize..=2usize, + once(element.map(|element| element.into_syntax().into())), + )) + } + pub fn with_r_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(3usize..=3usize, once(Some(element.into()))), + ) + } +} +impl GritPatternArgList { + pub fn with_grit_variable_list(self, element: GritVariableList) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritPatternAs { + pub fn with_pattern(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_as_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_variable(self, element: GritVariable) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritPatternBefore { + pub fn with_before_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_pattern(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritPatternContains { + pub fn with_contains_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_contains(self, element: MaybeCurlyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_pattern_contains_until_clause( + self, + element: Option, + ) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 2usize..=2usize, + once(element.map(|element| element.into_syntax().into())), + )) + } +} +impl GritPatternContainsUntilClause { + pub fn with_until_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_until(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritPatternDefinition { + pub fn with_visibility_token(self, element: Option) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(element.map(|element| element.into()))), + ) + } + pub fn with_pattern_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_name(self, element: GritName) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_l_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(3usize..=3usize, once(Some(element.into()))), + ) + } + pub fn with_args(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 4usize..=4usize, + once(element.map(|element| element.into_syntax().into())), + )) + } + pub fn with_r_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(5usize..=5usize, once(Some(element.into()))), + ) + } + pub fn with_language(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 6usize..=6usize, + once(element.map(|element| element.into_syntax().into())), + )) + } + pub fn with_body(self, element: GritPatternDefinitionBody) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(7usize..=7usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritPatternDefinitionBody { + pub fn with_l_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_patterns(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 1usize..=1usize, + once(element.map(|element| element.into_syntax().into())), + )) + } + pub fn with_r_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into()))), + ) + } +} +impl GritPatternElseClause { + pub fn with_else_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_else_pattern(self, element: MaybeCurlyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritPatternIfElse { + pub fn with_if_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_l_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_if_predicate(self, element: AnyGritPredicate) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_r_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(3usize..=3usize, once(Some(element.into()))), + ) + } + pub fn with_then_pattern(self, element: MaybeCurlyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(4usize..=4usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_pattern_else_clause(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 5usize..=5usize, + once(element.map(|element| element.into_syntax().into())), + )) + } +} +impl GritPatternIncludes { + pub fn with_includes_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_includes(self, element: MaybeCurlyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritPatternLimit { + pub fn with_pattern(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_limit_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_limit(self, element: GritIntLiteral) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritPatternMaybe { + pub fn with_maybe_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_pattern(self, element: MaybeCurlyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritPatternNot { + pub fn with_grit_not(self, element: GritNot) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_pattern(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritPatternOr { + pub fn with_or_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_l_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_patterns(self, element: GritPatternList) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_r_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(3usize..=3usize, once(Some(element.into()))), + ) + } +} +impl GritPatternOrElse { + pub fn with_orelse_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_l_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_patterns(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 2usize..=2usize, + once(element.map(|element| element.into_syntax().into())), + )) + } + pub fn with_r_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(3usize..=3usize, once(Some(element.into()))), + ) + } +} +impl GritPatternWhere { + pub fn with_pattern(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_where_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_side_condition(self, element: AnyGritPredicate) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritPredicateAccumulate { + pub fn with_left(self, element: GritVariable) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_add_assign_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_right(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritPredicateAnd { + pub fn with_and_token(self, element: Option) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(element.map(|element| element.into()))), + ) + } + pub fn with_l_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_predicates(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 2usize..=2usize, + once(element.map(|element| element.into_syntax().into())), + )) + } + pub fn with_r_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(3usize..=3usize, once(Some(element.into()))), + ) + } +} +impl GritPredicateAny { + pub fn with_any_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_l_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_predicates(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 2usize..=2usize, + once(element.map(|element| element.into_syntax().into())), + )) + } + pub fn with_r_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(3usize..=3usize, once(Some(element.into()))), + ) + } +} +impl GritPredicateAssignment { + pub fn with_container(self, element: AnyGritContainer) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_eq_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_pattern(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritPredicateCall { + pub fn with_name(self, element: GritName) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_l_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_named_args(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 2usize..=2usize, + once(element.map(|element| element.into_syntax().into())), + )) + } + pub fn with_r_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(3usize..=3usize, once(Some(element.into()))), + ) + } +} +impl GritPredicateDefinition { + pub fn with_predicate_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_name(self, element: GritName) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_l_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into()))), + ) + } + pub fn with_args(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 3usize..=3usize, + once(element.map(|element| element.into_syntax().into())), + )) + } + pub fn with_r_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(4usize..=4usize, once(Some(element.into()))), + ) + } + pub fn with_body(self, element: GritCurlyPredicateList) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(5usize..=5usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritPredicateElseClause { + pub fn with_else_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_else_predicate(self, element: AnyGritPredicate) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritPredicateEqual { + pub fn with_left(self, element: GritVariable) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_equality_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_right(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritPredicateGreater { + pub fn with_left(self, element: GritVariable) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_r_angle_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_right(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritPredicateGreaterEqual { + pub fn with_left(self, element: GritVariable) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_greater_than_equal_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_right(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritPredicateIfElse { + pub fn with_if_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_l_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_if_predicate(self, element: AnyGritPredicate) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_r_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(3usize..=3usize, once(Some(element.into()))), + ) + } + pub fn with_then_predicate(self, element: AnyGritPredicate) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(4usize..=4usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_grit_predicate_else_clause(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 5usize..=5usize, + once(element.map(|element| element.into_syntax().into())), + )) + } +} +impl GritPredicateLess { + pub fn with_left(self, element: GritVariable) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_l_angle_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_right(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritPredicateLessEqual { + pub fn with_left(self, element: GritVariable) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_less_than_equal_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_right(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritPredicateMatch { + pub fn with_left(self, element: GritPredicateMatchSubject) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_match_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_right(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritPredicateMaybe { + pub fn with_maybe_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_predicate(self, element: AnyGritPredicate) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritPredicateNot { + pub fn with_grit_not(self, element: GritNot) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_predicate(self, element: AnyGritPredicate) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritPredicateNotEqual { + pub fn with_left(self, element: GritVariable) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_inequality_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_right(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritPredicateOr { + pub fn with_or_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_l_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_predicates(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 2usize..=2usize, + once(element.map(|element| element.into_syntax().into())), + )) + } + pub fn with_r_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(3usize..=3usize, once(Some(element.into()))), + ) + } +} +impl GritPredicateReturn { + pub fn with_return_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_pattern(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritPredicateRewrite { + pub fn with_left(self, element: GritVariable) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_annotation(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 1usize..=1usize, + once(element.map(|element| element.into_syntax().into())), + )) + } + pub fn with_fat_arrow_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into()))), + ) + } + pub fn with_right(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(3usize..=3usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritRawBacktickSnippet { + pub fn with_value_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } +} +impl GritRegexLiteral { + pub fn with_value_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } +} +impl GritRegexPattern { + pub fn with_regex(self, element: GritRegex) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_variables(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 1usize..=1usize, + once(element.map(|element| element.into_syntax().into())), + )) + } +} +impl GritRegexPatternVariables { + pub fn with_l_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_grit_pattern_arg_list(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 1usize..=1usize, + once(element.map(|element| element.into_syntax().into())), + )) + } + pub fn with_r_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into()))), + ) + } +} +impl GritRewrite { + pub fn with_left(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_annotation(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 1usize..=1usize, + once(element.map(|element| element.into_syntax().into())), + )) + } + pub fn with_fat_arrow_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into()))), + ) + } + pub fn with_right(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(3usize..=3usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritRoot { + pub fn with_version(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 0usize..=0usize, + once(element.map(|element| element.into_syntax().into())), + )) + } + pub fn with_language(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 1usize..=1usize, + once(element.map(|element| element.into_syntax().into())), + )) + } + pub fn with_definitions(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 2usize..=2usize, + once(element.map(|element| element.into_syntax().into())), + )) + } + pub fn with_pattern(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 3usize..=3usize, + once(element.map(|element| element.into_syntax().into())), + )) + } + pub fn with_definitions_continued(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 4usize..=4usize, + once(element.map(|element| element.into_syntax().into())), + )) + } +} +impl GritSequential { + pub fn with_sequential_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_l_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_sequential(self, element: GritSequentialList) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_r_curly_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(3usize..=3usize, once(Some(element.into()))), + ) + } +} +impl GritSignedIntLiteral { + pub fn with_value_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } +} +impl GritSnippetRegex { + pub fn with_value_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } +} +impl GritSome { + pub fn with_some_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_pattern(self, element: MaybeCurlyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritStringLiteral { + pub fn with_value_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } +} +impl GritSubOperation { + pub fn with_left(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_minus_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_right(self, element: AnyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl GritUndefined { + pub fn with_undefined_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } +} +impl GritUnderscore { + pub fn with_dollar_underscore_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } +} +impl GritVariable { + pub fn with_grit_variable_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } +} +impl GritVersion { + pub fn with_engine_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_biome_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_l_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into()))), + ) + } + pub fn with_grit_double_literal(self, element: GritDoubleLiteral) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(3usize..=3usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_r_paren_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(4usize..=4usize, once(Some(element.into()))), + ) + } +} +impl GritWithin { + pub fn with_within_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_pattern(self, element: MaybeCurlyGritPattern) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } +} diff --git a/crates/biome_grit_syntax/src/lib.rs b/crates/biome_grit_syntax/src/lib.rs new file mode 100644 index 00000000000..78362643cf7 --- /dev/null +++ b/crates/biome_grit_syntax/src/lib.rs @@ -0,0 +1,110 @@ +//! A crate for generated Syntax node definitions and utility macros. +//! Both rome_grit_lexer and biome_grit_parser rely on these definitions, therefore +//! they are wrapped in this crate to prevent cyclic dependencies + +#[macro_use] +mod generated; +mod syntax_node; + +use biome_rowan::{AstNode, RawSyntaxKind, TriviaPieceKind}; +pub use generated::*; +pub use syntax_node::*; + +use GritSyntaxKind::*; + +impl From for GritSyntaxKind { + fn from(d: u16) -> GritSyntaxKind { + assert!(d <= (GritSyntaxKind::__LAST as u16)); + unsafe { std::mem::transmute::(d) } + } +} + +impl From for u16 { + fn from(k: GritSyntaxKind) -> u16 { + k as u16 + } +} + +impl GritSyntaxKind { + pub fn is_trivia(self) -> bool { + matches!( + self, + GritSyntaxKind::NEWLINE | GritSyntaxKind::WHITESPACE | GritSyntaxKind::COMMENT + ) + } + + /// Returns `true` for any contextual (await) or non-contextual keyword + #[inline] + pub const fn is_keyword(self) -> bool { + (self as u16) <= (GritSyntaxKind::RETURN_KW as u16) + && (self as u16) >= (GritSyntaxKind::SEQUENTIAL_KW as u16) + } +} + +impl biome_rowan::SyntaxKind for GritSyntaxKind { + const TOMBSTONE: Self = TOMBSTONE; + const EOF: Self = EOF; + + fn is_bogus(&self) -> bool { + matches!( + self, + GRIT_BOGUS + | GRIT_BOGUS_DEFINITION + | GRIT_BOGUS_PATTERN + | GRIT_BOGUS_LITERAL + | GRIT_BOGUS_NAMED_ARG + | GRIT_BOGUS_PREDICATE + ) + } + + fn to_bogus(&self) -> GritSyntaxKind { + match self { + kind if AnyGritDefinition::can_cast(*kind) => GRIT_BOGUS_DEFINITION, + kind if AnyGritPattern::can_cast(*kind) => GRIT_BOGUS_PATTERN, + kind if AnyGritLiteral::can_cast(*kind) => GRIT_BOGUS_LITERAL, + kind if AnyGritNamedArg::can_cast(*kind) => GRIT_BOGUS_NAMED_ARG, + kind if AnyGritPredicate::can_cast(*kind) => GRIT_BOGUS_PREDICATE, + + _ => GRIT_BOGUS, + } + } + + #[inline] + fn to_raw(&self) -> RawSyntaxKind { + RawSyntaxKind(*self as u16) + } + + #[inline] + fn from_raw(raw: RawSyntaxKind) -> Self { + Self::from(raw.0) + } + + fn is_root(&self) -> bool { + GritRoot::can_cast(*self) + } + + fn is_list(&self) -> bool { + GritSyntaxKind::is_list(*self) + } + + fn to_string(&self) -> Option<&'static str> { + GritSyntaxKind::to_string(self) + } +} + +impl TryFrom for TriviaPieceKind { + type Error = (); + + fn try_from(value: GritSyntaxKind) -> Result { + if value.is_trivia() { + match value { + GritSyntaxKind::NEWLINE => Ok(TriviaPieceKind::Newline), + GritSyntaxKind::WHITESPACE => Ok(TriviaPieceKind::Whitespace), + GritSyntaxKind::COMMENT => Ok(TriviaPieceKind::SingleLineComment), + _ => unreachable!("Not Trivia"), + } + } else { + Err(()) + } + } +} diff --git a/crates/biome_grit_syntax/src/syntax_node.rs b/crates/biome_grit_syntax/src/syntax_node.rs new file mode 100644 index 00000000000..c4848b893ec --- /dev/null +++ b/crates/biome_grit_syntax/src/syntax_node.rs @@ -0,0 +1,28 @@ +//! This module defines the Concrete Syntax Tree used by Biome. +//! +//! The tree is entirely lossless, whitespace, comments, and errors are preserved. +//! It also provides traversal methods including parent, children, and siblings of nodes. +//! +//! This is a simple wrapper around the `rowan` crate which does most of the heavy lifting and is language agnostic. + +use crate::{GritRoot, GritSyntaxKind}; +use biome_rowan::Language; +#[cfg(feature = "serde")] +use serde::Serialize; + +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[cfg_attr(feature = "serde", derive(Serialize, schemars::JsonSchema))] +pub struct GritLanguage; + +impl Language for GritLanguage { + type Kind = GritSyntaxKind; + type Root = GritRoot; +} + +pub type GritSyntaxNode = biome_rowan::SyntaxNode; +pub type GritSyntaxToken = biome_rowan::SyntaxToken; +pub type GritSyntaxElement = biome_rowan::SyntaxElement; +pub type GritSyntaxNodeChildren = biome_rowan::SyntaxNodeChildren; +pub type GritSyntaxElementChildren = biome_rowan::SyntaxElementChildren; +pub type GritSyntaxList = biome_rowan::SyntaxList; +pub type GritSyntaxTrivia = biome_rowan::syntax::SyntaxTrivia; diff --git a/xtask/codegen/gritql.ungram b/xtask/codegen/gritql.ungram new file mode 100644 index 00000000000..151ca377ddd --- /dev/null +++ b/xtask/codegen/gritql.ungram @@ -0,0 +1,554 @@ +// GritQL Un-Grammar. +// +// This grammar specifies the structure of Rust's concrete syntax tree. +// It does not specify parsing rules (ambiguities, precedence, etc are out of scope). +// Tokens are processed -- contextual keywords are recognised, compound operators glued. +// +// Legend: +// +// // -- comment +// Name = -- non-terminal definition +// 'ident' -- token (terminal) +// A B -- sequence +// A | B -- alternation +// A* -- zero or more repetition +// (A (',' A)* ','?) -- repetition of node A separated by ',' and allowing a trailing comma +// (A (',' A)*) -- repetition of node A separated by ',' without a trailing comma +// A? -- zero or one repetition +// (A) -- same as A +// label:A -- suggested name for field of AST node + +// NOTES +// +// - SyntaxNode, SyntaxToken and SyntaxElement will be stripped from the codegen +// - Bogus nodes are special nodes used to keep track of broken code; they are +// not part of the grammar but they will appear inside the green tree +// + + +/////////////// +// Bogus NODES +/////////////// +// SyntaxElement is a generic data structure that is meant to track nodes and tokens +// in cases where we care about both types +// +// As Bogus* node will need to yield both tokens and nodes without discrimination, +// and their children will need to yield nodes and tokens as well. +// For this reason, SyntaxElement = SyntaxElement +SyntaxElement = SyntaxElement + +GritBogus = SyntaxElement* +GritBogusDefinition = SyntaxElement* +GritBogusPattern = SyntaxElement* +GritBogusLiteral = SyntaxElement* +GritBogusNamedArg = SyntaxElement* +GritBogusPredicate = SyntaxElement* + +GritRoot = + version: GritVersion? + language: GritLanguageDeclaration? + definitions: GritDefinitionList? + pattern: AnyGritPattern? + definitions_continued: GritDefinitionList? + +GritSequential = 'sequential' '{' sequential: GritSequentialList '}' +GritSequentialList = AnyGritPattern (',' AnyGritPattern)* ','? + +GritFiles = 'multifile' '{' files: GritFilesList '}' +GritFilesList = AnyGritPattern (',' AnyGritPattern)* ','? + +AnyGritDefinition = + GritPatternDefinition + | GritPredicateDefinition + | GritFunctionDefinition + | GritBogusDefinition + +GritDefinitionList = AnyGritDefinition ('newline' AnyGritDefinition)* 'newline'? + +GritVersion = 'engine' 'biome' '(' GritDoubleLiteral ')' + +GritLanguageDeclaration = + 'language' + name: GritLanguageName + flavor: GritLanguageFlavor? + +GritLanguageFlavor = '(' GritLanguageFlavorList ')' ';'? +GritLanguageFlavorList = GritLanguageFlavorKind (',' GritLanguageFlavorKind)* ','? +GritLanguageFlavorKind = + flavor_kind: ( + // JavaScript flavors: + 'typescript' | 'jsx' + // Technically raw JS is supported, but we encourage using typescript in most cases - it will match raw JS fine + | 'js_do_not_use' + ) + +// --- patterns + +AnyGritPattern = + AnyGritLiteral + | GritPatternNot + | GritPatternOr + | GritPatternOrElse + | GritPatternAny + | GritPatternAnd + | GritPatternMaybe + | GritPatternIfElse + | GritPatternContains + | GritPatternIncludes + | GritPatternAfter + | GritPatternBefore + | GritWithin + | GritBubble + | GritNodeLike + | GritMapAccessor + | GritListAccessor + | GritDot + | GritSome + | GritEvery + | GritUnderscore + | GritVariable + | GritRegexPattern + | GritPatternAs + | GritPatternLimit + | GritAssignmentAsPattern + | GritPatternAccumulate + | GritRewrite + | GritLike + | GritPatternWhere + | GritMulOperation + | GritDivOperation + | GritModOperation + | GritAddOperation + | GritSubOperation + | GritSequential + | GritFiles + | '(' AnyGritPattern ')' + | GritBogusPattern + +MaybeCurlyGritPattern = AnyGritPattern | CurlyGritPattern +CurlyGritPattern = '{' AnyGritPattern '}' + +GritPatternList = AnyGritPattern (',' AnyGritPattern)* ','? + +AnyGritContainer = GritVariable | GritMapAccessor | GritListAccessor + +GritMulOperation = + left: AnyGritPattern '*' right: AnyGritPattern +GritDivOperation = + left: AnyGritPattern '/' right: AnyGritPattern +GritModOperation = + left: AnyGritPattern '%' right: AnyGritPattern +GritAddOperation = + left: AnyGritPattern '+' right: AnyGritPattern +GritSubOperation = + left: AnyGritPattern '-' right: AnyGritPattern + +GritPatternAs = + pattern: AnyGritPattern 'as' variable: GritVariable + +GritPatternLimit = + pattern: AnyGritPattern 'limit' limit: GritIntLiteral + +// statement, in the engine this is a predicate that always evaluates to true +// This is useful for initializing variables at the root of a pattern definition +GritAssignmentAsPattern = + container: AnyGritContainer '=' pattern: AnyGritPattern + +// Primarily used for initializing variables at the root of a pattern definition +GritPatternAccumulate = + left: AnyGritPattern '+=' right: AnyGritPattern + +GritPatternWhere = + pattern: AnyGritPattern 'where' side_condition: AnyGritPredicate + +AnyGritLiteral = + GritCodeSnippet + | GritStringLiteral + | GritIntLiteral + | GritDoubleLiteral + | GritBooleanLiteral + | GritUndefined + | GritMap + | GritList + | GritBogusLiteral + +GritPatternNot = + GritNot + pattern: AnyGritPattern + +GritPatternOr = 'or' '{' patterns: GritPatternList '}' + +GritPatternOrElse = 'orelse' '{' patterns: GritPatternList? '}' + +GritPatternAny = 'any' '{' patterns: GritPatternList? '}' + +GritPatternAnd = 'and' '{' patterns: GritPatternList? '}' + +GritPatternMaybe = 'maybe' pattern: MaybeCurlyGritPattern + +GritPatternAfter = 'after' pattern: AnyGritPattern + +GritPatternBefore = 'before' pattern: AnyGritPattern + +GritPatternContains = + 'contains' + contains: MaybeCurlyGritPattern + GritPatternContainsUntilClause? + +GritPatternContainsUntilClause = + 'until' + until: AnyGritPattern + +GritPatternIncludes = 'includes' includes: MaybeCurlyGritPattern + +GritRewrite = + left: AnyGritPattern + annotation: GritAnnotation? + '=>' + right: AnyGritPattern + +// --- conditional pattern ------------ +GritPatternIfElse = + 'if' + '(' + if_predicate: AnyGritPredicate + ')' + then_pattern: MaybeCurlyGritPattern + GritPatternElseClause? + +GritPatternElseClause = + 'else' + else_pattern: MaybeCurlyGritPattern +// --- conditional pattern ------------ + +GritWithin = + 'within' + pattern: MaybeCurlyGritPattern + +GritBubbleScope = '(' GritVariableList? ')' + +GritBubble = + 'bubble' + variables: GritBubbleScope? + pattern: MaybeCurlyGritPattern + +AnyGritNamedArg = + GritNamedArg + | GritNamedArgWithDefault + | GritBogusNamedArg + +GritNamedArg = + name: GritName + +GritNamedArgWithDefault = + name: GritName + '=' + pattern: AnyGritPattern + +GritNamedArgList = GritNamedArg (',' GritNamedArg)* ','? + +// maybe we should have a different fieldname for each choice? +GritNodeLike = + name: GritName + '(' + named_args: GritNamedArgList? + ')' + +GritLike = + 'like' + GritLikeThreshold? + '{' + example: AnyGritPattern + '}' + +GritLikeThreshold = + '(' + threshold: AnyGritPattern + ')' + +GritMap = + '{' + elements: GritMapElementList? + '}' + +GritMapElementList = GritMapElement (',' GritMapElement)* ','? + +GritMapElement = + key: GritName + ':' + value: AnyGritPattern + +GritMapAccessor = + map: GritMapAccessorSubject + '.' + key: GritMapKey + +GritMapAccessorSubject = GritMap | AnyGritContainer +GritMapKey = GritName | GritVariable + +GritList = + GritName? + '[' + patterns: GritListPatternList? + ']' + +GritListPatternList = (AnyGritListPattern (',' AnyGritListPattern)* ','?) + +AnyGritListPattern = AnyGritPattern | GritDotdotdot + +GritListAccessor = + list: GritListAccessorSubject + '[' + index: GritListIndex + ']' + +GritListAccessorSubject = GritList | AnyGritContainer +GritListIndex = AnyGritContainer | GritSignedIntLiteral + +GritDot = '.' + +GritSome = 'some' pattern: MaybeCurlyGritPattern +GritEvery = 'every' pattern: MaybeCurlyGritPattern + +GritDotdotdot = + dollar_dotdotdot: '$...' + MaybeCurlyGritPattern? + +GritUnderscore = + dollar_underscore: '$_' + +GritRegexPattern = + regex: GritRegex + variables: GritRegexPatternVariables? + +GritRegexPatternVariables = + '(' + GritPatternArgList? + ')' + +// node api does not have good support for fields (big sad) +// I double checked by priniting out a JSON stringified +// version of the object and it does not have the necessary +// fields. so in order to hide _pattern we create this intermediate +// value to extract the patternDefinitionBody. +GritPatternDefinitionBody = + '{' + patterns: GritPatternList? + '}' + +GritPatternDefinition = + visibility: 'private'? + 'pattern' + name: GritName + '(' + args: GritPatternArgList? + ')' + language: GritLanguageDeclaration? + body: GritPatternDefinitionBody + +GritPatternArgList = GritVariableList + +GritPredicateList = AnyGritPredicate (',' AnyGritPredicate)* ','? + +GritCurlyPredicateList = + '{' + predicates: GritPredicateList? + '}' + +GritPredicateDefinition = + 'predicate' + name: GritName + '(' + args: GritPatternArgList? + ')' + body: GritCurlyPredicateList + +GritFunctionDefinition = + 'function' + name: GritName + '(' + args: GritVariableList? + ')' + body: GritCurlyPredicateList + +AnyGritPredicate = + GritPredicateNot + | GritPredicateMaybe + | GritPredicateAnd + | GritPredicateOr + | GritPredicateAny + | GritPredicateIfElse + | GritPredicateAssignment + | GritPredicateAccumulate + | GritPredicateRewrite + | GritPredicateGreater + | GritPredicateLess + | GritPredicateGreaterEqual + | GritPredicateLessEqual + | GritPredicateNotEqual + | GritPredicateEqual + | GritPredicateMatch + | GritPredicateCall + | '(' AnyGritPredicate ')' + | GritBooleanLiteral + | GritPredicateReturn + | GritBogusPredicate + +GritPredicateNot = + GritNot + predicate: AnyGritPredicate + +GritPredicateMaybe = + 'maybe' + predicate: AnyGritPredicate + +GritPredicateAnd = + 'and'? + '{' + predicates: GritPredicateList? + '}' + +GritPredicateOr = + 'or' + '{' + predicates: GritPredicateList? + '}' + +GritPredicateAny = + 'any' + '{' + predicates: GritPredicateList? + '}' + +GritPredicateIfElse = + 'if' + '(' + if_predicate: AnyGritPredicate + ')' + then_predicate: AnyGritPredicate + GritPredicateElseClause? + +GritPredicateElseClause = + 'else' + else_predicate: AnyGritPredicate + +GritPredicateRewrite = + left: GritVariable + annotation: GritAnnotation? + '=>' + right: AnyGritPattern + +GritPredicateAssignment = + container: AnyGritContainer + '=' + pattern: AnyGritPattern + +GritPredicateAccumulate = + left: GritVariable + '+=' + right: AnyGritPattern + +GritPredicateGreater = + left: GritVariable + '>' + right: AnyGritPattern + +GritPredicateLess = + left: GritVariable + '<' + right: AnyGritPattern + +GritPredicateGreaterEqual = + left: GritVariable + '>=' + right: AnyGritPattern + +GritPredicateLessEqual = + left: GritVariable + '<=' + right: AnyGritPattern + +GritPredicateNotEqual = + left: GritVariable + '!=' + right: AnyGritPattern + +GritPredicateEqual = + left: GritVariable + '==' + right: AnyGritPattern + +GritPredicateMatch = + left: GritPredicateMatchSubject + match: '<:' + right: AnyGritPattern + +GritPredicateMatchSubject = AnyGritContainer | AnyGritLiteral + +GritPredicateCall = + name: GritName + '(' + named_args: GritNamedArgList? + ')' + +GritPredicateReturn = + 'return' + pattern: AnyGritPattern + +// --- tokens and lexical definitions + +GritBooleanLiteral = 'true' | 'false' + +GritVariable = 'grit_variable' +GritVariableList = GritVariable (',' GritVariable)* ','? + +// name for variables, labels +GritName = 'grit_name' + +// These are target languages +GritLanguageName = + 'js' + | 'css' + | 'json' + | 'grit' + | 'html' + +GritBacktickSnippet = value: 'grit_backtick_snippet' + +GritRawBacktickSnippet = value: 'grit_raw_backtick_snippet' + +GritDoubleQuoteSnippet = value: 'grit_double_quote_snippet' + +GritLanguageSpecificSnippet = + language: GritLanguageName + snippet: GritDoubleQuoteSnippet + +// a code snippet may be prefixed by a label; +// the label may be prefixed by a module or sort name (separated from the label by a dot) +// used to be: /((?:[A-Za-z0-9_]+\.)?[A-Za-z0-9_]*)?`(?:[^`\\]|\\`|\\n)*`/ +GritCodeSnippet = + source: GritCodeSnippetSource + +GritCodeSnippetSource = + GritBacktickSnippet + | GritLanguageSpecificSnippet + | GritRawBacktickSnippet + +GritNot = 'not' | '!' + +GritUndefined = 'undefined' + +GritIntLiteral = value: 'grit_int_literal' +GritSignedIntLiteral = value: 'grit_signed_int_literal' + +GritDoubleLiteral = value: 'grit_double_literal' + +GritStringLiteral = value: 'grit_string_literal' + +GritRegex = GritRegexLiteral | GritSnippetRegex + +GritRegexLiteral = value: 'grit_regex_literal' + +GritSnippetRegex = value: 'grit_snippet_regex_literal' + +GritAnnotation = 'grit_annotation' diff --git a/xtask/codegen/src/ast.rs b/xtask/codegen/src/ast.rs index 6b1900ba277..f746f9106f0 100644 --- a/xtask/codegen/src/ast.rs +++ b/xtask/codegen/src/ast.rs @@ -13,6 +13,7 @@ use crate::css_kinds_src::CSS_KINDS_SRC; use crate::generate_node_factory::generate_node_factory; use crate::generate_nodes_mut::generate_nodes_mut; use crate::generate_syntax_factory::generate_syntax_factory; +use crate::grit_kinds_src::GRIT_KINDS_SRC; use crate::html_kinds_src::HTML_KINDS_SRC; use crate::js_kinds_src::{ AstEnumSrc, AstListSeparatorConfiguration, AstListSrc, AstNodeSrc, TokenKind, JS_KINDS_SRC, @@ -48,10 +49,7 @@ pub fn generate_ast(mode: Mode, language_kind_list: Vec) -> Result<()> { }; for kind in codegen_language_kinds { println_string_with_fg_color( - format!( - "-------------------Generating Grammar for {}-------------------", - kind - ), + format!("-------------------Generating Grammar for {kind}-------------------"), Color::Green, ); let mut ast = load_ast(kind); @@ -62,11 +60,23 @@ pub fn generate_ast(mode: Mode, language_kind_list: Vec) -> Result<()> { Ok(()) } +#[test] +fn generating_gritql() { + let kind = LanguageKind::Grit; + let mut ast = load_ast(kind); + ast.sort(); + match generate_syntax(ast, &Mode::Overwrite, kind) { + Ok(()) => println!("hurray"), + Err(err) => println!("oops {err:?}"), + } +} + pub(crate) fn load_ast(language: LanguageKind) -> AstSrc { match language { LanguageKind::Js => load_js_ast(), LanguageKind::Css => load_css_ast(), LanguageKind::Json => load_json_ast(), + LanguageKind::Grit => load_gritql_ast(), LanguageKind::Html => load_html_ast(), } } @@ -85,6 +95,7 @@ pub(crate) fn generate_syntax(ast: AstSrc, mode: &Mode, language_kind: LanguageK LanguageKind::Js => JS_KINDS_SRC, LanguageKind::Css => CSS_KINDS_SRC, LanguageKind::Json => JSON_KINDS_SRC, + LanguageKind::Grit => GRIT_KINDS_SRC, LanguageKind::Html => HTML_KINDS_SRC, }; @@ -186,6 +197,12 @@ pub(crate) fn load_json_ast() -> AstSrc { make_ast(&grammar) } +pub(crate) fn load_gritql_ast() -> AstSrc { + let grammar_src = include_str!("../gritql.ungram"); + let grammar: Grammar = grammar_src.parse().unwrap(); + make_ast(&grammar) +} + pub(crate) fn load_html_ast() -> AstSrc { let grammar_src = include_str!("../html.ungram"); let grammar: Grammar = grammar_src.parse().unwrap(); diff --git a/xtask/codegen/src/formatter.rs b/xtask/codegen/src/formatter.rs index b5adc3973df..c8dee1b9e29 100644 --- a/xtask/codegen/src/formatter.rs +++ b/xtask/codegen/src/formatter.rs @@ -781,6 +781,21 @@ fn get_node_concept( _ => NodeConcept::Auxiliary, }, + LanguageKind::Grit => match name { + _ if name.starts_with("GritPattern") => NodeConcept::Expression, + + "GritAssignmentAsPattern" | "GritPredicateAssignment" => NodeConcept::Assignment, + + _ if name.ends_with("BacktickSnippet") + || name.ends_with("QuoteSnippet") + || name.ends_with("Literal") => + { + NodeConcept::Value + } + + _ => NodeConcept::Auxiliary, + }, + LanguageKind::Html => match name { _ if name.ends_with("Value") => NodeConcept::Value, _ => NodeConcept::Auxiliary, @@ -846,6 +861,7 @@ impl LanguageKind { LanguageKind::Js => "JsFormatter", LanguageKind::Css => "CssFormatter", LanguageKind::Json => "JsonFormatter", + LanguageKind::Grit => "GritFormatter", LanguageKind::Html => "HtmlFormatter", }; @@ -857,6 +873,7 @@ impl LanguageKind { LanguageKind::Js => "JsFormatContext", LanguageKind::Css => "CssFormatContext", LanguageKind::Json => "JsonFormatContext", + LanguageKind::Grit => "GritFormatContext", LanguageKind::Html => "HtmlFormatContext", }; diff --git a/xtask/codegen/src/generate_nodes.rs b/xtask/codegen/src/generate_nodes.rs index 3302a7e9138..3a29a493997 100644 --- a/xtask/codegen/src/generate_nodes.rs +++ b/xtask/codegen/src/generate_nodes.rs @@ -1,4 +1,5 @@ use crate::css_kinds_src::CSS_KINDS_SRC; +use crate::grit_kinds_src::GRIT_KINDS_SRC; use crate::html_kinds_src::HTML_KINDS_SRC; use crate::js_kinds_src::{AstNodeSrc, AstSrc, Field, TokenKind, JS_KINDS_SRC}; use crate::json_kinds_src::JSON_KINDS_SRC; @@ -962,6 +963,7 @@ pub(crate) fn token_kind_to_code( LanguageKind::Js => JS_KINDS_SRC, LanguageKind::Css => CSS_KINDS_SRC, LanguageKind::Json => JSON_KINDS_SRC, + LanguageKind::Grit => GRIT_KINDS_SRC, LanguageKind::Html => HTML_KINDS_SRC, }; if kind_source.literals.contains(&kind_variant_name.as_str()) @@ -977,7 +979,7 @@ pub(crate) fn token_kind_to_code( } else { // $ is valid syntax in rust and it's part of macros, // so we need to decorate the tokens with quotes - if name == "$=" { + if matches!(name, "$=" | "$..." | "$_") { let token = Literal::string(name); quote! { T![#token] } } else { diff --git a/xtask/codegen/src/generate_syntax_factory.rs b/xtask/codegen/src/generate_syntax_factory.rs index 008c2106615..957e6412d8b 100644 --- a/xtask/codegen/src/generate_syntax_factory.rs +++ b/xtask/codegen/src/generate_syntax_factory.rs @@ -22,6 +22,11 @@ pub fn generate_syntax_factory(ast: &AstSrc, language_kind: LanguageKind) -> Res quote! { JsonSyntaxKind }, quote! { JsonSyntaxFactory }, ), + LanguageKind::Grit => ( + quote! { biome_grit_syntax }, + quote! { GritSyntaxKind }, + quote! { GritSyntaxFactory }, + ), LanguageKind::Html => ( quote! { biome_html_syntax }, quote! { HtmlSyntaxKind }, diff --git a/xtask/codegen/src/generate_syntax_kinds.rs b/xtask/codegen/src/generate_syntax_kinds.rs index 9a956eb7392..bc8123b2f2e 100644 --- a/xtask/codegen/src/generate_syntax_kinds.rs +++ b/xtask/codegen/src/generate_syntax_kinds.rs @@ -12,7 +12,7 @@ pub fn generate_syntax_kinds(grammar: KindsSrc, language_kind: LanguageKind) -> if "{}[]()`".contains(token) { let c = token.chars().next().unwrap(); quote! { #c } - } else if *token == "$=" { + } else if matches!(*token, "$=" | "$..." | "$_") { let token = Literal::string(token); quote! { #token } } else { @@ -122,6 +122,19 @@ pub fn generate_syntax_kinds(grammar: KindsSrc, language_kind: LanguageKind) -> } } } + LanguageKind::Grit => { + quote! { + pub const fn to_string(&self) -> Option<&'static str> { + let tok = match self { + #(#punctuation => #punctuation_strings,)* + #(#full_keywords => #all_keyword_to_strings,)* + GRIT_STRING_LITERAL => "string literal", + _ => return None, + }; + Some(tok) + } + } + } LanguageKind::Html => { quote! { pub const fn to_string(&self) -> Option<&'static str> { diff --git a/xtask/codegen/src/grit_kinds_src.rs b/xtask/codegen/src/grit_kinds_src.rs new file mode 100644 index 00000000000..66400ee74c2 --- /dev/null +++ b/xtask/codegen/src/grit_kinds_src.rs @@ -0,0 +1,226 @@ +//! Definitions for the ECMAScript AST used for codegen +//! Based on the rust analyzer parser and ast definitions + +use crate::kind_src::KindsSrc; + +pub const GRIT_KINDS_SRC: KindsSrc = KindsSrc { + punct: &[ + ("$...", "DOLLAR_DOT3"), + ("$_", "DOLLAR_UNDERSCORE"), + ("<:", "MATCH"), + (";", "SEMICOLON"), + (",", "COMMA"), + ("(", "L_PAREN"), + (")", "R_PAREN"), + ("{", "L_CURLY"), + ("}", "R_CURLY"), + ("[", "L_BRACK"), + ("]", "R_BRACK"), + ("<", "L_ANGLE"), + (">", "R_ANGLE"), + ("+", "PLUS"), + ("*", "STAR"), + ("/", "SLASH"), + ("%", "PERCENT"), + (".", "DOT"), + (":", "COLON"), + ("=", "EQ"), + ("==", "EQ2"), + ("=>", "FAT_ARROW"), + ("!", "BANG"), + ("!=", "NEQ"), + ("-", "MINUS"), + ("<=", "LTEQ"), + (">=", "GTEQ"), + ("+=", "PLUSEQ"), + ("`", "BACKTICK"), + ], + keywords: &[ + // top-level: + "sequential", + "multifile", + "engine", + "biome", + "language", + // languages: + "js", + "css", + "json", + "grit", + "html", + // language flavors: + "typescript", + "jsx", + "js_do_not_use", + // clauses: + "as", + "limit", + "where", + "orelse", + "maybe", + "after", + "before", + "contains", + "until", + "includes", + "if", + "else", + "within", + "bubble", + "not", + // compound patterns: + "or", + "and", + "any", + // matches: + "some", + "every", + // definitions: + "private", + "pattern", + "predicate", + "function", + // values: + "true", + "false", + "undefined", + // other: + "like", + "return", + ], + literals: &[ + "GRIT_INT_LITERAL", + "GRIT_SIGNED_INT_LITERAL", + "GRIT_DOUBLE_LITERAL", + "GRIT_STRING_LITERAL", + "GRIT_REGEX_LITERAL", + "GRIT_SNIPPET_REGEX_LITERAL", + ], + tokens: &[ + "NEWLINE", + "WHITESPACE", + "COMMENT", + "GRIT_ANNOTATION", + "GRIT_BACKTICK_SNIPPET", + "GRIT_RAW_BACKTICK_SNIPPET", + "GRIT_DOUBLE_QUOTE_SNIPPET", + "GRIT_NAME", + "GRIT_VARIABLE", + ], + nodes: &[ + "ANY_GRIT_CONTAINER", + "ANY_GRIT_DEFINITION", + "ANY_GRIT_LIST_PATTERN", + "ANY_GRIT_LITERAL", + "ANY_GRIT_NAMED_ARG", + "ANY_GRIT_PATTERN", + "ANY_GRIT_PREDICATE", + "CURLY_GRIT_PATTERN", + "GRIT_ROOT", + "GRIT_SEQUENTIAL", + "GRIT_SEQUENTIAL_LIST", + "GRIT_FILES", + "GRIT_FILES_LIST", + "GRIT_DEFINITION_LIST", + "GRIT_VERSION", + "GRIT_LANGUAGE_DECLARATION", + "GRIT_LANGUAGE_FLAVOR", + "GRIT_LANGUAGE_FLAVOR_LIST", + "GRIT_LANGUAGE_FLAVOR_KIND", + "GRIT_PATTERN_LIST", + "GRIT_MUL_OPERATION", + "GRIT_DIV_OPERATION", + "GRIT_MOD_OPERATION", + "GRIT_ADD_OPERATION", + "GRIT_SUB_OPERATION", + "GRIT_PATTERN_AS", + "GRIT_PATTERN_LIMIT", + "GRIT_ASSIGNMENT_AS_PATTERN", + "GRIT_PATTERN_ACCUMULATE", + "GRIT_PATTERN_WHERE", + "GRIT_PATTERN_NOT", + "GRIT_PATTERN_OR", + "GRIT_PATTERN_OR_ELSE", + "GRIT_PATTERN_ANY", + "GRIT_PATTERN_AND", + "GRIT_PATTERN_MAYBE", + "GRIT_PATTERN_AFTER", + "GRIT_PATTERN_BEFORE", + "GRIT_PATTERN_CONTAINS", + "GRIT_PATTERN_CONTAINS_UNTIL_CLAUSE", + "GRIT_PATTERN_INCLUDES", + "GRIT_REWRITE", + "GRIT_PATTERN_IF_ELSE", + "GRIT_PATTERN_ELSE_CLAUSE", + "GRIT_WITHIN", + "GRIT_BUBBLE_SCOPE", + "GRIT_BUBBLE", + "GRIT_NAMED_ARG", + "GRIT_NAMED_ARG_WITH_DEFAULT", + "GRIT_NAMED_ARG_LIST", + "GRIT_NODE_LIKE", + "GRIT_LIKE", + "GRIT_LIKE_THRESHOLD", + "GRIT_MAP", + "GRIT_MAP_ELEMENT_LIST", + "GRIT_MAP_ELEMENT", + "GRIT_MAP_ACCESSOR", + "GRIT_MAP_ACCESSOR_SUBJECT", + "GRIT_MAP_KEY", + "GRIT_LIST", + "GRIT_LIST_PATTERN_LIST", + "GRIT_LIST_ACCESSOR", + "GRIT_LIST_ACCESSOR_SUBJECT", + "GRIT_LIST_INDEX", + "GRIT_DOT", + "GRIT_DOTDOTDOT", + "GRIT_SOME", + "GRIT_EVERY", + "GRIT_REGEX_PATTERN", + "GRIT_REGEX_PATTERN_VARIABLES", + "GRIT_PATTERN_DEFINITION_BODY", + "GRIT_PATTERN_DEFINITION", + "GRIT_PATTERN_ARG_LIST", + "GRIT_PREDICATE_LIST", + "GRIT_CURLY_PREDICATE_LIST", + "GRIT_PREDICATE_DEFINITION", + "GRIT_FUNCTION_DEFINITION", + "GRIT_PREDICATE_NOT", + "GRIT_PREDICATE_MAYBE", + "GRIT_PREDICATE_AND", + "GRIT_PREDICATE_OR", + "GRIT_PREDICATE_ANY", + "GRIT_PREDICATE_IF_ELSE", + "GRIT_PREDICATE_ELSE_CLAUSE", + "GRIT_PREDICATE_REWRITE", + "GRIT_PREDICATE_ASSIGNMENT", + "GRIT_PREDICATE_ACCUMULATE", + "GRIT_PREDICATE_GREATER", + "GRIT_PREDICATE_LESS", + "GRIT_PREDICATE_GREATER_EQUAL", + "GRIT_PREDICATE_LESS_EQUAL", + "GRIT_PREDICATE_NOT_EQUAL", + "GRIT_PREDICATE_EQUAL", + "GRIT_PREDICATE_MATCH", + "GRIT_PREDICATE_MATCH_SUBJECT", + "GRIT_PREDICATE_CALL", + "GRIT_PREDICATE_RETURN", + "GRIT_BOOLEAN_LITERAL", + "GRIT_VARIABLE_LIST", + "GRIT_LANGUAGE_NAME", + "GRIT_LANGUAGE_SPECIFIC_SNIPPET", + "GRIT_CODE_SNIPPET", + "GRIT_NOT", + "GRIT_SNIPPET_REGEX", + "GRIT_UNDEFINED", + "GRIT_UNDERSCORE", + "MAYBE_CURLY_GRIT_PATTERN", + // bogus nodes: + "GRIT_BOGUS", + "GRIT_BOGUS_DEFINITION", + "GRIT_BOGUS_PATTERN", + "GRIT_BOGUS_LITERAL", + "GRIT_BOGUS_NAMED_ARG", + "GRIT_BOGUS_PREDICATE", + ], +}; diff --git a/xtask/codegen/src/js_kinds_src.rs b/xtask/codegen/src/js_kinds_src.rs index 3f94315faae..77c5d7dfb22 100644 --- a/xtask/codegen/src/js_kinds_src.rs +++ b/xtask/codegen/src/js_kinds_src.rs @@ -2,6 +2,7 @@ //! Based on the rust analyzer parser and ast definitions use crate::css_kinds_src::CSS_KINDS_SRC; +use crate::grit_kinds_src::GRIT_KINDS_SRC; use crate::html_kinds_src::HTML_KINDS_SRC; use crate::json_kinds_src::JSON_KINDS_SRC; use crate::kind_src::{KindsSrc, LANGUAGE_PREFIXES}; @@ -691,6 +692,7 @@ impl Field { LanguageKind::Js => JS_KINDS_SRC, LanguageKind::Css => CSS_KINDS_SRC, LanguageKind::Json => JSON_KINDS_SRC, + LanguageKind::Grit => GRIT_KINDS_SRC, LanguageKind::Html => HTML_KINDS_SRC, }; diff --git a/xtask/codegen/src/lib.rs b/xtask/codegen/src/lib.rs index d51f0aa0d6c..959a9823b26 100644 --- a/xtask/codegen/src/lib.rs +++ b/xtask/codegen/src/lib.rs @@ -11,6 +11,7 @@ mod generate_nodes; mod generate_nodes_mut; mod generate_syntax_factory; mod generate_syntax_kinds; +mod grit_kinds_src; mod js_kinds_src; mod json_kinds_src; @@ -44,6 +45,7 @@ pub enum LanguageKind { Js, Css, Json, + Grit, Html, } @@ -53,15 +55,17 @@ impl std::fmt::Display for LanguageKind { LanguageKind::Js => write!(f, "js"), LanguageKind::Css => write!(f, "css"), LanguageKind::Json => write!(f, "json"), + LanguageKind::Grit => write!(f, "gritql"), LanguageKind::Html => write!(f, "html"), } } } -pub const ALL_LANGUAGE_KIND: [LanguageKind; 4] = [ +pub const ALL_LANGUAGE_KIND: [LanguageKind; 5] = [ LanguageKind::Js, LanguageKind::Css, LanguageKind::Json, + LanguageKind::Grit, LanguageKind::Html, ]; @@ -73,9 +77,10 @@ impl FromStr for LanguageKind { "js" => Ok(LanguageKind::Js), "css" => Ok(LanguageKind::Css), "json" => Ok(LanguageKind::Json), + "gritql" => Ok(LanguageKind::Grit), "html" => Ok(LanguageKind::Html), _ => Err(format!( - "Language {} not supported, please use: `js`, `css` or `json`", + "Language {} not supported, please use: `js`, `css`, `json`, `gritql` or `html`", kind )), } @@ -92,6 +97,7 @@ impl LanguageKind { LanguageKind::Js => quote! { JsSyntaxKind }, LanguageKind::Css => quote! { CssSyntaxKind }, LanguageKind::Json => quote! { JsonSyntaxKind }, + LanguageKind::Grit => quote! { GritSyntaxKind }, LanguageKind::Html => quote! { HtmlSyntaxKind }, } } @@ -101,6 +107,7 @@ impl LanguageKind { LanguageKind::Js => quote! { JsSyntaxNode }, LanguageKind::Css => quote! { CssSyntaxNode }, LanguageKind::Json => quote! { JsonSyntaxNode }, + LanguageKind::Grit => quote! { GritSyntaxNode }, LanguageKind::Html => quote! { HtmlSyntaxNode }, } } @@ -110,6 +117,7 @@ impl LanguageKind { LanguageKind::Js => quote! { JsSyntaxElement }, LanguageKind::Css => quote! { CssSyntaxElement }, LanguageKind::Json => quote! { JsonSyntaxElement }, + LanguageKind::Grit => quote! { GritSyntaxElement }, LanguageKind::Html => quote! { HtmlSyntaxElement }, } } @@ -119,6 +127,7 @@ impl LanguageKind { LanguageKind::Js => quote! { JsSyntaxToken }, LanguageKind::Css => quote! { CssSyntaxToken }, LanguageKind::Json => quote! { JsonSyntaxToken }, + LanguageKind::Grit => quote! { GritSyntaxToken }, LanguageKind::Html => quote! { HtmlSyntaxToken }, } } @@ -128,6 +137,7 @@ impl LanguageKind { LanguageKind::Js => quote! { JsSyntaxElementChildren }, LanguageKind::Css => quote! { CssSyntaxElementChildren }, LanguageKind::Json => quote! { JsonSyntaxElementChildren }, + LanguageKind::Grit => quote! { GritSyntaxElementChildren }, LanguageKind::Html => quote! { HtmlSyntaxElementChildren }, } } @@ -137,6 +147,7 @@ impl LanguageKind { LanguageKind::Js => quote! { JsSyntaxList }, LanguageKind::Css => quote! { CssSyntaxList }, LanguageKind::Json => quote! { JsonSyntaxList }, + LanguageKind::Grit => quote! { GritSyntaxList }, LanguageKind::Html => quote! { HtmlSyntaxList }, } } @@ -146,6 +157,7 @@ impl LanguageKind { LanguageKind::Js => quote! { JsLanguage }, LanguageKind::Css => quote! { CssLanguage }, LanguageKind::Json => quote! { JsonLanguage }, + LanguageKind::Grit => quote! { GritLanguage }, LanguageKind::Html => quote! { HtmlLanguage }, } } @@ -155,6 +167,7 @@ impl LanguageKind { LanguageKind::Js => "biome_js_formatter", LanguageKind::Css => "biome_css_formatter", LanguageKind::Json => "biome_json_formatter", + LanguageKind::Grit => "biome_grit_formatter", LanguageKind::Html => "biome_html_formatter", } } @@ -164,6 +177,7 @@ impl LanguageKind { LanguageKind::Js => "biome_js_syntax", LanguageKind::Css => "biome_css_syntax", LanguageKind::Json => "biome_json_syntax", + LanguageKind::Grit => "biome_grit_syntax", LanguageKind::Html => "biome_html_syntax", } } @@ -173,6 +187,7 @@ impl LanguageKind { LanguageKind::Js => "biome_js_factory", LanguageKind::Css => "biome_css_factory", LanguageKind::Json => "biome_json_factory", + LanguageKind::Grit => "biome_grit_factory", LanguageKind::Html => "biome_html_factory", } } From a3a0c243959a141a762033866ad99e1d14626b69 Mon Sep 17 00:00:00 2001 From: "Arend van Beelen jr." Date: Wed, 21 Feb 2024 21:07:04 +0100 Subject: [PATCH 02/12] WIP: Lexer --- crates/biome_grit_factory/src/generated.rs | 1 + .../src/generated/node_factory.rs | 12 +- .../src/generated/syntax_factory.rs | 38 +- crates/biome_grit_parser/src/lexer/mod.rs | 868 ++++++++++++++++++ crates/biome_grit_parser/src/lexer/tests.rs | 455 +++++++++ crates/biome_grit_parser/src/lib.rs | 1 + .../biome_grit_syntax/src/generated/kind.rs | 6 +- .../biome_grit_syntax/src/generated/macros.rs | 8 +- .../biome_grit_syntax/src/generated/nodes.rs | 212 +++-- .../src/generated/nodes_mut.rs | 16 +- crates/biome_grit_syntax/src/lib.rs | 3 +- crates/biome_json_parser/src/lexer/mod.rs | 31 +- xtask/codegen/gritql.ungram | 4 +- xtask/codegen/src/grit_kinds_src.rs | 4 +- 14 files changed, 1502 insertions(+), 157 deletions(-) create mode 100644 crates/biome_grit_parser/src/lexer/mod.rs create mode 100644 crates/biome_grit_parser/src/lexer/tests.rs diff --git a/crates/biome_grit_factory/src/generated.rs b/crates/biome_grit_factory/src/generated.rs index 32cee4d7753..36a6b03f332 100644 --- a/crates/biome_grit_factory/src/generated.rs +++ b/crates/biome_grit_factory/src/generated.rs @@ -1,6 +1,7 @@ #[rustfmt::skip] pub(super) mod syntax_factory; #[rustfmt::skip] +#[allow(unused)] pub(crate) mod node_factory; pub use syntax_factory::GritSyntaxFactory; diff --git a/crates/biome_grit_factory/src/generated/node_factory.rs b/crates/biome_grit_factory/src/generated/node_factory.rs index 3b1959d7f2e..a4414cbe022 100644 --- a/crates/biome_grit_factory/src/generated/node_factory.rs +++ b/crates/biome_grit_factory/src/generated/node_factory.rs @@ -780,6 +780,12 @@ pub fn grit_named_arg_with_default( ], )) } +pub fn grit_negative_int_literal(value_token: SyntaxToken) -> GritNegativeIntLiteral { + GritNegativeIntLiteral::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_NEGATIVE_INT_LITERAL, + [Some(SyntaxElement::Token(value_token))], + )) +} pub fn grit_node_like( name: GritName, l_paren_token: SyntaxToken, @@ -1885,12 +1891,6 @@ pub fn grit_sequential( ], )) } -pub fn grit_signed_int_literal(value_token: SyntaxToken) -> GritSignedIntLiteral { - GritSignedIntLiteral::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_SIGNED_INT_LITERAL, - [Some(SyntaxElement::Token(value_token))], - )) -} pub fn grit_snippet_regex(value_token: SyntaxToken) -> GritSnippetRegex { GritSnippetRegex::unwrap_cast(SyntaxNode::new_detached( GritSyntaxKind::GRIT_SNIPPET_REGEX, diff --git a/crates/biome_grit_factory/src/generated/syntax_factory.rs b/crates/biome_grit_factory/src/generated/syntax_factory.rs index b15a1684a05..08ddf6a0f44 100644 --- a/crates/biome_grit_factory/src/generated/syntax_factory.rs +++ b/crates/biome_grit_factory/src/generated/syntax_factory.rs @@ -1583,6 +1583,25 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.into_node(GRIT_NAMED_ARG_WITH_DEFAULT, children) } + GRIT_NEGATIVE_INT_LITERAL => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == GRIT_NEGATIVE_INT_LITERAL { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_NEGATIVE_INT_LITERAL.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_NEGATIVE_INT_LITERAL, children) + } GRIT_NODE_LIKE => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); @@ -3260,25 +3279,6 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.into_node(GRIT_SEQUENTIAL, children) } - GRIT_SIGNED_INT_LITERAL => { - let mut elements = (&children).into_iter(); - let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); - let mut current_element = elements.next(); - if let Some(element) = ¤t_element { - if element.kind() == GRIT_SIGNED_INT_LITERAL { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if current_element.is_some() { - return RawSyntaxNode::new( - GRIT_SIGNED_INT_LITERAL.to_bogus(), - children.into_iter().map(Some), - ); - } - slots.into_node(GRIT_SIGNED_INT_LITERAL, children) - } GRIT_SNIPPET_REGEX => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); diff --git a/crates/biome_grit_parser/src/lexer/mod.rs b/crates/biome_grit_parser/src/lexer/mod.rs new file mode 100644 index 00000000000..56e99d59ddd --- /dev/null +++ b/crates/biome_grit_parser/src/lexer/mod.rs @@ -0,0 +1,868 @@ +//! An extremely fast, lookup table based, GritQL lexer which yields SyntaxKind tokens used by the biome Grit parser. + +#[rustfmt::skip] +mod tests; + +use biome_grit_syntax::{GritSyntaxKind, GritSyntaxKind::*, TextLen, TextRange, TextSize, T}; +use biome_parser::diagnostic::ParseDiagnostic; +use biome_unicode_table::{lookup_byte, Dispatch::*}; +use std::iter::FusedIterator; +use std::ops::Add; +use unicode_bom::Bom; + +pub struct Token { + kind: GritSyntaxKind, + range: TextRange, +} + +impl Token { + pub fn kind(&self) -> GritSyntaxKind { + self.kind + } + + pub fn range(&self) -> TextRange { + self.range + } +} + +/// An extremely fast, lookup table based, lossless JSON lexer +#[derive(Debug)] +pub(crate) struct Lexer<'src> { + /// Source text + source: &'src str, + + /// The start byte position in the source text of the next token. + position: usize, + + diagnostics: Vec, +} + +impl<'src> Lexer<'src> { + /// Make a new lexer from a str, this is safe because strs are valid utf8 + pub fn from_str(string: &'src str) -> Self { + Self { + source: string, + position: 0, + diagnostics: Vec::new(), + } + } + + /// Returns the source code + pub fn source(&self) -> &'src str { + self.source + } + + pub fn finish(self) -> Vec { + self.diagnostics + } + + /// Lexes the next token. + /// + /// ## Return + /// Returns its kind and any potential error. + pub(crate) fn next_token(&mut self) -> Option { + let start = self.text_position(); + + match self.current_byte() { + Some(current) => { + let kind = self.lex_token(current); + + debug_assert!(start < self.text_position(), "Lexer did not progress"); + Some(Token { + kind, + range: TextRange::new(start, self.text_position()), + }) + } + None if self.position == self.source.len() => { + self.advance(1); + Some(Token { + kind: EOF, + range: TextRange::new(start, start), + }) + } + None => None, + } + } + + fn text_position(&self) -> TextSize { + TextSize::try_from(self.position).expect("Input to be smaller than 4 GB") + } + + /// Bumps the current byte and creates a lexed token of the passed in kind. + fn eat_byte(&mut self, tok: GritSyntaxKind) -> GritSyntaxKind { + self.advance(1); + tok + } + + /// Eats just one newline/line break and spits out the lexed token. + /// + /// ## Safety + /// Must be called at a newline character. + fn eat_newline(&mut self) -> GritSyntaxKind { + self.assert_at_char_boundary(); + + match self.current_byte() { + Some(b'\n') => self.advance(1), + Some(b'\r') => { + if self.peek_byte() == Some(b'\n') { + self.advance(2) + } else { + self.advance(1) + } + } + _ => {} + } + + NEWLINE + } + + /// Eats all whitespace until a non-whitespace or a newline is found. + /// + /// ## Safety + /// Must be called at a whitespace character. + fn eat_whitespace(&mut self) -> GritSyntaxKind { + self.assert_at_char_boundary(); + + while let Some(byte) = self.current_byte() { + match byte { + b'\t' | b' ' => self.advance(1), + b'\r' | b'\n' => { + break; + } + _ => match lookup_byte(byte) { + WHS => { + let start = self.text_position(); + self.advance(1); + + self.diagnostics.push( + ParseDiagnostic::new( + "GritQL only allows tabs, whitespace, carriage return and line feed whitespace.", + start..self.text_position(), + ) + .with_hint("Use a regular whitespace character instead."), + ) + } + _ => break, + }, + } + } + + WHITESPACE + } + + /// Check if the source starts with a Unicode BOM character. If it does, + /// consume it and return the UNICODE_BOM token kind. + /// + /// Note that JSON explicitly forbids BOM characters from appearing in a + /// network-transmitted JSON Text: https://datatracker.ietf.org/doc/html/rfc8259#section-8.1. + /// However, Windows editors in particular will occasionally add a BOM + /// anyway, and Biome should not remove those characters when present, so + /// they need to be tracked. + /// + /// ## Safety + /// Must be called at a valid UT8 char boundary (and realistically only at + /// the start position of the source). + fn consume_potential_bom(&mut self) -> Option { + // Bom needs at least the first three bytes of the source to know if it + // matches the UTF-8 BOM and not an alternative. This can be expanded + // to more bytes to support other BOM characters if Biome decides to + // support other encodings like UTF-16. + if let Some(first) = self.source().get(0..3) { + let bom = Bom::from(first.as_bytes()); + self.advance(bom.len()); + + match bom { + Bom::Null => None, + _ => Some(UNICODE_BOM), + } + } else { + None + } + } + + /// Get the UTF8 char which starts at the current byte + /// + /// ## Safety + /// Must be called at a valid UT8 char boundary + fn current_char_unchecked(&self) -> char { + // Precautionary measure for making sure the unsafe code below does not read over memory boundary + debug_assert!(!self.is_eof()); + self.assert_at_char_boundary(); + + // Safety: We know this is safe because we require the input to the lexer to be valid utf8 and we always call this when we are at a char + let string = unsafe { + std::str::from_utf8_unchecked(self.source.as_bytes().get_unchecked(self.position..)) + }; + let chr = if let Some(chr) = string.chars().next() { + chr + } else { + // Safety: we always call this when we are at a valid char, so this branch is completely unreachable + unsafe { + core::hint::unreachable_unchecked(); + } + }; + + chr + } + + /// Gets the current byte. + /// + /// ## Returns + /// The current byte if the lexer isn't at the end of the file. + #[inline] + fn current_byte(&self) -> Option { + if self.is_eof() { + None + } else { + Some(self.source.as_bytes()[self.position]) + } + } + + /// Asserts that the lexer is at a UTF8 char boundary + #[inline] + fn assert_at_char_boundary(&self) { + debug_assert!(self.source.is_char_boundary(self.position)); + } + + /// Asserts that the lexer is currently positioned at `byte` + #[inline] + fn assert_byte(&self, byte: u8) { + debug_assert_eq!(self.source.as_bytes()[self.position], byte); + } + + /// Peeks at the next byte + #[inline] + fn peek_byte(&self) -> Option { + self.byte_at(1) + } + + /// Returns the byte at position `self.position + offset` or `None` if it is out of bounds. + #[inline] + fn byte_at(&self, offset: usize) -> Option { + self.source.as_bytes().get(self.position + offset).copied() + } + + /// Advances the current position by `n` bytes. + #[inline] + fn advance(&mut self, n: usize) { + self.position += n; + } + + #[inline] + fn advance_byte_or_char(&mut self, chr: u8) { + if chr.is_ascii() { + self.advance(1); + } else { + self.advance_char_unchecked(); + } + } + + /// Advances the current position by the current char UTF8 length + /// + /// ## Safety + /// Must be called at a valid UT8 char boundary + #[inline] + fn advance_char_unchecked(&mut self) { + let c = self.current_char_unchecked(); + self.position += c.len_utf8(); + } + + /// Returns `true` if the parser is at or passed the end of the file. + #[inline] + fn is_eof(&self) -> bool { + self.position >= self.source.len() + } + + /// Lexes the next token + /// + /// Guaranteed to not be at the end of the file + fn lex_token(&mut self, current: u8) -> GritSyntaxKind { + match current { + b'\n' | b'\r' => self.eat_newline(), + b'\t' | b' ' => self.eat_whitespace(), + b'\'' | b'"' => self.lex_string_literal(current), + b'/' => self.lex_slash(), + b':' => self.eat_byte(T![:]), + b',' => self.eat_byte(T![,]), + b'[' => self.eat_byte(T!['[']), + b']' => self.eat_byte(T![']']), + b'{' => self.eat_byte(T!['{']), + b'}' => self.eat_byte(T!['}']), + b'$' => self.lex_variable(), + _ if is_leading_identifier_byte(current) => self.lex_name(current), + _ if (b'0'..=b'9').contains(¤t) || current == b'-' => self.lex_number(current), + _ if self.position == 0 && self.consume_potential_bom().is_some() => UNICODE_BOM, + _ => self.eat_unexpected_character(), + } + } + + #[inline] + fn eat_unexpected_character(&mut self) -> GritSyntaxKind { + self.assert_at_char_boundary(); + + let char = self.current_char_unchecked(); + let err = ParseDiagnostic::new( + format!("unexpected character `{}`", char), + self.text_position()..self.text_position() + char.text_len(), + ); + self.diagnostics.push(err); + self.advance(char.len_utf8()); + + ERROR_TOKEN + } + + /// Lexes a JSON number literal + fn lex_number(&mut self, first: u8) -> GritSyntaxKind { + self.assert_at_char_boundary(); + + let start = self.text_position(); + + if first == b'-' { + self.advance(1); + } + + let mut state = LexNumberState::FirstDigit; + + loop { + state = match self.current_byte() { + Some(b'0') => { + let position = self.text_position(); + + self.advance(1); + + match state { + LexNumberState::FirstDigit + if matches!(self.current_byte(), Some(b'0'..=b'9')) => + { + LexNumberState::Invalid { + position, + reason: InvalidNumberReason::Octal, + } + } + LexNumberState::FirstDigit => LexNumberState::IntegerPart, + state => state, + } + } + Some(b'0'..=b'9') => { + self.advance(1); + + match state { + LexNumberState::FirstDigit => LexNumberState::IntegerPart, + state => state, + } + } + Some(b'.') => { + let position = self.text_position(); + + self.advance(1); + + match state { + LexNumberState::IntegerPart + if matches!(self.current_byte(), Some(b'0'..=b'9')) => + { + LexNumberState::FractionalPart + } + LexNumberState::IntegerPart => LexNumberState::Invalid { + position: self.text_position(), + reason: InvalidNumberReason::MissingFraction, + }, + invalid @ LexNumberState::Invalid { .. } => invalid, + _ => LexNumberState::Invalid { + position, + reason: InvalidNumberReason::Fraction, + }, + } + } + Some(b'e' | b'E') => { + let position = self.text_position(); + + match self.peek_byte() { + Some(b'-' | b'+') => self.advance(2), + _ => self.advance(1), + }; + + match state { + LexNumberState::IntegerPart | LexNumberState::FractionalPart + if matches!(self.current_byte(), Some(b'0'..=b'9')) => + { + LexNumberState::Exponent + } + LexNumberState::IntegerPart | LexNumberState::FractionalPart => { + LexNumberState::Invalid { + position: self.text_position(), + reason: InvalidNumberReason::MissingExponent, + } + } + invalid @ LexNumberState::Invalid { .. } => invalid, + _ => LexNumberState::Invalid { + position, + reason: InvalidNumberReason::Exponent, + }, + } + } + _ => { + break; + } + } + } + + match state { + LexNumberState::IntegerPart => { + if first == b'-' { + GRIT_NEGATIVE_INT_LITERAL + } else { + GRIT_INT_LITERAL + } + } + LexNumberState::FractionalPart | LexNumberState::Exponent => GRIT_DOUBLE_LITERAL, + LexNumberState::FirstDigit => { + let err = ParseDiagnostic::new( + "Minus must be followed by a digit", + start..self.text_position(), + ); + self.diagnostics.push(err); + ERROR_TOKEN + } + LexNumberState::Invalid { position, reason } => { + let diagnostic = match reason { + InvalidNumberReason::Fraction => ParseDiagnostic::new( + "Invalid fraction part", + position..position + TextSize::from(1), + ), + InvalidNumberReason::Exponent => ParseDiagnostic::new( + "Invalid exponent part", + position..position + TextSize::from(1), + ), + InvalidNumberReason::Octal => ParseDiagnostic::new( + "GritQL doesn't allow octal number notation (numbers starting with zero)", + position..position + TextSize::from(1), + ), + InvalidNumberReason::MissingExponent => { + ParseDiagnostic::new("Missing exponent", start..position).with_detail( + position..position + TextSize::from(1), + "Expected a digit as the exponent", + ) + } + InvalidNumberReason::MissingFraction => ParseDiagnostic::new( + "Missing fraction", + position..position + TextSize::from(1), + ) + .with_hint("Remove the `.`"), + }; + + self.diagnostics.push(diagnostic); + ERROR_TOKEN + } + } + } + + fn lex_string_literal(&mut self, quote: u8) -> GritSyntaxKind { + // Handle invalid quotes + self.assert_at_char_boundary(); + let start = self.text_position(); + + self.advance(1); // Skip over the quote + let mut state = match quote { + b'\'' => LexStringState::InvalidQuote, + _ => LexStringState::InString, + }; + + while let Some(chr) = self.current_byte() { + let dispatch = lookup_byte(chr); + + match dispatch { + QOT if quote == chr => { + self.advance(1); + state = match state { + LexStringState::InString => LexStringState::Terminated, + state => state, + }; + break; + } + // '\t' etc + BSL => { + let escape_start = self.text_position(); + self.advance(1); + + match self.current_byte() { + Some(b'"' | b'\\' | b'/' | b'b' | b'f' | b'n' | b'r' | b't') => { + self.advance(1) + } + + Some(b'u') => match (self.lex_unicode_escape(), state) { + (Ok(_), _) => {} + (Err(err), LexStringState::InString) => { + self.diagnostics.push(err); + state = LexStringState::InvalidEscapeSequence; + } + (Err(_), _) => {} + }, + + // Handle escaped `'` but only if this is a single quote string. The whole string will + // be marked as erroneous + Some(b'\'') if quote == b'\'' => { + self.advance(1); + } + + Some(_) => { + if matches!(state, LexStringState::InString) { + let c = self.current_char_unchecked(); + self.diagnostics.push( + ParseDiagnostic::new( + + "Invalid escape sequence", + escape_start..self.text_position() + c.text_len(), + ) + .with_hint(r#"Valid escape sequences are: `\\`, `\/`, `/"`, `\b\`, `\f`, `\n`, `\r`, `\t` or any unicode escape sequence `\uXXXX` where X is hexedecimal number. "#), + ); + state = LexStringState::InvalidEscapeSequence; + } + } + + None => { + if matches!(state, LexStringState::InString) { + self.diagnostics.push(ParseDiagnostic::new( + + "Expected an escape sequence following a backslash, but found none", + escape_start..self.text_position(), + ) + .with_detail(self.text_position()..self.text_position(), "File ends here") + ); + state = LexStringState::InvalidEscapeSequence; + } + } + } + } + WHS if matches!(chr, b'\n' | b'\r') => { + let unterminated = + ParseDiagnostic::new("Missing closing quote", start..self.text_position()) + .with_detail(self.position..self.position + 1, "line breaks here"); + + self.diagnostics.push(unterminated); + + return GRIT_STRING_LITERAL; + } + UNI => self.advance_char_unchecked(), + + // Following the same rules as JSON here: + // All code points may be placed within the quotation marks except for the code points that + //must be escaped: + // * quotation mark: (U+0022), + // * reverse solidus (U+005C), + // * and the **control characters U+0000 to U+001F** <- This + ERR | WHS if matches!(state, LexStringState::InString) && chr <= 0x1f => { + self.diagnostics.push( + ParseDiagnostic::new( + + format!( + "Control character '\\u{chr:04x}' is not allowed in string literals." + ), + self.text_position()..self.text_position() + TextSize::from(1), + ) + .with_hint(format!("Use the escape sequence '\\u{chr:04x}' instead.")), + ); + state = LexStringState::InvalidEscapeSequence; + } + _ => self.advance(1), + } + } + + match state { + LexStringState::Terminated => GRIT_STRING_LITERAL, + LexStringState::InvalidQuote => { + let literal_range = TextRange::new(start, self.text_position()); + self.diagnostics.push( + ParseDiagnostic::new( + "GritQL does not allow single quoted strings", + literal_range, + ) + .with_hint("Use double quotes to escape the string."), + ); + ERROR_TOKEN + } + LexStringState::InString => { + let unterminated = + ParseDiagnostic::new("Missing closing quote", start..self.text_position()) + .with_detail( + self.source.text_len()..self.source.text_len(), + "file ends here", + ); + self.diagnostics.push(unterminated); + + GRIT_STRING_LITERAL + } + LexStringState::InvalidEscapeSequence => ERROR_TOKEN, + } + } + + /// Lexes a `\u0000` escape sequence. Assumes that the lexer is positioned at the `u` token. + /// + /// A unicode escape sequence must consist of 4 hex characters. + fn lex_unicode_escape(&mut self) -> Result<(), ParseDiagnostic> { + self.assert_byte(b'u'); + self.assert_at_char_boundary(); + + let start = self.text_position(); + + let start = start + // Subtract 1 to get position of `\` + .checked_sub(TextSize::from(1)) + .unwrap_or(start); + + self.advance(1); // Advance over `u'` + + for _ in 0..4 { + match self.current_byte() { + Some(byte) if byte.is_ascii_hexdigit() => self.advance(1), + Some(_) => { + let char = self.current_char_unchecked(); + // Reached a non hex digit which is invalid + return Err(ParseDiagnostic::new( + + "Invalid unicode sequence", + start..self.text_position(), + ) + .with_detail(self.text_position()..self.text_position().add(char.text_len()), "Non hexadecimal number") + .with_hint("A unicode escape sequence must consist of 4 hexadecimal numbers: `\\uXXXX`, e.g. `\\u002F' for '/'.")); + } + None => { + // Reached the end of the file before processing 4 hex digits + return Err(ParseDiagnostic::new( + + "Unicode escape sequence with two few hexadecimal numbers.", + start..self.text_position(), + ) + .with_detail( + self.text_position()..self.text_position(), + "reached the end of the file", + ) + .with_hint("A unicode escape sequence must consist of 4 hexadecimal numbers: `\\uXXXX`, e.g. `\\u002F' for '/'.")); + } + } + } + + Ok(()) + } + + /// Lexes a name for variables (without leading `$`), labels, and keywords. + fn lex_name(&mut self, first: u8) -> GritSyntaxKind { + self.assert_at_char_boundary(); + + // Note to keep the buffer large enough to fit every possible keyword that + // the lexer can return + const BUFFER_SIZE: usize = 14; + let mut buffer = [0u8; BUFFER_SIZE]; + let mut len = 0; + + self.advance_byte_or_char(first); + + while let Some(byte) = self.current_byte() { + if is_identifier_byte(byte) { + if len < BUFFER_SIZE { + buffer[len] = byte; + len += 1; + } + + self.advance(1) + } else { + break; + } + } + + match &buffer[..len] { + b"sequential" => SEQUENTIAL_KW, + b"multifile" => MULTIFILE_KW, + b"engine" => ENGINE_KW, + b"biome" => BIOME_KW, + b"language" => LANGUAGE_KW, + b"js" => JS_KW, + b"css" => CSS_KW, + b"json" => JSON_KW, + b"grit" => GRIT_KW, + b"html" => HTML_KW, + b"typescript" => TYPESCRIPT_KW, + b"jsx" => JSX_KW, + b"js_do_not_use" => JS_DO_NOT_USE_KW, + b"as" => AS_KW, + b"limit" => LIMIT_KW, + b"where" => WHERE_KW, + b"orelse" => ORELSE_KW, + b"maybe" => MAYBE_KW, + b"after" => AFTER_KW, + b"before" => BEFORE_KW, + b"contains" => CONTAINS_KW, + b"until" => UNTIL_KW, + b"includes" => INCLUDES_KW, + b"if" => IF_KW, + b"else" => ELSE_KW, + b"within" => WITHIN_KW, + b"bubble" => BUBBLE_KW, + b"not" => NOT_KW, + b"or" => OR_KW, + b"and" => AND_KW, + b"any" => ANY_KW, + b"some" => SOME_KW, + b"every" => EVERY_KW, + b"private" => PRIVATE_KW, + b"pattern" => PATTERN_KW, + b"predicate" => PREDICATE_KW, + b"function" => FUNCTION_KW, + b"true" => TRUE_KW, + b"false" => FALSE_KW, + b"undefined" => UNDEFINED_KW, + b"like" => LIKE_KW, + b"return" => RETURN_KW, + _ => GRIT_NAME, + } + } + + /// Lexes a variable (with leading `$`). + fn lex_variable(&mut self) -> GritSyntaxKind { + self.assert_at_char_boundary(); + self.advance(1); // Skip the leading `$`. + + while let Some(byte) = self.current_byte() { + if is_identifier_byte(byte) { + self.advance(1) + } else { + break; + } + } + + GRIT_VARIABLE + } + + /// Lexes a comment. + fn lex_slash(&mut self) -> GritSyntaxKind { + let start = self.text_position(); + match self.peek_byte() { + Some(b'*') => { + // eat `/*` + self.advance(2); + + let mut has_newline = false; + + while let Some(chr) = self.current_byte() { + match chr { + b'*' if self.peek_byte() == Some(b'/') => { + self.advance(2); + + if has_newline { + return MULTILINE_COMMENT; + } else { + return COMMENT; + } + } + b'\n' | b'\r' => { + has_newline = true; + self.advance(1) + } + chr => self.advance_byte_or_char(chr), + } + } + + let err = + ParseDiagnostic::new("Unterminated block comment", start..self.text_position()) + .with_detail( + self.position..self.position + 1, + "... but the file ends here", + ); + + self.diagnostics.push(err); + + if has_newline { + MULTILINE_COMMENT + } else { + COMMENT + } + } + Some(b'/') => { + self.advance(2); + + while let Some(chr) = self.current_byte() { + match chr { + b'\n' | b'\r' => return COMMENT, + chr => self.advance_byte_or_char(chr), + } + } + + COMMENT + } + _ => self.eat_unexpected_character(), + } + } +} + +impl Iterator for Lexer<'_> { + type Item = Token; + + fn next(&mut self) -> Option { + self.next_token() + } +} + +impl FusedIterator for Lexer<'_> {} + +#[derive(Debug, Copy, Clone)] +enum LexNumberState { + /// At the start, after a minus + FirstDigit, + + /// Parsing the digits before the exponent or fractional (after .`) part + IntegerPart, + + /// Parsing the digits after a `.` + FractionalPart, + + /// Parsing the exponent digits (after a `e` or `E`) + Exponent, + + /// Parsing the rest of an invalid number + Invalid { + reason: InvalidNumberReason, + position: TextSize, + }, +} + +#[derive(Copy, Clone, Debug)] +enum InvalidNumberReason { + /// Fraction in an invalid position + Fraction, + /// Exponent in an invalid position + Exponent, + + /// Missing digit after an `e` or `E` + MissingExponent, + + /// Missing digit after faction (.) + MissingFraction, + + /// Number starting with a 0 + Octal, +} + +#[derive(Copy, Clone, Debug)] +enum LexStringState { + /// When using `'` instead of `"` + InvalidQuote, + + /// String that contains an invalid escape sequence + InvalidEscapeSequence, + + /// Between the opening `"` and closing `"` quotes. + InString, + + /// Properly terminated string + Terminated, +} + +fn is_identifier_byte(byte: u8) -> bool { + (b'a'..=b'z').contains(&byte) + || (b'A'..=b'Z').contains(&byte) + || (b'0'..=b'9').contains(&byte) + || byte == b'_' +} + +fn is_leading_identifier_byte(byte: u8) -> bool { + (b'a'..=b'z').contains(&byte) || (b'A'..=b'Z').contains(&byte) || byte == b'_' +} diff --git a/crates/biome_grit_parser/src/lexer/tests.rs b/crates/biome_grit_parser/src/lexer/tests.rs new file mode 100644 index 00000000000..63c807b0fde --- /dev/null +++ b/crates/biome_grit_parser/src/lexer/tests.rs @@ -0,0 +1,455 @@ +#![cfg(test)] +#![allow(unused_mut, unused_variables, unused_assignments)] + +use super::{Lexer, TextSize}; +use biome_grit_syntax::GritSyntaxKind::{self, *}; +use quickcheck_macros::quickcheck; +use std::sync::mpsc::channel; +use std::thread; +use std::time::Duration; + +// Assert the result of lexing a piece of source code, +// and make sure the tokens yielded are fully lossless and the source can be reconstructed from only the tokens +macro_rules! assert_lex { + ($src:expr, $($kind:ident:$len:expr $(,)?)*) => {{ + let mut lexer = Lexer::from_str($src); + let mut idx = 0; + let mut tok_idx = TextSize::default(); + + let mut new_str = String::with_capacity($src.len()); + let tokens: Vec<_> = lexer.collect(); + + $( + assert_eq!( + tokens[idx].kind, + GritSyntaxKind::$kind, + "expected token kind {}, but found {:?}", + stringify!($kind), + tokens[idx].kind, + ); + + assert_eq!( + tokens[idx].range.len(), + TextSize::from($len), + "expected token length of {}, but found {:?} for token {:?}", + $len, + tokens[idx].range.len(), + tokens[idx].kind, + ); + + new_str.push_str(&$src[tokens[idx].range]); + tok_idx += tokens[idx].range.len(); + + idx += 1; + )* + + if idx < tokens.len() { + panic!( + "expected {} tokens but lexer returned {}, first unexpected token is '{:?}'", + idx, + tokens.len(), + tokens[idx].kind + ); + } else { + assert_eq!(idx, tokens.len()); + } + + assert_eq!($src, new_str, "Failed to reconstruct input"); + }}; +} + +// This is for testing if the lexer is truly lossless +// It parses random strings and puts them back together with the produced tokens and compares +#[quickcheck] +fn losslessness(string: String) -> bool { + // using an mpsc channel allows us to spawn a thread and spawn the lexer there, then if + // it takes more than 2 seconds we panic because it is 100% infinite recursion + let cloned = string.clone(); + let (sender, receiver) = channel(); + thread::spawn(move || { + let mut lexer = Lexer::from_str(&cloned); + let tokens: Vec<_> = lexer.map(|token| token.range).collect(); + + sender + .send(tokens) + .expect("Could not send tokens to receiver"); + }); + let token_ranges = receiver + .recv_timeout(Duration::from_secs(2)) + .unwrap_or_else(|_| { + panic!( + "Lexer is infinitely recursing with this code: ->{}<-", + string + ) + }); + + let mut new_str = String::with_capacity(string.len()); + let mut idx = TextSize::from(0); + + for range in token_ranges { + new_str.push_str(&string[range]); + idx += range.len(); + } + + string == new_str +} + +#[test] +fn empty() { + assert_lex! { + "", + EOF:0 + } +} + +#[test] +fn int() { + assert_lex! { + "5098382", + GRIT_INT_LITERAL:7, + EOF:0 + } +} + +#[test] +fn float() { + assert_lex! { + "345.893872", + GRIT_DOUBLE_LITERAL:10, + EOF:0 + } +} + +#[test] +fn float_invalid() { + assert_lex! { + "345.893872.43322", + ERROR_TOKEN:16, + EOF:0 + } +} + +#[test] +fn negative() { + assert_lex! { + "-5098382", + GRIT_NEGATIVE_INT_LITERAL:8, + EOF:0 + } +} + +#[test] +fn minus_without_number() { + assert_lex! { + "-", + ERROR_TOKEN:1, + EOF:0 + } +} + +#[test] +fn exponent() { + assert_lex! { + "-493e+534", + GRIT_DOUBLE_LITERAL:9, + EOF:0 + } + + assert_lex! { + "-493E-534", + GRIT_DOUBLE_LITERAL:9, + EOF:0 + } +} + +#[test] +fn multiple_exponent() { + assert_lex! { + "-493e5E3", + ERROR_TOKEN:8, + EOF:0 + } + + assert_lex! { + "-493e4E45", + ERROR_TOKEN:9, + EOF:0 + } +} + +#[test] +fn array() { + assert_lex! { + "[1, 2, 3, 4]", + L_BRACK:1, + GRIT_INT_LITERAL:1, + COMMA:1 + WHITESPACE:1, + GRIT_INT_LITERAL:1, + COMMA:1, + WHITESPACE:1, + GRIT_INT_LITERAL:1, + COMMA:1, + WHITESPACE:1, + GRIT_INT_LITERAL:1, + R_BRACK:1, + EOF:0, + } +} + +#[test] +fn object() { + assert_lex! { + r#"{ key: "value", other: 4 }"#, + L_CURLY:1, + WHITESPACE:1, + + GRIT_NAME:5, + COLON:1, + WHITESPACE:1, + GRIT_STRING_LITERAL:7, + COMMA:1, + + WHITESPACE:1, + GRIT_NAME:7, + COLON:1, + WHITESPACE:1, + GRIT_INT_LITERAL:1, + WHITESPACE:1, + R_CURLY:1, + EOF:0, + } +} + +#[test] +fn basic_string() { + assert_lex! { + r#""A string consisting of ASCII characters only""#, + GRIT_STRING_LITERAL:46, + EOF:0 + } +} + +#[test] +fn single_quote_string() { + assert_lex! { + r#"'A string token using single quotes that are not supported in GritQL'"#, + ERROR_TOKEN:67, + EOF:0 + } +} + +#[test] +fn unterminated_string() { + assert_lex! { + r#""A string without the closing quote"#, + GRIT_STRING_LITERAL:35, + EOF:0 + } +} + +#[test] +fn simple_escape_sequences() { + assert_lex! { + r#""Escaped \t""#, + GRIT_STRING_LITERAL:12, + EOF:0 + } + + assert_lex! { + r#""Escaped \"""#, + GRIT_STRING_LITERAL:12, + EOF:0 + } + + assert_lex! { + r#""Escaped \\""#, + GRIT_STRING_LITERAL:12, + EOF:0 + } + + assert_lex! { + r#""Escaped \/""#, + GRIT_STRING_LITERAL:12, + EOF:0 + } + + assert_lex! { + r#""Escaped \b""#, + GRIT_STRING_LITERAL:12, + EOF:0 + } + + assert_lex! { + r#""Escaped \f""#, + GRIT_STRING_LITERAL:12, + EOF:0 + } + + assert_lex! { + r#""Escaped \n""#, + GRIT_STRING_LITERAL:12, + EOF:0 + } + + assert_lex! { + r#""Escaped \r""#, + GRIT_STRING_LITERAL:12, + EOF:0 + } +} + +#[test] +fn unicode_escape() { + assert_lex! { + r#""Escaped \u002F""#, + GRIT_STRING_LITERAL:16, + EOF:0 + } + + assert_lex! { + r#""Escaped \u002f""#, + GRIT_STRING_LITERAL:16, + EOF:0 + } +} + +#[test] +fn invalid_unicode_escape() { + assert_lex! { + r#""Escaped \u0""#, + ERROR_TOKEN:13, + EOF:0 + } + + assert_lex! { + r#""Escaped \u002G""#, + ERROR_TOKEN:16, + EOF:0 + } +} + +#[test] +fn invalid_escape() { + assert_lex! { + r#""\"#, + ERROR_TOKEN:2, + EOF:0 + } + + assert_lex! { + r#""Invalid escape \'""#, + ERROR_TOKEN:19, + EOF:0 + } +} + +#[test] +fn single_quote_escape_in_single_quote_string() { + assert_lex! { + r"'A single \' escape'", + ERROR_TOKEN:20, + EOF:0 + } +} + +#[test] +fn identifiers() { + assert_lex! { + r#"asciiIdentifier"#, + GRIT_NAME:15, + EOF:0 + } + + assert_lex! { + r#"with_underscore_here"#, + GRIT_NAME:20, + EOF:0 + } + + assert_lex! { + r#"with_unicodeà"#, + GRIT_NAME:12, + ERROR_TOKEN:2, + EOF:0 + } + + assert_lex! { + r#"ᨀwith_unicodeàç"#, + ERROR_TOKEN:3, + GRIT_NAME:12, + ERROR_TOKEN:2, + ERROR_TOKEN:2, + EOF:0 + } +} + +#[test] +fn single_line_comments() { + assert_lex! { + "//abc + ", + COMMENT:5, + NEWLINE:1, + WHITESPACE:4, + EOF:0 + } + + assert_lex! { + "//a", + COMMENT:3, + EOF:0 + } +} + +#[test] +fn block_comment() { + assert_lex! { + "/* + */", + MULTILINE_COMMENT:13, + EOF:0 + } + + assert_lex! { + "/* */", + COMMENT:5, + EOF:0 + } + + assert_lex! { + "/* *", + COMMENT:4, + EOF:0 + } +} + +#[test] +fn keywords() { + let keywords = vec!["true", "false", "undefined", "as"]; + + for keyword in keywords { + let kind = GritSyntaxKind::from_keyword(keyword).expect( + "Expected `GritSyntaxKind::from_keyword` to return a kind for keyword {keyword}.", + ); + + let mut lexer = Lexer::from_str(keyword); + let current = lexer.next_token().expect("To have lexed keyword"); + + assert_eq!( + current.kind, kind, + "Expected token '{keyword}' to be of kind {:?} but is {:?}.", + kind, current.kind + ); + + assert_eq!( + current.range.len(), + TextSize::from(keyword.len() as u32), + "Expected lexed keyword to be of len {} but has length {:?}", + keyword.len(), + current.range.len() + ); + + assert_eq!(lexer.next_token().expect("Expected EOF token").kind, EOF); + } +} diff --git a/crates/biome_grit_parser/src/lib.rs b/crates/biome_grit_parser/src/lib.rs index e69de29bb2d..a5464ca53a5 100644 --- a/crates/biome_grit_parser/src/lib.rs +++ b/crates/biome_grit_parser/src/lib.rs @@ -0,0 +1 @@ +mod lexer; diff --git a/crates/biome_grit_syntax/src/generated/kind.rs b/crates/biome_grit_syntax/src/generated/kind.rs index 83739673982..2793a1d82ff 100644 --- a/crates/biome_grit_syntax/src/generated/kind.rs +++ b/crates/biome_grit_syntax/src/generated/kind.rs @@ -85,7 +85,7 @@ pub enum GritSyntaxKind { LIKE_KW, RETURN_KW, GRIT_INT_LITERAL, - GRIT_SIGNED_INT_LITERAL, + GRIT_NEGATIVE_INT_LITERAL, GRIT_DOUBLE_LITERAL, GRIT_STRING_LITERAL, GRIT_REGEX_LITERAL, @@ -93,6 +93,8 @@ pub enum GritSyntaxKind { NEWLINE, WHITESPACE, COMMENT, + MULTILINE_COMMENT, + ERROR_TOKEN, GRIT_ANNOTATION, GRIT_BACKTICK_SNIPPET, GRIT_RAW_BACKTICK_SNIPPET, @@ -229,7 +231,7 @@ impl GritSyntaxKind { pub const fn is_literal(self) -> bool { match self { GRIT_INT_LITERAL - | GRIT_SIGNED_INT_LITERAL + | GRIT_NEGATIVE_INT_LITERAL | GRIT_DOUBLE_LITERAL | GRIT_STRING_LITERAL | GRIT_REGEX_LITERAL diff --git a/crates/biome_grit_syntax/src/generated/macros.rs b/crates/biome_grit_syntax/src/generated/macros.rs index 95578e19a05..8b7e1c741bd 100644 --- a/crates/biome_grit_syntax/src/generated/macros.rs +++ b/crates/biome_grit_syntax/src/generated/macros.rs @@ -169,6 +169,10 @@ macro_rules! map_syntax_node { let $pattern = unsafe { $crate::GritNamedArgWithDefault::new_unchecked(node) }; $body } + $crate::GritSyntaxKind::GRIT_NEGATIVE_INT_LITERAL => { + let $pattern = unsafe { $crate::GritNegativeIntLiteral::new_unchecked(node) }; + $body + } $crate::GritSyntaxKind::GRIT_NODE_LIKE => { let $pattern = unsafe { $crate::GritNodeLike::new_unchecked(node) }; $body @@ -369,10 +373,6 @@ macro_rules! map_syntax_node { let $pattern = unsafe { $crate::GritSequential::new_unchecked(node) }; $body } - $crate::GritSyntaxKind::GRIT_SIGNED_INT_LITERAL => { - let $pattern = unsafe { $crate::GritSignedIntLiteral::new_unchecked(node) }; - $body - } $crate::GritSyntaxKind::GRIT_SNIPPET_REGEX => { let $pattern = unsafe { $crate::GritSnippetRegex::new_unchecked(node) }; $body diff --git a/crates/biome_grit_syntax/src/generated/nodes.rs b/crates/biome_grit_syntax/src/generated/nodes.rs index 40bbbb3fe13..0d4b0feef32 100644 --- a/crates/biome_grit_syntax/src/generated/nodes.rs +++ b/crates/biome_grit_syntax/src/generated/nodes.rs @@ -1996,6 +1996,42 @@ pub struct GritNamedArgWithDefaultFields { pub pattern: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritNegativeIntLiteral { + pub(crate) syntax: SyntaxNode, +} +impl GritNegativeIntLiteral { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritNegativeIntLiteralFields { + GritNegativeIntLiteralFields { + value_token: self.value_token(), + } + } + pub fn value_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritNegativeIntLiteral { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritNegativeIntLiteralFields { + pub value_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] pub struct GritNodeLike { pub(crate) syntax: SyntaxNode, } @@ -4295,42 +4331,6 @@ pub struct GritSequentialFields { pub r_curly_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] -pub struct GritSignedIntLiteral { - pub(crate) syntax: SyntaxNode, -} -impl GritSignedIntLiteral { - #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] - #[doc = r""] - #[doc = r" # Safety"] - #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] - #[doc = r" or a match on [SyntaxNode::kind]"] - #[inline] - pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { - Self { syntax } - } - pub fn as_fields(&self) -> GritSignedIntLiteralFields { - GritSignedIntLiteralFields { - value_token: self.value_token(), - } - } - pub fn value_token(&self) -> SyntaxResult { - support::required_token(&self.syntax, 0usize) - } -} -#[cfg(feature = "serde")] -impl Serialize for GritSignedIntLiteral { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - self.as_fields().serialize(serializer) - } -} -#[cfg_attr(feature = "serde", derive(Serialize))] -pub struct GritSignedIntLiteralFields { - pub value_token: SyntaxResult, -} -#[derive(Clone, PartialEq, Eq, Hash)] pub struct GritSnippetRegex { pub(crate) syntax: SyntaxNode, } @@ -4922,7 +4922,8 @@ impl GritListAccessorSubject { #[cfg_attr(feature = "serde", derive(Serialize))] pub enum GritListIndex { AnyGritContainer(AnyGritContainer), - GritSignedIntLiteral(GritSignedIntLiteral), + GritIntLiteral(GritIntLiteral), + GritNegativeIntLiteral(GritNegativeIntLiteral), } impl GritListIndex { pub fn as_any_grit_container(&self) -> Option<&AnyGritContainer> { @@ -4931,9 +4932,15 @@ impl GritListIndex { _ => None, } } - pub fn as_grit_signed_int_literal(&self) -> Option<&GritSignedIntLiteral> { + pub fn as_grit_int_literal(&self) -> Option<&GritIntLiteral> { match &self { - GritListIndex::GritSignedIntLiteral(item) => Some(item), + GritListIndex::GritIntLiteral(item) => Some(item), + _ => None, + } + } + pub fn as_grit_negative_int_literal(&self) -> Option<&GritNegativeIntLiteral> { + match &self { + GritListIndex::GritNegativeIntLiteral(item) => Some(item), _ => None, } } @@ -6918,6 +6925,47 @@ impl From for SyntaxElement { n.syntax.into() } } +impl AstNode for GritNegativeIntLiteral { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_NEGATIVE_INT_LITERAL as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_NEGATIVE_INT_LITERAL + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritNegativeIntLiteral { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritNegativeIntLiteral") + .field( + "value_token", + &support::DebugSyntaxResult(self.value_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritNegativeIntLiteral) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritNegativeIntLiteral) -> SyntaxElement { + n.syntax.into() + } +} impl AstNode for GritNodeLike { type Language = Language; const KIND_SET: SyntaxKindSet = @@ -9112,47 +9160,6 @@ impl From for SyntaxElement { n.syntax.into() } } -impl AstNode for GritSignedIntLiteral { - type Language = Language; - const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_SIGNED_INT_LITERAL as u16)); - fn can_cast(kind: SyntaxKind) -> bool { - kind == GRIT_SIGNED_INT_LITERAL - } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { - &self.syntax - } - fn into_syntax(self) -> SyntaxNode { - self.syntax - } -} -impl std::fmt::Debug for GritSignedIntLiteral { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("GritSignedIntLiteral") - .field( - "value_token", - &support::DebugSyntaxResult(self.value_token()), - ) - .finish() - } -} -impl From for SyntaxNode { - fn from(n: GritSignedIntLiteral) -> SyntaxNode { - n.syntax - } -} -impl From for SyntaxElement { - fn from(n: GritSignedIntLiteral) -> SyntaxElement { - n.syntax.into() - } -} impl AstNode for GritSnippetRegex { type Language = Language; const KIND_SET: SyntaxKindSet = @@ -10140,26 +10147,33 @@ impl From for SyntaxElement { node.into() } } -impl From for GritListIndex { - fn from(node: GritSignedIntLiteral) -> GritListIndex { - GritListIndex::GritSignedIntLiteral(node) +impl From for GritListIndex { + fn from(node: GritIntLiteral) -> GritListIndex { + GritListIndex::GritIntLiteral(node) + } +} +impl From for GritListIndex { + fn from(node: GritNegativeIntLiteral) -> GritListIndex { + GritListIndex::GritNegativeIntLiteral(node) } } impl AstNode for GritListIndex { type Language = Language; - const KIND_SET: SyntaxKindSet = - AnyGritContainer::KIND_SET.union(GritSignedIntLiteral::KIND_SET); + const KIND_SET: SyntaxKindSet = AnyGritContainer::KIND_SET + .union(GritIntLiteral::KIND_SET) + .union(GritNegativeIntLiteral::KIND_SET); fn can_cast(kind: SyntaxKind) -> bool { match kind { - GRIT_SIGNED_INT_LITERAL => true, + GRIT_INT_LITERAL | GRIT_NEGATIVE_INT_LITERAL => true, k if AnyGritContainer::can_cast(k) => true, _ => false, } } fn cast(syntax: SyntaxNode) -> Option { let res = match syntax.kind() { - GRIT_SIGNED_INT_LITERAL => { - GritListIndex::GritSignedIntLiteral(GritSignedIntLiteral { syntax }) + GRIT_INT_LITERAL => GritListIndex::GritIntLiteral(GritIntLiteral { syntax }), + GRIT_NEGATIVE_INT_LITERAL => { + GritListIndex::GritNegativeIntLiteral(GritNegativeIntLiteral { syntax }) } _ => { if let Some(any_grit_container) = AnyGritContainer::cast(syntax) { @@ -10172,13 +10186,15 @@ impl AstNode for GritListIndex { } fn syntax(&self) -> &SyntaxNode { match self { - GritListIndex::GritSignedIntLiteral(it) => &it.syntax, + GritListIndex::GritIntLiteral(it) => &it.syntax, + GritListIndex::GritNegativeIntLiteral(it) => &it.syntax, GritListIndex::AnyGritContainer(it) => it.syntax(), } } fn into_syntax(self) -> SyntaxNode { match self { - GritListIndex::GritSignedIntLiteral(it) => it.syntax, + GritListIndex::GritIntLiteral(it) => it.syntax, + GritListIndex::GritNegativeIntLiteral(it) => it.syntax, GritListIndex::AnyGritContainer(it) => it.into_syntax(), } } @@ -10187,7 +10203,8 @@ impl std::fmt::Debug for GritListIndex { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { GritListIndex::AnyGritContainer(it) => std::fmt::Debug::fmt(it, f), - GritListIndex::GritSignedIntLiteral(it) => std::fmt::Debug::fmt(it, f), + GritListIndex::GritIntLiteral(it) => std::fmt::Debug::fmt(it, f), + GritListIndex::GritNegativeIntLiteral(it) => std::fmt::Debug::fmt(it, f), } } } @@ -10195,7 +10212,8 @@ impl From for SyntaxNode { fn from(n: GritListIndex) -> SyntaxNode { match n { GritListIndex::AnyGritContainer(it) => it.into(), - GritListIndex::GritSignedIntLiteral(it) => it.into(), + GritListIndex::GritIntLiteral(it) => it.into(), + GritListIndex::GritNegativeIntLiteral(it) => it.into(), } } } @@ -10760,6 +10778,11 @@ impl std::fmt::Display for GritNamedArgWithDefault { std::fmt::Display::fmt(self.syntax(), f) } } +impl std::fmt::Display for GritNegativeIntLiteral { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} impl std::fmt::Display for GritNodeLike { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -11005,11 +11028,6 @@ impl std::fmt::Display for GritSequential { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for GritSignedIntLiteral { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} impl std::fmt::Display for GritSnippetRegex { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) diff --git a/crates/biome_grit_syntax/src/generated/nodes_mut.rs b/crates/biome_grit_syntax/src/generated/nodes_mut.rs index f81caa8979a..9111a30abc3 100644 --- a/crates/biome_grit_syntax/src/generated/nodes_mut.rs +++ b/crates/biome_grit_syntax/src/generated/nodes_mut.rs @@ -1033,6 +1033,14 @@ impl GritNamedArgWithDefault { ) } } +impl GritNegativeIntLiteral { + pub fn with_value_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } +} impl GritNodeLike { pub fn with_name(self, element: GritName) -> Self { Self::unwrap_cast( @@ -2070,14 +2078,6 @@ impl GritSequential { ) } } -impl GritSignedIntLiteral { - pub fn with_value_token(self, element: SyntaxToken) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(0usize..=0usize, once(Some(element.into()))), - ) - } -} impl GritSnippetRegex { pub fn with_value_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( diff --git a/crates/biome_grit_syntax/src/lib.rs b/crates/biome_grit_syntax/src/lib.rs index 78362643cf7..700b2cd0b5c 100644 --- a/crates/biome_grit_syntax/src/lib.rs +++ b/crates/biome_grit_syntax/src/lib.rs @@ -6,7 +6,8 @@ mod generated; mod syntax_node; -use biome_rowan::{AstNode, RawSyntaxKind, TriviaPieceKind}; +use biome_rowan::{AstNode, RawSyntaxKind}; +pub use biome_rowan::{TextLen, TextRange, TextSize, TokenAtOffset, TriviaPieceKind, WalkEvent}; pub use generated::*; pub use syntax_node::*; diff --git a/crates/biome_json_parser/src/lexer/mod.rs b/crates/biome_json_parser/src/lexer/mod.rs index 6a807a766b7..5b5b0ff06da 100644 --- a/crates/biome_json_parser/src/lexer/mod.rs +++ b/crates/biome_json_parser/src/lexer/mod.rs @@ -131,29 +131,26 @@ impl<'src> Lexer<'src> { self.assert_at_char_boundary(); while let Some(byte) = self.current_byte() { - let dispatch = lookup_byte(byte); - - match dispatch { - WHS => match byte { - b'\t' | b' ' => self.advance(1), - b'\r' | b'\n' => { - break; - } - _ => { + match byte { + b'\t' | b' ' => self.advance(1), + b'\r' | b'\n' => { + break; + } + _ => match lookup_byte(byte) { + WHS => { let start = self.text_position(); self.advance(1); self.diagnostics.push( - ParseDiagnostic::new( - "The JSON standard only allows tabs, whitespace, carriage return and line feed whitespace.", - start..self.text_position(), + ParseDiagnostic::new( + "The JSON standard only allows tabs, whitespace, carriage return and line feed whitespace.", + start..self.text_position(), + ) + .with_hint("Use a regular whitespace character instead."), ) - .with_hint("Use a regular whitespace character instead."), - ) } + _ => break, }, - - _ => break, } } } @@ -719,7 +716,7 @@ impl<'src> Lexer<'src> { } } - /// Lexes a comment. Comments are not supported in JSON but it should yield better error recovery. + /// Lexes a comment. Comments are only supported in JSONC. fn lex_slash(&mut self) -> JsonSyntaxKind { let start = self.text_position(); match self.peek_byte() { diff --git a/xtask/codegen/gritql.ungram b/xtask/codegen/gritql.ungram index 151ca377ddd..4fa9effa126 100644 --- a/xtask/codegen/gritql.ungram +++ b/xtask/codegen/gritql.ungram @@ -303,7 +303,7 @@ GritListAccessor = ']' GritListAccessorSubject = GritList | AnyGritContainer -GritListIndex = AnyGritContainer | GritSignedIntLiteral +GritListIndex = AnyGritContainer | GritNegativeIntLiteral | GritIntLiteral GritDot = '.' @@ -539,7 +539,7 @@ GritNot = 'not' | '!' GritUndefined = 'undefined' GritIntLiteral = value: 'grit_int_literal' -GritSignedIntLiteral = value: 'grit_signed_int_literal' +GritNegativeIntLiteral = value: 'grit_negative_int_literal' GritDoubleLiteral = value: 'grit_double_literal' diff --git a/xtask/codegen/src/grit_kinds_src.rs b/xtask/codegen/src/grit_kinds_src.rs index 66400ee74c2..0a85b28c37f 100644 --- a/xtask/codegen/src/grit_kinds_src.rs +++ b/xtask/codegen/src/grit_kinds_src.rs @@ -90,7 +90,7 @@ pub const GRIT_KINDS_SRC: KindsSrc = KindsSrc { ], literals: &[ "GRIT_INT_LITERAL", - "GRIT_SIGNED_INT_LITERAL", + "GRIT_NEGATIVE_INT_LITERAL", "GRIT_DOUBLE_LITERAL", "GRIT_STRING_LITERAL", "GRIT_REGEX_LITERAL", @@ -100,6 +100,8 @@ pub const GRIT_KINDS_SRC: KindsSrc = KindsSrc { "NEWLINE", "WHITESPACE", "COMMENT", + "MULTILINE_COMMENT", + "ERROR_TOKEN", "GRIT_ANNOTATION", "GRIT_BACKTICK_SNIPPET", "GRIT_RAW_BACKTICK_SNIPPET", From f09ef331e08e5d9d70b3d92e6a411493fe69cabe Mon Sep 17 00:00:00 2001 From: "Arend van Beelen jr." Date: Thu, 22 Feb 2024 21:56:33 +0100 Subject: [PATCH 03/12] Support more lexer tokens --- crates/biome_grit_parser/src/lexer/mod.rs | 265 +++++++++++++++++--- crates/biome_grit_parser/src/lexer/tests.rs | 144 ++++++++--- xtask/codegen/gritql.ungram | 4 +- xtask/codegen/src/grit_kinds_src.rs | 1 - 4 files changed, 341 insertions(+), 73 deletions(-) diff --git a/crates/biome_grit_parser/src/lexer/mod.rs b/crates/biome_grit_parser/src/lexer/mod.rs index 56e99d59ddd..ebff2625aef 100644 --- a/crates/biome_grit_parser/src/lexer/mod.rs +++ b/crates/biome_grit_parser/src/lexer/mod.rs @@ -5,7 +5,6 @@ mod tests; use biome_grit_syntax::{GritSyntaxKind, GritSyntaxKind::*, TextLen, TextRange, TextSize, T}; use biome_parser::diagnostic::ParseDiagnostic; -use biome_unicode_table::{lookup_byte, Dispatch::*}; use std::iter::FusedIterator; use std::ops::Add; use unicode_bom::Bom; @@ -129,8 +128,8 @@ impl<'src> Lexer<'src> { b'\r' | b'\n' => { break; } - _ => match lookup_byte(byte) { - WHS => { + _ => match byte { + b' ' | b'\t' | b'\n' | b'\r' => { let start = self.text_position(); self.advance(1); @@ -281,6 +280,7 @@ impl<'src> Lexer<'src> { b'\n' | b'\r' => self.eat_newline(), b'\t' | b' ' => self.eat_whitespace(), b'\'' | b'"' => self.lex_string_literal(current), + b'`' => self.lex_backtick_snippet(), b'/' => self.lex_slash(), b':' => self.eat_byte(T![:]), b',' => self.eat_byte(T![,]), @@ -468,10 +468,8 @@ impl<'src> Lexer<'src> { }; while let Some(chr) = self.current_byte() { - let dispatch = lookup_byte(chr); - - match dispatch { - QOT if quote == chr => { + match chr { + b'\'' | b'"' if quote == chr => { self.advance(1); state = match state { LexStringState::InString => LexStringState::Terminated, @@ -480,12 +478,12 @@ impl<'src> Lexer<'src> { break; } // '\t' etc - BSL => { + b'\\' => { let escape_start = self.text_position(); self.advance(1); match self.current_byte() { - Some(b'"' | b'\\' | b'/' | b'b' | b'f' | b'n' | b'r' | b't') => { + Some(b'$' | b'\\' | b'"' | b'n') => { self.advance(1) } @@ -513,7 +511,7 @@ impl<'src> Lexer<'src> { "Invalid escape sequence", escape_start..self.text_position() + c.text_len(), ) - .with_hint(r#"Valid escape sequences are: `\\`, `\/`, `/"`, `\b\`, `\f`, `\n`, `\r`, `\t` or any unicode escape sequence `\uXXXX` where X is hexedecimal number. "#), + .with_hint(r#"Valid escape sequences are: `\$`, `\\`, `\"`, `\n`."#), ); state = LexStringState::InvalidEscapeSequence; } @@ -533,37 +531,16 @@ impl<'src> Lexer<'src> { } } } - WHS if matches!(chr, b'\n' | b'\r') => { + b'\n' | b'\r' => { let unterminated = ParseDiagnostic::new("Missing closing quote", start..self.text_position()) .with_detail(self.position..self.position + 1, "line breaks here"); self.diagnostics.push(unterminated); - return GRIT_STRING_LITERAL; - } - UNI => self.advance_char_unchecked(), - - // Following the same rules as JSON here: - // All code points may be placed within the quotation marks except for the code points that - //must be escaped: - // * quotation mark: (U+0022), - // * reverse solidus (U+005C), - // * and the **control characters U+0000 to U+001F** <- This - ERR | WHS if matches!(state, LexStringState::InString) && chr <= 0x1f => { - self.diagnostics.push( - ParseDiagnostic::new( - - format!( - "Control character '\\u{chr:04x}' is not allowed in string literals." - ), - self.text_position()..self.text_position() + TextSize::from(1), - ) - .with_hint(format!("Use the escape sequence '\\u{chr:04x}' instead.")), - ); - state = LexStringState::InvalidEscapeSequence; + return ERROR_TOKEN; } - _ => self.advance(1), + _ => self.advance_char_unchecked(), } } @@ -589,12 +566,90 @@ impl<'src> Lexer<'src> { ); self.diagnostics.push(unterminated); - GRIT_STRING_LITERAL + ERROR_TOKEN } LexStringState::InvalidEscapeSequence => ERROR_TOKEN, } } + fn lex_backtick_snippet(&mut self) -> GritSyntaxKind { + // Handle invalid quotes + self.assert_at_char_boundary(); + let start = self.text_position(); + + self.advance(1); // Skip over the backtick + let mut state = LexBacktickSnippet::InSnippet; + + while let Some(chr) = self.current_byte() { + match chr { + b'`' => { + self.advance(1); + state = match state { + LexBacktickSnippet::InSnippet => LexBacktickSnippet::Terminated, + state => state, + }; + break; + } + // '\t' etc + b'\\' => { + let escape_start = self.text_position(); + self.advance(1); + + match self.current_byte() { + Some(b'$' | b'\\' | b'`' | b'n') => { + self.advance(1) + } + + Some(_) => { + if matches!(state, LexBacktickSnippet::InSnippet) { + let c = self.current_char_unchecked(); + self.diagnostics.push( + ParseDiagnostic::new( + + "Invalid escape sequence", + escape_start..self.text_position() + c.text_len(), + ) + .with_hint(r#"Valid escape sequences are: `\$`, `\\`, `\``, `\n`."#), + ); + state = LexBacktickSnippet::InvalidEscapeSequence; + } + } + + None => { + if matches!(state, LexBacktickSnippet::InSnippet) { + self.diagnostics.push(ParseDiagnostic::new( + + "Expected an escape sequence following a backslash, but found none", + escape_start..self.text_position(), + ) + .with_detail(self.text_position()..self.text_position(), "File ends here") + ); + state = LexBacktickSnippet::InvalidEscapeSequence; + } + } + } + } + _ => self.advance_char_unchecked(), + } + } + + match state { + LexBacktickSnippet::Terminated => GRIT_BACKTICK_SNIPPET, + LexBacktickSnippet::InSnippet => { + let unterminated = + ParseDiagnostic::new("Missing closing quote", start..self.text_position()) + .with_detail( + self.source.text_len()..self.source.text_len(), + "file ends here", + ); + self.diagnostics.push(unterminated); + + ERROR_TOKEN + } + LexBacktickSnippet::InvalidEscapeSequence => ERROR_TOKEN, + } + } + /// Lexes a `\u0000` escape sequence. Assumes that the lexer is positioned at the `u` token. /// /// A unicode escape sequence must consist of 4 hex characters. @@ -645,14 +700,18 @@ impl<'src> Lexer<'src> { } /// Lexes a name for variables (without leading `$`), labels, and keywords. + /// + /// Branches into regular expressions and raw backticks, which have named prefixes. fn lex_name(&mut self, first: u8) -> GritSyntaxKind { + let name_start = self.text_position(); self.assert_at_char_boundary(); // Note to keep the buffer large enough to fit every possible keyword that // the lexer can return const BUFFER_SIZE: usize = 14; let mut buffer = [0u8; BUFFER_SIZE]; - let mut len = 0; + buffer[0] = first; + let mut len = 1; self.advance_byte_or_char(first); @@ -664,6 +723,43 @@ impl<'src> Lexer<'src> { } self.advance(1) + } else if byte == b'"' { + return match &buffer[..len] { + b"r" => self.lex_regex(), + _ => { + self.diagnostics.push(ParseDiagnostic::new( + + "Unxpected string prefix", + name_start..self.text_position(), + ) + .with_hint("Use the `r` prefix to create a regex literal.") + ); + + ERROR_TOKEN + } + }; + } else if byte == b'`' { + return match &buffer[..len] { + b"r" => match self.lex_backtick_snippet() { + GRIT_BACKTICK_SNIPPET => GRIT_SNIPPET_REGEX_LITERAL, + other => other + } + b"raw" => match self.lex_backtick_snippet() { + GRIT_BACKTICK_SNIPPET => GRIT_RAW_BACKTICK_SNIPPET, + other => other + } + _ => { + self.diagnostics.push(ParseDiagnostic::new( + + "Unxpected snippet prefix", + name_start..self.text_position(), + ) + .with_hint("Supported snippet prefixes are `r` and `raw`.") + ); + + ERROR_TOKEN + } + } } else { break; } @@ -716,6 +812,76 @@ impl<'src> Lexer<'src> { } } + /// Lexes a regular expression. + fn lex_regex(&mut self) -> GritSyntaxKind { + // Handle invalid quotes + self.assert_at_char_boundary(); + let start = self.text_position(); + + self.advance(1); // Skip over the quote + let mut state = LexRegexState::InRegex; + + while let Some(chr) = self.current_byte() { + match chr { + b'"' => { + self.advance(1); + state = match state { + LexRegexState::InRegex => LexRegexState::Terminated, + state => state, + }; + break; + } + // '\t' etc + b'\\' => { + let escape_start = self.text_position(); + self.advance(1); + + match self.current_byte() { + Some(_) => self.advance_char_unchecked(), + + None => { + if matches!(state, LexRegexState::InRegex) { + self.diagnostics.push(ParseDiagnostic::new( + + "Expected an escape sequence following a backslash, but found none", + escape_start..self.text_position(), + ) + .with_detail(self.text_position()..self.text_position(), "File ends here") + ); + return ERROR_TOKEN; + } + } + } + } + b'\n' | b'\r' => { + let unterminated = + ParseDiagnostic::new("Missing closing quote", start..self.text_position()) + .with_detail(self.position..self.position + 1, "line breaks here"); + + self.diagnostics.push(unterminated); + + return ERROR_TOKEN; + } + _ => self.advance_char_unchecked(), + } + } + + match state { + LexRegexState::Terminated => GRIT_REGEX_LITERAL, + LexRegexState::InRegex => { + let unterminated = + ParseDiagnostic::new("Missing closing quote", start..self.text_position()) + .with_detail( + self.source.text_len()..self.source.text_len(), + "file ends here", + ); + self.diagnostics.push(unterminated); + + ERROR_TOKEN + } + } + } + /// Lexes a variable (with leading `$`). fn lex_variable(&mut self) -> GritSyntaxKind { self.assert_at_char_boundary(); @@ -843,16 +1009,37 @@ enum InvalidNumberReason { #[derive(Copy, Clone, Debug)] enum LexStringState { - /// When using `'` instead of `"` + /// When using `'` instead of `"`. InvalidQuote, - /// String that contains an invalid escape sequence + /// String that contains an invalid escape sequence. InvalidEscapeSequence, /// Between the opening `"` and closing `"` quotes. InString, - /// Properly terminated string + /// Properly terminated string. + Terminated, +} + +#[derive(Copy, Clone, Debug)] +enum LexBacktickSnippet { + /// Between the opening and closing backticks. + InSnippet, + + /// Snippet that contains an invalid escape sequence. + InvalidEscapeSequence, + + /// Properly terminated snippet. + Terminated, +} + +#[derive(Copy, Clone, Debug)] +enum LexRegexState { + /// Between the opening and closing quotes. + InRegex, + + /// Properly terminated regex. Terminated, } diff --git a/crates/biome_grit_parser/src/lexer/tests.rs b/crates/biome_grit_parser/src/lexer/tests.rs index 63c807b0fde..88845ebd09b 100644 --- a/crates/biome_grit_parser/src/lexer/tests.rs +++ b/crates/biome_grit_parser/src/lexer/tests.rs @@ -204,14 +204,14 @@ fn object() { L_CURLY:1, WHITESPACE:1, - GRIT_NAME:5, + GRIT_NAME:3, COLON:1, WHITESPACE:1, GRIT_STRING_LITERAL:7, COMMA:1, WHITESPACE:1, - GRIT_NAME:7, + GRIT_NAME:5, COLON:1, WHITESPACE:1, GRIT_INT_LITERAL:1, @@ -234,7 +234,7 @@ fn basic_string() { fn single_quote_string() { assert_lex! { r#"'A string token using single quotes that are not supported in GritQL'"#, - ERROR_TOKEN:67, + ERROR_TOKEN:69, EOF:0 } } @@ -243,7 +243,7 @@ fn single_quote_string() { fn unterminated_string() { assert_lex! { r#""A string without the closing quote"#, - GRIT_STRING_LITERAL:35, + ERROR_TOKEN:35, EOF:0 } } @@ -251,7 +251,7 @@ fn unterminated_string() { #[test] fn simple_escape_sequences() { assert_lex! { - r#""Escaped \t""#, + r#""Escaped \$""#, GRIT_STRING_LITERAL:12, EOF:0 } @@ -268,35 +268,11 @@ fn simple_escape_sequences() { EOF:0 } - assert_lex! { - r#""Escaped \/""#, - GRIT_STRING_LITERAL:12, - EOF:0 - } - - assert_lex! { - r#""Escaped \b""#, - GRIT_STRING_LITERAL:12, - EOF:0 - } - - assert_lex! { - r#""Escaped \f""#, - GRIT_STRING_LITERAL:12, - EOF:0 - } - assert_lex! { r#""Escaped \n""#, GRIT_STRING_LITERAL:12, EOF:0 } - - assert_lex! { - r#""Escaped \r""#, - GRIT_STRING_LITERAL:12, - EOF:0 - } } #[test] @@ -354,7 +330,7 @@ fn single_quote_escape_in_single_quote_string() { } #[test] -fn identifiers() { +fn names() { assert_lex! { r#"asciiIdentifier"#, GRIT_NAME:15, @@ -384,6 +360,114 @@ fn identifiers() { } } +#[test] +fn regex() { + assert_lex! { + r#"r"a+b?""#, + GRIT_REGEX_LITERAL:7, + EOF:0 + } + + assert_lex! { + r#"r"a\\.b?""#, + GRIT_REGEX_LITERAL:9, + EOF:0 + } + + assert_lex! { + r#"r"a\"b?""#, + GRIT_REGEX_LITERAL:8, + EOF:0 + } + + assert_lex! { + r#"r"a+b?"#, + ERROR_TOKEN: 6, + EOF:0 + } +} + +#[test] +fn snippet_regex() { + assert_lex! { + r#"r`a+b?`"#, + GRIT_SNIPPET_REGEX_LITERAL:7, + EOF:0 + } + + assert_lex! { + r#"r`a\\.b?`"#, + GRIT_SNIPPET_REGEX_LITERAL:9, + EOF:0 + } + + assert_lex! { + r#"r`a\`b?`"#, + GRIT_SNIPPET_REGEX_LITERAL:8, + EOF:0 + } + + assert_lex! { + r#"r`a+b?"#, + ERROR_TOKEN: 6, + EOF:0 + } +} + +#[test] +fn snippets() { + assert_lex! { + r#"`console.log()`"#, + GRIT_BACKTICK_SNIPPET:15, + EOF:0 + } + + assert_lex! { + r#"`console.log($message)`"#, + GRIT_BACKTICK_SNIPPET:23, + EOF:0 + } + + assert_lex! { + r#"`console.log(\$message)`"#, + GRIT_BACKTICK_SNIPPET:24, + EOF:0 + } + + assert_lex! { + r#"`console.log(\/message)`"#, + ERROR_TOKEN:24, + EOF:0 + } +} + +#[test] +fn raw_snippets() { + assert_lex! { + r#"raw`console.log()`"#, + GRIT_RAW_BACKTICK_SNIPPET:18, + EOF:0 + } + + assert_lex! { + r#"raw`console.log($message)`"#, + GRIT_RAW_BACKTICK_SNIPPET:26, + EOF:0 + } + + assert_lex! { + r#"raw`console.log(\$message)`"#, + GRIT_RAW_BACKTICK_SNIPPET:27, + EOF:0 + } + + assert_lex! { + r#"raw`console.log(\/message)`"#, + ERROR_TOKEN:27, + EOF:0 + } +} + #[test] fn single_line_comments() { assert_lex! { diff --git a/xtask/codegen/gritql.ungram b/xtask/codegen/gritql.ungram index 4fa9effa126..1159133785a 100644 --- a/xtask/codegen/gritql.ungram +++ b/xtask/codegen/gritql.ungram @@ -517,11 +517,9 @@ GritBacktickSnippet = value: 'grit_backtick_snippet' GritRawBacktickSnippet = value: 'grit_raw_backtick_snippet' -GritDoubleQuoteSnippet = value: 'grit_double_quote_snippet' - GritLanguageSpecificSnippet = language: GritLanguageName - snippet: GritDoubleQuoteSnippet + snippet: 'grit_string_literal' // a code snippet may be prefixed by a label; // the label may be prefixed by a module or sort name (separated from the label by a dot) diff --git a/xtask/codegen/src/grit_kinds_src.rs b/xtask/codegen/src/grit_kinds_src.rs index 0a85b28c37f..73d6dc2efb6 100644 --- a/xtask/codegen/src/grit_kinds_src.rs +++ b/xtask/codegen/src/grit_kinds_src.rs @@ -105,7 +105,6 @@ pub const GRIT_KINDS_SRC: KindsSrc = KindsSrc { "GRIT_ANNOTATION", "GRIT_BACKTICK_SNIPPET", "GRIT_RAW_BACKTICK_SNIPPET", - "GRIT_DOUBLE_QUOTE_SNIPPET", "GRIT_NAME", "GRIT_VARIABLE", ], From b219163f85a51f3636f74f28cbcaa6076cf323fc Mon Sep 17 00:00:00 2001 From: "Arend van Beelen jr." Date: Fri, 23 Feb 2024 16:31:08 +0100 Subject: [PATCH 04/12] WIP: Start on parser --- Cargo.lock | 6 +- .../src/generated/node_factory.rs | 133 ++-- .../src/generated/syntax_factory.rs | 135 ++-- crates/biome_grit_parser/Cargo.toml | 6 +- crates/biome_grit_parser/src/lexer/mod.rs | 56 +- crates/biome_grit_parser/src/lib.rs | 96 +++ crates/biome_grit_parser/src/parser.rs | 168 ++++ crates/biome_grit_parser/src/token_source.rs | 105 +++ .../grit_test_suite/err/incorrect_engine.grit | 1 + .../err/incorrect_engine.grit.snap | 61 ++ .../err/incorrect_version.grit | 1 + .../err/incorrect_version.grit.snap | 59 ++ .../grit_test_suite/err/missing_version.grit | 1 + .../err/missing_version.grit.snap | 61 ++ .../ok/pattern_with_version.grit | 1 + .../ok/pattern_with_version.grit.snap | 51 ++ crates/biome_grit_parser/tests/spec_test.rs | 116 +++ crates/biome_grit_parser/tests/spec_tests.rs | 13 + .../biome_grit_syntax/src/generated/kind.rs | 9 +- .../biome_grit_syntax/src/generated/macros.rs | 36 +- .../biome_grit_syntax/src/generated/nodes.rs | 722 ++++++++---------- .../src/generated/nodes_mut.rs | 80 +- xtask/codegen/gritql.ungram | 37 +- xtask/codegen/src/grit_kinds_src.rs | 8 +- 24 files changed, 1309 insertions(+), 653 deletions(-) create mode 100644 crates/biome_grit_parser/src/parser.rs create mode 100644 crates/biome_grit_parser/src/token_source.rs create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_engine.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_engine.grit.snap create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_version.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_version.grit.snap create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/err/missing_version.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/err/missing_version.grit.snap create mode 100755 crates/biome_grit_parser/tests/grit_test_suite/ok/pattern_with_version.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/pattern_with_version.grit.snap create mode 100644 crates/biome_grit_parser/tests/spec_test.rs create mode 100644 crates/biome_grit_parser/tests/spec_tests.rs diff --git a/Cargo.lock b/Cargo.lock index df328bec650..c376da0ca59 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -488,13 +488,9 @@ dependencies = [ "biome_rowan", "biome_unicode_table", "bitflags 2.3.1", - "cfg-if", - "drop_bomb", - "expect-test", - "indexmap 1.9.3", + "insta", "quickcheck", "quickcheck_macros", - "rustc-hash", "schemars", "serde", "serde_json", diff --git a/crates/biome_grit_factory/src/generated/node_factory.rs b/crates/biome_grit_factory/src/generated/node_factory.rs index a4414cbe022..44c4d9d6b2d 100644 --- a/crates/biome_grit_factory/src/generated/node_factory.rs +++ b/crates/biome_grit_factory/src/generated/node_factory.rs @@ -120,7 +120,7 @@ pub fn any_grit_predicate( l_paren_token: SyntaxToken, any_grit_predicate: AnyGritPredicate, r_paren_token: SyntaxToken, - grit_boolean_literal: GritBooleanLiteral, + grit_boolean_value: GritBooleanValue, grit_predicate_return: GritPredicateReturn, grit_bogus_predicate: GritBogusPredicate, ) -> AnyGritPredicate { @@ -149,7 +149,7 @@ pub fn any_grit_predicate( Some(SyntaxElement::Token(l_paren_token)), Some(SyntaxElement::Node(any_grit_predicate.into_syntax())), Some(SyntaxElement::Token(r_paren_token)), - Some(SyntaxElement::Node(grit_boolean_literal.into_syntax())), + Some(SyntaxElement::Node(grit_boolean_value.into_syntax())), Some(SyntaxElement::Node(grit_predicate_return.into_syntax())), Some(SyntaxElement::Node(grit_bogus_predicate.into_syntax())), ], @@ -209,12 +209,9 @@ pub fn grit_backtick_snippet(value_token: SyntaxToken) -> GritBacktickSnippet { [Some(SyntaxElement::Token(value_token))], )) } -pub fn grit_boolean_literal( - true_token: SyntaxToken, - false_token: SyntaxToken, -) -> GritBooleanLiteral { - GritBooleanLiteral::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_BOOLEAN_LITERAL, +pub fn grit_boolean_value(true_token: SyntaxToken, false_token: SyntaxToken) -> GritBooleanValue { + GritBooleanValue::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_BOOLEAN_VALUE, [ Some(SyntaxElement::Token(true_token)), Some(SyntaxElement::Token(false_token)), @@ -369,15 +366,9 @@ impl GritDotdotdotBuilder { )) } } -pub fn grit_double_literal(value_token: SyntaxToken) -> GritDoubleLiteral { - GritDoubleLiteral::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_DOUBLE_LITERAL, - [Some(SyntaxElement::Token(value_token))], - )) -} -pub fn grit_double_quote_snippet(value_token: SyntaxToken) -> GritDoubleQuoteSnippet { - GritDoubleQuoteSnippet::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_DOUBLE_QUOTE_SNIPPET, +pub fn grit_double_value(value_token: SyntaxToken) -> GritDoubleValue { + GritDoubleValue::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_DOUBLE_VALUE, [Some(SyntaxElement::Token(value_token))], )) } @@ -450,9 +441,9 @@ impl GritFunctionDefinitionBuilder { )) } } -pub fn grit_int_literal(value_token: SyntaxToken) -> GritIntLiteral { - GritIntLiteral::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_INT_LITERAL, +pub fn grit_int_value(value_token: SyntaxToken) -> GritIntValue { + GritIntValue::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_INT_VALUE, [Some(SyntaxElement::Token(value_token))], )) } @@ -464,18 +455,24 @@ pub fn grit_language_declaration( language_token, name, flavor: None, + semicolon_token: None, } } pub struct GritLanguageDeclarationBuilder { language_token: SyntaxToken, name: GritLanguageName, flavor: Option, + semicolon_token: Option, } impl GritLanguageDeclarationBuilder { pub fn with_flavor(mut self, flavor: GritLanguageFlavor) -> Self { self.flavor = Some(flavor); self } + pub fn with_semicolon_token(mut self, semicolon_token: SyntaxToken) -> Self { + self.semicolon_token = Some(semicolon_token); + self + } pub fn build(self) -> GritLanguageDeclaration { GritLanguageDeclaration::unwrap_cast(SyntaxNode::new_detached( GritSyntaxKind::GRIT_LANGUAGE_DECLARATION, @@ -484,6 +481,8 @@ impl GritLanguageDeclarationBuilder { Some(SyntaxElement::Node(self.name.into_syntax())), self.flavor .map(|token| SyntaxElement::Node(token.into_syntax())), + self.semicolon_token + .map(|token| SyntaxElement::Token(token)), ], )) } @@ -492,39 +491,15 @@ pub fn grit_language_flavor( l_paren_token: SyntaxToken, grit_language_flavor_list: GritLanguageFlavorList, r_paren_token: SyntaxToken, -) -> GritLanguageFlavorBuilder { - GritLanguageFlavorBuilder { - l_paren_token, - grit_language_flavor_list, - r_paren_token, - semicolon_token: None, - } -} -pub struct GritLanguageFlavorBuilder { - l_paren_token: SyntaxToken, - grit_language_flavor_list: GritLanguageFlavorList, - r_paren_token: SyntaxToken, - semicolon_token: Option, -} -impl GritLanguageFlavorBuilder { - pub fn with_semicolon_token(mut self, semicolon_token: SyntaxToken) -> Self { - self.semicolon_token = Some(semicolon_token); - self - } - pub fn build(self) -> GritLanguageFlavor { - GritLanguageFlavor::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_LANGUAGE_FLAVOR, - [ - Some(SyntaxElement::Token(self.l_paren_token)), - Some(SyntaxElement::Node( - self.grit_language_flavor_list.into_syntax(), - )), - Some(SyntaxElement::Token(self.r_paren_token)), - self.semicolon_token - .map(|token| SyntaxElement::Token(token)), - ], - )) - } +) -> GritLanguageFlavor { + GritLanguageFlavor::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_LANGUAGE_FLAVOR, + [ + Some(SyntaxElement::Token(l_paren_token)), + Some(SyntaxElement::Node(grit_language_flavor_list.into_syntax())), + Some(SyntaxElement::Token(r_paren_token)), + ], + )) } pub fn grit_language_flavor_kind(flavor_kind_token: SyntaxToken) -> GritLanguageFlavorKind { GritLanguageFlavorKind::unwrap_cast(SyntaxNode::new_detached( @@ -552,13 +527,13 @@ pub fn grit_language_name( } pub fn grit_language_specific_snippet( language: GritLanguageName, - snippet: GritDoubleQuoteSnippet, + snippet_token: SyntaxToken, ) -> GritLanguageSpecificSnippet { GritLanguageSpecificSnippet::unwrap_cast(SyntaxNode::new_detached( GritSyntaxKind::GRIT_LANGUAGE_SPECIFIC_SNIPPET, [ Some(SyntaxElement::Node(language.into_syntax())), - Some(SyntaxElement::Node(snippet.into_syntax())), + Some(SyntaxElement::Token(snippet_token)), ], )) } @@ -780,9 +755,9 @@ pub fn grit_named_arg_with_default( ], )) } -pub fn grit_negative_int_literal(value_token: SyntaxToken) -> GritNegativeIntLiteral { - GritNegativeIntLiteral::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_NEGATIVE_INT_LITERAL, +pub fn grit_negative_int_value(value_token: SyntaxToken) -> GritNegativeIntValue { + GritNegativeIntValue::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_NEGATIVE_INT_VALUE, [Some(SyntaxElement::Token(value_token))], )) } @@ -1171,7 +1146,7 @@ pub fn grit_pattern_includes( pub fn grit_pattern_limit( pattern: AnyGritPattern, limit_token: SyntaxToken, - limit: GritIntLiteral, + limit: GritIntValue, ) -> GritPatternLimit { GritPatternLimit::unwrap_cast(SyntaxNode::new_detached( GritSyntaxKind::GRIT_PATTERN_LIMIT, @@ -1720,12 +1695,6 @@ pub fn grit_raw_backtick_snippet(value_token: SyntaxToken) -> GritRawBacktickSni [Some(SyntaxElement::Token(value_token))], )) } -pub fn grit_regex_literal(value_token: SyntaxToken) -> GritRegexLiteral { - GritRegexLiteral::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_REGEX_LITERAL, - [Some(SyntaxElement::Token(value_token))], - )) -} pub fn grit_regex_pattern(regex: GritRegex) -> GritRegexPatternBuilder { GritRegexPatternBuilder { regex, @@ -1784,6 +1753,12 @@ impl GritRegexPatternVariablesBuilder { )) } } +pub fn grit_regex_value(value_token: SyntaxToken) -> GritRegexValue { + GritRegexValue::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_REGEX_VALUE, + [Some(SyntaxElement::Token(value_token))], + )) +} pub fn grit_rewrite( left: AnyGritPattern, fat_arrow_token: SyntaxToken, @@ -1820,8 +1795,10 @@ impl GritRewriteBuilder { )) } } -pub fn grit_root() -> GritRootBuilder { +pub fn grit_root(eof_token: SyntaxToken) -> GritRootBuilder { GritRootBuilder { + eof_token, + bom_token: None, version: None, language: None, definitions: None, @@ -1830,6 +1807,8 @@ pub fn grit_root() -> GritRootBuilder { } } pub struct GritRootBuilder { + eof_token: SyntaxToken, + bom_token: Option, version: Option, language: Option, definitions: Option, @@ -1837,6 +1816,10 @@ pub struct GritRootBuilder { definitions_continued: Option, } impl GritRootBuilder { + pub fn with_bom_token(mut self, bom_token: SyntaxToken) -> Self { + self.bom_token = Some(bom_token); + self + } pub fn with_version(mut self, version: GritVersion) -> Self { self.version = Some(version); self @@ -1861,6 +1844,7 @@ impl GritRootBuilder { GritRoot::unwrap_cast(SyntaxNode::new_detached( GritSyntaxKind::GRIT_ROOT, [ + self.bom_token.map(|token| SyntaxElement::Token(token)), self.version .map(|token| SyntaxElement::Node(token.into_syntax())), self.language @@ -1871,6 +1855,7 @@ impl GritRootBuilder { .map(|token| SyntaxElement::Node(token.into_syntax())), self.definitions_continued .map(|token| SyntaxElement::Node(token.into_syntax())), + Some(SyntaxElement::Token(self.eof_token)), ], )) } @@ -1891,9 +1876,9 @@ pub fn grit_sequential( ], )) } -pub fn grit_snippet_regex(value_token: SyntaxToken) -> GritSnippetRegex { - GritSnippetRegex::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_SNIPPET_REGEX, +pub fn grit_snippet_regex_value(value_token: SyntaxToken) -> GritSnippetRegexValue { + GritSnippetRegexValue::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_SNIPPET_REGEX_VALUE, [Some(SyntaxElement::Token(value_token))], )) } @@ -1906,9 +1891,9 @@ pub fn grit_some(some_token: SyntaxToken, pattern: MaybeCurlyGritPattern) -> Gri ], )) } -pub fn grit_string_literal(value_token: SyntaxToken) -> GritStringLiteral { - GritStringLiteral::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_STRING_LITERAL, +pub fn grit_string_value(value_token: SyntaxToken) -> GritStringValue { + GritStringValue::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_STRING_VALUE, [Some(SyntaxElement::Token(value_token))], )) } @@ -1948,7 +1933,7 @@ pub fn grit_version( engine_token: SyntaxToken, biome_token: SyntaxToken, l_paren_token: SyntaxToken, - grit_double_literal: GritDoubleLiteral, + grit_double_value: GritDoubleValue, r_paren_token: SyntaxToken, ) -> GritVersion { GritVersion::unwrap_cast(SyntaxNode::new_detached( @@ -1957,7 +1942,7 @@ pub fn grit_version( Some(SyntaxElement::Token(engine_token)), Some(SyntaxElement::Token(biome_token)), Some(SyntaxElement::Token(l_paren_token)), - Some(SyntaxElement::Node(grit_double_literal.into_syntax())), + Some(SyntaxElement::Node(grit_double_value.into_syntax())), Some(SyntaxElement::Token(r_paren_token)), ], )) diff --git a/crates/biome_grit_factory/src/generated/syntax_factory.rs b/crates/biome_grit_factory/src/generated/syntax_factory.rs index 08ddf6a0f44..2409a8f45ac 100644 --- a/crates/biome_grit_factory/src/generated/syntax_factory.rs +++ b/crates/biome_grit_factory/src/generated/syntax_factory.rs @@ -464,7 +464,7 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.next_slot(); if let Some(element) = ¤t_element { - if GritBooleanLiteral::can_cast(element.kind()) { + if GritBooleanValue::can_cast(element.kind()) { slots.mark_present(); current_element = elements.next(); } @@ -629,7 +629,7 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.into_node(GRIT_BACKTICK_SNIPPET, children) } - GRIT_BOOLEAN_LITERAL => { + GRIT_BOOLEAN_VALUE => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); let mut current_element = elements.next(); @@ -649,11 +649,11 @@ impl SyntaxFactory for GritSyntaxFactory { slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( - GRIT_BOOLEAN_LITERAL.to_bogus(), + GRIT_BOOLEAN_VALUE.to_bogus(), children.into_iter().map(Some), ); } - slots.into_node(GRIT_BOOLEAN_LITERAL, children) + slots.into_node(GRIT_BOOLEAN_VALUE, children) } GRIT_BUBBLE => { let mut elements = (&children).into_iter(); @@ -848,7 +848,7 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.into_node(GRIT_DOTDOTDOT, children) } - GRIT_DOUBLE_LITERAL => { + GRIT_DOUBLE_VALUE => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); let mut current_element = elements.next(); @@ -861,30 +861,11 @@ impl SyntaxFactory for GritSyntaxFactory { slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( - GRIT_DOUBLE_LITERAL.to_bogus(), + GRIT_DOUBLE_VALUE.to_bogus(), children.into_iter().map(Some), ); } - slots.into_node(GRIT_DOUBLE_LITERAL, children) - } - GRIT_DOUBLE_QUOTE_SNIPPET => { - let mut elements = (&children).into_iter(); - let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); - let mut current_element = elements.next(); - if let Some(element) = ¤t_element { - if element.kind() == GRIT_DOUBLE_QUOTE_SNIPPET { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if current_element.is_some() { - return RawSyntaxNode::new( - GRIT_DOUBLE_QUOTE_SNIPPET.to_bogus(), - children.into_iter().map(Some), - ); - } - slots.into_node(GRIT_DOUBLE_QUOTE_SNIPPET, children) + slots.into_node(GRIT_DOUBLE_VALUE, children) } GRIT_EVERY => { let mut elements = (&children).into_iter(); @@ -1006,7 +987,7 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.into_node(GRIT_FUNCTION_DEFINITION, children) } - GRIT_INT_LITERAL => { + GRIT_INT_VALUE => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); let mut current_element = elements.next(); @@ -1019,15 +1000,15 @@ impl SyntaxFactory for GritSyntaxFactory { slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( - GRIT_INT_LITERAL.to_bogus(), + GRIT_INT_VALUE.to_bogus(), children.into_iter().map(Some), ); } - slots.into_node(GRIT_INT_LITERAL, children) + slots.into_node(GRIT_INT_VALUE, children) } GRIT_LANGUAGE_DECLARATION => { let mut elements = (&children).into_iter(); - let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); let mut current_element = elements.next(); if let Some(element) = ¤t_element { if element.kind() == T![language] { @@ -1050,6 +1031,13 @@ impl SyntaxFactory for GritSyntaxFactory { } } slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [;] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( GRIT_LANGUAGE_DECLARATION.to_bogus(), @@ -1060,7 +1048,7 @@ impl SyntaxFactory for GritSyntaxFactory { } GRIT_LANGUAGE_FLAVOR => { let mut elements = (&children).into_iter(); - let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); let mut current_element = elements.next(); if let Some(element) = ¤t_element { if element.kind() == T!['('] { @@ -1083,13 +1071,6 @@ impl SyntaxFactory for GritSyntaxFactory { } } slots.next_slot(); - if let Some(element) = ¤t_element { - if element.kind() == T ! [;] { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( GRIT_LANGUAGE_FLAVOR.to_bogus(), @@ -1176,7 +1157,7 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.next_slot(); if let Some(element) = ¤t_element { - if GritDoubleQuoteSnippet::can_cast(element.kind()) { + if element.kind() == GRIT_STRING_LITERAL { slots.mark_present(); current_element = elements.next(); } @@ -1583,7 +1564,7 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.into_node(GRIT_NAMED_ARG_WITH_DEFAULT, children) } - GRIT_NEGATIVE_INT_LITERAL => { + GRIT_NEGATIVE_INT_VALUE => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); let mut current_element = elements.next(); @@ -1596,11 +1577,11 @@ impl SyntaxFactory for GritSyntaxFactory { slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( - GRIT_NEGATIVE_INT_LITERAL.to_bogus(), + GRIT_NEGATIVE_INT_VALUE.to_bogus(), children.into_iter().map(Some), ); } - slots.into_node(GRIT_NEGATIVE_INT_LITERAL, children) + slots.into_node(GRIT_NEGATIVE_INT_VALUE, children) } GRIT_NODE_LIKE => { let mut elements = (&children).into_iter(); @@ -2167,7 +2148,7 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.next_slot(); if let Some(element) = ¤t_element { - if GritIntLiteral::can_cast(element.kind()) { + if GritIntValue::can_cast(element.kind()) { slots.mark_present(); current_element = elements.next(); } @@ -3074,25 +3055,6 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.into_node(GRIT_RAW_BACKTICK_SNIPPET, children) } - GRIT_REGEX_LITERAL => { - let mut elements = (&children).into_iter(); - let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); - let mut current_element = elements.next(); - if let Some(element) = ¤t_element { - if element.kind() == GRIT_REGEX_LITERAL { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if current_element.is_some() { - return RawSyntaxNode::new( - GRIT_REGEX_LITERAL.to_bogus(), - children.into_iter().map(Some), - ); - } - slots.into_node(GRIT_REGEX_LITERAL, children) - } GRIT_REGEX_PATTERN => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); @@ -3152,6 +3114,25 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.into_node(GRIT_REGEX_PATTERN_VARIABLES, children) } + GRIT_REGEX_VALUE => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == GRIT_REGEX_LITERAL { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_REGEX_VALUE.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_REGEX_VALUE, children) + } GRIT_REWRITE => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); @@ -3194,8 +3175,15 @@ impl SyntaxFactory for GritSyntaxFactory { } GRIT_ROOT => { let mut elements = (&children).into_iter(); - let mut slots: RawNodeSlots<5usize> = RawNodeSlots::default(); + let mut slots: RawNodeSlots<7usize> = RawNodeSlots::default(); let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![UNICODE_BOM] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); if let Some(element) = ¤t_element { if GritVersion::can_cast(element.kind()) { slots.mark_present(); @@ -3231,6 +3219,13 @@ impl SyntaxFactory for GritSyntaxFactory { } } slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![EOF] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( GRIT_ROOT.to_bogus(), @@ -3279,7 +3274,7 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.into_node(GRIT_SEQUENTIAL, children) } - GRIT_SNIPPET_REGEX => { + GRIT_SNIPPET_REGEX_VALUE => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); let mut current_element = elements.next(); @@ -3292,11 +3287,11 @@ impl SyntaxFactory for GritSyntaxFactory { slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( - GRIT_SNIPPET_REGEX.to_bogus(), + GRIT_SNIPPET_REGEX_VALUE.to_bogus(), children.into_iter().map(Some), ); } - slots.into_node(GRIT_SNIPPET_REGEX, children) + slots.into_node(GRIT_SNIPPET_REGEX_VALUE, children) } GRIT_SOME => { let mut elements = (&children).into_iter(); @@ -3324,7 +3319,7 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.into_node(GRIT_SOME, children) } - GRIT_STRING_LITERAL => { + GRIT_STRING_VALUE => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); let mut current_element = elements.next(); @@ -3337,11 +3332,11 @@ impl SyntaxFactory for GritSyntaxFactory { slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( - GRIT_STRING_LITERAL.to_bogus(), + GRIT_STRING_VALUE.to_bogus(), children.into_iter().map(Some), ); } - slots.into_node(GRIT_STRING_LITERAL, children) + slots.into_node(GRIT_STRING_VALUE, children) } GRIT_SUB_OPERATION => { let mut elements = (&children).into_iter(); @@ -3459,7 +3454,7 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.next_slot(); if let Some(element) = ¤t_element { - if GritDoubleLiteral::can_cast(element.kind()) { + if GritDoubleValue::can_cast(element.kind()) { slots.mark_present(); current_element = elements.next(); } diff --git a/crates/biome_grit_parser/Cargo.toml b/crates/biome_grit_parser/Cargo.toml index d636d9d8771..6b4e25c6050 100644 --- a/crates/biome_grit_parser/Cargo.toml +++ b/crates/biome_grit_parser/Cargo.toml @@ -19,10 +19,6 @@ biome_parser = { workspace = true } biome_rowan = { workspace = true } biome_unicode_table = { workspace = true } bitflags = { workspace = true } -cfg-if = "1.0.0" -drop_bomb = "0.1.5" -indexmap = { workspace = true } -rustc-hash = { workspace = true } schemars = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } @@ -31,7 +27,7 @@ tracing = { workspace = true } unicode-bom = { workspace = true } [dev-dependencies] -expect-test = "1.2.2" +insta = { workspace = true } quickcheck = { workspace = true } quickcheck_macros = { workspace = true } tests_macros = { workspace = true } diff --git a/crates/biome_grit_parser/src/lexer/mod.rs b/crates/biome_grit_parser/src/lexer/mod.rs index ebff2625aef..2f61d305522 100644 --- a/crates/biome_grit_parser/src/lexer/mod.rs +++ b/crates/biome_grit_parser/src/lexer/mod.rs @@ -288,6 +288,8 @@ impl<'src> Lexer<'src> { b']' => self.eat_byte(T![']']), b'{' => self.eat_byte(T!['{']), b'}' => self.eat_byte(T!['}']), + b'(' => self.eat_byte(T!['(']), + b')' => self.eat_byte(T![')']), b'$' => self.lex_variable(), _ if is_leading_identifier_byte(current) => self.lex_name(current), _ if (b'0'..=b'9').contains(¤t) || current == b'-' => self.lex_number(current), @@ -483,9 +485,7 @@ impl<'src> Lexer<'src> { self.advance(1); match self.current_byte() { - Some(b'$' | b'\\' | b'"' | b'n') => { - self.advance(1) - } + Some(b'$' | b'\\' | b'"' | b'n') => self.advance(1), Some(b'u') => match (self.lex_unicode_escape(), state) { (Ok(_), _) => {} @@ -507,11 +507,12 @@ impl<'src> Lexer<'src> { let c = self.current_char_unchecked(); self.diagnostics.push( ParseDiagnostic::new( - "Invalid escape sequence", escape_start..self.text_position() + c.text_len(), ) - .with_hint(r#"Valid escape sequences are: `\$`, `\\`, `\"`, `\n`."#), + .with_hint( + r#"Valid escape sequences are: `\$`, `\\`, `\"`, `\n`."#, + ), ); state = LexStringState::InvalidEscapeSequence; } @@ -596,20 +597,19 @@ impl<'src> Lexer<'src> { self.advance(1); match self.current_byte() { - Some(b'$' | b'\\' | b'`' | b'n') => { - self.advance(1) - } + Some(b'$' | b'\\' | b'`' | b'n') => self.advance(1), Some(_) => { if matches!(state, LexBacktickSnippet::InSnippet) { let c = self.current_char_unchecked(); self.diagnostics.push( ParseDiagnostic::new( - "Invalid escape sequence", escape_start..self.text_position() + c.text_len(), ) - .with_hint(r#"Valid escape sequences are: `\$`, `\\`, `\``, `\n`."#), + .with_hint( + r#"Valid escape sequences are: `\$`, `\\`, `\``, `\n`."#, + ), ); state = LexBacktickSnippet::InvalidEscapeSequence; } @@ -727,12 +727,12 @@ impl<'src> Lexer<'src> { return match &buffer[..len] { b"r" => self.lex_regex(), _ => { - self.diagnostics.push(ParseDiagnostic::new( - - "Unxpected string prefix", - name_start..self.text_position(), - ) - .with_hint("Use the `r` prefix to create a regex literal.") + self.diagnostics.push( + ParseDiagnostic::new( + "Unxpected string prefix", + name_start..self.text_position(), + ) + .with_hint("Use the `r` prefix to create a regex literal."), ); ERROR_TOKEN @@ -742,24 +742,24 @@ impl<'src> Lexer<'src> { return match &buffer[..len] { b"r" => match self.lex_backtick_snippet() { GRIT_BACKTICK_SNIPPET => GRIT_SNIPPET_REGEX_LITERAL, - other => other - } + other => other, + }, b"raw" => match self.lex_backtick_snippet() { GRIT_BACKTICK_SNIPPET => GRIT_RAW_BACKTICK_SNIPPET, - other => other - } + other => other, + }, _ => { - self.diagnostics.push(ParseDiagnostic::new( - - "Unxpected snippet prefix", - name_start..self.text_position(), - ) - .with_hint("Supported snippet prefixes are `r` and `raw`.") + self.diagnostics.push( + ParseDiagnostic::new( + "Unxpected snippet prefix", + name_start..self.text_position(), + ) + .with_hint("Supported snippet prefixes are `r` and `raw`."), ); - + ERROR_TOKEN } - } + }; } else { break; } diff --git a/crates/biome_grit_parser/src/lib.rs b/crates/biome_grit_parser/src/lib.rs index a5464ca53a5..0c0485705a5 100644 --- a/crates/biome_grit_parser/src/lib.rs +++ b/crates/biome_grit_parser/src/lib.rs @@ -1 +1,97 @@ mod lexer; +mod parser; +mod token_source; + +use biome_grit_factory::GritSyntaxFactory; +use biome_grit_syntax::{GritLanguage, GritRoot, GritSyntaxNode}; +use biome_parser::diagnostic::ParseDiagnostic; +use biome_parser::tree_sink::LosslessTreeSink; +use biome_rowan::{AstNode, NodeCache}; +use parser::{parse_root, GritParser}; + +pub(crate) type GritLosslessTreeSink<'source> = + LosslessTreeSink<'source, GritLanguage, GritSyntaxFactory>; + +pub fn parse_grit(source: &str) -> GritParse { + let mut cache = NodeCache::default(); + parse_grit_with_cache(source, &mut cache) +} + +/// Parses the provided string as a GritQL pattern using the provided node cache. +pub fn parse_grit_with_cache(source: &str, cache: &mut NodeCache) -> GritParse { + tracing::debug_span!("parse").in_scope(move || { + let mut parser = GritParser::new(source); + + parse_root(&mut parser); + + let (events, diagnostics, trivia) = parser.finish(); + + let mut tree_sink = GritLosslessTreeSink::with_cache(source, &trivia, cache); + biome_parser::event::process(&mut tree_sink, events, diagnostics); + let (green, diagnostics) = tree_sink.finish(); + + GritParse::new(green, diagnostics) + }) +} + +/// A utility struct for managing the result of a parser job +#[derive(Debug)] +pub struct GritParse { + root: GritSyntaxNode, + diagnostics: Vec, +} + +impl GritParse { + pub fn new(root: GritSyntaxNode, diagnostics: Vec) -> Self { + Self { root, diagnostics } + } + + /// The syntax node represented by this Parse result + /// + /// ``` + /// # use biome_grit_parser::parse_grit; + /// # use biome_grit_syntax::GritSyntaxKind; + /// # use biome_rowan::{AstNode, AstNodeList, SyntaxError}; + /// + /// # fn main() -> Result<(), SyntaxError> { + /// use biome_grit_syntax::GritSyntaxKind; + /// use biome_grit_parser::GritParserOptions; + /// let parse = parse_grit(r#"`console.log($message)`"#); + /// + /// // Get the root value + /// let root_value = parse.tree().value()?; + /// + /// assert_eq!(root_value.syntax().kind(), GritSyntaxKind::GRIT_ARRAY_VALUE); + /// + /// # Ok(()) + /// # } + /// ``` + pub fn syntax(&self) -> GritSyntaxNode { + self.root.clone() + } + + /// Get the diagnostics which occurred when parsing + pub fn diagnostics(&self) -> &[ParseDiagnostic] { + &self.diagnostics + } + + /// Get the diagnostics which occurred when parsing + pub fn into_diagnostics(self) -> Vec { + self.diagnostics + } + + /// Returns [true] if the parser encountered some errors during the parsing. + pub fn has_errors(&self) -> bool { + self.diagnostics + .iter() + .any(|diagnostic| diagnostic.is_error()) + } + + /// Convert this parse result into a typed AST node. + /// + /// # Panics + /// Panics if the node represented by this parse result mismatches. + pub fn tree(&self) -> GritRoot { + GritRoot::unwrap_cast(self.syntax()) + } +} diff --git a/crates/biome_grit_parser/src/parser.rs b/crates/biome_grit_parser/src/parser.rs new file mode 100644 index 00000000000..ab3096aa147 --- /dev/null +++ b/crates/biome_grit_parser/src/parser.rs @@ -0,0 +1,168 @@ +use crate::token_source::GritTokenSource; +use biome_grit_syntax::GritSyntaxKind::{self, *}; +use biome_grit_syntax::T; +use biome_parser::diagnostic::merge_diagnostics; +use biome_parser::event::Event; +use biome_parser::prelude::{ParsedSyntax::*, *}; +use biome_parser::token_source::Trivia; +use biome_parser::ParserContext; +use biome_rowan::TextRange; + +pub(crate) struct GritParser<'source> { + context: ParserContext, + source: GritTokenSource<'source>, +} + +impl<'source> GritParser<'source> { + pub fn new(source: &'source str) -> Self { + Self { + context: ParserContext::default(), + source: GritTokenSource::from_str(source), + } + } + + pub fn finish( + self, + ) -> ( + Vec>, + Vec, + Vec, + ) { + let (trivia, lexer_diagnostics) = self.source.finish(); + let (events, parse_diagnostics) = self.context.finish(); + + let diagnostics = merge_diagnostics(lexer_diagnostics, parse_diagnostics); + + (events, diagnostics, trivia) + } +} + +impl<'source> Parser for GritParser<'source> { + type Kind = GritSyntaxKind; + type Source = GritTokenSource<'source>; + + fn context(&self) -> &ParserContext { + &self.context + } + + fn context_mut(&mut self) -> &mut ParserContext { + &mut self.context + } + + fn source(&self) -> &Self::Source { + &self.source + } + + fn source_mut(&mut self) -> &mut Self::Source { + &mut self.source + } +} + +pub(crate) fn parse_root(p: &mut GritParser) -> CompletedMarker { + let m = p.start(); + + p.eat(UNICODE_BOM); + + parse_version(p); + parse_language(p); + parse_definition_list(p); + //parse_pattern(p); + parse_definition_list(p); + + p.eat(EOF); + + m.complete(p, GRIT_ROOT) +} + +fn parse_version(p: &mut GritParser) -> Option { + if !p.at(T![engine]) { + return None; + } + + let m = p.start(); + p.bump(T![engine]); + + let engine_range = p.cur_range(); + if p.eat(T![biome]) { + if p.eat(T!['(']) { + match parse_double_value(p) { + Present(_) => { + p.eat(T![')']); + } + Absent => p.error(p.err_builder("Expected version as a double", p.cur_range())), + } + } else { + let engine_end = engine_range.end(); + p.error(p.err_builder( + "Expected an engine version", + TextRange::new(engine_end, engine_end), + )) + } + } else { + p.error(p.err_builder("Engine must be `biome`", engine_range)); + } + + let result = m.complete(p, GRIT_VERSION); + + Some(result) +} + +fn parse_double_value(p: &mut GritParser) -> ParsedSyntax { + if !p.at(GRIT_DOUBLE_LITERAL) { + return Absent; + } + + let m = p.start(); + p.bump(GRIT_DOUBLE_LITERAL); + Present(m.complete(p, GRIT_DOUBLE_VALUE)) +} + +fn parse_language(p: &mut GritParser) -> Option { + if !p.at(T![language]) { + return None; + } + + let m = p.start(); + p.bump(T![language]); + + if !p.eat(GRIT_LANGUAGE_NAME) { + p.error(p.err_builder("Expected a supported language", p.cur_range())) + } + + parse_language_flavor(p); + + p.eat(T![;]); + + let result = m.complete(p, GRIT_LANGUAGE_DECLARATION); + + Some(result) +} + +fn parse_language_flavor(p: &mut GritParser) -> Option { + if !p.at(T!['(']) { + return None; + } + + let m = p.start(); + p.eat(T!['(']); + + while p.eat(GRIT_LANGUAGE_FLAVOR_KIND) { + if !p.eat(T![,]) { + break; + } + } + + p.expect(T![')']); + + let result = m.complete(p, GRIT_LANGUAGE_FLAVOR); + + Some(result) +} + +fn parse_definition_list(p: &mut GritParser) -> CompletedMarker { + let m = p.start(); + + // TODO + + m.complete(p, GRIT_DEFINITION_LIST) +} diff --git a/crates/biome_grit_parser/src/token_source.rs b/crates/biome_grit_parser/src/token_source.rs new file mode 100644 index 00000000000..bbff3951eca --- /dev/null +++ b/crates/biome_grit_parser/src/token_source.rs @@ -0,0 +1,105 @@ +use crate::lexer::{Lexer, Token}; +use biome_grit_syntax::GritSyntaxKind::{EOF, TOMBSTONE}; +use biome_grit_syntax::{GritSyntaxKind, TextRange}; +use biome_parser::diagnostic::ParseDiagnostic; +use biome_parser::prelude::TokenSource; +use biome_parser::token_source::Trivia; +use biome_rowan::TriviaPieceKind; + +pub(crate) struct GritTokenSource<'source> { + lexer: Lexer<'source>, + trivia: Vec, + current: GritSyntaxKind, + current_range: TextRange, + preceding_line_break: bool, +} + +impl<'source> GritTokenSource<'source> { + pub fn from_str(source: &'source str) -> Self { + let lexer = Lexer::from_str(source); + + let mut source = Self { + lexer, + trivia: Vec::new(), + current: TOMBSTONE, + current_range: TextRange::default(), + preceding_line_break: false, + }; + + source.next_non_trivia_token(true); + source + } + + fn next_non_trivia_token(&mut self, first_token: bool) { + let mut trailing = !first_token; + self.preceding_line_break = false; + + while let Some(token) = self.lexer.next_token() { + let trivia_kind = TriviaPieceKind::try_from(token.kind()); + + match trivia_kind { + Err(_) => { + self.set_current_token(token); + // Not trivia + break; + } + Ok(trivia_kind) => { + if trivia_kind.is_newline() { + trailing = false; + self.preceding_line_break = true; + } + + self.trivia + .push(Trivia::new(trivia_kind, token.range(), trailing)); + } + } + } + } + + fn set_current_token(&mut self, token: Token) { + self.current = token.kind(); + self.current_range = token.range() + } +} + +impl<'source> TokenSource for GritTokenSource<'source> { + type Kind = GritSyntaxKind; + + fn current(&self) -> Self::Kind { + self.current + } + + fn current_range(&self) -> TextRange { + self.current_range + } + + fn text(&self) -> &str { + self.lexer.source() + } + + fn has_preceding_line_break(&self) -> bool { + self.preceding_line_break + } + + fn bump(&mut self) { + if self.current != EOF { + self.next_non_trivia_token(false) + } + } + + fn skip_as_trivia(&mut self) { + if self.current() != EOF { + self.trivia.push(Trivia::new( + TriviaPieceKind::Skipped, + self.current_range(), + false, + )); + + self.next_non_trivia_token(false) + } + } + + fn finish(self) -> (Vec, Vec) { + (self.trivia, self.lexer.finish()) + } +} diff --git a/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_engine.grit b/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_engine.grit new file mode 100644 index 00000000000..ddc662cab0c --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_engine.grit @@ -0,0 +1 @@ +engine marzano (1.0) diff --git a/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_engine.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_engine.grit.snap new file mode 100644 index 00000000000..26ca00a9d33 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_engine.grit.snap @@ -0,0 +1,61 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +engine marzano (1.0) + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: GritVersion { + engine_token: ENGINE_KW@0..7 "engine" [] [Whitespace(" ")], + biome_token: missing (required), + l_paren_token: missing (required), + grit_double_value: missing (required), + r_paren_token: missing (required), + }, + language: missing (optional), + definitions: GritDefinitionList [], + pattern: missing (optional), + definitions_continued: GritDefinitionList [], + eof_token: EOF@7..21 "marzano (1.0)\n" [] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..21 + 0: (empty) + 1: GRIT_VERSION@0..7 + 0: ENGINE_KW@0..7 "engine" [] [Whitespace(" ")] + 1: (empty) + 2: (empty) + 3: (empty) + 4: (empty) + 2: (empty) + 3: GRIT_DEFINITION_LIST@7..7 + 4: (empty) + 5: GRIT_DEFINITION_LIST@7..7 + 6: EOF@7..21 "marzano (1.0)\n" [] [] + +``` + +## Diagnostics + +``` +incorrect_engine.grit:1:8 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Engine must be `biome` + + > 1 │ engine marzano (1.0) + │ ^^^^^^^ + 2 │ + +``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_version.grit b/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_version.grit new file mode 100644 index 00000000000..c6b43053efc --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_version.grit @@ -0,0 +1 @@ +engine biome ("1.0") \ No newline at end of file diff --git a/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_version.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_version.grit.snap new file mode 100644 index 00000000000..54d2d670193 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_version.grit.snap @@ -0,0 +1,59 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +engine biome ("1.0") +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: GritVersion { + engine_token: ENGINE_KW@0..7 "engine" [] [Whitespace(" ")], + biome_token: BIOME_KW@7..13 "biome" [] [Whitespace(" ")], + l_paren_token: L_PAREN@13..14 "(" [] [], + grit_double_value: missing (required), + r_paren_token: missing (required), + }, + language: missing (optional), + definitions: GritDefinitionList [], + pattern: missing (optional), + definitions_continued: GritDefinitionList [], + eof_token: EOF@14..20 "\"1.0\")" [] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..20 + 0: (empty) + 1: GRIT_VERSION@0..14 + 0: ENGINE_KW@0..7 "engine" [] [Whitespace(" ")] + 1: BIOME_KW@7..13 "biome" [] [Whitespace(" ")] + 2: L_PAREN@13..14 "(" [] [] + 3: (empty) + 4: (empty) + 2: (empty) + 3: GRIT_DEFINITION_LIST@14..14 + 4: (empty) + 5: GRIT_DEFINITION_LIST@14..14 + 6: EOF@14..20 "\"1.0\")" [] [] + +``` + +## Diagnostics + +``` +incorrect_version.grit:1:15 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected version as a double + + > 1 │ engine biome ("1.0") + │ ^^^^^ + +``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/err/missing_version.grit b/crates/biome_grit_parser/tests/grit_test_suite/err/missing_version.grit new file mode 100644 index 00000000000..71c2c01273b --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/err/missing_version.grit @@ -0,0 +1 @@ +engine biome diff --git a/crates/biome_grit_parser/tests/grit_test_suite/err/missing_version.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/err/missing_version.grit.snap new file mode 100644 index 00000000000..2657439ff1d --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/err/missing_version.grit.snap @@ -0,0 +1,61 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +engine biome + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: GritVersion { + engine_token: ENGINE_KW@0..7 "engine" [] [Whitespace(" ")], + biome_token: BIOME_KW@7..12 "biome" [] [], + l_paren_token: missing (required), + grit_double_value: missing (required), + r_paren_token: missing (required), + }, + language: missing (optional), + definitions: GritDefinitionList [], + pattern: missing (optional), + definitions_continued: GritDefinitionList [], + eof_token: EOF@12..13 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..13 + 0: (empty) + 1: GRIT_VERSION@0..12 + 0: ENGINE_KW@0..7 "engine" [] [Whitespace(" ")] + 1: BIOME_KW@7..12 "biome" [] [] + 2: (empty) + 3: (empty) + 4: (empty) + 2: (empty) + 3: GRIT_DEFINITION_LIST@12..12 + 4: (empty) + 5: GRIT_DEFINITION_LIST@12..12 + 6: EOF@12..13 "" [Newline("\n")] [] + +``` + +## Diagnostics + +``` +missing_version.grit:1:13 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected an engine version + + > 1 │ engine biome + │ + 2 │ + +``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/pattern_with_version.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/pattern_with_version.grit new file mode 100755 index 00000000000..cbd6ef9d6e4 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/pattern_with_version.grit @@ -0,0 +1 @@ +engine biome (1.0) diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/pattern_with_version.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/pattern_with_version.grit.snap new file mode 100644 index 00000000000..27ac07ec154 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/pattern_with_version.grit.snap @@ -0,0 +1,51 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +engine biome (1.0) + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: GritVersion { + engine_token: ENGINE_KW@0..7 "engine" [] [Whitespace(" ")], + biome_token: BIOME_KW@7..13 "biome" [] [Whitespace(" ")], + l_paren_token: L_PAREN@13..14 "(" [] [], + grit_double_value: GritDoubleValue { + value_token: GRIT_DOUBLE_LITERAL@14..17 "1.0" [] [], + }, + r_paren_token: R_PAREN@17..18 ")" [] [], + }, + language: missing (optional), + definitions: GritDefinitionList [], + pattern: missing (optional), + definitions_continued: GritDefinitionList [], + eof_token: EOF@18..19 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..19 + 0: (empty) + 1: GRIT_VERSION@0..18 + 0: ENGINE_KW@0..7 "engine" [] [Whitespace(" ")] + 1: BIOME_KW@7..13 "biome" [] [Whitespace(" ")] + 2: L_PAREN@13..14 "(" [] [] + 3: GRIT_DOUBLE_VALUE@14..17 + 0: GRIT_DOUBLE_LITERAL@14..17 "1.0" [] [] + 4: R_PAREN@17..18 ")" [] [] + 2: (empty) + 3: GRIT_DEFINITION_LIST@18..18 + 4: (empty) + 5: GRIT_DEFINITION_LIST@18..18 + 6: EOF@18..19 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_grit_parser/tests/spec_test.rs b/crates/biome_grit_parser/tests/spec_test.rs new file mode 100644 index 00000000000..546dab4e320 --- /dev/null +++ b/crates/biome_grit_parser/tests/spec_test.rs @@ -0,0 +1,116 @@ +use biome_console::fmt::{Formatter, Termcolor}; +use biome_console::markup; +use biome_diagnostics::display::PrintDiagnostic; +use biome_diagnostics::termcolor; +use biome_diagnostics::DiagnosticExt; +use biome_grit_parser::parse_grit; +use biome_rowan::SyntaxKind; +use std::fmt::Write; +use std::fs; +use std::path::Path; + +#[derive(Copy, Clone)] +pub enum ExpectedOutcome { + Pass, + Fail, +} + +pub fn run(test_case: &str, _snapshot_name: &str, test_directory: &str, outcome_str: &str) { + let outcome = match outcome_str { + "ok" => ExpectedOutcome::Pass, + "error" => ExpectedOutcome::Fail, + _ => panic!("Invalid expected outcome {outcome_str}"), + }; + + let test_case_path = Path::new(test_case); + + let file_name = test_case_path + .file_name() + .expect("Expected test to have a file name") + .to_str() + .expect("File name to be valid UTF8"); + + let content = fs::read_to_string(test_case_path) + .expect("Expected test path to be a readable file in UTF8 encoding"); + + let parsed = parse_grit(&content); + let formatted_ast = format!("{:#?}", parsed.tree()); + + let mut snapshot = String::new(); + writeln!(snapshot, "## Input\n```grit\n{content}\n```\n").unwrap(); + + writeln!( + snapshot, + r#"## AST + +``` +{formatted_ast} +``` + +## CST + +``` +{:#?} +``` +"#, + parsed.syntax() + ) + .unwrap(); + + let diagnostics = parsed.diagnostics(); + if !diagnostics.is_empty() { + let mut diagnostics_buffer = termcolor::Buffer::no_color(); + + let termcolor = &mut Termcolor(&mut diagnostics_buffer); + let mut formatter = Formatter::new(termcolor); + + for diagnostic in diagnostics { + let error = diagnostic + .clone() + .with_file_path(file_name) + .with_file_source_code(&content); + + formatter + .write_markup(markup! { { PrintDiagnostic::verbose(&error) } }) + .expect("failed to emit diagnostic"); + } + + let formatted_diagnostics = + std::str::from_utf8(diagnostics_buffer.as_slice()).expect("non utf8 in error buffer"); + + if matches!(outcome, ExpectedOutcome::Pass) { + panic!("Expected no errors to be present in a test case that is expected to pass but the following diagnostics are present:\n{formatted_diagnostics}") + } + + writeln!(snapshot, "## Diagnostics\n\n```").unwrap(); + snapshot.write_str(formatted_diagnostics).unwrap(); + + writeln!(snapshot, "```\n").unwrap(); + } + + match outcome { + ExpectedOutcome::Pass => { + let missing_required = formatted_ast.contains("missing (required)"); + if missing_required + || parsed + .syntax() + .descendants() + .any(|node| node.kind().is_bogus()) + { + panic!("Parsed tree of a 'OK' test case should not contain any missing required children or bogus nodes"); + } + } + ExpectedOutcome::Fail => { + if parsed.diagnostics().is_empty() { + panic!("Failing test must have diagnostics"); + } + } + } + + insta::with_settings!({ + prepend_module_to_snapshot => false, + snapshot_path => &test_directory, + }, { + insta::assert_snapshot!(file_name, snapshot); + }); +} diff --git a/crates/biome_grit_parser/tests/spec_tests.rs b/crates/biome_grit_parser/tests/spec_tests.rs new file mode 100644 index 00000000000..13de9566490 --- /dev/null +++ b/crates/biome_grit_parser/tests/spec_tests.rs @@ -0,0 +1,13 @@ +#![allow(non_snake_case)] + +mod spec_test; + +mod ok { + //! Tests that are valid GritQL + tests_macros::gen_tests! {"tests/grit_test_suite/ok/*.grit", crate::spec_test::run, "ok"} +} + +mod err { + //! Tests that must fail because they are not valid GritQL + tests_macros::gen_tests! {"tests/grit_test_suite/err/*.grit", crate::spec_test::run, "error"} +} diff --git a/crates/biome_grit_syntax/src/generated/kind.rs b/crates/biome_grit_syntax/src/generated/kind.rs index 2793a1d82ff..e55ea31d2a4 100644 --- a/crates/biome_grit_syntax/src/generated/kind.rs +++ b/crates/biome_grit_syntax/src/generated/kind.rs @@ -98,7 +98,6 @@ pub enum GritSyntaxKind { GRIT_ANNOTATION, GRIT_BACKTICK_SNIPPET, GRIT_RAW_BACKTICK_SNIPPET, - GRIT_DOUBLE_QUOTE_SNIPPET, GRIT_NAME, GRIT_VARIABLE, ANY_GRIT_CONTAINER, @@ -204,7 +203,13 @@ pub enum GritSyntaxKind { GRIT_LANGUAGE_SPECIFIC_SNIPPET, GRIT_CODE_SNIPPET, GRIT_NOT, - GRIT_SNIPPET_REGEX, + GRIT_BOOLEAN_VALUE, + GRIT_DOUBLE_VALUE, + GRIT_INT_VALUE, + GRIT_NEGATIVE_INT_VALUE, + GRIT_REGEX_VALUE, + GRIT_SNIPPET_REGEX_VALUE, + GRIT_STRING_VALUE, GRIT_UNDEFINED, GRIT_UNDERSCORE, MAYBE_CURLY_GRIT_PATTERN, diff --git a/crates/biome_grit_syntax/src/generated/macros.rs b/crates/biome_grit_syntax/src/generated/macros.rs index 8b7e1c741bd..5a2cd3071b6 100644 --- a/crates/biome_grit_syntax/src/generated/macros.rs +++ b/crates/biome_grit_syntax/src/generated/macros.rs @@ -44,8 +44,8 @@ macro_rules! map_syntax_node { let $pattern = unsafe { $crate::GritBacktickSnippet::new_unchecked(node) }; $body } - $crate::GritSyntaxKind::GRIT_BOOLEAN_LITERAL => { - let $pattern = unsafe { $crate::GritBooleanLiteral::new_unchecked(node) }; + $crate::GritSyntaxKind::GRIT_BOOLEAN_VALUE => { + let $pattern = unsafe { $crate::GritBooleanValue::new_unchecked(node) }; $body } $crate::GritSyntaxKind::GRIT_BUBBLE => { @@ -76,12 +76,8 @@ macro_rules! map_syntax_node { let $pattern = unsafe { $crate::GritDotdotdot::new_unchecked(node) }; $body } - $crate::GritSyntaxKind::GRIT_DOUBLE_LITERAL => { - let $pattern = unsafe { $crate::GritDoubleLiteral::new_unchecked(node) }; - $body - } - $crate::GritSyntaxKind::GRIT_DOUBLE_QUOTE_SNIPPET => { - let $pattern = unsafe { $crate::GritDoubleQuoteSnippet::new_unchecked(node) }; + $crate::GritSyntaxKind::GRIT_DOUBLE_VALUE => { + let $pattern = unsafe { $crate::GritDoubleValue::new_unchecked(node) }; $body } $crate::GritSyntaxKind::GRIT_EVERY => { @@ -96,8 +92,8 @@ macro_rules! map_syntax_node { let $pattern = unsafe { $crate::GritFunctionDefinition::new_unchecked(node) }; $body } - $crate::GritSyntaxKind::GRIT_INT_LITERAL => { - let $pattern = unsafe { $crate::GritIntLiteral::new_unchecked(node) }; + $crate::GritSyntaxKind::GRIT_INT_VALUE => { + let $pattern = unsafe { $crate::GritIntValue::new_unchecked(node) }; $body } $crate::GritSyntaxKind::GRIT_LANGUAGE_DECLARATION => { @@ -169,8 +165,8 @@ macro_rules! map_syntax_node { let $pattern = unsafe { $crate::GritNamedArgWithDefault::new_unchecked(node) }; $body } - $crate::GritSyntaxKind::GRIT_NEGATIVE_INT_LITERAL => { - let $pattern = unsafe { $crate::GritNegativeIntLiteral::new_unchecked(node) }; + $crate::GritSyntaxKind::GRIT_NEGATIVE_INT_VALUE => { + let $pattern = unsafe { $crate::GritNegativeIntValue::new_unchecked(node) }; $body } $crate::GritSyntaxKind::GRIT_NODE_LIKE => { @@ -348,10 +344,6 @@ macro_rules! map_syntax_node { let $pattern = unsafe { $crate::GritRawBacktickSnippet::new_unchecked(node) }; $body } - $crate::GritSyntaxKind::GRIT_REGEX_LITERAL => { - let $pattern = unsafe { $crate::GritRegexLiteral::new_unchecked(node) }; - $body - } $crate::GritSyntaxKind::GRIT_REGEX_PATTERN => { let $pattern = unsafe { $crate::GritRegexPattern::new_unchecked(node) }; $body @@ -361,6 +353,10 @@ macro_rules! map_syntax_node { unsafe { $crate::GritRegexPatternVariables::new_unchecked(node) }; $body } + $crate::GritSyntaxKind::GRIT_REGEX_VALUE => { + let $pattern = unsafe { $crate::GritRegexValue::new_unchecked(node) }; + $body + } $crate::GritSyntaxKind::GRIT_REWRITE => { let $pattern = unsafe { $crate::GritRewrite::new_unchecked(node) }; $body @@ -373,16 +369,16 @@ macro_rules! map_syntax_node { let $pattern = unsafe { $crate::GritSequential::new_unchecked(node) }; $body } - $crate::GritSyntaxKind::GRIT_SNIPPET_REGEX => { - let $pattern = unsafe { $crate::GritSnippetRegex::new_unchecked(node) }; + $crate::GritSyntaxKind::GRIT_SNIPPET_REGEX_VALUE => { + let $pattern = unsafe { $crate::GritSnippetRegexValue::new_unchecked(node) }; $body } $crate::GritSyntaxKind::GRIT_SOME => { let $pattern = unsafe { $crate::GritSome::new_unchecked(node) }; $body } - $crate::GritSyntaxKind::GRIT_STRING_LITERAL => { - let $pattern = unsafe { $crate::GritStringLiteral::new_unchecked(node) }; + $crate::GritSyntaxKind::GRIT_STRING_VALUE => { + let $pattern = unsafe { $crate::GritStringValue::new_unchecked(node) }; $body } $crate::GritSyntaxKind::GRIT_SUB_OPERATION => { diff --git a/crates/biome_grit_syntax/src/generated/nodes.rs b/crates/biome_grit_syntax/src/generated/nodes.rs index 0d4b0feef32..4b5b6073267 100644 --- a/crates/biome_grit_syntax/src/generated/nodes.rs +++ b/crates/biome_grit_syntax/src/generated/nodes.rs @@ -296,7 +296,7 @@ impl AnyGritPredicate { l_paren_token: self.l_paren_token(), any_grit_predicate: self.any_grit_predicate(), r_paren_token: self.r_paren_token(), - grit_boolean_literal: self.grit_boolean_literal(), + grit_boolean_value: self.grit_boolean_value(), grit_predicate_return: self.grit_predicate_return(), grit_bogus_predicate: self.grit_bogus_predicate(), } @@ -361,7 +361,7 @@ impl AnyGritPredicate { pub fn r_paren_token(&self) -> SyntaxResult { support::required_token(&self.syntax, 19usize) } - pub fn grit_boolean_literal(&self) -> SyntaxResult { + pub fn grit_boolean_value(&self) -> SyntaxResult { support::required_node(&self.syntax, 20usize) } pub fn grit_predicate_return(&self) -> SyntaxResult { @@ -402,7 +402,7 @@ pub struct AnyGritPredicateFields { pub l_paren_token: SyntaxResult, pub any_grit_predicate: SyntaxResult, pub r_paren_token: SyntaxResult, - pub grit_boolean_literal: SyntaxResult, + pub grit_boolean_value: SyntaxResult, pub grit_predicate_return: SyntaxResult, pub grit_bogus_predicate: SyntaxResult, } @@ -617,10 +617,10 @@ pub struct GritBacktickSnippetFields { pub value_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] -pub struct GritBooleanLiteral { +pub struct GritBooleanValue { pub(crate) syntax: SyntaxNode, } -impl GritBooleanLiteral { +impl GritBooleanValue { #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] #[doc = r""] #[doc = r" # Safety"] @@ -630,8 +630,8 @@ impl GritBooleanLiteral { pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { Self { syntax } } - pub fn as_fields(&self) -> GritBooleanLiteralFields { - GritBooleanLiteralFields { + pub fn as_fields(&self) -> GritBooleanValueFields { + GritBooleanValueFields { true_token: self.true_token(), false_token: self.false_token(), } @@ -644,7 +644,7 @@ impl GritBooleanLiteral { } } #[cfg(feature = "serde")] -impl Serialize for GritBooleanLiteral { +impl Serialize for GritBooleanValue { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -653,7 +653,7 @@ impl Serialize for GritBooleanLiteral { } } #[cfg_attr(feature = "serde", derive(Serialize))] -pub struct GritBooleanLiteralFields { +pub struct GritBooleanValueFields { pub true_token: SyntaxResult, pub false_token: SyntaxResult, } @@ -955,10 +955,10 @@ pub struct GritDotdotdotFields { pub maybe_curly_grit_pattern: Option, } #[derive(Clone, PartialEq, Eq, Hash)] -pub struct GritDoubleLiteral { +pub struct GritDoubleValue { pub(crate) syntax: SyntaxNode, } -impl GritDoubleLiteral { +impl GritDoubleValue { #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] #[doc = r""] #[doc = r" # Safety"] @@ -968,8 +968,8 @@ impl GritDoubleLiteral { pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { Self { syntax } } - pub fn as_fields(&self) -> GritDoubleLiteralFields { - GritDoubleLiteralFields { + pub fn as_fields(&self) -> GritDoubleValueFields { + GritDoubleValueFields { value_token: self.value_token(), } } @@ -978,7 +978,7 @@ impl GritDoubleLiteral { } } #[cfg(feature = "serde")] -impl Serialize for GritDoubleLiteral { +impl Serialize for GritDoubleValue { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -987,43 +987,7 @@ impl Serialize for GritDoubleLiteral { } } #[cfg_attr(feature = "serde", derive(Serialize))] -pub struct GritDoubleLiteralFields { - pub value_token: SyntaxResult, -} -#[derive(Clone, PartialEq, Eq, Hash)] -pub struct GritDoubleQuoteSnippet { - pub(crate) syntax: SyntaxNode, -} -impl GritDoubleQuoteSnippet { - #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] - #[doc = r""] - #[doc = r" # Safety"] - #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] - #[doc = r" or a match on [SyntaxNode::kind]"] - #[inline] - pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { - Self { syntax } - } - pub fn as_fields(&self) -> GritDoubleQuoteSnippetFields { - GritDoubleQuoteSnippetFields { - value_token: self.value_token(), - } - } - pub fn value_token(&self) -> SyntaxResult { - support::required_token(&self.syntax, 0usize) - } -} -#[cfg(feature = "serde")] -impl Serialize for GritDoubleQuoteSnippet { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - self.as_fields().serialize(serializer) - } -} -#[cfg_attr(feature = "serde", derive(Serialize))] -pub struct GritDoubleQuoteSnippetFields { +pub struct GritDoubleValueFields { pub value_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] @@ -1180,10 +1144,10 @@ pub struct GritFunctionDefinitionFields { pub body: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] -pub struct GritIntLiteral { +pub struct GritIntValue { pub(crate) syntax: SyntaxNode, } -impl GritIntLiteral { +impl GritIntValue { #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] #[doc = r""] #[doc = r" # Safety"] @@ -1193,8 +1157,8 @@ impl GritIntLiteral { pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { Self { syntax } } - pub fn as_fields(&self) -> GritIntLiteralFields { - GritIntLiteralFields { + pub fn as_fields(&self) -> GritIntValueFields { + GritIntValueFields { value_token: self.value_token(), } } @@ -1203,7 +1167,7 @@ impl GritIntLiteral { } } #[cfg(feature = "serde")] -impl Serialize for GritIntLiteral { +impl Serialize for GritIntValue { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -1212,7 +1176,7 @@ impl Serialize for GritIntLiteral { } } #[cfg_attr(feature = "serde", derive(Serialize))] -pub struct GritIntLiteralFields { +pub struct GritIntValueFields { pub value_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] @@ -1234,6 +1198,7 @@ impl GritLanguageDeclaration { language_token: self.language_token(), name: self.name(), flavor: self.flavor(), + semicolon_token: self.semicolon_token(), } } pub fn language_token(&self) -> SyntaxResult { @@ -1245,6 +1210,9 @@ impl GritLanguageDeclaration { pub fn flavor(&self) -> Option { support::node(&self.syntax, 2usize) } + pub fn semicolon_token(&self) -> Option { + support::token(&self.syntax, 3usize) + } } #[cfg(feature = "serde")] impl Serialize for GritLanguageDeclaration { @@ -1260,6 +1228,7 @@ pub struct GritLanguageDeclarationFields { pub language_token: SyntaxResult, pub name: SyntaxResult, pub flavor: Option, + pub semicolon_token: Option, } #[derive(Clone, PartialEq, Eq, Hash)] pub struct GritLanguageFlavor { @@ -1280,7 +1249,6 @@ impl GritLanguageFlavor { l_paren_token: self.l_paren_token(), grit_language_flavor_list: self.grit_language_flavor_list(), r_paren_token: self.r_paren_token(), - semicolon_token: self.semicolon_token(), } } pub fn l_paren_token(&self) -> SyntaxResult { @@ -1292,9 +1260,6 @@ impl GritLanguageFlavor { pub fn r_paren_token(&self) -> SyntaxResult { support::required_token(&self.syntax, 2usize) } - pub fn semicolon_token(&self) -> Option { - support::token(&self.syntax, 3usize) - } } #[cfg(feature = "serde")] impl Serialize for GritLanguageFlavor { @@ -1310,7 +1275,6 @@ pub struct GritLanguageFlavorFields { pub l_paren_token: SyntaxResult, pub grit_language_flavor_list: GritLanguageFlavorList, pub r_paren_token: SyntaxResult, - pub semicolon_token: Option, } #[derive(Clone, PartialEq, Eq, Hash)] pub struct GritLanguageFlavorKind { @@ -1421,14 +1385,14 @@ impl GritLanguageSpecificSnippet { pub fn as_fields(&self) -> GritLanguageSpecificSnippetFields { GritLanguageSpecificSnippetFields { language: self.language(), - snippet: self.snippet(), + snippet_token: self.snippet_token(), } } pub fn language(&self) -> SyntaxResult { support::required_node(&self.syntax, 0usize) } - pub fn snippet(&self) -> SyntaxResult { - support::required_node(&self.syntax, 1usize) + pub fn snippet_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) } } #[cfg(feature = "serde")] @@ -1443,7 +1407,7 @@ impl Serialize for GritLanguageSpecificSnippet { #[cfg_attr(feature = "serde", derive(Serialize))] pub struct GritLanguageSpecificSnippetFields { pub language: SyntaxResult, - pub snippet: SyntaxResult, + pub snippet_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] pub struct GritLike { @@ -1996,10 +1960,10 @@ pub struct GritNamedArgWithDefaultFields { pub pattern: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] -pub struct GritNegativeIntLiteral { +pub struct GritNegativeIntValue { pub(crate) syntax: SyntaxNode, } -impl GritNegativeIntLiteral { +impl GritNegativeIntValue { #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] #[doc = r""] #[doc = r" # Safety"] @@ -2009,8 +1973,8 @@ impl GritNegativeIntLiteral { pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { Self { syntax } } - pub fn as_fields(&self) -> GritNegativeIntLiteralFields { - GritNegativeIntLiteralFields { + pub fn as_fields(&self) -> GritNegativeIntValueFields { + GritNegativeIntValueFields { value_token: self.value_token(), } } @@ -2019,7 +1983,7 @@ impl GritNegativeIntLiteral { } } #[cfg(feature = "serde")] -impl Serialize for GritNegativeIntLiteral { +impl Serialize for GritNegativeIntValue { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -2028,7 +1992,7 @@ impl Serialize for GritNegativeIntLiteral { } } #[cfg_attr(feature = "serde", derive(Serialize))] -pub struct GritNegativeIntLiteralFields { +pub struct GritNegativeIntValueFields { pub value_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] @@ -2809,7 +2773,7 @@ impl GritPatternLimit { pub fn limit_token(&self) -> SyntaxResult { support::required_token(&self.syntax, 1usize) } - pub fn limit(&self) -> SyntaxResult { + pub fn limit(&self) -> SyntaxResult { support::required_node(&self.syntax, 2usize) } } @@ -2826,7 +2790,7 @@ impl Serialize for GritPatternLimit { pub struct GritPatternLimitFields { pub pattern: SyntaxResult, pub limit_token: SyntaxResult, - pub limit: SyntaxResult, + pub limit: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] pub struct GritPatternMaybe { @@ -4050,42 +4014,6 @@ pub struct GritRawBacktickSnippetFields { pub value_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] -pub struct GritRegexLiteral { - pub(crate) syntax: SyntaxNode, -} -impl GritRegexLiteral { - #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] - #[doc = r""] - #[doc = r" # Safety"] - #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] - #[doc = r" or a match on [SyntaxNode::kind]"] - #[inline] - pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { - Self { syntax } - } - pub fn as_fields(&self) -> GritRegexLiteralFields { - GritRegexLiteralFields { - value_token: self.value_token(), - } - } - pub fn value_token(&self) -> SyntaxResult { - support::required_token(&self.syntax, 0usize) - } -} -#[cfg(feature = "serde")] -impl Serialize for GritRegexLiteral { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - self.as_fields().serialize(serializer) - } -} -#[cfg_attr(feature = "serde", derive(Serialize))] -pub struct GritRegexLiteralFields { - pub value_token: SyntaxResult, -} -#[derive(Clone, PartialEq, Eq, Hash)] pub struct GritRegexPattern { pub(crate) syntax: SyntaxNode, } @@ -4173,6 +4101,42 @@ pub struct GritRegexPatternVariablesFields { pub r_paren_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritRegexValue { + pub(crate) syntax: SyntaxNode, +} +impl GritRegexValue { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritRegexValueFields { + GritRegexValueFields { + value_token: self.value_token(), + } + } + pub fn value_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritRegexValue { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritRegexValueFields { + pub value_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] pub struct GritRewrite { pub(crate) syntax: SyntaxNode, } @@ -4239,27 +4203,35 @@ impl GritRoot { } pub fn as_fields(&self) -> GritRootFields { GritRootFields { + bom_token: self.bom_token(), version: self.version(), language: self.language(), definitions: self.definitions(), pattern: self.pattern(), definitions_continued: self.definitions_continued(), + eof_token: self.eof_token(), } } + pub fn bom_token(&self) -> Option { + support::token(&self.syntax, 0usize) + } pub fn version(&self) -> Option { - support::node(&self.syntax, 0usize) + support::node(&self.syntax, 1usize) } pub fn language(&self) -> Option { - support::node(&self.syntax, 1usize) + support::node(&self.syntax, 2usize) } pub fn definitions(&self) -> GritDefinitionList { - support::list(&self.syntax, 2usize) + support::list(&self.syntax, 3usize) } pub fn pattern(&self) -> Option { - support::node(&self.syntax, 3usize) + support::node(&self.syntax, 4usize) } pub fn definitions_continued(&self) -> GritDefinitionList { - support::list(&self.syntax, 4usize) + support::list(&self.syntax, 5usize) + } + pub fn eof_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 6usize) } } #[cfg(feature = "serde")] @@ -4273,11 +4245,13 @@ impl Serialize for GritRoot { } #[cfg_attr(feature = "serde", derive(Serialize))] pub struct GritRootFields { + pub bom_token: Option, pub version: Option, pub language: Option, pub definitions: GritDefinitionList, pub pattern: Option, pub definitions_continued: GritDefinitionList, + pub eof_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] pub struct GritSequential { @@ -4331,10 +4305,10 @@ pub struct GritSequentialFields { pub r_curly_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] -pub struct GritSnippetRegex { +pub struct GritSnippetRegexValue { pub(crate) syntax: SyntaxNode, } -impl GritSnippetRegex { +impl GritSnippetRegexValue { #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] #[doc = r""] #[doc = r" # Safety"] @@ -4344,8 +4318,8 @@ impl GritSnippetRegex { pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { Self { syntax } } - pub fn as_fields(&self) -> GritSnippetRegexFields { - GritSnippetRegexFields { + pub fn as_fields(&self) -> GritSnippetRegexValueFields { + GritSnippetRegexValueFields { value_token: self.value_token(), } } @@ -4354,7 +4328,7 @@ impl GritSnippetRegex { } } #[cfg(feature = "serde")] -impl Serialize for GritSnippetRegex { +impl Serialize for GritSnippetRegexValue { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -4363,7 +4337,7 @@ impl Serialize for GritSnippetRegex { } } #[cfg_attr(feature = "serde", derive(Serialize))] -pub struct GritSnippetRegexFields { +pub struct GritSnippetRegexValueFields { pub value_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] @@ -4408,10 +4382,10 @@ pub struct GritSomeFields { pub pattern: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] -pub struct GritStringLiteral { +pub struct GritStringValue { pub(crate) syntax: SyntaxNode, } -impl GritStringLiteral { +impl GritStringValue { #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] #[doc = r""] #[doc = r" # Safety"] @@ -4421,8 +4395,8 @@ impl GritStringLiteral { pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { Self { syntax } } - pub fn as_fields(&self) -> GritStringLiteralFields { - GritStringLiteralFields { + pub fn as_fields(&self) -> GritStringValueFields { + GritStringValueFields { value_token: self.value_token(), } } @@ -4431,7 +4405,7 @@ impl GritStringLiteral { } } #[cfg(feature = "serde")] -impl Serialize for GritStringLiteral { +impl Serialize for GritStringValue { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -4440,7 +4414,7 @@ impl Serialize for GritStringLiteral { } } #[cfg_attr(feature = "serde", derive(Serialize))] -pub struct GritStringLiteralFields { +pub struct GritStringValueFields { pub value_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] @@ -4616,7 +4590,7 @@ impl GritVersion { engine_token: self.engine_token(), biome_token: self.biome_token(), l_paren_token: self.l_paren_token(), - grit_double_literal: self.grit_double_literal(), + grit_double_value: self.grit_double_value(), r_paren_token: self.r_paren_token(), } } @@ -4629,7 +4603,7 @@ impl GritVersion { pub fn l_paren_token(&self) -> SyntaxResult { support::required_token(&self.syntax, 2usize) } - pub fn grit_double_literal(&self) -> SyntaxResult { + pub fn grit_double_value(&self) -> SyntaxResult { support::required_node(&self.syntax, 3usize) } pub fn r_paren_token(&self) -> SyntaxResult { @@ -4650,7 +4624,7 @@ pub struct GritVersionFields { pub engine_token: SyntaxResult, pub biome_token: SyntaxResult, pub l_paren_token: SyntaxResult, - pub grit_double_literal: SyntaxResult, + pub grit_double_value: SyntaxResult, pub r_paren_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] @@ -4779,13 +4753,13 @@ impl AnyGritListPattern { #[cfg_attr(feature = "serde", derive(Serialize))] pub enum AnyGritLiteral { GritBogusLiteral(GritBogusLiteral), - GritBooleanLiteral(GritBooleanLiteral), + GritBooleanValue(GritBooleanValue), GritCodeSnippet(GritCodeSnippet), - GritDoubleLiteral(GritDoubleLiteral), - GritIntLiteral(GritIntLiteral), + GritDoubleValue(GritDoubleValue), + GritIntValue(GritIntValue), GritList(GritList), GritMap(GritMap), - GritStringLiteral(GritStringLiteral), + GritStringValue(GritStringValue), GritUndefined(GritUndefined), } impl AnyGritLiteral { @@ -4795,9 +4769,9 @@ impl AnyGritLiteral { _ => None, } } - pub fn as_grit_boolean_literal(&self) -> Option<&GritBooleanLiteral> { + pub fn as_grit_boolean_value(&self) -> Option<&GritBooleanValue> { match &self { - AnyGritLiteral::GritBooleanLiteral(item) => Some(item), + AnyGritLiteral::GritBooleanValue(item) => Some(item), _ => None, } } @@ -4807,15 +4781,15 @@ impl AnyGritLiteral { _ => None, } } - pub fn as_grit_double_literal(&self) -> Option<&GritDoubleLiteral> { + pub fn as_grit_double_value(&self) -> Option<&GritDoubleValue> { match &self { - AnyGritLiteral::GritDoubleLiteral(item) => Some(item), + AnyGritLiteral::GritDoubleValue(item) => Some(item), _ => None, } } - pub fn as_grit_int_literal(&self) -> Option<&GritIntLiteral> { + pub fn as_grit_int_value(&self) -> Option<&GritIntValue> { match &self { - AnyGritLiteral::GritIntLiteral(item) => Some(item), + AnyGritLiteral::GritIntValue(item) => Some(item), _ => None, } } @@ -4831,9 +4805,9 @@ impl AnyGritLiteral { _ => None, } } - pub fn as_grit_string_literal(&self) -> Option<&GritStringLiteral> { + pub fn as_grit_string_value(&self) -> Option<&GritStringValue> { match &self { - AnyGritLiteral::GritStringLiteral(item) => Some(item), + AnyGritLiteral::GritStringValue(item) => Some(item), _ => None, } } @@ -4922,8 +4896,8 @@ impl GritListAccessorSubject { #[cfg_attr(feature = "serde", derive(Serialize))] pub enum GritListIndex { AnyGritContainer(AnyGritContainer), - GritIntLiteral(GritIntLiteral), - GritNegativeIntLiteral(GritNegativeIntLiteral), + GritIntValue(GritIntValue), + GritNegativeIntValue(GritNegativeIntValue), } impl GritListIndex { pub fn as_any_grit_container(&self) -> Option<&AnyGritContainer> { @@ -4932,15 +4906,15 @@ impl GritListIndex { _ => None, } } - pub fn as_grit_int_literal(&self) -> Option<&GritIntLiteral> { + pub fn as_grit_int_value(&self) -> Option<&GritIntValue> { match &self { - GritListIndex::GritIntLiteral(item) => Some(item), + GritListIndex::GritIntValue(item) => Some(item), _ => None, } } - pub fn as_grit_negative_int_literal(&self) -> Option<&GritNegativeIntLiteral> { + pub fn as_grit_negative_int_value(&self) -> Option<&GritNegativeIntValue> { match &self { - GritListIndex::GritNegativeIntLiteral(item) => Some(item), + GritListIndex::GritNegativeIntValue(item) => Some(item), _ => None, } } @@ -5008,19 +4982,19 @@ impl GritPredicateMatchSubject { #[derive(Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize))] pub enum GritRegex { - GritRegexLiteral(GritRegexLiteral), - GritSnippetRegex(GritSnippetRegex), + GritRegexValue(GritRegexValue), + GritSnippetRegexValue(GritSnippetRegexValue), } impl GritRegex { - pub fn as_grit_regex_literal(&self) -> Option<&GritRegexLiteral> { + pub fn as_grit_regex_value(&self) -> Option<&GritRegexValue> { match &self { - GritRegex::GritRegexLiteral(item) => Some(item), + GritRegex::GritRegexValue(item) => Some(item), _ => None, } } - pub fn as_grit_snippet_regex(&self) -> Option<&GritSnippetRegex> { + pub fn as_grit_snippet_regex_value(&self) -> Option<&GritSnippetRegexValue> { match &self { - GritRegex::GritSnippetRegex(item) => Some(item), + GritRegex::GritSnippetRegexValue(item) => Some(item), _ => None, } } @@ -5336,8 +5310,8 @@ impl std::fmt::Debug for AnyGritPredicate { &support::DebugSyntaxResult(self.r_paren_token()), ) .field( - "grit_boolean_literal", - &support::DebugSyntaxResult(self.grit_boolean_literal()), + "grit_boolean_value", + &support::DebugSyntaxResult(self.grit_boolean_value()), ) .field( "grit_predicate_return", @@ -5571,12 +5545,12 @@ impl From for SyntaxElement { n.syntax.into() } } -impl AstNode for GritBooleanLiteral { +impl AstNode for GritBooleanValue { type Language = Language; const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_BOOLEAN_LITERAL as u16)); + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_BOOLEAN_VALUE as u16)); fn can_cast(kind: SyntaxKind) -> bool { - kind == GRIT_BOOLEAN_LITERAL + kind == GRIT_BOOLEAN_VALUE } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { @@ -5592,9 +5566,9 @@ impl AstNode for GritBooleanLiteral { self.syntax } } -impl std::fmt::Debug for GritBooleanLiteral { +impl std::fmt::Debug for GritBooleanValue { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("GritBooleanLiteral") + f.debug_struct("GritBooleanValue") .field("true_token", &support::DebugSyntaxResult(self.true_token())) .field( "false_token", @@ -5603,13 +5577,13 @@ impl std::fmt::Debug for GritBooleanLiteral { .finish() } } -impl From for SyntaxNode { - fn from(n: GritBooleanLiteral) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: GritBooleanValue) -> SyntaxNode { n.syntax } } -impl From for SyntaxElement { - fn from(n: GritBooleanLiteral) -> SyntaxElement { +impl From for SyntaxElement { + fn from(n: GritBooleanValue) -> SyntaxElement { n.syntax.into() } } @@ -5915,12 +5889,12 @@ impl From for SyntaxElement { n.syntax.into() } } -impl AstNode for GritDoubleLiteral { +impl AstNode for GritDoubleValue { type Language = Language; const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_DOUBLE_LITERAL as u16)); + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_DOUBLE_VALUE as u16)); fn can_cast(kind: SyntaxKind) -> bool { - kind == GRIT_DOUBLE_LITERAL + kind == GRIT_DOUBLE_VALUE } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { @@ -5936,9 +5910,9 @@ impl AstNode for GritDoubleLiteral { self.syntax } } -impl std::fmt::Debug for GritDoubleLiteral { +impl std::fmt::Debug for GritDoubleValue { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("GritDoubleLiteral") + f.debug_struct("GritDoubleValue") .field( "value_token", &support::DebugSyntaxResult(self.value_token()), @@ -5946,54 +5920,13 @@ impl std::fmt::Debug for GritDoubleLiteral { .finish() } } -impl From for SyntaxNode { - fn from(n: GritDoubleLiteral) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: GritDoubleValue) -> SyntaxNode { n.syntax } } -impl From for SyntaxElement { - fn from(n: GritDoubleLiteral) -> SyntaxElement { - n.syntax.into() - } -} -impl AstNode for GritDoubleQuoteSnippet { - type Language = Language; - const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_DOUBLE_QUOTE_SNIPPET as u16)); - fn can_cast(kind: SyntaxKind) -> bool { - kind == GRIT_DOUBLE_QUOTE_SNIPPET - } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { - &self.syntax - } - fn into_syntax(self) -> SyntaxNode { - self.syntax - } -} -impl std::fmt::Debug for GritDoubleQuoteSnippet { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("GritDoubleQuoteSnippet") - .field( - "value_token", - &support::DebugSyntaxResult(self.value_token()), - ) - .finish() - } -} -impl From for SyntaxNode { - fn from(n: GritDoubleQuoteSnippet) -> SyntaxNode { - n.syntax - } -} -impl From for SyntaxElement { - fn from(n: GritDoubleQuoteSnippet) -> SyntaxElement { +impl From for SyntaxElement { + fn from(n: GritDoubleValue) -> SyntaxElement { n.syntax.into() } } @@ -6141,12 +6074,12 @@ impl From for SyntaxElement { n.syntax.into() } } -impl AstNode for GritIntLiteral { +impl AstNode for GritIntValue { type Language = Language; const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_INT_LITERAL as u16)); + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_INT_VALUE as u16)); fn can_cast(kind: SyntaxKind) -> bool { - kind == GRIT_INT_LITERAL + kind == GRIT_INT_VALUE } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { @@ -6162,9 +6095,9 @@ impl AstNode for GritIntLiteral { self.syntax } } -impl std::fmt::Debug for GritIntLiteral { +impl std::fmt::Debug for GritIntValue { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("GritIntLiteral") + f.debug_struct("GritIntValue") .field( "value_token", &support::DebugSyntaxResult(self.value_token()), @@ -6172,13 +6105,13 @@ impl std::fmt::Debug for GritIntLiteral { .finish() } } -impl From for SyntaxNode { - fn from(n: GritIntLiteral) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: GritIntValue) -> SyntaxNode { n.syntax } } -impl From for SyntaxElement { - fn from(n: GritIntLiteral) -> SyntaxElement { +impl From for SyntaxElement { + fn from(n: GritIntValue) -> SyntaxElement { n.syntax.into() } } @@ -6212,6 +6145,10 @@ impl std::fmt::Debug for GritLanguageDeclaration { ) .field("name", &support::DebugSyntaxResult(self.name())) .field("flavor", &support::DebugOptionalElement(self.flavor())) + .field( + "semicolon_token", + &support::DebugOptionalElement(self.semicolon_token()), + ) .finish() } } @@ -6261,10 +6198,6 @@ impl std::fmt::Debug for GritLanguageFlavor { "r_paren_token", &support::DebugSyntaxResult(self.r_paren_token()), ) - .field( - "semicolon_token", - &support::DebugOptionalElement(self.semicolon_token()), - ) .finish() } } @@ -6386,7 +6319,10 @@ impl std::fmt::Debug for GritLanguageSpecificSnippet { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("GritLanguageSpecificSnippet") .field("language", &support::DebugSyntaxResult(self.language())) - .field("snippet", &support::DebugSyntaxResult(self.snippet())) + .field( + "snippet_token", + &support::DebugSyntaxResult(self.snippet_token()), + ) .finish() } } @@ -6925,12 +6861,12 @@ impl From for SyntaxElement { n.syntax.into() } } -impl AstNode for GritNegativeIntLiteral { +impl AstNode for GritNegativeIntValue { type Language = Language; const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_NEGATIVE_INT_LITERAL as u16)); + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_NEGATIVE_INT_VALUE as u16)); fn can_cast(kind: SyntaxKind) -> bool { - kind == GRIT_NEGATIVE_INT_LITERAL + kind == GRIT_NEGATIVE_INT_VALUE } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { @@ -6946,9 +6882,9 @@ impl AstNode for GritNegativeIntLiteral { self.syntax } } -impl std::fmt::Debug for GritNegativeIntLiteral { +impl std::fmt::Debug for GritNegativeIntValue { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("GritNegativeIntLiteral") + f.debug_struct("GritNegativeIntValue") .field( "value_token", &support::DebugSyntaxResult(self.value_token()), @@ -6956,13 +6892,13 @@ impl std::fmt::Debug for GritNegativeIntLiteral { .finish() } } -impl From for SyntaxNode { - fn from(n: GritNegativeIntLiteral) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: GritNegativeIntValue) -> SyntaxNode { n.syntax } } -impl From for SyntaxElement { - fn from(n: GritNegativeIntLiteral) -> SyntaxElement { +impl From for SyntaxElement { + fn from(n: GritNegativeIntValue) -> SyntaxElement { n.syntax.into() } } @@ -8889,47 +8825,6 @@ impl From for SyntaxElement { n.syntax.into() } } -impl AstNode for GritRegexLiteral { - type Language = Language; - const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_REGEX_LITERAL as u16)); - fn can_cast(kind: SyntaxKind) -> bool { - kind == GRIT_REGEX_LITERAL - } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { - &self.syntax - } - fn into_syntax(self) -> SyntaxNode { - self.syntax - } -} -impl std::fmt::Debug for GritRegexLiteral { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("GritRegexLiteral") - .field( - "value_token", - &support::DebugSyntaxResult(self.value_token()), - ) - .finish() - } -} -impl From for SyntaxNode { - fn from(n: GritRegexLiteral) -> SyntaxNode { - n.syntax - } -} -impl From for SyntaxElement { - fn from(n: GritRegexLiteral) -> SyntaxElement { - n.syntax.into() - } -} impl AstNode for GritRegexPattern { type Language = Language; const KIND_SET: SyntaxKindSet = @@ -9021,6 +8916,47 @@ impl From for SyntaxElement { n.syntax.into() } } +impl AstNode for GritRegexValue { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_REGEX_VALUE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_REGEX_VALUE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritRegexValue { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritRegexValue") + .field( + "value_token", + &support::DebugSyntaxResult(self.value_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritRegexValue) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritRegexValue) -> SyntaxElement { + n.syntax.into() + } +} impl AstNode for GritRewrite { type Language = Language; const KIND_SET: SyntaxKindSet = @@ -9092,11 +9028,16 @@ impl AstNode for GritRoot { impl std::fmt::Debug for GritRoot { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("GritRoot") + .field( + "bom_token", + &support::DebugOptionalElement(self.bom_token()), + ) .field("version", &support::DebugOptionalElement(self.version())) .field("language", &support::DebugOptionalElement(self.language())) .field("definitions", &self.definitions()) .field("pattern", &support::DebugOptionalElement(self.pattern())) .field("definitions_continued", &self.definitions_continued()) + .field("eof_token", &support::DebugSyntaxResult(self.eof_token())) .finish() } } @@ -9160,12 +9101,12 @@ impl From for SyntaxElement { n.syntax.into() } } -impl AstNode for GritSnippetRegex { +impl AstNode for GritSnippetRegexValue { type Language = Language; const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_SNIPPET_REGEX as u16)); + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_SNIPPET_REGEX_VALUE as u16)); fn can_cast(kind: SyntaxKind) -> bool { - kind == GRIT_SNIPPET_REGEX + kind == GRIT_SNIPPET_REGEX_VALUE } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { @@ -9181,9 +9122,9 @@ impl AstNode for GritSnippetRegex { self.syntax } } -impl std::fmt::Debug for GritSnippetRegex { +impl std::fmt::Debug for GritSnippetRegexValue { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("GritSnippetRegex") + f.debug_struct("GritSnippetRegexValue") .field( "value_token", &support::DebugSyntaxResult(self.value_token()), @@ -9191,13 +9132,13 @@ impl std::fmt::Debug for GritSnippetRegex { .finish() } } -impl From for SyntaxNode { - fn from(n: GritSnippetRegex) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: GritSnippetRegexValue) -> SyntaxNode { n.syntax } } -impl From for SyntaxElement { - fn from(n: GritSnippetRegex) -> SyntaxElement { +impl From for SyntaxElement { + fn from(n: GritSnippetRegexValue) -> SyntaxElement { n.syntax.into() } } @@ -9240,12 +9181,12 @@ impl From for SyntaxElement { n.syntax.into() } } -impl AstNode for GritStringLiteral { +impl AstNode for GritStringValue { type Language = Language; const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_STRING_LITERAL as u16)); + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_STRING_VALUE as u16)); fn can_cast(kind: SyntaxKind) -> bool { - kind == GRIT_STRING_LITERAL + kind == GRIT_STRING_VALUE } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { @@ -9261,9 +9202,9 @@ impl AstNode for GritStringLiteral { self.syntax } } -impl std::fmt::Debug for GritStringLiteral { +impl std::fmt::Debug for GritStringValue { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("GritStringLiteral") + f.debug_struct("GritStringValue") .field( "value_token", &support::DebugSyntaxResult(self.value_token()), @@ -9271,13 +9212,13 @@ impl std::fmt::Debug for GritStringLiteral { .finish() } } -impl From for SyntaxNode { - fn from(n: GritStringLiteral) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: GritStringValue) -> SyntaxNode { n.syntax } } -impl From for SyntaxElement { - fn from(n: GritStringLiteral) -> SyntaxElement { +impl From for SyntaxElement { + fn from(n: GritStringValue) -> SyntaxElement { n.syntax.into() } } @@ -9484,8 +9425,8 @@ impl std::fmt::Debug for GritVersion { &support::DebugSyntaxResult(self.l_paren_token()), ) .field( - "grit_double_literal", - &support::DebugSyntaxResult(self.grit_double_literal()), + "grit_double_value", + &support::DebugSyntaxResult(self.grit_double_value()), ) .field( "r_paren_token", @@ -9778,9 +9719,9 @@ impl From for AnyGritLiteral { AnyGritLiteral::GritBogusLiteral(node) } } -impl From for AnyGritLiteral { - fn from(node: GritBooleanLiteral) -> AnyGritLiteral { - AnyGritLiteral::GritBooleanLiteral(node) +impl From for AnyGritLiteral { + fn from(node: GritBooleanValue) -> AnyGritLiteral { + AnyGritLiteral::GritBooleanValue(node) } } impl From for AnyGritLiteral { @@ -9788,14 +9729,14 @@ impl From for AnyGritLiteral { AnyGritLiteral::GritCodeSnippet(node) } } -impl From for AnyGritLiteral { - fn from(node: GritDoubleLiteral) -> AnyGritLiteral { - AnyGritLiteral::GritDoubleLiteral(node) +impl From for AnyGritLiteral { + fn from(node: GritDoubleValue) -> AnyGritLiteral { + AnyGritLiteral::GritDoubleValue(node) } } -impl From for AnyGritLiteral { - fn from(node: GritIntLiteral) -> AnyGritLiteral { - AnyGritLiteral::GritIntLiteral(node) +impl From for AnyGritLiteral { + fn from(node: GritIntValue) -> AnyGritLiteral { + AnyGritLiteral::GritIntValue(node) } } impl From for AnyGritLiteral { @@ -9808,9 +9749,9 @@ impl From for AnyGritLiteral { AnyGritLiteral::GritMap(node) } } -impl From for AnyGritLiteral { - fn from(node: GritStringLiteral) -> AnyGritLiteral { - AnyGritLiteral::GritStringLiteral(node) +impl From for AnyGritLiteral { + fn from(node: GritStringValue) -> AnyGritLiteral { + AnyGritLiteral::GritStringValue(node) } } impl From for AnyGritLiteral { @@ -9821,40 +9762,38 @@ impl From for AnyGritLiteral { impl AstNode for AnyGritLiteral { type Language = Language; const KIND_SET: SyntaxKindSet = GritBogusLiteral::KIND_SET - .union(GritBooleanLiteral::KIND_SET) + .union(GritBooleanValue::KIND_SET) .union(GritCodeSnippet::KIND_SET) - .union(GritDoubleLiteral::KIND_SET) - .union(GritIntLiteral::KIND_SET) + .union(GritDoubleValue::KIND_SET) + .union(GritIntValue::KIND_SET) .union(GritList::KIND_SET) .union(GritMap::KIND_SET) - .union(GritStringLiteral::KIND_SET) + .union(GritStringValue::KIND_SET) .union(GritUndefined::KIND_SET); fn can_cast(kind: SyntaxKind) -> bool { matches!( kind, GRIT_BOGUS_LITERAL - | GRIT_BOOLEAN_LITERAL + | GRIT_BOOLEAN_VALUE | GRIT_CODE_SNIPPET - | GRIT_DOUBLE_LITERAL - | GRIT_INT_LITERAL + | GRIT_DOUBLE_VALUE + | GRIT_INT_VALUE | GRIT_LIST | GRIT_MAP - | GRIT_STRING_LITERAL + | GRIT_STRING_VALUE | GRIT_UNDEFINED ) } fn cast(syntax: SyntaxNode) -> Option { let res = match syntax.kind() { GRIT_BOGUS_LITERAL => AnyGritLiteral::GritBogusLiteral(GritBogusLiteral { syntax }), - GRIT_BOOLEAN_LITERAL => { - AnyGritLiteral::GritBooleanLiteral(GritBooleanLiteral { syntax }) - } + GRIT_BOOLEAN_VALUE => AnyGritLiteral::GritBooleanValue(GritBooleanValue { syntax }), GRIT_CODE_SNIPPET => AnyGritLiteral::GritCodeSnippet(GritCodeSnippet { syntax }), - GRIT_DOUBLE_LITERAL => AnyGritLiteral::GritDoubleLiteral(GritDoubleLiteral { syntax }), - GRIT_INT_LITERAL => AnyGritLiteral::GritIntLiteral(GritIntLiteral { syntax }), + GRIT_DOUBLE_VALUE => AnyGritLiteral::GritDoubleValue(GritDoubleValue { syntax }), + GRIT_INT_VALUE => AnyGritLiteral::GritIntValue(GritIntValue { syntax }), GRIT_LIST => AnyGritLiteral::GritList(GritList { syntax }), GRIT_MAP => AnyGritLiteral::GritMap(GritMap { syntax }), - GRIT_STRING_LITERAL => AnyGritLiteral::GritStringLiteral(GritStringLiteral { syntax }), + GRIT_STRING_VALUE => AnyGritLiteral::GritStringValue(GritStringValue { syntax }), GRIT_UNDEFINED => AnyGritLiteral::GritUndefined(GritUndefined { syntax }), _ => return None, }; @@ -9863,26 +9802,26 @@ impl AstNode for AnyGritLiteral { fn syntax(&self) -> &SyntaxNode { match self { AnyGritLiteral::GritBogusLiteral(it) => &it.syntax, - AnyGritLiteral::GritBooleanLiteral(it) => &it.syntax, + AnyGritLiteral::GritBooleanValue(it) => &it.syntax, AnyGritLiteral::GritCodeSnippet(it) => &it.syntax, - AnyGritLiteral::GritDoubleLiteral(it) => &it.syntax, - AnyGritLiteral::GritIntLiteral(it) => &it.syntax, + AnyGritLiteral::GritDoubleValue(it) => &it.syntax, + AnyGritLiteral::GritIntValue(it) => &it.syntax, AnyGritLiteral::GritList(it) => &it.syntax, AnyGritLiteral::GritMap(it) => &it.syntax, - AnyGritLiteral::GritStringLiteral(it) => &it.syntax, + AnyGritLiteral::GritStringValue(it) => &it.syntax, AnyGritLiteral::GritUndefined(it) => &it.syntax, } } fn into_syntax(self) -> SyntaxNode { match self { AnyGritLiteral::GritBogusLiteral(it) => it.syntax, - AnyGritLiteral::GritBooleanLiteral(it) => it.syntax, + AnyGritLiteral::GritBooleanValue(it) => it.syntax, AnyGritLiteral::GritCodeSnippet(it) => it.syntax, - AnyGritLiteral::GritDoubleLiteral(it) => it.syntax, - AnyGritLiteral::GritIntLiteral(it) => it.syntax, + AnyGritLiteral::GritDoubleValue(it) => it.syntax, + AnyGritLiteral::GritIntValue(it) => it.syntax, AnyGritLiteral::GritList(it) => it.syntax, AnyGritLiteral::GritMap(it) => it.syntax, - AnyGritLiteral::GritStringLiteral(it) => it.syntax, + AnyGritLiteral::GritStringValue(it) => it.syntax, AnyGritLiteral::GritUndefined(it) => it.syntax, } } @@ -9891,13 +9830,13 @@ impl std::fmt::Debug for AnyGritLiteral { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { AnyGritLiteral::GritBogusLiteral(it) => std::fmt::Debug::fmt(it, f), - AnyGritLiteral::GritBooleanLiteral(it) => std::fmt::Debug::fmt(it, f), + AnyGritLiteral::GritBooleanValue(it) => std::fmt::Debug::fmt(it, f), AnyGritLiteral::GritCodeSnippet(it) => std::fmt::Debug::fmt(it, f), - AnyGritLiteral::GritDoubleLiteral(it) => std::fmt::Debug::fmt(it, f), - AnyGritLiteral::GritIntLiteral(it) => std::fmt::Debug::fmt(it, f), + AnyGritLiteral::GritDoubleValue(it) => std::fmt::Debug::fmt(it, f), + AnyGritLiteral::GritIntValue(it) => std::fmt::Debug::fmt(it, f), AnyGritLiteral::GritList(it) => std::fmt::Debug::fmt(it, f), AnyGritLiteral::GritMap(it) => std::fmt::Debug::fmt(it, f), - AnyGritLiteral::GritStringLiteral(it) => std::fmt::Debug::fmt(it, f), + AnyGritLiteral::GritStringValue(it) => std::fmt::Debug::fmt(it, f), AnyGritLiteral::GritUndefined(it) => std::fmt::Debug::fmt(it, f), } } @@ -9906,13 +9845,13 @@ impl From for SyntaxNode { fn from(n: AnyGritLiteral) -> SyntaxNode { match n { AnyGritLiteral::GritBogusLiteral(it) => it.into(), - AnyGritLiteral::GritBooleanLiteral(it) => it.into(), + AnyGritLiteral::GritBooleanValue(it) => it.into(), AnyGritLiteral::GritCodeSnippet(it) => it.into(), - AnyGritLiteral::GritDoubleLiteral(it) => it.into(), - AnyGritLiteral::GritIntLiteral(it) => it.into(), + AnyGritLiteral::GritDoubleValue(it) => it.into(), + AnyGritLiteral::GritIntValue(it) => it.into(), AnyGritLiteral::GritList(it) => it.into(), AnyGritLiteral::GritMap(it) => it.into(), - AnyGritLiteral::GritStringLiteral(it) => it.into(), + AnyGritLiteral::GritStringValue(it) => it.into(), AnyGritLiteral::GritUndefined(it) => it.into(), } } @@ -10147,33 +10086,33 @@ impl From for SyntaxElement { node.into() } } -impl From for GritListIndex { - fn from(node: GritIntLiteral) -> GritListIndex { - GritListIndex::GritIntLiteral(node) +impl From for GritListIndex { + fn from(node: GritIntValue) -> GritListIndex { + GritListIndex::GritIntValue(node) } } -impl From for GritListIndex { - fn from(node: GritNegativeIntLiteral) -> GritListIndex { - GritListIndex::GritNegativeIntLiteral(node) +impl From for GritListIndex { + fn from(node: GritNegativeIntValue) -> GritListIndex { + GritListIndex::GritNegativeIntValue(node) } } impl AstNode for GritListIndex { type Language = Language; const KIND_SET: SyntaxKindSet = AnyGritContainer::KIND_SET - .union(GritIntLiteral::KIND_SET) - .union(GritNegativeIntLiteral::KIND_SET); + .union(GritIntValue::KIND_SET) + .union(GritNegativeIntValue::KIND_SET); fn can_cast(kind: SyntaxKind) -> bool { match kind { - GRIT_INT_LITERAL | GRIT_NEGATIVE_INT_LITERAL => true, + GRIT_INT_VALUE | GRIT_NEGATIVE_INT_VALUE => true, k if AnyGritContainer::can_cast(k) => true, _ => false, } } fn cast(syntax: SyntaxNode) -> Option { let res = match syntax.kind() { - GRIT_INT_LITERAL => GritListIndex::GritIntLiteral(GritIntLiteral { syntax }), - GRIT_NEGATIVE_INT_LITERAL => { - GritListIndex::GritNegativeIntLiteral(GritNegativeIntLiteral { syntax }) + GRIT_INT_VALUE => GritListIndex::GritIntValue(GritIntValue { syntax }), + GRIT_NEGATIVE_INT_VALUE => { + GritListIndex::GritNegativeIntValue(GritNegativeIntValue { syntax }) } _ => { if let Some(any_grit_container) = AnyGritContainer::cast(syntax) { @@ -10186,15 +10125,15 @@ impl AstNode for GritListIndex { } fn syntax(&self) -> &SyntaxNode { match self { - GritListIndex::GritIntLiteral(it) => &it.syntax, - GritListIndex::GritNegativeIntLiteral(it) => &it.syntax, + GritListIndex::GritIntValue(it) => &it.syntax, + GritListIndex::GritNegativeIntValue(it) => &it.syntax, GritListIndex::AnyGritContainer(it) => it.syntax(), } } fn into_syntax(self) -> SyntaxNode { match self { - GritListIndex::GritIntLiteral(it) => it.syntax, - GritListIndex::GritNegativeIntLiteral(it) => it.syntax, + GritListIndex::GritIntValue(it) => it.syntax, + GritListIndex::GritNegativeIntValue(it) => it.syntax, GritListIndex::AnyGritContainer(it) => it.into_syntax(), } } @@ -10203,8 +10142,8 @@ impl std::fmt::Debug for GritListIndex { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { GritListIndex::AnyGritContainer(it) => std::fmt::Debug::fmt(it, f), - GritListIndex::GritIntLiteral(it) => std::fmt::Debug::fmt(it, f), - GritListIndex::GritNegativeIntLiteral(it) => std::fmt::Debug::fmt(it, f), + GritListIndex::GritIntValue(it) => std::fmt::Debug::fmt(it, f), + GritListIndex::GritNegativeIntValue(it) => std::fmt::Debug::fmt(it, f), } } } @@ -10212,8 +10151,8 @@ impl From for SyntaxNode { fn from(n: GritListIndex) -> SyntaxNode { match n { GritListIndex::AnyGritContainer(it) => it.into(), - GritListIndex::GritIntLiteral(it) => it.into(), - GritListIndex::GritNegativeIntLiteral(it) => it.into(), + GritListIndex::GritIntValue(it) => it.into(), + GritListIndex::GritNegativeIntValue(it) => it.into(), } } } @@ -10401,57 +10340,59 @@ impl From for SyntaxElement { node.into() } } -impl From for GritRegex { - fn from(node: GritRegexLiteral) -> GritRegex { - GritRegex::GritRegexLiteral(node) +impl From for GritRegex { + fn from(node: GritRegexValue) -> GritRegex { + GritRegex::GritRegexValue(node) } } -impl From for GritRegex { - fn from(node: GritSnippetRegex) -> GritRegex { - GritRegex::GritSnippetRegex(node) +impl From for GritRegex { + fn from(node: GritSnippetRegexValue) -> GritRegex { + GritRegex::GritSnippetRegexValue(node) } } impl AstNode for GritRegex { type Language = Language; const KIND_SET: SyntaxKindSet = - GritRegexLiteral::KIND_SET.union(GritSnippetRegex::KIND_SET); + GritRegexValue::KIND_SET.union(GritSnippetRegexValue::KIND_SET); fn can_cast(kind: SyntaxKind) -> bool { - matches!(kind, GRIT_REGEX_LITERAL | GRIT_SNIPPET_REGEX) + matches!(kind, GRIT_REGEX_VALUE | GRIT_SNIPPET_REGEX_VALUE) } fn cast(syntax: SyntaxNode) -> Option { let res = match syntax.kind() { - GRIT_REGEX_LITERAL => GritRegex::GritRegexLiteral(GritRegexLiteral { syntax }), - GRIT_SNIPPET_REGEX => GritRegex::GritSnippetRegex(GritSnippetRegex { syntax }), + GRIT_REGEX_VALUE => GritRegex::GritRegexValue(GritRegexValue { syntax }), + GRIT_SNIPPET_REGEX_VALUE => { + GritRegex::GritSnippetRegexValue(GritSnippetRegexValue { syntax }) + } _ => return None, }; Some(res) } fn syntax(&self) -> &SyntaxNode { match self { - GritRegex::GritRegexLiteral(it) => &it.syntax, - GritRegex::GritSnippetRegex(it) => &it.syntax, + GritRegex::GritRegexValue(it) => &it.syntax, + GritRegex::GritSnippetRegexValue(it) => &it.syntax, } } fn into_syntax(self) -> SyntaxNode { match self { - GritRegex::GritRegexLiteral(it) => it.syntax, - GritRegex::GritSnippetRegex(it) => it.syntax, + GritRegex::GritRegexValue(it) => it.syntax, + GritRegex::GritSnippetRegexValue(it) => it.syntax, } } } impl std::fmt::Debug for GritRegex { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - GritRegex::GritRegexLiteral(it) => std::fmt::Debug::fmt(it, f), - GritRegex::GritSnippetRegex(it) => std::fmt::Debug::fmt(it, f), + GritRegex::GritRegexValue(it) => std::fmt::Debug::fmt(it, f), + GritRegex::GritSnippetRegexValue(it) => std::fmt::Debug::fmt(it, f), } } } impl From for SyntaxNode { fn from(n: GritRegex) -> SyntaxNode { match n { - GritRegex::GritRegexLiteral(it) => it.into(), - GritRegex::GritSnippetRegex(it) => it.into(), + GritRegex::GritRegexValue(it) => it.into(), + GritRegex::GritSnippetRegexValue(it) => it.into(), } } } @@ -10623,7 +10564,7 @@ impl std::fmt::Display for GritBacktickSnippet { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for GritBooleanLiteral { +impl std::fmt::Display for GritBooleanValue { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -10663,12 +10604,7 @@ impl std::fmt::Display for GritDotdotdot { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for GritDoubleLiteral { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} -impl std::fmt::Display for GritDoubleQuoteSnippet { +impl std::fmt::Display for GritDoubleValue { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -10688,7 +10624,7 @@ impl std::fmt::Display for GritFunctionDefinition { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for GritIntLiteral { +impl std::fmt::Display for GritIntValue { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -10778,7 +10714,7 @@ impl std::fmt::Display for GritNamedArgWithDefault { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for GritNegativeIntLiteral { +impl std::fmt::Display for GritNegativeIntValue { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -10998,17 +10934,17 @@ impl std::fmt::Display for GritRawBacktickSnippet { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for GritRegexLiteral { +impl std::fmt::Display for GritRegexPattern { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for GritRegexPattern { +impl std::fmt::Display for GritRegexPatternVariables { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for GritRegexPatternVariables { +impl std::fmt::Display for GritRegexValue { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -11028,7 +10964,7 @@ impl std::fmt::Display for GritSequential { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for GritSnippetRegex { +impl std::fmt::Display for GritSnippetRegexValue { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -11038,7 +10974,7 @@ impl std::fmt::Display for GritSome { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for GritStringLiteral { +impl std::fmt::Display for GritStringValue { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } diff --git a/crates/biome_grit_syntax/src/generated/nodes_mut.rs b/crates/biome_grit_syntax/src/generated/nodes_mut.rs index 9111a30abc3..c691a445e9d 100644 --- a/crates/biome_grit_syntax/src/generated/nodes_mut.rs +++ b/crates/biome_grit_syntax/src/generated/nodes_mut.rs @@ -372,7 +372,7 @@ impl AnyGritPredicate { .splice_slots(19usize..=19usize, once(Some(element.into()))), ) } - pub fn with_grit_boolean_literal(self, element: GritBooleanLiteral) -> Self { + pub fn with_grit_boolean_value(self, element: GritBooleanValue) -> Self { Self::unwrap_cast( self.syntax .splice_slots(20usize..=20usize, once(Some(element.into_syntax().into()))), @@ -467,7 +467,7 @@ impl GritBacktickSnippet { ) } } -impl GritBooleanLiteral { +impl GritBooleanValue { pub fn with_true_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax @@ -591,15 +591,7 @@ impl GritDotdotdot { )) } } -impl GritDoubleLiteral { - pub fn with_value_token(self, element: SyntaxToken) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(0usize..=0usize, once(Some(element.into()))), - ) - } -} -impl GritDoubleQuoteSnippet { +impl GritDoubleValue { pub fn with_value_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax @@ -685,7 +677,7 @@ impl GritFunctionDefinition { ) } } -impl GritIntLiteral { +impl GritIntValue { pub fn with_value_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax @@ -712,6 +704,12 @@ impl GritLanguageDeclaration { once(element.map(|element| element.into_syntax().into())), )) } + pub fn with_semicolon_token(self, element: Option) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(3usize..=3usize, once(element.map(|element| element.into()))), + ) + } } impl GritLanguageFlavor { pub fn with_l_paren_token(self, element: SyntaxToken) -> Self { @@ -732,12 +730,6 @@ impl GritLanguageFlavor { .splice_slots(2usize..=2usize, once(Some(element.into()))), ) } - pub fn with_semicolon_token(self, element: Option) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(3usize..=3usize, once(element.map(|element| element.into()))), - ) - } } impl GritLanguageFlavorKind { pub fn with_flavor_kind_token(self, element: SyntaxToken) -> Self { @@ -786,10 +778,10 @@ impl GritLanguageSpecificSnippet { .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), ) } - pub fn with_snippet(self, element: GritDoubleQuoteSnippet) -> Self { + pub fn with_snippet_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax - .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + .splice_slots(1usize..=1usize, once(Some(element.into()))), ) } } @@ -1033,7 +1025,7 @@ impl GritNamedArgWithDefault { ) } } -impl GritNegativeIntLiteral { +impl GritNegativeIntValue { pub fn with_value_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax @@ -1395,7 +1387,7 @@ impl GritPatternLimit { .splice_slots(1usize..=1usize, once(Some(element.into()))), ) } - pub fn with_limit(self, element: GritIntLiteral) -> Self { + pub fn with_limit(self, element: GritIntValue) -> Self { Self::unwrap_cast( self.syntax .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), @@ -1952,14 +1944,6 @@ impl GritRawBacktickSnippet { ) } } -impl GritRegexLiteral { - pub fn with_value_token(self, element: SyntaxToken) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(0usize..=0usize, once(Some(element.into()))), - ) - } -} impl GritRegexPattern { pub fn with_regex(self, element: GritRegex) -> Self { Self::unwrap_cast( @@ -1994,6 +1978,14 @@ impl GritRegexPatternVariables { ) } } +impl GritRegexValue { + pub fn with_value_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } +} impl GritRewrite { pub fn with_left(self, element: AnyGritPattern) -> Self { Self::unwrap_cast( @@ -2021,36 +2013,48 @@ impl GritRewrite { } } impl GritRoot { + pub fn with_bom_token(self, element: Option) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(element.map(|element| element.into()))), + ) + } pub fn with_version(self, element: Option) -> Self { Self::unwrap_cast(self.syntax.splice_slots( - 0usize..=0usize, + 1usize..=1usize, once(element.map(|element| element.into_syntax().into())), )) } pub fn with_language(self, element: Option) -> Self { Self::unwrap_cast(self.syntax.splice_slots( - 1usize..=1usize, + 2usize..=2usize, once(element.map(|element| element.into_syntax().into())), )) } pub fn with_definitions(self, element: Option) -> Self { Self::unwrap_cast(self.syntax.splice_slots( - 2usize..=2usize, + 3usize..=3usize, once(element.map(|element| element.into_syntax().into())), )) } pub fn with_pattern(self, element: Option) -> Self { Self::unwrap_cast(self.syntax.splice_slots( - 3usize..=3usize, + 4usize..=4usize, once(element.map(|element| element.into_syntax().into())), )) } pub fn with_definitions_continued(self, element: Option) -> Self { Self::unwrap_cast(self.syntax.splice_slots( - 4usize..=4usize, + 5usize..=5usize, once(element.map(|element| element.into_syntax().into())), )) } + pub fn with_eof_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(6usize..=6usize, once(Some(element.into()))), + ) + } } impl GritSequential { pub fn with_sequential_token(self, element: SyntaxToken) -> Self { @@ -2078,7 +2082,7 @@ impl GritSequential { ) } } -impl GritSnippetRegex { +impl GritSnippetRegexValue { pub fn with_value_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax @@ -2100,7 +2104,7 @@ impl GritSome { ) } } -impl GritStringLiteral { +impl GritStringValue { pub fn with_value_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax @@ -2171,7 +2175,7 @@ impl GritVersion { .splice_slots(2usize..=2usize, once(Some(element.into()))), ) } - pub fn with_grit_double_literal(self, element: GritDoubleLiteral) -> Self { + pub fn with_grit_double_value(self, element: GritDoubleValue) -> Self { Self::unwrap_cast( self.syntax .splice_slots(3usize..=3usize, once(Some(element.into_syntax().into()))), diff --git a/xtask/codegen/gritql.ungram b/xtask/codegen/gritql.ungram index 1159133785a..fa666d5410c 100644 --- a/xtask/codegen/gritql.ungram +++ b/xtask/codegen/gritql.ungram @@ -45,11 +45,13 @@ GritBogusNamedArg = SyntaxElement* GritBogusPredicate = SyntaxElement* GritRoot = + bom: 'UNICODE_BOM'? version: GritVersion? language: GritLanguageDeclaration? definitions: GritDefinitionList? pattern: AnyGritPattern? definitions_continued: GritDefinitionList? + eof: 'EOF' GritSequential = 'sequential' '{' sequential: GritSequentialList '}' GritSequentialList = AnyGritPattern (',' AnyGritPattern)* ','? @@ -65,14 +67,15 @@ AnyGritDefinition = GritDefinitionList = AnyGritDefinition ('newline' AnyGritDefinition)* 'newline'? -GritVersion = 'engine' 'biome' '(' GritDoubleLiteral ')' +GritVersion = 'engine' 'biome' '(' GritDoubleValue ')' GritLanguageDeclaration = 'language' name: GritLanguageName flavor: GritLanguageFlavor? + ';'? -GritLanguageFlavor = '(' GritLanguageFlavorList ')' ';'? +GritLanguageFlavor = '(' GritLanguageFlavorList ')' GritLanguageFlavorList = GritLanguageFlavorKind (',' GritLanguageFlavorKind)* ','? GritLanguageFlavorKind = flavor_kind: ( @@ -147,7 +150,7 @@ GritPatternAs = pattern: AnyGritPattern 'as' variable: GritVariable GritPatternLimit = - pattern: AnyGritPattern 'limit' limit: GritIntLiteral + pattern: AnyGritPattern 'limit' limit: GritIntValue // statement, in the engine this is a predicate that always evaluates to true // This is useful for initializing variables at the root of a pattern definition @@ -163,10 +166,10 @@ GritPatternWhere = AnyGritLiteral = GritCodeSnippet - | GritStringLiteral - | GritIntLiteral - | GritDoubleLiteral - | GritBooleanLiteral + | GritStringValue + | GritIntValue + | GritDoubleValue + | GritBooleanValue | GritUndefined | GritMap | GritList @@ -303,7 +306,7 @@ GritListAccessor = ']' GritListAccessorSubject = GritList | AnyGritContainer -GritListIndex = AnyGritContainer | GritNegativeIntLiteral | GritIntLiteral +GritListIndex = AnyGritContainer | GritNegativeIntValue | GritIntValue GritDot = '.' @@ -390,7 +393,7 @@ AnyGritPredicate = | GritPredicateMatch | GritPredicateCall | '(' AnyGritPredicate ')' - | GritBooleanLiteral + | GritBooleanValue | GritPredicateReturn | GritBogusPredicate @@ -497,7 +500,7 @@ GritPredicateReturn = // --- tokens and lexical definitions -GritBooleanLiteral = 'true' | 'false' +GritBooleanValue = 'true' | 'false' GritVariable = 'grit_variable' GritVariableList = GritVariable (',' GritVariable)* ','? @@ -536,17 +539,17 @@ GritNot = 'not' | '!' GritUndefined = 'undefined' -GritIntLiteral = value: 'grit_int_literal' -GritNegativeIntLiteral = value: 'grit_negative_int_literal' +GritIntValue = value: 'grit_int_literal' +GritNegativeIntValue = value: 'grit_negative_int_literal' -GritDoubleLiteral = value: 'grit_double_literal' +GritDoubleValue = value: 'grit_double_literal' -GritStringLiteral = value: 'grit_string_literal' +GritStringValue = value: 'grit_string_literal' -GritRegex = GritRegexLiteral | GritSnippetRegex +GritRegex = GritRegexValue | GritSnippetRegexValue -GritRegexLiteral = value: 'grit_regex_literal' +GritRegexValue = value: 'grit_regex_literal' -GritSnippetRegex = value: 'grit_snippet_regex_literal' +GritSnippetRegexValue = value: 'grit_snippet_regex_literal' GritAnnotation = 'grit_annotation' diff --git a/xtask/codegen/src/grit_kinds_src.rs b/xtask/codegen/src/grit_kinds_src.rs index 73d6dc2efb6..10ec69b2bbf 100644 --- a/xtask/codegen/src/grit_kinds_src.rs +++ b/xtask/codegen/src/grit_kinds_src.rs @@ -212,7 +212,13 @@ pub const GRIT_KINDS_SRC: KindsSrc = KindsSrc { "GRIT_LANGUAGE_SPECIFIC_SNIPPET", "GRIT_CODE_SNIPPET", "GRIT_NOT", - "GRIT_SNIPPET_REGEX", + "GRIT_BOOLEAN_VALUE", + "GRIT_DOUBLE_VALUE", + "GRIT_INT_VALUE", + "GRIT_NEGATIVE_INT_VALUE", + "GRIT_REGEX_VALUE", + "GRIT_SNIPPET_REGEX_VALUE", + "GRIT_STRING_VALUE", "GRIT_UNDEFINED", "GRIT_UNDERSCORE", "MAYBE_CURLY_GRIT_PATTERN", From a1b3373ff02d82dcf7cc40c355b7ee59b00937db Mon Sep 17 00:00:00 2001 From: "Arend van Beelen jr." Date: Sun, 25 Feb 2024 11:03:34 +0100 Subject: [PATCH 05/12] Parser progress --- .../src/generated/node_factory.rs | 233 +- .../src/generated/syntax_factory.rs | 569 +-- crates/biome_grit_parser/src/lexer/mod.rs | 19 + crates/biome_grit_parser/src/lib.rs | 22 +- crates/biome_grit_parser/src/parser.rs | 211 +- .../err/incorrect_engine.grit.snap | 2 +- .../err/incorrect_version.grit.snap | 2 +- .../grit_test_suite/err/invalid_language.grit | 1 + .../err/invalid_language.grit.snap | 59 + .../err/language_with_invalid_flavor.grit | 1 + .../language_with_invalid_flavor.grit.snap | 69 + .../err/missing_version.grit.snap | 2 +- .../grit_test_suite/ok/backtick_snippet.grit | 1 + .../ok/backtick_snippet.grit.snap | 43 + .../tests/grit_test_suite/ok/language.grit | 1 + .../grit_test_suite/ok/language.grit.snap | 49 + .../ok/language_with_flavor.grit | 1 + .../ok/language_with_flavor.grit.snap | 62 + .../biome_grit_syntax/src/generated/kind.rs | 48 +- .../biome_grit_syntax/src/generated/macros.rs | 54 +- .../biome_grit_syntax/src/generated/nodes.rs | 3413 ++++++++++------- .../src/generated/nodes_mut.rs | 430 +-- xtask/codegen/gritql.ungram | 64 +- xtask/codegen/src/grit_kinds_src.rs | 41 +- 24 files changed, 2856 insertions(+), 2541 deletions(-) create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/err/invalid_language.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/err/invalid_language.grit.snap create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/err/language_with_invalid_flavor.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/err/language_with_invalid_flavor.grit.snap create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/backtick_snippet.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/backtick_snippet.grit.snap create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/language.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/language.grit.snap create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/language_with_flavor.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/language_with_flavor.grit.snap diff --git a/crates/biome_grit_factory/src/generated/node_factory.rs b/crates/biome_grit_factory/src/generated/node_factory.rs index 44c4d9d6b2d..d0486563479 100644 --- a/crates/biome_grit_factory/src/generated/node_factory.rs +++ b/crates/biome_grit_factory/src/generated/node_factory.rs @@ -7,151 +7,31 @@ use biome_grit_syntax::{ GritSyntaxToken as SyntaxToken, *, }; use biome_rowan::AstNode; -pub fn any_grit_pattern( - any_grit_literal: AnyGritLiteral, - grit_pattern_not: GritPatternNot, - grit_pattern_or: GritPatternOr, - grit_pattern_or_else: GritPatternOrElse, - grit_pattern_any: GritPatternAny, - grit_pattern_and: GritPatternAnd, - grit_pattern_maybe: GritPatternMaybe, - grit_pattern_if_else: GritPatternIfElse, - grit_pattern_contains: GritPatternContains, - grit_pattern_includes: GritPatternIncludes, - grit_pattern_after: GritPatternAfter, - grit_pattern_before: GritPatternBefore, - grit_within: GritWithin, - grit_bubble: GritBubble, - grit_node_like: GritNodeLike, - grit_map_accessor: GritMapAccessor, - grit_list_accessor: GritListAccessor, - grit_dot: GritDot, - grit_some: GritSome, - grit_every: GritEvery, - grit_underscore: GritUnderscore, - grit_variable: GritVariable, - grit_regex_pattern: GritRegexPattern, - grit_pattern_as: GritPatternAs, - grit_pattern_limit: GritPatternLimit, - grit_assignment_as_pattern: GritAssignmentAsPattern, - grit_pattern_accumulate: GritPatternAccumulate, - grit_rewrite: GritRewrite, - grit_like: GritLike, - grit_pattern_where: GritPatternWhere, - grit_mul_operation: GritMulOperation, - grit_div_operation: GritDivOperation, - grit_mod_operation: GritModOperation, - grit_add_operation: GritAddOperation, - grit_sub_operation: GritSubOperation, - grit_sequential: GritSequential, - grit_files: GritFiles, +pub fn bracketed_grit_pattern( l_paren_token: SyntaxToken, any_grit_pattern: AnyGritPattern, r_paren_token: SyntaxToken, - grit_bogus_pattern: GritBogusPattern, -) -> AnyGritPattern { - AnyGritPattern::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::ANY_GRIT_PATTERN, +) -> BracketedGritPattern { + BracketedGritPattern::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::BRACKETED_GRIT_PATTERN, [ - Some(SyntaxElement::Node(any_grit_literal.into_syntax())), - Some(SyntaxElement::Node(grit_pattern_not.into_syntax())), - Some(SyntaxElement::Node(grit_pattern_or.into_syntax())), - Some(SyntaxElement::Node(grit_pattern_or_else.into_syntax())), - Some(SyntaxElement::Node(grit_pattern_any.into_syntax())), - Some(SyntaxElement::Node(grit_pattern_and.into_syntax())), - Some(SyntaxElement::Node(grit_pattern_maybe.into_syntax())), - Some(SyntaxElement::Node(grit_pattern_if_else.into_syntax())), - Some(SyntaxElement::Node(grit_pattern_contains.into_syntax())), - Some(SyntaxElement::Node(grit_pattern_includes.into_syntax())), - Some(SyntaxElement::Node(grit_pattern_after.into_syntax())), - Some(SyntaxElement::Node(grit_pattern_before.into_syntax())), - Some(SyntaxElement::Node(grit_within.into_syntax())), - Some(SyntaxElement::Node(grit_bubble.into_syntax())), - Some(SyntaxElement::Node(grit_node_like.into_syntax())), - Some(SyntaxElement::Node(grit_map_accessor.into_syntax())), - Some(SyntaxElement::Node(grit_list_accessor.into_syntax())), - Some(SyntaxElement::Node(grit_dot.into_syntax())), - Some(SyntaxElement::Node(grit_some.into_syntax())), - Some(SyntaxElement::Node(grit_every.into_syntax())), - Some(SyntaxElement::Node(grit_underscore.into_syntax())), - Some(SyntaxElement::Node(grit_variable.into_syntax())), - Some(SyntaxElement::Node(grit_regex_pattern.into_syntax())), - Some(SyntaxElement::Node(grit_pattern_as.into_syntax())), - Some(SyntaxElement::Node(grit_pattern_limit.into_syntax())), - Some(SyntaxElement::Node( - grit_assignment_as_pattern.into_syntax(), - )), - Some(SyntaxElement::Node(grit_pattern_accumulate.into_syntax())), - Some(SyntaxElement::Node(grit_rewrite.into_syntax())), - Some(SyntaxElement::Node(grit_like.into_syntax())), - Some(SyntaxElement::Node(grit_pattern_where.into_syntax())), - Some(SyntaxElement::Node(grit_mul_operation.into_syntax())), - Some(SyntaxElement::Node(grit_div_operation.into_syntax())), - Some(SyntaxElement::Node(grit_mod_operation.into_syntax())), - Some(SyntaxElement::Node(grit_add_operation.into_syntax())), - Some(SyntaxElement::Node(grit_sub_operation.into_syntax())), - Some(SyntaxElement::Node(grit_sequential.into_syntax())), - Some(SyntaxElement::Node(grit_files.into_syntax())), Some(SyntaxElement::Token(l_paren_token)), Some(SyntaxElement::Node(any_grit_pattern.into_syntax())), Some(SyntaxElement::Token(r_paren_token)), - Some(SyntaxElement::Node(grit_bogus_pattern.into_syntax())), ], )) } -pub fn any_grit_predicate( - grit_predicate_not: GritPredicateNot, - grit_predicate_maybe: GritPredicateMaybe, - grit_predicate_and: GritPredicateAnd, - grit_predicate_or: GritPredicateOr, - grit_predicate_any: GritPredicateAny, - grit_predicate_if_else: GritPredicateIfElse, - grit_predicate_assignment: GritPredicateAssignment, - grit_predicate_accumulate: GritPredicateAccumulate, - grit_predicate_rewrite: GritPredicateRewrite, - grit_predicate_greater: GritPredicateGreater, - grit_predicate_less: GritPredicateLess, - grit_predicate_greater_equal: GritPredicateGreaterEqual, - grit_predicate_less_equal: GritPredicateLessEqual, - grit_predicate_not_equal: GritPredicateNotEqual, - grit_predicate_equal: GritPredicateEqual, - grit_predicate_match: GritPredicateMatch, - grit_predicate_call: GritPredicateCall, +pub fn bracketed_grit_predicate( l_paren_token: SyntaxToken, any_grit_predicate: AnyGritPredicate, r_paren_token: SyntaxToken, - grit_boolean_value: GritBooleanValue, - grit_predicate_return: GritPredicateReturn, - grit_bogus_predicate: GritBogusPredicate, -) -> AnyGritPredicate { - AnyGritPredicate::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::ANY_GRIT_PREDICATE, +) -> BracketedGritPredicate { + BracketedGritPredicate::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::BRACKETED_GRIT_PREDICATE, [ - Some(SyntaxElement::Node(grit_predicate_not.into_syntax())), - Some(SyntaxElement::Node(grit_predicate_maybe.into_syntax())), - Some(SyntaxElement::Node(grit_predicate_and.into_syntax())), - Some(SyntaxElement::Node(grit_predicate_or.into_syntax())), - Some(SyntaxElement::Node(grit_predicate_any.into_syntax())), - Some(SyntaxElement::Node(grit_predicate_if_else.into_syntax())), - Some(SyntaxElement::Node(grit_predicate_assignment.into_syntax())), - Some(SyntaxElement::Node(grit_predicate_accumulate.into_syntax())), - Some(SyntaxElement::Node(grit_predicate_rewrite.into_syntax())), - Some(SyntaxElement::Node(grit_predicate_greater.into_syntax())), - Some(SyntaxElement::Node(grit_predicate_less.into_syntax())), - Some(SyntaxElement::Node( - grit_predicate_greater_equal.into_syntax(), - )), - Some(SyntaxElement::Node(grit_predicate_less_equal.into_syntax())), - Some(SyntaxElement::Node(grit_predicate_not_equal.into_syntax())), - Some(SyntaxElement::Node(grit_predicate_equal.into_syntax())), - Some(SyntaxElement::Node(grit_predicate_match.into_syntax())), - Some(SyntaxElement::Node(grit_predicate_call.into_syntax())), Some(SyntaxElement::Token(l_paren_token)), Some(SyntaxElement::Node(any_grit_predicate.into_syntax())), Some(SyntaxElement::Token(r_paren_token)), - Some(SyntaxElement::Node(grit_boolean_value.into_syntax())), - Some(SyntaxElement::Node(grit_predicate_return.into_syntax())), - Some(SyntaxElement::Node(grit_bogus_predicate.into_syntax())), ], )) } @@ -203,15 +83,18 @@ pub fn grit_assignment_as_pattern( ], )) } -pub fn grit_backtick_snippet(value_token: SyntaxToken) -> GritBacktickSnippet { - GritBacktickSnippet::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_BACKTICK_SNIPPET, +pub fn grit_backtick_snippet_literal(value_token: SyntaxToken) -> GritBacktickSnippetLiteral { + GritBacktickSnippetLiteral::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_BACKTICK_SNIPPET_LITERAL, [Some(SyntaxElement::Token(value_token))], )) } -pub fn grit_boolean_value(true_token: SyntaxToken, false_token: SyntaxToken) -> GritBooleanValue { - GritBooleanValue::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_BOOLEAN_VALUE, +pub fn grit_boolean_literal( + true_token: SyntaxToken, + false_token: SyntaxToken, +) -> GritBooleanLiteral { + GritBooleanLiteral::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_BOOLEAN_LITERAL, [ Some(SyntaxElement::Token(true_token)), Some(SyntaxElement::Token(false_token)), @@ -366,9 +249,9 @@ impl GritDotdotdotBuilder { )) } } -pub fn grit_double_value(value_token: SyntaxToken) -> GritDoubleValue { - GritDoubleValue::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_DOUBLE_VALUE, +pub fn grit_double_literal(value_token: SyntaxToken) -> GritDoubleLiteral { + GritDoubleLiteral::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_DOUBLE_LITERAL, [Some(SyntaxElement::Token(value_token))], )) } @@ -441,9 +324,9 @@ impl GritFunctionDefinitionBuilder { )) } } -pub fn grit_int_value(value_token: SyntaxToken) -> GritIntValue { - GritIntValue::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_INT_VALUE, +pub fn grit_int_literal(value_token: SyntaxToken) -> GritIntLiteral { + GritIntLiteral::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_INT_LITERAL, [Some(SyntaxElement::Token(value_token))], )) } @@ -507,22 +390,10 @@ pub fn grit_language_flavor_kind(flavor_kind_token: SyntaxToken) -> GritLanguage [Some(SyntaxElement::Token(flavor_kind_token))], )) } -pub fn grit_language_name( - js_token: SyntaxToken, - css_token: SyntaxToken, - json_token: SyntaxToken, - grit_token: SyntaxToken, - html_token: SyntaxToken, -) -> GritLanguageName { +pub fn grit_language_name(language_kind_token: SyntaxToken) -> GritLanguageName { GritLanguageName::unwrap_cast(SyntaxNode::new_detached( GritSyntaxKind::GRIT_LANGUAGE_NAME, - [ - Some(SyntaxElement::Token(js_token)), - Some(SyntaxElement::Token(css_token)), - Some(SyntaxElement::Token(json_token)), - Some(SyntaxElement::Token(grit_token)), - Some(SyntaxElement::Token(html_token)), - ], + [Some(SyntaxElement::Token(language_kind_token))], )) } pub fn grit_language_specific_snippet( @@ -755,9 +626,9 @@ pub fn grit_named_arg_with_default( ], )) } -pub fn grit_negative_int_value(value_token: SyntaxToken) -> GritNegativeIntValue { - GritNegativeIntValue::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_NEGATIVE_INT_VALUE, +pub fn grit_negative_int_literal(value_token: SyntaxToken) -> GritNegativeIntLiteral { + GritNegativeIntLiteral::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_NEGATIVE_INT_LITERAL, [Some(SyntaxElement::Token(value_token))], )) } @@ -1146,7 +1017,7 @@ pub fn grit_pattern_includes( pub fn grit_pattern_limit( pattern: AnyGritPattern, limit_token: SyntaxToken, - limit: GritIntValue, + limit: GritIntLiteral, ) -> GritPatternLimit { GritPatternLimit::unwrap_cast(SyntaxNode::new_detached( GritSyntaxKind::GRIT_PATTERN_LIMIT, @@ -1689,20 +1560,28 @@ impl GritPredicateRewriteBuilder { )) } } -pub fn grit_raw_backtick_snippet(value_token: SyntaxToken) -> GritRawBacktickSnippet { - GritRawBacktickSnippet::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_RAW_BACKTICK_SNIPPET, +pub fn grit_raw_backtick_snippet_literal( + value_token: SyntaxToken, +) -> GritRawBacktickSnippetLiteral { + GritRawBacktickSnippetLiteral::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_RAW_BACKTICK_SNIPPET_LITERAL, + [Some(SyntaxElement::Token(value_token))], + )) +} +pub fn grit_regex_literal(value_token: SyntaxToken) -> GritRegexLiteral { + GritRegexLiteral::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_REGEX_LITERAL, [Some(SyntaxElement::Token(value_token))], )) } -pub fn grit_regex_pattern(regex: GritRegex) -> GritRegexPatternBuilder { +pub fn grit_regex_pattern(regex: AnyGritRegex) -> GritRegexPatternBuilder { GritRegexPatternBuilder { regex, variables: None, } } pub struct GritRegexPatternBuilder { - regex: GritRegex, + regex: AnyGritRegex, variables: Option, } impl GritRegexPatternBuilder { @@ -1753,12 +1632,6 @@ impl GritRegexPatternVariablesBuilder { )) } } -pub fn grit_regex_value(value_token: SyntaxToken) -> GritRegexValue { - GritRegexValue::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_REGEX_VALUE, - [Some(SyntaxElement::Token(value_token))], - )) -} pub fn grit_rewrite( left: AnyGritPattern, fat_arrow_token: SyntaxToken, @@ -1876,9 +1749,9 @@ pub fn grit_sequential( ], )) } -pub fn grit_snippet_regex_value(value_token: SyntaxToken) -> GritSnippetRegexValue { - GritSnippetRegexValue::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_SNIPPET_REGEX_VALUE, +pub fn grit_snippet_regex_literal(value_token: SyntaxToken) -> GritSnippetRegexLiteral { + GritSnippetRegexLiteral::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_SNIPPET_REGEX_LITERAL, [Some(SyntaxElement::Token(value_token))], )) } @@ -1891,9 +1764,9 @@ pub fn grit_some(some_token: SyntaxToken, pattern: MaybeCurlyGritPattern) -> Gri ], )) } -pub fn grit_string_value(value_token: SyntaxToken) -> GritStringValue { - GritStringValue::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_STRING_VALUE, +pub fn grit_string_literal(value_token: SyntaxToken) -> GritStringLiteral { + GritStringLiteral::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_STRING_LITERAL, [Some(SyntaxElement::Token(value_token))], )) } @@ -1911,9 +1784,9 @@ pub fn grit_sub_operation( ], )) } -pub fn grit_undefined(undefined_token: SyntaxToken) -> GritUndefined { - GritUndefined::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_UNDEFINED, +pub fn grit_undefined_literal(undefined_token: SyntaxToken) -> GritUndefinedLiteral { + GritUndefinedLiteral::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_UNDEFINED_LITERAL, [Some(SyntaxElement::Token(undefined_token))], )) } @@ -1933,7 +1806,7 @@ pub fn grit_version( engine_token: SyntaxToken, biome_token: SyntaxToken, l_paren_token: SyntaxToken, - grit_double_value: GritDoubleValue, + grit_double_literal: GritDoubleLiteral, r_paren_token: SyntaxToken, ) -> GritVersion { GritVersion::unwrap_cast(SyntaxNode::new_detached( @@ -1942,7 +1815,7 @@ pub fn grit_version( Some(SyntaxElement::Token(engine_token)), Some(SyntaxElement::Token(biome_token)), Some(SyntaxElement::Token(l_paren_token)), - Some(SyntaxElement::Node(grit_double_value.into_syntax())), + Some(SyntaxElement::Node(grit_double_literal.into_syntax())), Some(SyntaxElement::Token(r_paren_token)), ], )) diff --git a/crates/biome_grit_factory/src/generated/syntax_factory.rs b/crates/biome_grit_factory/src/generated/syntax_factory.rs index 2409a8f45ac..2c00dc37675 100644 --- a/crates/biome_grit_factory/src/generated/syntax_factory.rs +++ b/crates/biome_grit_factory/src/generated/syntax_factory.rs @@ -20,269 +20,10 @@ impl SyntaxFactory for GritSyntaxFactory { | GRIT_BOGUS_NAMED_ARG | GRIT_BOGUS_PATTERN | GRIT_BOGUS_PREDICATE => RawSyntaxNode::new(kind, children.into_iter().map(Some)), - ANY_GRIT_PATTERN => { + BRACKETED_GRIT_PATTERN => { let mut elements = (&children).into_iter(); - let mut slots: RawNodeSlots<41usize> = RawNodeSlots::default(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); let mut current_element = elements.next(); - if let Some(element) = ¤t_element { - if AnyGritLiteral::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPatternNot::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPatternOr::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPatternOrElse::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPatternAny::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPatternAnd::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPatternMaybe::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPatternIfElse::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPatternContains::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPatternIncludes::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPatternAfter::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPatternBefore::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritWithin::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritBubble::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritNodeLike::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritMapAccessor::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritListAccessor::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritDot::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritSome::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritEvery::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritUnderscore::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritVariable::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritRegexPattern::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPatternAs::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPatternLimit::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritAssignmentAsPattern::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPatternAccumulate::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritRewrite::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritLike::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPatternWhere::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritMulOperation::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritDivOperation::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritModOperation::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritAddOperation::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritSubOperation::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritSequential::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritFiles::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); if let Some(element) = ¤t_element { if element.kind() == T!['('] { slots.mark_present(); @@ -304,144 +45,18 @@ impl SyntaxFactory for GritSyntaxFactory { } } slots.next_slot(); - if let Some(element) = ¤t_element { - if GritBogusPattern::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( - ANY_GRIT_PATTERN.to_bogus(), + BRACKETED_GRIT_PATTERN.to_bogus(), children.into_iter().map(Some), ); } - slots.into_node(ANY_GRIT_PATTERN, children) + slots.into_node(BRACKETED_GRIT_PATTERN, children) } - ANY_GRIT_PREDICATE => { + BRACKETED_GRIT_PREDICATE => { let mut elements = (&children).into_iter(); - let mut slots: RawNodeSlots<23usize> = RawNodeSlots::default(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); let mut current_element = elements.next(); - if let Some(element) = ¤t_element { - if GritPredicateNot::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPredicateMaybe::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPredicateAnd::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPredicateOr::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPredicateAny::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPredicateIfElse::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPredicateAssignment::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPredicateAccumulate::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPredicateRewrite::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPredicateGreater::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPredicateLess::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPredicateGreaterEqual::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPredicateLessEqual::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPredicateNotEqual::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPredicateEqual::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPredicateMatch::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPredicateCall::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); if let Some(element) = ¤t_element { if element.kind() == T!['('] { slots.mark_present(); @@ -463,34 +78,13 @@ impl SyntaxFactory for GritSyntaxFactory { } } slots.next_slot(); - if let Some(element) = ¤t_element { - if GritBooleanValue::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritPredicateReturn::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GritBogusPredicate::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( - ANY_GRIT_PREDICATE.to_bogus(), + BRACKETED_GRIT_PREDICATE.to_bogus(), children.into_iter().map(Some), ); } - slots.into_node(ANY_GRIT_PREDICATE, children) + slots.into_node(BRACKETED_GRIT_PREDICATE, children) } CURLY_GRIT_PATTERN => { let mut elements = (&children).into_iter(); @@ -610,7 +204,7 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.into_node(GRIT_ASSIGNMENT_AS_PATTERN, children) } - GRIT_BACKTICK_SNIPPET => { + GRIT_BACKTICK_SNIPPET_LITERAL => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); let mut current_element = elements.next(); @@ -623,13 +217,13 @@ impl SyntaxFactory for GritSyntaxFactory { slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( - GRIT_BACKTICK_SNIPPET.to_bogus(), + GRIT_BACKTICK_SNIPPET_LITERAL.to_bogus(), children.into_iter().map(Some), ); } - slots.into_node(GRIT_BACKTICK_SNIPPET, children) + slots.into_node(GRIT_BACKTICK_SNIPPET_LITERAL, children) } - GRIT_BOOLEAN_VALUE => { + GRIT_BOOLEAN_LITERAL => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); let mut current_element = elements.next(); @@ -649,11 +243,11 @@ impl SyntaxFactory for GritSyntaxFactory { slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( - GRIT_BOOLEAN_VALUE.to_bogus(), + GRIT_BOOLEAN_LITERAL.to_bogus(), children.into_iter().map(Some), ); } - slots.into_node(GRIT_BOOLEAN_VALUE, children) + slots.into_node(GRIT_BOOLEAN_LITERAL, children) } GRIT_BUBBLE => { let mut elements = (&children).into_iter(); @@ -848,12 +442,12 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.into_node(GRIT_DOTDOTDOT, children) } - GRIT_DOUBLE_VALUE => { + GRIT_DOUBLE_LITERAL => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); let mut current_element = elements.next(); if let Some(element) = ¤t_element { - if element.kind() == GRIT_DOUBLE_LITERAL { + if element.kind() == GRIT_DOUBLE { slots.mark_present(); current_element = elements.next(); } @@ -861,11 +455,11 @@ impl SyntaxFactory for GritSyntaxFactory { slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( - GRIT_DOUBLE_VALUE.to_bogus(), + GRIT_DOUBLE_LITERAL.to_bogus(), children.into_iter().map(Some), ); } - slots.into_node(GRIT_DOUBLE_VALUE, children) + slots.into_node(GRIT_DOUBLE_LITERAL, children) } GRIT_EVERY => { let mut elements = (&children).into_iter(); @@ -987,12 +581,12 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.into_node(GRIT_FUNCTION_DEFINITION, children) } - GRIT_INT_VALUE => { + GRIT_INT_LITERAL => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); let mut current_element = elements.next(); if let Some(element) = ¤t_element { - if element.kind() == GRIT_INT_LITERAL { + if element.kind() == GRIT_INT { slots.mark_present(); current_element = elements.next(); } @@ -1000,11 +594,11 @@ impl SyntaxFactory for GritSyntaxFactory { slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( - GRIT_INT_VALUE.to_bogus(), + GRIT_INT_LITERAL.to_bogus(), children.into_iter().map(Some), ); } - slots.into_node(GRIT_INT_VALUE, children) + slots.into_node(GRIT_INT_LITERAL, children) } GRIT_LANGUAGE_DECLARATION => { let mut elements = (&children).into_iter(); @@ -1084,7 +678,7 @@ impl SyntaxFactory for GritSyntaxFactory { let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); let mut current_element = elements.next(); if let Some(element) = ¤t_element { - if matches!(element.kind(), T![typescript] | T![jsx] | T![js_do_not_use]) { + if matches!(element.kind(), T![typescript] | T![jsx]) { slots.mark_present(); current_element = elements.next(); } @@ -1100,38 +694,13 @@ impl SyntaxFactory for GritSyntaxFactory { } GRIT_LANGUAGE_NAME => { let mut elements = (&children).into_iter(); - let mut slots: RawNodeSlots<5usize> = RawNodeSlots::default(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); let mut current_element = elements.next(); if let Some(element) = ¤t_element { - if element.kind() == T![js] { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if element.kind() == T![css] { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if element.kind() == T![json] { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if element.kind() == T![grit] { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if element.kind() == T![html] { + if matches!( + element.kind(), + T![js] | T![css] | T![json] | T![grit] | T![html] + ) { slots.mark_present(); current_element = elements.next(); } @@ -1157,7 +726,7 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.next_slot(); if let Some(element) = ¤t_element { - if element.kind() == GRIT_STRING_LITERAL { + if element.kind() == GRIT_STRING { slots.mark_present(); current_element = elements.next(); } @@ -1564,12 +1133,12 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.into_node(GRIT_NAMED_ARG_WITH_DEFAULT, children) } - GRIT_NEGATIVE_INT_VALUE => { + GRIT_NEGATIVE_INT_LITERAL => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); let mut current_element = elements.next(); if let Some(element) = ¤t_element { - if element.kind() == GRIT_NEGATIVE_INT_LITERAL { + if element.kind() == GRIT_NEGATIVE_INT { slots.mark_present(); current_element = elements.next(); } @@ -1577,11 +1146,11 @@ impl SyntaxFactory for GritSyntaxFactory { slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( - GRIT_NEGATIVE_INT_VALUE.to_bogus(), + GRIT_NEGATIVE_INT_LITERAL.to_bogus(), children.into_iter().map(Some), ); } - slots.into_node(GRIT_NEGATIVE_INT_VALUE, children) + slots.into_node(GRIT_NEGATIVE_INT_LITERAL, children) } GRIT_NODE_LIKE => { let mut elements = (&children).into_iter(); @@ -2148,7 +1717,7 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.next_slot(); if let Some(element) = ¤t_element { - if GritIntValue::can_cast(element.kind()) { + if GritIntLiteral::can_cast(element.kind()) { slots.mark_present(); current_element = elements.next(); } @@ -3036,7 +2605,7 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.into_node(GRIT_PREDICATE_REWRITE, children) } - GRIT_RAW_BACKTICK_SNIPPET => { + GRIT_RAW_BACKTICK_SNIPPET_LITERAL => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); let mut current_element = elements.next(); @@ -3049,18 +2618,37 @@ impl SyntaxFactory for GritSyntaxFactory { slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( - GRIT_RAW_BACKTICK_SNIPPET.to_bogus(), + GRIT_RAW_BACKTICK_SNIPPET_LITERAL.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(GRIT_RAW_BACKTICK_SNIPPET_LITERAL, children) + } + GRIT_REGEX_LITERAL => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == GRIT_REGEX { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + GRIT_REGEX_LITERAL.to_bogus(), children.into_iter().map(Some), ); } - slots.into_node(GRIT_RAW_BACKTICK_SNIPPET, children) + slots.into_node(GRIT_REGEX_LITERAL, children) } GRIT_REGEX_PATTERN => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); let mut current_element = elements.next(); if let Some(element) = ¤t_element { - if GritRegex::can_cast(element.kind()) { + if AnyGritRegex::can_cast(element.kind()) { slots.mark_present(); current_element = elements.next(); } @@ -3114,25 +2702,6 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.into_node(GRIT_REGEX_PATTERN_VARIABLES, children) } - GRIT_REGEX_VALUE => { - let mut elements = (&children).into_iter(); - let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); - let mut current_element = elements.next(); - if let Some(element) = ¤t_element { - if element.kind() == GRIT_REGEX_LITERAL { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if current_element.is_some() { - return RawSyntaxNode::new( - GRIT_REGEX_VALUE.to_bogus(), - children.into_iter().map(Some), - ); - } - slots.into_node(GRIT_REGEX_VALUE, children) - } GRIT_REWRITE => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); @@ -3274,12 +2843,12 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.into_node(GRIT_SEQUENTIAL, children) } - GRIT_SNIPPET_REGEX_VALUE => { + GRIT_SNIPPET_REGEX_LITERAL => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); let mut current_element = elements.next(); if let Some(element) = ¤t_element { - if element.kind() == GRIT_SNIPPET_REGEX_LITERAL { + if element.kind() == GRIT_SNIPPET_REGEX { slots.mark_present(); current_element = elements.next(); } @@ -3287,11 +2856,11 @@ impl SyntaxFactory for GritSyntaxFactory { slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( - GRIT_SNIPPET_REGEX_VALUE.to_bogus(), + GRIT_SNIPPET_REGEX_LITERAL.to_bogus(), children.into_iter().map(Some), ); } - slots.into_node(GRIT_SNIPPET_REGEX_VALUE, children) + slots.into_node(GRIT_SNIPPET_REGEX_LITERAL, children) } GRIT_SOME => { let mut elements = (&children).into_iter(); @@ -3319,12 +2888,12 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.into_node(GRIT_SOME, children) } - GRIT_STRING_VALUE => { + GRIT_STRING_LITERAL => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); let mut current_element = elements.next(); if let Some(element) = ¤t_element { - if element.kind() == GRIT_STRING_LITERAL { + if element.kind() == GRIT_STRING { slots.mark_present(); current_element = elements.next(); } @@ -3332,11 +2901,11 @@ impl SyntaxFactory for GritSyntaxFactory { slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( - GRIT_STRING_VALUE.to_bogus(), + GRIT_STRING_LITERAL.to_bogus(), children.into_iter().map(Some), ); } - slots.into_node(GRIT_STRING_VALUE, children) + slots.into_node(GRIT_STRING_LITERAL, children) } GRIT_SUB_OPERATION => { let mut elements = (&children).into_iter(); @@ -3371,7 +2940,7 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.into_node(GRIT_SUB_OPERATION, children) } - GRIT_UNDEFINED => { + GRIT_UNDEFINED_LITERAL => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); let mut current_element = elements.next(); @@ -3384,11 +2953,11 @@ impl SyntaxFactory for GritSyntaxFactory { slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( - GRIT_UNDEFINED.to_bogus(), + GRIT_UNDEFINED_LITERAL.to_bogus(), children.into_iter().map(Some), ); } - slots.into_node(GRIT_UNDEFINED, children) + slots.into_node(GRIT_UNDEFINED_LITERAL, children) } GRIT_UNDERSCORE => { let mut elements = (&children).into_iter(); @@ -3454,7 +3023,7 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.next_slot(); if let Some(element) = ¤t_element { - if GritDoubleValue::can_cast(element.kind()) { + if GritDoubleLiteral::can_cast(element.kind()) { slots.mark_present(); current_element = elements.next(); } diff --git a/crates/biome_grit_parser/src/lexer/mod.rs b/crates/biome_grit_parser/src/lexer/mod.rs index 2f61d305522..d336c7fc4f9 100644 --- a/crates/biome_grit_parser/src/lexer/mod.rs +++ b/crates/biome_grit_parser/src/lexer/mod.rs @@ -282,7 +282,9 @@ impl<'src> Lexer<'src> { b'\'' | b'"' => self.lex_string_literal(current), b'`' => self.lex_backtick_snippet(), b'/' => self.lex_slash(), + b'=' => self.eat_equals_or_rewrite(), b':' => self.eat_byte(T![:]), + b';' => self.eat_byte(T![;]), b',' => self.eat_byte(T![,]), b'[' => self.eat_byte(T!['[']), b']' => self.eat_byte(T![']']), @@ -298,6 +300,23 @@ impl<'src> Lexer<'src> { } } + fn eat_equals_or_rewrite(&mut self) -> GritSyntaxKind { + assert_eq!(self.current_byte(), Some(b'=')); + self.advance(1); + + match self.current_byte() { + Some(b'=') => { + self.advance(1); + T![==] + } + Some(b'>') => { + self.advance(1); + T![=>] + } + _ => T![=], + } + } + #[inline] fn eat_unexpected_character(&mut self) -> GritSyntaxKind { self.assert_at_char_boundary(); diff --git a/crates/biome_grit_parser/src/lib.rs b/crates/biome_grit_parser/src/lib.rs index 0c0485705a5..ff1d61e8c6c 100644 --- a/crates/biome_grit_parser/src/lib.rs +++ b/crates/biome_grit_parser/src/lib.rs @@ -50,20 +50,24 @@ impl GritParse { /// /// ``` /// # use biome_grit_parser::parse_grit; - /// # use biome_grit_syntax::GritSyntaxKind; + /// # use biome_grit_syntax::{GritSyntaxKind, AnyGritLiteral, AnyGritPattern}; /// # use biome_rowan::{AstNode, AstNodeList, SyntaxError}; /// - /// # fn main() -> Result<(), SyntaxError> { + /// # fn main() { /// use biome_grit_syntax::GritSyntaxKind; - /// use biome_grit_parser::GritParserOptions; /// let parse = parse_grit(r#"`console.log($message)`"#); /// - /// // Get the root value - /// let root_value = parse.tree().value()?; - /// - /// assert_eq!(root_value.syntax().kind(), GritSyntaxKind::GRIT_ARRAY_VALUE); - /// - /// # Ok(()) + /// // Get the pattern + /// let pattern = parse.tree().pattern(); + /// match pattern { + /// Some(AnyGritPattern::AnyGritLiteral(AnyGritLiteral::GritCodeSnippet(snippet))) => { + /// assert_eq!( + /// snippet.source().unwrap().syntax().kind(), + /// GritSyntaxKind::GRIT_BACKTICK_SNIPPET_LITERAL + /// ); + /// } + /// _ => panic!("Unexpected pattern"), + /// } /// # } /// ``` pub fn syntax(&self) -> GritSyntaxNode { diff --git a/crates/biome_grit_parser/src/parser.rs b/crates/biome_grit_parser/src/parser.rs index ab3096aa147..7a2d768ad1f 100644 --- a/crates/biome_grit_parser/src/parser.rs +++ b/crates/biome_grit_parser/src/parser.rs @@ -8,6 +8,16 @@ use biome_parser::token_source::Trivia; use biome_parser::ParserContext; use biome_rowan::TextRange; +const BOOLEAN_VALUE_SET: TokenSet = token_set![TRUE_KW, FALSE_KW]; + +const SUPPORTED_LANGUAGE_SET: TokenSet = + token_set![T![js], T![json], T![css], T![grit], T![html]]; + +const SUPPORTED_LANGUAGE_FLAVOR_SET: TokenSet = token_set![T![typescript], T![jsx]]; + +const CODE_SNIPPET_SET: TokenSet = + SUPPORTED_LANGUAGE_SET.union(token_set![GRIT_BACKTICK_SNIPPET, GRIT_RAW_BACKTICK_SNIPPET]); + pub(crate) struct GritParser<'source> { context: ParserContext, source: GritTokenSource<'source>, @@ -66,7 +76,7 @@ pub(crate) fn parse_root(p: &mut GritParser) -> CompletedMarker { parse_version(p); parse_language(p); parse_definition_list(p); - //parse_pattern(p); + let _ = parse_pattern(p); parse_definition_list(p); p.eat(EOF); @@ -85,7 +95,7 @@ fn parse_version(p: &mut GritParser) -> Option { let engine_range = p.cur_range(); if p.eat(T![biome]) { if p.eat(T!['(']) { - match parse_double_value(p) { + match parse_double_literal(p) { Present(_) => { p.eat(T![')']); } @@ -107,16 +117,6 @@ fn parse_version(p: &mut GritParser) -> Option { Some(result) } -fn parse_double_value(p: &mut GritParser) -> ParsedSyntax { - if !p.at(GRIT_DOUBLE_LITERAL) { - return Absent; - } - - let m = p.start(); - p.bump(GRIT_DOUBLE_LITERAL); - Present(m.complete(p, GRIT_DOUBLE_VALUE)) -} - fn parse_language(p: &mut GritParser) -> Option { if !p.at(T![language]) { return None; @@ -125,8 +125,15 @@ fn parse_language(p: &mut GritParser) -> Option { let m = p.start(); p.bump(T![language]); - if !p.eat(GRIT_LANGUAGE_NAME) { - p.error(p.err_builder("Expected a supported language", p.cur_range())) + if p.at_ts(SUPPORTED_LANGUAGE_SET) { + let m = p.start(); + p.bump_ts(SUPPORTED_LANGUAGE_SET); + m.complete(p, GRIT_LANGUAGE_NAME); + } else { + p.error(p.err_builder( + "Expected a supported language; must be one of `js`, `json`, `css`, `html`, or `grit`", + p.cur_range(), + )) } parse_language_flavor(p); @@ -144,15 +151,35 @@ fn parse_language_flavor(p: &mut GritParser) -> Option { } let m = p.start(); - p.eat(T!['(']); + p.bump(T!['(']); - while p.eat(GRIT_LANGUAGE_FLAVOR_KIND) { - if !p.eat(T![,]) { - break; + { + let m = p.start(); + + loop { + if p.at_ts(SUPPORTED_LANGUAGE_FLAVOR_SET) { + let m = p.start(); + p.bump_ts(SUPPORTED_LANGUAGE_FLAVOR_SET); + m.complete(p, GRIT_LANGUAGE_FLAVOR_KIND); + + if !p.eat(T![,]) { + break; + } + } else if p.at(T![')']) { + break; + } else { + p.error(p.err_builder( + "Expected a supported language flavor; must be one of `typescript` or `jsx`", + p.cur_range(), + )); + break; + } } + + m.complete(p, GRIT_LANGUAGE_FLAVOR_LIST); } - p.expect(T![')']); + p.eat(T![')']); let result = m.complete(p, GRIT_LANGUAGE_FLAVOR); @@ -166,3 +193,149 @@ fn parse_definition_list(p: &mut GritParser) -> CompletedMarker { m.complete(p, GRIT_DEFINITION_LIST) } + +fn parse_pattern(p: &mut GritParser) -> ParsedSyntax { + match p.cur() { + _ => parse_literal(p), + } +} + +fn parse_literal(p: &mut GritParser) -> ParsedSyntax { + match p.cur() { + TRUE_KW | FALSE_KW => parse_boolean_literal(p), + GRIT_DOUBLE => parse_double_literal(p), + GRIT_INT => parse_int_literal(p), + GRIT_NEGATIVE_INT => parse_negative_int_literal(p), + GRIT_STRING => parse_string_literal(p), + UNDEFINED_KW => parse_undefined_literal(p), + kind if CODE_SNIPPET_SET.contains(kind) => parse_code_snippet(p), + // TODO: List + // TODO: Map + _ => Absent, + } +} + +#[inline] +fn parse_backtick_snippet_literal(p: &mut GritParser) -> ParsedSyntax { + if !p.at(GRIT_BACKTICK_SNIPPET) { + return Absent; + } + + let m = p.start(); + p.bump(GRIT_BACKTICK_SNIPPET); + Present(m.complete(p, GRIT_BACKTICK_SNIPPET_LITERAL)) +} + +#[inline] +fn parse_boolean_literal(p: &mut GritParser) -> ParsedSyntax { + if !p.at_ts(BOOLEAN_VALUE_SET) { + return Absent; + } + + let m = p.start(); + p.bump_ts(BOOLEAN_VALUE_SET); + Present(m.complete(p, GRIT_BOOLEAN_LITERAL)) +} + +#[inline] +fn parse_code_snippet(p: &mut GritParser) -> ParsedSyntax { + if !p.at_ts(CODE_SNIPPET_SET) { + return Absent; + } + + let m = p.start(); + + let syntax = match p.cur() { + GRIT_BACKTICK_SNIPPET => parse_backtick_snippet_literal(p), + GRIT_RAW_BACKTICK_SNIPPET => parse_raw_backtick_snippet_literal(p), + _ => parse_language_specific_snippet(p), + }; + + match syntax { + Present(_) => Present(m.complete(p, GRIT_CODE_SNIPPET)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_double_literal(p: &mut GritParser) -> ParsedSyntax { + if !p.at(GRIT_DOUBLE) { + return Absent; + } + + let m = p.start(); + p.bump(GRIT_DOUBLE); + Present(m.complete(p, GRIT_DOUBLE_LITERAL)) +} + +#[inline] +fn parse_int_literal(p: &mut GritParser) -> ParsedSyntax { + if !p.at(GRIT_INT) { + return Absent; + } + + let m = p.start(); + p.bump(GRIT_INT); + Present(m.complete(p, GRIT_INT_LITERAL)) +} + +#[inline] +fn parse_language_specific_snippet(p: &mut GritParser) -> ParsedSyntax { + if !p.at_ts(SUPPORTED_LANGUAGE_SET) { + return Absent; + } + + let m = p.start(); + + p.bump_ts(SUPPORTED_LANGUAGE_SET); + p.eat(GRIT_STRING); + + Present(m.complete(p, GRIT_LANGUAGE_SPECIFIC_SNIPPET)) +} + +#[inline] +fn parse_negative_int_literal(p: &mut GritParser) -> ParsedSyntax { + if !p.at(GRIT_NEGATIVE_INT) { + return Absent; + } + + let m = p.start(); + p.bump(GRIT_NEGATIVE_INT); + Present(m.complete(p, GRIT_NEGATIVE_INT_LITERAL)) +} + +#[inline] +fn parse_raw_backtick_snippet_literal(p: &mut GritParser) -> ParsedSyntax { + if !p.at(GRIT_RAW_BACKTICK_SNIPPET) { + return Absent; + } + + let m = p.start(); + p.bump(GRIT_RAW_BACKTICK_SNIPPET); + Present(m.complete(p, GRIT_RAW_BACKTICK_SNIPPET_LITERAL)) +} + +#[inline] +fn parse_string_literal(p: &mut GritParser) -> ParsedSyntax { + if !p.at(GRIT_STRING) { + return Absent; + } + + let m = p.start(); + p.bump(GRIT_STRING); + Present(m.complete(p, GRIT_STRING_LITERAL)) +} + +#[inline] +fn parse_undefined_literal(p: &mut GritParser) -> ParsedSyntax { + if !p.at(UNDEFINED_KW) { + return Absent; + } + + let m = p.start(); + p.bump(UNDEFINED_KW); + Present(m.complete(p, GRIT_UNDEFINED_LITERAL)) +} diff --git a/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_engine.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_engine.grit.snap index 26ca00a9d33..34985662e17 100644 --- a/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_engine.grit.snap +++ b/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_engine.grit.snap @@ -17,7 +17,7 @@ GritRoot { engine_token: ENGINE_KW@0..7 "engine" [] [Whitespace(" ")], biome_token: missing (required), l_paren_token: missing (required), - grit_double_value: missing (required), + grit_double_literal: missing (required), r_paren_token: missing (required), }, language: missing (optional), diff --git a/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_version.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_version.grit.snap index 54d2d670193..12302a196e7 100644 --- a/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_version.grit.snap +++ b/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_version.grit.snap @@ -16,7 +16,7 @@ GritRoot { engine_token: ENGINE_KW@0..7 "engine" [] [Whitespace(" ")], biome_token: BIOME_KW@7..13 "biome" [] [Whitespace(" ")], l_paren_token: L_PAREN@13..14 "(" [] [], - grit_double_value: missing (required), + grit_double_literal: missing (required), r_paren_token: missing (required), }, language: missing (optional), diff --git a/crates/biome_grit_parser/tests/grit_test_suite/err/invalid_language.grit b/crates/biome_grit_parser/tests/grit_test_suite/err/invalid_language.grit new file mode 100644 index 00000000000..88386d21e4d --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/err/invalid_language.grit @@ -0,0 +1 @@ +language non_existing; diff --git a/crates/biome_grit_parser/tests/grit_test_suite/err/invalid_language.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/err/invalid_language.grit.snap new file mode 100644 index 00000000000..eb621283757 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/err/invalid_language.grit.snap @@ -0,0 +1,59 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +language non_existing; + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: GritLanguageDeclaration { + language_token: LANGUAGE_KW@0..9 "language" [] [Whitespace(" ")], + name: missing (required), + flavor: missing (optional), + semicolon_token: missing (optional), + }, + definitions: GritDefinitionList [], + pattern: missing (optional), + definitions_continued: GritDefinitionList [], + eof_token: EOF@9..23 "non_existing;\n" [] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..23 + 0: (empty) + 1: (empty) + 2: GRIT_LANGUAGE_DECLARATION@0..9 + 0: LANGUAGE_KW@0..9 "language" [] [Whitespace(" ")] + 1: (empty) + 2: (empty) + 3: (empty) + 3: GRIT_DEFINITION_LIST@9..9 + 4: (empty) + 5: GRIT_DEFINITION_LIST@9..9 + 6: EOF@9..23 "non_existing;\n" [] [] + +``` + +## Diagnostics + +``` +invalid_language.grit:1:10 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a supported language; must be one of `js`, `json`, `css`, `html`, or `grit` + + > 1 │ language non_existing; + │ ^^^^^^^^^^^^ + 2 │ + +``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/err/language_with_invalid_flavor.grit b/crates/biome_grit_parser/tests/grit_test_suite/err/language_with_invalid_flavor.grit new file mode 100644 index 00000000000..f9104e786b1 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/err/language_with_invalid_flavor.grit @@ -0,0 +1 @@ +language js(vanilla); diff --git a/crates/biome_grit_parser/tests/grit_test_suite/err/language_with_invalid_flavor.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/err/language_with_invalid_flavor.grit.snap new file mode 100644 index 00000000000..b76271b89e8 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/err/language_with_invalid_flavor.grit.snap @@ -0,0 +1,69 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +language js(vanilla); + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: GritLanguageDeclaration { + language_token: LANGUAGE_KW@0..9 "language" [] [Whitespace(" ")], + name: GritLanguageName { + language_kind: JS_KW@9..11 "js" [] [], + }, + flavor: GritLanguageFlavor { + l_paren_token: L_PAREN@11..12 "(" [] [], + grit_language_flavor_list: GritLanguageFlavorList [], + r_paren_token: missing (required), + }, + semicolon_token: missing (optional), + }, + definitions: GritDefinitionList [], + pattern: missing (optional), + definitions_continued: GritDefinitionList [], + eof_token: EOF@12..22 "vanilla);\n" [] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..22 + 0: (empty) + 1: (empty) + 2: GRIT_LANGUAGE_DECLARATION@0..12 + 0: LANGUAGE_KW@0..9 "language" [] [Whitespace(" ")] + 1: GRIT_LANGUAGE_NAME@9..11 + 0: JS_KW@9..11 "js" [] [] + 2: GRIT_LANGUAGE_FLAVOR@11..12 + 0: L_PAREN@11..12 "(" [] [] + 1: GRIT_LANGUAGE_FLAVOR_LIST@12..12 + 2: (empty) + 3: (empty) + 3: GRIT_DEFINITION_LIST@12..12 + 4: (empty) + 5: GRIT_DEFINITION_LIST@12..12 + 6: EOF@12..22 "vanilla);\n" [] [] + +``` + +## Diagnostics + +``` +language_with_invalid_flavor.grit:1:13 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a supported language flavor; must be one of `typescript` or `jsx` + + > 1 │ language js(vanilla); + │ ^^^^^^^ + 2 │ + +``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/err/missing_version.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/err/missing_version.grit.snap index 2657439ff1d..d5563288b53 100644 --- a/crates/biome_grit_parser/tests/grit_test_suite/err/missing_version.grit.snap +++ b/crates/biome_grit_parser/tests/grit_test_suite/err/missing_version.grit.snap @@ -17,7 +17,7 @@ GritRoot { engine_token: ENGINE_KW@0..7 "engine" [] [Whitespace(" ")], biome_token: BIOME_KW@7..12 "biome" [] [], l_paren_token: missing (required), - grit_double_value: missing (required), + grit_double_literal: missing (required), r_paren_token: missing (required), }, language: missing (optional), diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/backtick_snippet.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/backtick_snippet.grit new file mode 100644 index 00000000000..d34bfa5c3d1 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/backtick_snippet.grit @@ -0,0 +1 @@ +`console.log($message)` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/backtick_snippet.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/backtick_snippet.grit.snap new file mode 100644 index 00000000000..01e3d514dd1 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/backtick_snippet.grit.snap @@ -0,0 +1,43 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +`console.log($message)` + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: missing (optional), + definitions: GritDefinitionList [], + pattern: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@0..23 "`console.log($message)`" [] [], + }, + }, + definitions_continued: GritDefinitionList [], + eof_token: EOF@23..24 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..24 + 0: (empty) + 1: (empty) + 2: (empty) + 3: GRIT_DEFINITION_LIST@0..0 + 4: GRIT_CODE_SNIPPET@0..23 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@0..23 + 0: GRIT_BACKTICK_SNIPPET@0..23 "`console.log($message)`" [] [] + 5: GRIT_DEFINITION_LIST@23..23 + 6: EOF@23..24 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/language.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/language.grit new file mode 100644 index 00000000000..fb3505b966f --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/language.grit @@ -0,0 +1 @@ +language js; diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/language.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/language.grit.snap new file mode 100644 index 00000000000..4e5f512fa46 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/language.grit.snap @@ -0,0 +1,49 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +language js; + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: GritLanguageDeclaration { + language_token: LANGUAGE_KW@0..9 "language" [] [Whitespace(" ")], + name: GritLanguageName { + language_kind: JS_KW@9..11 "js" [] [], + }, + flavor: missing (optional), + semicolon_token: SEMICOLON@11..12 ";" [] [], + }, + definitions: GritDefinitionList [], + pattern: missing (optional), + definitions_continued: GritDefinitionList [], + eof_token: EOF@12..13 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..13 + 0: (empty) + 1: (empty) + 2: GRIT_LANGUAGE_DECLARATION@0..12 + 0: LANGUAGE_KW@0..9 "language" [] [Whitespace(" ")] + 1: GRIT_LANGUAGE_NAME@9..11 + 0: JS_KW@9..11 "js" [] [] + 2: (empty) + 3: SEMICOLON@11..12 ";" [] [] + 3: GRIT_DEFINITION_LIST@12..12 + 4: (empty) + 5: GRIT_DEFINITION_LIST@12..12 + 6: EOF@12..13 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/language_with_flavor.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/language_with_flavor.grit new file mode 100644 index 00000000000..cb77a59e183 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/language_with_flavor.grit @@ -0,0 +1 @@ +language js(typescript); diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/language_with_flavor.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/language_with_flavor.grit.snap new file mode 100644 index 00000000000..c2ff293337c --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/language_with_flavor.grit.snap @@ -0,0 +1,62 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +language js(typescript); + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: GritLanguageDeclaration { + language_token: LANGUAGE_KW@0..9 "language" [] [Whitespace(" ")], + name: GritLanguageName { + language_kind: JS_KW@9..11 "js" [] [], + }, + flavor: GritLanguageFlavor { + l_paren_token: L_PAREN@11..12 "(" [] [], + grit_language_flavor_list: GritLanguageFlavorList [ + GritLanguageFlavorKind { + flavor_kind: TYPESCRIPT_KW@12..22 "typescript" [] [], + }, + ], + r_paren_token: R_PAREN@22..23 ")" [] [], + }, + semicolon_token: SEMICOLON@23..24 ";" [] [], + }, + definitions: GritDefinitionList [], + pattern: missing (optional), + definitions_continued: GritDefinitionList [], + eof_token: EOF@24..25 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..25 + 0: (empty) + 1: (empty) + 2: GRIT_LANGUAGE_DECLARATION@0..24 + 0: LANGUAGE_KW@0..9 "language" [] [Whitespace(" ")] + 1: GRIT_LANGUAGE_NAME@9..11 + 0: JS_KW@9..11 "js" [] [] + 2: GRIT_LANGUAGE_FLAVOR@11..23 + 0: L_PAREN@11..12 "(" [] [] + 1: GRIT_LANGUAGE_FLAVOR_LIST@12..22 + 0: GRIT_LANGUAGE_FLAVOR_KIND@12..22 + 0: TYPESCRIPT_KW@12..22 "typescript" [] [] + 2: R_PAREN@22..23 ")" [] [] + 3: SEMICOLON@23..24 ";" [] [] + 3: GRIT_DEFINITION_LIST@24..24 + 4: (empty) + 5: GRIT_DEFINITION_LIST@24..24 + 6: EOF@24..25 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_grit_syntax/src/generated/kind.rs b/crates/biome_grit_syntax/src/generated/kind.rs index e55ea31d2a4..5a1e93445e1 100644 --- a/crates/biome_grit_syntax/src/generated/kind.rs +++ b/crates/biome_grit_syntax/src/generated/kind.rs @@ -84,12 +84,12 @@ pub enum GritSyntaxKind { UNDEFINED_KW, LIKE_KW, RETURN_KW, - GRIT_INT_LITERAL, - GRIT_NEGATIVE_INT_LITERAL, - GRIT_DOUBLE_LITERAL, - GRIT_STRING_LITERAL, - GRIT_REGEX_LITERAL, - GRIT_SNIPPET_REGEX_LITERAL, + GRIT_INT, + GRIT_NEGATIVE_INT, + GRIT_DOUBLE, + GRIT_STRING, + GRIT_REGEX, + GRIT_SNIPPET_REGEX, NEWLINE, WHITESPACE, COMMENT, @@ -100,13 +100,8 @@ pub enum GritSyntaxKind { GRIT_RAW_BACKTICK_SNIPPET, GRIT_NAME, GRIT_VARIABLE, - ANY_GRIT_CONTAINER, - ANY_GRIT_DEFINITION, - ANY_GRIT_LIST_PATTERN, - ANY_GRIT_LITERAL, - ANY_GRIT_NAMED_ARG, - ANY_GRIT_PATTERN, - ANY_GRIT_PREDICATE, + BRACKETED_GRIT_PATTERN, + BRACKETED_GRIT_PREDICATE, CURLY_GRIT_PATTERN, GRIT_ROOT, GRIT_SEQUENTIAL, @@ -197,22 +192,23 @@ pub enum GritSyntaxKind { GRIT_PREDICATE_MATCH_SUBJECT, GRIT_PREDICATE_CALL, GRIT_PREDICATE_RETURN, - GRIT_BOOLEAN_LITERAL, GRIT_VARIABLE_LIST, GRIT_LANGUAGE_NAME, GRIT_LANGUAGE_SPECIFIC_SNIPPET, GRIT_CODE_SNIPPET, GRIT_NOT, - GRIT_BOOLEAN_VALUE, - GRIT_DOUBLE_VALUE, - GRIT_INT_VALUE, - GRIT_NEGATIVE_INT_VALUE, - GRIT_REGEX_VALUE, - GRIT_SNIPPET_REGEX_VALUE, - GRIT_STRING_VALUE, - GRIT_UNDEFINED, GRIT_UNDERSCORE, MAYBE_CURLY_GRIT_PATTERN, + GRIT_BACKTICK_SNIPPET_LITERAL, + GRIT_BOOLEAN_LITERAL, + GRIT_UNDEFINED_LITERAL, + GRIT_INT_LITERAL, + GRIT_NEGATIVE_INT_LITERAL, + GRIT_DOUBLE_LITERAL, + GRIT_STRING_LITERAL, + GRIT_RAW_BACKTICK_SNIPPET_LITERAL, + GRIT_REGEX_LITERAL, + GRIT_SNIPPET_REGEX_LITERAL, GRIT_BOGUS, GRIT_BOGUS_DEFINITION, GRIT_BOGUS_PATTERN, @@ -235,12 +231,8 @@ impl GritSyntaxKind { } pub const fn is_literal(self) -> bool { match self { - GRIT_INT_LITERAL - | GRIT_NEGATIVE_INT_LITERAL - | GRIT_DOUBLE_LITERAL - | GRIT_STRING_LITERAL - | GRIT_REGEX_LITERAL - | GRIT_SNIPPET_REGEX_LITERAL => true, + GRIT_INT | GRIT_NEGATIVE_INT | GRIT_DOUBLE | GRIT_STRING | GRIT_REGEX + | GRIT_SNIPPET_REGEX => true, _ => false, } } diff --git a/crates/biome_grit_syntax/src/generated/macros.rs b/crates/biome_grit_syntax/src/generated/macros.rs index 5a2cd3071b6..a060969fadb 100644 --- a/crates/biome_grit_syntax/src/generated/macros.rs +++ b/crates/biome_grit_syntax/src/generated/macros.rs @@ -16,12 +16,12 @@ macro_rules! map_syntax_node { ($ node : expr , $ pattern : pat => $ body : expr) => { match $node { node => match $crate::GritSyntaxNode::kind(&node) { - $crate::GritSyntaxKind::ANY_GRIT_PATTERN => { - let $pattern = unsafe { $crate::AnyGritPattern::new_unchecked(node) }; + $crate::GritSyntaxKind::BRACKETED_GRIT_PATTERN => { + let $pattern = unsafe { $crate::BracketedGritPattern::new_unchecked(node) }; $body } - $crate::GritSyntaxKind::ANY_GRIT_PREDICATE => { - let $pattern = unsafe { $crate::AnyGritPredicate::new_unchecked(node) }; + $crate::GritSyntaxKind::BRACKETED_GRIT_PREDICATE => { + let $pattern = unsafe { $crate::BracketedGritPredicate::new_unchecked(node) }; $body } $crate::GritSyntaxKind::CURLY_GRIT_PATTERN => { @@ -40,12 +40,13 @@ macro_rules! map_syntax_node { let $pattern = unsafe { $crate::GritAssignmentAsPattern::new_unchecked(node) }; $body } - $crate::GritSyntaxKind::GRIT_BACKTICK_SNIPPET => { - let $pattern = unsafe { $crate::GritBacktickSnippet::new_unchecked(node) }; + $crate::GritSyntaxKind::GRIT_BACKTICK_SNIPPET_LITERAL => { + let $pattern = + unsafe { $crate::GritBacktickSnippetLiteral::new_unchecked(node) }; $body } - $crate::GritSyntaxKind::GRIT_BOOLEAN_VALUE => { - let $pattern = unsafe { $crate::GritBooleanValue::new_unchecked(node) }; + $crate::GritSyntaxKind::GRIT_BOOLEAN_LITERAL => { + let $pattern = unsafe { $crate::GritBooleanLiteral::new_unchecked(node) }; $body } $crate::GritSyntaxKind::GRIT_BUBBLE => { @@ -76,8 +77,8 @@ macro_rules! map_syntax_node { let $pattern = unsafe { $crate::GritDotdotdot::new_unchecked(node) }; $body } - $crate::GritSyntaxKind::GRIT_DOUBLE_VALUE => { - let $pattern = unsafe { $crate::GritDoubleValue::new_unchecked(node) }; + $crate::GritSyntaxKind::GRIT_DOUBLE_LITERAL => { + let $pattern = unsafe { $crate::GritDoubleLiteral::new_unchecked(node) }; $body } $crate::GritSyntaxKind::GRIT_EVERY => { @@ -92,8 +93,8 @@ macro_rules! map_syntax_node { let $pattern = unsafe { $crate::GritFunctionDefinition::new_unchecked(node) }; $body } - $crate::GritSyntaxKind::GRIT_INT_VALUE => { - let $pattern = unsafe { $crate::GritIntValue::new_unchecked(node) }; + $crate::GritSyntaxKind::GRIT_INT_LITERAL => { + let $pattern = unsafe { $crate::GritIntLiteral::new_unchecked(node) }; $body } $crate::GritSyntaxKind::GRIT_LANGUAGE_DECLARATION => { @@ -165,8 +166,8 @@ macro_rules! map_syntax_node { let $pattern = unsafe { $crate::GritNamedArgWithDefault::new_unchecked(node) }; $body } - $crate::GritSyntaxKind::GRIT_NEGATIVE_INT_VALUE => { - let $pattern = unsafe { $crate::GritNegativeIntValue::new_unchecked(node) }; + $crate::GritSyntaxKind::GRIT_NEGATIVE_INT_LITERAL => { + let $pattern = unsafe { $crate::GritNegativeIntLiteral::new_unchecked(node) }; $body } $crate::GritSyntaxKind::GRIT_NODE_LIKE => { @@ -340,8 +341,13 @@ macro_rules! map_syntax_node { let $pattern = unsafe { $crate::GritPredicateRewrite::new_unchecked(node) }; $body } - $crate::GritSyntaxKind::GRIT_RAW_BACKTICK_SNIPPET => { - let $pattern = unsafe { $crate::GritRawBacktickSnippet::new_unchecked(node) }; + $crate::GritSyntaxKind::GRIT_RAW_BACKTICK_SNIPPET_LITERAL => { + let $pattern = + unsafe { $crate::GritRawBacktickSnippetLiteral::new_unchecked(node) }; + $body + } + $crate::GritSyntaxKind::GRIT_REGEX_LITERAL => { + let $pattern = unsafe { $crate::GritRegexLiteral::new_unchecked(node) }; $body } $crate::GritSyntaxKind::GRIT_REGEX_PATTERN => { @@ -353,10 +359,6 @@ macro_rules! map_syntax_node { unsafe { $crate::GritRegexPatternVariables::new_unchecked(node) }; $body } - $crate::GritSyntaxKind::GRIT_REGEX_VALUE => { - let $pattern = unsafe { $crate::GritRegexValue::new_unchecked(node) }; - $body - } $crate::GritSyntaxKind::GRIT_REWRITE => { let $pattern = unsafe { $crate::GritRewrite::new_unchecked(node) }; $body @@ -369,24 +371,24 @@ macro_rules! map_syntax_node { let $pattern = unsafe { $crate::GritSequential::new_unchecked(node) }; $body } - $crate::GritSyntaxKind::GRIT_SNIPPET_REGEX_VALUE => { - let $pattern = unsafe { $crate::GritSnippetRegexValue::new_unchecked(node) }; + $crate::GritSyntaxKind::GRIT_SNIPPET_REGEX_LITERAL => { + let $pattern = unsafe { $crate::GritSnippetRegexLiteral::new_unchecked(node) }; $body } $crate::GritSyntaxKind::GRIT_SOME => { let $pattern = unsafe { $crate::GritSome::new_unchecked(node) }; $body } - $crate::GritSyntaxKind::GRIT_STRING_VALUE => { - let $pattern = unsafe { $crate::GritStringValue::new_unchecked(node) }; + $crate::GritSyntaxKind::GRIT_STRING_LITERAL => { + let $pattern = unsafe { $crate::GritStringLiteral::new_unchecked(node) }; $body } $crate::GritSyntaxKind::GRIT_SUB_OPERATION => { let $pattern = unsafe { $crate::GritSubOperation::new_unchecked(node) }; $body } - $crate::GritSyntaxKind::GRIT_UNDEFINED => { - let $pattern = unsafe { $crate::GritUndefined::new_unchecked(node) }; + $crate::GritSyntaxKind::GRIT_UNDEFINED_LITERAL => { + let $pattern = unsafe { $crate::GritUndefinedLiteral::new_unchecked(node) }; $body } $crate::GritSyntaxKind::GRIT_UNDERSCORE => { diff --git a/crates/biome_grit_syntax/src/generated/nodes.rs b/crates/biome_grit_syntax/src/generated/nodes.rs index 4b5b6073267..d02ee6c3fac 100644 --- a/crates/biome_grit_syntax/src/generated/nodes.rs +++ b/crates/biome_grit_syntax/src/generated/nodes.rs @@ -25,10 +25,10 @@ use std::fmt::{Debug, Formatter}; #[allow(dead_code)] pub(crate) const SLOT_MAP_EMPTY_VALUE: u8 = u8::MAX; #[derive(Clone, PartialEq, Eq, Hash)] -pub struct AnyGritPattern { +pub struct BracketedGritPattern { pub(crate) syntax: SyntaxNode, } -impl AnyGritPattern { +impl BracketedGritPattern { #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] #[doc = r""] #[doc = r" # Safety"] @@ -38,177 +38,25 @@ impl AnyGritPattern { pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { Self { syntax } } - pub fn as_fields(&self) -> AnyGritPatternFields { - AnyGritPatternFields { - any_grit_literal: self.any_grit_literal(), - grit_pattern_not: self.grit_pattern_not(), - grit_pattern_or: self.grit_pattern_or(), - grit_pattern_or_else: self.grit_pattern_or_else(), - grit_pattern_any: self.grit_pattern_any(), - grit_pattern_and: self.grit_pattern_and(), - grit_pattern_maybe: self.grit_pattern_maybe(), - grit_pattern_if_else: self.grit_pattern_if_else(), - grit_pattern_contains: self.grit_pattern_contains(), - grit_pattern_includes: self.grit_pattern_includes(), - grit_pattern_after: self.grit_pattern_after(), - grit_pattern_before: self.grit_pattern_before(), - grit_within: self.grit_within(), - grit_bubble: self.grit_bubble(), - grit_node_like: self.grit_node_like(), - grit_map_accessor: self.grit_map_accessor(), - grit_list_accessor: self.grit_list_accessor(), - grit_dot: self.grit_dot(), - grit_some: self.grit_some(), - grit_every: self.grit_every(), - grit_underscore: self.grit_underscore(), - grit_variable: self.grit_variable(), - grit_regex_pattern: self.grit_regex_pattern(), - grit_pattern_as: self.grit_pattern_as(), - grit_pattern_limit: self.grit_pattern_limit(), - grit_assignment_as_pattern: self.grit_assignment_as_pattern(), - grit_pattern_accumulate: self.grit_pattern_accumulate(), - grit_rewrite: self.grit_rewrite(), - grit_like: self.grit_like(), - grit_pattern_where: self.grit_pattern_where(), - grit_mul_operation: self.grit_mul_operation(), - grit_div_operation: self.grit_div_operation(), - grit_mod_operation: self.grit_mod_operation(), - grit_add_operation: self.grit_add_operation(), - grit_sub_operation: self.grit_sub_operation(), - grit_sequential: self.grit_sequential(), - grit_files: self.grit_files(), + pub fn as_fields(&self) -> BracketedGritPatternFields { + BracketedGritPatternFields { l_paren_token: self.l_paren_token(), any_grit_pattern: self.any_grit_pattern(), r_paren_token: self.r_paren_token(), - grit_bogus_pattern: self.grit_bogus_pattern(), } } - pub fn any_grit_literal(&self) -> SyntaxResult { - support::required_node(&self.syntax, 0usize) - } - pub fn grit_pattern_not(&self) -> SyntaxResult { - support::required_node(&self.syntax, 1usize) - } - pub fn grit_pattern_or(&self) -> SyntaxResult { - support::required_node(&self.syntax, 2usize) - } - pub fn grit_pattern_or_else(&self) -> SyntaxResult { - support::required_node(&self.syntax, 3usize) - } - pub fn grit_pattern_any(&self) -> SyntaxResult { - support::required_node(&self.syntax, 4usize) - } - pub fn grit_pattern_and(&self) -> SyntaxResult { - support::required_node(&self.syntax, 5usize) - } - pub fn grit_pattern_maybe(&self) -> SyntaxResult { - support::required_node(&self.syntax, 6usize) - } - pub fn grit_pattern_if_else(&self) -> SyntaxResult { - support::required_node(&self.syntax, 7usize) - } - pub fn grit_pattern_contains(&self) -> SyntaxResult { - support::required_node(&self.syntax, 8usize) - } - pub fn grit_pattern_includes(&self) -> SyntaxResult { - support::required_node(&self.syntax, 9usize) - } - pub fn grit_pattern_after(&self) -> SyntaxResult { - support::required_node(&self.syntax, 10usize) - } - pub fn grit_pattern_before(&self) -> SyntaxResult { - support::required_node(&self.syntax, 11usize) - } - pub fn grit_within(&self) -> SyntaxResult { - support::required_node(&self.syntax, 12usize) - } - pub fn grit_bubble(&self) -> SyntaxResult { - support::required_node(&self.syntax, 13usize) - } - pub fn grit_node_like(&self) -> SyntaxResult { - support::required_node(&self.syntax, 14usize) - } - pub fn grit_map_accessor(&self) -> SyntaxResult { - support::required_node(&self.syntax, 15usize) - } - pub fn grit_list_accessor(&self) -> SyntaxResult { - support::required_node(&self.syntax, 16usize) - } - pub fn grit_dot(&self) -> SyntaxResult { - support::required_node(&self.syntax, 17usize) - } - pub fn grit_some(&self) -> SyntaxResult { - support::required_node(&self.syntax, 18usize) - } - pub fn grit_every(&self) -> SyntaxResult { - support::required_node(&self.syntax, 19usize) - } - pub fn grit_underscore(&self) -> SyntaxResult { - support::required_node(&self.syntax, 20usize) - } - pub fn grit_variable(&self) -> SyntaxResult { - support::required_node(&self.syntax, 21usize) - } - pub fn grit_regex_pattern(&self) -> SyntaxResult { - support::required_node(&self.syntax, 22usize) - } - pub fn grit_pattern_as(&self) -> SyntaxResult { - support::required_node(&self.syntax, 23usize) - } - pub fn grit_pattern_limit(&self) -> SyntaxResult { - support::required_node(&self.syntax, 24usize) - } - pub fn grit_assignment_as_pattern(&self) -> SyntaxResult { - support::required_node(&self.syntax, 25usize) - } - pub fn grit_pattern_accumulate(&self) -> SyntaxResult { - support::required_node(&self.syntax, 26usize) - } - pub fn grit_rewrite(&self) -> SyntaxResult { - support::required_node(&self.syntax, 27usize) - } - pub fn grit_like(&self) -> SyntaxResult { - support::required_node(&self.syntax, 28usize) - } - pub fn grit_pattern_where(&self) -> SyntaxResult { - support::required_node(&self.syntax, 29usize) - } - pub fn grit_mul_operation(&self) -> SyntaxResult { - support::required_node(&self.syntax, 30usize) - } - pub fn grit_div_operation(&self) -> SyntaxResult { - support::required_node(&self.syntax, 31usize) - } - pub fn grit_mod_operation(&self) -> SyntaxResult { - support::required_node(&self.syntax, 32usize) - } - pub fn grit_add_operation(&self) -> SyntaxResult { - support::required_node(&self.syntax, 33usize) - } - pub fn grit_sub_operation(&self) -> SyntaxResult { - support::required_node(&self.syntax, 34usize) - } - pub fn grit_sequential(&self) -> SyntaxResult { - support::required_node(&self.syntax, 35usize) - } - pub fn grit_files(&self) -> SyntaxResult { - support::required_node(&self.syntax, 36usize) - } pub fn l_paren_token(&self) -> SyntaxResult { - support::required_token(&self.syntax, 37usize) + support::required_token(&self.syntax, 0usize) } pub fn any_grit_pattern(&self) -> SyntaxResult { - support::required_node(&self.syntax, 38usize) + support::required_node(&self.syntax, 1usize) } pub fn r_paren_token(&self) -> SyntaxResult { - support::required_token(&self.syntax, 39usize) - } - pub fn grit_bogus_pattern(&self) -> SyntaxResult { - support::required_node(&self.syntax, 40usize) + support::required_token(&self.syntax, 2usize) } } #[cfg(feature = "serde")] -impl Serialize for AnyGritPattern { +impl Serialize for BracketedGritPattern { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -217,54 +65,16 @@ impl Serialize for AnyGritPattern { } } #[cfg_attr(feature = "serde", derive(Serialize))] -pub struct AnyGritPatternFields { - pub any_grit_literal: SyntaxResult, - pub grit_pattern_not: SyntaxResult, - pub grit_pattern_or: SyntaxResult, - pub grit_pattern_or_else: SyntaxResult, - pub grit_pattern_any: SyntaxResult, - pub grit_pattern_and: SyntaxResult, - pub grit_pattern_maybe: SyntaxResult, - pub grit_pattern_if_else: SyntaxResult, - pub grit_pattern_contains: SyntaxResult, - pub grit_pattern_includes: SyntaxResult, - pub grit_pattern_after: SyntaxResult, - pub grit_pattern_before: SyntaxResult, - pub grit_within: SyntaxResult, - pub grit_bubble: SyntaxResult, - pub grit_node_like: SyntaxResult, - pub grit_map_accessor: SyntaxResult, - pub grit_list_accessor: SyntaxResult, - pub grit_dot: SyntaxResult, - pub grit_some: SyntaxResult, - pub grit_every: SyntaxResult, - pub grit_underscore: SyntaxResult, - pub grit_variable: SyntaxResult, - pub grit_regex_pattern: SyntaxResult, - pub grit_pattern_as: SyntaxResult, - pub grit_pattern_limit: SyntaxResult, - pub grit_assignment_as_pattern: SyntaxResult, - pub grit_pattern_accumulate: SyntaxResult, - pub grit_rewrite: SyntaxResult, - pub grit_like: SyntaxResult, - pub grit_pattern_where: SyntaxResult, - pub grit_mul_operation: SyntaxResult, - pub grit_div_operation: SyntaxResult, - pub grit_mod_operation: SyntaxResult, - pub grit_add_operation: SyntaxResult, - pub grit_sub_operation: SyntaxResult, - pub grit_sequential: SyntaxResult, - pub grit_files: SyntaxResult, +pub struct BracketedGritPatternFields { pub l_paren_token: SyntaxResult, pub any_grit_pattern: SyntaxResult, pub r_paren_token: SyntaxResult, - pub grit_bogus_pattern: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] -pub struct AnyGritPredicate { +pub struct BracketedGritPredicate { pub(crate) syntax: SyntaxNode, } -impl AnyGritPredicate { +impl BracketedGritPredicate { #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] #[doc = r""] #[doc = r" # Safety"] @@ -274,105 +84,25 @@ impl AnyGritPredicate { pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { Self { syntax } } - pub fn as_fields(&self) -> AnyGritPredicateFields { - AnyGritPredicateFields { - grit_predicate_not: self.grit_predicate_not(), - grit_predicate_maybe: self.grit_predicate_maybe(), - grit_predicate_and: self.grit_predicate_and(), - grit_predicate_or: self.grit_predicate_or(), - grit_predicate_any: self.grit_predicate_any(), - grit_predicate_if_else: self.grit_predicate_if_else(), - grit_predicate_assignment: self.grit_predicate_assignment(), - grit_predicate_accumulate: self.grit_predicate_accumulate(), - grit_predicate_rewrite: self.grit_predicate_rewrite(), - grit_predicate_greater: self.grit_predicate_greater(), - grit_predicate_less: self.grit_predicate_less(), - grit_predicate_greater_equal: self.grit_predicate_greater_equal(), - grit_predicate_less_equal: self.grit_predicate_less_equal(), - grit_predicate_not_equal: self.grit_predicate_not_equal(), - grit_predicate_equal: self.grit_predicate_equal(), - grit_predicate_match: self.grit_predicate_match(), - grit_predicate_call: self.grit_predicate_call(), + pub fn as_fields(&self) -> BracketedGritPredicateFields { + BracketedGritPredicateFields { l_paren_token: self.l_paren_token(), any_grit_predicate: self.any_grit_predicate(), r_paren_token: self.r_paren_token(), - grit_boolean_value: self.grit_boolean_value(), - grit_predicate_return: self.grit_predicate_return(), - grit_bogus_predicate: self.grit_bogus_predicate(), } } - pub fn grit_predicate_not(&self) -> SyntaxResult { - support::required_node(&self.syntax, 0usize) - } - pub fn grit_predicate_maybe(&self) -> SyntaxResult { - support::required_node(&self.syntax, 1usize) - } - pub fn grit_predicate_and(&self) -> SyntaxResult { - support::required_node(&self.syntax, 2usize) - } - pub fn grit_predicate_or(&self) -> SyntaxResult { - support::required_node(&self.syntax, 3usize) - } - pub fn grit_predicate_any(&self) -> SyntaxResult { - support::required_node(&self.syntax, 4usize) - } - pub fn grit_predicate_if_else(&self) -> SyntaxResult { - support::required_node(&self.syntax, 5usize) - } - pub fn grit_predicate_assignment(&self) -> SyntaxResult { - support::required_node(&self.syntax, 6usize) - } - pub fn grit_predicate_accumulate(&self) -> SyntaxResult { - support::required_node(&self.syntax, 7usize) - } - pub fn grit_predicate_rewrite(&self) -> SyntaxResult { - support::required_node(&self.syntax, 8usize) - } - pub fn grit_predicate_greater(&self) -> SyntaxResult { - support::required_node(&self.syntax, 9usize) - } - pub fn grit_predicate_less(&self) -> SyntaxResult { - support::required_node(&self.syntax, 10usize) - } - pub fn grit_predicate_greater_equal(&self) -> SyntaxResult { - support::required_node(&self.syntax, 11usize) - } - pub fn grit_predicate_less_equal(&self) -> SyntaxResult { - support::required_node(&self.syntax, 12usize) - } - pub fn grit_predicate_not_equal(&self) -> SyntaxResult { - support::required_node(&self.syntax, 13usize) - } - pub fn grit_predicate_equal(&self) -> SyntaxResult { - support::required_node(&self.syntax, 14usize) - } - pub fn grit_predicate_match(&self) -> SyntaxResult { - support::required_node(&self.syntax, 15usize) - } - pub fn grit_predicate_call(&self) -> SyntaxResult { - support::required_node(&self.syntax, 16usize) - } pub fn l_paren_token(&self) -> SyntaxResult { - support::required_token(&self.syntax, 17usize) + support::required_token(&self.syntax, 0usize) } pub fn any_grit_predicate(&self) -> SyntaxResult { - support::required_node(&self.syntax, 18usize) + support::required_node(&self.syntax, 1usize) } pub fn r_paren_token(&self) -> SyntaxResult { - support::required_token(&self.syntax, 19usize) - } - pub fn grit_boolean_value(&self) -> SyntaxResult { - support::required_node(&self.syntax, 20usize) - } - pub fn grit_predicate_return(&self) -> SyntaxResult { - support::required_node(&self.syntax, 21usize) - } - pub fn grit_bogus_predicate(&self) -> SyntaxResult { - support::required_node(&self.syntax, 22usize) + support::required_token(&self.syntax, 2usize) } } #[cfg(feature = "serde")] -impl Serialize for AnyGritPredicate { +impl Serialize for BracketedGritPredicate { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -381,30 +111,10 @@ impl Serialize for AnyGritPredicate { } } #[cfg_attr(feature = "serde", derive(Serialize))] -pub struct AnyGritPredicateFields { - pub grit_predicate_not: SyntaxResult, - pub grit_predicate_maybe: SyntaxResult, - pub grit_predicate_and: SyntaxResult, - pub grit_predicate_or: SyntaxResult, - pub grit_predicate_any: SyntaxResult, - pub grit_predicate_if_else: SyntaxResult, - pub grit_predicate_assignment: SyntaxResult, - pub grit_predicate_accumulate: SyntaxResult, - pub grit_predicate_rewrite: SyntaxResult, - pub grit_predicate_greater: SyntaxResult, - pub grit_predicate_less: SyntaxResult, - pub grit_predicate_greater_equal: SyntaxResult, - pub grit_predicate_less_equal: SyntaxResult, - pub grit_predicate_not_equal: SyntaxResult, - pub grit_predicate_equal: SyntaxResult, - pub grit_predicate_match: SyntaxResult, - pub grit_predicate_call: SyntaxResult, +pub struct BracketedGritPredicateFields { pub l_paren_token: SyntaxResult, pub any_grit_predicate: SyntaxResult, pub r_paren_token: SyntaxResult, - pub grit_boolean_value: SyntaxResult, - pub grit_predicate_return: SyntaxResult, - pub grit_bogus_predicate: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] pub struct CurlyGritPattern { @@ -581,10 +291,10 @@ pub struct GritAssignmentAsPatternFields { pub pattern: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] -pub struct GritBacktickSnippet { +pub struct GritBacktickSnippetLiteral { pub(crate) syntax: SyntaxNode, } -impl GritBacktickSnippet { +impl GritBacktickSnippetLiteral { #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] #[doc = r""] #[doc = r" # Safety"] @@ -594,8 +304,8 @@ impl GritBacktickSnippet { pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { Self { syntax } } - pub fn as_fields(&self) -> GritBacktickSnippetFields { - GritBacktickSnippetFields { + pub fn as_fields(&self) -> GritBacktickSnippetLiteralFields { + GritBacktickSnippetLiteralFields { value_token: self.value_token(), } } @@ -604,7 +314,7 @@ impl GritBacktickSnippet { } } #[cfg(feature = "serde")] -impl Serialize for GritBacktickSnippet { +impl Serialize for GritBacktickSnippetLiteral { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -613,14 +323,14 @@ impl Serialize for GritBacktickSnippet { } } #[cfg_attr(feature = "serde", derive(Serialize))] -pub struct GritBacktickSnippetFields { +pub struct GritBacktickSnippetLiteralFields { pub value_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] -pub struct GritBooleanValue { +pub struct GritBooleanLiteral { pub(crate) syntax: SyntaxNode, } -impl GritBooleanValue { +impl GritBooleanLiteral { #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] #[doc = r""] #[doc = r" # Safety"] @@ -630,8 +340,8 @@ impl GritBooleanValue { pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { Self { syntax } } - pub fn as_fields(&self) -> GritBooleanValueFields { - GritBooleanValueFields { + pub fn as_fields(&self) -> GritBooleanLiteralFields { + GritBooleanLiteralFields { true_token: self.true_token(), false_token: self.false_token(), } @@ -644,7 +354,7 @@ impl GritBooleanValue { } } #[cfg(feature = "serde")] -impl Serialize for GritBooleanValue { +impl Serialize for GritBooleanLiteral { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -653,7 +363,7 @@ impl Serialize for GritBooleanValue { } } #[cfg_attr(feature = "serde", derive(Serialize))] -pub struct GritBooleanValueFields { +pub struct GritBooleanLiteralFields { pub true_token: SyntaxResult, pub false_token: SyntaxResult, } @@ -955,10 +665,10 @@ pub struct GritDotdotdotFields { pub maybe_curly_grit_pattern: Option, } #[derive(Clone, PartialEq, Eq, Hash)] -pub struct GritDoubleValue { +pub struct GritDoubleLiteral { pub(crate) syntax: SyntaxNode, } -impl GritDoubleValue { +impl GritDoubleLiteral { #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] #[doc = r""] #[doc = r" # Safety"] @@ -968,8 +678,8 @@ impl GritDoubleValue { pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { Self { syntax } } - pub fn as_fields(&self) -> GritDoubleValueFields { - GritDoubleValueFields { + pub fn as_fields(&self) -> GritDoubleLiteralFields { + GritDoubleLiteralFields { value_token: self.value_token(), } } @@ -978,7 +688,7 @@ impl GritDoubleValue { } } #[cfg(feature = "serde")] -impl Serialize for GritDoubleValue { +impl Serialize for GritDoubleLiteral { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -987,7 +697,7 @@ impl Serialize for GritDoubleValue { } } #[cfg_attr(feature = "serde", derive(Serialize))] -pub struct GritDoubleValueFields { +pub struct GritDoubleLiteralFields { pub value_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] @@ -1144,10 +854,10 @@ pub struct GritFunctionDefinitionFields { pub body: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] -pub struct GritIntValue { +pub struct GritIntLiteral { pub(crate) syntax: SyntaxNode, } -impl GritIntValue { +impl GritIntLiteral { #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] #[doc = r""] #[doc = r" # Safety"] @@ -1157,8 +867,8 @@ impl GritIntValue { pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { Self { syntax } } - pub fn as_fields(&self) -> GritIntValueFields { - GritIntValueFields { + pub fn as_fields(&self) -> GritIntLiteralFields { + GritIntLiteralFields { value_token: self.value_token(), } } @@ -1167,7 +877,7 @@ impl GritIntValue { } } #[cfg(feature = "serde")] -impl Serialize for GritIntValue { +impl Serialize for GritIntLiteral { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -1176,7 +886,7 @@ impl Serialize for GritIntValue { } } #[cfg_attr(feature = "serde", derive(Serialize))] -pub struct GritIntValueFields { +pub struct GritIntLiteralFields { pub value_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] @@ -1328,28 +1038,12 @@ impl GritLanguageName { } pub fn as_fields(&self) -> GritLanguageNameFields { GritLanguageNameFields { - js_token: self.js_token(), - css_token: self.css_token(), - json_token: self.json_token(), - grit_token: self.grit_token(), - html_token: self.html_token(), + language_kind: self.language_kind(), } } - pub fn js_token(&self) -> SyntaxResult { + pub fn language_kind(&self) -> SyntaxResult { support::required_token(&self.syntax, 0usize) } - pub fn css_token(&self) -> SyntaxResult { - support::required_token(&self.syntax, 1usize) - } - pub fn json_token(&self) -> SyntaxResult { - support::required_token(&self.syntax, 2usize) - } - pub fn grit_token(&self) -> SyntaxResult { - support::required_token(&self.syntax, 3usize) - } - pub fn html_token(&self) -> SyntaxResult { - support::required_token(&self.syntax, 4usize) - } } #[cfg(feature = "serde")] impl Serialize for GritLanguageName { @@ -1362,11 +1056,7 @@ impl Serialize for GritLanguageName { } #[cfg_attr(feature = "serde", derive(Serialize))] pub struct GritLanguageNameFields { - pub js_token: SyntaxResult, - pub css_token: SyntaxResult, - pub json_token: SyntaxResult, - pub grit_token: SyntaxResult, - pub html_token: SyntaxResult, + pub language_kind: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] pub struct GritLanguageSpecificSnippet { @@ -1960,10 +1650,10 @@ pub struct GritNamedArgWithDefaultFields { pub pattern: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] -pub struct GritNegativeIntValue { +pub struct GritNegativeIntLiteral { pub(crate) syntax: SyntaxNode, } -impl GritNegativeIntValue { +impl GritNegativeIntLiteral { #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] #[doc = r""] #[doc = r" # Safety"] @@ -1973,8 +1663,8 @@ impl GritNegativeIntValue { pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { Self { syntax } } - pub fn as_fields(&self) -> GritNegativeIntValueFields { - GritNegativeIntValueFields { + pub fn as_fields(&self) -> GritNegativeIntLiteralFields { + GritNegativeIntLiteralFields { value_token: self.value_token(), } } @@ -1983,7 +1673,7 @@ impl GritNegativeIntValue { } } #[cfg(feature = "serde")] -impl Serialize for GritNegativeIntValue { +impl Serialize for GritNegativeIntLiteral { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -1992,7 +1682,7 @@ impl Serialize for GritNegativeIntValue { } } #[cfg_attr(feature = "serde", derive(Serialize))] -pub struct GritNegativeIntValueFields { +pub struct GritNegativeIntLiteralFields { pub value_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] @@ -2773,7 +2463,7 @@ impl GritPatternLimit { pub fn limit_token(&self) -> SyntaxResult { support::required_token(&self.syntax, 1usize) } - pub fn limit(&self) -> SyntaxResult { + pub fn limit(&self) -> SyntaxResult { support::required_node(&self.syntax, 2usize) } } @@ -2790,7 +2480,7 @@ impl Serialize for GritPatternLimit { pub struct GritPatternLimitFields { pub pattern: SyntaxResult, pub limit_token: SyntaxResult, - pub limit: SyntaxResult, + pub limit: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] pub struct GritPatternMaybe { @@ -3978,10 +3668,46 @@ pub struct GritPredicateRewriteFields { pub right: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] -pub struct GritRawBacktickSnippet { +pub struct GritRawBacktickSnippetLiteral { + pub(crate) syntax: SyntaxNode, +} +impl GritRawBacktickSnippetLiteral { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> GritRawBacktickSnippetLiteralFields { + GritRawBacktickSnippetLiteralFields { + value_token: self.value_token(), + } + } + pub fn value_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for GritRawBacktickSnippetLiteral { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritRawBacktickSnippetLiteralFields { + pub value_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct GritRegexLiteral { pub(crate) syntax: SyntaxNode, } -impl GritRawBacktickSnippet { +impl GritRegexLiteral { #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] #[doc = r""] #[doc = r" # Safety"] @@ -3991,8 +3717,8 @@ impl GritRawBacktickSnippet { pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { Self { syntax } } - pub fn as_fields(&self) -> GritRawBacktickSnippetFields { - GritRawBacktickSnippetFields { + pub fn as_fields(&self) -> GritRegexLiteralFields { + GritRegexLiteralFields { value_token: self.value_token(), } } @@ -4001,7 +3727,7 @@ impl GritRawBacktickSnippet { } } #[cfg(feature = "serde")] -impl Serialize for GritRawBacktickSnippet { +impl Serialize for GritRegexLiteral { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -4010,7 +3736,7 @@ impl Serialize for GritRawBacktickSnippet { } } #[cfg_attr(feature = "serde", derive(Serialize))] -pub struct GritRawBacktickSnippetFields { +pub struct GritRegexLiteralFields { pub value_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] @@ -4033,7 +3759,7 @@ impl GritRegexPattern { variables: self.variables(), } } - pub fn regex(&self) -> SyntaxResult { + pub fn regex(&self) -> SyntaxResult { support::required_node(&self.syntax, 0usize) } pub fn variables(&self) -> Option { @@ -4051,7 +3777,7 @@ impl Serialize for GritRegexPattern { } #[cfg_attr(feature = "serde", derive(Serialize))] pub struct GritRegexPatternFields { - pub regex: SyntaxResult, + pub regex: SyntaxResult, pub variables: Option, } #[derive(Clone, PartialEq, Eq, Hash)] @@ -4101,42 +3827,6 @@ pub struct GritRegexPatternVariablesFields { pub r_paren_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] -pub struct GritRegexValue { - pub(crate) syntax: SyntaxNode, -} -impl GritRegexValue { - #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] - #[doc = r""] - #[doc = r" # Safety"] - #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] - #[doc = r" or a match on [SyntaxNode::kind]"] - #[inline] - pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { - Self { syntax } - } - pub fn as_fields(&self) -> GritRegexValueFields { - GritRegexValueFields { - value_token: self.value_token(), - } - } - pub fn value_token(&self) -> SyntaxResult { - support::required_token(&self.syntax, 0usize) - } -} -#[cfg(feature = "serde")] -impl Serialize for GritRegexValue { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - self.as_fields().serialize(serializer) - } -} -#[cfg_attr(feature = "serde", derive(Serialize))] -pub struct GritRegexValueFields { - pub value_token: SyntaxResult, -} -#[derive(Clone, PartialEq, Eq, Hash)] pub struct GritRewrite { pub(crate) syntax: SyntaxNode, } @@ -4305,10 +3995,10 @@ pub struct GritSequentialFields { pub r_curly_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] -pub struct GritSnippetRegexValue { +pub struct GritSnippetRegexLiteral { pub(crate) syntax: SyntaxNode, } -impl GritSnippetRegexValue { +impl GritSnippetRegexLiteral { #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] #[doc = r""] #[doc = r" # Safety"] @@ -4318,8 +4008,8 @@ impl GritSnippetRegexValue { pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { Self { syntax } } - pub fn as_fields(&self) -> GritSnippetRegexValueFields { - GritSnippetRegexValueFields { + pub fn as_fields(&self) -> GritSnippetRegexLiteralFields { + GritSnippetRegexLiteralFields { value_token: self.value_token(), } } @@ -4328,7 +4018,7 @@ impl GritSnippetRegexValue { } } #[cfg(feature = "serde")] -impl Serialize for GritSnippetRegexValue { +impl Serialize for GritSnippetRegexLiteral { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -4337,7 +4027,7 @@ impl Serialize for GritSnippetRegexValue { } } #[cfg_attr(feature = "serde", derive(Serialize))] -pub struct GritSnippetRegexValueFields { +pub struct GritSnippetRegexLiteralFields { pub value_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] @@ -4382,10 +4072,10 @@ pub struct GritSomeFields { pub pattern: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] -pub struct GritStringValue { +pub struct GritStringLiteral { pub(crate) syntax: SyntaxNode, } -impl GritStringValue { +impl GritStringLiteral { #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] #[doc = r""] #[doc = r" # Safety"] @@ -4395,8 +4085,8 @@ impl GritStringValue { pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { Self { syntax } } - pub fn as_fields(&self) -> GritStringValueFields { - GritStringValueFields { + pub fn as_fields(&self) -> GritStringLiteralFields { + GritStringLiteralFields { value_token: self.value_token(), } } @@ -4405,7 +4095,7 @@ impl GritStringValue { } } #[cfg(feature = "serde")] -impl Serialize for GritStringValue { +impl Serialize for GritStringLiteral { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -4414,7 +4104,7 @@ impl Serialize for GritStringValue { } } #[cfg_attr(feature = "serde", derive(Serialize))] -pub struct GritStringValueFields { +pub struct GritStringLiteralFields { pub value_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] @@ -4464,10 +4154,10 @@ pub struct GritSubOperationFields { pub right: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] -pub struct GritUndefined { +pub struct GritUndefinedLiteral { pub(crate) syntax: SyntaxNode, } -impl GritUndefined { +impl GritUndefinedLiteral { #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] #[doc = r""] #[doc = r" # Safety"] @@ -4477,8 +4167,8 @@ impl GritUndefined { pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { Self { syntax } } - pub fn as_fields(&self) -> GritUndefinedFields { - GritUndefinedFields { + pub fn as_fields(&self) -> GritUndefinedLiteralFields { + GritUndefinedLiteralFields { undefined_token: self.undefined_token(), } } @@ -4487,7 +4177,7 @@ impl GritUndefined { } } #[cfg(feature = "serde")] -impl Serialize for GritUndefined { +impl Serialize for GritUndefinedLiteral { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -4496,7 +4186,7 @@ impl Serialize for GritUndefined { } } #[cfg_attr(feature = "serde", derive(Serialize))] -pub struct GritUndefinedFields { +pub struct GritUndefinedLiteralFields { pub undefined_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] @@ -4590,7 +4280,7 @@ impl GritVersion { engine_token: self.engine_token(), biome_token: self.biome_token(), l_paren_token: self.l_paren_token(), - grit_double_value: self.grit_double_value(), + grit_double_literal: self.grit_double_literal(), r_paren_token: self.r_paren_token(), } } @@ -4603,7 +4293,7 @@ impl GritVersion { pub fn l_paren_token(&self) -> SyntaxResult { support::required_token(&self.syntax, 2usize) } - pub fn grit_double_value(&self) -> SyntaxResult { + pub fn grit_double_literal(&self) -> SyntaxResult { support::required_node(&self.syntax, 3usize) } pub fn r_paren_token(&self) -> SyntaxResult { @@ -4624,7 +4314,7 @@ pub struct GritVersionFields { pub engine_token: SyntaxResult, pub biome_token: SyntaxResult, pub l_paren_token: SyntaxResult, - pub grit_double_value: SyntaxResult, + pub grit_double_literal: SyntaxResult, pub r_paren_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] @@ -4753,14 +4443,14 @@ impl AnyGritListPattern { #[cfg_attr(feature = "serde", derive(Serialize))] pub enum AnyGritLiteral { GritBogusLiteral(GritBogusLiteral), - GritBooleanValue(GritBooleanValue), + GritBooleanLiteral(GritBooleanLiteral), GritCodeSnippet(GritCodeSnippet), - GritDoubleValue(GritDoubleValue), - GritIntValue(GritIntValue), + GritDoubleLiteral(GritDoubleLiteral), + GritIntLiteral(GritIntLiteral), GritList(GritList), GritMap(GritMap), - GritStringValue(GritStringValue), - GritUndefined(GritUndefined), + GritStringLiteral(GritStringLiteral), + GritUndefinedLiteral(GritUndefinedLiteral), } impl AnyGritLiteral { pub fn as_grit_bogus_literal(&self) -> Option<&GritBogusLiteral> { @@ -4769,9 +4459,9 @@ impl AnyGritLiteral { _ => None, } } - pub fn as_grit_boolean_value(&self) -> Option<&GritBooleanValue> { + pub fn as_grit_boolean_literal(&self) -> Option<&GritBooleanLiteral> { match &self { - AnyGritLiteral::GritBooleanValue(item) => Some(item), + AnyGritLiteral::GritBooleanLiteral(item) => Some(item), _ => None, } } @@ -4781,15 +4471,15 @@ impl AnyGritLiteral { _ => None, } } - pub fn as_grit_double_value(&self) -> Option<&GritDoubleValue> { + pub fn as_grit_double_literal(&self) -> Option<&GritDoubleLiteral> { match &self { - AnyGritLiteral::GritDoubleValue(item) => Some(item), + AnyGritLiteral::GritDoubleLiteral(item) => Some(item), _ => None, } } - pub fn as_grit_int_value(&self) -> Option<&GritIntValue> { + pub fn as_grit_int_literal(&self) -> Option<&GritIntLiteral> { match &self { - AnyGritLiteral::GritIntValue(item) => Some(item), + AnyGritLiteral::GritIntLiteral(item) => Some(item), _ => None, } } @@ -4805,15 +4495,15 @@ impl AnyGritLiteral { _ => None, } } - pub fn as_grit_string_value(&self) -> Option<&GritStringValue> { + pub fn as_grit_string_literal(&self) -> Option<&GritStringLiteral> { match &self { - AnyGritLiteral::GritStringValue(item) => Some(item), + AnyGritLiteral::GritStringLiteral(item) => Some(item), _ => None, } } - pub fn as_grit_undefined(&self) -> Option<&GritUndefined> { + pub fn as_grit_undefined_literal(&self) -> Option<&GritUndefinedLiteral> { match &self { - AnyGritLiteral::GritUndefined(item) => Some(item), + AnyGritLiteral::GritUndefinedLiteral(item) => Some(item), _ => None, } } @@ -4847,335 +4537,634 @@ impl AnyGritNamedArg { } #[derive(Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize))] -pub enum GritCodeSnippetSource { - GritBacktickSnippet(GritBacktickSnippet), - GritLanguageSpecificSnippet(GritLanguageSpecificSnippet), - GritRawBacktickSnippet(GritRawBacktickSnippet), +pub enum AnyGritPattern { + AnyGritLiteral(AnyGritLiteral), + BracketedGritPattern(BracketedGritPattern), + GritAddOperation(GritAddOperation), + GritAssignmentAsPattern(GritAssignmentAsPattern), + GritBogusPattern(GritBogusPattern), + GritBubble(GritBubble), + GritDivOperation(GritDivOperation), + GritDot(GritDot), + GritEvery(GritEvery), + GritFiles(GritFiles), + GritLike(GritLike), + GritListAccessor(GritListAccessor), + GritMapAccessor(GritMapAccessor), + GritModOperation(GritModOperation), + GritMulOperation(GritMulOperation), + GritNodeLike(GritNodeLike), + GritPatternAccumulate(GritPatternAccumulate), + GritPatternAfter(GritPatternAfter), + GritPatternAnd(GritPatternAnd), + GritPatternAny(GritPatternAny), + GritPatternAs(GritPatternAs), + GritPatternBefore(GritPatternBefore), + GritPatternContains(GritPatternContains), + GritPatternIfElse(GritPatternIfElse), + GritPatternIncludes(GritPatternIncludes), + GritPatternLimit(GritPatternLimit), + GritPatternMaybe(GritPatternMaybe), + GritPatternNot(GritPatternNot), + GritPatternOr(GritPatternOr), + GritPatternOrElse(GritPatternOrElse), + GritPatternWhere(GritPatternWhere), + GritRegexPattern(GritRegexPattern), + GritRewrite(GritRewrite), + GritSequential(GritSequential), + GritSome(GritSome), + GritSubOperation(GritSubOperation), + GritUnderscore(GritUnderscore), + GritVariable(GritVariable), + GritWithin(GritWithin), } -impl GritCodeSnippetSource { - pub fn as_grit_backtick_snippet(&self) -> Option<&GritBacktickSnippet> { +impl AnyGritPattern { + pub fn as_any_grit_literal(&self) -> Option<&AnyGritLiteral> { match &self { - GritCodeSnippetSource::GritBacktickSnippet(item) => Some(item), + AnyGritPattern::AnyGritLiteral(item) => Some(item), _ => None, } } - pub fn as_grit_language_specific_snippet(&self) -> Option<&GritLanguageSpecificSnippet> { + pub fn as_bracketed_grit_pattern(&self) -> Option<&BracketedGritPattern> { match &self { - GritCodeSnippetSource::GritLanguageSpecificSnippet(item) => Some(item), + AnyGritPattern::BracketedGritPattern(item) => Some(item), _ => None, } } - pub fn as_grit_raw_backtick_snippet(&self) -> Option<&GritRawBacktickSnippet> { + pub fn as_grit_add_operation(&self) -> Option<&GritAddOperation> { match &self { - GritCodeSnippetSource::GritRawBacktickSnippet(item) => Some(item), + AnyGritPattern::GritAddOperation(item) => Some(item), _ => None, } } -} -#[derive(Clone, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize))] -pub enum GritListAccessorSubject { - AnyGritContainer(AnyGritContainer), - GritList(GritList), -} -impl GritListAccessorSubject { - pub fn as_any_grit_container(&self) -> Option<&AnyGritContainer> { + pub fn as_grit_assignment_as_pattern(&self) -> Option<&GritAssignmentAsPattern> { match &self { - GritListAccessorSubject::AnyGritContainer(item) => Some(item), + AnyGritPattern::GritAssignmentAsPattern(item) => Some(item), _ => None, } } - pub fn as_grit_list(&self) -> Option<&GritList> { + pub fn as_grit_bogus_pattern(&self) -> Option<&GritBogusPattern> { match &self { - GritListAccessorSubject::GritList(item) => Some(item), + AnyGritPattern::GritBogusPattern(item) => Some(item), _ => None, } } -} -#[derive(Clone, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize))] -pub enum GritListIndex { - AnyGritContainer(AnyGritContainer), - GritIntValue(GritIntValue), - GritNegativeIntValue(GritNegativeIntValue), -} -impl GritListIndex { - pub fn as_any_grit_container(&self) -> Option<&AnyGritContainer> { + pub fn as_grit_bubble(&self) -> Option<&GritBubble> { match &self { - GritListIndex::AnyGritContainer(item) => Some(item), + AnyGritPattern::GritBubble(item) => Some(item), _ => None, } } - pub fn as_grit_int_value(&self) -> Option<&GritIntValue> { + pub fn as_grit_div_operation(&self) -> Option<&GritDivOperation> { match &self { - GritListIndex::GritIntValue(item) => Some(item), + AnyGritPattern::GritDivOperation(item) => Some(item), _ => None, } } - pub fn as_grit_negative_int_value(&self) -> Option<&GritNegativeIntValue> { + pub fn as_grit_dot(&self) -> Option<&GritDot> { match &self { - GritListIndex::GritNegativeIntValue(item) => Some(item), + AnyGritPattern::GritDot(item) => Some(item), _ => None, } } -} -#[derive(Clone, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize))] -pub enum GritMapAccessorSubject { - AnyGritContainer(AnyGritContainer), - GritMap(GritMap), -} -impl GritMapAccessorSubject { - pub fn as_any_grit_container(&self) -> Option<&AnyGritContainer> { + pub fn as_grit_every(&self) -> Option<&GritEvery> { match &self { - GritMapAccessorSubject::AnyGritContainer(item) => Some(item), + AnyGritPattern::GritEvery(item) => Some(item), _ => None, } } - pub fn as_grit_map(&self) -> Option<&GritMap> { + pub fn as_grit_files(&self) -> Option<&GritFiles> { match &self { - GritMapAccessorSubject::GritMap(item) => Some(item), + AnyGritPattern::GritFiles(item) => Some(item), _ => None, } } -} -#[derive(Clone, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize))] -pub enum GritMapKey { - GritName(GritName), - GritVariable(GritVariable), -} -impl GritMapKey { - pub fn as_grit_name(&self) -> Option<&GritName> { + pub fn as_grit_like(&self) -> Option<&GritLike> { match &self { - GritMapKey::GritName(item) => Some(item), + AnyGritPattern::GritLike(item) => Some(item), _ => None, } } - pub fn as_grit_variable(&self) -> Option<&GritVariable> { + pub fn as_grit_list_accessor(&self) -> Option<&GritListAccessor> { match &self { - GritMapKey::GritVariable(item) => Some(item), + AnyGritPattern::GritListAccessor(item) => Some(item), _ => None, } } -} -#[derive(Clone, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize))] -pub enum GritPredicateMatchSubject { - AnyGritContainer(AnyGritContainer), - AnyGritLiteral(AnyGritLiteral), -} -impl GritPredicateMatchSubject { - pub fn as_any_grit_container(&self) -> Option<&AnyGritContainer> { + pub fn as_grit_map_accessor(&self) -> Option<&GritMapAccessor> { match &self { - GritPredicateMatchSubject::AnyGritContainer(item) => Some(item), + AnyGritPattern::GritMapAccessor(item) => Some(item), _ => None, } } - pub fn as_any_grit_literal(&self) -> Option<&AnyGritLiteral> { + pub fn as_grit_mod_operation(&self) -> Option<&GritModOperation> { match &self { - GritPredicateMatchSubject::AnyGritLiteral(item) => Some(item), + AnyGritPattern::GritModOperation(item) => Some(item), _ => None, } } -} -#[derive(Clone, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize))] -pub enum GritRegex { - GritRegexValue(GritRegexValue), - GritSnippetRegexValue(GritSnippetRegexValue), -} -impl GritRegex { - pub fn as_grit_regex_value(&self) -> Option<&GritRegexValue> { + pub fn as_grit_mul_operation(&self) -> Option<&GritMulOperation> { match &self { - GritRegex::GritRegexValue(item) => Some(item), + AnyGritPattern::GritMulOperation(item) => Some(item), _ => None, } } - pub fn as_grit_snippet_regex_value(&self) -> Option<&GritSnippetRegexValue> { + pub fn as_grit_node_like(&self) -> Option<&GritNodeLike> { match &self { - GritRegex::GritSnippetRegexValue(item) => Some(item), + AnyGritPattern::GritNodeLike(item) => Some(item), _ => None, } } -} -#[derive(Clone, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize))] -pub enum MaybeCurlyGritPattern { - AnyGritPattern(AnyGritPattern), - CurlyGritPattern(CurlyGritPattern), -} -impl MaybeCurlyGritPattern { - pub fn as_any_grit_pattern(&self) -> Option<&AnyGritPattern> { + pub fn as_grit_pattern_accumulate(&self) -> Option<&GritPatternAccumulate> { match &self { - MaybeCurlyGritPattern::AnyGritPattern(item) => Some(item), + AnyGritPattern::GritPatternAccumulate(item) => Some(item), _ => None, } } - pub fn as_curly_grit_pattern(&self) -> Option<&CurlyGritPattern> { + pub fn as_grit_pattern_after(&self) -> Option<&GritPatternAfter> { match &self { - MaybeCurlyGritPattern::CurlyGritPattern(item) => Some(item), + AnyGritPattern::GritPatternAfter(item) => Some(item), _ => None, } } -} -impl AstNode for AnyGritPattern { - type Language = Language; - const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(ANY_GRIT_PATTERN as u16)); - fn can_cast(kind: SyntaxKind) -> bool { - kind == ANY_GRIT_PATTERN + pub fn as_grit_pattern_and(&self) -> Option<&GritPatternAnd> { + match &self { + AnyGritPattern::GritPatternAnd(item) => Some(item), + _ => None, + } } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None + pub fn as_grit_pattern_any(&self) -> Option<&GritPatternAny> { + match &self { + AnyGritPattern::GritPatternAny(item) => Some(item), + _ => None, } } - fn syntax(&self) -> &SyntaxNode { - &self.syntax + pub fn as_grit_pattern_as(&self) -> Option<&GritPatternAs> { + match &self { + AnyGritPattern::GritPatternAs(item) => Some(item), + _ => None, + } } - fn into_syntax(self) -> SyntaxNode { - self.syntax + pub fn as_grit_pattern_before(&self) -> Option<&GritPatternBefore> { + match &self { + AnyGritPattern::GritPatternBefore(item) => Some(item), + _ => None, + } + } + pub fn as_grit_pattern_contains(&self) -> Option<&GritPatternContains> { + match &self { + AnyGritPattern::GritPatternContains(item) => Some(item), + _ => None, + } + } + pub fn as_grit_pattern_if_else(&self) -> Option<&GritPatternIfElse> { + match &self { + AnyGritPattern::GritPatternIfElse(item) => Some(item), + _ => None, + } + } + pub fn as_grit_pattern_includes(&self) -> Option<&GritPatternIncludes> { + match &self { + AnyGritPattern::GritPatternIncludes(item) => Some(item), + _ => None, + } + } + pub fn as_grit_pattern_limit(&self) -> Option<&GritPatternLimit> { + match &self { + AnyGritPattern::GritPatternLimit(item) => Some(item), + _ => None, + } + } + pub fn as_grit_pattern_maybe(&self) -> Option<&GritPatternMaybe> { + match &self { + AnyGritPattern::GritPatternMaybe(item) => Some(item), + _ => None, + } + } + pub fn as_grit_pattern_not(&self) -> Option<&GritPatternNot> { + match &self { + AnyGritPattern::GritPatternNot(item) => Some(item), + _ => None, + } + } + pub fn as_grit_pattern_or(&self) -> Option<&GritPatternOr> { + match &self { + AnyGritPattern::GritPatternOr(item) => Some(item), + _ => None, + } + } + pub fn as_grit_pattern_or_else(&self) -> Option<&GritPatternOrElse> { + match &self { + AnyGritPattern::GritPatternOrElse(item) => Some(item), + _ => None, + } + } + pub fn as_grit_pattern_where(&self) -> Option<&GritPatternWhere> { + match &self { + AnyGritPattern::GritPatternWhere(item) => Some(item), + _ => None, + } + } + pub fn as_grit_regex_pattern(&self) -> Option<&GritRegexPattern> { + match &self { + AnyGritPattern::GritRegexPattern(item) => Some(item), + _ => None, + } + } + pub fn as_grit_rewrite(&self) -> Option<&GritRewrite> { + match &self { + AnyGritPattern::GritRewrite(item) => Some(item), + _ => None, + } + } + pub fn as_grit_sequential(&self) -> Option<&GritSequential> { + match &self { + AnyGritPattern::GritSequential(item) => Some(item), + _ => None, + } + } + pub fn as_grit_some(&self) -> Option<&GritSome> { + match &self { + AnyGritPattern::GritSome(item) => Some(item), + _ => None, + } + } + pub fn as_grit_sub_operation(&self) -> Option<&GritSubOperation> { + match &self { + AnyGritPattern::GritSubOperation(item) => Some(item), + _ => None, + } + } + pub fn as_grit_underscore(&self) -> Option<&GritUnderscore> { + match &self { + AnyGritPattern::GritUnderscore(item) => Some(item), + _ => None, + } + } + pub fn as_grit_variable(&self) -> Option<&GritVariable> { + match &self { + AnyGritPattern::GritVariable(item) => Some(item), + _ => None, + } + } + pub fn as_grit_within(&self) -> Option<&GritWithin> { + match &self { + AnyGritPattern::GritWithin(item) => Some(item), + _ => None, + } + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub enum AnyGritPredicate { + BracketedGritPredicate(BracketedGritPredicate), + GritBogusPredicate(GritBogusPredicate), + GritBooleanLiteral(GritBooleanLiteral), + GritPredicateAccumulate(GritPredicateAccumulate), + GritPredicateAnd(GritPredicateAnd), + GritPredicateAny(GritPredicateAny), + GritPredicateAssignment(GritPredicateAssignment), + GritPredicateCall(GritPredicateCall), + GritPredicateEqual(GritPredicateEqual), + GritPredicateGreater(GritPredicateGreater), + GritPredicateGreaterEqual(GritPredicateGreaterEqual), + GritPredicateIfElse(GritPredicateIfElse), + GritPredicateLess(GritPredicateLess), + GritPredicateLessEqual(GritPredicateLessEqual), + GritPredicateMatch(GritPredicateMatch), + GritPredicateMaybe(GritPredicateMaybe), + GritPredicateNot(GritPredicateNot), + GritPredicateNotEqual(GritPredicateNotEqual), + GritPredicateOr(GritPredicateOr), + GritPredicateReturn(GritPredicateReturn), + GritPredicateRewrite(GritPredicateRewrite), +} +impl AnyGritPredicate { + pub fn as_bracketed_grit_predicate(&self) -> Option<&BracketedGritPredicate> { + match &self { + AnyGritPredicate::BracketedGritPredicate(item) => Some(item), + _ => None, + } + } + pub fn as_grit_bogus_predicate(&self) -> Option<&GritBogusPredicate> { + match &self { + AnyGritPredicate::GritBogusPredicate(item) => Some(item), + _ => None, + } + } + pub fn as_grit_boolean_literal(&self) -> Option<&GritBooleanLiteral> { + match &self { + AnyGritPredicate::GritBooleanLiteral(item) => Some(item), + _ => None, + } + } + pub fn as_grit_predicate_accumulate(&self) -> Option<&GritPredicateAccumulate> { + match &self { + AnyGritPredicate::GritPredicateAccumulate(item) => Some(item), + _ => None, + } + } + pub fn as_grit_predicate_and(&self) -> Option<&GritPredicateAnd> { + match &self { + AnyGritPredicate::GritPredicateAnd(item) => Some(item), + _ => None, + } + } + pub fn as_grit_predicate_any(&self) -> Option<&GritPredicateAny> { + match &self { + AnyGritPredicate::GritPredicateAny(item) => Some(item), + _ => None, + } + } + pub fn as_grit_predicate_assignment(&self) -> Option<&GritPredicateAssignment> { + match &self { + AnyGritPredicate::GritPredicateAssignment(item) => Some(item), + _ => None, + } + } + pub fn as_grit_predicate_call(&self) -> Option<&GritPredicateCall> { + match &self { + AnyGritPredicate::GritPredicateCall(item) => Some(item), + _ => None, + } + } + pub fn as_grit_predicate_equal(&self) -> Option<&GritPredicateEqual> { + match &self { + AnyGritPredicate::GritPredicateEqual(item) => Some(item), + _ => None, + } + } + pub fn as_grit_predicate_greater(&self) -> Option<&GritPredicateGreater> { + match &self { + AnyGritPredicate::GritPredicateGreater(item) => Some(item), + _ => None, + } + } + pub fn as_grit_predicate_greater_equal(&self) -> Option<&GritPredicateGreaterEqual> { + match &self { + AnyGritPredicate::GritPredicateGreaterEqual(item) => Some(item), + _ => None, + } + } + pub fn as_grit_predicate_if_else(&self) -> Option<&GritPredicateIfElse> { + match &self { + AnyGritPredicate::GritPredicateIfElse(item) => Some(item), + _ => None, + } + } + pub fn as_grit_predicate_less(&self) -> Option<&GritPredicateLess> { + match &self { + AnyGritPredicate::GritPredicateLess(item) => Some(item), + _ => None, + } + } + pub fn as_grit_predicate_less_equal(&self) -> Option<&GritPredicateLessEqual> { + match &self { + AnyGritPredicate::GritPredicateLessEqual(item) => Some(item), + _ => None, + } + } + pub fn as_grit_predicate_match(&self) -> Option<&GritPredicateMatch> { + match &self { + AnyGritPredicate::GritPredicateMatch(item) => Some(item), + _ => None, + } + } + pub fn as_grit_predicate_maybe(&self) -> Option<&GritPredicateMaybe> { + match &self { + AnyGritPredicate::GritPredicateMaybe(item) => Some(item), + _ => None, + } + } + pub fn as_grit_predicate_not(&self) -> Option<&GritPredicateNot> { + match &self { + AnyGritPredicate::GritPredicateNot(item) => Some(item), + _ => None, + } + } + pub fn as_grit_predicate_not_equal(&self) -> Option<&GritPredicateNotEqual> { + match &self { + AnyGritPredicate::GritPredicateNotEqual(item) => Some(item), + _ => None, + } + } + pub fn as_grit_predicate_or(&self) -> Option<&GritPredicateOr> { + match &self { + AnyGritPredicate::GritPredicateOr(item) => Some(item), + _ => None, + } + } + pub fn as_grit_predicate_return(&self) -> Option<&GritPredicateReturn> { + match &self { + AnyGritPredicate::GritPredicateReturn(item) => Some(item), + _ => None, + } + } + pub fn as_grit_predicate_rewrite(&self) -> Option<&GritPredicateRewrite> { + match &self { + AnyGritPredicate::GritPredicateRewrite(item) => Some(item), + _ => None, + } + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub enum AnyGritRegex { + GritRegexLiteral(GritRegexLiteral), + GritSnippetRegexLiteral(GritSnippetRegexLiteral), +} +impl AnyGritRegex { + pub fn as_grit_regex_literal(&self) -> Option<&GritRegexLiteral> { + match &self { + AnyGritRegex::GritRegexLiteral(item) => Some(item), + _ => None, + } + } + pub fn as_grit_snippet_regex_literal(&self) -> Option<&GritSnippetRegexLiteral> { + match &self { + AnyGritRegex::GritSnippetRegexLiteral(item) => Some(item), + _ => None, + } + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub enum GritCodeSnippetSource { + GritBacktickSnippetLiteral(GritBacktickSnippetLiteral), + GritLanguageSpecificSnippet(GritLanguageSpecificSnippet), + GritRawBacktickSnippetLiteral(GritRawBacktickSnippetLiteral), +} +impl GritCodeSnippetSource { + pub fn as_grit_backtick_snippet_literal(&self) -> Option<&GritBacktickSnippetLiteral> { + match &self { + GritCodeSnippetSource::GritBacktickSnippetLiteral(item) => Some(item), + _ => None, + } + } + pub fn as_grit_language_specific_snippet(&self) -> Option<&GritLanguageSpecificSnippet> { + match &self { + GritCodeSnippetSource::GritLanguageSpecificSnippet(item) => Some(item), + _ => None, + } + } + pub fn as_grit_raw_backtick_snippet_literal(&self) -> Option<&GritRawBacktickSnippetLiteral> { + match &self { + GritCodeSnippetSource::GritRawBacktickSnippetLiteral(item) => Some(item), + _ => None, + } + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub enum GritListAccessorSubject { + AnyGritContainer(AnyGritContainer), + GritList(GritList), +} +impl GritListAccessorSubject { + pub fn as_any_grit_container(&self) -> Option<&AnyGritContainer> { + match &self { + GritListAccessorSubject::AnyGritContainer(item) => Some(item), + _ => None, + } + } + pub fn as_grit_list(&self) -> Option<&GritList> { + match &self { + GritListAccessorSubject::GritList(item) => Some(item), + _ => None, + } + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub enum GritListIndex { + AnyGritContainer(AnyGritContainer), + GritIntLiteral(GritIntLiteral), + GritNegativeIntLiteral(GritNegativeIntLiteral), +} +impl GritListIndex { + pub fn as_any_grit_container(&self) -> Option<&AnyGritContainer> { + match &self { + GritListIndex::AnyGritContainer(item) => Some(item), + _ => None, + } + } + pub fn as_grit_int_literal(&self) -> Option<&GritIntLiteral> { + match &self { + GritListIndex::GritIntLiteral(item) => Some(item), + _ => None, + } + } + pub fn as_grit_negative_int_literal(&self) -> Option<&GritNegativeIntLiteral> { + match &self { + GritListIndex::GritNegativeIntLiteral(item) => Some(item), + _ => None, + } + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub enum GritMapAccessorSubject { + AnyGritContainer(AnyGritContainer), + GritMap(GritMap), +} +impl GritMapAccessorSubject { + pub fn as_any_grit_container(&self) -> Option<&AnyGritContainer> { + match &self { + GritMapAccessorSubject::AnyGritContainer(item) => Some(item), + _ => None, + } + } + pub fn as_grit_map(&self) -> Option<&GritMap> { + match &self { + GritMapAccessorSubject::GritMap(item) => Some(item), + _ => None, + } + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub enum GritMapKey { + GritName(GritName), + GritVariable(GritVariable), +} +impl GritMapKey { + pub fn as_grit_name(&self) -> Option<&GritName> { + match &self { + GritMapKey::GritName(item) => Some(item), + _ => None, + } + } + pub fn as_grit_variable(&self) -> Option<&GritVariable> { + match &self { + GritMapKey::GritVariable(item) => Some(item), + _ => None, + } } } -impl std::fmt::Debug for AnyGritPattern { +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub enum GritPredicateMatchSubject { + AnyGritContainer(AnyGritContainer), + AnyGritLiteral(AnyGritLiteral), +} +impl GritPredicateMatchSubject { + pub fn as_any_grit_container(&self) -> Option<&AnyGritContainer> { + match &self { + GritPredicateMatchSubject::AnyGritContainer(item) => Some(item), + _ => None, + } + } + pub fn as_any_grit_literal(&self) -> Option<&AnyGritLiteral> { + match &self { + GritPredicateMatchSubject::AnyGritLiteral(item) => Some(item), + _ => None, + } + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub enum MaybeCurlyGritPattern { + AnyGritPattern(AnyGritPattern), + CurlyGritPattern(CurlyGritPattern), +} +impl MaybeCurlyGritPattern { + pub fn as_any_grit_pattern(&self) -> Option<&AnyGritPattern> { + match &self { + MaybeCurlyGritPattern::AnyGritPattern(item) => Some(item), + _ => None, + } + } + pub fn as_curly_grit_pattern(&self) -> Option<&CurlyGritPattern> { + match &self { + MaybeCurlyGritPattern::CurlyGritPattern(item) => Some(item), + _ => None, + } + } +} +impl AstNode for BracketedGritPattern { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(BRACKETED_GRIT_PATTERN as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == BRACKETED_GRIT_PATTERN + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for BracketedGritPattern { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("AnyGritPattern") - .field( - "any_grit_literal", - &support::DebugSyntaxResult(self.any_grit_literal()), - ) - .field( - "grit_pattern_not", - &support::DebugSyntaxResult(self.grit_pattern_not()), - ) - .field( - "grit_pattern_or", - &support::DebugSyntaxResult(self.grit_pattern_or()), - ) - .field( - "grit_pattern_or_else", - &support::DebugSyntaxResult(self.grit_pattern_or_else()), - ) - .field( - "grit_pattern_any", - &support::DebugSyntaxResult(self.grit_pattern_any()), - ) - .field( - "grit_pattern_and", - &support::DebugSyntaxResult(self.grit_pattern_and()), - ) - .field( - "grit_pattern_maybe", - &support::DebugSyntaxResult(self.grit_pattern_maybe()), - ) - .field( - "grit_pattern_if_else", - &support::DebugSyntaxResult(self.grit_pattern_if_else()), - ) - .field( - "grit_pattern_contains", - &support::DebugSyntaxResult(self.grit_pattern_contains()), - ) - .field( - "grit_pattern_includes", - &support::DebugSyntaxResult(self.grit_pattern_includes()), - ) - .field( - "grit_pattern_after", - &support::DebugSyntaxResult(self.grit_pattern_after()), - ) - .field( - "grit_pattern_before", - &support::DebugSyntaxResult(self.grit_pattern_before()), - ) - .field( - "grit_within", - &support::DebugSyntaxResult(self.grit_within()), - ) - .field( - "grit_bubble", - &support::DebugSyntaxResult(self.grit_bubble()), - ) - .field( - "grit_node_like", - &support::DebugSyntaxResult(self.grit_node_like()), - ) - .field( - "grit_map_accessor", - &support::DebugSyntaxResult(self.grit_map_accessor()), - ) - .field( - "grit_list_accessor", - &support::DebugSyntaxResult(self.grit_list_accessor()), - ) - .field("grit_dot", &support::DebugSyntaxResult(self.grit_dot())) - .field("grit_some", &support::DebugSyntaxResult(self.grit_some())) - .field("grit_every", &support::DebugSyntaxResult(self.grit_every())) - .field( - "grit_underscore", - &support::DebugSyntaxResult(self.grit_underscore()), - ) - .field( - "grit_variable", - &support::DebugSyntaxResult(self.grit_variable()), - ) - .field( - "grit_regex_pattern", - &support::DebugSyntaxResult(self.grit_regex_pattern()), - ) - .field( - "grit_pattern_as", - &support::DebugSyntaxResult(self.grit_pattern_as()), - ) - .field( - "grit_pattern_limit", - &support::DebugSyntaxResult(self.grit_pattern_limit()), - ) - .field( - "grit_assignment_as_pattern", - &support::DebugSyntaxResult(self.grit_assignment_as_pattern()), - ) - .field( - "grit_pattern_accumulate", - &support::DebugSyntaxResult(self.grit_pattern_accumulate()), - ) - .field( - "grit_rewrite", - &support::DebugSyntaxResult(self.grit_rewrite()), - ) - .field("grit_like", &support::DebugSyntaxResult(self.grit_like())) - .field( - "grit_pattern_where", - &support::DebugSyntaxResult(self.grit_pattern_where()), - ) - .field( - "grit_mul_operation", - &support::DebugSyntaxResult(self.grit_mul_operation()), - ) - .field( - "grit_div_operation", - &support::DebugSyntaxResult(self.grit_div_operation()), - ) - .field( - "grit_mod_operation", - &support::DebugSyntaxResult(self.grit_mod_operation()), - ) - .field( - "grit_add_operation", - &support::DebugSyntaxResult(self.grit_add_operation()), - ) - .field( - "grit_sub_operation", - &support::DebugSyntaxResult(self.grit_sub_operation()), - ) - .field( - "grit_sequential", - &support::DebugSyntaxResult(self.grit_sequential()), - ) - .field("grit_files", &support::DebugSyntaxResult(self.grit_files())) + f.debug_struct("BracketedGritPattern") .field( "l_paren_token", &support::DebugSyntaxResult(self.l_paren_token()), @@ -5188,29 +5177,25 @@ impl std::fmt::Debug for AnyGritPattern { "r_paren_token", &support::DebugSyntaxResult(self.r_paren_token()), ) - .field( - "grit_bogus_pattern", - &support::DebugSyntaxResult(self.grit_bogus_pattern()), - ) .finish() } } -impl From for SyntaxNode { - fn from(n: AnyGritPattern) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: BracketedGritPattern) -> SyntaxNode { n.syntax } } -impl From for SyntaxElement { - fn from(n: AnyGritPattern) -> SyntaxElement { +impl From for SyntaxElement { + fn from(n: BracketedGritPattern) -> SyntaxElement { n.syntax.into() } } -impl AstNode for AnyGritPredicate { +impl AstNode for BracketedGritPredicate { type Language = Language; const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(ANY_GRIT_PREDICATE as u16)); + SyntaxKindSet::from_raw(RawSyntaxKind(BRACKETED_GRIT_PREDICATE as u16)); fn can_cast(kind: SyntaxKind) -> bool { - kind == ANY_GRIT_PREDICATE + kind == BRACKETED_GRIT_PREDICATE } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { @@ -5226,77 +5211,9 @@ impl AstNode for AnyGritPredicate { self.syntax } } -impl std::fmt::Debug for AnyGritPredicate { +impl std::fmt::Debug for BracketedGritPredicate { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("AnyGritPredicate") - .field( - "grit_predicate_not", - &support::DebugSyntaxResult(self.grit_predicate_not()), - ) - .field( - "grit_predicate_maybe", - &support::DebugSyntaxResult(self.grit_predicate_maybe()), - ) - .field( - "grit_predicate_and", - &support::DebugSyntaxResult(self.grit_predicate_and()), - ) - .field( - "grit_predicate_or", - &support::DebugSyntaxResult(self.grit_predicate_or()), - ) - .field( - "grit_predicate_any", - &support::DebugSyntaxResult(self.grit_predicate_any()), - ) - .field( - "grit_predicate_if_else", - &support::DebugSyntaxResult(self.grit_predicate_if_else()), - ) - .field( - "grit_predicate_assignment", - &support::DebugSyntaxResult(self.grit_predicate_assignment()), - ) - .field( - "grit_predicate_accumulate", - &support::DebugSyntaxResult(self.grit_predicate_accumulate()), - ) - .field( - "grit_predicate_rewrite", - &support::DebugSyntaxResult(self.grit_predicate_rewrite()), - ) - .field( - "grit_predicate_greater", - &support::DebugSyntaxResult(self.grit_predicate_greater()), - ) - .field( - "grit_predicate_less", - &support::DebugSyntaxResult(self.grit_predicate_less()), - ) - .field( - "grit_predicate_greater_equal", - &support::DebugSyntaxResult(self.grit_predicate_greater_equal()), - ) - .field( - "grit_predicate_less_equal", - &support::DebugSyntaxResult(self.grit_predicate_less_equal()), - ) - .field( - "grit_predicate_not_equal", - &support::DebugSyntaxResult(self.grit_predicate_not_equal()), - ) - .field( - "grit_predicate_equal", - &support::DebugSyntaxResult(self.grit_predicate_equal()), - ) - .field( - "grit_predicate_match", - &support::DebugSyntaxResult(self.grit_predicate_match()), - ) - .field( - "grit_predicate_call", - &support::DebugSyntaxResult(self.grit_predicate_call()), - ) + f.debug_struct("BracketedGritPredicate") .field( "l_paren_token", &support::DebugSyntaxResult(self.l_paren_token()), @@ -5309,28 +5226,16 @@ impl std::fmt::Debug for AnyGritPredicate { "r_paren_token", &support::DebugSyntaxResult(self.r_paren_token()), ) - .field( - "grit_boolean_value", - &support::DebugSyntaxResult(self.grit_boolean_value()), - ) - .field( - "grit_predicate_return", - &support::DebugSyntaxResult(self.grit_predicate_return()), - ) - .field( - "grit_bogus_predicate", - &support::DebugSyntaxResult(self.grit_bogus_predicate()), - ) .finish() } } -impl From for SyntaxNode { - fn from(n: AnyGritPredicate) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: BracketedGritPredicate) -> SyntaxNode { n.syntax } } -impl From for SyntaxElement { - fn from(n: AnyGritPredicate) -> SyntaxElement { +impl From for SyntaxElement { + fn from(n: BracketedGritPredicate) -> SyntaxElement { n.syntax.into() } } @@ -5504,12 +5409,12 @@ impl From for SyntaxElement { n.syntax.into() } } -impl AstNode for GritBacktickSnippet { +impl AstNode for GritBacktickSnippetLiteral { type Language = Language; const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_BACKTICK_SNIPPET as u16)); + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_BACKTICK_SNIPPET_LITERAL as u16)); fn can_cast(kind: SyntaxKind) -> bool { - kind == GRIT_BACKTICK_SNIPPET + kind == GRIT_BACKTICK_SNIPPET_LITERAL } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { @@ -5525,9 +5430,9 @@ impl AstNode for GritBacktickSnippet { self.syntax } } -impl std::fmt::Debug for GritBacktickSnippet { +impl std::fmt::Debug for GritBacktickSnippetLiteral { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("GritBacktickSnippet") + f.debug_struct("GritBacktickSnippetLiteral") .field( "value_token", &support::DebugSyntaxResult(self.value_token()), @@ -5535,22 +5440,22 @@ impl std::fmt::Debug for GritBacktickSnippet { .finish() } } -impl From for SyntaxNode { - fn from(n: GritBacktickSnippet) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: GritBacktickSnippetLiteral) -> SyntaxNode { n.syntax } } -impl From for SyntaxElement { - fn from(n: GritBacktickSnippet) -> SyntaxElement { +impl From for SyntaxElement { + fn from(n: GritBacktickSnippetLiteral) -> SyntaxElement { n.syntax.into() } } -impl AstNode for GritBooleanValue { +impl AstNode for GritBooleanLiteral { type Language = Language; const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_BOOLEAN_VALUE as u16)); + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_BOOLEAN_LITERAL as u16)); fn can_cast(kind: SyntaxKind) -> bool { - kind == GRIT_BOOLEAN_VALUE + kind == GRIT_BOOLEAN_LITERAL } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { @@ -5566,9 +5471,9 @@ impl AstNode for GritBooleanValue { self.syntax } } -impl std::fmt::Debug for GritBooleanValue { +impl std::fmt::Debug for GritBooleanLiteral { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("GritBooleanValue") + f.debug_struct("GritBooleanLiteral") .field("true_token", &support::DebugSyntaxResult(self.true_token())) .field( "false_token", @@ -5577,13 +5482,13 @@ impl std::fmt::Debug for GritBooleanValue { .finish() } } -impl From for SyntaxNode { - fn from(n: GritBooleanValue) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: GritBooleanLiteral) -> SyntaxNode { n.syntax } } -impl From for SyntaxElement { - fn from(n: GritBooleanValue) -> SyntaxElement { +impl From for SyntaxElement { + fn from(n: GritBooleanLiteral) -> SyntaxElement { n.syntax.into() } } @@ -5889,12 +5794,12 @@ impl From for SyntaxElement { n.syntax.into() } } -impl AstNode for GritDoubleValue { +impl AstNode for GritDoubleLiteral { type Language = Language; const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_DOUBLE_VALUE as u16)); + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_DOUBLE_LITERAL as u16)); fn can_cast(kind: SyntaxKind) -> bool { - kind == GRIT_DOUBLE_VALUE + kind == GRIT_DOUBLE_LITERAL } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { @@ -5910,9 +5815,9 @@ impl AstNode for GritDoubleValue { self.syntax } } -impl std::fmt::Debug for GritDoubleValue { +impl std::fmt::Debug for GritDoubleLiteral { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("GritDoubleValue") + f.debug_struct("GritDoubleLiteral") .field( "value_token", &support::DebugSyntaxResult(self.value_token()), @@ -5920,13 +5825,13 @@ impl std::fmt::Debug for GritDoubleValue { .finish() } } -impl From for SyntaxNode { - fn from(n: GritDoubleValue) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: GritDoubleLiteral) -> SyntaxNode { n.syntax } } -impl From for SyntaxElement { - fn from(n: GritDoubleValue) -> SyntaxElement { +impl From for SyntaxElement { + fn from(n: GritDoubleLiteral) -> SyntaxElement { n.syntax.into() } } @@ -6074,12 +5979,12 @@ impl From for SyntaxElement { n.syntax.into() } } -impl AstNode for GritIntValue { +impl AstNode for GritIntLiteral { type Language = Language; const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_INT_VALUE as u16)); + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_INT_LITERAL as u16)); fn can_cast(kind: SyntaxKind) -> bool { - kind == GRIT_INT_VALUE + kind == GRIT_INT_LITERAL } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { @@ -6095,9 +6000,9 @@ impl AstNode for GritIntValue { self.syntax } } -impl std::fmt::Debug for GritIntValue { +impl std::fmt::Debug for GritIntLiteral { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("GritIntValue") + f.debug_struct("GritIntLiteral") .field( "value_token", &support::DebugSyntaxResult(self.value_token()), @@ -6105,13 +6010,13 @@ impl std::fmt::Debug for GritIntValue { .finish() } } -impl From for SyntaxNode { - fn from(n: GritIntValue) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: GritIntLiteral) -> SyntaxNode { n.syntax } } -impl From for SyntaxElement { - fn from(n: GritIntValue) -> SyntaxElement { +impl From for SyntaxElement { + fn from(n: GritIntLiteral) -> SyntaxElement { n.syntax.into() } } @@ -6276,11 +6181,10 @@ impl AstNode for GritLanguageName { impl std::fmt::Debug for GritLanguageName { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("GritLanguageName") - .field("js_token", &support::DebugSyntaxResult(self.js_token())) - .field("css_token", &support::DebugSyntaxResult(self.css_token())) - .field("json_token", &support::DebugSyntaxResult(self.json_token())) - .field("grit_token", &support::DebugSyntaxResult(self.grit_token())) - .field("html_token", &support::DebugSyntaxResult(self.html_token())) + .field( + "language_kind", + &support::DebugSyntaxResult(self.language_kind()), + ) .finish() } } @@ -6861,12 +6765,12 @@ impl From for SyntaxElement { n.syntax.into() } } -impl AstNode for GritNegativeIntValue { +impl AstNode for GritNegativeIntLiteral { type Language = Language; const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_NEGATIVE_INT_VALUE as u16)); + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_NEGATIVE_INT_LITERAL as u16)); fn can_cast(kind: SyntaxKind) -> bool { - kind == GRIT_NEGATIVE_INT_VALUE + kind == GRIT_NEGATIVE_INT_LITERAL } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { @@ -6882,9 +6786,9 @@ impl AstNode for GritNegativeIntValue { self.syntax } } -impl std::fmt::Debug for GritNegativeIntValue { +impl std::fmt::Debug for GritNegativeIntLiteral { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("GritNegativeIntValue") + f.debug_struct("GritNegativeIntLiteral") .field( "value_token", &support::DebugSyntaxResult(self.value_token()), @@ -6892,13 +6796,13 @@ impl std::fmt::Debug for GritNegativeIntValue { .finish() } } -impl From for SyntaxNode { - fn from(n: GritNegativeIntValue) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: GritNegativeIntLiteral) -> SyntaxNode { n.syntax } } -impl From for SyntaxElement { - fn from(n: GritNegativeIntValue) -> SyntaxElement { +impl From for SyntaxElement { + fn from(n: GritNegativeIntLiteral) -> SyntaxElement { n.syntax.into() } } @@ -8784,12 +8688,12 @@ impl From for SyntaxElement { n.syntax.into() } } -impl AstNode for GritRawBacktickSnippet { +impl AstNode for GritRawBacktickSnippetLiteral { type Language = Language; const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_RAW_BACKTICK_SNIPPET as u16)); + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_RAW_BACKTICK_SNIPPET_LITERAL as u16)); fn can_cast(kind: SyntaxKind) -> bool { - kind == GRIT_RAW_BACKTICK_SNIPPET + kind == GRIT_RAW_BACKTICK_SNIPPET_LITERAL } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { @@ -8805,9 +8709,9 @@ impl AstNode for GritRawBacktickSnippet { self.syntax } } -impl std::fmt::Debug for GritRawBacktickSnippet { +impl std::fmt::Debug for GritRawBacktickSnippetLiteral { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("GritRawBacktickSnippet") + f.debug_struct("GritRawBacktickSnippetLiteral") .field( "value_token", &support::DebugSyntaxResult(self.value_token()), @@ -8815,22 +8719,22 @@ impl std::fmt::Debug for GritRawBacktickSnippet { .finish() } } -impl From for SyntaxNode { - fn from(n: GritRawBacktickSnippet) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: GritRawBacktickSnippetLiteral) -> SyntaxNode { n.syntax } } -impl From for SyntaxElement { - fn from(n: GritRawBacktickSnippet) -> SyntaxElement { +impl From for SyntaxElement { + fn from(n: GritRawBacktickSnippetLiteral) -> SyntaxElement { n.syntax.into() } } -impl AstNode for GritRegexPattern { +impl AstNode for GritRegexLiteral { type Language = Language; const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_REGEX_PATTERN as u16)); + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_REGEX_LITERAL as u16)); fn can_cast(kind: SyntaxKind) -> bool { - kind == GRIT_REGEX_PATTERN + kind == GRIT_REGEX_LITERAL } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { @@ -8846,33 +8750,32 @@ impl AstNode for GritRegexPattern { self.syntax } } -impl std::fmt::Debug for GritRegexPattern { +impl std::fmt::Debug for GritRegexLiteral { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("GritRegexPattern") - .field("regex", &support::DebugSyntaxResult(self.regex())) + f.debug_struct("GritRegexLiteral") .field( - "variables", - &support::DebugOptionalElement(self.variables()), + "value_token", + &support::DebugSyntaxResult(self.value_token()), ) .finish() } } -impl From for SyntaxNode { - fn from(n: GritRegexPattern) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: GritRegexLiteral) -> SyntaxNode { n.syntax } } -impl From for SyntaxElement { - fn from(n: GritRegexPattern) -> SyntaxElement { +impl From for SyntaxElement { + fn from(n: GritRegexLiteral) -> SyntaxElement { n.syntax.into() } } -impl AstNode for GritRegexPatternVariables { +impl AstNode for GritRegexPattern { type Language = Language; const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_REGEX_PATTERN_VARIABLES as u16)); + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_REGEX_PATTERN as u16)); fn can_cast(kind: SyntaxKind) -> bool { - kind == GRIT_REGEX_PATTERN_VARIABLES + kind == GRIT_REGEX_PATTERN } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { @@ -8888,40 +8791,33 @@ impl AstNode for GritRegexPatternVariables { self.syntax } } -impl std::fmt::Debug for GritRegexPatternVariables { +impl std::fmt::Debug for GritRegexPattern { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("GritRegexPatternVariables") - .field( - "l_paren_token", - &support::DebugSyntaxResult(self.l_paren_token()), - ) - .field( - "grit_pattern_arg_list", - &support::DebugOptionalElement(self.grit_pattern_arg_list()), - ) + f.debug_struct("GritRegexPattern") + .field("regex", &support::DebugSyntaxResult(self.regex())) .field( - "r_paren_token", - &support::DebugSyntaxResult(self.r_paren_token()), + "variables", + &support::DebugOptionalElement(self.variables()), ) .finish() } } -impl From for SyntaxNode { - fn from(n: GritRegexPatternVariables) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: GritRegexPattern) -> SyntaxNode { n.syntax } } -impl From for SyntaxElement { - fn from(n: GritRegexPatternVariables) -> SyntaxElement { +impl From for SyntaxElement { + fn from(n: GritRegexPattern) -> SyntaxElement { n.syntax.into() } } -impl AstNode for GritRegexValue { +impl AstNode for GritRegexPatternVariables { type Language = Language; const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_REGEX_VALUE as u16)); + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_REGEX_PATTERN_VARIABLES as u16)); fn can_cast(kind: SyntaxKind) -> bool { - kind == GRIT_REGEX_VALUE + kind == GRIT_REGEX_PATTERN_VARIABLES } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { @@ -8937,23 +8833,31 @@ impl AstNode for GritRegexValue { self.syntax } } -impl std::fmt::Debug for GritRegexValue { +impl std::fmt::Debug for GritRegexPatternVariables { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("GritRegexValue") + f.debug_struct("GritRegexPatternVariables") .field( - "value_token", - &support::DebugSyntaxResult(self.value_token()), + "l_paren_token", + &support::DebugSyntaxResult(self.l_paren_token()), + ) + .field( + "grit_pattern_arg_list", + &support::DebugOptionalElement(self.grit_pattern_arg_list()), + ) + .field( + "r_paren_token", + &support::DebugSyntaxResult(self.r_paren_token()), ) .finish() } } -impl From for SyntaxNode { - fn from(n: GritRegexValue) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: GritRegexPatternVariables) -> SyntaxNode { n.syntax } } -impl From for SyntaxElement { - fn from(n: GritRegexValue) -> SyntaxElement { +impl From for SyntaxElement { + fn from(n: GritRegexPatternVariables) -> SyntaxElement { n.syntax.into() } } @@ -9101,12 +9005,12 @@ impl From for SyntaxElement { n.syntax.into() } } -impl AstNode for GritSnippetRegexValue { +impl AstNode for GritSnippetRegexLiteral { type Language = Language; const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_SNIPPET_REGEX_VALUE as u16)); + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_SNIPPET_REGEX_LITERAL as u16)); fn can_cast(kind: SyntaxKind) -> bool { - kind == GRIT_SNIPPET_REGEX_VALUE + kind == GRIT_SNIPPET_REGEX_LITERAL } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { @@ -9122,9 +9026,9 @@ impl AstNode for GritSnippetRegexValue { self.syntax } } -impl std::fmt::Debug for GritSnippetRegexValue { +impl std::fmt::Debug for GritSnippetRegexLiteral { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("GritSnippetRegexValue") + f.debug_struct("GritSnippetRegexLiteral") .field( "value_token", &support::DebugSyntaxResult(self.value_token()), @@ -9132,13 +9036,13 @@ impl std::fmt::Debug for GritSnippetRegexValue { .finish() } } -impl From for SyntaxNode { - fn from(n: GritSnippetRegexValue) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: GritSnippetRegexLiteral) -> SyntaxNode { n.syntax } } -impl From for SyntaxElement { - fn from(n: GritSnippetRegexValue) -> SyntaxElement { +impl From for SyntaxElement { + fn from(n: GritSnippetRegexLiteral) -> SyntaxElement { n.syntax.into() } } @@ -9181,12 +9085,12 @@ impl From for SyntaxElement { n.syntax.into() } } -impl AstNode for GritStringValue { +impl AstNode for GritStringLiteral { type Language = Language; const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_STRING_VALUE as u16)); + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_STRING_LITERAL as u16)); fn can_cast(kind: SyntaxKind) -> bool { - kind == GRIT_STRING_VALUE + kind == GRIT_STRING_LITERAL } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { @@ -9202,9 +9106,9 @@ impl AstNode for GritStringValue { self.syntax } } -impl std::fmt::Debug for GritStringValue { +impl std::fmt::Debug for GritStringLiteral { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("GritStringValue") + f.debug_struct("GritStringLiteral") .field( "value_token", &support::DebugSyntaxResult(self.value_token()), @@ -9212,13 +9116,13 @@ impl std::fmt::Debug for GritStringValue { .finish() } } -impl From for SyntaxNode { - fn from(n: GritStringValue) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: GritStringLiteral) -> SyntaxNode { n.syntax } } -impl From for SyntaxElement { - fn from(n: GritStringValue) -> SyntaxElement { +impl From for SyntaxElement { + fn from(n: GritStringLiteral) -> SyntaxElement { n.syntax.into() } } @@ -9265,12 +9169,12 @@ impl From for SyntaxElement { n.syntax.into() } } -impl AstNode for GritUndefined { +impl AstNode for GritUndefinedLiteral { type Language = Language; const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_UNDEFINED as u16)); + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_UNDEFINED_LITERAL as u16)); fn can_cast(kind: SyntaxKind) -> bool { - kind == GRIT_UNDEFINED + kind == GRIT_UNDEFINED_LITERAL } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { @@ -9286,9 +9190,9 @@ impl AstNode for GritUndefined { self.syntax } } -impl std::fmt::Debug for GritUndefined { +impl std::fmt::Debug for GritUndefinedLiteral { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("GritUndefined") + f.debug_struct("GritUndefinedLiteral") .field( "undefined_token", &support::DebugSyntaxResult(self.undefined_token()), @@ -9296,13 +9200,13 @@ impl std::fmt::Debug for GritUndefined { .finish() } } -impl From for SyntaxNode { - fn from(n: GritUndefined) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: GritUndefinedLiteral) -> SyntaxNode { n.syntax } } -impl From for SyntaxElement { - fn from(n: GritUndefined) -> SyntaxElement { +impl From for SyntaxElement { + fn from(n: GritUndefinedLiteral) -> SyntaxElement { n.syntax.into() } } @@ -9425,8 +9329,8 @@ impl std::fmt::Debug for GritVersion { &support::DebugSyntaxResult(self.l_paren_token()), ) .field( - "grit_double_value", - &support::DebugSyntaxResult(self.grit_double_value()), + "grit_double_literal", + &support::DebugSyntaxResult(self.grit_double_literal()), ) .field( "r_paren_token", @@ -9466,146 +9370,443 @@ impl AstNode for GritWithin { self.syntax } } -impl std::fmt::Debug for GritWithin { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("GritWithin") - .field( - "within_token", - &support::DebugSyntaxResult(self.within_token()), - ) - .field("pattern", &support::DebugSyntaxResult(self.pattern())) - .finish() +impl std::fmt::Debug for GritWithin { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritWithin") + .field( + "within_token", + &support::DebugSyntaxResult(self.within_token()), + ) + .field("pattern", &support::DebugSyntaxResult(self.pattern())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritWithin) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritWithin) -> SyntaxElement { + n.syntax.into() + } +} +impl From for AnyGritContainer { + fn from(node: GritListAccessor) -> AnyGritContainer { + AnyGritContainer::GritListAccessor(node) + } +} +impl From for AnyGritContainer { + fn from(node: GritMapAccessor) -> AnyGritContainer { + AnyGritContainer::GritMapAccessor(node) + } +} +impl From for AnyGritContainer { + fn from(node: GritVariable) -> AnyGritContainer { + AnyGritContainer::GritVariable(node) + } +} +impl AstNode for AnyGritContainer { + type Language = Language; + const KIND_SET: SyntaxKindSet = GritListAccessor::KIND_SET + .union(GritMapAccessor::KIND_SET) + .union(GritVariable::KIND_SET); + fn can_cast(kind: SyntaxKind) -> bool { + matches!(kind, GRIT_LIST_ACCESSOR | GRIT_MAP_ACCESSOR | GRIT_VARIABLE) + } + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + GRIT_LIST_ACCESSOR => AnyGritContainer::GritListAccessor(GritListAccessor { syntax }), + GRIT_MAP_ACCESSOR => AnyGritContainer::GritMapAccessor(GritMapAccessor { syntax }), + GRIT_VARIABLE => AnyGritContainer::GritVariable(GritVariable { syntax }), + _ => return None, + }; + Some(res) + } + fn syntax(&self) -> &SyntaxNode { + match self { + AnyGritContainer::GritListAccessor(it) => &it.syntax, + AnyGritContainer::GritMapAccessor(it) => &it.syntax, + AnyGritContainer::GritVariable(it) => &it.syntax, + } + } + fn into_syntax(self) -> SyntaxNode { + match self { + AnyGritContainer::GritListAccessor(it) => it.syntax, + AnyGritContainer::GritMapAccessor(it) => it.syntax, + AnyGritContainer::GritVariable(it) => it.syntax, + } + } +} +impl std::fmt::Debug for AnyGritContainer { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + AnyGritContainer::GritListAccessor(it) => std::fmt::Debug::fmt(it, f), + AnyGritContainer::GritMapAccessor(it) => std::fmt::Debug::fmt(it, f), + AnyGritContainer::GritVariable(it) => std::fmt::Debug::fmt(it, f), + } + } +} +impl From for SyntaxNode { + fn from(n: AnyGritContainer) -> SyntaxNode { + match n { + AnyGritContainer::GritListAccessor(it) => it.into(), + AnyGritContainer::GritMapAccessor(it) => it.into(), + AnyGritContainer::GritVariable(it) => it.into(), + } + } +} +impl From for SyntaxElement { + fn from(n: AnyGritContainer) -> SyntaxElement { + let node: SyntaxNode = n.into(); + node.into() + } +} +impl From for AnyGritDefinition { + fn from(node: GritBogusDefinition) -> AnyGritDefinition { + AnyGritDefinition::GritBogusDefinition(node) + } +} +impl From for AnyGritDefinition { + fn from(node: GritFunctionDefinition) -> AnyGritDefinition { + AnyGritDefinition::GritFunctionDefinition(node) + } +} +impl From for AnyGritDefinition { + fn from(node: GritPatternDefinition) -> AnyGritDefinition { + AnyGritDefinition::GritPatternDefinition(node) + } +} +impl From for AnyGritDefinition { + fn from(node: GritPredicateDefinition) -> AnyGritDefinition { + AnyGritDefinition::GritPredicateDefinition(node) + } +} +impl AstNode for AnyGritDefinition { + type Language = Language; + const KIND_SET: SyntaxKindSet = GritBogusDefinition::KIND_SET + .union(GritFunctionDefinition::KIND_SET) + .union(GritPatternDefinition::KIND_SET) + .union(GritPredicateDefinition::KIND_SET); + fn can_cast(kind: SyntaxKind) -> bool { + matches!( + kind, + GRIT_BOGUS_DEFINITION + | GRIT_FUNCTION_DEFINITION + | GRIT_PATTERN_DEFINITION + | GRIT_PREDICATE_DEFINITION + ) + } + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + GRIT_BOGUS_DEFINITION => { + AnyGritDefinition::GritBogusDefinition(GritBogusDefinition { syntax }) + } + GRIT_FUNCTION_DEFINITION => { + AnyGritDefinition::GritFunctionDefinition(GritFunctionDefinition { syntax }) + } + GRIT_PATTERN_DEFINITION => { + AnyGritDefinition::GritPatternDefinition(GritPatternDefinition { syntax }) + } + GRIT_PREDICATE_DEFINITION => { + AnyGritDefinition::GritPredicateDefinition(GritPredicateDefinition { syntax }) + } + _ => return None, + }; + Some(res) + } + fn syntax(&self) -> &SyntaxNode { + match self { + AnyGritDefinition::GritBogusDefinition(it) => &it.syntax, + AnyGritDefinition::GritFunctionDefinition(it) => &it.syntax, + AnyGritDefinition::GritPatternDefinition(it) => &it.syntax, + AnyGritDefinition::GritPredicateDefinition(it) => &it.syntax, + } + } + fn into_syntax(self) -> SyntaxNode { + match self { + AnyGritDefinition::GritBogusDefinition(it) => it.syntax, + AnyGritDefinition::GritFunctionDefinition(it) => it.syntax, + AnyGritDefinition::GritPatternDefinition(it) => it.syntax, + AnyGritDefinition::GritPredicateDefinition(it) => it.syntax, + } + } +} +impl std::fmt::Debug for AnyGritDefinition { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + AnyGritDefinition::GritBogusDefinition(it) => std::fmt::Debug::fmt(it, f), + AnyGritDefinition::GritFunctionDefinition(it) => std::fmt::Debug::fmt(it, f), + AnyGritDefinition::GritPatternDefinition(it) => std::fmt::Debug::fmt(it, f), + AnyGritDefinition::GritPredicateDefinition(it) => std::fmt::Debug::fmt(it, f), + } + } +} +impl From for SyntaxNode { + fn from(n: AnyGritDefinition) -> SyntaxNode { + match n { + AnyGritDefinition::GritBogusDefinition(it) => it.into(), + AnyGritDefinition::GritFunctionDefinition(it) => it.into(), + AnyGritDefinition::GritPatternDefinition(it) => it.into(), + AnyGritDefinition::GritPredicateDefinition(it) => it.into(), + } + } +} +impl From for SyntaxElement { + fn from(n: AnyGritDefinition) -> SyntaxElement { + let node: SyntaxNode = n.into(); + node.into() + } +} +impl From for AnyGritListPattern { + fn from(node: GritDotdotdot) -> AnyGritListPattern { + AnyGritListPattern::GritDotdotdot(node) + } +} +impl AstNode for AnyGritListPattern { + type Language = Language; + const KIND_SET: SyntaxKindSet = + AnyGritPattern::KIND_SET.union(GritDotdotdot::KIND_SET); + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + GRIT_DOTDOTDOT => true, + k if AnyGritPattern::can_cast(k) => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + GRIT_DOTDOTDOT => AnyGritListPattern::GritDotdotdot(GritDotdotdot { syntax }), + _ => { + if let Some(any_grit_pattern) = AnyGritPattern::cast(syntax) { + return Some(AnyGritListPattern::AnyGritPattern(any_grit_pattern)); + } + return None; + } + }; + Some(res) + } + fn syntax(&self) -> &SyntaxNode { + match self { + AnyGritListPattern::GritDotdotdot(it) => &it.syntax, + AnyGritListPattern::AnyGritPattern(it) => it.syntax(), + } + } + fn into_syntax(self) -> SyntaxNode { + match self { + AnyGritListPattern::GritDotdotdot(it) => it.syntax, + AnyGritListPattern::AnyGritPattern(it) => it.into_syntax(), + } + } +} +impl std::fmt::Debug for AnyGritListPattern { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + AnyGritListPattern::AnyGritPattern(it) => std::fmt::Debug::fmt(it, f), + AnyGritListPattern::GritDotdotdot(it) => std::fmt::Debug::fmt(it, f), + } + } +} +impl From for SyntaxNode { + fn from(n: AnyGritListPattern) -> SyntaxNode { + match n { + AnyGritListPattern::AnyGritPattern(it) => it.into(), + AnyGritListPattern::GritDotdotdot(it) => it.into(), + } + } +} +impl From for SyntaxElement { + fn from(n: AnyGritListPattern) -> SyntaxElement { + let node: SyntaxNode = n.into(); + node.into() + } +} +impl From for AnyGritLiteral { + fn from(node: GritBogusLiteral) -> AnyGritLiteral { + AnyGritLiteral::GritBogusLiteral(node) + } +} +impl From for AnyGritLiteral { + fn from(node: GritBooleanLiteral) -> AnyGritLiteral { + AnyGritLiteral::GritBooleanLiteral(node) + } +} +impl From for AnyGritLiteral { + fn from(node: GritCodeSnippet) -> AnyGritLiteral { + AnyGritLiteral::GritCodeSnippet(node) + } +} +impl From for AnyGritLiteral { + fn from(node: GritDoubleLiteral) -> AnyGritLiteral { + AnyGritLiteral::GritDoubleLiteral(node) } } -impl From for SyntaxNode { - fn from(n: GritWithin) -> SyntaxNode { - n.syntax +impl From for AnyGritLiteral { + fn from(node: GritIntLiteral) -> AnyGritLiteral { + AnyGritLiteral::GritIntLiteral(node) } } -impl From for SyntaxElement { - fn from(n: GritWithin) -> SyntaxElement { - n.syntax.into() +impl From for AnyGritLiteral { + fn from(node: GritList) -> AnyGritLiteral { + AnyGritLiteral::GritList(node) } } -impl From for AnyGritContainer { - fn from(node: GritListAccessor) -> AnyGritContainer { - AnyGritContainer::GritListAccessor(node) +impl From for AnyGritLiteral { + fn from(node: GritMap) -> AnyGritLiteral { + AnyGritLiteral::GritMap(node) } } -impl From for AnyGritContainer { - fn from(node: GritMapAccessor) -> AnyGritContainer { - AnyGritContainer::GritMapAccessor(node) +impl From for AnyGritLiteral { + fn from(node: GritStringLiteral) -> AnyGritLiteral { + AnyGritLiteral::GritStringLiteral(node) } } -impl From for AnyGritContainer { - fn from(node: GritVariable) -> AnyGritContainer { - AnyGritContainer::GritVariable(node) +impl From for AnyGritLiteral { + fn from(node: GritUndefinedLiteral) -> AnyGritLiteral { + AnyGritLiteral::GritUndefinedLiteral(node) } } -impl AstNode for AnyGritContainer { +impl AstNode for AnyGritLiteral { type Language = Language; - const KIND_SET: SyntaxKindSet = GritListAccessor::KIND_SET - .union(GritMapAccessor::KIND_SET) - .union(GritVariable::KIND_SET); + const KIND_SET: SyntaxKindSet = GritBogusLiteral::KIND_SET + .union(GritBooleanLiteral::KIND_SET) + .union(GritCodeSnippet::KIND_SET) + .union(GritDoubleLiteral::KIND_SET) + .union(GritIntLiteral::KIND_SET) + .union(GritList::KIND_SET) + .union(GritMap::KIND_SET) + .union(GritStringLiteral::KIND_SET) + .union(GritUndefinedLiteral::KIND_SET); fn can_cast(kind: SyntaxKind) -> bool { - matches!(kind, GRIT_LIST_ACCESSOR | GRIT_MAP_ACCESSOR | GRIT_VARIABLE) + matches!( + kind, + GRIT_BOGUS_LITERAL + | GRIT_BOOLEAN_LITERAL + | GRIT_CODE_SNIPPET + | GRIT_DOUBLE_LITERAL + | GRIT_INT_LITERAL + | GRIT_LIST + | GRIT_MAP + | GRIT_STRING_LITERAL + | GRIT_UNDEFINED_LITERAL + ) } fn cast(syntax: SyntaxNode) -> Option { let res = match syntax.kind() { - GRIT_LIST_ACCESSOR => AnyGritContainer::GritListAccessor(GritListAccessor { syntax }), - GRIT_MAP_ACCESSOR => AnyGritContainer::GritMapAccessor(GritMapAccessor { syntax }), - GRIT_VARIABLE => AnyGritContainer::GritVariable(GritVariable { syntax }), + GRIT_BOGUS_LITERAL => AnyGritLiteral::GritBogusLiteral(GritBogusLiteral { syntax }), + GRIT_BOOLEAN_LITERAL => { + AnyGritLiteral::GritBooleanLiteral(GritBooleanLiteral { syntax }) + } + GRIT_CODE_SNIPPET => AnyGritLiteral::GritCodeSnippet(GritCodeSnippet { syntax }), + GRIT_DOUBLE_LITERAL => AnyGritLiteral::GritDoubleLiteral(GritDoubleLiteral { syntax }), + GRIT_INT_LITERAL => AnyGritLiteral::GritIntLiteral(GritIntLiteral { syntax }), + GRIT_LIST => AnyGritLiteral::GritList(GritList { syntax }), + GRIT_MAP => AnyGritLiteral::GritMap(GritMap { syntax }), + GRIT_STRING_LITERAL => AnyGritLiteral::GritStringLiteral(GritStringLiteral { syntax }), + GRIT_UNDEFINED_LITERAL => { + AnyGritLiteral::GritUndefinedLiteral(GritUndefinedLiteral { syntax }) + } _ => return None, }; Some(res) } fn syntax(&self) -> &SyntaxNode { match self { - AnyGritContainer::GritListAccessor(it) => &it.syntax, - AnyGritContainer::GritMapAccessor(it) => &it.syntax, - AnyGritContainer::GritVariable(it) => &it.syntax, + AnyGritLiteral::GritBogusLiteral(it) => &it.syntax, + AnyGritLiteral::GritBooleanLiteral(it) => &it.syntax, + AnyGritLiteral::GritCodeSnippet(it) => &it.syntax, + AnyGritLiteral::GritDoubleLiteral(it) => &it.syntax, + AnyGritLiteral::GritIntLiteral(it) => &it.syntax, + AnyGritLiteral::GritList(it) => &it.syntax, + AnyGritLiteral::GritMap(it) => &it.syntax, + AnyGritLiteral::GritStringLiteral(it) => &it.syntax, + AnyGritLiteral::GritUndefinedLiteral(it) => &it.syntax, } } fn into_syntax(self) -> SyntaxNode { match self { - AnyGritContainer::GritListAccessor(it) => it.syntax, - AnyGritContainer::GritMapAccessor(it) => it.syntax, - AnyGritContainer::GritVariable(it) => it.syntax, + AnyGritLiteral::GritBogusLiteral(it) => it.syntax, + AnyGritLiteral::GritBooleanLiteral(it) => it.syntax, + AnyGritLiteral::GritCodeSnippet(it) => it.syntax, + AnyGritLiteral::GritDoubleLiteral(it) => it.syntax, + AnyGritLiteral::GritIntLiteral(it) => it.syntax, + AnyGritLiteral::GritList(it) => it.syntax, + AnyGritLiteral::GritMap(it) => it.syntax, + AnyGritLiteral::GritStringLiteral(it) => it.syntax, + AnyGritLiteral::GritUndefinedLiteral(it) => it.syntax, } } } -impl std::fmt::Debug for AnyGritContainer { +impl std::fmt::Debug for AnyGritLiteral { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - AnyGritContainer::GritListAccessor(it) => std::fmt::Debug::fmt(it, f), - AnyGritContainer::GritMapAccessor(it) => std::fmt::Debug::fmt(it, f), - AnyGritContainer::GritVariable(it) => std::fmt::Debug::fmt(it, f), + AnyGritLiteral::GritBogusLiteral(it) => std::fmt::Debug::fmt(it, f), + AnyGritLiteral::GritBooleanLiteral(it) => std::fmt::Debug::fmt(it, f), + AnyGritLiteral::GritCodeSnippet(it) => std::fmt::Debug::fmt(it, f), + AnyGritLiteral::GritDoubleLiteral(it) => std::fmt::Debug::fmt(it, f), + AnyGritLiteral::GritIntLiteral(it) => std::fmt::Debug::fmt(it, f), + AnyGritLiteral::GritList(it) => std::fmt::Debug::fmt(it, f), + AnyGritLiteral::GritMap(it) => std::fmt::Debug::fmt(it, f), + AnyGritLiteral::GritStringLiteral(it) => std::fmt::Debug::fmt(it, f), + AnyGritLiteral::GritUndefinedLiteral(it) => std::fmt::Debug::fmt(it, f), } } } -impl From for SyntaxNode { - fn from(n: AnyGritContainer) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: AnyGritLiteral) -> SyntaxNode { match n { - AnyGritContainer::GritListAccessor(it) => it.into(), - AnyGritContainer::GritMapAccessor(it) => it.into(), - AnyGritContainer::GritVariable(it) => it.into(), + AnyGritLiteral::GritBogusLiteral(it) => it.into(), + AnyGritLiteral::GritBooleanLiteral(it) => it.into(), + AnyGritLiteral::GritCodeSnippet(it) => it.into(), + AnyGritLiteral::GritDoubleLiteral(it) => it.into(), + AnyGritLiteral::GritIntLiteral(it) => it.into(), + AnyGritLiteral::GritList(it) => it.into(), + AnyGritLiteral::GritMap(it) => it.into(), + AnyGritLiteral::GritStringLiteral(it) => it.into(), + AnyGritLiteral::GritUndefinedLiteral(it) => it.into(), } } } -impl From for SyntaxElement { - fn from(n: AnyGritContainer) -> SyntaxElement { +impl From for SyntaxElement { + fn from(n: AnyGritLiteral) -> SyntaxElement { let node: SyntaxNode = n.into(); node.into() } } -impl From for AnyGritDefinition { - fn from(node: GritBogusDefinition) -> AnyGritDefinition { - AnyGritDefinition::GritBogusDefinition(node) - } -} -impl From for AnyGritDefinition { - fn from(node: GritFunctionDefinition) -> AnyGritDefinition { - AnyGritDefinition::GritFunctionDefinition(node) +impl From for AnyGritNamedArg { + fn from(node: GritBogusNamedArg) -> AnyGritNamedArg { + AnyGritNamedArg::GritBogusNamedArg(node) } } -impl From for AnyGritDefinition { - fn from(node: GritPatternDefinition) -> AnyGritDefinition { - AnyGritDefinition::GritPatternDefinition(node) +impl From for AnyGritNamedArg { + fn from(node: GritNamedArg) -> AnyGritNamedArg { + AnyGritNamedArg::GritNamedArg(node) } } -impl From for AnyGritDefinition { - fn from(node: GritPredicateDefinition) -> AnyGritDefinition { - AnyGritDefinition::GritPredicateDefinition(node) +impl From for AnyGritNamedArg { + fn from(node: GritNamedArgWithDefault) -> AnyGritNamedArg { + AnyGritNamedArg::GritNamedArgWithDefault(node) } } -impl AstNode for AnyGritDefinition { +impl AstNode for AnyGritNamedArg { type Language = Language; - const KIND_SET: SyntaxKindSet = GritBogusDefinition::KIND_SET - .union(GritFunctionDefinition::KIND_SET) - .union(GritPatternDefinition::KIND_SET) - .union(GritPredicateDefinition::KIND_SET); + const KIND_SET: SyntaxKindSet = GritBogusNamedArg::KIND_SET + .union(GritNamedArg::KIND_SET) + .union(GritNamedArgWithDefault::KIND_SET); fn can_cast(kind: SyntaxKind) -> bool { matches!( kind, - GRIT_BOGUS_DEFINITION - | GRIT_FUNCTION_DEFINITION - | GRIT_PATTERN_DEFINITION - | GRIT_PREDICATE_DEFINITION + GRIT_BOGUS_NAMED_ARG | GRIT_NAMED_ARG | GRIT_NAMED_ARG_WITH_DEFAULT ) } fn cast(syntax: SyntaxNode) -> Option { let res = match syntax.kind() { - GRIT_BOGUS_DEFINITION => { - AnyGritDefinition::GritBogusDefinition(GritBogusDefinition { syntax }) - } - GRIT_FUNCTION_DEFINITION => { - AnyGritDefinition::GritFunctionDefinition(GritFunctionDefinition { syntax }) - } - GRIT_PATTERN_DEFINITION => { - AnyGritDefinition::GritPatternDefinition(GritPatternDefinition { syntax }) + GRIT_BOGUS_NAMED_ARG => { + AnyGritNamedArg::GritBogusNamedArg(GritBogusNamedArg { syntax }) } - GRIT_PREDICATE_DEFINITION => { - AnyGritDefinition::GritPredicateDefinition(GritPredicateDefinition { syntax }) + GRIT_NAMED_ARG => AnyGritNamedArg::GritNamedArg(GritNamedArg { syntax }), + GRIT_NAMED_ARG_WITH_DEFAULT => { + AnyGritNamedArg::GritNamedArgWithDefault(GritNamedArgWithDefault { syntax }) } _ => return None, }; @@ -9613,289 +9814,908 @@ impl AstNode for AnyGritDefinition { } fn syntax(&self) -> &SyntaxNode { match self { - AnyGritDefinition::GritBogusDefinition(it) => &it.syntax, - AnyGritDefinition::GritFunctionDefinition(it) => &it.syntax, - AnyGritDefinition::GritPatternDefinition(it) => &it.syntax, - AnyGritDefinition::GritPredicateDefinition(it) => &it.syntax, + AnyGritNamedArg::GritBogusNamedArg(it) => &it.syntax, + AnyGritNamedArg::GritNamedArg(it) => &it.syntax, + AnyGritNamedArg::GritNamedArgWithDefault(it) => &it.syntax, } } fn into_syntax(self) -> SyntaxNode { match self { - AnyGritDefinition::GritBogusDefinition(it) => it.syntax, - AnyGritDefinition::GritFunctionDefinition(it) => it.syntax, - AnyGritDefinition::GritPatternDefinition(it) => it.syntax, - AnyGritDefinition::GritPredicateDefinition(it) => it.syntax, + AnyGritNamedArg::GritBogusNamedArg(it) => it.syntax, + AnyGritNamedArg::GritNamedArg(it) => it.syntax, + AnyGritNamedArg::GritNamedArgWithDefault(it) => it.syntax, } } } -impl std::fmt::Debug for AnyGritDefinition { +impl std::fmt::Debug for AnyGritNamedArg { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - AnyGritDefinition::GritBogusDefinition(it) => std::fmt::Debug::fmt(it, f), - AnyGritDefinition::GritFunctionDefinition(it) => std::fmt::Debug::fmt(it, f), - AnyGritDefinition::GritPatternDefinition(it) => std::fmt::Debug::fmt(it, f), - AnyGritDefinition::GritPredicateDefinition(it) => std::fmt::Debug::fmt(it, f), + AnyGritNamedArg::GritBogusNamedArg(it) => std::fmt::Debug::fmt(it, f), + AnyGritNamedArg::GritNamedArg(it) => std::fmt::Debug::fmt(it, f), + AnyGritNamedArg::GritNamedArgWithDefault(it) => std::fmt::Debug::fmt(it, f), } } } -impl From for SyntaxNode { - fn from(n: AnyGritDefinition) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: AnyGritNamedArg) -> SyntaxNode { match n { - AnyGritDefinition::GritBogusDefinition(it) => it.into(), - AnyGritDefinition::GritFunctionDefinition(it) => it.into(), - AnyGritDefinition::GritPatternDefinition(it) => it.into(), - AnyGritDefinition::GritPredicateDefinition(it) => it.into(), + AnyGritNamedArg::GritBogusNamedArg(it) => it.into(), + AnyGritNamedArg::GritNamedArg(it) => it.into(), + AnyGritNamedArg::GritNamedArgWithDefault(it) => it.into(), } } } -impl From for SyntaxElement { - fn from(n: AnyGritDefinition) -> SyntaxElement { - let node: SyntaxNode = n.into(); - node.into() +impl From for SyntaxElement { + fn from(n: AnyGritNamedArg) -> SyntaxElement { + let node: SyntaxNode = n.into(); + node.into() + } +} +impl From for AnyGritPattern { + fn from(node: BracketedGritPattern) -> AnyGritPattern { + AnyGritPattern::BracketedGritPattern(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritAddOperation) -> AnyGritPattern { + AnyGritPattern::GritAddOperation(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritAssignmentAsPattern) -> AnyGritPattern { + AnyGritPattern::GritAssignmentAsPattern(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritBogusPattern) -> AnyGritPattern { + AnyGritPattern::GritBogusPattern(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritBubble) -> AnyGritPattern { + AnyGritPattern::GritBubble(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritDivOperation) -> AnyGritPattern { + AnyGritPattern::GritDivOperation(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritDot) -> AnyGritPattern { + AnyGritPattern::GritDot(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritEvery) -> AnyGritPattern { + AnyGritPattern::GritEvery(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritFiles) -> AnyGritPattern { + AnyGritPattern::GritFiles(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritLike) -> AnyGritPattern { + AnyGritPattern::GritLike(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritListAccessor) -> AnyGritPattern { + AnyGritPattern::GritListAccessor(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritMapAccessor) -> AnyGritPattern { + AnyGritPattern::GritMapAccessor(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritModOperation) -> AnyGritPattern { + AnyGritPattern::GritModOperation(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritMulOperation) -> AnyGritPattern { + AnyGritPattern::GritMulOperation(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritNodeLike) -> AnyGritPattern { + AnyGritPattern::GritNodeLike(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritPatternAccumulate) -> AnyGritPattern { + AnyGritPattern::GritPatternAccumulate(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritPatternAfter) -> AnyGritPattern { + AnyGritPattern::GritPatternAfter(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritPatternAnd) -> AnyGritPattern { + AnyGritPattern::GritPatternAnd(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritPatternAny) -> AnyGritPattern { + AnyGritPattern::GritPatternAny(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritPatternAs) -> AnyGritPattern { + AnyGritPattern::GritPatternAs(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritPatternBefore) -> AnyGritPattern { + AnyGritPattern::GritPatternBefore(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritPatternContains) -> AnyGritPattern { + AnyGritPattern::GritPatternContains(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritPatternIfElse) -> AnyGritPattern { + AnyGritPattern::GritPatternIfElse(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritPatternIncludes) -> AnyGritPattern { + AnyGritPattern::GritPatternIncludes(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritPatternLimit) -> AnyGritPattern { + AnyGritPattern::GritPatternLimit(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritPatternMaybe) -> AnyGritPattern { + AnyGritPattern::GritPatternMaybe(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritPatternNot) -> AnyGritPattern { + AnyGritPattern::GritPatternNot(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritPatternOr) -> AnyGritPattern { + AnyGritPattern::GritPatternOr(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritPatternOrElse) -> AnyGritPattern { + AnyGritPattern::GritPatternOrElse(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritPatternWhere) -> AnyGritPattern { + AnyGritPattern::GritPatternWhere(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritRegexPattern) -> AnyGritPattern { + AnyGritPattern::GritRegexPattern(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritRewrite) -> AnyGritPattern { + AnyGritPattern::GritRewrite(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritSequential) -> AnyGritPattern { + AnyGritPattern::GritSequential(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritSome) -> AnyGritPattern { + AnyGritPattern::GritSome(node) } } -impl From for AnyGritListPattern { - fn from(node: AnyGritPattern) -> AnyGritListPattern { - AnyGritListPattern::AnyGritPattern(node) +impl From for AnyGritPattern { + fn from(node: GritSubOperation) -> AnyGritPattern { + AnyGritPattern::GritSubOperation(node) } } -impl From for AnyGritListPattern { - fn from(node: GritDotdotdot) -> AnyGritListPattern { - AnyGritListPattern::GritDotdotdot(node) +impl From for AnyGritPattern { + fn from(node: GritUnderscore) -> AnyGritPattern { + AnyGritPattern::GritUnderscore(node) } } -impl AstNode for AnyGritListPattern { +impl From for AnyGritPattern { + fn from(node: GritVariable) -> AnyGritPattern { + AnyGritPattern::GritVariable(node) + } +} +impl From for AnyGritPattern { + fn from(node: GritWithin) -> AnyGritPattern { + AnyGritPattern::GritWithin(node) + } +} +impl AstNode for AnyGritPattern { type Language = Language; - const KIND_SET: SyntaxKindSet = - AnyGritPattern::KIND_SET.union(GritDotdotdot::KIND_SET); + const KIND_SET: SyntaxKindSet = AnyGritLiteral::KIND_SET + .union(BracketedGritPattern::KIND_SET) + .union(GritAddOperation::KIND_SET) + .union(GritAssignmentAsPattern::KIND_SET) + .union(GritBogusPattern::KIND_SET) + .union(GritBubble::KIND_SET) + .union(GritDivOperation::KIND_SET) + .union(GritDot::KIND_SET) + .union(GritEvery::KIND_SET) + .union(GritFiles::KIND_SET) + .union(GritLike::KIND_SET) + .union(GritListAccessor::KIND_SET) + .union(GritMapAccessor::KIND_SET) + .union(GritModOperation::KIND_SET) + .union(GritMulOperation::KIND_SET) + .union(GritNodeLike::KIND_SET) + .union(GritPatternAccumulate::KIND_SET) + .union(GritPatternAfter::KIND_SET) + .union(GritPatternAnd::KIND_SET) + .union(GritPatternAny::KIND_SET) + .union(GritPatternAs::KIND_SET) + .union(GritPatternBefore::KIND_SET) + .union(GritPatternContains::KIND_SET) + .union(GritPatternIfElse::KIND_SET) + .union(GritPatternIncludes::KIND_SET) + .union(GritPatternLimit::KIND_SET) + .union(GritPatternMaybe::KIND_SET) + .union(GritPatternNot::KIND_SET) + .union(GritPatternOr::KIND_SET) + .union(GritPatternOrElse::KIND_SET) + .union(GritPatternWhere::KIND_SET) + .union(GritRegexPattern::KIND_SET) + .union(GritRewrite::KIND_SET) + .union(GritSequential::KIND_SET) + .union(GritSome::KIND_SET) + .union(GritSubOperation::KIND_SET) + .union(GritUnderscore::KIND_SET) + .union(GritVariable::KIND_SET) + .union(GritWithin::KIND_SET); fn can_cast(kind: SyntaxKind) -> bool { - matches!(kind, ANY_GRIT_PATTERN | GRIT_DOTDOTDOT) + match kind { + BRACKETED_GRIT_PATTERN + | GRIT_ADD_OPERATION + | GRIT_ASSIGNMENT_AS_PATTERN + | GRIT_BOGUS_PATTERN + | GRIT_BUBBLE + | GRIT_DIV_OPERATION + | GRIT_DOT + | GRIT_EVERY + | GRIT_FILES + | GRIT_LIKE + | GRIT_LIST_ACCESSOR + | GRIT_MAP_ACCESSOR + | GRIT_MOD_OPERATION + | GRIT_MUL_OPERATION + | GRIT_NODE_LIKE + | GRIT_PATTERN_ACCUMULATE + | GRIT_PATTERN_AFTER + | GRIT_PATTERN_AND + | GRIT_PATTERN_ANY + | GRIT_PATTERN_AS + | GRIT_PATTERN_BEFORE + | GRIT_PATTERN_CONTAINS + | GRIT_PATTERN_IF_ELSE + | GRIT_PATTERN_INCLUDES + | GRIT_PATTERN_LIMIT + | GRIT_PATTERN_MAYBE + | GRIT_PATTERN_NOT + | GRIT_PATTERN_OR + | GRIT_PATTERN_OR_ELSE + | GRIT_PATTERN_WHERE + | GRIT_REGEX_PATTERN + | GRIT_REWRITE + | GRIT_SEQUENTIAL + | GRIT_SOME + | GRIT_SUB_OPERATION + | GRIT_UNDERSCORE + | GRIT_VARIABLE + | GRIT_WITHIN => true, + k if AnyGritLiteral::can_cast(k) => true, + _ => false, + } } fn cast(syntax: SyntaxNode) -> Option { let res = match syntax.kind() { - ANY_GRIT_PATTERN => AnyGritListPattern::AnyGritPattern(AnyGritPattern { syntax }), - GRIT_DOTDOTDOT => AnyGritListPattern::GritDotdotdot(GritDotdotdot { syntax }), - _ => return None, + BRACKETED_GRIT_PATTERN => { + AnyGritPattern::BracketedGritPattern(BracketedGritPattern { syntax }) + } + GRIT_ADD_OPERATION => AnyGritPattern::GritAddOperation(GritAddOperation { syntax }), + GRIT_ASSIGNMENT_AS_PATTERN => { + AnyGritPattern::GritAssignmentAsPattern(GritAssignmentAsPattern { syntax }) + } + GRIT_BOGUS_PATTERN => AnyGritPattern::GritBogusPattern(GritBogusPattern { syntax }), + GRIT_BUBBLE => AnyGritPattern::GritBubble(GritBubble { syntax }), + GRIT_DIV_OPERATION => AnyGritPattern::GritDivOperation(GritDivOperation { syntax }), + GRIT_DOT => AnyGritPattern::GritDot(GritDot { syntax }), + GRIT_EVERY => AnyGritPattern::GritEvery(GritEvery { syntax }), + GRIT_FILES => AnyGritPattern::GritFiles(GritFiles { syntax }), + GRIT_LIKE => AnyGritPattern::GritLike(GritLike { syntax }), + GRIT_LIST_ACCESSOR => AnyGritPattern::GritListAccessor(GritListAccessor { syntax }), + GRIT_MAP_ACCESSOR => AnyGritPattern::GritMapAccessor(GritMapAccessor { syntax }), + GRIT_MOD_OPERATION => AnyGritPattern::GritModOperation(GritModOperation { syntax }), + GRIT_MUL_OPERATION => AnyGritPattern::GritMulOperation(GritMulOperation { syntax }), + GRIT_NODE_LIKE => AnyGritPattern::GritNodeLike(GritNodeLike { syntax }), + GRIT_PATTERN_ACCUMULATE => { + AnyGritPattern::GritPatternAccumulate(GritPatternAccumulate { syntax }) + } + GRIT_PATTERN_AFTER => AnyGritPattern::GritPatternAfter(GritPatternAfter { syntax }), + GRIT_PATTERN_AND => AnyGritPattern::GritPatternAnd(GritPatternAnd { syntax }), + GRIT_PATTERN_ANY => AnyGritPattern::GritPatternAny(GritPatternAny { syntax }), + GRIT_PATTERN_AS => AnyGritPattern::GritPatternAs(GritPatternAs { syntax }), + GRIT_PATTERN_BEFORE => AnyGritPattern::GritPatternBefore(GritPatternBefore { syntax }), + GRIT_PATTERN_CONTAINS => { + AnyGritPattern::GritPatternContains(GritPatternContains { syntax }) + } + GRIT_PATTERN_IF_ELSE => AnyGritPattern::GritPatternIfElse(GritPatternIfElse { syntax }), + GRIT_PATTERN_INCLUDES => { + AnyGritPattern::GritPatternIncludes(GritPatternIncludes { syntax }) + } + GRIT_PATTERN_LIMIT => AnyGritPattern::GritPatternLimit(GritPatternLimit { syntax }), + GRIT_PATTERN_MAYBE => AnyGritPattern::GritPatternMaybe(GritPatternMaybe { syntax }), + GRIT_PATTERN_NOT => AnyGritPattern::GritPatternNot(GritPatternNot { syntax }), + GRIT_PATTERN_OR => AnyGritPattern::GritPatternOr(GritPatternOr { syntax }), + GRIT_PATTERN_OR_ELSE => AnyGritPattern::GritPatternOrElse(GritPatternOrElse { syntax }), + GRIT_PATTERN_WHERE => AnyGritPattern::GritPatternWhere(GritPatternWhere { syntax }), + GRIT_REGEX_PATTERN => AnyGritPattern::GritRegexPattern(GritRegexPattern { syntax }), + GRIT_REWRITE => AnyGritPattern::GritRewrite(GritRewrite { syntax }), + GRIT_SEQUENTIAL => AnyGritPattern::GritSequential(GritSequential { syntax }), + GRIT_SOME => AnyGritPattern::GritSome(GritSome { syntax }), + GRIT_SUB_OPERATION => AnyGritPattern::GritSubOperation(GritSubOperation { syntax }), + GRIT_UNDERSCORE => AnyGritPattern::GritUnderscore(GritUnderscore { syntax }), + GRIT_VARIABLE => AnyGritPattern::GritVariable(GritVariable { syntax }), + GRIT_WITHIN => AnyGritPattern::GritWithin(GritWithin { syntax }), + _ => { + if let Some(any_grit_literal) = AnyGritLiteral::cast(syntax) { + return Some(AnyGritPattern::AnyGritLiteral(any_grit_literal)); + } + return None; + } }; Some(res) } fn syntax(&self) -> &SyntaxNode { match self { - AnyGritListPattern::AnyGritPattern(it) => &it.syntax, - AnyGritListPattern::GritDotdotdot(it) => &it.syntax, + AnyGritPattern::BracketedGritPattern(it) => &it.syntax, + AnyGritPattern::GritAddOperation(it) => &it.syntax, + AnyGritPattern::GritAssignmentAsPattern(it) => &it.syntax, + AnyGritPattern::GritBogusPattern(it) => &it.syntax, + AnyGritPattern::GritBubble(it) => &it.syntax, + AnyGritPattern::GritDivOperation(it) => &it.syntax, + AnyGritPattern::GritDot(it) => &it.syntax, + AnyGritPattern::GritEvery(it) => &it.syntax, + AnyGritPattern::GritFiles(it) => &it.syntax, + AnyGritPattern::GritLike(it) => &it.syntax, + AnyGritPattern::GritListAccessor(it) => &it.syntax, + AnyGritPattern::GritMapAccessor(it) => &it.syntax, + AnyGritPattern::GritModOperation(it) => &it.syntax, + AnyGritPattern::GritMulOperation(it) => &it.syntax, + AnyGritPattern::GritNodeLike(it) => &it.syntax, + AnyGritPattern::GritPatternAccumulate(it) => &it.syntax, + AnyGritPattern::GritPatternAfter(it) => &it.syntax, + AnyGritPattern::GritPatternAnd(it) => &it.syntax, + AnyGritPattern::GritPatternAny(it) => &it.syntax, + AnyGritPattern::GritPatternAs(it) => &it.syntax, + AnyGritPattern::GritPatternBefore(it) => &it.syntax, + AnyGritPattern::GritPatternContains(it) => &it.syntax, + AnyGritPattern::GritPatternIfElse(it) => &it.syntax, + AnyGritPattern::GritPatternIncludes(it) => &it.syntax, + AnyGritPattern::GritPatternLimit(it) => &it.syntax, + AnyGritPattern::GritPatternMaybe(it) => &it.syntax, + AnyGritPattern::GritPatternNot(it) => &it.syntax, + AnyGritPattern::GritPatternOr(it) => &it.syntax, + AnyGritPattern::GritPatternOrElse(it) => &it.syntax, + AnyGritPattern::GritPatternWhere(it) => &it.syntax, + AnyGritPattern::GritRegexPattern(it) => &it.syntax, + AnyGritPattern::GritRewrite(it) => &it.syntax, + AnyGritPattern::GritSequential(it) => &it.syntax, + AnyGritPattern::GritSome(it) => &it.syntax, + AnyGritPattern::GritSubOperation(it) => &it.syntax, + AnyGritPattern::GritUnderscore(it) => &it.syntax, + AnyGritPattern::GritVariable(it) => &it.syntax, + AnyGritPattern::GritWithin(it) => &it.syntax, + AnyGritPattern::AnyGritLiteral(it) => it.syntax(), } } fn into_syntax(self) -> SyntaxNode { match self { - AnyGritListPattern::AnyGritPattern(it) => it.syntax, - AnyGritListPattern::GritDotdotdot(it) => it.syntax, + AnyGritPattern::BracketedGritPattern(it) => it.syntax, + AnyGritPattern::GritAddOperation(it) => it.syntax, + AnyGritPattern::GritAssignmentAsPattern(it) => it.syntax, + AnyGritPattern::GritBogusPattern(it) => it.syntax, + AnyGritPattern::GritBubble(it) => it.syntax, + AnyGritPattern::GritDivOperation(it) => it.syntax, + AnyGritPattern::GritDot(it) => it.syntax, + AnyGritPattern::GritEvery(it) => it.syntax, + AnyGritPattern::GritFiles(it) => it.syntax, + AnyGritPattern::GritLike(it) => it.syntax, + AnyGritPattern::GritListAccessor(it) => it.syntax, + AnyGritPattern::GritMapAccessor(it) => it.syntax, + AnyGritPattern::GritModOperation(it) => it.syntax, + AnyGritPattern::GritMulOperation(it) => it.syntax, + AnyGritPattern::GritNodeLike(it) => it.syntax, + AnyGritPattern::GritPatternAccumulate(it) => it.syntax, + AnyGritPattern::GritPatternAfter(it) => it.syntax, + AnyGritPattern::GritPatternAnd(it) => it.syntax, + AnyGritPattern::GritPatternAny(it) => it.syntax, + AnyGritPattern::GritPatternAs(it) => it.syntax, + AnyGritPattern::GritPatternBefore(it) => it.syntax, + AnyGritPattern::GritPatternContains(it) => it.syntax, + AnyGritPattern::GritPatternIfElse(it) => it.syntax, + AnyGritPattern::GritPatternIncludes(it) => it.syntax, + AnyGritPattern::GritPatternLimit(it) => it.syntax, + AnyGritPattern::GritPatternMaybe(it) => it.syntax, + AnyGritPattern::GritPatternNot(it) => it.syntax, + AnyGritPattern::GritPatternOr(it) => it.syntax, + AnyGritPattern::GritPatternOrElse(it) => it.syntax, + AnyGritPattern::GritPatternWhere(it) => it.syntax, + AnyGritPattern::GritRegexPattern(it) => it.syntax, + AnyGritPattern::GritRewrite(it) => it.syntax, + AnyGritPattern::GritSequential(it) => it.syntax, + AnyGritPattern::GritSome(it) => it.syntax, + AnyGritPattern::GritSubOperation(it) => it.syntax, + AnyGritPattern::GritUnderscore(it) => it.syntax, + AnyGritPattern::GritVariable(it) => it.syntax, + AnyGritPattern::GritWithin(it) => it.syntax, + AnyGritPattern::AnyGritLiteral(it) => it.into_syntax(), } } } -impl std::fmt::Debug for AnyGritListPattern { +impl std::fmt::Debug for AnyGritPattern { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - AnyGritListPattern::AnyGritPattern(it) => std::fmt::Debug::fmt(it, f), - AnyGritListPattern::GritDotdotdot(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::AnyGritLiteral(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::BracketedGritPattern(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritAddOperation(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritAssignmentAsPattern(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritBogusPattern(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritBubble(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritDivOperation(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritDot(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritEvery(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritFiles(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritLike(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritListAccessor(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritMapAccessor(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritModOperation(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritMulOperation(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritNodeLike(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritPatternAccumulate(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritPatternAfter(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritPatternAnd(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritPatternAny(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritPatternAs(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritPatternBefore(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritPatternContains(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritPatternIfElse(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritPatternIncludes(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritPatternLimit(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritPatternMaybe(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritPatternNot(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritPatternOr(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritPatternOrElse(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritPatternWhere(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritRegexPattern(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritRewrite(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritSequential(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritSome(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritSubOperation(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritUnderscore(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritVariable(it) => std::fmt::Debug::fmt(it, f), + AnyGritPattern::GritWithin(it) => std::fmt::Debug::fmt(it, f), } } } -impl From for SyntaxNode { - fn from(n: AnyGritListPattern) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: AnyGritPattern) -> SyntaxNode { match n { - AnyGritListPattern::AnyGritPattern(it) => it.into(), - AnyGritListPattern::GritDotdotdot(it) => it.into(), + AnyGritPattern::AnyGritLiteral(it) => it.into(), + AnyGritPattern::BracketedGritPattern(it) => it.into(), + AnyGritPattern::GritAddOperation(it) => it.into(), + AnyGritPattern::GritAssignmentAsPattern(it) => it.into(), + AnyGritPattern::GritBogusPattern(it) => it.into(), + AnyGritPattern::GritBubble(it) => it.into(), + AnyGritPattern::GritDivOperation(it) => it.into(), + AnyGritPattern::GritDot(it) => it.into(), + AnyGritPattern::GritEvery(it) => it.into(), + AnyGritPattern::GritFiles(it) => it.into(), + AnyGritPattern::GritLike(it) => it.into(), + AnyGritPattern::GritListAccessor(it) => it.into(), + AnyGritPattern::GritMapAccessor(it) => it.into(), + AnyGritPattern::GritModOperation(it) => it.into(), + AnyGritPattern::GritMulOperation(it) => it.into(), + AnyGritPattern::GritNodeLike(it) => it.into(), + AnyGritPattern::GritPatternAccumulate(it) => it.into(), + AnyGritPattern::GritPatternAfter(it) => it.into(), + AnyGritPattern::GritPatternAnd(it) => it.into(), + AnyGritPattern::GritPatternAny(it) => it.into(), + AnyGritPattern::GritPatternAs(it) => it.into(), + AnyGritPattern::GritPatternBefore(it) => it.into(), + AnyGritPattern::GritPatternContains(it) => it.into(), + AnyGritPattern::GritPatternIfElse(it) => it.into(), + AnyGritPattern::GritPatternIncludes(it) => it.into(), + AnyGritPattern::GritPatternLimit(it) => it.into(), + AnyGritPattern::GritPatternMaybe(it) => it.into(), + AnyGritPattern::GritPatternNot(it) => it.into(), + AnyGritPattern::GritPatternOr(it) => it.into(), + AnyGritPattern::GritPatternOrElse(it) => it.into(), + AnyGritPattern::GritPatternWhere(it) => it.into(), + AnyGritPattern::GritRegexPattern(it) => it.into(), + AnyGritPattern::GritRewrite(it) => it.into(), + AnyGritPattern::GritSequential(it) => it.into(), + AnyGritPattern::GritSome(it) => it.into(), + AnyGritPattern::GritSubOperation(it) => it.into(), + AnyGritPattern::GritUnderscore(it) => it.into(), + AnyGritPattern::GritVariable(it) => it.into(), + AnyGritPattern::GritWithin(it) => it.into(), } } } -impl From for SyntaxElement { - fn from(n: AnyGritListPattern) -> SyntaxElement { +impl From for SyntaxElement { + fn from(n: AnyGritPattern) -> SyntaxElement { let node: SyntaxNode = n.into(); node.into() } } -impl From for AnyGritLiteral { - fn from(node: GritBogusLiteral) -> AnyGritLiteral { - AnyGritLiteral::GritBogusLiteral(node) +impl From for AnyGritPredicate { + fn from(node: BracketedGritPredicate) -> AnyGritPredicate { + AnyGritPredicate::BracketedGritPredicate(node) } } -impl From for AnyGritLiteral { - fn from(node: GritBooleanValue) -> AnyGritLiteral { - AnyGritLiteral::GritBooleanValue(node) +impl From for AnyGritPredicate { + fn from(node: GritBogusPredicate) -> AnyGritPredicate { + AnyGritPredicate::GritBogusPredicate(node) } } -impl From for AnyGritLiteral { - fn from(node: GritCodeSnippet) -> AnyGritLiteral { - AnyGritLiteral::GritCodeSnippet(node) +impl From for AnyGritPredicate { + fn from(node: GritBooleanLiteral) -> AnyGritPredicate { + AnyGritPredicate::GritBooleanLiteral(node) } } -impl From for AnyGritLiteral { - fn from(node: GritDoubleValue) -> AnyGritLiteral { - AnyGritLiteral::GritDoubleValue(node) +impl From for AnyGritPredicate { + fn from(node: GritPredicateAccumulate) -> AnyGritPredicate { + AnyGritPredicate::GritPredicateAccumulate(node) } } -impl From for AnyGritLiteral { - fn from(node: GritIntValue) -> AnyGritLiteral { - AnyGritLiteral::GritIntValue(node) +impl From for AnyGritPredicate { + fn from(node: GritPredicateAnd) -> AnyGritPredicate { + AnyGritPredicate::GritPredicateAnd(node) } } -impl From for AnyGritLiteral { - fn from(node: GritList) -> AnyGritLiteral { - AnyGritLiteral::GritList(node) +impl From for AnyGritPredicate { + fn from(node: GritPredicateAny) -> AnyGritPredicate { + AnyGritPredicate::GritPredicateAny(node) } } -impl From for AnyGritLiteral { - fn from(node: GritMap) -> AnyGritLiteral { - AnyGritLiteral::GritMap(node) +impl From for AnyGritPredicate { + fn from(node: GritPredicateAssignment) -> AnyGritPredicate { + AnyGritPredicate::GritPredicateAssignment(node) } } -impl From for AnyGritLiteral { - fn from(node: GritStringValue) -> AnyGritLiteral { - AnyGritLiteral::GritStringValue(node) +impl From for AnyGritPredicate { + fn from(node: GritPredicateCall) -> AnyGritPredicate { + AnyGritPredicate::GritPredicateCall(node) } } -impl From for AnyGritLiteral { - fn from(node: GritUndefined) -> AnyGritLiteral { - AnyGritLiteral::GritUndefined(node) +impl From for AnyGritPredicate { + fn from(node: GritPredicateEqual) -> AnyGritPredicate { + AnyGritPredicate::GritPredicateEqual(node) } } -impl AstNode for AnyGritLiteral { +impl From for AnyGritPredicate { + fn from(node: GritPredicateGreater) -> AnyGritPredicate { + AnyGritPredicate::GritPredicateGreater(node) + } +} +impl From for AnyGritPredicate { + fn from(node: GritPredicateGreaterEqual) -> AnyGritPredicate { + AnyGritPredicate::GritPredicateGreaterEqual(node) + } +} +impl From for AnyGritPredicate { + fn from(node: GritPredicateIfElse) -> AnyGritPredicate { + AnyGritPredicate::GritPredicateIfElse(node) + } +} +impl From for AnyGritPredicate { + fn from(node: GritPredicateLess) -> AnyGritPredicate { + AnyGritPredicate::GritPredicateLess(node) + } +} +impl From for AnyGritPredicate { + fn from(node: GritPredicateLessEqual) -> AnyGritPredicate { + AnyGritPredicate::GritPredicateLessEqual(node) + } +} +impl From for AnyGritPredicate { + fn from(node: GritPredicateMatch) -> AnyGritPredicate { + AnyGritPredicate::GritPredicateMatch(node) + } +} +impl From for AnyGritPredicate { + fn from(node: GritPredicateMaybe) -> AnyGritPredicate { + AnyGritPredicate::GritPredicateMaybe(node) + } +} +impl From for AnyGritPredicate { + fn from(node: GritPredicateNot) -> AnyGritPredicate { + AnyGritPredicate::GritPredicateNot(node) + } +} +impl From for AnyGritPredicate { + fn from(node: GritPredicateNotEqual) -> AnyGritPredicate { + AnyGritPredicate::GritPredicateNotEqual(node) + } +} +impl From for AnyGritPredicate { + fn from(node: GritPredicateOr) -> AnyGritPredicate { + AnyGritPredicate::GritPredicateOr(node) + } +} +impl From for AnyGritPredicate { + fn from(node: GritPredicateReturn) -> AnyGritPredicate { + AnyGritPredicate::GritPredicateReturn(node) + } +} +impl From for AnyGritPredicate { + fn from(node: GritPredicateRewrite) -> AnyGritPredicate { + AnyGritPredicate::GritPredicateRewrite(node) + } +} +impl AstNode for AnyGritPredicate { type Language = Language; - const KIND_SET: SyntaxKindSet = GritBogusLiteral::KIND_SET - .union(GritBooleanValue::KIND_SET) - .union(GritCodeSnippet::KIND_SET) - .union(GritDoubleValue::KIND_SET) - .union(GritIntValue::KIND_SET) - .union(GritList::KIND_SET) - .union(GritMap::KIND_SET) - .union(GritStringValue::KIND_SET) - .union(GritUndefined::KIND_SET); + const KIND_SET: SyntaxKindSet = BracketedGritPredicate::KIND_SET + .union(GritBogusPredicate::KIND_SET) + .union(GritBooleanLiteral::KIND_SET) + .union(GritPredicateAccumulate::KIND_SET) + .union(GritPredicateAnd::KIND_SET) + .union(GritPredicateAny::KIND_SET) + .union(GritPredicateAssignment::KIND_SET) + .union(GritPredicateCall::KIND_SET) + .union(GritPredicateEqual::KIND_SET) + .union(GritPredicateGreater::KIND_SET) + .union(GritPredicateGreaterEqual::KIND_SET) + .union(GritPredicateIfElse::KIND_SET) + .union(GritPredicateLess::KIND_SET) + .union(GritPredicateLessEqual::KIND_SET) + .union(GritPredicateMatch::KIND_SET) + .union(GritPredicateMaybe::KIND_SET) + .union(GritPredicateNot::KIND_SET) + .union(GritPredicateNotEqual::KIND_SET) + .union(GritPredicateOr::KIND_SET) + .union(GritPredicateReturn::KIND_SET) + .union(GritPredicateRewrite::KIND_SET); fn can_cast(kind: SyntaxKind) -> bool { matches!( kind, - GRIT_BOGUS_LITERAL - | GRIT_BOOLEAN_VALUE - | GRIT_CODE_SNIPPET - | GRIT_DOUBLE_VALUE - | GRIT_INT_VALUE - | GRIT_LIST - | GRIT_MAP - | GRIT_STRING_VALUE - | GRIT_UNDEFINED + BRACKETED_GRIT_PREDICATE + | GRIT_BOGUS_PREDICATE + | GRIT_BOOLEAN_LITERAL + | GRIT_PREDICATE_ACCUMULATE + | GRIT_PREDICATE_AND + | GRIT_PREDICATE_ANY + | GRIT_PREDICATE_ASSIGNMENT + | GRIT_PREDICATE_CALL + | GRIT_PREDICATE_EQUAL + | GRIT_PREDICATE_GREATER + | GRIT_PREDICATE_GREATER_EQUAL + | GRIT_PREDICATE_IF_ELSE + | GRIT_PREDICATE_LESS + | GRIT_PREDICATE_LESS_EQUAL + | GRIT_PREDICATE_MATCH + | GRIT_PREDICATE_MAYBE + | GRIT_PREDICATE_NOT + | GRIT_PREDICATE_NOT_EQUAL + | GRIT_PREDICATE_OR + | GRIT_PREDICATE_RETURN + | GRIT_PREDICATE_REWRITE ) } fn cast(syntax: SyntaxNode) -> Option { let res = match syntax.kind() { - GRIT_BOGUS_LITERAL => AnyGritLiteral::GritBogusLiteral(GritBogusLiteral { syntax }), - GRIT_BOOLEAN_VALUE => AnyGritLiteral::GritBooleanValue(GritBooleanValue { syntax }), - GRIT_CODE_SNIPPET => AnyGritLiteral::GritCodeSnippet(GritCodeSnippet { syntax }), - GRIT_DOUBLE_VALUE => AnyGritLiteral::GritDoubleValue(GritDoubleValue { syntax }), - GRIT_INT_VALUE => AnyGritLiteral::GritIntValue(GritIntValue { syntax }), - GRIT_LIST => AnyGritLiteral::GritList(GritList { syntax }), - GRIT_MAP => AnyGritLiteral::GritMap(GritMap { syntax }), - GRIT_STRING_VALUE => AnyGritLiteral::GritStringValue(GritStringValue { syntax }), - GRIT_UNDEFINED => AnyGritLiteral::GritUndefined(GritUndefined { syntax }), + BRACKETED_GRIT_PREDICATE => { + AnyGritPredicate::BracketedGritPredicate(BracketedGritPredicate { syntax }) + } + GRIT_BOGUS_PREDICATE => { + AnyGritPredicate::GritBogusPredicate(GritBogusPredicate { syntax }) + } + GRIT_BOOLEAN_LITERAL => { + AnyGritPredicate::GritBooleanLiteral(GritBooleanLiteral { syntax }) + } + GRIT_PREDICATE_ACCUMULATE => { + AnyGritPredicate::GritPredicateAccumulate(GritPredicateAccumulate { syntax }) + } + GRIT_PREDICATE_AND => AnyGritPredicate::GritPredicateAnd(GritPredicateAnd { syntax }), + GRIT_PREDICATE_ANY => AnyGritPredicate::GritPredicateAny(GritPredicateAny { syntax }), + GRIT_PREDICATE_ASSIGNMENT => { + AnyGritPredicate::GritPredicateAssignment(GritPredicateAssignment { syntax }) + } + GRIT_PREDICATE_CALL => { + AnyGritPredicate::GritPredicateCall(GritPredicateCall { syntax }) + } + GRIT_PREDICATE_EQUAL => { + AnyGritPredicate::GritPredicateEqual(GritPredicateEqual { syntax }) + } + GRIT_PREDICATE_GREATER => { + AnyGritPredicate::GritPredicateGreater(GritPredicateGreater { syntax }) + } + GRIT_PREDICATE_GREATER_EQUAL => { + AnyGritPredicate::GritPredicateGreaterEqual(GritPredicateGreaterEqual { syntax }) + } + GRIT_PREDICATE_IF_ELSE => { + AnyGritPredicate::GritPredicateIfElse(GritPredicateIfElse { syntax }) + } + GRIT_PREDICATE_LESS => { + AnyGritPredicate::GritPredicateLess(GritPredicateLess { syntax }) + } + GRIT_PREDICATE_LESS_EQUAL => { + AnyGritPredicate::GritPredicateLessEqual(GritPredicateLessEqual { syntax }) + } + GRIT_PREDICATE_MATCH => { + AnyGritPredicate::GritPredicateMatch(GritPredicateMatch { syntax }) + } + GRIT_PREDICATE_MAYBE => { + AnyGritPredicate::GritPredicateMaybe(GritPredicateMaybe { syntax }) + } + GRIT_PREDICATE_NOT => AnyGritPredicate::GritPredicateNot(GritPredicateNot { syntax }), + GRIT_PREDICATE_NOT_EQUAL => { + AnyGritPredicate::GritPredicateNotEqual(GritPredicateNotEqual { syntax }) + } + GRIT_PREDICATE_OR => AnyGritPredicate::GritPredicateOr(GritPredicateOr { syntax }), + GRIT_PREDICATE_RETURN => { + AnyGritPredicate::GritPredicateReturn(GritPredicateReturn { syntax }) + } + GRIT_PREDICATE_REWRITE => { + AnyGritPredicate::GritPredicateRewrite(GritPredicateRewrite { syntax }) + } _ => return None, }; Some(res) } fn syntax(&self) -> &SyntaxNode { match self { - AnyGritLiteral::GritBogusLiteral(it) => &it.syntax, - AnyGritLiteral::GritBooleanValue(it) => &it.syntax, - AnyGritLiteral::GritCodeSnippet(it) => &it.syntax, - AnyGritLiteral::GritDoubleValue(it) => &it.syntax, - AnyGritLiteral::GritIntValue(it) => &it.syntax, - AnyGritLiteral::GritList(it) => &it.syntax, - AnyGritLiteral::GritMap(it) => &it.syntax, - AnyGritLiteral::GritStringValue(it) => &it.syntax, - AnyGritLiteral::GritUndefined(it) => &it.syntax, + AnyGritPredicate::BracketedGritPredicate(it) => &it.syntax, + AnyGritPredicate::GritBogusPredicate(it) => &it.syntax, + AnyGritPredicate::GritBooleanLiteral(it) => &it.syntax, + AnyGritPredicate::GritPredicateAccumulate(it) => &it.syntax, + AnyGritPredicate::GritPredicateAnd(it) => &it.syntax, + AnyGritPredicate::GritPredicateAny(it) => &it.syntax, + AnyGritPredicate::GritPredicateAssignment(it) => &it.syntax, + AnyGritPredicate::GritPredicateCall(it) => &it.syntax, + AnyGritPredicate::GritPredicateEqual(it) => &it.syntax, + AnyGritPredicate::GritPredicateGreater(it) => &it.syntax, + AnyGritPredicate::GritPredicateGreaterEqual(it) => &it.syntax, + AnyGritPredicate::GritPredicateIfElse(it) => &it.syntax, + AnyGritPredicate::GritPredicateLess(it) => &it.syntax, + AnyGritPredicate::GritPredicateLessEqual(it) => &it.syntax, + AnyGritPredicate::GritPredicateMatch(it) => &it.syntax, + AnyGritPredicate::GritPredicateMaybe(it) => &it.syntax, + AnyGritPredicate::GritPredicateNot(it) => &it.syntax, + AnyGritPredicate::GritPredicateNotEqual(it) => &it.syntax, + AnyGritPredicate::GritPredicateOr(it) => &it.syntax, + AnyGritPredicate::GritPredicateReturn(it) => &it.syntax, + AnyGritPredicate::GritPredicateRewrite(it) => &it.syntax, } } fn into_syntax(self) -> SyntaxNode { match self { - AnyGritLiteral::GritBogusLiteral(it) => it.syntax, - AnyGritLiteral::GritBooleanValue(it) => it.syntax, - AnyGritLiteral::GritCodeSnippet(it) => it.syntax, - AnyGritLiteral::GritDoubleValue(it) => it.syntax, - AnyGritLiteral::GritIntValue(it) => it.syntax, - AnyGritLiteral::GritList(it) => it.syntax, - AnyGritLiteral::GritMap(it) => it.syntax, - AnyGritLiteral::GritStringValue(it) => it.syntax, - AnyGritLiteral::GritUndefined(it) => it.syntax, + AnyGritPredicate::BracketedGritPredicate(it) => it.syntax, + AnyGritPredicate::GritBogusPredicate(it) => it.syntax, + AnyGritPredicate::GritBooleanLiteral(it) => it.syntax, + AnyGritPredicate::GritPredicateAccumulate(it) => it.syntax, + AnyGritPredicate::GritPredicateAnd(it) => it.syntax, + AnyGritPredicate::GritPredicateAny(it) => it.syntax, + AnyGritPredicate::GritPredicateAssignment(it) => it.syntax, + AnyGritPredicate::GritPredicateCall(it) => it.syntax, + AnyGritPredicate::GritPredicateEqual(it) => it.syntax, + AnyGritPredicate::GritPredicateGreater(it) => it.syntax, + AnyGritPredicate::GritPredicateGreaterEqual(it) => it.syntax, + AnyGritPredicate::GritPredicateIfElse(it) => it.syntax, + AnyGritPredicate::GritPredicateLess(it) => it.syntax, + AnyGritPredicate::GritPredicateLessEqual(it) => it.syntax, + AnyGritPredicate::GritPredicateMatch(it) => it.syntax, + AnyGritPredicate::GritPredicateMaybe(it) => it.syntax, + AnyGritPredicate::GritPredicateNot(it) => it.syntax, + AnyGritPredicate::GritPredicateNotEqual(it) => it.syntax, + AnyGritPredicate::GritPredicateOr(it) => it.syntax, + AnyGritPredicate::GritPredicateReturn(it) => it.syntax, + AnyGritPredicate::GritPredicateRewrite(it) => it.syntax, } } } -impl std::fmt::Debug for AnyGritLiteral { +impl std::fmt::Debug for AnyGritPredicate { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - AnyGritLiteral::GritBogusLiteral(it) => std::fmt::Debug::fmt(it, f), - AnyGritLiteral::GritBooleanValue(it) => std::fmt::Debug::fmt(it, f), - AnyGritLiteral::GritCodeSnippet(it) => std::fmt::Debug::fmt(it, f), - AnyGritLiteral::GritDoubleValue(it) => std::fmt::Debug::fmt(it, f), - AnyGritLiteral::GritIntValue(it) => std::fmt::Debug::fmt(it, f), - AnyGritLiteral::GritList(it) => std::fmt::Debug::fmt(it, f), - AnyGritLiteral::GritMap(it) => std::fmt::Debug::fmt(it, f), - AnyGritLiteral::GritStringValue(it) => std::fmt::Debug::fmt(it, f), - AnyGritLiteral::GritUndefined(it) => std::fmt::Debug::fmt(it, f), + AnyGritPredicate::BracketedGritPredicate(it) => std::fmt::Debug::fmt(it, f), + AnyGritPredicate::GritBogusPredicate(it) => std::fmt::Debug::fmt(it, f), + AnyGritPredicate::GritBooleanLiteral(it) => std::fmt::Debug::fmt(it, f), + AnyGritPredicate::GritPredicateAccumulate(it) => std::fmt::Debug::fmt(it, f), + AnyGritPredicate::GritPredicateAnd(it) => std::fmt::Debug::fmt(it, f), + AnyGritPredicate::GritPredicateAny(it) => std::fmt::Debug::fmt(it, f), + AnyGritPredicate::GritPredicateAssignment(it) => std::fmt::Debug::fmt(it, f), + AnyGritPredicate::GritPredicateCall(it) => std::fmt::Debug::fmt(it, f), + AnyGritPredicate::GritPredicateEqual(it) => std::fmt::Debug::fmt(it, f), + AnyGritPredicate::GritPredicateGreater(it) => std::fmt::Debug::fmt(it, f), + AnyGritPredicate::GritPredicateGreaterEqual(it) => std::fmt::Debug::fmt(it, f), + AnyGritPredicate::GritPredicateIfElse(it) => std::fmt::Debug::fmt(it, f), + AnyGritPredicate::GritPredicateLess(it) => std::fmt::Debug::fmt(it, f), + AnyGritPredicate::GritPredicateLessEqual(it) => std::fmt::Debug::fmt(it, f), + AnyGritPredicate::GritPredicateMatch(it) => std::fmt::Debug::fmt(it, f), + AnyGritPredicate::GritPredicateMaybe(it) => std::fmt::Debug::fmt(it, f), + AnyGritPredicate::GritPredicateNot(it) => std::fmt::Debug::fmt(it, f), + AnyGritPredicate::GritPredicateNotEqual(it) => std::fmt::Debug::fmt(it, f), + AnyGritPredicate::GritPredicateOr(it) => std::fmt::Debug::fmt(it, f), + AnyGritPredicate::GritPredicateReturn(it) => std::fmt::Debug::fmt(it, f), + AnyGritPredicate::GritPredicateRewrite(it) => std::fmt::Debug::fmt(it, f), } } } -impl From for SyntaxNode { - fn from(n: AnyGritLiteral) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: AnyGritPredicate) -> SyntaxNode { match n { - AnyGritLiteral::GritBogusLiteral(it) => it.into(), - AnyGritLiteral::GritBooleanValue(it) => it.into(), - AnyGritLiteral::GritCodeSnippet(it) => it.into(), - AnyGritLiteral::GritDoubleValue(it) => it.into(), - AnyGritLiteral::GritIntValue(it) => it.into(), - AnyGritLiteral::GritList(it) => it.into(), - AnyGritLiteral::GritMap(it) => it.into(), - AnyGritLiteral::GritStringValue(it) => it.into(), - AnyGritLiteral::GritUndefined(it) => it.into(), + AnyGritPredicate::BracketedGritPredicate(it) => it.into(), + AnyGritPredicate::GritBogusPredicate(it) => it.into(), + AnyGritPredicate::GritBooleanLiteral(it) => it.into(), + AnyGritPredicate::GritPredicateAccumulate(it) => it.into(), + AnyGritPredicate::GritPredicateAnd(it) => it.into(), + AnyGritPredicate::GritPredicateAny(it) => it.into(), + AnyGritPredicate::GritPredicateAssignment(it) => it.into(), + AnyGritPredicate::GritPredicateCall(it) => it.into(), + AnyGritPredicate::GritPredicateEqual(it) => it.into(), + AnyGritPredicate::GritPredicateGreater(it) => it.into(), + AnyGritPredicate::GritPredicateGreaterEqual(it) => it.into(), + AnyGritPredicate::GritPredicateIfElse(it) => it.into(), + AnyGritPredicate::GritPredicateLess(it) => it.into(), + AnyGritPredicate::GritPredicateLessEqual(it) => it.into(), + AnyGritPredicate::GritPredicateMatch(it) => it.into(), + AnyGritPredicate::GritPredicateMaybe(it) => it.into(), + AnyGritPredicate::GritPredicateNot(it) => it.into(), + AnyGritPredicate::GritPredicateNotEqual(it) => it.into(), + AnyGritPredicate::GritPredicateOr(it) => it.into(), + AnyGritPredicate::GritPredicateReturn(it) => it.into(), + AnyGritPredicate::GritPredicateRewrite(it) => it.into(), } } } -impl From for SyntaxElement { - fn from(n: AnyGritLiteral) -> SyntaxElement { +impl From for SyntaxElement { + fn from(n: AnyGritPredicate) -> SyntaxElement { let node: SyntaxNode = n.into(); node.into() } } -impl From for AnyGritNamedArg { - fn from(node: GritBogusNamedArg) -> AnyGritNamedArg { - AnyGritNamedArg::GritBogusNamedArg(node) - } -} -impl From for AnyGritNamedArg { - fn from(node: GritNamedArg) -> AnyGritNamedArg { - AnyGritNamedArg::GritNamedArg(node) +impl From for AnyGritRegex { + fn from(node: GritRegexLiteral) -> AnyGritRegex { + AnyGritRegex::GritRegexLiteral(node) } } -impl From for AnyGritNamedArg { - fn from(node: GritNamedArgWithDefault) -> AnyGritNamedArg { - AnyGritNamedArg::GritNamedArgWithDefault(node) +impl From for AnyGritRegex { + fn from(node: GritSnippetRegexLiteral) -> AnyGritRegex { + AnyGritRegex::GritSnippetRegexLiteral(node) } } -impl AstNode for AnyGritNamedArg { +impl AstNode for AnyGritRegex { type Language = Language; - const KIND_SET: SyntaxKindSet = GritBogusNamedArg::KIND_SET - .union(GritNamedArg::KIND_SET) - .union(GritNamedArgWithDefault::KIND_SET); + const KIND_SET: SyntaxKindSet = + GritRegexLiteral::KIND_SET.union(GritSnippetRegexLiteral::KIND_SET); fn can_cast(kind: SyntaxKind) -> bool { - matches!( - kind, - GRIT_BOGUS_NAMED_ARG | GRIT_NAMED_ARG | GRIT_NAMED_ARG_WITH_DEFAULT - ) + matches!(kind, GRIT_REGEX_LITERAL | GRIT_SNIPPET_REGEX_LITERAL) } fn cast(syntax: SyntaxNode) -> Option { let res = match syntax.kind() { - GRIT_BOGUS_NAMED_ARG => { - AnyGritNamedArg::GritBogusNamedArg(GritBogusNamedArg { syntax }) - } - GRIT_NAMED_ARG => AnyGritNamedArg::GritNamedArg(GritNamedArg { syntax }), - GRIT_NAMED_ARG_WITH_DEFAULT => { - AnyGritNamedArg::GritNamedArgWithDefault(GritNamedArgWithDefault { syntax }) + GRIT_REGEX_LITERAL => AnyGritRegex::GritRegexLiteral(GritRegexLiteral { syntax }), + GRIT_SNIPPET_REGEX_LITERAL => { + AnyGritRegex::GritSnippetRegexLiteral(GritSnippetRegexLiteral { syntax }) } _ => return None, }; @@ -9903,46 +10723,42 @@ impl AstNode for AnyGritNamedArg { } fn syntax(&self) -> &SyntaxNode { match self { - AnyGritNamedArg::GritBogusNamedArg(it) => &it.syntax, - AnyGritNamedArg::GritNamedArg(it) => &it.syntax, - AnyGritNamedArg::GritNamedArgWithDefault(it) => &it.syntax, + AnyGritRegex::GritRegexLiteral(it) => &it.syntax, + AnyGritRegex::GritSnippetRegexLiteral(it) => &it.syntax, } } fn into_syntax(self) -> SyntaxNode { match self { - AnyGritNamedArg::GritBogusNamedArg(it) => it.syntax, - AnyGritNamedArg::GritNamedArg(it) => it.syntax, - AnyGritNamedArg::GritNamedArgWithDefault(it) => it.syntax, + AnyGritRegex::GritRegexLiteral(it) => it.syntax, + AnyGritRegex::GritSnippetRegexLiteral(it) => it.syntax, } } } -impl std::fmt::Debug for AnyGritNamedArg { +impl std::fmt::Debug for AnyGritRegex { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - AnyGritNamedArg::GritBogusNamedArg(it) => std::fmt::Debug::fmt(it, f), - AnyGritNamedArg::GritNamedArg(it) => std::fmt::Debug::fmt(it, f), - AnyGritNamedArg::GritNamedArgWithDefault(it) => std::fmt::Debug::fmt(it, f), + AnyGritRegex::GritRegexLiteral(it) => std::fmt::Debug::fmt(it, f), + AnyGritRegex::GritSnippetRegexLiteral(it) => std::fmt::Debug::fmt(it, f), } } } -impl From for SyntaxNode { - fn from(n: AnyGritNamedArg) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: AnyGritRegex) -> SyntaxNode { match n { - AnyGritNamedArg::GritBogusNamedArg(it) => it.into(), - AnyGritNamedArg::GritNamedArg(it) => it.into(), - AnyGritNamedArg::GritNamedArgWithDefault(it) => it.into(), + AnyGritRegex::GritRegexLiteral(it) => it.into(), + AnyGritRegex::GritSnippetRegexLiteral(it) => it.into(), } } } -impl From for SyntaxElement { - fn from(n: AnyGritNamedArg) -> SyntaxElement { +impl From for SyntaxElement { + fn from(n: AnyGritRegex) -> SyntaxElement { let node: SyntaxNode = n.into(); node.into() } } -impl From for GritCodeSnippetSource { - fn from(node: GritBacktickSnippet) -> GritCodeSnippetSource { - GritCodeSnippetSource::GritBacktickSnippet(node) +impl From for GritCodeSnippetSource { + fn from(node: GritBacktickSnippetLiteral) -> GritCodeSnippetSource { + GritCodeSnippetSource::GritBacktickSnippetLiteral(node) } } impl From for GritCodeSnippetSource { @@ -9950,34 +10766,40 @@ impl From for GritCodeSnippetSource { GritCodeSnippetSource::GritLanguageSpecificSnippet(node) } } -impl From for GritCodeSnippetSource { - fn from(node: GritRawBacktickSnippet) -> GritCodeSnippetSource { - GritCodeSnippetSource::GritRawBacktickSnippet(node) +impl From for GritCodeSnippetSource { + fn from(node: GritRawBacktickSnippetLiteral) -> GritCodeSnippetSource { + GritCodeSnippetSource::GritRawBacktickSnippetLiteral(node) } } impl AstNode for GritCodeSnippetSource { type Language = Language; - const KIND_SET: SyntaxKindSet = GritBacktickSnippet::KIND_SET + const KIND_SET: SyntaxKindSet = GritBacktickSnippetLiteral::KIND_SET .union(GritLanguageSpecificSnippet::KIND_SET) - .union(GritRawBacktickSnippet::KIND_SET); + .union(GritRawBacktickSnippetLiteral::KIND_SET); fn can_cast(kind: SyntaxKind) -> bool { matches!( kind, - GRIT_BACKTICK_SNIPPET | GRIT_LANGUAGE_SPECIFIC_SNIPPET | GRIT_RAW_BACKTICK_SNIPPET + GRIT_BACKTICK_SNIPPET_LITERAL + | GRIT_LANGUAGE_SPECIFIC_SNIPPET + | GRIT_RAW_BACKTICK_SNIPPET_LITERAL ) } fn cast(syntax: SyntaxNode) -> Option { let res = match syntax.kind() { - GRIT_BACKTICK_SNIPPET => { - GritCodeSnippetSource::GritBacktickSnippet(GritBacktickSnippet { syntax }) + GRIT_BACKTICK_SNIPPET_LITERAL => { + GritCodeSnippetSource::GritBacktickSnippetLiteral(GritBacktickSnippetLiteral { + syntax, + }) } GRIT_LANGUAGE_SPECIFIC_SNIPPET => { GritCodeSnippetSource::GritLanguageSpecificSnippet(GritLanguageSpecificSnippet { syntax, }) } - GRIT_RAW_BACKTICK_SNIPPET => { - GritCodeSnippetSource::GritRawBacktickSnippet(GritRawBacktickSnippet { syntax }) + GRIT_RAW_BACKTICK_SNIPPET_LITERAL => { + GritCodeSnippetSource::GritRawBacktickSnippetLiteral( + GritRawBacktickSnippetLiteral { syntax }, + ) } _ => return None, }; @@ -9985,34 +10807,34 @@ impl AstNode for GritCodeSnippetSource { } fn syntax(&self) -> &SyntaxNode { match self { - GritCodeSnippetSource::GritBacktickSnippet(it) => &it.syntax, + GritCodeSnippetSource::GritBacktickSnippetLiteral(it) => &it.syntax, GritCodeSnippetSource::GritLanguageSpecificSnippet(it) => &it.syntax, - GritCodeSnippetSource::GritRawBacktickSnippet(it) => &it.syntax, + GritCodeSnippetSource::GritRawBacktickSnippetLiteral(it) => &it.syntax, } } fn into_syntax(self) -> SyntaxNode { match self { - GritCodeSnippetSource::GritBacktickSnippet(it) => it.syntax, + GritCodeSnippetSource::GritBacktickSnippetLiteral(it) => it.syntax, GritCodeSnippetSource::GritLanguageSpecificSnippet(it) => it.syntax, - GritCodeSnippetSource::GritRawBacktickSnippet(it) => it.syntax, + GritCodeSnippetSource::GritRawBacktickSnippetLiteral(it) => it.syntax, } } } impl std::fmt::Debug for GritCodeSnippetSource { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - GritCodeSnippetSource::GritBacktickSnippet(it) => std::fmt::Debug::fmt(it, f), + GritCodeSnippetSource::GritBacktickSnippetLiteral(it) => std::fmt::Debug::fmt(it, f), GritCodeSnippetSource::GritLanguageSpecificSnippet(it) => std::fmt::Debug::fmt(it, f), - GritCodeSnippetSource::GritRawBacktickSnippet(it) => std::fmt::Debug::fmt(it, f), + GritCodeSnippetSource::GritRawBacktickSnippetLiteral(it) => std::fmt::Debug::fmt(it, f), } } } impl From for SyntaxNode { fn from(n: GritCodeSnippetSource) -> SyntaxNode { match n { - GritCodeSnippetSource::GritBacktickSnippet(it) => it.into(), + GritCodeSnippetSource::GritBacktickSnippetLiteral(it) => it.into(), GritCodeSnippetSource::GritLanguageSpecificSnippet(it) => it.into(), - GritCodeSnippetSource::GritRawBacktickSnippet(it) => it.into(), + GritCodeSnippetSource::GritRawBacktickSnippetLiteral(it) => it.into(), } } } @@ -10086,33 +10908,33 @@ impl From for SyntaxElement { node.into() } } -impl From for GritListIndex { - fn from(node: GritIntValue) -> GritListIndex { - GritListIndex::GritIntValue(node) +impl From for GritListIndex { + fn from(node: GritIntLiteral) -> GritListIndex { + GritListIndex::GritIntLiteral(node) } } -impl From for GritListIndex { - fn from(node: GritNegativeIntValue) -> GritListIndex { - GritListIndex::GritNegativeIntValue(node) +impl From for GritListIndex { + fn from(node: GritNegativeIntLiteral) -> GritListIndex { + GritListIndex::GritNegativeIntLiteral(node) } } impl AstNode for GritListIndex { type Language = Language; const KIND_SET: SyntaxKindSet = AnyGritContainer::KIND_SET - .union(GritIntValue::KIND_SET) - .union(GritNegativeIntValue::KIND_SET); + .union(GritIntLiteral::KIND_SET) + .union(GritNegativeIntLiteral::KIND_SET); fn can_cast(kind: SyntaxKind) -> bool { match kind { - GRIT_INT_VALUE | GRIT_NEGATIVE_INT_VALUE => true, + GRIT_INT_LITERAL | GRIT_NEGATIVE_INT_LITERAL => true, k if AnyGritContainer::can_cast(k) => true, _ => false, } } fn cast(syntax: SyntaxNode) -> Option { let res = match syntax.kind() { - GRIT_INT_VALUE => GritListIndex::GritIntValue(GritIntValue { syntax }), - GRIT_NEGATIVE_INT_VALUE => { - GritListIndex::GritNegativeIntValue(GritNegativeIntValue { syntax }) + GRIT_INT_LITERAL => GritListIndex::GritIntLiteral(GritIntLiteral { syntax }), + GRIT_NEGATIVE_INT_LITERAL => { + GritListIndex::GritNegativeIntLiteral(GritNegativeIntLiteral { syntax }) } _ => { if let Some(any_grit_container) = AnyGritContainer::cast(syntax) { @@ -10125,15 +10947,15 @@ impl AstNode for GritListIndex { } fn syntax(&self) -> &SyntaxNode { match self { - GritListIndex::GritIntValue(it) => &it.syntax, - GritListIndex::GritNegativeIntValue(it) => &it.syntax, + GritListIndex::GritIntLiteral(it) => &it.syntax, + GritListIndex::GritNegativeIntLiteral(it) => &it.syntax, GritListIndex::AnyGritContainer(it) => it.syntax(), } } fn into_syntax(self) -> SyntaxNode { match self { - GritListIndex::GritIntValue(it) => it.syntax, - GritListIndex::GritNegativeIntValue(it) => it.syntax, + GritListIndex::GritIntLiteral(it) => it.syntax, + GritListIndex::GritNegativeIntLiteral(it) => it.syntax, GritListIndex::AnyGritContainer(it) => it.into_syntax(), } } @@ -10142,8 +10964,8 @@ impl std::fmt::Debug for GritListIndex { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { GritListIndex::AnyGritContainer(it) => std::fmt::Debug::fmt(it, f), - GritListIndex::GritIntValue(it) => std::fmt::Debug::fmt(it, f), - GritListIndex::GritNegativeIntValue(it) => std::fmt::Debug::fmt(it, f), + GritListIndex::GritIntLiteral(it) => std::fmt::Debug::fmt(it, f), + GritListIndex::GritNegativeIntLiteral(it) => std::fmt::Debug::fmt(it, f), } } } @@ -10151,8 +10973,8 @@ impl From for SyntaxNode { fn from(n: GritListIndex) -> SyntaxNode { match n { GritListIndex::AnyGritContainer(it) => it.into(), - GritListIndex::GritIntValue(it) => it.into(), - GritListIndex::GritNegativeIntValue(it) => it.into(), + GritListIndex::GritIntLiteral(it) => it.into(), + GritListIndex::GritNegativeIntLiteral(it) => it.into(), } } } @@ -10340,73 +11162,6 @@ impl From for SyntaxElement { node.into() } } -impl From for GritRegex { - fn from(node: GritRegexValue) -> GritRegex { - GritRegex::GritRegexValue(node) - } -} -impl From for GritRegex { - fn from(node: GritSnippetRegexValue) -> GritRegex { - GritRegex::GritSnippetRegexValue(node) - } -} -impl AstNode for GritRegex { - type Language = Language; - const KIND_SET: SyntaxKindSet = - GritRegexValue::KIND_SET.union(GritSnippetRegexValue::KIND_SET); - fn can_cast(kind: SyntaxKind) -> bool { - matches!(kind, GRIT_REGEX_VALUE | GRIT_SNIPPET_REGEX_VALUE) - } - fn cast(syntax: SyntaxNode) -> Option { - let res = match syntax.kind() { - GRIT_REGEX_VALUE => GritRegex::GritRegexValue(GritRegexValue { syntax }), - GRIT_SNIPPET_REGEX_VALUE => { - GritRegex::GritSnippetRegexValue(GritSnippetRegexValue { syntax }) - } - _ => return None, - }; - Some(res) - } - fn syntax(&self) -> &SyntaxNode { - match self { - GritRegex::GritRegexValue(it) => &it.syntax, - GritRegex::GritSnippetRegexValue(it) => &it.syntax, - } - } - fn into_syntax(self) -> SyntaxNode { - match self { - GritRegex::GritRegexValue(it) => it.syntax, - GritRegex::GritSnippetRegexValue(it) => it.syntax, - } - } -} -impl std::fmt::Debug for GritRegex { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - GritRegex::GritRegexValue(it) => std::fmt::Debug::fmt(it, f), - GritRegex::GritSnippetRegexValue(it) => std::fmt::Debug::fmt(it, f), - } - } -} -impl From for SyntaxNode { - fn from(n: GritRegex) -> SyntaxNode { - match n { - GritRegex::GritRegexValue(it) => it.into(), - GritRegex::GritSnippetRegexValue(it) => it.into(), - } - } -} -impl From for SyntaxElement { - fn from(n: GritRegex) -> SyntaxElement { - let node: SyntaxNode = n.into(); - node.into() - } -} -impl From for MaybeCurlyGritPattern { - fn from(node: AnyGritPattern) -> MaybeCurlyGritPattern { - MaybeCurlyGritPattern::AnyGritPattern(node) - } -} impl From for MaybeCurlyGritPattern { fn from(node: CurlyGritPattern) -> MaybeCurlyGritPattern { MaybeCurlyGritPattern::CurlyGritPattern(node) @@ -10417,28 +11172,36 @@ impl AstNode for MaybeCurlyGritPattern { const KIND_SET: SyntaxKindSet = AnyGritPattern::KIND_SET.union(CurlyGritPattern::KIND_SET); fn can_cast(kind: SyntaxKind) -> bool { - matches!(kind, ANY_GRIT_PATTERN | CURLY_GRIT_PATTERN) + match kind { + CURLY_GRIT_PATTERN => true, + k if AnyGritPattern::can_cast(k) => true, + _ => false, + } } fn cast(syntax: SyntaxNode) -> Option { let res = match syntax.kind() { - ANY_GRIT_PATTERN => MaybeCurlyGritPattern::AnyGritPattern(AnyGritPattern { syntax }), CURLY_GRIT_PATTERN => { MaybeCurlyGritPattern::CurlyGritPattern(CurlyGritPattern { syntax }) } - _ => return None, + _ => { + if let Some(any_grit_pattern) = AnyGritPattern::cast(syntax) { + return Some(MaybeCurlyGritPattern::AnyGritPattern(any_grit_pattern)); + } + return None; + } }; Some(res) } fn syntax(&self) -> &SyntaxNode { match self { - MaybeCurlyGritPattern::AnyGritPattern(it) => &it.syntax, MaybeCurlyGritPattern::CurlyGritPattern(it) => &it.syntax, + MaybeCurlyGritPattern::AnyGritPattern(it) => it.syntax(), } } fn into_syntax(self) -> SyntaxNode { match self { - MaybeCurlyGritPattern::AnyGritPattern(it) => it.syntax, MaybeCurlyGritPattern::CurlyGritPattern(it) => it.syntax, + MaybeCurlyGritPattern::AnyGritPattern(it) => it.into_syntax(), } } } @@ -10489,6 +11252,21 @@ impl std::fmt::Display for AnyGritNamedArg { std::fmt::Display::fmt(self.syntax(), f) } } +impl std::fmt::Display for AnyGritPattern { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for AnyGritPredicate { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for AnyGritRegex { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} impl std::fmt::Display for GritCodeSnippetSource { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -10519,22 +11297,17 @@ impl std::fmt::Display for GritPredicateMatchSubject { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for GritRegex { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} impl std::fmt::Display for MaybeCurlyGritPattern { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for AnyGritPattern { +impl std::fmt::Display for BracketedGritPattern { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for AnyGritPredicate { +impl std::fmt::Display for BracketedGritPredicate { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -10559,12 +11332,12 @@ impl std::fmt::Display for GritAssignmentAsPattern { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for GritBacktickSnippet { +impl std::fmt::Display for GritBacktickSnippetLiteral { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for GritBooleanValue { +impl std::fmt::Display for GritBooleanLiteral { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -10604,7 +11377,7 @@ impl std::fmt::Display for GritDotdotdot { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for GritDoubleValue { +impl std::fmt::Display for GritDoubleLiteral { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -10624,7 +11397,7 @@ impl std::fmt::Display for GritFunctionDefinition { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for GritIntValue { +impl std::fmt::Display for GritIntLiteral { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -10714,7 +11487,7 @@ impl std::fmt::Display for GritNamedArgWithDefault { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for GritNegativeIntValue { +impl std::fmt::Display for GritNegativeIntLiteral { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -10929,22 +11702,22 @@ impl std::fmt::Display for GritPredicateRewrite { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for GritRawBacktickSnippet { +impl std::fmt::Display for GritRawBacktickSnippetLiteral { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for GritRegexPattern { +impl std::fmt::Display for GritRegexLiteral { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for GritRegexPatternVariables { +impl std::fmt::Display for GritRegexPattern { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for GritRegexValue { +impl std::fmt::Display for GritRegexPatternVariables { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -10964,7 +11737,7 @@ impl std::fmt::Display for GritSequential { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for GritSnippetRegexValue { +impl std::fmt::Display for GritSnippetRegexLiteral { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -10974,7 +11747,7 @@ impl std::fmt::Display for GritSome { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for GritStringValue { +impl std::fmt::Display for GritStringLiteral { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -10984,7 +11757,7 @@ impl std::fmt::Display for GritSubOperation { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for GritUndefined { +impl std::fmt::Display for GritUndefinedLiteral { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } diff --git a/crates/biome_grit_syntax/src/generated/nodes_mut.rs b/crates/biome_grit_syntax/src/generated/nodes_mut.rs index c691a445e9d..f8f21621b10 100644 --- a/crates/biome_grit_syntax/src/generated/nodes_mut.rs +++ b/crates/biome_grit_syntax/src/generated/nodes_mut.rs @@ -3,391 +3,43 @@ use crate::{generated::nodes::*, GritSyntaxToken as SyntaxToken}; use biome_rowan::AstNode; use std::iter::once; -impl AnyGritPattern { - pub fn with_any_grit_literal(self, element: AnyGritLiteral) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_pattern_not(self, element: GritPatternNot) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_pattern_or(self, element: GritPatternOr) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_pattern_or_else(self, element: GritPatternOrElse) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(3usize..=3usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_pattern_any(self, element: GritPatternAny) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(4usize..=4usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_pattern_and(self, element: GritPatternAnd) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(5usize..=5usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_pattern_maybe(self, element: GritPatternMaybe) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(6usize..=6usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_pattern_if_else(self, element: GritPatternIfElse) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(7usize..=7usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_pattern_contains(self, element: GritPatternContains) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(8usize..=8usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_pattern_includes(self, element: GritPatternIncludes) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(9usize..=9usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_pattern_after(self, element: GritPatternAfter) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(10usize..=10usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_pattern_before(self, element: GritPatternBefore) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(11usize..=11usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_within(self, element: GritWithin) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(12usize..=12usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_bubble(self, element: GritBubble) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(13usize..=13usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_node_like(self, element: GritNodeLike) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(14usize..=14usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_map_accessor(self, element: GritMapAccessor) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(15usize..=15usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_list_accessor(self, element: GritListAccessor) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(16usize..=16usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_dot(self, element: GritDot) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(17usize..=17usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_some(self, element: GritSome) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(18usize..=18usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_every(self, element: GritEvery) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(19usize..=19usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_underscore(self, element: GritUnderscore) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(20usize..=20usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_variable(self, element: GritVariable) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(21usize..=21usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_regex_pattern(self, element: GritRegexPattern) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(22usize..=22usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_pattern_as(self, element: GritPatternAs) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(23usize..=23usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_pattern_limit(self, element: GritPatternLimit) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(24usize..=24usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_assignment_as_pattern(self, element: GritAssignmentAsPattern) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(25usize..=25usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_pattern_accumulate(self, element: GritPatternAccumulate) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(26usize..=26usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_rewrite(self, element: GritRewrite) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(27usize..=27usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_like(self, element: GritLike) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(28usize..=28usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_pattern_where(self, element: GritPatternWhere) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(29usize..=29usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_mul_operation(self, element: GritMulOperation) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(30usize..=30usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_div_operation(self, element: GritDivOperation) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(31usize..=31usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_mod_operation(self, element: GritModOperation) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(32usize..=32usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_add_operation(self, element: GritAddOperation) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(33usize..=33usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_sub_operation(self, element: GritSubOperation) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(34usize..=34usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_sequential(self, element: GritSequential) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(35usize..=35usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_files(self, element: GritFiles) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(36usize..=36usize, once(Some(element.into_syntax().into()))), - ) - } +impl BracketedGritPattern { pub fn with_l_paren_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax - .splice_slots(37usize..=37usize, once(Some(element.into()))), + .splice_slots(0usize..=0usize, once(Some(element.into()))), ) } pub fn with_any_grit_pattern(self, element: AnyGritPattern) -> Self { Self::unwrap_cast( self.syntax - .splice_slots(38usize..=38usize, once(Some(element.into_syntax().into()))), + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), ) } pub fn with_r_paren_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax - .splice_slots(39usize..=39usize, once(Some(element.into()))), - ) - } - pub fn with_grit_bogus_pattern(self, element: GritBogusPattern) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(40usize..=40usize, once(Some(element.into_syntax().into()))), + .splice_slots(2usize..=2usize, once(Some(element.into()))), ) } } -impl AnyGritPredicate { - pub fn with_grit_predicate_not(self, element: GritPredicateNot) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_predicate_maybe(self, element: GritPredicateMaybe) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_predicate_and(self, element: GritPredicateAnd) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_predicate_or(self, element: GritPredicateOr) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(3usize..=3usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_predicate_any(self, element: GritPredicateAny) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(4usize..=4usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_predicate_if_else(self, element: GritPredicateIfElse) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(5usize..=5usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_predicate_assignment(self, element: GritPredicateAssignment) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(6usize..=6usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_predicate_accumulate(self, element: GritPredicateAccumulate) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(7usize..=7usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_predicate_rewrite(self, element: GritPredicateRewrite) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(8usize..=8usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_predicate_greater(self, element: GritPredicateGreater) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(9usize..=9usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_predicate_less(self, element: GritPredicateLess) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(10usize..=10usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_predicate_greater_equal(self, element: GritPredicateGreaterEqual) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(11usize..=11usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_predicate_less_equal(self, element: GritPredicateLessEqual) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(12usize..=12usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_predicate_not_equal(self, element: GritPredicateNotEqual) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(13usize..=13usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_predicate_equal(self, element: GritPredicateEqual) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(14usize..=14usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_predicate_match(self, element: GritPredicateMatch) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(15usize..=15usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_predicate_call(self, element: GritPredicateCall) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(16usize..=16usize, once(Some(element.into_syntax().into()))), - ) - } +impl BracketedGritPredicate { pub fn with_l_paren_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax - .splice_slots(17usize..=17usize, once(Some(element.into()))), + .splice_slots(0usize..=0usize, once(Some(element.into()))), ) } pub fn with_any_grit_predicate(self, element: AnyGritPredicate) -> Self { Self::unwrap_cast( self.syntax - .splice_slots(18usize..=18usize, once(Some(element.into_syntax().into()))), + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), ) } pub fn with_r_paren_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax - .splice_slots(19usize..=19usize, once(Some(element.into()))), - ) - } - pub fn with_grit_boolean_value(self, element: GritBooleanValue) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(20usize..=20usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_predicate_return(self, element: GritPredicateReturn) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(21usize..=21usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_grit_bogus_predicate(self, element: GritBogusPredicate) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(22usize..=22usize, once(Some(element.into_syntax().into()))), + .splice_slots(2usize..=2usize, once(Some(element.into()))), ) } } @@ -459,7 +111,7 @@ impl GritAssignmentAsPattern { ) } } -impl GritBacktickSnippet { +impl GritBacktickSnippetLiteral { pub fn with_value_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax @@ -467,7 +119,7 @@ impl GritBacktickSnippet { ) } } -impl GritBooleanValue { +impl GritBooleanLiteral { pub fn with_true_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax @@ -591,7 +243,7 @@ impl GritDotdotdot { )) } } -impl GritDoubleValue { +impl GritDoubleLiteral { pub fn with_value_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax @@ -677,7 +329,7 @@ impl GritFunctionDefinition { ) } } -impl GritIntValue { +impl GritIntLiteral { pub fn with_value_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax @@ -740,36 +392,12 @@ impl GritLanguageFlavorKind { } } impl GritLanguageName { - pub fn with_js_token(self, element: SyntaxToken) -> Self { + pub fn with_language_kind_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax .splice_slots(0usize..=0usize, once(Some(element.into()))), ) } - pub fn with_css_token(self, element: SyntaxToken) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(1usize..=1usize, once(Some(element.into()))), - ) - } - pub fn with_json_token(self, element: SyntaxToken) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(2usize..=2usize, once(Some(element.into()))), - ) - } - pub fn with_grit_token(self, element: SyntaxToken) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(3usize..=3usize, once(Some(element.into()))), - ) - } - pub fn with_html_token(self, element: SyntaxToken) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(4usize..=4usize, once(Some(element.into()))), - ) - } } impl GritLanguageSpecificSnippet { pub fn with_language(self, element: GritLanguageName) -> Self { @@ -1025,7 +653,7 @@ impl GritNamedArgWithDefault { ) } } -impl GritNegativeIntValue { +impl GritNegativeIntLiteral { pub fn with_value_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax @@ -1387,7 +1015,7 @@ impl GritPatternLimit { .splice_slots(1usize..=1usize, once(Some(element.into()))), ) } - pub fn with_limit(self, element: GritIntValue) -> Self { + pub fn with_limit(self, element: GritIntLiteral) -> Self { Self::unwrap_cast( self.syntax .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), @@ -1936,7 +1564,15 @@ impl GritPredicateRewrite { ) } } -impl GritRawBacktickSnippet { +impl GritRawBacktickSnippetLiteral { + pub fn with_value_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } +} +impl GritRegexLiteral { pub fn with_value_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax @@ -1945,7 +1581,7 @@ impl GritRawBacktickSnippet { } } impl GritRegexPattern { - pub fn with_regex(self, element: GritRegex) -> Self { + pub fn with_regex(self, element: AnyGritRegex) -> Self { Self::unwrap_cast( self.syntax .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), @@ -1978,14 +1614,6 @@ impl GritRegexPatternVariables { ) } } -impl GritRegexValue { - pub fn with_value_token(self, element: SyntaxToken) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(0usize..=0usize, once(Some(element.into()))), - ) - } -} impl GritRewrite { pub fn with_left(self, element: AnyGritPattern) -> Self { Self::unwrap_cast( @@ -2082,7 +1710,7 @@ impl GritSequential { ) } } -impl GritSnippetRegexValue { +impl GritSnippetRegexLiteral { pub fn with_value_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax @@ -2104,7 +1732,7 @@ impl GritSome { ) } } -impl GritStringValue { +impl GritStringLiteral { pub fn with_value_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax @@ -2132,7 +1760,7 @@ impl GritSubOperation { ) } } -impl GritUndefined { +impl GritUndefinedLiteral { pub fn with_undefined_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax @@ -2175,7 +1803,7 @@ impl GritVersion { .splice_slots(2usize..=2usize, once(Some(element.into()))), ) } - pub fn with_grit_double_value(self, element: GritDoubleValue) -> Self { + pub fn with_grit_double_literal(self, element: GritDoubleLiteral) -> Self { Self::unwrap_cast( self.syntax .splice_slots(3usize..=3usize, once(Some(element.into_syntax().into()))), diff --git a/xtask/codegen/gritql.ungram b/xtask/codegen/gritql.ungram index fa666d5410c..9dea1eafdfd 100644 --- a/xtask/codegen/gritql.ungram +++ b/xtask/codegen/gritql.ungram @@ -67,7 +67,7 @@ AnyGritDefinition = GritDefinitionList = AnyGritDefinition ('newline' AnyGritDefinition)* 'newline'? -GritVersion = 'engine' 'biome' '(' GritDoubleValue ')' +GritVersion = 'engine' 'biome' '(' GritDoubleLiteral ')' GritLanguageDeclaration = 'language' @@ -81,8 +81,6 @@ GritLanguageFlavorKind = flavor_kind: ( // JavaScript flavors: 'typescript' | 'jsx' - // Technically raw JS is supported, but we encourage using typescript in most cases - it will match raw JS fine - | 'js_do_not_use' ) // --- patterns @@ -125,9 +123,11 @@ AnyGritPattern = | GritSubOperation | GritSequential | GritFiles - | '(' AnyGritPattern ')' + | BracketedGritPattern | GritBogusPattern +BracketedGritPattern = '(' AnyGritPattern ')' + MaybeCurlyGritPattern = AnyGritPattern | CurlyGritPattern CurlyGritPattern = '{' AnyGritPattern '}' @@ -150,7 +150,7 @@ GritPatternAs = pattern: AnyGritPattern 'as' variable: GritVariable GritPatternLimit = - pattern: AnyGritPattern 'limit' limit: GritIntValue + pattern: AnyGritPattern 'limit' limit: GritIntLiteral // statement, in the engine this is a predicate that always evaluates to true // This is useful for initializing variables at the root of a pattern definition @@ -166,11 +166,11 @@ GritPatternWhere = AnyGritLiteral = GritCodeSnippet - | GritStringValue - | GritIntValue - | GritDoubleValue - | GritBooleanValue - | GritUndefined + | GritStringLiteral + | GritIntLiteral + | GritDoubleLiteral + | GritBooleanLiteral + | GritUndefinedLiteral | GritMap | GritList | GritBogusLiteral @@ -306,7 +306,7 @@ GritListAccessor = ']' GritListAccessorSubject = GritList | AnyGritContainer -GritListIndex = AnyGritContainer | GritNegativeIntValue | GritIntValue +GritListIndex = AnyGritContainer | GritNegativeIntLiteral | GritIntLiteral GritDot = '.' @@ -321,7 +321,7 @@ GritUnderscore = dollar_underscore: '$_' GritRegexPattern = - regex: GritRegex + regex: AnyGritRegex variables: GritRegexPatternVariables? GritRegexPatternVariables = @@ -392,11 +392,13 @@ AnyGritPredicate = | GritPredicateEqual | GritPredicateMatch | GritPredicateCall - | '(' AnyGritPredicate ')' - | GritBooleanValue + | BracketedGritPredicate + | GritBooleanLiteral | GritPredicateReturn | GritBogusPredicate +BracketedGritPredicate = '(' AnyGritPredicate ')' + GritPredicateNot = GritNot predicate: AnyGritPredicate @@ -500,7 +502,7 @@ GritPredicateReturn = // --- tokens and lexical definitions -GritBooleanValue = 'true' | 'false' +GritBooleanLiteral = 'true' | 'false' GritVariable = 'grit_variable' GritVariableList = GritVariable (',' GritVariable)* ','? @@ -510,19 +512,15 @@ GritName = 'grit_name' // These are target languages GritLanguageName = - 'js' - | 'css' - | 'json' - | 'grit' - | 'html' + language_kind: ('js' | 'css' | 'json' | 'grit' | 'html') -GritBacktickSnippet = value: 'grit_backtick_snippet' +GritBacktickSnippetLiteral = value: 'grit_backtick_snippet' -GritRawBacktickSnippet = value: 'grit_raw_backtick_snippet' +GritRawBacktickSnippetLiteral = value: 'grit_raw_backtick_snippet' GritLanguageSpecificSnippet = language: GritLanguageName - snippet: 'grit_string_literal' + snippet: 'grit_string' // a code snippet may be prefixed by a label; // the label may be prefixed by a module or sort name (separated from the label by a dot) @@ -531,25 +529,25 @@ GritCodeSnippet = source: GritCodeSnippetSource GritCodeSnippetSource = - GritBacktickSnippet + GritBacktickSnippetLiteral | GritLanguageSpecificSnippet - | GritRawBacktickSnippet + | GritRawBacktickSnippetLiteral GritNot = 'not' | '!' -GritUndefined = 'undefined' +GritUndefinedLiteral = 'undefined' -GritIntValue = value: 'grit_int_literal' -GritNegativeIntValue = value: 'grit_negative_int_literal' +GritIntLiteral = value: 'grit_int' +GritNegativeIntLiteral = value: 'grit_negative_int' -GritDoubleValue = value: 'grit_double_literal' +GritDoubleLiteral = value: 'grit_double' -GritStringValue = value: 'grit_string_literal' +GritStringLiteral = value: 'grit_string' -GritRegex = GritRegexValue | GritSnippetRegexValue +AnyGritRegex = GritRegexLiteral | GritSnippetRegexLiteral -GritRegexValue = value: 'grit_regex_literal' +GritRegexLiteral = value: 'grit_regex' -GritSnippetRegexValue = value: 'grit_snippet_regex_literal' +GritSnippetRegexLiteral = value: 'grit_snippet_regex' GritAnnotation = 'grit_annotation' diff --git a/xtask/codegen/src/grit_kinds_src.rs b/xtask/codegen/src/grit_kinds_src.rs index 10ec69b2bbf..1a144226515 100644 --- a/xtask/codegen/src/grit_kinds_src.rs +++ b/xtask/codegen/src/grit_kinds_src.rs @@ -89,12 +89,12 @@ pub const GRIT_KINDS_SRC: KindsSrc = KindsSrc { "return", ], literals: &[ - "GRIT_INT_LITERAL", - "GRIT_NEGATIVE_INT_LITERAL", - "GRIT_DOUBLE_LITERAL", - "GRIT_STRING_LITERAL", - "GRIT_REGEX_LITERAL", - "GRIT_SNIPPET_REGEX_LITERAL", + "GRIT_INT", + "GRIT_NEGATIVE_INT", + "GRIT_DOUBLE", + "GRIT_STRING", + "GRIT_REGEX", + "GRIT_SNIPPET_REGEX", ], tokens: &[ "NEWLINE", @@ -109,13 +109,8 @@ pub const GRIT_KINDS_SRC: KindsSrc = KindsSrc { "GRIT_VARIABLE", ], nodes: &[ - "ANY_GRIT_CONTAINER", - "ANY_GRIT_DEFINITION", - "ANY_GRIT_LIST_PATTERN", - "ANY_GRIT_LITERAL", - "ANY_GRIT_NAMED_ARG", - "ANY_GRIT_PATTERN", - "ANY_GRIT_PREDICATE", + "BRACKETED_GRIT_PATTERN", + "BRACKETED_GRIT_PREDICATE", "CURLY_GRIT_PATTERN", "GRIT_ROOT", "GRIT_SEQUENTIAL", @@ -206,22 +201,24 @@ pub const GRIT_KINDS_SRC: KindsSrc = KindsSrc { "GRIT_PREDICATE_MATCH_SUBJECT", "GRIT_PREDICATE_CALL", "GRIT_PREDICATE_RETURN", - "GRIT_BOOLEAN_LITERAL", "GRIT_VARIABLE_LIST", "GRIT_LANGUAGE_NAME", "GRIT_LANGUAGE_SPECIFIC_SNIPPET", "GRIT_CODE_SNIPPET", "GRIT_NOT", - "GRIT_BOOLEAN_VALUE", - "GRIT_DOUBLE_VALUE", - "GRIT_INT_VALUE", - "GRIT_NEGATIVE_INT_VALUE", - "GRIT_REGEX_VALUE", - "GRIT_SNIPPET_REGEX_VALUE", - "GRIT_STRING_VALUE", - "GRIT_UNDEFINED", "GRIT_UNDERSCORE", "MAYBE_CURLY_GRIT_PATTERN", + // literal wrappers: + "GRIT_BACKTICK_SNIPPET_LITERAL", + "GRIT_BOOLEAN_LITERAL", + "GRIT_UNDEFINED_LITERAL", + "GRIT_INT_LITERAL", + "GRIT_NEGATIVE_INT_LITERAL", + "GRIT_DOUBLE_LITERAL", + "GRIT_STRING_LITERAL", + "GRIT_RAW_BACKTICK_SNIPPET_LITERAL", + "GRIT_REGEX_LITERAL", + "GRIT_SNIPPET_REGEX_LITERAL", // bogus nodes: "GRIT_BOGUS", "GRIT_BOGUS_DEFINITION", From 71cf549d09dfc3984aeb580bd4329fa5c78f2545 Mon Sep 17 00:00:00 2001 From: "Arend van Beelen jr." Date: Mon, 26 Feb 2024 22:08:07 +0100 Subject: [PATCH 06/12] Covered most patterns and some predicates --- .../src/generated/node_factory.rs | 46 +- .../src/generated/syntax_factory.rs | 18 +- crates/biome_grit_parser/src/lexer/mod.rs | 57 +- crates/biome_grit_parser/src/lexer/tests.rs | 48 +- crates/biome_grit_parser/src/parser.rs | 341 --------- .../biome_grit_parser/src/parser/literals.rs | 153 ++++ crates/biome_grit_parser/src/parser/mod.rs | 227 ++++++ .../biome_grit_parser/src/parser/patterns.rs | 692 ++++++++++++++++++ .../src/parser/predicates.rs | 256 +++++++ .../err/incorrect_version.grit.snap | 13 +- .../ok/pattern_with_version.grit.snap | 8 +- .../tests/grit_test_suite/ok/rewrite.grit | 1 + .../grit_test_suite/ok/rewrite.grit.snap | 58 ++ .../grit_test_suite/ok/rewrite_in_where.grit | 6 + .../ok/rewrite_in_where.grit.snap | 134 ++++ .../biome_grit_syntax/src/generated/kind.rs | 6 +- .../biome_grit_syntax/src/generated/macros.rs | 8 - .../biome_grit_syntax/src/generated/nodes.rs | 174 +---- .../src/generated/nodes_mut.rs | 4 +- xtask/codegen/gritql.ungram | 6 +- xtask/codegen/src/grit_kinds_src.rs | 2 - 21 files changed, 1626 insertions(+), 632 deletions(-) delete mode 100644 crates/biome_grit_parser/src/parser.rs create mode 100644 crates/biome_grit_parser/src/parser/literals.rs create mode 100644 crates/biome_grit_parser/src/parser/mod.rs create mode 100644 crates/biome_grit_parser/src/parser/patterns.rs create mode 100644 crates/biome_grit_parser/src/parser/predicates.rs create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/rewrite.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/rewrite.grit.snap create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/rewrite_in_where.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/rewrite_in_where.grit.snap diff --git a/crates/biome_grit_factory/src/generated/node_factory.rs b/crates/biome_grit_factory/src/generated/node_factory.rs index d0486563479..f686db683da 100644 --- a/crates/biome_grit_factory/src/generated/node_factory.rs +++ b/crates/biome_grit_factory/src/generated/node_factory.rs @@ -267,7 +267,7 @@ pub fn grit_every(every_token: SyntaxToken, pattern: MaybeCurlyGritPattern) -> G pub fn grit_files( multifile_token: SyntaxToken, l_curly_token: SyntaxToken, - files: GritFilesList, + files: GritPatternList, r_curly_token: SyntaxToken, ) -> GritFiles { GritFiles::unwrap_cast(SyntaxNode::new_detached( @@ -1736,7 +1736,7 @@ impl GritRootBuilder { pub fn grit_sequential( sequential_token: SyntaxToken, l_curly_token: SyntaxToken, - sequential: GritSequentialList, + sequential: GritPatternList, r_curly_token: SyntaxToken, ) -> GritSequential { GritSequential::unwrap_cast(SyntaxNode::new_detached( @@ -1850,27 +1850,6 @@ where }), )) } -pub fn grit_files_list(items: I, separators: S) -> GritFilesList -where - I: IntoIterator, - I::IntoIter: ExactSizeIterator, - S: IntoIterator, - S::IntoIter: ExactSizeIterator, -{ - let mut items = items.into_iter(); - let mut separators = separators.into_iter(); - let length = items.len() + separators.len(); - GritFilesList::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_FILES_LIST, - (0..length).map(|index| { - if index % 2 == 0 { - Some(items.next()?.into_syntax().into()) - } else { - Some(separators.next()?.into()) - } - }), - )) -} pub fn grit_language_flavor_list(items: I, separators: S) -> GritLanguageFlavorList where I: IntoIterator, @@ -1997,27 +1976,6 @@ where }), )) } -pub fn grit_sequential_list(items: I, separators: S) -> GritSequentialList -where - I: IntoIterator, - I::IntoIter: ExactSizeIterator, - S: IntoIterator, - S::IntoIter: ExactSizeIterator, -{ - let mut items = items.into_iter(); - let mut separators = separators.into_iter(); - let length = items.len() + separators.len(); - GritSequentialList::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_SEQUENTIAL_LIST, - (0..length).map(|index| { - if index % 2 == 0 { - Some(items.next()?.into_syntax().into()) - } else { - Some(separators.next()?.into()) - } - }), - )) -} pub fn grit_variable_list(items: I, separators: S) -> GritVariableList where I: IntoIterator, diff --git a/crates/biome_grit_factory/src/generated/syntax_factory.rs b/crates/biome_grit_factory/src/generated/syntax_factory.rs index 2c00dc37675..1e4a1a2807f 100644 --- a/crates/biome_grit_factory/src/generated/syntax_factory.rs +++ b/crates/biome_grit_factory/src/generated/syntax_factory.rs @@ -506,7 +506,7 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.next_slot(); if let Some(element) = ¤t_element { - if GritFilesList::can_cast(element.kind()) { + if GritPatternList::can_cast(element.kind()) { slots.mark_present(); current_element = elements.next(); } @@ -2822,7 +2822,7 @@ impl SyntaxFactory for GritSyntaxFactory { } slots.next_slot(); if let Some(element) = ¤t_element { - if GritSequentialList::can_cast(element.kind()) { + if GritPatternList::can_cast(element.kind()) { slots.mark_present(); current_element = elements.next(); } @@ -3077,13 +3077,6 @@ impl SyntaxFactory for GritSyntaxFactory { NEWLINE, true, ), - GRIT_FILES_LIST => Self::make_separated_list_syntax( - kind, - children, - AnyGritPattern::can_cast, - T ! [,], - true, - ), GRIT_LANGUAGE_FLAVOR_LIST => Self::make_separated_list_syntax( kind, children, @@ -3126,13 +3119,6 @@ impl SyntaxFactory for GritSyntaxFactory { T ! [,], true, ), - GRIT_SEQUENTIAL_LIST => Self::make_separated_list_syntax( - kind, - children, - AnyGritPattern::can_cast, - T ! [,], - true, - ), GRIT_VARIABLE_LIST => Self::make_separated_list_syntax( kind, children, diff --git a/crates/biome_grit_parser/src/lexer/mod.rs b/crates/biome_grit_parser/src/lexer/mod.rs index d336c7fc4f9..89c56b7a8be 100644 --- a/crates/biome_grit_parser/src/lexer/mod.rs +++ b/crates/biome_grit_parser/src/lexer/mod.rs @@ -283,8 +283,11 @@ impl<'src> Lexer<'src> { b'`' => self.lex_backtick_snippet(), b'/' => self.lex_slash(), b'=' => self.eat_equals_or_rewrite(), + b'<' => self.eat_lt_or_match(), + b'>' => self.eat_gt(), b':' => self.eat_byte(T![:]), b';' => self.eat_byte(T![;]), + b'.' => self.eat_byte(T![.]), b',' => self.eat_byte(T![,]), b'[' => self.eat_byte(T!['[']), b']' => self.eat_byte(T![']']), @@ -317,6 +320,36 @@ impl<'src> Lexer<'src> { } } + fn eat_lt_or_match(&mut self) -> GritSyntaxKind { + assert_eq!(self.current_byte(), Some(b'<')); + self.advance(1); + + match self.current_byte() { + Some(b':') => { + self.advance(1); + T![<:] + } + Some(b'=') => { + self.advance(1); + T![<=] + } + _ => T![<], + } + } + + fn eat_gt(&mut self) -> GritSyntaxKind { + assert_eq!(self.current_byte(), Some(b'>')); + self.advance(1); + + match self.current_byte() { + Some(b'=') => { + self.advance(1); + T![>=] + } + _ => T![>], + } + } + #[inline] fn eat_unexpected_character(&mut self) -> GritSyntaxKind { self.assert_at_char_boundary(); @@ -430,12 +463,12 @@ impl<'src> Lexer<'src> { match state { LexNumberState::IntegerPart => { if first == b'-' { - GRIT_NEGATIVE_INT_LITERAL + GRIT_NEGATIVE_INT } else { - GRIT_INT_LITERAL + GRIT_INT } } - LexNumberState::FractionalPart | LexNumberState::Exponent => GRIT_DOUBLE_LITERAL, + LexNumberState::FractionalPart | LexNumberState::Exponent => GRIT_DOUBLE, LexNumberState::FirstDigit => { let err = ParseDiagnostic::new( "Minus must be followed by a digit", @@ -565,7 +598,7 @@ impl<'src> Lexer<'src> { } match state { - LexStringState::Terminated => GRIT_STRING_LITERAL, + LexStringState::Terminated => GRIT_STRING, LexStringState::InvalidQuote => { let literal_range = TextRange::new(start, self.text_position()); self.diagnostics.push( @@ -745,13 +778,19 @@ impl<'src> Lexer<'src> { } else if byte == b'"' { return match &buffer[..len] { b"r" => self.lex_regex(), + b"js" => T![js], + b"json" => T![json], + b"css" => T![css], + b"grit" => T![grit], + b"html" => T![html], _ => { self.diagnostics.push( ParseDiagnostic::new( "Unxpected string prefix", name_start..self.text_position(), ) - .with_hint("Use the `r` prefix to create a regex literal."), + .with_hint("Use a language annotation to create a language-specific snippet or use the `r` prefix to create a regex literal.") + .with_hint("Supported language annotations are `js`, `json`, `css`, `grit`, and `html`."), ); ERROR_TOKEN @@ -760,7 +799,7 @@ impl<'src> Lexer<'src> { } else if byte == b'`' { return match &buffer[..len] { b"r" => match self.lex_backtick_snippet() { - GRIT_BACKTICK_SNIPPET => GRIT_SNIPPET_REGEX_LITERAL, + GRIT_BACKTICK_SNIPPET => GRIT_SNIPPET_REGEX, other => other, }, b"raw" => match self.lex_backtick_snippet() { @@ -886,7 +925,7 @@ impl<'src> Lexer<'src> { } match state { - LexRegexState::Terminated => GRIT_REGEX_LITERAL, + LexRegexState::Terminated => GRIT_REGEX, LexRegexState::InRegex => { let unterminated = ParseDiagnostic::new("Missing closing quote", start..self.text_position()) @@ -906,6 +945,10 @@ impl<'src> Lexer<'src> { self.assert_at_char_boundary(); self.advance(1); // Skip the leading `$`. + if self.current_byte() == Some(b'_') { + return GRIT_UNDERSCORE; + } + while let Some(byte) = self.current_byte() { if is_identifier_byte(byte) { self.advance(1) diff --git a/crates/biome_grit_parser/src/lexer/tests.rs b/crates/biome_grit_parser/src/lexer/tests.rs index 88845ebd09b..9a03be4aac8 100644 --- a/crates/biome_grit_parser/src/lexer/tests.rs +++ b/crates/biome_grit_parser/src/lexer/tests.rs @@ -106,7 +106,7 @@ fn empty() { fn int() { assert_lex! { "5098382", - GRIT_INT_LITERAL:7, + GRIT_INT:7, EOF:0 } } @@ -115,7 +115,7 @@ fn int() { fn float() { assert_lex! { "345.893872", - GRIT_DOUBLE_LITERAL:10, + GRIT_DOUBLE:10, EOF:0 } } @@ -133,7 +133,7 @@ fn float_invalid() { fn negative() { assert_lex! { "-5098382", - GRIT_NEGATIVE_INT_LITERAL:8, + GRIT_NEGATIVE_INT:8, EOF:0 } } @@ -151,13 +151,13 @@ fn minus_without_number() { fn exponent() { assert_lex! { "-493e+534", - GRIT_DOUBLE_LITERAL:9, + GRIT_DOUBLE:9, EOF:0 } assert_lex! { "-493E-534", - GRIT_DOUBLE_LITERAL:9, + GRIT_DOUBLE:9, EOF:0 } } @@ -182,16 +182,16 @@ fn array() { assert_lex! { "[1, 2, 3, 4]", L_BRACK:1, - GRIT_INT_LITERAL:1, + GRIT_INT:1, COMMA:1 WHITESPACE:1, - GRIT_INT_LITERAL:1, + GRIT_INT:1, COMMA:1, WHITESPACE:1, - GRIT_INT_LITERAL:1, + GRIT_INT:1, COMMA:1, WHITESPACE:1, - GRIT_INT_LITERAL:1, + GRIT_INT:1, R_BRACK:1, EOF:0, } @@ -207,14 +207,14 @@ fn object() { GRIT_NAME:3, COLON:1, WHITESPACE:1, - GRIT_STRING_LITERAL:7, + GRIT_STRING:7, COMMA:1, WHITESPACE:1, GRIT_NAME:5, COLON:1, WHITESPACE:1, - GRIT_INT_LITERAL:1, + GRIT_INT:1, WHITESPACE:1, R_CURLY:1, EOF:0, @@ -225,7 +225,7 @@ fn object() { fn basic_string() { assert_lex! { r#""A string consisting of ASCII characters only""#, - GRIT_STRING_LITERAL:46, + GRIT_STRING:46, EOF:0 } } @@ -252,25 +252,25 @@ fn unterminated_string() { fn simple_escape_sequences() { assert_lex! { r#""Escaped \$""#, - GRIT_STRING_LITERAL:12, + GRIT_STRING:12, EOF:0 } assert_lex! { r#""Escaped \"""#, - GRIT_STRING_LITERAL:12, + GRIT_STRING:12, EOF:0 } assert_lex! { r#""Escaped \\""#, - GRIT_STRING_LITERAL:12, + GRIT_STRING:12, EOF:0 } assert_lex! { r#""Escaped \n""#, - GRIT_STRING_LITERAL:12, + GRIT_STRING:12, EOF:0 } } @@ -279,13 +279,13 @@ fn simple_escape_sequences() { fn unicode_escape() { assert_lex! { r#""Escaped \u002F""#, - GRIT_STRING_LITERAL:16, + GRIT_STRING:16, EOF:0 } assert_lex! { r#""Escaped \u002f""#, - GRIT_STRING_LITERAL:16, + GRIT_STRING:16, EOF:0 } } @@ -364,19 +364,19 @@ fn names() { fn regex() { assert_lex! { r#"r"a+b?""#, - GRIT_REGEX_LITERAL:7, + GRIT_REGEX:7, EOF:0 } assert_lex! { r#"r"a\\.b?""#, - GRIT_REGEX_LITERAL:9, + GRIT_REGEX:9, EOF:0 } assert_lex! { r#"r"a\"b?""#, - GRIT_REGEX_LITERAL:8, + GRIT_REGEX:8, EOF:0 } @@ -391,19 +391,19 @@ fn regex() { fn snippet_regex() { assert_lex! { r#"r`a+b?`"#, - GRIT_SNIPPET_REGEX_LITERAL:7, + GRIT_SNIPPET_REGEX:7, EOF:0 } assert_lex! { r#"r`a\\.b?`"#, - GRIT_SNIPPET_REGEX_LITERAL:9, + GRIT_SNIPPET_REGEX:9, EOF:0 } assert_lex! { r#"r`a\`b?`"#, - GRIT_SNIPPET_REGEX_LITERAL:8, + GRIT_SNIPPET_REGEX:8, EOF:0 } diff --git a/crates/biome_grit_parser/src/parser.rs b/crates/biome_grit_parser/src/parser.rs deleted file mode 100644 index 7a2d768ad1f..00000000000 --- a/crates/biome_grit_parser/src/parser.rs +++ /dev/null @@ -1,341 +0,0 @@ -use crate::token_source::GritTokenSource; -use biome_grit_syntax::GritSyntaxKind::{self, *}; -use biome_grit_syntax::T; -use biome_parser::diagnostic::merge_diagnostics; -use biome_parser::event::Event; -use biome_parser::prelude::{ParsedSyntax::*, *}; -use biome_parser::token_source::Trivia; -use biome_parser::ParserContext; -use biome_rowan::TextRange; - -const BOOLEAN_VALUE_SET: TokenSet = token_set![TRUE_KW, FALSE_KW]; - -const SUPPORTED_LANGUAGE_SET: TokenSet = - token_set![T![js], T![json], T![css], T![grit], T![html]]; - -const SUPPORTED_LANGUAGE_FLAVOR_SET: TokenSet = token_set![T![typescript], T![jsx]]; - -const CODE_SNIPPET_SET: TokenSet = - SUPPORTED_LANGUAGE_SET.union(token_set![GRIT_BACKTICK_SNIPPET, GRIT_RAW_BACKTICK_SNIPPET]); - -pub(crate) struct GritParser<'source> { - context: ParserContext, - source: GritTokenSource<'source>, -} - -impl<'source> GritParser<'source> { - pub fn new(source: &'source str) -> Self { - Self { - context: ParserContext::default(), - source: GritTokenSource::from_str(source), - } - } - - pub fn finish( - self, - ) -> ( - Vec>, - Vec, - Vec, - ) { - let (trivia, lexer_diagnostics) = self.source.finish(); - let (events, parse_diagnostics) = self.context.finish(); - - let diagnostics = merge_diagnostics(lexer_diagnostics, parse_diagnostics); - - (events, diagnostics, trivia) - } -} - -impl<'source> Parser for GritParser<'source> { - type Kind = GritSyntaxKind; - type Source = GritTokenSource<'source>; - - fn context(&self) -> &ParserContext { - &self.context - } - - fn context_mut(&mut self) -> &mut ParserContext { - &mut self.context - } - - fn source(&self) -> &Self::Source { - &self.source - } - - fn source_mut(&mut self) -> &mut Self::Source { - &mut self.source - } -} - -pub(crate) fn parse_root(p: &mut GritParser) -> CompletedMarker { - let m = p.start(); - - p.eat(UNICODE_BOM); - - parse_version(p); - parse_language(p); - parse_definition_list(p); - let _ = parse_pattern(p); - parse_definition_list(p); - - p.eat(EOF); - - m.complete(p, GRIT_ROOT) -} - -fn parse_version(p: &mut GritParser) -> Option { - if !p.at(T![engine]) { - return None; - } - - let m = p.start(); - p.bump(T![engine]); - - let engine_range = p.cur_range(); - if p.eat(T![biome]) { - if p.eat(T!['(']) { - match parse_double_literal(p) { - Present(_) => { - p.eat(T![')']); - } - Absent => p.error(p.err_builder("Expected version as a double", p.cur_range())), - } - } else { - let engine_end = engine_range.end(); - p.error(p.err_builder( - "Expected an engine version", - TextRange::new(engine_end, engine_end), - )) - } - } else { - p.error(p.err_builder("Engine must be `biome`", engine_range)); - } - - let result = m.complete(p, GRIT_VERSION); - - Some(result) -} - -fn parse_language(p: &mut GritParser) -> Option { - if !p.at(T![language]) { - return None; - } - - let m = p.start(); - p.bump(T![language]); - - if p.at_ts(SUPPORTED_LANGUAGE_SET) { - let m = p.start(); - p.bump_ts(SUPPORTED_LANGUAGE_SET); - m.complete(p, GRIT_LANGUAGE_NAME); - } else { - p.error(p.err_builder( - "Expected a supported language; must be one of `js`, `json`, `css`, `html`, or `grit`", - p.cur_range(), - )) - } - - parse_language_flavor(p); - - p.eat(T![;]); - - let result = m.complete(p, GRIT_LANGUAGE_DECLARATION); - - Some(result) -} - -fn parse_language_flavor(p: &mut GritParser) -> Option { - if !p.at(T!['(']) { - return None; - } - - let m = p.start(); - p.bump(T!['(']); - - { - let m = p.start(); - - loop { - if p.at_ts(SUPPORTED_LANGUAGE_FLAVOR_SET) { - let m = p.start(); - p.bump_ts(SUPPORTED_LANGUAGE_FLAVOR_SET); - m.complete(p, GRIT_LANGUAGE_FLAVOR_KIND); - - if !p.eat(T![,]) { - break; - } - } else if p.at(T![')']) { - break; - } else { - p.error(p.err_builder( - "Expected a supported language flavor; must be one of `typescript` or `jsx`", - p.cur_range(), - )); - break; - } - } - - m.complete(p, GRIT_LANGUAGE_FLAVOR_LIST); - } - - p.eat(T![')']); - - let result = m.complete(p, GRIT_LANGUAGE_FLAVOR); - - Some(result) -} - -fn parse_definition_list(p: &mut GritParser) -> CompletedMarker { - let m = p.start(); - - // TODO - - m.complete(p, GRIT_DEFINITION_LIST) -} - -fn parse_pattern(p: &mut GritParser) -> ParsedSyntax { - match p.cur() { - _ => parse_literal(p), - } -} - -fn parse_literal(p: &mut GritParser) -> ParsedSyntax { - match p.cur() { - TRUE_KW | FALSE_KW => parse_boolean_literal(p), - GRIT_DOUBLE => parse_double_literal(p), - GRIT_INT => parse_int_literal(p), - GRIT_NEGATIVE_INT => parse_negative_int_literal(p), - GRIT_STRING => parse_string_literal(p), - UNDEFINED_KW => parse_undefined_literal(p), - kind if CODE_SNIPPET_SET.contains(kind) => parse_code_snippet(p), - // TODO: List - // TODO: Map - _ => Absent, - } -} - -#[inline] -fn parse_backtick_snippet_literal(p: &mut GritParser) -> ParsedSyntax { - if !p.at(GRIT_BACKTICK_SNIPPET) { - return Absent; - } - - let m = p.start(); - p.bump(GRIT_BACKTICK_SNIPPET); - Present(m.complete(p, GRIT_BACKTICK_SNIPPET_LITERAL)) -} - -#[inline] -fn parse_boolean_literal(p: &mut GritParser) -> ParsedSyntax { - if !p.at_ts(BOOLEAN_VALUE_SET) { - return Absent; - } - - let m = p.start(); - p.bump_ts(BOOLEAN_VALUE_SET); - Present(m.complete(p, GRIT_BOOLEAN_LITERAL)) -} - -#[inline] -fn parse_code_snippet(p: &mut GritParser) -> ParsedSyntax { - if !p.at_ts(CODE_SNIPPET_SET) { - return Absent; - } - - let m = p.start(); - - let syntax = match p.cur() { - GRIT_BACKTICK_SNIPPET => parse_backtick_snippet_literal(p), - GRIT_RAW_BACKTICK_SNIPPET => parse_raw_backtick_snippet_literal(p), - _ => parse_language_specific_snippet(p), - }; - - match syntax { - Present(_) => Present(m.complete(p, GRIT_CODE_SNIPPET)), - Absent => { - m.abandon(p); - Absent - } - } -} - -#[inline] -fn parse_double_literal(p: &mut GritParser) -> ParsedSyntax { - if !p.at(GRIT_DOUBLE) { - return Absent; - } - - let m = p.start(); - p.bump(GRIT_DOUBLE); - Present(m.complete(p, GRIT_DOUBLE_LITERAL)) -} - -#[inline] -fn parse_int_literal(p: &mut GritParser) -> ParsedSyntax { - if !p.at(GRIT_INT) { - return Absent; - } - - let m = p.start(); - p.bump(GRIT_INT); - Present(m.complete(p, GRIT_INT_LITERAL)) -} - -#[inline] -fn parse_language_specific_snippet(p: &mut GritParser) -> ParsedSyntax { - if !p.at_ts(SUPPORTED_LANGUAGE_SET) { - return Absent; - } - - let m = p.start(); - - p.bump_ts(SUPPORTED_LANGUAGE_SET); - p.eat(GRIT_STRING); - - Present(m.complete(p, GRIT_LANGUAGE_SPECIFIC_SNIPPET)) -} - -#[inline] -fn parse_negative_int_literal(p: &mut GritParser) -> ParsedSyntax { - if !p.at(GRIT_NEGATIVE_INT) { - return Absent; - } - - let m = p.start(); - p.bump(GRIT_NEGATIVE_INT); - Present(m.complete(p, GRIT_NEGATIVE_INT_LITERAL)) -} - -#[inline] -fn parse_raw_backtick_snippet_literal(p: &mut GritParser) -> ParsedSyntax { - if !p.at(GRIT_RAW_BACKTICK_SNIPPET) { - return Absent; - } - - let m = p.start(); - p.bump(GRIT_RAW_BACKTICK_SNIPPET); - Present(m.complete(p, GRIT_RAW_BACKTICK_SNIPPET_LITERAL)) -} - -#[inline] -fn parse_string_literal(p: &mut GritParser) -> ParsedSyntax { - if !p.at(GRIT_STRING) { - return Absent; - } - - let m = p.start(); - p.bump(GRIT_STRING); - Present(m.complete(p, GRIT_STRING_LITERAL)) -} - -#[inline] -fn parse_undefined_literal(p: &mut GritParser) -> ParsedSyntax { - if !p.at(UNDEFINED_KW) { - return Absent; - } - - let m = p.start(); - p.bump(UNDEFINED_KW); - Present(m.complete(p, GRIT_UNDEFINED_LITERAL)) -} diff --git a/crates/biome_grit_parser/src/parser/literals.rs b/crates/biome_grit_parser/src/parser/literals.rs new file mode 100644 index 00000000000..fbfe6b40860 --- /dev/null +++ b/crates/biome_grit_parser/src/parser/literals.rs @@ -0,0 +1,153 @@ +use super::{GritParser, SUPPORTED_LANGUAGE_SET}; +use biome_grit_syntax::GritSyntaxKind::{self, *}; +use biome_parser::prelude::{ParsedSyntax::*, *}; + +const BOOLEAN_VALUE_SET: TokenSet = token_set![TRUE_KW, FALSE_KW]; + +const CODE_SNIPPET_SET: TokenSet = + SUPPORTED_LANGUAGE_SET.union(token_set![GRIT_BACKTICK_SNIPPET, GRIT_RAW_BACKTICK_SNIPPET]); + +pub(crate) fn parse_literal(p: &mut GritParser) -> ParsedSyntax { + match p.cur() { + TRUE_KW | FALSE_KW => parse_boolean_literal(p), + GRIT_DOUBLE => parse_double_literal(p), + GRIT_INT => parse_int_literal(p), + GRIT_NEGATIVE_INT => parse_negative_int_literal(p), + GRIT_STRING => parse_string_literal(p), + UNDEFINED_KW => parse_undefined_literal(p), + kind if CODE_SNIPPET_SET.contains(kind) => parse_code_snippet(p), + // TODO: List + // TODO: Map + _ => Absent, + } +} + +#[inline] +fn parse_backtick_snippet_literal(p: &mut GritParser) -> ParsedSyntax { + if !p.at(GRIT_BACKTICK_SNIPPET) { + return Absent; + } + + let m = p.start(); + p.bump(GRIT_BACKTICK_SNIPPET); + Present(m.complete(p, GRIT_BACKTICK_SNIPPET_LITERAL)) +} + +#[inline] +pub(crate) fn parse_boolean_literal(p: &mut GritParser) -> ParsedSyntax { + if !p.at_ts(BOOLEAN_VALUE_SET) { + return Absent; + } + + let m = p.start(); + p.bump_ts(BOOLEAN_VALUE_SET); + Present(m.complete(p, GRIT_BOOLEAN_LITERAL)) +} + +#[inline] +fn parse_code_snippet(p: &mut GritParser) -> ParsedSyntax { + if !p.at_ts(CODE_SNIPPET_SET) { + return Absent; + } + + let m = p.start(); + + let syntax = match p.cur() { + GRIT_BACKTICK_SNIPPET => parse_backtick_snippet_literal(p), + GRIT_RAW_BACKTICK_SNIPPET => parse_raw_backtick_snippet_literal(p), + _ => parse_language_specific_snippet(p), + }; + + match syntax { + Present(_) => Present(m.complete(p, GRIT_CODE_SNIPPET)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +pub(crate) fn parse_double_literal(p: &mut GritParser) -> ParsedSyntax { + if !p.at(GRIT_DOUBLE) { + return Absent; + } + + let m = p.start(); + p.bump(GRIT_DOUBLE); + Present(m.complete(p, GRIT_DOUBLE_LITERAL)) +} + +#[inline] +fn parse_int_literal(p: &mut GritParser) -> ParsedSyntax { + if !p.at(GRIT_INT) { + return Absent; + } + + let m = p.start(); + p.bump(GRIT_INT); + Present(m.complete(p, GRIT_INT_LITERAL)) +} + +#[inline] +fn parse_language_specific_snippet(p: &mut GritParser) -> ParsedSyntax { + if !p.at_ts(SUPPORTED_LANGUAGE_SET) { + return Absent; + } + + let m = p.start(); + + { + let m = p.start(); + p.bump_ts(SUPPORTED_LANGUAGE_SET); + m.complete(p, GRIT_LANGUAGE_NAME); + } + + p.eat(GRIT_STRING); + + Present(m.complete(p, GRIT_LANGUAGE_SPECIFIC_SNIPPET)) +} + +#[inline] +fn parse_negative_int_literal(p: &mut GritParser) -> ParsedSyntax { + if !p.at(GRIT_NEGATIVE_INT) { + return Absent; + } + + let m = p.start(); + p.bump(GRIT_NEGATIVE_INT); + Present(m.complete(p, GRIT_NEGATIVE_INT_LITERAL)) +} + +#[inline] +fn parse_raw_backtick_snippet_literal(p: &mut GritParser) -> ParsedSyntax { + if !p.at(GRIT_RAW_BACKTICK_SNIPPET) { + return Absent; + } + + let m = p.start(); + p.bump(GRIT_RAW_BACKTICK_SNIPPET); + Present(m.complete(p, GRIT_RAW_BACKTICK_SNIPPET_LITERAL)) +} + +#[inline] +fn parse_string_literal(p: &mut GritParser) -> ParsedSyntax { + if !p.at(GRIT_STRING) { + return Absent; + } + + let m = p.start(); + p.bump(GRIT_STRING); + Present(m.complete(p, GRIT_STRING_LITERAL)) +} + +#[inline] +fn parse_undefined_literal(p: &mut GritParser) -> ParsedSyntax { + if !p.at(UNDEFINED_KW) { + return Absent; + } + + let m = p.start(); + p.bump(UNDEFINED_KW); + Present(m.complete(p, GRIT_UNDEFINED_LITERAL)) +} diff --git a/crates/biome_grit_parser/src/parser/mod.rs b/crates/biome_grit_parser/src/parser/mod.rs new file mode 100644 index 00000000000..fdf98aabbae --- /dev/null +++ b/crates/biome_grit_parser/src/parser/mod.rs @@ -0,0 +1,227 @@ +mod literals; +mod patterns; +mod predicates; + +use crate::token_source::GritTokenSource; +use biome_grit_syntax::GritSyntaxKind::{self, *}; +use biome_grit_syntax::T; +use biome_parser::diagnostic::merge_diagnostics; +use biome_parser::event::Event; +use biome_parser::prelude::{ParsedSyntax::*, *}; +use biome_parser::token_source::Trivia; +use biome_parser::ParserContext; +use biome_rowan::TextRange; +use literals::parse_double_literal; +use patterns::parse_pattern; + +const SUPPORTED_LANGUAGE_SET: TokenSet = + token_set![T![js], T![json], T![css], T![grit], T![html]]; + +const SUPPORTED_LANGUAGE_FLAVOR_SET: TokenSet = token_set![T![typescript], T![jsx]]; + +pub(crate) struct GritParser<'source> { + context: ParserContext, + source: GritTokenSource<'source>, +} + +impl<'source> GritParser<'source> { + pub fn new(source: &'source str) -> Self { + Self { + context: ParserContext::default(), + source: GritTokenSource::from_str(source), + } + } + + pub fn finish( + self, + ) -> ( + Vec>, + Vec, + Vec, + ) { + let (trivia, lexer_diagnostics) = self.source.finish(); + let (events, parse_diagnostics) = self.context.finish(); + + let diagnostics = merge_diagnostics(lexer_diagnostics, parse_diagnostics); + + (events, diagnostics, trivia) + } +} + +impl<'source> Parser for GritParser<'source> { + type Kind = GritSyntaxKind; + type Source = GritTokenSource<'source>; + + fn context(&self) -> &ParserContext { + &self.context + } + + fn context_mut(&mut self) -> &mut ParserContext { + &mut self.context + } + + fn source(&self) -> &Self::Source { + &self.source + } + + fn source_mut(&mut self) -> &mut Self::Source { + &mut self.source + } +} + +pub(crate) fn parse_root(p: &mut GritParser) -> CompletedMarker { + let m = p.start(); + + p.eat(UNICODE_BOM); + + parse_version(p); + parse_language(p); + parse_definition_list(p); + let _ = parse_pattern(p); + parse_definition_list(p); + + p.eat(EOF); + + m.complete(p, GRIT_ROOT) +} + +fn parse_version(p: &mut GritParser) -> Option { + if !p.at(T![engine]) { + return None; + } + + let m = p.start(); + p.bump(T![engine]); + + let engine_range = p.cur_range(); + if p.eat(T![biome]) { + if p.eat(T!['(']) { + match parse_double_literal(p) { + Present(_) => { + p.eat(T![')']); + } + Absent => p.error(p.err_builder("Expected version as a double", p.cur_range())), + } + } else { + let engine_end = engine_range.end(); + p.error(p.err_builder( + "Expected an engine version", + TextRange::new(engine_end, engine_end), + )) + } + } else { + p.error(p.err_builder("Engine must be `biome`", engine_range)); + } + + let result = m.complete(p, GRIT_VERSION); + + Some(result) +} + +fn parse_language(p: &mut GritParser) -> Option { + if !p.at(T![language]) { + return None; + } + + let m = p.start(); + p.bump(T![language]); + + if p.at_ts(SUPPORTED_LANGUAGE_SET) { + let m = p.start(); + p.bump_ts(SUPPORTED_LANGUAGE_SET); + m.complete(p, GRIT_LANGUAGE_NAME); + } else { + p.error(p.err_builder( + "Expected a supported language; must be one of `js`, `json`, `css`, `html`, or `grit`", + p.cur_range(), + )) + } + + let _ = parse_language_flavor(p); + + p.eat(T![;]); + + let result = m.complete(p, GRIT_LANGUAGE_DECLARATION); + + Some(result) +} + +fn parse_language_flavor(p: &mut GritParser) -> ParsedSyntax { + if !p.at(T!['(']) { + return Absent; + } + + let m = p.start(); + p.bump(T!['(']); + + if parse_language_flavor_list(p) == Absent { + p.error(p.err_builder("Expected a language flavor", p.cur_range())); + m.abandon(p); + return Absent; + } + + p.eat(T![')']); + + Present(m.complete(p, GRIT_LANGUAGE_FLAVOR)) +} + +fn parse_language_flavor_list(p: &mut GritParser) -> ParsedSyntax { + let m = p.start(); + + let _ = parse_language_flavor_kind(p); + + while p.eat(T![,]) { + let _ = parse_language_flavor_kind(p); + } + + Present(m.complete(p, GRIT_LANGUAGE_FLAVOR_LIST)) +} + +fn parse_language_flavor_kind(p: &mut GritParser) -> ParsedSyntax { + let m = p.start(); + + if p.at_ts(SUPPORTED_LANGUAGE_FLAVOR_SET) { + p.bump_ts(SUPPORTED_LANGUAGE_FLAVOR_SET); + Present(m.complete(p, GRIT_LANGUAGE_FLAVOR_KIND)) + } else { + p.error(p.err_builder( + "Expected a supported language flavor; must be one of `typescript` or `jsx`", + p.cur_range(), + )); + m.abandon(p); + Absent + } +} + +fn parse_definition_list(p: &mut GritParser) -> CompletedMarker { + let m = p.start(); + + match p.cur() { + GRIT_BOGUS => { + let m = p.start(); + p.bump(GRIT_BOGUS); + m.complete(p, GRIT_BOGUS_DEFINITION); + } + _ => {} + } + + m.complete(p, GRIT_DEFINITION_LIST) +} + +#[inline] +fn parse_variable_list(p: &mut GritParser) -> ParsedSyntax { + if !p.at(GRIT_VARIABLE) { + return Absent; + } + + let m = p.start(); + p.bump(GRIT_VARIABLE); + + while p.eat(T![,]) { + if !p.eat(GRIT_VARIABLE) { + break; + } + } + + Present(m.complete(p, GRIT_VARIABLE_LIST)) +} diff --git a/crates/biome_grit_parser/src/parser/patterns.rs b/crates/biome_grit_parser/src/parser/patterns.rs new file mode 100644 index 00000000000..a01a4d0ddae --- /dev/null +++ b/crates/biome_grit_parser/src/parser/patterns.rs @@ -0,0 +1,692 @@ +use super::literals::parse_literal; +use super::predicates::parse_predicate; +use super::{parse_variable_list, GritParser}; +use biome_grit_syntax::GritSyntaxKind::{self, *}; +use biome_grit_syntax::T; +use biome_parser::prelude::{ParsedSyntax::*, *}; + +const NOT_SET: TokenSet = token_set![NOT_KW, T![!]]; + +const REGEX_SET: TokenSet = token_set![GRIT_REGEX, GRIT_SNIPPET_REGEX]; + +pub(crate) fn parse_pattern(p: &mut GritParser) -> ParsedSyntax { + let left = match p.cur() { + NOT_KW | T![!] => parse_pattern_not(p), + OR_KW => parse_pattern_or(p), + ORELSE_KW => parse_pattern_orelse(p), + ANY_KW => parse_pattern_any(p), + AND_KW => parse_pattern_and(p), + MAYBE_KW => parse_pattern_maybe(p), + IF_KW => parse_pattern_if_else(p), + CONTAINS_KW => parse_pattern_contains(p), + INCLUDES_KW => parse_pattern_includes(p), + AFTER_KW => parse_pattern_after(p), + BEFORE_KW => parse_pattern_before(p), + WITHIN_KW => parse_pattern_within(p), + BUBBLE_KW => parse_bubble(p), + // TODO: GritNodeLike => {} + // TODO: GritMapAccessor => {} + // TODO: GritListAccessor => {} + T![.] => parse_dot(p), + SOME_KW => parse_some(p), + EVERY_KW => parse_every(p), + GRIT_UNDERSCORE => { + let m = p.start(); + p.bump(GRIT_UNDERSCORE); + Present(m.complete(p, GRIT_UNDERSCORE)) + } + GRIT_VARIABLE => { + let m = p.start(); + p.bump(GRIT_VARIABLE); + Present(m.complete(p, GRIT_VARIABLE)) + } + GRIT_REGEX | GRIT_SNIPPET_REGEX => parse_regex_pattern(p), + // TODO: GritPatternAs => {} + // TODO: GritPatternLimit => {} + // TODO: GritAssignmentAsPattern => {} + // TODO: GritPatternAccumulate => {} + LIKE_KW => parse_like(p), + // TODO: GritMulOperation => {} + // TODO: GritDivOperation => {} + // TODO: GritModOperation => {} + // TODO: GritAddOperation => {} + // TODO: GritSubOperation => {} + SEQUENTIAL_KW => parse_sequential(p), + MULTIFILE_KW => parse_files(p), + T!['('] => parse_bracketed_pattern(p), + _ => parse_literal(p), + }; + + if left == Absent { + return Absent; + } + + match p.cur() { + T![=>] => parse_rewrite(p, left), + WHERE_KW => parse_pattern_where(p, left), + _ => left, + } +} + +#[inline] +fn parse_bracketed_pattern(p: &mut GritParser) -> ParsedSyntax { + if !p.at(T!['(']) { + return Absent; + } + + let m = p.start(); + p.bump(T!['(']); + + let result = parse_pattern(p); + + p.eat(T![')']); + + match result { + Present(_) => Present(m.complete(p, BRACKETED_GRIT_PATTERN)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_bubble(p: &mut GritParser) -> ParsedSyntax { + if !p.at(BUBBLE_KW) { + return Absent; + } + + let m = p.start(); + p.bump(BUBBLE_KW); + + let _ = parse_bubble_scope(p); + + match parse_maybe_curly_pattern(p) { + Present(_) => Present(m.complete(p, GRIT_BUBBLE)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_bubble_scope(p: &mut GritParser) -> ParsedSyntax { + if !p.at(T!['(']) { + return Absent; + } + + let m = p.start(); + p.bump(T!['(']); + + if p.eat(T![')']) { + return Present(m.complete(p, GRIT_BUBBLE_SCOPE)); + } + + let _ = parse_variable_list(p); + + p.eat(T![')']); + + Present(m.complete(p, GRIT_BUBBLE)) +} + +#[inline] +fn parse_curly_pattern(p: &mut GritParser) -> ParsedSyntax { + if !p.at(T!['{']) { + return Absent; + } + + let m = p.start(); + p.bump(T!['{']); + + let result = parse_pattern(p); + + p.eat(T!['}']); + + match result { + Present(_) => Present(m.complete(p, CURLY_GRIT_PATTERN)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_dot(p: &mut GritParser) -> ParsedSyntax { + if !p.at(T![.]) { + return Absent; + } + + let m = p.start(); + p.bump(T![.]); + Present(m.complete(p, GRIT_DOT)) +} + +#[inline] +fn parse_every(p: &mut GritParser) -> ParsedSyntax { + if !p.at(EVERY_KW) { + return Absent; + } + + let m = p.start(); + p.bump(EVERY_KW); + + match parse_maybe_curly_pattern(p) { + Present(_) => Present(m.complete(p, GRIT_EVERY)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_files(p: &mut GritParser) -> ParsedSyntax { + if !p.at(MULTIFILE_KW) { + return Absent; + } + + let m = p.start(); + p.bump(MULTIFILE_KW); + + p.eat(T!['{']); + + let result = parse_pattern_list(p); + + p.eat(T!['}']); + + match result { + Present(_) => Present(m.complete(p, GRIT_FILES)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_like(p: &mut GritParser) -> ParsedSyntax { + if !p.at(LIKE_KW) { + return Absent; + } + + let m = p.start(); + p.bump(LIKE_KW); + + let _ = parse_like_threshold(p); + + p.eat(T!['{']); + + let result = parse_pattern(p); + + p.eat(T!['}']); + + match result { + Present(_) => Present(m.complete(p, GRIT_LIKE)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_like_threshold(p: &mut GritParser) -> ParsedSyntax { + if !p.at(T!['(']) { + return Absent; + } + + let m = p.start(); + p.bump(T!['(']); + + let result = parse_pattern(p); + + p.eat(T![')']); + + match result { + Present(_) => Present(m.complete(p, GRIT_LIKE_THRESHOLD)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_maybe_curly_pattern(p: &mut GritParser) -> ParsedSyntax { + let m = p.start(); + + let result = if p.at(T!['{']) { + parse_curly_pattern(p) + } else { + parse_pattern(p) + }; + + match result { + Present(_) => Present(m.complete(p, MAYBE_CURLY_GRIT_PATTERN)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_pattern_after(p: &mut GritParser) -> ParsedSyntax { + if !p.at(AFTER_KW) { + return Absent; + } + + let m = p.start(); + p.bump(AFTER_KW); + match parse_pattern(p) { + Present(_) => Present(m.complete(p, GRIT_PATTERN_AFTER)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_pattern_and(p: &mut GritParser) -> ParsedSyntax { + if !p.at(AND_KW) { + return Absent; + } + + let m = p.start(); + p.bump(AND_KW); + p.eat(T!['{']); + + if p.eat(T!['}']) { + return Present(m.complete(p, GRIT_PATTERN_AND)); + } + + let result = parse_pattern_list(p); + + p.eat(T!['}']); + + match result { + Present(_) => Present(m.complete(p, GRIT_PATTERN_AND)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_pattern_any(p: &mut GritParser) -> ParsedSyntax { + if !p.at(ANY_KW) { + return Absent; + } + + let m = p.start(); + p.bump(ANY_KW); + p.eat(T!['{']); + + if p.eat(T!['}']) { + return Present(m.complete(p, GRIT_PATTERN_ANY)); + } + + let result = parse_pattern_list(p); + + p.eat(T!['}']); + + match result { + Present(_) => Present(m.complete(p, GRIT_PATTERN_ANY)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_pattern_arg_list(p: &mut GritParser) -> ParsedSyntax { + let m = p.start(); + match parse_variable_list(p) { + Present(_) => Present(m.complete(p, GRIT_PATTERN_ARG_LIST)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_pattern_before(p: &mut GritParser) -> ParsedSyntax { + if !p.at(BEFORE_KW) { + return Absent; + } + + let m = p.start(); + p.bump(BEFORE_KW); + match parse_pattern(p) { + Present(_) => Present(m.complete(p, GRIT_PATTERN_BEFORE)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_pattern_contains(p: &mut GritParser) -> ParsedSyntax { + if !p.at(CONTAINS_KW) { + return Absent; + } + + let m = p.start(); + p.bump(CONTAINS_KW); + + match parse_maybe_curly_pattern(p) { + Present(_) => { + let _ = parse_pattern_contains_until_clause(p); + + Present(m.complete(p, GRIT_PATTERN_CONTAINS)) + } + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_pattern_contains_until_clause(p: &mut GritParser) -> ParsedSyntax { + if !p.at(UNTIL_KW) { + return Absent; + } + + let m = p.start(); + p.bump(UNTIL_KW); + + match parse_pattern(p) { + Present(_) => Present(m.complete(p, GRIT_PATTERN_CONTAINS_UNTIL_CLAUSE)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_pattern_if_else(p: &mut GritParser) -> ParsedSyntax { + if !p.at(IF_KW) { + return Absent; + } + + let m = p.start(); + p.bump(IF_KW); + p.eat(T!['(']); + + let _ = parse_predicate(p); + + p.eat(T![')']); + + let _ = parse_maybe_curly_pattern(p); + + let _ = parse_pattern_else_clause(p); + + Present(m.complete(p, GRIT_PATTERN_IF_ELSE)) +} + +#[inline] +fn parse_pattern_else_clause(p: &mut GritParser) -> ParsedSyntax { + if !p.at(ELSE_KW) { + return Absent; + } + + let m = p.start(); + p.bump(ELSE_KW); + + match parse_maybe_curly_pattern(p) { + Present(_) => Present(m.complete(p, GRIT_PATTERN_ELSE_CLAUSE)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_pattern_includes(p: &mut GritParser) -> ParsedSyntax { + if !p.at(INCLUDES_KW) { + return Absent; + } + + let m = p.start(); + p.bump(INCLUDES_KW); + + match parse_maybe_curly_pattern(p) { + Present(_) => Present(m.complete(p, GRIT_PATTERN_INCLUDES)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_pattern_list(p: &mut GritParser) -> ParsedSyntax { + let m = p.start(); + + if parse_pattern(p) == Absent { + m.abandon(p); + return Absent; + } + + while p.eat(T![,]) { + if parse_pattern(p) == Absent { + break; + } + } + + Present(m.complete(p, GRIT_PATTERN_LIST)) +} + +#[inline] +fn parse_pattern_maybe(p: &mut GritParser) -> ParsedSyntax { + if !p.at(MAYBE_KW) { + return Absent; + } + + let m = p.start(); + p.bump(MAYBE_KW); + match parse_maybe_curly_pattern(p) { + Present(_) => Present(m.complete(p, GRIT_PATTERN_MAYBE)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_pattern_not(p: &mut GritParser) -> ParsedSyntax { + if !p.at_ts(NOT_SET) { + return Absent; + } + + let m = p.start(); + p.bump_ts(NOT_SET); + match parse_pattern(p) { + Present(_) => Present(m.complete(p, GRIT_PATTERN_NOT)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_pattern_or(p: &mut GritParser) -> ParsedSyntax { + if !p.at(OR_KW) { + return Absent; + } + + let m = p.start(); + p.bump(OR_KW); + p.eat(T!['{']); + + let result = parse_pattern_list(p); + + p.eat(T!['}']); + + match result { + Present(_) => Present(m.complete(p, GRIT_PATTERN_OR)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_pattern_orelse(p: &mut GritParser) -> ParsedSyntax { + if !p.at(ORELSE_KW) { + return Absent; + } + + let m = p.start(); + p.bump(ORELSE_KW); + p.eat(T!['{']); + + if p.eat(T!['}']) { + return Present(m.complete(p, GRIT_PATTERN_OR_ELSE)); + } + + let _ = parse_pattern_list(p); + + p.eat(T!['}']); + + Present(m.complete(p, GRIT_PATTERN_OR_ELSE)) +} + +#[inline] +fn parse_pattern_where(p: &mut GritParser, left: ParsedSyntax) -> ParsedSyntax { + if !p.at(WHERE_KW) { + return Absent; + } + + let m = left.precede(p); + p.bump(WHERE_KW); + + match parse_predicate(p) { + Present(_) => Present(m.complete(p, GRIT_PATTERN_WHERE)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_pattern_within(p: &mut GritParser) -> ParsedSyntax { + if !p.at(WITHIN_KW) { + return Absent; + } + + let m = p.start(); + p.bump(WITHIN_KW); + + match parse_maybe_curly_pattern(p) { + Present(_) => Present(m.complete(p, GRIT_WITHIN)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_regex_pattern(p: &mut GritParser) -> ParsedSyntax { + if !p.at_ts(REGEX_SET) { + return Absent; + } + + let m = p.start(); + p.bump_ts(REGEX_SET); + + let _ = parse_regex_pattern_variables(p); + + Present(m.complete(p, GRIT_REGEX_PATTERN)) +} + +#[inline] +fn parse_regex_pattern_variables(p: &mut GritParser) -> ParsedSyntax { + if !p.at(T!['(']) { + return Absent; + } + + let m = p.start(); + p.bump(T!['(']); + + let _ = parse_pattern_arg_list(p); + + p.eat(T![')']); + + Present(m.complete(p, GRIT_REGEX_PATTERN_VARIABLES)) +} + +#[inline] +fn parse_rewrite(p: &mut GritParser, left: ParsedSyntax) -> ParsedSyntax { + if !p.at(T![=>]) { + return Absent; + } + + let m = left.precede(p); + p.bump(T![=>]); + + match parse_pattern(p) { + Present(_) => Present(m.complete(p, GRIT_REWRITE)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_sequential(p: &mut GritParser) -> ParsedSyntax { + if !p.at(SEQUENTIAL_KW) { + return Absent; + } + + let m = p.start(); + p.bump(SEQUENTIAL_KW); + + p.eat(T!['{']); + + let result = parse_pattern_list(p); + + p.eat(T!['}']); + + match result { + Present(_) => Present(m.complete(p, GRIT_SEQUENTIAL)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_some(p: &mut GritParser) -> ParsedSyntax { + if !p.at(SOME_KW) { + return Absent; + } + + let m = p.start(); + p.bump(SOME_KW); + + match parse_maybe_curly_pattern(p) { + Present(_) => Present(m.complete(p, GRIT_SOME)), + Absent => { + m.abandon(p); + Absent + } + } +} diff --git a/crates/biome_grit_parser/src/parser/predicates.rs b/crates/biome_grit_parser/src/parser/predicates.rs new file mode 100644 index 00000000000..2eccd910c14 --- /dev/null +++ b/crates/biome_grit_parser/src/parser/predicates.rs @@ -0,0 +1,256 @@ +use super::literals::{parse_boolean_literal, parse_literal}; +use super::patterns::parse_pattern; +use super::GritParser; +use biome_grit_syntax::GritSyntaxKind::{self, *}; +use biome_grit_syntax::T; +use biome_parser::prelude::{ParsedSyntax::*, *}; + +const NOT_SET: TokenSet = token_set![NOT_KW, T![!]]; + +pub(crate) fn parse_predicate(p: &mut GritParser) -> ParsedSyntax { + match p.cur() { + NOT_KW | T![!] => parse_predicate_not(p), + MAYBE_KW => parse_predicate_maybe(p), + AND_KW | T!['{'] => parse_predicate_and(p), + OR_KW => parse_predicate_or(p), + ANY_KW => parse_predicate_any(p), + IF_KW => parse_predicate_if_else(p), + // TODO: GritPredicateAssignment => {} + // TODO: GritPredicateAccumulate => {} + // TODO: GritPredicateRewrite => {} + // TODO: GritPredicateGreater => {} + // TODO: GritPredicateLess => {} + // TODO: GritPredicateGreaterEqual => {} + // TODO: GritPredicateLessEqual => {} + // TODO: GritPredicateNotEqual => {} + // TODO: GritPredicateEqual => {} + // TODO: GritPredicateCall => {} + T!['('] => parse_bracketed_predicate(p), + T![true] | T![false] => parse_boolean_literal(p), + // TODO: GritPredicateReturn => {} + _ => parse_predicate_match(p), + } +} + +#[inline] +fn parse_bracketed_predicate(p: &mut GritParser) -> ParsedSyntax { + if !p.at(T!['(']) { + return Absent; + } + + let m = p.start(); + p.bump(T!['(']); + + let result = parse_predicate(p); + + p.eat(T![')']); + + match result { + Present(_) => Present(m.complete(p, BRACKETED_GRIT_PREDICATE)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_predicate_and(p: &mut GritParser) -> ParsedSyntax { + if !p.at(AND_KW) && !p.at(T!['{']) { + return Absent; + } + + let m = p.start(); + p.eat(AND_KW); + p.eat(T!['{']); + + if p.eat(T!['}']) { + return Present(m.complete(p, GRIT_PREDICATE_AND)); + } + + let result = parse_predicate_list(p); + + p.eat(T!['}']); + + match result { + Present(_) => Present(m.complete(p, GRIT_PREDICATE_AND)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_predicate_any(p: &mut GritParser) -> ParsedSyntax { + if !p.at(ANY_KW) { + return Absent; + } + + let m = p.start(); + p.bump(ANY_KW); + p.eat(T!['{']); + + if p.eat(T!['}']) { + return Present(m.complete(p, GRIT_PREDICATE_ANY)); + } + + let result = parse_predicate_list(p); + + p.eat(T!['}']); + + match result { + Present(_) => Present(m.complete(p, GRIT_PREDICATE_ANY)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_predicate_if_else(p: &mut GritParser) -> ParsedSyntax { + if !p.at(IF_KW) { + return Absent; + } + + let m = p.start(); + p.bump(IF_KW); + p.eat(T!['(']); + + let _ = parse_predicate(p); + + p.eat(T![')']); + + let _ = parse_predicate(p); + + let _ = parse_predicate_else_clause(p); + + Present(m.complete(p, GRIT_PREDICATE_IF_ELSE)) +} + +#[inline] +fn parse_predicate_else_clause(p: &mut GritParser) -> ParsedSyntax { + if !p.at(ELSE_KW) { + return Absent; + } + + let m = p.start(); + p.bump(ELSE_KW); + + match parse_predicate(p) { + Present(_) => Present(m.complete(p, GRIT_PREDICATE_ELSE_CLAUSE)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_predicate_list(p: &mut GritParser) -> ParsedSyntax { + let m = p.start(); + + if parse_predicate(p) == Absent { + m.abandon(p); + return Absent; + } + + while p.eat(T![,]) { + if parse_predicate(p) == Absent { + break; + } + } + + Present(m.complete(p, GRIT_PREDICATE_LIST)) +} + +#[inline] +fn parse_predicate_match(p: &mut GritParser) -> ParsedSyntax { + let m = p.start(); + + if parse_predicate_match_subject(p) == Absent { + m.abandon(p); + return Absent; + } + + if !p.eat(T![<:]) { + m.abandon(p); + return Absent; + } + + let _ = parse_pattern(p); + + Present(m.complete(p, GRIT_PREDICATE_MATCH)) +} + +#[inline] +fn parse_predicate_match_subject(p: &mut GritParser) -> ParsedSyntax { + match p.cur() { + GRIT_VARIABLE => { + let m = p.start(); + p.bump(GRIT_VARIABLE); + Present(m.complete(p, GRIT_VARIABLE)) + } + // TODO: GritMapAccessor => {} + // TODO: GritListAccessor => {} + _ => parse_literal(p), + } +} + +#[inline] +fn parse_predicate_maybe(p: &mut GritParser) -> ParsedSyntax { + if !p.at(MAYBE_KW) { + return Absent; + } + + let m = p.start(); + p.bump(MAYBE_KW); + match parse_predicate(p) { + Present(_) => Present(m.complete(p, GRIT_PREDICATE_MAYBE)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_predicate_not(p: &mut GritParser) -> ParsedSyntax { + if !p.at_ts(NOT_SET) { + return Absent; + } + + let m = p.start(); + p.bump_ts(NOT_SET); + match parse_predicate(p) { + Present(_) => Present(m.complete(p, GRIT_PREDICATE_NOT)), + Absent => { + m.abandon(p); + Absent + } + } +} + +#[inline] +fn parse_predicate_or(p: &mut GritParser) -> ParsedSyntax { + if !p.at(OR_KW) { + return Absent; + } + + let m = p.start(); + p.bump(OR_KW); + p.eat(T!['{']); + + let result = parse_predicate_list(p); + + p.eat(T!['}']); + + match result { + Present(_) => Present(m.complete(p, GRIT_PREDICATE_OR)), + Absent => { + m.abandon(p); + Absent + } + } +} diff --git a/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_version.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_version.grit.snap index 12302a196e7..c5905ad5fce 100644 --- a/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_version.grit.snap +++ b/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_version.grit.snap @@ -21,9 +21,11 @@ GritRoot { }, language: missing (optional), definitions: GritDefinitionList [], - pattern: missing (optional), + pattern: GritStringLiteral { + value_token: GRIT_STRING@14..19 "\"1.0\"" [] [], + }, definitions_continued: GritDefinitionList [], - eof_token: EOF@14..20 "\"1.0\")" [] [], + eof_token: EOF@19..20 ")" [] [], } ``` @@ -40,9 +42,10 @@ GritRoot { 4: (empty) 2: (empty) 3: GRIT_DEFINITION_LIST@14..14 - 4: (empty) - 5: GRIT_DEFINITION_LIST@14..14 - 6: EOF@14..20 "\"1.0\")" [] [] + 4: GRIT_STRING_LITERAL@14..19 + 0: GRIT_STRING@14..19 "\"1.0\"" [] [] + 5: GRIT_DEFINITION_LIST@19..19 + 6: EOF@19..20 ")" [] [] ``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/pattern_with_version.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/pattern_with_version.grit.snap index 27ac07ec154..b08d8cd4a7c 100644 --- a/crates/biome_grit_parser/tests/grit_test_suite/ok/pattern_with_version.grit.snap +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/pattern_with_version.grit.snap @@ -17,8 +17,8 @@ GritRoot { engine_token: ENGINE_KW@0..7 "engine" [] [Whitespace(" ")], biome_token: BIOME_KW@7..13 "biome" [] [Whitespace(" ")], l_paren_token: L_PAREN@13..14 "(" [] [], - grit_double_value: GritDoubleValue { - value_token: GRIT_DOUBLE_LITERAL@14..17 "1.0" [] [], + grit_double_literal: GritDoubleLiteral { + value_token: GRIT_DOUBLE@14..17 "1.0" [] [], }, r_paren_token: R_PAREN@17..18 ")" [] [], }, @@ -39,8 +39,8 @@ GritRoot { 0: ENGINE_KW@0..7 "engine" [] [Whitespace(" ")] 1: BIOME_KW@7..13 "biome" [] [Whitespace(" ")] 2: L_PAREN@13..14 "(" [] [] - 3: GRIT_DOUBLE_VALUE@14..17 - 0: GRIT_DOUBLE_LITERAL@14..17 "1.0" [] [] + 3: GRIT_DOUBLE_LITERAL@14..17 + 0: GRIT_DOUBLE@14..17 "1.0" [] [] 4: R_PAREN@17..18 ")" [] [] 2: (empty) 3: GRIT_DEFINITION_LIST@18..18 diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/rewrite.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/rewrite.grit new file mode 100644 index 00000000000..a6da123c348 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/rewrite.grit @@ -0,0 +1 @@ +`println` => `console.log` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/rewrite.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/rewrite.grit.snap new file mode 100644 index 00000000000..fa09b9e7eb2 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/rewrite.grit.snap @@ -0,0 +1,58 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +`println` => `console.log` + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: missing (optional), + definitions: GritDefinitionList [], + pattern: GritRewrite { + left: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@0..10 "`println`" [] [Whitespace(" ")], + }, + }, + annotation: missing (optional), + fat_arrow_token: FAT_ARROW@10..13 "=>" [] [Whitespace(" ")], + right: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@13..26 "`console.log`" [] [], + }, + }, + }, + definitions_continued: GritDefinitionList [], + eof_token: EOF@26..27 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..27 + 0: (empty) + 1: (empty) + 2: (empty) + 3: GRIT_DEFINITION_LIST@0..0 + 4: GRIT_REWRITE@0..26 + 0: GRIT_CODE_SNIPPET@0..10 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@0..10 + 0: GRIT_BACKTICK_SNIPPET@0..10 "`println`" [] [Whitespace(" ")] + 1: (empty) + 2: FAT_ARROW@10..13 "=>" [] [Whitespace(" ")] + 3: GRIT_CODE_SNIPPET@13..26 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@13..26 + 0: GRIT_BACKTICK_SNIPPET@13..26 "`console.log`" [] [] + 5: GRIT_DEFINITION_LIST@26..26 + 6: EOF@26..27 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/rewrite_in_where.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/rewrite_in_where.grit new file mode 100644 index 00000000000..89133d2e286 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/rewrite_in_where.grit @@ -0,0 +1,6 @@ +engine biome(0.1) +language js + +`$test($_)` where { + $test <: js"test.only" => js"test" +} diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/rewrite_in_where.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/rewrite_in_where.grit.snap new file mode 100644 index 00000000000..7eef4cbed92 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/rewrite_in_where.grit.snap @@ -0,0 +1,134 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +engine biome(0.1) +language js + +`$test($_)` where { + $test <: js"test.only" => js"test" +} + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: GritVersion { + engine_token: ENGINE_KW@0..7 "engine" [] [Whitespace(" ")], + biome_token: BIOME_KW@7..12 "biome" [] [], + l_paren_token: L_PAREN@12..13 "(" [] [], + grit_double_literal: GritDoubleLiteral { + value_token: GRIT_DOUBLE@13..16 "0.1" [] [], + }, + r_paren_token: R_PAREN@16..17 ")" [] [], + }, + language: GritLanguageDeclaration { + language_token: LANGUAGE_KW@17..27 "language" [Newline("\n")] [Whitespace(" ")], + name: GritLanguageName { + language_kind: JS_KW@27..29 "js" [] [], + }, + flavor: missing (optional), + semicolon_token: missing (optional), + }, + definitions: GritDefinitionList [], + pattern: GritPatternWhere { + pattern: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@29..43 "`$test($_)`" [Newline("\n"), Newline("\n")] [Whitespace(" ")], + }, + }, + where_token: WHERE_KW@43..49 "where" [] [Whitespace(" ")], + side_condition: GritPredicateAnd { + and_token: missing (optional), + l_curly_token: L_CURLY@49..50 "{" [] [], + predicates: GritPredicateList [ + GritPredicateMatch { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@50..61 "$test" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + match_token: MATCH@61..64 "<:" [] [Whitespace(" ")], + right: GritRewrite { + left: GritCodeSnippet { + source: GritLanguageSpecificSnippet { + language: GritLanguageName { + language_kind: JS_KW@64..66 "js" [] [], + }, + snippet_token: GRIT_STRING@66..78 "\"test.only\"" [] [Whitespace(" ")], + }, + }, + annotation: missing (optional), + fat_arrow_token: FAT_ARROW@78..81 "=>" [] [Whitespace(" ")], + right: GritCodeSnippet { + source: GritLanguageSpecificSnippet { + language: GritLanguageName { + language_kind: JS_KW@81..83 "js" [] [], + }, + snippet_token: GRIT_STRING@83..89 "\"test\"" [] [], + }, + }, + }, + }, + ], + r_curly_token: R_CURLY@89..91 "}" [Newline("\n")] [], + }, + }, + definitions_continued: GritDefinitionList [], + eof_token: EOF@91..92 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..92 + 0: (empty) + 1: GRIT_VERSION@0..17 + 0: ENGINE_KW@0..7 "engine" [] [Whitespace(" ")] + 1: BIOME_KW@7..12 "biome" [] [] + 2: L_PAREN@12..13 "(" [] [] + 3: GRIT_DOUBLE_LITERAL@13..16 + 0: GRIT_DOUBLE@13..16 "0.1" [] [] + 4: R_PAREN@16..17 ")" [] [] + 2: GRIT_LANGUAGE_DECLARATION@17..29 + 0: LANGUAGE_KW@17..27 "language" [Newline("\n")] [Whitespace(" ")] + 1: GRIT_LANGUAGE_NAME@27..29 + 0: JS_KW@27..29 "js" [] [] + 2: (empty) + 3: (empty) + 3: GRIT_DEFINITION_LIST@29..29 + 4: GRIT_PATTERN_WHERE@29..91 + 0: GRIT_CODE_SNIPPET@29..43 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@29..43 + 0: GRIT_BACKTICK_SNIPPET@29..43 "`$test($_)`" [Newline("\n"), Newline("\n")] [Whitespace(" ")] + 1: WHERE_KW@43..49 "where" [] [Whitespace(" ")] + 2: GRIT_PREDICATE_AND@49..91 + 0: (empty) + 1: L_CURLY@49..50 "{" [] [] + 2: GRIT_PREDICATE_LIST@50..89 + 0: GRIT_PREDICATE_MATCH@50..89 + 0: GRIT_VARIABLE@50..61 + 0: GRIT_VARIABLE@50..61 "$test" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: MATCH@61..64 "<:" [] [Whitespace(" ")] + 2: GRIT_REWRITE@64..89 + 0: GRIT_CODE_SNIPPET@64..78 + 0: GRIT_LANGUAGE_SPECIFIC_SNIPPET@64..78 + 0: GRIT_LANGUAGE_NAME@64..66 + 0: JS_KW@64..66 "js" [] [] + 1: GRIT_STRING@66..78 "\"test.only\"" [] [Whitespace(" ")] + 1: (empty) + 2: FAT_ARROW@78..81 "=>" [] [Whitespace(" ")] + 3: GRIT_CODE_SNIPPET@81..89 + 0: GRIT_LANGUAGE_SPECIFIC_SNIPPET@81..89 + 0: GRIT_LANGUAGE_NAME@81..83 + 0: JS_KW@81..83 "js" [] [] + 1: GRIT_STRING@83..89 "\"test\"" [] [] + 3: R_CURLY@89..91 "}" [Newline("\n")] [] + 5: GRIT_DEFINITION_LIST@91..91 + 6: EOF@91..92 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_grit_syntax/src/generated/kind.rs b/crates/biome_grit_syntax/src/generated/kind.rs index 5a1e93445e1..da06da565a4 100644 --- a/crates/biome_grit_syntax/src/generated/kind.rs +++ b/crates/biome_grit_syntax/src/generated/kind.rs @@ -105,9 +105,7 @@ pub enum GritSyntaxKind { CURLY_GRIT_PATTERN, GRIT_ROOT, GRIT_SEQUENTIAL, - GRIT_SEQUENTIAL_LIST, GRIT_FILES, - GRIT_FILES_LIST, GRIT_DEFINITION_LIST, GRIT_VERSION, GRIT_LANGUAGE_DECLARATION, @@ -238,9 +236,7 @@ impl GritSyntaxKind { } pub const fn is_list(self) -> bool { match self { - GRIT_SEQUENTIAL_LIST - | GRIT_FILES_LIST - | GRIT_DEFINITION_LIST + GRIT_DEFINITION_LIST | GRIT_LANGUAGE_FLAVOR_LIST | GRIT_PATTERN_LIST | GRIT_NAMED_ARG_LIST diff --git a/crates/biome_grit_syntax/src/generated/macros.rs b/crates/biome_grit_syntax/src/generated/macros.rs index a060969fadb..608c471a057 100644 --- a/crates/biome_grit_syntax/src/generated/macros.rs +++ b/crates/biome_grit_syntax/src/generated/macros.rs @@ -435,10 +435,6 @@ macro_rules! map_syntax_node { let $pattern = unsafe { $crate::GritDefinitionList::new_unchecked(node) }; $body } - $crate::GritSyntaxKind::GRIT_FILES_LIST => { - let $pattern = unsafe { $crate::GritFilesList::new_unchecked(node) }; - $body - } $crate::GritSyntaxKind::GRIT_LANGUAGE_FLAVOR_LIST => { let $pattern = unsafe { $crate::GritLanguageFlavorList::new_unchecked(node) }; $body @@ -463,10 +459,6 @@ macro_rules! map_syntax_node { let $pattern = unsafe { $crate::GritPredicateList::new_unchecked(node) }; $body } - $crate::GritSyntaxKind::GRIT_SEQUENTIAL_LIST => { - let $pattern = unsafe { $crate::GritSequentialList::new_unchecked(node) }; - $body - } $crate::GritSyntaxKind::GRIT_VARIABLE_LIST => { let $pattern = unsafe { $crate::GritVariableList::new_unchecked(node) }; $body diff --git a/crates/biome_grit_syntax/src/generated/nodes.rs b/crates/biome_grit_syntax/src/generated/nodes.rs index d02ee6c3fac..7dfbb426d37 100644 --- a/crates/biome_grit_syntax/src/generated/nodes.rs +++ b/crates/biome_grit_syntax/src/generated/nodes.rs @@ -769,7 +769,7 @@ impl GritFiles { pub fn l_curly_token(&self) -> SyntaxResult { support::required_token(&self.syntax, 1usize) } - pub fn files(&self) -> GritFilesList { + pub fn files(&self) -> GritPatternList { support::list(&self.syntax, 2usize) } pub fn r_curly_token(&self) -> SyntaxResult { @@ -789,7 +789,7 @@ impl Serialize for GritFiles { pub struct GritFilesFields { pub multifile_token: SyntaxResult, pub l_curly_token: SyntaxResult, - pub files: GritFilesList, + pub files: GritPatternList, pub r_curly_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] @@ -3971,7 +3971,7 @@ impl GritSequential { pub fn l_curly_token(&self) -> SyntaxResult { support::required_token(&self.syntax, 1usize) } - pub fn sequential(&self) -> GritSequentialList { + pub fn sequential(&self) -> GritPatternList { support::list(&self.syntax, 2usize) } pub fn r_curly_token(&self) -> SyntaxResult { @@ -3991,7 +3991,7 @@ impl Serialize for GritSequential { pub struct GritSequentialFields { pub sequential_token: SyntaxResult, pub l_curly_token: SyntaxResult, - pub sequential: GritSequentialList, + pub sequential: GritPatternList, pub r_curly_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] @@ -12208,89 +12208,6 @@ impl IntoIterator for &GritDefinitionList { } } #[derive(Clone, Eq, PartialEq, Hash)] -pub struct GritFilesList { - syntax_list: SyntaxList, -} -impl GritFilesList { - #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] - #[doc = r""] - #[doc = r" # Safety"] - #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] - #[doc = r" or a match on [SyntaxNode::kind]"] - #[inline] - pub unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { - Self { - syntax_list: syntax.into_list(), - } - } -} -impl AstNode for GritFilesList { - type Language = Language; - const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_FILES_LIST as u16)); - fn can_cast(kind: SyntaxKind) -> bool { - kind == GRIT_FILES_LIST - } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(GritFilesList { - syntax_list: syntax.into_list(), - }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { - self.syntax_list.node() - } - fn into_syntax(self) -> SyntaxNode { - self.syntax_list.into_node() - } -} -#[cfg(feature = "serde")] -impl Serialize for GritFilesList { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - let mut seq = serializer.serialize_seq(Some(self.len()))?; - for e in self.iter() { - seq.serialize_element(&e)?; - } - seq.end() - } -} -impl AstSeparatedList for GritFilesList { - type Language = Language; - type Node = AnyGritPattern; - fn syntax_list(&self) -> &SyntaxList { - &self.syntax_list - } - fn into_syntax_list(self) -> SyntaxList { - self.syntax_list - } -} -impl Debug for GritFilesList { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - f.write_str("GritFilesList ")?; - f.debug_list().entries(self.elements()).finish() - } -} -impl IntoIterator for GritFilesList { - type Item = SyntaxResult; - type IntoIter = AstSeparatedListNodesIterator; - fn into_iter(self) -> Self::IntoIter { - self.iter() - } -} -impl IntoIterator for &GritFilesList { - type Item = SyntaxResult; - type IntoIter = AstSeparatedListNodesIterator; - fn into_iter(self) -> Self::IntoIter { - self.iter() - } -} -#[derive(Clone, Eq, PartialEq, Hash)] pub struct GritLanguageFlavorList { syntax_list: SyntaxList, } @@ -12789,89 +12706,6 @@ impl IntoIterator for &GritPredicateList { } } #[derive(Clone, Eq, PartialEq, Hash)] -pub struct GritSequentialList { - syntax_list: SyntaxList, -} -impl GritSequentialList { - #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] - #[doc = r""] - #[doc = r" # Safety"] - #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] - #[doc = r" or a match on [SyntaxNode::kind]"] - #[inline] - pub unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { - Self { - syntax_list: syntax.into_list(), - } - } -} -impl AstNode for GritSequentialList { - type Language = Language; - const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_SEQUENTIAL_LIST as u16)); - fn can_cast(kind: SyntaxKind) -> bool { - kind == GRIT_SEQUENTIAL_LIST - } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(GritSequentialList { - syntax_list: syntax.into_list(), - }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { - self.syntax_list.node() - } - fn into_syntax(self) -> SyntaxNode { - self.syntax_list.into_node() - } -} -#[cfg(feature = "serde")] -impl Serialize for GritSequentialList { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - let mut seq = serializer.serialize_seq(Some(self.len()))?; - for e in self.iter() { - seq.serialize_element(&e)?; - } - seq.end() - } -} -impl AstSeparatedList for GritSequentialList { - type Language = Language; - type Node = AnyGritPattern; - fn syntax_list(&self) -> &SyntaxList { - &self.syntax_list - } - fn into_syntax_list(self) -> SyntaxList { - self.syntax_list - } -} -impl Debug for GritSequentialList { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - f.write_str("GritSequentialList ")?; - f.debug_list().entries(self.elements()).finish() - } -} -impl IntoIterator for GritSequentialList { - type Item = SyntaxResult; - type IntoIter = AstSeparatedListNodesIterator; - fn into_iter(self) -> Self::IntoIter { - self.iter() - } -} -impl IntoIterator for &GritSequentialList { - type Item = SyntaxResult; - type IntoIter = AstSeparatedListNodesIterator; - fn into_iter(self) -> Self::IntoIter { - self.iter() - } -} -#[derive(Clone, Eq, PartialEq, Hash)] pub struct GritVariableList { syntax_list: SyntaxList, } diff --git a/crates/biome_grit_syntax/src/generated/nodes_mut.rs b/crates/biome_grit_syntax/src/generated/nodes_mut.rs index f8f21621b10..b5c9d54d03b 100644 --- a/crates/biome_grit_syntax/src/generated/nodes_mut.rs +++ b/crates/biome_grit_syntax/src/generated/nodes_mut.rs @@ -278,7 +278,7 @@ impl GritFiles { .splice_slots(1usize..=1usize, once(Some(element.into()))), ) } - pub fn with_files(self, element: GritFilesList) -> Self { + pub fn with_files(self, element: GritPatternList) -> Self { Self::unwrap_cast( self.syntax .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), @@ -1697,7 +1697,7 @@ impl GritSequential { .splice_slots(1usize..=1usize, once(Some(element.into()))), ) } - pub fn with_sequential(self, element: GritSequentialList) -> Self { + pub fn with_sequential(self, element: GritPatternList) -> Self { Self::unwrap_cast( self.syntax .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), diff --git a/xtask/codegen/gritql.ungram b/xtask/codegen/gritql.ungram index 9dea1eafdfd..1d42a3b6c84 100644 --- a/xtask/codegen/gritql.ungram +++ b/xtask/codegen/gritql.ungram @@ -53,11 +53,9 @@ GritRoot = definitions_continued: GritDefinitionList? eof: 'EOF' -GritSequential = 'sequential' '{' sequential: GritSequentialList '}' -GritSequentialList = AnyGritPattern (',' AnyGritPattern)* ','? +GritSequential = 'sequential' '{' sequential: GritPatternList '}' -GritFiles = 'multifile' '{' files: GritFilesList '}' -GritFilesList = AnyGritPattern (',' AnyGritPattern)* ','? +GritFiles = 'multifile' '{' files: GritPatternList '}' AnyGritDefinition = GritPatternDefinition diff --git a/xtask/codegen/src/grit_kinds_src.rs b/xtask/codegen/src/grit_kinds_src.rs index 1a144226515..d4b940528ce 100644 --- a/xtask/codegen/src/grit_kinds_src.rs +++ b/xtask/codegen/src/grit_kinds_src.rs @@ -114,9 +114,7 @@ pub const GRIT_KINDS_SRC: KindsSrc = KindsSrc { "CURLY_GRIT_PATTERN", "GRIT_ROOT", "GRIT_SEQUENTIAL", - "GRIT_SEQUENTIAL_LIST", "GRIT_FILES", - "GRIT_FILES_LIST", "GRIT_DEFINITION_LIST", "GRIT_VERSION", "GRIT_LANGUAGE_DECLARATION", From ade9f9d7fa530e956bbd008de8c8bd262af68471 Mon Sep 17 00:00:00 2001 From: "Arend van Beelen jr." Date: Mon, 26 Feb 2024 22:27:16 +0100 Subject: [PATCH 07/12] Generate formatter --- crates/biome_grit_formatter/src/generated.rs | 4551 +++++++++++++++++ .../src/grit/any/code_snippet_source.rs | 16 + .../src/grit/any/container.rs | 16 + .../src/grit/any/definition.rs | 17 + .../src/grit/any/list_accessor_subject.rs | 15 + .../src/grit/any/list_index.rs | 16 + .../src/grit/any/list_pattern.rs | 15 + .../src/grit/any/literal.rs | 22 + .../src/grit/any/map_accessor_subject.rs | 15 + .../src/grit/any/map_key.rs | 15 + .../biome_grit_formatter/src/grit/any/mod.rs | 16 + .../src/grit/any/named_arg.rs | 16 + .../src/grit/any/pattern.rs | 52 + .../src/grit/any/predicate.rs | 34 + .../src/grit/any/predicate_match_subject.rs | 15 + .../src/grit/any/regex.rs | 15 + .../src/grit/auxiliary/add_operation.rs | 10 + .../src/grit/auxiliary/annotation.rs | 10 + .../grit/auxiliary/assignment_as_pattern.rs | 14 + .../src/grit/auxiliary/bubble.rs | 10 + .../src/grit/auxiliary/bubble_scope.rs | 10 + .../src/grit/auxiliary/code_snippet.rs | 10 + .../src/grit/auxiliary/div_operation.rs | 10 + .../src/grit/auxiliary/dot.rs | 10 + .../src/grit/auxiliary/dotdotdot.rs | 10 + .../src/grit/auxiliary/every.rs | 10 + .../src/grit/auxiliary/files.rs | 10 + .../src/grit/auxiliary/function_definition.rs | 10 + .../grit/auxiliary/language_declaration.rs | 14 + .../src/grit/auxiliary/language_flavor.rs | 10 + .../grit/auxiliary/language_flavor_kind.rs | 10 + .../src/grit/auxiliary/language_name.rs | 10 + .../auxiliary/language_specific_snippet.rs | 14 + .../src/grit/auxiliary/like.rs | 10 + .../src/grit/auxiliary/like_threshold.rs | 10 + .../src/grit/auxiliary/list_accessor.rs | 10 + .../src/grit/auxiliary/map.rs | 10 + .../src/grit/auxiliary/map_accessor.rs | 10 + .../src/grit/auxiliary/map_element.rs | 10 + .../src/grit/auxiliary/mod.rs | 82 + .../src/grit/auxiliary/mod_operation.rs | 10 + .../src/grit/auxiliary/mul_operation.rs | 10 + .../src/grit/auxiliary/name.rs | 10 + .../src/grit/auxiliary/named_arg.rs | 10 + .../grit/auxiliary/named_arg_with_default.rs | 14 + .../src/grit/auxiliary/node_like.rs | 10 + .../src/grit/auxiliary/not.rs | 10 + .../src/grit/auxiliary/pattern_accumulate.rs | 10 + .../src/grit/auxiliary/pattern_after.rs | 10 + .../src/grit/auxiliary/pattern_and.rs | 10 + .../src/grit/auxiliary/pattern_any.rs | 10 + .../src/grit/auxiliary/pattern_as.rs | 10 + .../src/grit/auxiliary/pattern_before.rs | 10 + .../src/grit/auxiliary/pattern_contains.rs | 10 + .../pattern_contains_until_clause.rs | 14 + .../src/grit/auxiliary/pattern_definition.rs | 10 + .../grit/auxiliary/pattern_definition_body.rs | 14 + .../src/grit/auxiliary/pattern_else_clause.rs | 10 + .../src/grit/auxiliary/pattern_if_else.rs | 10 + .../src/grit/auxiliary/pattern_includes.rs | 10 + .../src/grit/auxiliary/pattern_limit.rs | 10 + .../src/grit/auxiliary/pattern_maybe.rs | 10 + .../src/grit/auxiliary/pattern_not.rs | 10 + .../src/grit/auxiliary/pattern_or.rs | 10 + .../src/grit/auxiliary/pattern_or_else.rs | 10 + .../src/grit/auxiliary/pattern_where.rs | 10 + .../grit/auxiliary/predicate_accumulate.rs | 14 + .../src/grit/auxiliary/predicate_and.rs | 10 + .../src/grit/auxiliary/predicate_any.rs | 10 + .../grit/auxiliary/predicate_assignment.rs | 14 + .../src/grit/auxiliary/predicate_call.rs | 10 + .../grit/auxiliary/predicate_definition.rs | 14 + .../grit/auxiliary/predicate_else_clause.rs | 14 + .../src/grit/auxiliary/predicate_equal.rs | 10 + .../src/grit/auxiliary/predicate_greater.rs | 10 + .../grit/auxiliary/predicate_greater_equal.rs | 14 + .../src/grit/auxiliary/predicate_if_else.rs | 10 + .../src/grit/auxiliary/predicate_less.rs | 10 + .../grit/auxiliary/predicate_less_equal.rs | 10 + .../src/grit/auxiliary/predicate_match.rs | 10 + .../src/grit/auxiliary/predicate_maybe.rs | 10 + .../src/grit/auxiliary/predicate_not.rs | 10 + .../src/grit/auxiliary/predicate_not_equal.rs | 10 + .../src/grit/auxiliary/predicate_or.rs | 10 + .../src/grit/auxiliary/predicate_return.rs | 10 + .../src/grit/auxiliary/predicate_rewrite.rs | 10 + .../src/grit/auxiliary/regex_pattern.rs | 10 + .../grit/auxiliary/regex_pattern_variables.rs | 14 + .../src/grit/auxiliary/rewrite.rs | 10 + .../src/grit/auxiliary/root.rs | 10 + .../src/grit/auxiliary/sequential.rs | 10 + .../src/grit/auxiliary/some.rs | 10 + .../src/grit/auxiliary/sub_operation.rs | 10 + .../src/grit/auxiliary/underscore.rs | 10 + .../src/grit/auxiliary/variable.rs | 10 + .../src/grit/auxiliary/version.rs | 10 + .../src/grit/auxiliary/within.rs | 10 + .../src/grit/bogus/bogus.rs | 5 + .../src/grit/bogus/bogus_definition.rs | 5 + .../src/grit/bogus/bogus_literal.rs | 5 + .../src/grit/bogus/bogus_named_arg.rs | 5 + .../src/grit/bogus/bogus_pattern.rs | 5 + .../src/grit/bogus/bogus_predicate.rs | 5 + .../src/grit/bogus/mod.rs | 9 + .../src/grit/lists/curly_predicate_list.rs | 10 + .../src/grit/lists/definition_list.rs | 10 + .../src/grit/lists/language_flavor_list.rs | 10 + .../src/grit/lists/list.rs | 10 + .../src/grit/lists/list_pattern_list.rs | 10 + .../src/grit/lists/map_element_list.rs | 10 + .../src/grit/lists/mod.rs | 13 + .../src/grit/lists/named_arg_list.rs | 10 + .../src/grit/lists/pattern_arg_list.rs | 10 + .../src/grit/lists/pattern_list.rs | 10 + .../src/grit/lists/predicate_list.rs | 10 + .../src/grit/lists/variable_list.rs | 10 + crates/biome_grit_formatter/src/grit/mod.rs | 7 + .../grit/value/backtick_snippet_literal.rs | 14 + .../src/grit/value/boolean_literal.rs | 10 + .../src/grit/value/double_literal.rs | 10 + .../src/grit/value/int_literal.rs | 10 + .../src/grit/value/mod.rs | 12 + .../src/grit/value/negative_int_literal.rs | 10 + .../value/raw_backtick_snippet_literal.rs | 14 + .../src/grit/value/regex_literal.rs | 10 + .../src/grit/value/snippet_regex_literal.rs | 14 + .../src/grit/value/string_literal.rs | 10 + .../src/grit/value/undefined_literal.rs | 10 + .../src/js/any/curly_grit_pattern.rs | 15 + crates/biome_grit_formatter/src/js/any/mod.rs | 3 + .../src/js/expressions/grit_pattern.rs | 10 + .../src/js/expressions/grit_predicate.rs | 10 + .../src/js/expressions/mod.rs | 4 + crates/biome_grit_formatter/src/js/mod.rs | 4 + xtask/codegen/src/formatter.rs | 8 + 135 files changed, 6123 insertions(+) create mode 100644 crates/biome_grit_formatter/src/generated.rs create mode 100644 crates/biome_grit_formatter/src/grit/any/code_snippet_source.rs create mode 100644 crates/biome_grit_formatter/src/grit/any/container.rs create mode 100644 crates/biome_grit_formatter/src/grit/any/definition.rs create mode 100644 crates/biome_grit_formatter/src/grit/any/list_accessor_subject.rs create mode 100644 crates/biome_grit_formatter/src/grit/any/list_index.rs create mode 100644 crates/biome_grit_formatter/src/grit/any/list_pattern.rs create mode 100644 crates/biome_grit_formatter/src/grit/any/literal.rs create mode 100644 crates/biome_grit_formatter/src/grit/any/map_accessor_subject.rs create mode 100644 crates/biome_grit_formatter/src/grit/any/map_key.rs create mode 100644 crates/biome_grit_formatter/src/grit/any/mod.rs create mode 100644 crates/biome_grit_formatter/src/grit/any/named_arg.rs create mode 100644 crates/biome_grit_formatter/src/grit/any/pattern.rs create mode 100644 crates/biome_grit_formatter/src/grit/any/predicate.rs create mode 100644 crates/biome_grit_formatter/src/grit/any/predicate_match_subject.rs create mode 100644 crates/biome_grit_formatter/src/grit/any/regex.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/add_operation.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/annotation.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/assignment_as_pattern.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/bubble.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/bubble_scope.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/code_snippet.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/div_operation.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/dot.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/dotdotdot.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/every.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/files.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/function_definition.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/language_declaration.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/language_flavor.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/language_flavor_kind.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/language_name.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/language_specific_snippet.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/like.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/like_threshold.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/list_accessor.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/map.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/map_accessor.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/map_element.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/mod.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/mod_operation.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/mul_operation.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/name.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/named_arg.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/named_arg_with_default.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/node_like.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/not.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/pattern_accumulate.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/pattern_after.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/pattern_and.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/pattern_any.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/pattern_as.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/pattern_before.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/pattern_contains.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/pattern_contains_until_clause.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/pattern_definition.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/pattern_definition_body.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/pattern_else_clause.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/pattern_if_else.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/pattern_includes.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/pattern_limit.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/pattern_maybe.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/pattern_not.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/pattern_or.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/pattern_or_else.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/pattern_where.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/predicate_accumulate.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/predicate_and.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/predicate_any.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/predicate_assignment.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/predicate_call.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/predicate_definition.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/predicate_else_clause.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/predicate_equal.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/predicate_greater.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/predicate_greater_equal.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/predicate_if_else.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/predicate_less.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/predicate_less_equal.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/predicate_match.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/predicate_maybe.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/predicate_not.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/predicate_not_equal.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/predicate_or.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/predicate_return.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/predicate_rewrite.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/regex_pattern.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/regex_pattern_variables.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/rewrite.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/root.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/sequential.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/some.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/sub_operation.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/underscore.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/variable.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/version.rs create mode 100644 crates/biome_grit_formatter/src/grit/auxiliary/within.rs create mode 100644 crates/biome_grit_formatter/src/grit/bogus/bogus.rs create mode 100644 crates/biome_grit_formatter/src/grit/bogus/bogus_definition.rs create mode 100644 crates/biome_grit_formatter/src/grit/bogus/bogus_literal.rs create mode 100644 crates/biome_grit_formatter/src/grit/bogus/bogus_named_arg.rs create mode 100644 crates/biome_grit_formatter/src/grit/bogus/bogus_pattern.rs create mode 100644 crates/biome_grit_formatter/src/grit/bogus/bogus_predicate.rs create mode 100644 crates/biome_grit_formatter/src/grit/bogus/mod.rs create mode 100644 crates/biome_grit_formatter/src/grit/lists/curly_predicate_list.rs create mode 100644 crates/biome_grit_formatter/src/grit/lists/definition_list.rs create mode 100644 crates/biome_grit_formatter/src/grit/lists/language_flavor_list.rs create mode 100644 crates/biome_grit_formatter/src/grit/lists/list.rs create mode 100644 crates/biome_grit_formatter/src/grit/lists/list_pattern_list.rs create mode 100644 crates/biome_grit_formatter/src/grit/lists/map_element_list.rs create mode 100644 crates/biome_grit_formatter/src/grit/lists/mod.rs create mode 100644 crates/biome_grit_formatter/src/grit/lists/named_arg_list.rs create mode 100644 crates/biome_grit_formatter/src/grit/lists/pattern_arg_list.rs create mode 100644 crates/biome_grit_formatter/src/grit/lists/pattern_list.rs create mode 100644 crates/biome_grit_formatter/src/grit/lists/predicate_list.rs create mode 100644 crates/biome_grit_formatter/src/grit/lists/variable_list.rs create mode 100644 crates/biome_grit_formatter/src/grit/mod.rs create mode 100644 crates/biome_grit_formatter/src/grit/value/backtick_snippet_literal.rs create mode 100644 crates/biome_grit_formatter/src/grit/value/boolean_literal.rs create mode 100644 crates/biome_grit_formatter/src/grit/value/double_literal.rs create mode 100644 crates/biome_grit_formatter/src/grit/value/int_literal.rs create mode 100644 crates/biome_grit_formatter/src/grit/value/mod.rs create mode 100644 crates/biome_grit_formatter/src/grit/value/negative_int_literal.rs create mode 100644 crates/biome_grit_formatter/src/grit/value/raw_backtick_snippet_literal.rs create mode 100644 crates/biome_grit_formatter/src/grit/value/regex_literal.rs create mode 100644 crates/biome_grit_formatter/src/grit/value/snippet_regex_literal.rs create mode 100644 crates/biome_grit_formatter/src/grit/value/string_literal.rs create mode 100644 crates/biome_grit_formatter/src/grit/value/undefined_literal.rs create mode 100644 crates/biome_grit_formatter/src/js/any/curly_grit_pattern.rs create mode 100644 crates/biome_grit_formatter/src/js/any/mod.rs create mode 100644 crates/biome_grit_formatter/src/js/expressions/grit_pattern.rs create mode 100644 crates/biome_grit_formatter/src/js/expressions/grit_predicate.rs create mode 100644 crates/biome_grit_formatter/src/js/expressions/mod.rs create mode 100644 crates/biome_grit_formatter/src/js/mod.rs diff --git a/crates/biome_grit_formatter/src/generated.rs b/crates/biome_grit_formatter/src/generated.rs new file mode 100644 index 00000000000..aa554b420d1 --- /dev/null +++ b/crates/biome_grit_formatter/src/generated.rs @@ -0,0 +1,4551 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +use crate::{ + AsFormat, FormatBogusNodeRule, FormatNodeRule, GritFormatContext, GritFormatter, IntoFormat, +}; +use biome_formatter::{FormatOwnedWithRule, FormatRefWithRule, FormatResult, FormatRule}; +impl FormatRule for crate::grit::auxiliary::root::FormatGritRoot { + type Context = GritFormatContext; + #[inline(always)] + fn fmt(&self, node: &biome_grit_syntax::GritRoot, f: &mut GritFormatter) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritRoot { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritRoot, + crate::grit::auxiliary::root::FormatGritRoot, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::root::FormatGritRoot::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritRoot { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritRoot, + crate::grit::auxiliary::root::FormatGritRoot, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::root::FormatGritRoot::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::version::FormatGritVersion +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritVersion, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritVersion { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritVersion, + crate::grit::auxiliary::version::FormatGritVersion, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::version::FormatGritVersion::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritVersion { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritVersion, + crate::grit::auxiliary::version::FormatGritVersion, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::version::FormatGritVersion::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::language_declaration::FormatGritLanguageDeclaration +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritLanguageDeclaration, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritLanguageDeclaration { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritLanguageDeclaration, + crate::grit::auxiliary::language_declaration::FormatGritLanguageDeclaration, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::language_declaration::FormatGritLanguageDeclaration::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritLanguageDeclaration { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritLanguageDeclaration, + crate::grit::auxiliary::language_declaration::FormatGritLanguageDeclaration, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::language_declaration::FormatGritLanguageDeclaration::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::sequential::FormatGritSequential +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritSequential, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritSequential { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritSequential, + crate::grit::auxiliary::sequential::FormatGritSequential, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::sequential::FormatGritSequential::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritSequential { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritSequential, + crate::grit::auxiliary::sequential::FormatGritSequential, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::sequential::FormatGritSequential::default(), + ) + } +} +impl FormatRule for crate::grit::auxiliary::files::FormatGritFiles { + type Context = GritFormatContext; + #[inline(always)] + fn fmt(&self, node: &biome_grit_syntax::GritFiles, f: &mut GritFormatter) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritFiles { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritFiles, + crate::grit::auxiliary::files::FormatGritFiles, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::files::FormatGritFiles::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritFiles { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritFiles, + crate::grit::auxiliary::files::FormatGritFiles, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::files::FormatGritFiles::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::pattern_definition::FormatGritPatternDefinition +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPatternDefinition, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPatternDefinition { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPatternDefinition, + crate::grit::auxiliary::pattern_definition::FormatGritPatternDefinition, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::pattern_definition::FormatGritPatternDefinition::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPatternDefinition { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPatternDefinition, + crate::grit::auxiliary::pattern_definition::FormatGritPatternDefinition, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::pattern_definition::FormatGritPatternDefinition::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::predicate_definition::FormatGritPredicateDefinition +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPredicateDefinition, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPredicateDefinition { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPredicateDefinition, + crate::grit::auxiliary::predicate_definition::FormatGritPredicateDefinition, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::predicate_definition::FormatGritPredicateDefinition::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPredicateDefinition { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPredicateDefinition, + crate::grit::auxiliary::predicate_definition::FormatGritPredicateDefinition, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::predicate_definition::FormatGritPredicateDefinition::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::function_definition::FormatGritFunctionDefinition +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritFunctionDefinition, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritFunctionDefinition { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritFunctionDefinition, + crate::grit::auxiliary::function_definition::FormatGritFunctionDefinition, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::function_definition::FormatGritFunctionDefinition::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritFunctionDefinition { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritFunctionDefinition, + crate::grit::auxiliary::function_definition::FormatGritFunctionDefinition, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::function_definition::FormatGritFunctionDefinition::default(), + ) + } +} +impl FormatRule + for crate::grit::value::double_literal::FormatGritDoubleLiteral +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritDoubleLiteral, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritDoubleLiteral { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritDoubleLiteral, + crate::grit::value::double_literal::FormatGritDoubleLiteral, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::value::double_literal::FormatGritDoubleLiteral::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritDoubleLiteral { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritDoubleLiteral, + crate::grit::value::double_literal::FormatGritDoubleLiteral, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::value::double_literal::FormatGritDoubleLiteral::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::language_name::FormatGritLanguageName +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritLanguageName, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritLanguageName { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritLanguageName, + crate::grit::auxiliary::language_name::FormatGritLanguageName, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::language_name::FormatGritLanguageName::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritLanguageName { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritLanguageName, + crate::grit::auxiliary::language_name::FormatGritLanguageName, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::language_name::FormatGritLanguageName::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::language_flavor::FormatGritLanguageFlavor +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritLanguageFlavor, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritLanguageFlavor { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritLanguageFlavor, + crate::grit::auxiliary::language_flavor::FormatGritLanguageFlavor, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::language_flavor::FormatGritLanguageFlavor::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritLanguageFlavor { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritLanguageFlavor, + crate::grit::auxiliary::language_flavor::FormatGritLanguageFlavor, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::language_flavor::FormatGritLanguageFlavor::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::language_flavor_kind::FormatGritLanguageFlavorKind +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritLanguageFlavorKind, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritLanguageFlavorKind { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritLanguageFlavorKind, + crate::grit::auxiliary::language_flavor_kind::FormatGritLanguageFlavorKind, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::language_flavor_kind::FormatGritLanguageFlavorKind::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritLanguageFlavorKind { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritLanguageFlavorKind, + crate::grit::auxiliary::language_flavor_kind::FormatGritLanguageFlavorKind, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::language_flavor_kind::FormatGritLanguageFlavorKind::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::pattern_not::FormatGritPatternNot +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPatternNot, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPatternNot { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPatternNot, + crate::grit::auxiliary::pattern_not::FormatGritPatternNot, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::pattern_not::FormatGritPatternNot::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPatternNot { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPatternNot, + crate::grit::auxiliary::pattern_not::FormatGritPatternNot, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::pattern_not::FormatGritPatternNot::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::pattern_or::FormatGritPatternOr +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPatternOr, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPatternOr { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPatternOr, + crate::grit::auxiliary::pattern_or::FormatGritPatternOr, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::pattern_or::FormatGritPatternOr::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPatternOr { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPatternOr, + crate::grit::auxiliary::pattern_or::FormatGritPatternOr, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::pattern_or::FormatGritPatternOr::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::pattern_or_else::FormatGritPatternOrElse +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPatternOrElse, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPatternOrElse { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPatternOrElse, + crate::grit::auxiliary::pattern_or_else::FormatGritPatternOrElse, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::pattern_or_else::FormatGritPatternOrElse::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPatternOrElse { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPatternOrElse, + crate::grit::auxiliary::pattern_or_else::FormatGritPatternOrElse, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::pattern_or_else::FormatGritPatternOrElse::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::pattern_any::FormatGritPatternAny +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPatternAny, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPatternAny { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPatternAny, + crate::grit::auxiliary::pattern_any::FormatGritPatternAny, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::pattern_any::FormatGritPatternAny::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPatternAny { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPatternAny, + crate::grit::auxiliary::pattern_any::FormatGritPatternAny, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::pattern_any::FormatGritPatternAny::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::pattern_and::FormatGritPatternAnd +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPatternAnd, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPatternAnd { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPatternAnd, + crate::grit::auxiliary::pattern_and::FormatGritPatternAnd, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::pattern_and::FormatGritPatternAnd::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPatternAnd { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPatternAnd, + crate::grit::auxiliary::pattern_and::FormatGritPatternAnd, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::pattern_and::FormatGritPatternAnd::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::pattern_maybe::FormatGritPatternMaybe +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPatternMaybe, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPatternMaybe { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPatternMaybe, + crate::grit::auxiliary::pattern_maybe::FormatGritPatternMaybe, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::pattern_maybe::FormatGritPatternMaybe::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPatternMaybe { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPatternMaybe, + crate::grit::auxiliary::pattern_maybe::FormatGritPatternMaybe, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::pattern_maybe::FormatGritPatternMaybe::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::pattern_if_else::FormatGritPatternIfElse +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPatternIfElse, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPatternIfElse { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPatternIfElse, + crate::grit::auxiliary::pattern_if_else::FormatGritPatternIfElse, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::pattern_if_else::FormatGritPatternIfElse::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPatternIfElse { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPatternIfElse, + crate::grit::auxiliary::pattern_if_else::FormatGritPatternIfElse, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::pattern_if_else::FormatGritPatternIfElse::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::pattern_contains::FormatGritPatternContains +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPatternContains, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPatternContains { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPatternContains, + crate::grit::auxiliary::pattern_contains::FormatGritPatternContains, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::pattern_contains::FormatGritPatternContains::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPatternContains { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPatternContains, + crate::grit::auxiliary::pattern_contains::FormatGritPatternContains, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::pattern_contains::FormatGritPatternContains::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::pattern_includes::FormatGritPatternIncludes +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPatternIncludes, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPatternIncludes { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPatternIncludes, + crate::grit::auxiliary::pattern_includes::FormatGritPatternIncludes, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::pattern_includes::FormatGritPatternIncludes::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPatternIncludes { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPatternIncludes, + crate::grit::auxiliary::pattern_includes::FormatGritPatternIncludes, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::pattern_includes::FormatGritPatternIncludes::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::pattern_after::FormatGritPatternAfter +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPatternAfter, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPatternAfter { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPatternAfter, + crate::grit::auxiliary::pattern_after::FormatGritPatternAfter, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::pattern_after::FormatGritPatternAfter::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPatternAfter { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPatternAfter, + crate::grit::auxiliary::pattern_after::FormatGritPatternAfter, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::pattern_after::FormatGritPatternAfter::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::pattern_before::FormatGritPatternBefore +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPatternBefore, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPatternBefore { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPatternBefore, + crate::grit::auxiliary::pattern_before::FormatGritPatternBefore, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::pattern_before::FormatGritPatternBefore::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPatternBefore { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPatternBefore, + crate::grit::auxiliary::pattern_before::FormatGritPatternBefore, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::pattern_before::FormatGritPatternBefore::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::within::FormatGritWithin +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt(&self, node: &biome_grit_syntax::GritWithin, f: &mut GritFormatter) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritWithin { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritWithin, + crate::grit::auxiliary::within::FormatGritWithin, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::within::FormatGritWithin::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritWithin { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritWithin, + crate::grit::auxiliary::within::FormatGritWithin, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::within::FormatGritWithin::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::bubble::FormatGritBubble +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt(&self, node: &biome_grit_syntax::GritBubble, f: &mut GritFormatter) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritBubble { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritBubble, + crate::grit::auxiliary::bubble::FormatGritBubble, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::bubble::FormatGritBubble::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritBubble { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritBubble, + crate::grit::auxiliary::bubble::FormatGritBubble, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::bubble::FormatGritBubble::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::node_like::FormatGritNodeLike +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritNodeLike, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritNodeLike { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritNodeLike, + crate::grit::auxiliary::node_like::FormatGritNodeLike, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::node_like::FormatGritNodeLike::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritNodeLike { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritNodeLike, + crate::grit::auxiliary::node_like::FormatGritNodeLike, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::node_like::FormatGritNodeLike::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::map_accessor::FormatGritMapAccessor +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritMapAccessor, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritMapAccessor { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritMapAccessor, + crate::grit::auxiliary::map_accessor::FormatGritMapAccessor, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::map_accessor::FormatGritMapAccessor::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritMapAccessor { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritMapAccessor, + crate::grit::auxiliary::map_accessor::FormatGritMapAccessor, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::map_accessor::FormatGritMapAccessor::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::list_accessor::FormatGritListAccessor +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritListAccessor, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritListAccessor { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritListAccessor, + crate::grit::auxiliary::list_accessor::FormatGritListAccessor, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::list_accessor::FormatGritListAccessor::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritListAccessor { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritListAccessor, + crate::grit::auxiliary::list_accessor::FormatGritListAccessor, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::list_accessor::FormatGritListAccessor::default(), + ) + } +} +impl FormatRule for crate::grit::auxiliary::dot::FormatGritDot { + type Context = GritFormatContext; + #[inline(always)] + fn fmt(&self, node: &biome_grit_syntax::GritDot, f: &mut GritFormatter) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritDot { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritDot, + crate::grit::auxiliary::dot::FormatGritDot, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new(self, crate::grit::auxiliary::dot::FormatGritDot::default()) + } +} +impl IntoFormat for biome_grit_syntax::GritDot { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new(self, crate::grit::auxiliary::dot::FormatGritDot::default()) + } +} +impl FormatRule for crate::grit::auxiliary::some::FormatGritSome { + type Context = GritFormatContext; + #[inline(always)] + fn fmt(&self, node: &biome_grit_syntax::GritSome, f: &mut GritFormatter) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritSome { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritSome, + crate::grit::auxiliary::some::FormatGritSome, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::some::FormatGritSome::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritSome { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritSome, + crate::grit::auxiliary::some::FormatGritSome, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::some::FormatGritSome::default(), + ) + } +} +impl FormatRule for crate::grit::auxiliary::every::FormatGritEvery { + type Context = GritFormatContext; + #[inline(always)] + fn fmt(&self, node: &biome_grit_syntax::GritEvery, f: &mut GritFormatter) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritEvery { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritEvery, + crate::grit::auxiliary::every::FormatGritEvery, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::every::FormatGritEvery::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritEvery { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritEvery, + crate::grit::auxiliary::every::FormatGritEvery, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::every::FormatGritEvery::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::underscore::FormatGritUnderscore +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritUnderscore, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritUnderscore { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritUnderscore, + crate::grit::auxiliary::underscore::FormatGritUnderscore, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::underscore::FormatGritUnderscore::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritUnderscore { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritUnderscore, + crate::grit::auxiliary::underscore::FormatGritUnderscore, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::underscore::FormatGritUnderscore::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::variable::FormatGritVariable +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritVariable, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritVariable { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritVariable, + crate::grit::auxiliary::variable::FormatGritVariable, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::variable::FormatGritVariable::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritVariable { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritVariable, + crate::grit::auxiliary::variable::FormatGritVariable, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::variable::FormatGritVariable::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::regex_pattern::FormatGritRegexPattern +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritRegexPattern, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritRegexPattern { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritRegexPattern, + crate::grit::auxiliary::regex_pattern::FormatGritRegexPattern, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::regex_pattern::FormatGritRegexPattern::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritRegexPattern { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritRegexPattern, + crate::grit::auxiliary::regex_pattern::FormatGritRegexPattern, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::regex_pattern::FormatGritRegexPattern::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::pattern_as::FormatGritPatternAs +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPatternAs, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPatternAs { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPatternAs, + crate::grit::auxiliary::pattern_as::FormatGritPatternAs, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::pattern_as::FormatGritPatternAs::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPatternAs { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPatternAs, + crate::grit::auxiliary::pattern_as::FormatGritPatternAs, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::pattern_as::FormatGritPatternAs::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::pattern_limit::FormatGritPatternLimit +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPatternLimit, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPatternLimit { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPatternLimit, + crate::grit::auxiliary::pattern_limit::FormatGritPatternLimit, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::pattern_limit::FormatGritPatternLimit::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPatternLimit { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPatternLimit, + crate::grit::auxiliary::pattern_limit::FormatGritPatternLimit, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::pattern_limit::FormatGritPatternLimit::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::assignment_as_pattern::FormatGritAssignmentAsPattern +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritAssignmentAsPattern, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritAssignmentAsPattern { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritAssignmentAsPattern, + crate::grit::auxiliary::assignment_as_pattern::FormatGritAssignmentAsPattern, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::assignment_as_pattern::FormatGritAssignmentAsPattern::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritAssignmentAsPattern { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritAssignmentAsPattern, + crate::grit::auxiliary::assignment_as_pattern::FormatGritAssignmentAsPattern, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::assignment_as_pattern::FormatGritAssignmentAsPattern::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::pattern_accumulate::FormatGritPatternAccumulate +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPatternAccumulate, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPatternAccumulate { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPatternAccumulate, + crate::grit::auxiliary::pattern_accumulate::FormatGritPatternAccumulate, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::pattern_accumulate::FormatGritPatternAccumulate::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPatternAccumulate { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPatternAccumulate, + crate::grit::auxiliary::pattern_accumulate::FormatGritPatternAccumulate, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::pattern_accumulate::FormatGritPatternAccumulate::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::rewrite::FormatGritRewrite +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritRewrite, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritRewrite { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritRewrite, + crate::grit::auxiliary::rewrite::FormatGritRewrite, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::rewrite::FormatGritRewrite::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritRewrite { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritRewrite, + crate::grit::auxiliary::rewrite::FormatGritRewrite, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::rewrite::FormatGritRewrite::default(), + ) + } +} +impl FormatRule for crate::grit::auxiliary::like::FormatGritLike { + type Context = GritFormatContext; + #[inline(always)] + fn fmt(&self, node: &biome_grit_syntax::GritLike, f: &mut GritFormatter) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritLike { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritLike, + crate::grit::auxiliary::like::FormatGritLike, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::like::FormatGritLike::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritLike { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritLike, + crate::grit::auxiliary::like::FormatGritLike, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::like::FormatGritLike::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::pattern_where::FormatGritPatternWhere +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPatternWhere, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPatternWhere { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPatternWhere, + crate::grit::auxiliary::pattern_where::FormatGritPatternWhere, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::pattern_where::FormatGritPatternWhere::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPatternWhere { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPatternWhere, + crate::grit::auxiliary::pattern_where::FormatGritPatternWhere, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::pattern_where::FormatGritPatternWhere::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::mul_operation::FormatGritMulOperation +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritMulOperation, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritMulOperation { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritMulOperation, + crate::grit::auxiliary::mul_operation::FormatGritMulOperation, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::mul_operation::FormatGritMulOperation::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritMulOperation { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritMulOperation, + crate::grit::auxiliary::mul_operation::FormatGritMulOperation, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::mul_operation::FormatGritMulOperation::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::div_operation::FormatGritDivOperation +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritDivOperation, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritDivOperation { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritDivOperation, + crate::grit::auxiliary::div_operation::FormatGritDivOperation, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::div_operation::FormatGritDivOperation::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritDivOperation { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritDivOperation, + crate::grit::auxiliary::div_operation::FormatGritDivOperation, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::div_operation::FormatGritDivOperation::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::mod_operation::FormatGritModOperation +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritModOperation, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritModOperation { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritModOperation, + crate::grit::auxiliary::mod_operation::FormatGritModOperation, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::mod_operation::FormatGritModOperation::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritModOperation { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritModOperation, + crate::grit::auxiliary::mod_operation::FormatGritModOperation, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::mod_operation::FormatGritModOperation::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::add_operation::FormatGritAddOperation +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritAddOperation, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritAddOperation { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritAddOperation, + crate::grit::auxiliary::add_operation::FormatGritAddOperation, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::add_operation::FormatGritAddOperation::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritAddOperation { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritAddOperation, + crate::grit::auxiliary::add_operation::FormatGritAddOperation, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::add_operation::FormatGritAddOperation::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::sub_operation::FormatGritSubOperation +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritSubOperation, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritSubOperation { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritSubOperation, + crate::grit::auxiliary::sub_operation::FormatGritSubOperation, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::sub_operation::FormatGritSubOperation::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritSubOperation { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritSubOperation, + crate::grit::auxiliary::sub_operation::FormatGritSubOperation, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::sub_operation::FormatGritSubOperation::default(), + ) + } +} +impl FormatRule + for crate::js::expressions::grit_pattern::FormatBracketedGritPattern +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::BracketedGritPattern, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::BracketedGritPattern { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::BracketedGritPattern, + crate::js::expressions::grit_pattern::FormatBracketedGritPattern, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::js::expressions::grit_pattern::FormatBracketedGritPattern::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::BracketedGritPattern { + type Format = FormatOwnedWithRule< + biome_grit_syntax::BracketedGritPattern, + crate::js::expressions::grit_pattern::FormatBracketedGritPattern, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::js::expressions::grit_pattern::FormatBracketedGritPattern::default(), + ) + } +} +impl FormatRule + for crate::js::expressions::grit_pattern::FormatCurlyGritPattern +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::CurlyGritPattern, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::CurlyGritPattern { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::CurlyGritPattern, + crate::js::expressions::grit_pattern::FormatCurlyGritPattern, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::js::expressions::grit_pattern::FormatCurlyGritPattern::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::CurlyGritPattern { + type Format = FormatOwnedWithRule< + biome_grit_syntax::CurlyGritPattern, + crate::js::expressions::grit_pattern::FormatCurlyGritPattern, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::js::expressions::grit_pattern::FormatCurlyGritPattern::default(), + ) + } +} +impl FormatRule + for crate::grit::value::int_literal::FormatGritIntLiteral +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritIntLiteral, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritIntLiteral { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritIntLiteral, + crate::grit::value::int_literal::FormatGritIntLiteral, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::value::int_literal::FormatGritIntLiteral::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritIntLiteral { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritIntLiteral, + crate::grit::value::int_literal::FormatGritIntLiteral, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::value::int_literal::FormatGritIntLiteral::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::code_snippet::FormatGritCodeSnippet +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritCodeSnippet, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritCodeSnippet { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritCodeSnippet, + crate::grit::auxiliary::code_snippet::FormatGritCodeSnippet, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::code_snippet::FormatGritCodeSnippet::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritCodeSnippet { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritCodeSnippet, + crate::grit::auxiliary::code_snippet::FormatGritCodeSnippet, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::code_snippet::FormatGritCodeSnippet::default(), + ) + } +} +impl FormatRule + for crate::grit::value::string_literal::FormatGritStringLiteral +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritStringLiteral, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritStringLiteral { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritStringLiteral, + crate::grit::value::string_literal::FormatGritStringLiteral, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::value::string_literal::FormatGritStringLiteral::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritStringLiteral { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritStringLiteral, + crate::grit::value::string_literal::FormatGritStringLiteral, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::value::string_literal::FormatGritStringLiteral::default(), + ) + } +} +impl FormatRule + for crate::grit::value::boolean_literal::FormatGritBooleanLiteral +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritBooleanLiteral, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritBooleanLiteral { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritBooleanLiteral, + crate::grit::value::boolean_literal::FormatGritBooleanLiteral, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::value::boolean_literal::FormatGritBooleanLiteral::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritBooleanLiteral { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritBooleanLiteral, + crate::grit::value::boolean_literal::FormatGritBooleanLiteral, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::value::boolean_literal::FormatGritBooleanLiteral::default(), + ) + } +} +impl FormatRule + for crate::grit::value::undefined_literal::FormatGritUndefinedLiteral +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritUndefinedLiteral, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritUndefinedLiteral { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritUndefinedLiteral, + crate::grit::value::undefined_literal::FormatGritUndefinedLiteral, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::value::undefined_literal::FormatGritUndefinedLiteral::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritUndefinedLiteral { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritUndefinedLiteral, + crate::grit::value::undefined_literal::FormatGritUndefinedLiteral, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::value::undefined_literal::FormatGritUndefinedLiteral::default(), + ) + } +} +impl FormatRule for crate::grit::auxiliary::map::FormatGritMap { + type Context = GritFormatContext; + #[inline(always)] + fn fmt(&self, node: &biome_grit_syntax::GritMap, f: &mut GritFormatter) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritMap { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritMap, + crate::grit::auxiliary::map::FormatGritMap, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new(self, crate::grit::auxiliary::map::FormatGritMap::default()) + } +} +impl IntoFormat for biome_grit_syntax::GritMap { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new(self, crate::grit::auxiliary::map::FormatGritMap::default()) + } +} +impl FormatRule for crate::grit::lists::list::FormatGritList { + type Context = GritFormatContext; + #[inline(always)] + fn fmt(&self, node: &biome_grit_syntax::GritList, f: &mut GritFormatter) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritList { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritList, + crate::grit::lists::list::FormatGritList, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new(self, crate::grit::lists::list::FormatGritList::default()) + } +} +impl IntoFormat for biome_grit_syntax::GritList { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new(self, crate::grit::lists::list::FormatGritList::default()) + } +} +impl FormatRule for crate::grit::auxiliary::not::FormatGritNot { + type Context = GritFormatContext; + #[inline(always)] + fn fmt(&self, node: &biome_grit_syntax::GritNot, f: &mut GritFormatter) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritNot { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritNot, + crate::grit::auxiliary::not::FormatGritNot, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new(self, crate::grit::auxiliary::not::FormatGritNot::default()) + } +} +impl IntoFormat for biome_grit_syntax::GritNot { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new(self, crate::grit::auxiliary::not::FormatGritNot::default()) + } +} +impl FormatRule + for crate::grit::auxiliary::pattern_contains_until_clause::FormatGritPatternContainsUntilClause +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPatternContainsUntilClause, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPatternContainsUntilClause { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPatternContainsUntilClause, + crate::grit::auxiliary::pattern_contains_until_clause::FormatGritPatternContainsUntilClause, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: grit :: auxiliary :: pattern_contains_until_clause :: FormatGritPatternContainsUntilClause :: default ()) + } +} +impl IntoFormat for biome_grit_syntax::GritPatternContainsUntilClause { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPatternContainsUntilClause, + crate::grit::auxiliary::pattern_contains_until_clause::FormatGritPatternContainsUntilClause, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: grit :: auxiliary :: pattern_contains_until_clause :: FormatGritPatternContainsUntilClause :: default ()) + } +} +impl FormatRule + for crate::grit::auxiliary::annotation::FormatGritAnnotation +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritAnnotation, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritAnnotation { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritAnnotation, + crate::grit::auxiliary::annotation::FormatGritAnnotation, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::annotation::FormatGritAnnotation::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritAnnotation { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritAnnotation, + crate::grit::auxiliary::annotation::FormatGritAnnotation, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::annotation::FormatGritAnnotation::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::pattern_else_clause::FormatGritPatternElseClause +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPatternElseClause, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPatternElseClause { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPatternElseClause, + crate::grit::auxiliary::pattern_else_clause::FormatGritPatternElseClause, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::pattern_else_clause::FormatGritPatternElseClause::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPatternElseClause { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPatternElseClause, + crate::grit::auxiliary::pattern_else_clause::FormatGritPatternElseClause, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::pattern_else_clause::FormatGritPatternElseClause::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::bubble_scope::FormatGritBubbleScope +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritBubbleScope, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritBubbleScope { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritBubbleScope, + crate::grit::auxiliary::bubble_scope::FormatGritBubbleScope, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::bubble_scope::FormatGritBubbleScope::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritBubbleScope { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritBubbleScope, + crate::grit::auxiliary::bubble_scope::FormatGritBubbleScope, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::bubble_scope::FormatGritBubbleScope::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::named_arg::FormatGritNamedArg +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritNamedArg, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritNamedArg { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritNamedArg, + crate::grit::auxiliary::named_arg::FormatGritNamedArg, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::named_arg::FormatGritNamedArg::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritNamedArg { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritNamedArg, + crate::grit::auxiliary::named_arg::FormatGritNamedArg, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::named_arg::FormatGritNamedArg::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::named_arg_with_default::FormatGritNamedArgWithDefault +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritNamedArgWithDefault, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritNamedArgWithDefault { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritNamedArgWithDefault, + crate::grit::auxiliary::named_arg_with_default::FormatGritNamedArgWithDefault, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::named_arg_with_default::FormatGritNamedArgWithDefault::default( + ), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritNamedArgWithDefault { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritNamedArgWithDefault, + crate::grit::auxiliary::named_arg_with_default::FormatGritNamedArgWithDefault, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::named_arg_with_default::FormatGritNamedArgWithDefault::default( + ), + ) + } +} +impl FormatRule for crate::grit::auxiliary::name::FormatGritName { + type Context = GritFormatContext; + #[inline(always)] + fn fmt(&self, node: &biome_grit_syntax::GritName, f: &mut GritFormatter) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritName { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritName, + crate::grit::auxiliary::name::FormatGritName, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::name::FormatGritName::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritName { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritName, + crate::grit::auxiliary::name::FormatGritName, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::name::FormatGritName::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::like_threshold::FormatGritLikeThreshold +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritLikeThreshold, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritLikeThreshold { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritLikeThreshold, + crate::grit::auxiliary::like_threshold::FormatGritLikeThreshold, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::like_threshold::FormatGritLikeThreshold::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritLikeThreshold { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritLikeThreshold, + crate::grit::auxiliary::like_threshold::FormatGritLikeThreshold, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::like_threshold::FormatGritLikeThreshold::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::map_element::FormatGritMapElement +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritMapElement, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritMapElement { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritMapElement, + crate::grit::auxiliary::map_element::FormatGritMapElement, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::map_element::FormatGritMapElement::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritMapElement { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritMapElement, + crate::grit::auxiliary::map_element::FormatGritMapElement, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::map_element::FormatGritMapElement::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::dotdotdot::FormatGritDotdotdot +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritDotdotdot, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritDotdotdot { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritDotdotdot, + crate::grit::auxiliary::dotdotdot::FormatGritDotdotdot, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::dotdotdot::FormatGritDotdotdot::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritDotdotdot { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritDotdotdot, + crate::grit::auxiliary::dotdotdot::FormatGritDotdotdot, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::dotdotdot::FormatGritDotdotdot::default(), + ) + } +} +impl FormatRule + for crate::grit::value::negative_int_literal::FormatGritNegativeIntLiteral +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritNegativeIntLiteral, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritNegativeIntLiteral { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritNegativeIntLiteral, + crate::grit::value::negative_int_literal::FormatGritNegativeIntLiteral, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::value::negative_int_literal::FormatGritNegativeIntLiteral::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritNegativeIntLiteral { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritNegativeIntLiteral, + crate::grit::value::negative_int_literal::FormatGritNegativeIntLiteral, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::value::negative_int_literal::FormatGritNegativeIntLiteral::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::regex_pattern_variables::FormatGritRegexPatternVariables +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritRegexPatternVariables, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritRegexPatternVariables { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritRegexPatternVariables, + crate::grit::auxiliary::regex_pattern_variables::FormatGritRegexPatternVariables, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: grit :: auxiliary :: regex_pattern_variables :: FormatGritRegexPatternVariables :: default ()) + } +} +impl IntoFormat for biome_grit_syntax::GritRegexPatternVariables { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritRegexPatternVariables, + crate::grit::auxiliary::regex_pattern_variables::FormatGritRegexPatternVariables, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: grit :: auxiliary :: regex_pattern_variables :: FormatGritRegexPatternVariables :: default ()) + } +} +impl FormatRule + for crate::grit::lists::pattern_arg_list::FormatGritPatternArgList +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPatternArgList, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPatternArgList { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPatternArgList, + crate::grit::lists::pattern_arg_list::FormatGritPatternArgList, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::lists::pattern_arg_list::FormatGritPatternArgList::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPatternArgList { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPatternArgList, + crate::grit::lists::pattern_arg_list::FormatGritPatternArgList, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::lists::pattern_arg_list::FormatGritPatternArgList::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::pattern_definition_body::FormatGritPatternDefinitionBody +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPatternDefinitionBody, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPatternDefinitionBody { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPatternDefinitionBody, + crate::grit::auxiliary::pattern_definition_body::FormatGritPatternDefinitionBody, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: grit :: auxiliary :: pattern_definition_body :: FormatGritPatternDefinitionBody :: default ()) + } +} +impl IntoFormat for biome_grit_syntax::GritPatternDefinitionBody { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPatternDefinitionBody, + crate::grit::auxiliary::pattern_definition_body::FormatGritPatternDefinitionBody, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: grit :: auxiliary :: pattern_definition_body :: FormatGritPatternDefinitionBody :: default ()) + } +} +impl FormatRule + for crate::grit::lists::curly_predicate_list::FormatGritCurlyPredicateList +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritCurlyPredicateList, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritCurlyPredicateList { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritCurlyPredicateList, + crate::grit::lists::curly_predicate_list::FormatGritCurlyPredicateList, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::lists::curly_predicate_list::FormatGritCurlyPredicateList::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritCurlyPredicateList { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritCurlyPredicateList, + crate::grit::lists::curly_predicate_list::FormatGritCurlyPredicateList, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::lists::curly_predicate_list::FormatGritCurlyPredicateList::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::predicate_not::FormatGritPredicateNot +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPredicateNot, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPredicateNot { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPredicateNot, + crate::grit::auxiliary::predicate_not::FormatGritPredicateNot, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::predicate_not::FormatGritPredicateNot::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPredicateNot { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPredicateNot, + crate::grit::auxiliary::predicate_not::FormatGritPredicateNot, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::predicate_not::FormatGritPredicateNot::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::predicate_maybe::FormatGritPredicateMaybe +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPredicateMaybe, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPredicateMaybe { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPredicateMaybe, + crate::grit::auxiliary::predicate_maybe::FormatGritPredicateMaybe, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::predicate_maybe::FormatGritPredicateMaybe::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPredicateMaybe { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPredicateMaybe, + crate::grit::auxiliary::predicate_maybe::FormatGritPredicateMaybe, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::predicate_maybe::FormatGritPredicateMaybe::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::predicate_and::FormatGritPredicateAnd +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPredicateAnd, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPredicateAnd { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPredicateAnd, + crate::grit::auxiliary::predicate_and::FormatGritPredicateAnd, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::predicate_and::FormatGritPredicateAnd::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPredicateAnd { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPredicateAnd, + crate::grit::auxiliary::predicate_and::FormatGritPredicateAnd, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::predicate_and::FormatGritPredicateAnd::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::predicate_or::FormatGritPredicateOr +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPredicateOr, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPredicateOr { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPredicateOr, + crate::grit::auxiliary::predicate_or::FormatGritPredicateOr, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::predicate_or::FormatGritPredicateOr::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPredicateOr { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPredicateOr, + crate::grit::auxiliary::predicate_or::FormatGritPredicateOr, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::predicate_or::FormatGritPredicateOr::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::predicate_any::FormatGritPredicateAny +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPredicateAny, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPredicateAny { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPredicateAny, + crate::grit::auxiliary::predicate_any::FormatGritPredicateAny, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::predicate_any::FormatGritPredicateAny::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPredicateAny { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPredicateAny, + crate::grit::auxiliary::predicate_any::FormatGritPredicateAny, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::predicate_any::FormatGritPredicateAny::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::predicate_if_else::FormatGritPredicateIfElse +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPredicateIfElse, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPredicateIfElse { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPredicateIfElse, + crate::grit::auxiliary::predicate_if_else::FormatGritPredicateIfElse, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::predicate_if_else::FormatGritPredicateIfElse::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPredicateIfElse { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPredicateIfElse, + crate::grit::auxiliary::predicate_if_else::FormatGritPredicateIfElse, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::predicate_if_else::FormatGritPredicateIfElse::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::predicate_assignment::FormatGritPredicateAssignment +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPredicateAssignment, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPredicateAssignment { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPredicateAssignment, + crate::grit::auxiliary::predicate_assignment::FormatGritPredicateAssignment, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::predicate_assignment::FormatGritPredicateAssignment::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPredicateAssignment { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPredicateAssignment, + crate::grit::auxiliary::predicate_assignment::FormatGritPredicateAssignment, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::predicate_assignment::FormatGritPredicateAssignment::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::predicate_accumulate::FormatGritPredicateAccumulate +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPredicateAccumulate, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPredicateAccumulate { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPredicateAccumulate, + crate::grit::auxiliary::predicate_accumulate::FormatGritPredicateAccumulate, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::predicate_accumulate::FormatGritPredicateAccumulate::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPredicateAccumulate { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPredicateAccumulate, + crate::grit::auxiliary::predicate_accumulate::FormatGritPredicateAccumulate, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::predicate_accumulate::FormatGritPredicateAccumulate::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::predicate_rewrite::FormatGritPredicateRewrite +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPredicateRewrite, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPredicateRewrite { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPredicateRewrite, + crate::grit::auxiliary::predicate_rewrite::FormatGritPredicateRewrite, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::predicate_rewrite::FormatGritPredicateRewrite::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPredicateRewrite { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPredicateRewrite, + crate::grit::auxiliary::predicate_rewrite::FormatGritPredicateRewrite, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::predicate_rewrite::FormatGritPredicateRewrite::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::predicate_greater::FormatGritPredicateGreater +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPredicateGreater, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPredicateGreater { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPredicateGreater, + crate::grit::auxiliary::predicate_greater::FormatGritPredicateGreater, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::predicate_greater::FormatGritPredicateGreater::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPredicateGreater { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPredicateGreater, + crate::grit::auxiliary::predicate_greater::FormatGritPredicateGreater, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::predicate_greater::FormatGritPredicateGreater::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::predicate_less::FormatGritPredicateLess +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPredicateLess, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPredicateLess { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPredicateLess, + crate::grit::auxiliary::predicate_less::FormatGritPredicateLess, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::predicate_less::FormatGritPredicateLess::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPredicateLess { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPredicateLess, + crate::grit::auxiliary::predicate_less::FormatGritPredicateLess, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::predicate_less::FormatGritPredicateLess::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::predicate_greater_equal::FormatGritPredicateGreaterEqual +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPredicateGreaterEqual, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPredicateGreaterEqual { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPredicateGreaterEqual, + crate::grit::auxiliary::predicate_greater_equal::FormatGritPredicateGreaterEqual, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: grit :: auxiliary :: predicate_greater_equal :: FormatGritPredicateGreaterEqual :: default ()) + } +} +impl IntoFormat for biome_grit_syntax::GritPredicateGreaterEqual { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPredicateGreaterEqual, + crate::grit::auxiliary::predicate_greater_equal::FormatGritPredicateGreaterEqual, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: grit :: auxiliary :: predicate_greater_equal :: FormatGritPredicateGreaterEqual :: default ()) + } +} +impl FormatRule + for crate::grit::auxiliary::predicate_less_equal::FormatGritPredicateLessEqual +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPredicateLessEqual, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPredicateLessEqual { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPredicateLessEqual, + crate::grit::auxiliary::predicate_less_equal::FormatGritPredicateLessEqual, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::predicate_less_equal::FormatGritPredicateLessEqual::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPredicateLessEqual { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPredicateLessEqual, + crate::grit::auxiliary::predicate_less_equal::FormatGritPredicateLessEqual, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::predicate_less_equal::FormatGritPredicateLessEqual::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::predicate_not_equal::FormatGritPredicateNotEqual +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPredicateNotEqual, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPredicateNotEqual { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPredicateNotEqual, + crate::grit::auxiliary::predicate_not_equal::FormatGritPredicateNotEqual, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::predicate_not_equal::FormatGritPredicateNotEqual::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPredicateNotEqual { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPredicateNotEqual, + crate::grit::auxiliary::predicate_not_equal::FormatGritPredicateNotEqual, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::predicate_not_equal::FormatGritPredicateNotEqual::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::predicate_equal::FormatGritPredicateEqual +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPredicateEqual, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPredicateEqual { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPredicateEqual, + crate::grit::auxiliary::predicate_equal::FormatGritPredicateEqual, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::predicate_equal::FormatGritPredicateEqual::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPredicateEqual { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPredicateEqual, + crate::grit::auxiliary::predicate_equal::FormatGritPredicateEqual, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::predicate_equal::FormatGritPredicateEqual::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::predicate_match::FormatGritPredicateMatch +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPredicateMatch, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPredicateMatch { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPredicateMatch, + crate::grit::auxiliary::predicate_match::FormatGritPredicateMatch, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::predicate_match::FormatGritPredicateMatch::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPredicateMatch { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPredicateMatch, + crate::grit::auxiliary::predicate_match::FormatGritPredicateMatch, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::predicate_match::FormatGritPredicateMatch::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::predicate_call::FormatGritPredicateCall +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPredicateCall, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPredicateCall { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPredicateCall, + crate::grit::auxiliary::predicate_call::FormatGritPredicateCall, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::predicate_call::FormatGritPredicateCall::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPredicateCall { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPredicateCall, + crate::grit::auxiliary::predicate_call::FormatGritPredicateCall, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::predicate_call::FormatGritPredicateCall::default(), + ) + } +} +impl FormatRule + for crate::js::expressions::grit_predicate::FormatBracketedGritPredicate +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::BracketedGritPredicate, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::BracketedGritPredicate { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::BracketedGritPredicate, + crate::js::expressions::grit_predicate::FormatBracketedGritPredicate, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::js::expressions::grit_predicate::FormatBracketedGritPredicate::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::BracketedGritPredicate { + type Format = FormatOwnedWithRule< + biome_grit_syntax::BracketedGritPredicate, + crate::js::expressions::grit_predicate::FormatBracketedGritPredicate, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::js::expressions::grit_predicate::FormatBracketedGritPredicate::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::predicate_return::FormatGritPredicateReturn +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPredicateReturn, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPredicateReturn { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPredicateReturn, + crate::grit::auxiliary::predicate_return::FormatGritPredicateReturn, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::predicate_return::FormatGritPredicateReturn::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPredicateReturn { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPredicateReturn, + crate::grit::auxiliary::predicate_return::FormatGritPredicateReturn, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::predicate_return::FormatGritPredicateReturn::default(), + ) + } +} +impl FormatRule + for crate::grit::auxiliary::predicate_else_clause::FormatGritPredicateElseClause +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritPredicateElseClause, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritPredicateElseClause { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPredicateElseClause, + crate::grit::auxiliary::predicate_else_clause::FormatGritPredicateElseClause, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::auxiliary::predicate_else_clause::FormatGritPredicateElseClause::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPredicateElseClause { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPredicateElseClause, + crate::grit::auxiliary::predicate_else_clause::FormatGritPredicateElseClause, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::auxiliary::predicate_else_clause::FormatGritPredicateElseClause::default(), + ) + } +} +impl FormatRule + for crate::grit::value::backtick_snippet_literal::FormatGritBacktickSnippetLiteral +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritBacktickSnippetLiteral, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritBacktickSnippetLiteral { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritBacktickSnippetLiteral, + crate::grit::value::backtick_snippet_literal::FormatGritBacktickSnippetLiteral, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::value::backtick_snippet_literal::FormatGritBacktickSnippetLiteral::default( + ), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritBacktickSnippetLiteral { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritBacktickSnippetLiteral, + crate::grit::value::backtick_snippet_literal::FormatGritBacktickSnippetLiteral, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::value::backtick_snippet_literal::FormatGritBacktickSnippetLiteral::default( + ), + ) + } +} +impl FormatRule + for crate::grit::value::raw_backtick_snippet_literal::FormatGritRawBacktickSnippetLiteral +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritRawBacktickSnippetLiteral, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritRawBacktickSnippetLiteral { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritRawBacktickSnippetLiteral, + crate::grit::value::raw_backtick_snippet_literal::FormatGritRawBacktickSnippetLiteral, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: grit :: value :: raw_backtick_snippet_literal :: FormatGritRawBacktickSnippetLiteral :: default ()) + } +} +impl IntoFormat for biome_grit_syntax::GritRawBacktickSnippetLiteral { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritRawBacktickSnippetLiteral, + crate::grit::value::raw_backtick_snippet_literal::FormatGritRawBacktickSnippetLiteral, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: grit :: value :: raw_backtick_snippet_literal :: FormatGritRawBacktickSnippetLiteral :: default ()) + } +} +impl FormatRule + for crate::grit::auxiliary::language_specific_snippet::FormatGritLanguageSpecificSnippet +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritLanguageSpecificSnippet, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritLanguageSpecificSnippet { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritLanguageSpecificSnippet, + crate::grit::auxiliary::language_specific_snippet::FormatGritLanguageSpecificSnippet, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: grit :: auxiliary :: language_specific_snippet :: FormatGritLanguageSpecificSnippet :: default ()) + } +} +impl IntoFormat for biome_grit_syntax::GritLanguageSpecificSnippet { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritLanguageSpecificSnippet, + crate::grit::auxiliary::language_specific_snippet::FormatGritLanguageSpecificSnippet, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: grit :: auxiliary :: language_specific_snippet :: FormatGritLanguageSpecificSnippet :: default ()) + } +} +impl FormatRule + for crate::grit::value::regex_literal::FormatGritRegexLiteral +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritRegexLiteral, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritRegexLiteral { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritRegexLiteral, + crate::grit::value::regex_literal::FormatGritRegexLiteral, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::value::regex_literal::FormatGritRegexLiteral::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritRegexLiteral { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritRegexLiteral, + crate::grit::value::regex_literal::FormatGritRegexLiteral, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::value::regex_literal::FormatGritRegexLiteral::default(), + ) + } +} +impl FormatRule + for crate::grit::value::snippet_regex_literal::FormatGritSnippetRegexLiteral +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritSnippetRegexLiteral, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritSnippetRegexLiteral { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritSnippetRegexLiteral, + crate::grit::value::snippet_regex_literal::FormatGritSnippetRegexLiteral, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::value::snippet_regex_literal::FormatGritSnippetRegexLiteral::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritSnippetRegexLiteral { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritSnippetRegexLiteral, + crate::grit::value::snippet_regex_literal::FormatGritSnippetRegexLiteral, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::value::snippet_regex_literal::FormatGritSnippetRegexLiteral::default(), + ) + } +} +impl AsFormat for biome_grit_syntax::GritDefinitionList { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritDefinitionList, + crate::grit::lists::definition_list::FormatGritDefinitionList, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::lists::definition_list::FormatGritDefinitionList::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritDefinitionList { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritDefinitionList, + crate::grit::lists::definition_list::FormatGritDefinitionList, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::lists::definition_list::FormatGritDefinitionList::default(), + ) + } +} +impl AsFormat for biome_grit_syntax::GritLanguageFlavorList { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritLanguageFlavorList, + crate::grit::lists::language_flavor_list::FormatGritLanguageFlavorList, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::lists::language_flavor_list::FormatGritLanguageFlavorList::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritLanguageFlavorList { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritLanguageFlavorList, + crate::grit::lists::language_flavor_list::FormatGritLanguageFlavorList, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::lists::language_flavor_list::FormatGritLanguageFlavorList::default(), + ) + } +} +impl AsFormat for biome_grit_syntax::GritListPatternList { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritListPatternList, + crate::grit::lists::list_pattern_list::FormatGritListPatternList, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::lists::list_pattern_list::FormatGritListPatternList::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritListPatternList { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritListPatternList, + crate::grit::lists::list_pattern_list::FormatGritListPatternList, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::lists::list_pattern_list::FormatGritListPatternList::default(), + ) + } +} +impl AsFormat for biome_grit_syntax::GritMapElementList { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritMapElementList, + crate::grit::lists::map_element_list::FormatGritMapElementList, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::lists::map_element_list::FormatGritMapElementList::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritMapElementList { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritMapElementList, + crate::grit::lists::map_element_list::FormatGritMapElementList, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::lists::map_element_list::FormatGritMapElementList::default(), + ) + } +} +impl AsFormat for biome_grit_syntax::GritNamedArgList { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritNamedArgList, + crate::grit::lists::named_arg_list::FormatGritNamedArgList, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::lists::named_arg_list::FormatGritNamedArgList::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritNamedArgList { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritNamedArgList, + crate::grit::lists::named_arg_list::FormatGritNamedArgList, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::lists::named_arg_list::FormatGritNamedArgList::default(), + ) + } +} +impl AsFormat for biome_grit_syntax::GritPatternList { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPatternList, + crate::grit::lists::pattern_list::FormatGritPatternList, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::lists::pattern_list::FormatGritPatternList::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPatternList { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPatternList, + crate::grit::lists::pattern_list::FormatGritPatternList, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::lists::pattern_list::FormatGritPatternList::default(), + ) + } +} +impl AsFormat for biome_grit_syntax::GritPredicateList { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPredicateList, + crate::grit::lists::predicate_list::FormatGritPredicateList, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::lists::predicate_list::FormatGritPredicateList::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPredicateList { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPredicateList, + crate::grit::lists::predicate_list::FormatGritPredicateList, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::lists::predicate_list::FormatGritPredicateList::default(), + ) + } +} +impl AsFormat for biome_grit_syntax::GritVariableList { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritVariableList, + crate::grit::lists::variable_list::FormatGritVariableList, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::lists::variable_list::FormatGritVariableList::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritVariableList { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritVariableList, + crate::grit::lists::variable_list::FormatGritVariableList, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::lists::variable_list::FormatGritVariableList::default(), + ) + } +} +impl FormatRule for crate::grit::bogus::bogus::FormatGritBogus { + type Context = GritFormatContext; + #[inline(always)] + fn fmt(&self, node: &biome_grit_syntax::GritBogus, f: &mut GritFormatter) -> FormatResult<()> { + FormatBogusNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritBogus { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritBogus, + crate::grit::bogus::bogus::FormatGritBogus, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new(self, crate::grit::bogus::bogus::FormatGritBogus::default()) + } +} +impl IntoFormat for biome_grit_syntax::GritBogus { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritBogus, + crate::grit::bogus::bogus::FormatGritBogus, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new(self, crate::grit::bogus::bogus::FormatGritBogus::default()) + } +} +impl FormatRule + for crate::grit::bogus::bogus_definition::FormatGritBogusDefinition +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritBogusDefinition, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatBogusNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritBogusDefinition { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritBogusDefinition, + crate::grit::bogus::bogus_definition::FormatGritBogusDefinition, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::bogus::bogus_definition::FormatGritBogusDefinition::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritBogusDefinition { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritBogusDefinition, + crate::grit::bogus::bogus_definition::FormatGritBogusDefinition, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::bogus::bogus_definition::FormatGritBogusDefinition::default(), + ) + } +} +impl FormatRule + for crate::grit::bogus::bogus_pattern::FormatGritBogusPattern +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritBogusPattern, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatBogusNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritBogusPattern { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritBogusPattern, + crate::grit::bogus::bogus_pattern::FormatGritBogusPattern, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::bogus::bogus_pattern::FormatGritBogusPattern::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritBogusPattern { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritBogusPattern, + crate::grit::bogus::bogus_pattern::FormatGritBogusPattern, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::bogus::bogus_pattern::FormatGritBogusPattern::default(), + ) + } +} +impl FormatRule + for crate::grit::bogus::bogus_literal::FormatGritBogusLiteral +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritBogusLiteral, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatBogusNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritBogusLiteral { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritBogusLiteral, + crate::grit::bogus::bogus_literal::FormatGritBogusLiteral, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::bogus::bogus_literal::FormatGritBogusLiteral::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritBogusLiteral { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritBogusLiteral, + crate::grit::bogus::bogus_literal::FormatGritBogusLiteral, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::bogus::bogus_literal::FormatGritBogusLiteral::default(), + ) + } +} +impl FormatRule + for crate::grit::bogus::bogus_named_arg::FormatGritBogusNamedArg +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritBogusNamedArg, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatBogusNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritBogusNamedArg { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritBogusNamedArg, + crate::grit::bogus::bogus_named_arg::FormatGritBogusNamedArg, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::bogus::bogus_named_arg::FormatGritBogusNamedArg::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritBogusNamedArg { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritBogusNamedArg, + crate::grit::bogus::bogus_named_arg::FormatGritBogusNamedArg, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::bogus::bogus_named_arg::FormatGritBogusNamedArg::default(), + ) + } +} +impl FormatRule + for crate::grit::bogus::bogus_predicate::FormatGritBogusPredicate +{ + type Context = GritFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_grit_syntax::GritBogusPredicate, + f: &mut GritFormatter, + ) -> FormatResult<()> { + FormatBogusNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_grit_syntax::GritBogusPredicate { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritBogusPredicate, + crate::grit::bogus::bogus_predicate::FormatGritBogusPredicate, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::bogus::bogus_predicate::FormatGritBogusPredicate::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritBogusPredicate { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritBogusPredicate, + crate::grit::bogus::bogus_predicate::FormatGritBogusPredicate, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::bogus::bogus_predicate::FormatGritBogusPredicate::default(), + ) + } +} +impl AsFormat for biome_grit_syntax::AnyGritPattern { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::AnyGritPattern, + crate::grit::any::pattern::FormatAnyGritPattern, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::any::pattern::FormatAnyGritPattern::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::AnyGritPattern { + type Format = FormatOwnedWithRule< + biome_grit_syntax::AnyGritPattern, + crate::grit::any::pattern::FormatAnyGritPattern, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::any::pattern::FormatAnyGritPattern::default(), + ) + } +} +impl AsFormat for biome_grit_syntax::AnyGritDefinition { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::AnyGritDefinition, + crate::grit::any::definition::FormatAnyGritDefinition, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::any::definition::FormatAnyGritDefinition::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::AnyGritDefinition { + type Format = FormatOwnedWithRule< + biome_grit_syntax::AnyGritDefinition, + crate::grit::any::definition::FormatAnyGritDefinition, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::any::definition::FormatAnyGritDefinition::default(), + ) + } +} +impl AsFormat for biome_grit_syntax::AnyGritLiteral { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::AnyGritLiteral, + crate::grit::any::literal::FormatAnyGritLiteral, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::any::literal::FormatAnyGritLiteral::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::AnyGritLiteral { + type Format = FormatOwnedWithRule< + biome_grit_syntax::AnyGritLiteral, + crate::grit::any::literal::FormatAnyGritLiteral, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::any::literal::FormatAnyGritLiteral::default(), + ) + } +} +impl AsFormat for biome_grit_syntax::MaybeCurlyGritPattern { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::MaybeCurlyGritPattern, + crate::js::any::curly_grit_pattern::FormatMaybeCurlyGritPattern, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::js::any::curly_grit_pattern::FormatMaybeCurlyGritPattern::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::MaybeCurlyGritPattern { + type Format = FormatOwnedWithRule< + biome_grit_syntax::MaybeCurlyGritPattern, + crate::js::any::curly_grit_pattern::FormatMaybeCurlyGritPattern, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::js::any::curly_grit_pattern::FormatMaybeCurlyGritPattern::default(), + ) + } +} +impl AsFormat for biome_grit_syntax::AnyGritContainer { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::AnyGritContainer, + crate::grit::any::container::FormatAnyGritContainer, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::any::container::FormatAnyGritContainer::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::AnyGritContainer { + type Format = FormatOwnedWithRule< + biome_grit_syntax::AnyGritContainer, + crate::grit::any::container::FormatAnyGritContainer, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::any::container::FormatAnyGritContainer::default(), + ) + } +} +impl AsFormat for biome_grit_syntax::AnyGritPredicate { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::AnyGritPredicate, + crate::grit::any::predicate::FormatAnyGritPredicate, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::any::predicate::FormatAnyGritPredicate::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::AnyGritPredicate { + type Format = FormatOwnedWithRule< + biome_grit_syntax::AnyGritPredicate, + crate::grit::any::predicate::FormatAnyGritPredicate, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::any::predicate::FormatAnyGritPredicate::default(), + ) + } +} +impl AsFormat for biome_grit_syntax::AnyGritNamedArg { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::AnyGritNamedArg, + crate::grit::any::named_arg::FormatAnyGritNamedArg, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::any::named_arg::FormatAnyGritNamedArg::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::AnyGritNamedArg { + type Format = FormatOwnedWithRule< + biome_grit_syntax::AnyGritNamedArg, + crate::grit::any::named_arg::FormatAnyGritNamedArg, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::any::named_arg::FormatAnyGritNamedArg::default(), + ) + } +} +impl AsFormat for biome_grit_syntax::GritMapAccessorSubject { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritMapAccessorSubject, + crate::grit::any::map_accessor_subject::FormatGritMapAccessorSubject, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::any::map_accessor_subject::FormatGritMapAccessorSubject::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritMapAccessorSubject { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritMapAccessorSubject, + crate::grit::any::map_accessor_subject::FormatGritMapAccessorSubject, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::any::map_accessor_subject::FormatGritMapAccessorSubject::default(), + ) + } +} +impl AsFormat for biome_grit_syntax::GritMapKey { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritMapKey, + crate::grit::any::map_key::FormatGritMapKey, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new(self, crate::grit::any::map_key::FormatGritMapKey::default()) + } +} +impl IntoFormat for biome_grit_syntax::GritMapKey { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritMapKey, + crate::grit::any::map_key::FormatGritMapKey, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new(self, crate::grit::any::map_key::FormatGritMapKey::default()) + } +} +impl AsFormat for biome_grit_syntax::AnyGritListPattern { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::AnyGritListPattern, + crate::grit::any::list_pattern::FormatAnyGritListPattern, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::any::list_pattern::FormatAnyGritListPattern::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::AnyGritListPattern { + type Format = FormatOwnedWithRule< + biome_grit_syntax::AnyGritListPattern, + crate::grit::any::list_pattern::FormatAnyGritListPattern, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::any::list_pattern::FormatAnyGritListPattern::default(), + ) + } +} +impl AsFormat for biome_grit_syntax::GritListAccessorSubject { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritListAccessorSubject, + crate::grit::any::list_accessor_subject::FormatGritListAccessorSubject, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::any::list_accessor_subject::FormatGritListAccessorSubject::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritListAccessorSubject { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritListAccessorSubject, + crate::grit::any::list_accessor_subject::FormatGritListAccessorSubject, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::any::list_accessor_subject::FormatGritListAccessorSubject::default(), + ) + } +} +impl AsFormat for biome_grit_syntax::GritListIndex { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritListIndex, + crate::grit::any::list_index::FormatGritListIndex, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::any::list_index::FormatGritListIndex::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritListIndex { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritListIndex, + crate::grit::any::list_index::FormatGritListIndex, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::any::list_index::FormatGritListIndex::default(), + ) + } +} +impl AsFormat for biome_grit_syntax::AnyGritRegex { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::AnyGritRegex, + crate::grit::any::regex::FormatAnyGritRegex, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new(self, crate::grit::any::regex::FormatAnyGritRegex::default()) + } +} +impl IntoFormat for biome_grit_syntax::AnyGritRegex { + type Format = FormatOwnedWithRule< + biome_grit_syntax::AnyGritRegex, + crate::grit::any::regex::FormatAnyGritRegex, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new(self, crate::grit::any::regex::FormatAnyGritRegex::default()) + } +} +impl AsFormat for biome_grit_syntax::GritPredicateMatchSubject { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritPredicateMatchSubject, + crate::grit::any::predicate_match_subject::FormatGritPredicateMatchSubject, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::any::predicate_match_subject::FormatGritPredicateMatchSubject::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritPredicateMatchSubject { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritPredicateMatchSubject, + crate::grit::any::predicate_match_subject::FormatGritPredicateMatchSubject, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::any::predicate_match_subject::FormatGritPredicateMatchSubject::default(), + ) + } +} +impl AsFormat for biome_grit_syntax::GritCodeSnippetSource { + type Format<'a> = FormatRefWithRule< + 'a, + biome_grit_syntax::GritCodeSnippetSource, + crate::grit::any::code_snippet_source::FormatGritCodeSnippetSource, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::grit::any::code_snippet_source::FormatGritCodeSnippetSource::default(), + ) + } +} +impl IntoFormat for biome_grit_syntax::GritCodeSnippetSource { + type Format = FormatOwnedWithRule< + biome_grit_syntax::GritCodeSnippetSource, + crate::grit::any::code_snippet_source::FormatGritCodeSnippetSource, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::grit::any::code_snippet_source::FormatGritCodeSnippetSource::default(), + ) + } +} diff --git a/crates/biome_grit_formatter/src/grit/any/code_snippet_source.rs b/crates/biome_grit_formatter/src/grit/any/code_snippet_source.rs new file mode 100644 index 00000000000..465d5312996 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/any/code_snippet_source.rs @@ -0,0 +1,16 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +use crate::prelude::*; +use biome_grit_syntax::GritCodeSnippetSource; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritCodeSnippetSource; +impl FormatRule for FormatGritCodeSnippetSource { + type Context = GritFormatContext; + fn fmt(&self, node: &GritCodeSnippetSource, f: &mut GritFormatter) -> FormatResult<()> { + match node { + GritCodeSnippetSource::GritBacktickSnippetLiteral(node) => node.format().fmt(f), + GritCodeSnippetSource::GritLanguageSpecificSnippet(node) => node.format().fmt(f), + GritCodeSnippetSource::GritRawBacktickSnippetLiteral(node) => node.format().fmt(f), + } + } +} diff --git a/crates/biome_grit_formatter/src/grit/any/container.rs b/crates/biome_grit_formatter/src/grit/any/container.rs new file mode 100644 index 00000000000..9d581d31e7a --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/any/container.rs @@ -0,0 +1,16 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +use crate::prelude::*; +use biome_grit_syntax::AnyGritContainer; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatAnyGritContainer; +impl FormatRule for FormatAnyGritContainer { + type Context = GritFormatContext; + fn fmt(&self, node: &AnyGritContainer, f: &mut GritFormatter) -> FormatResult<()> { + match node { + AnyGritContainer::GritVariable(node) => node.format().fmt(f), + AnyGritContainer::GritMapAccessor(node) => node.format().fmt(f), + AnyGritContainer::GritListAccessor(node) => node.format().fmt(f), + } + } +} diff --git a/crates/biome_grit_formatter/src/grit/any/definition.rs b/crates/biome_grit_formatter/src/grit/any/definition.rs new file mode 100644 index 00000000000..e741ef2e5bf --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/any/definition.rs @@ -0,0 +1,17 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +use crate::prelude::*; +use biome_grit_syntax::AnyGritDefinition; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatAnyGritDefinition; +impl FormatRule for FormatAnyGritDefinition { + type Context = GritFormatContext; + fn fmt(&self, node: &AnyGritDefinition, f: &mut GritFormatter) -> FormatResult<()> { + match node { + AnyGritDefinition::GritPatternDefinition(node) => node.format().fmt(f), + AnyGritDefinition::GritPredicateDefinition(node) => node.format().fmt(f), + AnyGritDefinition::GritFunctionDefinition(node) => node.format().fmt(f), + AnyGritDefinition::GritBogusDefinition(node) => node.format().fmt(f), + } + } +} diff --git a/crates/biome_grit_formatter/src/grit/any/list_accessor_subject.rs b/crates/biome_grit_formatter/src/grit/any/list_accessor_subject.rs new file mode 100644 index 00000000000..f1a67ae7bb9 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/any/list_accessor_subject.rs @@ -0,0 +1,15 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +use crate::prelude::*; +use biome_grit_syntax::GritListAccessorSubject; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritListAccessorSubject; +impl FormatRule for FormatGritListAccessorSubject { + type Context = GritFormatContext; + fn fmt(&self, node: &GritListAccessorSubject, f: &mut GritFormatter) -> FormatResult<()> { + match node { + GritListAccessorSubject::GritList(node) => node.format().fmt(f), + GritListAccessorSubject::AnyGritContainer(node) => node.format().fmt(f), + } + } +} diff --git a/crates/biome_grit_formatter/src/grit/any/list_index.rs b/crates/biome_grit_formatter/src/grit/any/list_index.rs new file mode 100644 index 00000000000..54607f5543f --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/any/list_index.rs @@ -0,0 +1,16 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +use crate::prelude::*; +use biome_grit_syntax::GritListIndex; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritListIndex; +impl FormatRule for FormatGritListIndex { + type Context = GritFormatContext; + fn fmt(&self, node: &GritListIndex, f: &mut GritFormatter) -> FormatResult<()> { + match node { + GritListIndex::AnyGritContainer(node) => node.format().fmt(f), + GritListIndex::GritNegativeIntLiteral(node) => node.format().fmt(f), + GritListIndex::GritIntLiteral(node) => node.format().fmt(f), + } + } +} diff --git a/crates/biome_grit_formatter/src/grit/any/list_pattern.rs b/crates/biome_grit_formatter/src/grit/any/list_pattern.rs new file mode 100644 index 00000000000..7eefe85891a --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/any/list_pattern.rs @@ -0,0 +1,15 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +use crate::prelude::*; +use biome_grit_syntax::AnyGritListPattern; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatAnyGritListPattern; +impl FormatRule for FormatAnyGritListPattern { + type Context = GritFormatContext; + fn fmt(&self, node: &AnyGritListPattern, f: &mut GritFormatter) -> FormatResult<()> { + match node { + AnyGritListPattern::AnyGritPattern(node) => node.format().fmt(f), + AnyGritListPattern::GritDotdotdot(node) => node.format().fmt(f), + } + } +} diff --git a/crates/biome_grit_formatter/src/grit/any/literal.rs b/crates/biome_grit_formatter/src/grit/any/literal.rs new file mode 100644 index 00000000000..62d659f18ba --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/any/literal.rs @@ -0,0 +1,22 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +use crate::prelude::*; +use biome_grit_syntax::AnyGritLiteral; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatAnyGritLiteral; +impl FormatRule for FormatAnyGritLiteral { + type Context = GritFormatContext; + fn fmt(&self, node: &AnyGritLiteral, f: &mut GritFormatter) -> FormatResult<()> { + match node { + AnyGritLiteral::GritCodeSnippet(node) => node.format().fmt(f), + AnyGritLiteral::GritStringLiteral(node) => node.format().fmt(f), + AnyGritLiteral::GritIntLiteral(node) => node.format().fmt(f), + AnyGritLiteral::GritDoubleLiteral(node) => node.format().fmt(f), + AnyGritLiteral::GritBooleanLiteral(node) => node.format().fmt(f), + AnyGritLiteral::GritUndefinedLiteral(node) => node.format().fmt(f), + AnyGritLiteral::GritMap(node) => node.format().fmt(f), + AnyGritLiteral::GritList(node) => node.format().fmt(f), + AnyGritLiteral::GritBogusLiteral(node) => node.format().fmt(f), + } + } +} diff --git a/crates/biome_grit_formatter/src/grit/any/map_accessor_subject.rs b/crates/biome_grit_formatter/src/grit/any/map_accessor_subject.rs new file mode 100644 index 00000000000..4926967fe99 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/any/map_accessor_subject.rs @@ -0,0 +1,15 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +use crate::prelude::*; +use biome_grit_syntax::GritMapAccessorSubject; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritMapAccessorSubject; +impl FormatRule for FormatGritMapAccessorSubject { + type Context = GritFormatContext; + fn fmt(&self, node: &GritMapAccessorSubject, f: &mut GritFormatter) -> FormatResult<()> { + match node { + GritMapAccessorSubject::GritMap(node) => node.format().fmt(f), + GritMapAccessorSubject::AnyGritContainer(node) => node.format().fmt(f), + } + } +} diff --git a/crates/biome_grit_formatter/src/grit/any/map_key.rs b/crates/biome_grit_formatter/src/grit/any/map_key.rs new file mode 100644 index 00000000000..154b1a830c5 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/any/map_key.rs @@ -0,0 +1,15 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +use crate::prelude::*; +use biome_grit_syntax::GritMapKey; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritMapKey; +impl FormatRule for FormatGritMapKey { + type Context = GritFormatContext; + fn fmt(&self, node: &GritMapKey, f: &mut GritFormatter) -> FormatResult<()> { + match node { + GritMapKey::GritName(node) => node.format().fmt(f), + GritMapKey::GritVariable(node) => node.format().fmt(f), + } + } +} diff --git a/crates/biome_grit_formatter/src/grit/any/mod.rs b/crates/biome_grit_formatter/src/grit/any/mod.rs new file mode 100644 index 00000000000..957b54c2587 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/any/mod.rs @@ -0,0 +1,16 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +pub(crate) mod code_snippet_source; +pub(crate) mod container; +pub(crate) mod definition; +pub(crate) mod list_accessor_subject; +pub(crate) mod list_index; +pub(crate) mod list_pattern; +pub(crate) mod literal; +pub(crate) mod map_accessor_subject; +pub(crate) mod map_key; +pub(crate) mod named_arg; +pub(crate) mod pattern; +pub(crate) mod predicate; +pub(crate) mod predicate_match_subject; +pub(crate) mod regex; diff --git a/crates/biome_grit_formatter/src/grit/any/named_arg.rs b/crates/biome_grit_formatter/src/grit/any/named_arg.rs new file mode 100644 index 00000000000..5fe84c1e26a --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/any/named_arg.rs @@ -0,0 +1,16 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +use crate::prelude::*; +use biome_grit_syntax::AnyGritNamedArg; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatAnyGritNamedArg; +impl FormatRule for FormatAnyGritNamedArg { + type Context = GritFormatContext; + fn fmt(&self, node: &AnyGritNamedArg, f: &mut GritFormatter) -> FormatResult<()> { + match node { + AnyGritNamedArg::GritNamedArg(node) => node.format().fmt(f), + AnyGritNamedArg::GritNamedArgWithDefault(node) => node.format().fmt(f), + AnyGritNamedArg::GritBogusNamedArg(node) => node.format().fmt(f), + } + } +} diff --git a/crates/biome_grit_formatter/src/grit/any/pattern.rs b/crates/biome_grit_formatter/src/grit/any/pattern.rs new file mode 100644 index 00000000000..1c0af3f2012 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/any/pattern.rs @@ -0,0 +1,52 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +use crate::prelude::*; +use biome_grit_syntax::AnyGritPattern; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatAnyGritPattern; +impl FormatRule for FormatAnyGritPattern { + type Context = GritFormatContext; + fn fmt(&self, node: &AnyGritPattern, f: &mut GritFormatter) -> FormatResult<()> { + match node { + AnyGritPattern::AnyGritLiteral(node) => node.format().fmt(f), + AnyGritPattern::GritPatternNot(node) => node.format().fmt(f), + AnyGritPattern::GritPatternOr(node) => node.format().fmt(f), + AnyGritPattern::GritPatternOrElse(node) => node.format().fmt(f), + AnyGritPattern::GritPatternAny(node) => node.format().fmt(f), + AnyGritPattern::GritPatternAnd(node) => node.format().fmt(f), + AnyGritPattern::GritPatternMaybe(node) => node.format().fmt(f), + AnyGritPattern::GritPatternIfElse(node) => node.format().fmt(f), + AnyGritPattern::GritPatternContains(node) => node.format().fmt(f), + AnyGritPattern::GritPatternIncludes(node) => node.format().fmt(f), + AnyGritPattern::GritPatternAfter(node) => node.format().fmt(f), + AnyGritPattern::GritPatternBefore(node) => node.format().fmt(f), + AnyGritPattern::GritWithin(node) => node.format().fmt(f), + AnyGritPattern::GritBubble(node) => node.format().fmt(f), + AnyGritPattern::GritNodeLike(node) => node.format().fmt(f), + AnyGritPattern::GritMapAccessor(node) => node.format().fmt(f), + AnyGritPattern::GritListAccessor(node) => node.format().fmt(f), + AnyGritPattern::GritDot(node) => node.format().fmt(f), + AnyGritPattern::GritSome(node) => node.format().fmt(f), + AnyGritPattern::GritEvery(node) => node.format().fmt(f), + AnyGritPattern::GritUnderscore(node) => node.format().fmt(f), + AnyGritPattern::GritVariable(node) => node.format().fmt(f), + AnyGritPattern::GritRegexPattern(node) => node.format().fmt(f), + AnyGritPattern::GritPatternAs(node) => node.format().fmt(f), + AnyGritPattern::GritPatternLimit(node) => node.format().fmt(f), + AnyGritPattern::GritAssignmentAsPattern(node) => node.format().fmt(f), + AnyGritPattern::GritPatternAccumulate(node) => node.format().fmt(f), + AnyGritPattern::GritRewrite(node) => node.format().fmt(f), + AnyGritPattern::GritLike(node) => node.format().fmt(f), + AnyGritPattern::GritPatternWhere(node) => node.format().fmt(f), + AnyGritPattern::GritMulOperation(node) => node.format().fmt(f), + AnyGritPattern::GritDivOperation(node) => node.format().fmt(f), + AnyGritPattern::GritModOperation(node) => node.format().fmt(f), + AnyGritPattern::GritAddOperation(node) => node.format().fmt(f), + AnyGritPattern::GritSubOperation(node) => node.format().fmt(f), + AnyGritPattern::GritSequential(node) => node.format().fmt(f), + AnyGritPattern::GritFiles(node) => node.format().fmt(f), + AnyGritPattern::BracketedGritPattern(node) => node.format().fmt(f), + AnyGritPattern::GritBogusPattern(node) => node.format().fmt(f), + } + } +} diff --git a/crates/biome_grit_formatter/src/grit/any/predicate.rs b/crates/biome_grit_formatter/src/grit/any/predicate.rs new file mode 100644 index 00000000000..fa1a8466a61 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/any/predicate.rs @@ -0,0 +1,34 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +use crate::prelude::*; +use biome_grit_syntax::AnyGritPredicate; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatAnyGritPredicate; +impl FormatRule for FormatAnyGritPredicate { + type Context = GritFormatContext; + fn fmt(&self, node: &AnyGritPredicate, f: &mut GritFormatter) -> FormatResult<()> { + match node { + AnyGritPredicate::GritPredicateNot(node) => node.format().fmt(f), + AnyGritPredicate::GritPredicateMaybe(node) => node.format().fmt(f), + AnyGritPredicate::GritPredicateAnd(node) => node.format().fmt(f), + AnyGritPredicate::GritPredicateOr(node) => node.format().fmt(f), + AnyGritPredicate::GritPredicateAny(node) => node.format().fmt(f), + AnyGritPredicate::GritPredicateIfElse(node) => node.format().fmt(f), + AnyGritPredicate::GritPredicateAssignment(node) => node.format().fmt(f), + AnyGritPredicate::GritPredicateAccumulate(node) => node.format().fmt(f), + AnyGritPredicate::GritPredicateRewrite(node) => node.format().fmt(f), + AnyGritPredicate::GritPredicateGreater(node) => node.format().fmt(f), + AnyGritPredicate::GritPredicateLess(node) => node.format().fmt(f), + AnyGritPredicate::GritPredicateGreaterEqual(node) => node.format().fmt(f), + AnyGritPredicate::GritPredicateLessEqual(node) => node.format().fmt(f), + AnyGritPredicate::GritPredicateNotEqual(node) => node.format().fmt(f), + AnyGritPredicate::GritPredicateEqual(node) => node.format().fmt(f), + AnyGritPredicate::GritPredicateMatch(node) => node.format().fmt(f), + AnyGritPredicate::GritPredicateCall(node) => node.format().fmt(f), + AnyGritPredicate::BracketedGritPredicate(node) => node.format().fmt(f), + AnyGritPredicate::GritBooleanLiteral(node) => node.format().fmt(f), + AnyGritPredicate::GritPredicateReturn(node) => node.format().fmt(f), + AnyGritPredicate::GritBogusPredicate(node) => node.format().fmt(f), + } + } +} diff --git a/crates/biome_grit_formatter/src/grit/any/predicate_match_subject.rs b/crates/biome_grit_formatter/src/grit/any/predicate_match_subject.rs new file mode 100644 index 00000000000..92f22836cea --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/any/predicate_match_subject.rs @@ -0,0 +1,15 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +use crate::prelude::*; +use biome_grit_syntax::GritPredicateMatchSubject; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPredicateMatchSubject; +impl FormatRule for FormatGritPredicateMatchSubject { + type Context = GritFormatContext; + fn fmt(&self, node: &GritPredicateMatchSubject, f: &mut GritFormatter) -> FormatResult<()> { + match node { + GritPredicateMatchSubject::AnyGritContainer(node) => node.format().fmt(f), + GritPredicateMatchSubject::AnyGritLiteral(node) => node.format().fmt(f), + } + } +} diff --git a/crates/biome_grit_formatter/src/grit/any/regex.rs b/crates/biome_grit_formatter/src/grit/any/regex.rs new file mode 100644 index 00000000000..c4d2e565039 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/any/regex.rs @@ -0,0 +1,15 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +use crate::prelude::*; +use biome_grit_syntax::AnyGritRegex; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatAnyGritRegex; +impl FormatRule for FormatAnyGritRegex { + type Context = GritFormatContext; + fn fmt(&self, node: &AnyGritRegex, f: &mut GritFormatter) -> FormatResult<()> { + match node { + AnyGritRegex::GritRegexLiteral(node) => node.format().fmt(f), + AnyGritRegex::GritSnippetRegexLiteral(node) => node.format().fmt(f), + } + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/add_operation.rs b/crates/biome_grit_formatter/src/grit/auxiliary/add_operation.rs new file mode 100644 index 00000000000..e063453ce77 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/add_operation.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritAddOperation; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritAddOperation; +impl FormatNodeRule for FormatGritAddOperation { + fn fmt_fields(&self, node: &GritAddOperation, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/annotation.rs b/crates/biome_grit_formatter/src/grit/auxiliary/annotation.rs new file mode 100644 index 00000000000..9a1d3514788 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/annotation.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritAnnotation; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritAnnotation; +impl FormatNodeRule for FormatGritAnnotation { + fn fmt_fields(&self, node: &GritAnnotation, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/assignment_as_pattern.rs b/crates/biome_grit_formatter/src/grit/auxiliary/assignment_as_pattern.rs new file mode 100644 index 00000000000..a3879bbaaab --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/assignment_as_pattern.rs @@ -0,0 +1,14 @@ +use crate::prelude::*; +use biome_grit_syntax::GritAssignmentAsPattern; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritAssignmentAsPattern; +impl FormatNodeRule for FormatGritAssignmentAsPattern { + fn fmt_fields( + &self, + node: &GritAssignmentAsPattern, + f: &mut GritFormatter, + ) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/bubble.rs b/crates/biome_grit_formatter/src/grit/auxiliary/bubble.rs new file mode 100644 index 00000000000..9513e01b697 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/bubble.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritBubble; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritBubble; +impl FormatNodeRule for FormatGritBubble { + fn fmt_fields(&self, node: &GritBubble, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/bubble_scope.rs b/crates/biome_grit_formatter/src/grit/auxiliary/bubble_scope.rs new file mode 100644 index 00000000000..a471b58fc4b --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/bubble_scope.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritBubbleScope; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritBubbleScope; +impl FormatNodeRule for FormatGritBubbleScope { + fn fmt_fields(&self, node: &GritBubbleScope, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/code_snippet.rs b/crates/biome_grit_formatter/src/grit/auxiliary/code_snippet.rs new file mode 100644 index 00000000000..6dc62de3c21 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/code_snippet.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritCodeSnippet; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritCodeSnippet; +impl FormatNodeRule for FormatGritCodeSnippet { + fn fmt_fields(&self, node: &GritCodeSnippet, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/div_operation.rs b/crates/biome_grit_formatter/src/grit/auxiliary/div_operation.rs new file mode 100644 index 00000000000..2088be6d0e2 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/div_operation.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritDivOperation; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritDivOperation; +impl FormatNodeRule for FormatGritDivOperation { + fn fmt_fields(&self, node: &GritDivOperation, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/dot.rs b/crates/biome_grit_formatter/src/grit/auxiliary/dot.rs new file mode 100644 index 00000000000..4e1972c9270 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/dot.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritDot; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritDot; +impl FormatNodeRule for FormatGritDot { + fn fmt_fields(&self, node: &GritDot, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/dotdotdot.rs b/crates/biome_grit_formatter/src/grit/auxiliary/dotdotdot.rs new file mode 100644 index 00000000000..0d48726ea25 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/dotdotdot.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritDotdotdot; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritDotdotdot; +impl FormatNodeRule for FormatGritDotdotdot { + fn fmt_fields(&self, node: &GritDotdotdot, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/every.rs b/crates/biome_grit_formatter/src/grit/auxiliary/every.rs new file mode 100644 index 00000000000..3ad8d2fcbb4 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/every.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritEvery; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritEvery; +impl FormatNodeRule for FormatGritEvery { + fn fmt_fields(&self, node: &GritEvery, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/files.rs b/crates/biome_grit_formatter/src/grit/auxiliary/files.rs new file mode 100644 index 00000000000..be2306fdf62 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/files.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritFiles; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritFiles; +impl FormatNodeRule for FormatGritFiles { + fn fmt_fields(&self, node: &GritFiles, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/function_definition.rs b/crates/biome_grit_formatter/src/grit/auxiliary/function_definition.rs new file mode 100644 index 00000000000..bee82b18d28 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/function_definition.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritFunctionDefinition; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritFunctionDefinition; +impl FormatNodeRule for FormatGritFunctionDefinition { + fn fmt_fields(&self, node: &GritFunctionDefinition, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/language_declaration.rs b/crates/biome_grit_formatter/src/grit/auxiliary/language_declaration.rs new file mode 100644 index 00000000000..5c86b94513d --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/language_declaration.rs @@ -0,0 +1,14 @@ +use crate::prelude::*; +use biome_grit_syntax::GritLanguageDeclaration; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritLanguageDeclaration; +impl FormatNodeRule for FormatGritLanguageDeclaration { + fn fmt_fields( + &self, + node: &GritLanguageDeclaration, + f: &mut GritFormatter, + ) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/language_flavor.rs b/crates/biome_grit_formatter/src/grit/auxiliary/language_flavor.rs new file mode 100644 index 00000000000..19641a82ea2 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/language_flavor.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritLanguageFlavor; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritLanguageFlavor; +impl FormatNodeRule for FormatGritLanguageFlavor { + fn fmt_fields(&self, node: &GritLanguageFlavor, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/language_flavor_kind.rs b/crates/biome_grit_formatter/src/grit/auxiliary/language_flavor_kind.rs new file mode 100644 index 00000000000..db79c337782 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/language_flavor_kind.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritLanguageFlavorKind; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritLanguageFlavorKind; +impl FormatNodeRule for FormatGritLanguageFlavorKind { + fn fmt_fields(&self, node: &GritLanguageFlavorKind, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/language_name.rs b/crates/biome_grit_formatter/src/grit/auxiliary/language_name.rs new file mode 100644 index 00000000000..98d8e40f2af --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/language_name.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritLanguageName; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritLanguageName; +impl FormatNodeRule for FormatGritLanguageName { + fn fmt_fields(&self, node: &GritLanguageName, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/language_specific_snippet.rs b/crates/biome_grit_formatter/src/grit/auxiliary/language_specific_snippet.rs new file mode 100644 index 00000000000..16f76495c22 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/language_specific_snippet.rs @@ -0,0 +1,14 @@ +use crate::prelude::*; +use biome_grit_syntax::GritLanguageSpecificSnippet; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritLanguageSpecificSnippet; +impl FormatNodeRule for FormatGritLanguageSpecificSnippet { + fn fmt_fields( + &self, + node: &GritLanguageSpecificSnippet, + f: &mut GritFormatter, + ) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/like.rs b/crates/biome_grit_formatter/src/grit/auxiliary/like.rs new file mode 100644 index 00000000000..83625c5dccb --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/like.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritLike; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritLike; +impl FormatNodeRule for FormatGritLike { + fn fmt_fields(&self, node: &GritLike, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/like_threshold.rs b/crates/biome_grit_formatter/src/grit/auxiliary/like_threshold.rs new file mode 100644 index 00000000000..b55b9016092 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/like_threshold.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritLikeThreshold; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritLikeThreshold; +impl FormatNodeRule for FormatGritLikeThreshold { + fn fmt_fields(&self, node: &GritLikeThreshold, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/list_accessor.rs b/crates/biome_grit_formatter/src/grit/auxiliary/list_accessor.rs new file mode 100644 index 00000000000..5a0df449aa0 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/list_accessor.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritListAccessor; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritListAccessor; +impl FormatNodeRule for FormatGritListAccessor { + fn fmt_fields(&self, node: &GritListAccessor, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/map.rs b/crates/biome_grit_formatter/src/grit/auxiliary/map.rs new file mode 100644 index 00000000000..6b311f9303e --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/map.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritMap; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritMap; +impl FormatNodeRule for FormatGritMap { + fn fmt_fields(&self, node: &GritMap, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/map_accessor.rs b/crates/biome_grit_formatter/src/grit/auxiliary/map_accessor.rs new file mode 100644 index 00000000000..781ed09712c --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/map_accessor.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritMapAccessor; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritMapAccessor; +impl FormatNodeRule for FormatGritMapAccessor { + fn fmt_fields(&self, node: &GritMapAccessor, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/map_element.rs b/crates/biome_grit_formatter/src/grit/auxiliary/map_element.rs new file mode 100644 index 00000000000..2b374998473 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/map_element.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritMapElement; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritMapElement; +impl FormatNodeRule for FormatGritMapElement { + fn fmt_fields(&self, node: &GritMapElement, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/mod.rs b/crates/biome_grit_formatter/src/grit/auxiliary/mod.rs new file mode 100644 index 00000000000..a64427a65e6 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/mod.rs @@ -0,0 +1,82 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +pub(crate) mod add_operation; +pub(crate) mod annotation; +pub(crate) mod assignment_as_pattern; +pub(crate) mod bubble; +pub(crate) mod bubble_scope; +pub(crate) mod code_snippet; +pub(crate) mod div_operation; +pub(crate) mod dot; +pub(crate) mod dotdotdot; +pub(crate) mod every; +pub(crate) mod files; +pub(crate) mod function_definition; +pub(crate) mod language_declaration; +pub(crate) mod language_flavor; +pub(crate) mod language_flavor_kind; +pub(crate) mod language_name; +pub(crate) mod language_specific_snippet; +pub(crate) mod like; +pub(crate) mod like_threshold; +pub(crate) mod list_accessor; +pub(crate) mod map; +pub(crate) mod map_accessor; +pub(crate) mod map_element; +pub(crate) mod mod_operation; +pub(crate) mod mul_operation; +pub(crate) mod name; +pub(crate) mod named_arg; +pub(crate) mod named_arg_with_default; +pub(crate) mod node_like; +pub(crate) mod not; +pub(crate) mod pattern_accumulate; +pub(crate) mod pattern_after; +pub(crate) mod pattern_and; +pub(crate) mod pattern_any; +pub(crate) mod pattern_as; +pub(crate) mod pattern_before; +pub(crate) mod pattern_contains; +pub(crate) mod pattern_contains_until_clause; +pub(crate) mod pattern_definition; +pub(crate) mod pattern_definition_body; +pub(crate) mod pattern_else_clause; +pub(crate) mod pattern_if_else; +pub(crate) mod pattern_includes; +pub(crate) mod pattern_limit; +pub(crate) mod pattern_maybe; +pub(crate) mod pattern_not; +pub(crate) mod pattern_or; +pub(crate) mod pattern_or_else; +pub(crate) mod pattern_where; +pub(crate) mod predicate_accumulate; +pub(crate) mod predicate_and; +pub(crate) mod predicate_any; +pub(crate) mod predicate_assignment; +pub(crate) mod predicate_call; +pub(crate) mod predicate_definition; +pub(crate) mod predicate_else_clause; +pub(crate) mod predicate_equal; +pub(crate) mod predicate_greater; +pub(crate) mod predicate_greater_equal; +pub(crate) mod predicate_if_else; +pub(crate) mod predicate_less; +pub(crate) mod predicate_less_equal; +pub(crate) mod predicate_match; +pub(crate) mod predicate_maybe; +pub(crate) mod predicate_not; +pub(crate) mod predicate_not_equal; +pub(crate) mod predicate_or; +pub(crate) mod predicate_return; +pub(crate) mod predicate_rewrite; +pub(crate) mod regex_pattern; +pub(crate) mod regex_pattern_variables; +pub(crate) mod rewrite; +pub(crate) mod root; +pub(crate) mod sequential; +pub(crate) mod some; +pub(crate) mod sub_operation; +pub(crate) mod underscore; +pub(crate) mod variable; +pub(crate) mod version; +pub(crate) mod within; diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/mod_operation.rs b/crates/biome_grit_formatter/src/grit/auxiliary/mod_operation.rs new file mode 100644 index 00000000000..6d0d55c053e --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/mod_operation.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritModOperation; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritModOperation; +impl FormatNodeRule for FormatGritModOperation { + fn fmt_fields(&self, node: &GritModOperation, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/mul_operation.rs b/crates/biome_grit_formatter/src/grit/auxiliary/mul_operation.rs new file mode 100644 index 00000000000..e88079f187d --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/mul_operation.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritMulOperation; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritMulOperation; +impl FormatNodeRule for FormatGritMulOperation { + fn fmt_fields(&self, node: &GritMulOperation, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/name.rs b/crates/biome_grit_formatter/src/grit/auxiliary/name.rs new file mode 100644 index 00000000000..c8a168e32ce --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/name.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritName; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritName; +impl FormatNodeRule for FormatGritName { + fn fmt_fields(&self, node: &GritName, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/named_arg.rs b/crates/biome_grit_formatter/src/grit/auxiliary/named_arg.rs new file mode 100644 index 00000000000..5fe069d9fc4 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/named_arg.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritNamedArg; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritNamedArg; +impl FormatNodeRule for FormatGritNamedArg { + fn fmt_fields(&self, node: &GritNamedArg, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/named_arg_with_default.rs b/crates/biome_grit_formatter/src/grit/auxiliary/named_arg_with_default.rs new file mode 100644 index 00000000000..82bf0eae9a7 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/named_arg_with_default.rs @@ -0,0 +1,14 @@ +use crate::prelude::*; +use biome_grit_syntax::GritNamedArgWithDefault; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritNamedArgWithDefault; +impl FormatNodeRule for FormatGritNamedArgWithDefault { + fn fmt_fields( + &self, + node: &GritNamedArgWithDefault, + f: &mut GritFormatter, + ) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/node_like.rs b/crates/biome_grit_formatter/src/grit/auxiliary/node_like.rs new file mode 100644 index 00000000000..8869a1f60ce --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/node_like.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritNodeLike; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritNodeLike; +impl FormatNodeRule for FormatGritNodeLike { + fn fmt_fields(&self, node: &GritNodeLike, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/not.rs b/crates/biome_grit_formatter/src/grit/auxiliary/not.rs new file mode 100644 index 00000000000..6c0d4ac58e0 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/not.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritNot; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritNot; +impl FormatNodeRule for FormatGritNot { + fn fmt_fields(&self, node: &GritNot, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/pattern_accumulate.rs b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_accumulate.rs new file mode 100644 index 00000000000..bc08abc6620 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_accumulate.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPatternAccumulate; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPatternAccumulate; +impl FormatNodeRule for FormatGritPatternAccumulate { + fn fmt_fields(&self, node: &GritPatternAccumulate, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/pattern_after.rs b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_after.rs new file mode 100644 index 00000000000..271f565d376 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_after.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPatternAfter; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPatternAfter; +impl FormatNodeRule for FormatGritPatternAfter { + fn fmt_fields(&self, node: &GritPatternAfter, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/pattern_and.rs b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_and.rs new file mode 100644 index 00000000000..eb40ca5bc45 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_and.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPatternAnd; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPatternAnd; +impl FormatNodeRule for FormatGritPatternAnd { + fn fmt_fields(&self, node: &GritPatternAnd, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/pattern_any.rs b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_any.rs new file mode 100644 index 00000000000..f1014b3905c --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_any.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPatternAny; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPatternAny; +impl FormatNodeRule for FormatGritPatternAny { + fn fmt_fields(&self, node: &GritPatternAny, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/pattern_as.rs b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_as.rs new file mode 100644 index 00000000000..b92b13cce92 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_as.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPatternAs; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPatternAs; +impl FormatNodeRule for FormatGritPatternAs { + fn fmt_fields(&self, node: &GritPatternAs, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/pattern_before.rs b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_before.rs new file mode 100644 index 00000000000..f52af58a7df --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_before.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPatternBefore; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPatternBefore; +impl FormatNodeRule for FormatGritPatternBefore { + fn fmt_fields(&self, node: &GritPatternBefore, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/pattern_contains.rs b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_contains.rs new file mode 100644 index 00000000000..a497b6712ae --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_contains.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPatternContains; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPatternContains; +impl FormatNodeRule for FormatGritPatternContains { + fn fmt_fields(&self, node: &GritPatternContains, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/pattern_contains_until_clause.rs b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_contains_until_clause.rs new file mode 100644 index 00000000000..53f1f98cac2 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_contains_until_clause.rs @@ -0,0 +1,14 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPatternContainsUntilClause; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPatternContainsUntilClause; +impl FormatNodeRule for FormatGritPatternContainsUntilClause { + fn fmt_fields( + &self, + node: &GritPatternContainsUntilClause, + f: &mut GritFormatter, + ) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/pattern_definition.rs b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_definition.rs new file mode 100644 index 00000000000..9d893b5236f --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_definition.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPatternDefinition; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPatternDefinition; +impl FormatNodeRule for FormatGritPatternDefinition { + fn fmt_fields(&self, node: &GritPatternDefinition, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/pattern_definition_body.rs b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_definition_body.rs new file mode 100644 index 00000000000..7f7ef6a039a --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_definition_body.rs @@ -0,0 +1,14 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPatternDefinitionBody; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPatternDefinitionBody; +impl FormatNodeRule for FormatGritPatternDefinitionBody { + fn fmt_fields( + &self, + node: &GritPatternDefinitionBody, + f: &mut GritFormatter, + ) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/pattern_else_clause.rs b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_else_clause.rs new file mode 100644 index 00000000000..89b46cb100a --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_else_clause.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPatternElseClause; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPatternElseClause; +impl FormatNodeRule for FormatGritPatternElseClause { + fn fmt_fields(&self, node: &GritPatternElseClause, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/pattern_if_else.rs b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_if_else.rs new file mode 100644 index 00000000000..abaabd20812 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_if_else.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPatternIfElse; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPatternIfElse; +impl FormatNodeRule for FormatGritPatternIfElse { + fn fmt_fields(&self, node: &GritPatternIfElse, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/pattern_includes.rs b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_includes.rs new file mode 100644 index 00000000000..ff9762ba83a --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_includes.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPatternIncludes; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPatternIncludes; +impl FormatNodeRule for FormatGritPatternIncludes { + fn fmt_fields(&self, node: &GritPatternIncludes, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/pattern_limit.rs b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_limit.rs new file mode 100644 index 00000000000..ed1a4d8de56 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_limit.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPatternLimit; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPatternLimit; +impl FormatNodeRule for FormatGritPatternLimit { + fn fmt_fields(&self, node: &GritPatternLimit, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/pattern_maybe.rs b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_maybe.rs new file mode 100644 index 00000000000..39cd74f5b90 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_maybe.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPatternMaybe; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPatternMaybe; +impl FormatNodeRule for FormatGritPatternMaybe { + fn fmt_fields(&self, node: &GritPatternMaybe, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/pattern_not.rs b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_not.rs new file mode 100644 index 00000000000..1c2a0571396 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_not.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPatternNot; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPatternNot; +impl FormatNodeRule for FormatGritPatternNot { + fn fmt_fields(&self, node: &GritPatternNot, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/pattern_or.rs b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_or.rs new file mode 100644 index 00000000000..5df18456c96 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_or.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPatternOr; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPatternOr; +impl FormatNodeRule for FormatGritPatternOr { + fn fmt_fields(&self, node: &GritPatternOr, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/pattern_or_else.rs b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_or_else.rs new file mode 100644 index 00000000000..6953cdfe550 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_or_else.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPatternOrElse; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPatternOrElse; +impl FormatNodeRule for FormatGritPatternOrElse { + fn fmt_fields(&self, node: &GritPatternOrElse, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/pattern_where.rs b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_where.rs new file mode 100644 index 00000000000..bbdfa34e0ae --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/pattern_where.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPatternWhere; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPatternWhere; +impl FormatNodeRule for FormatGritPatternWhere { + fn fmt_fields(&self, node: &GritPatternWhere, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/predicate_accumulate.rs b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_accumulate.rs new file mode 100644 index 00000000000..3449decbdf5 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_accumulate.rs @@ -0,0 +1,14 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPredicateAccumulate; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPredicateAccumulate; +impl FormatNodeRule for FormatGritPredicateAccumulate { + fn fmt_fields( + &self, + node: &GritPredicateAccumulate, + f: &mut GritFormatter, + ) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/predicate_and.rs b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_and.rs new file mode 100644 index 00000000000..d48416ef152 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_and.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPredicateAnd; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPredicateAnd; +impl FormatNodeRule for FormatGritPredicateAnd { + fn fmt_fields(&self, node: &GritPredicateAnd, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/predicate_any.rs b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_any.rs new file mode 100644 index 00000000000..fe958f14145 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_any.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPredicateAny; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPredicateAny; +impl FormatNodeRule for FormatGritPredicateAny { + fn fmt_fields(&self, node: &GritPredicateAny, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/predicate_assignment.rs b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_assignment.rs new file mode 100644 index 00000000000..8c23c6f779b --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_assignment.rs @@ -0,0 +1,14 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPredicateAssignment; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPredicateAssignment; +impl FormatNodeRule for FormatGritPredicateAssignment { + fn fmt_fields( + &self, + node: &GritPredicateAssignment, + f: &mut GritFormatter, + ) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/predicate_call.rs b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_call.rs new file mode 100644 index 00000000000..ab68963aa42 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_call.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPredicateCall; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPredicateCall; +impl FormatNodeRule for FormatGritPredicateCall { + fn fmt_fields(&self, node: &GritPredicateCall, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/predicate_definition.rs b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_definition.rs new file mode 100644 index 00000000000..3f4aa712a88 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_definition.rs @@ -0,0 +1,14 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPredicateDefinition; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPredicateDefinition; +impl FormatNodeRule for FormatGritPredicateDefinition { + fn fmt_fields( + &self, + node: &GritPredicateDefinition, + f: &mut GritFormatter, + ) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/predicate_else_clause.rs b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_else_clause.rs new file mode 100644 index 00000000000..8fa86cb3d49 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_else_clause.rs @@ -0,0 +1,14 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPredicateElseClause; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPredicateElseClause; +impl FormatNodeRule for FormatGritPredicateElseClause { + fn fmt_fields( + &self, + node: &GritPredicateElseClause, + f: &mut GritFormatter, + ) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/predicate_equal.rs b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_equal.rs new file mode 100644 index 00000000000..e890306ecf8 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_equal.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPredicateEqual; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPredicateEqual; +impl FormatNodeRule for FormatGritPredicateEqual { + fn fmt_fields(&self, node: &GritPredicateEqual, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/predicate_greater.rs b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_greater.rs new file mode 100644 index 00000000000..42ea64490fb --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_greater.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPredicateGreater; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPredicateGreater; +impl FormatNodeRule for FormatGritPredicateGreater { + fn fmt_fields(&self, node: &GritPredicateGreater, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/predicate_greater_equal.rs b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_greater_equal.rs new file mode 100644 index 00000000000..9e522b07daa --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_greater_equal.rs @@ -0,0 +1,14 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPredicateGreaterEqual; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPredicateGreaterEqual; +impl FormatNodeRule for FormatGritPredicateGreaterEqual { + fn fmt_fields( + &self, + node: &GritPredicateGreaterEqual, + f: &mut GritFormatter, + ) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/predicate_if_else.rs b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_if_else.rs new file mode 100644 index 00000000000..6488b650584 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_if_else.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPredicateIfElse; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPredicateIfElse; +impl FormatNodeRule for FormatGritPredicateIfElse { + fn fmt_fields(&self, node: &GritPredicateIfElse, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/predicate_less.rs b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_less.rs new file mode 100644 index 00000000000..480d8b99403 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_less.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPredicateLess; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPredicateLess; +impl FormatNodeRule for FormatGritPredicateLess { + fn fmt_fields(&self, node: &GritPredicateLess, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/predicate_less_equal.rs b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_less_equal.rs new file mode 100644 index 00000000000..334d06775d6 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_less_equal.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPredicateLessEqual; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPredicateLessEqual; +impl FormatNodeRule for FormatGritPredicateLessEqual { + fn fmt_fields(&self, node: &GritPredicateLessEqual, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/predicate_match.rs b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_match.rs new file mode 100644 index 00000000000..d4fc199209d --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_match.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPredicateMatch; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPredicateMatch; +impl FormatNodeRule for FormatGritPredicateMatch { + fn fmt_fields(&self, node: &GritPredicateMatch, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/predicate_maybe.rs b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_maybe.rs new file mode 100644 index 00000000000..bb8beb4b4ef --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_maybe.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPredicateMaybe; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPredicateMaybe; +impl FormatNodeRule for FormatGritPredicateMaybe { + fn fmt_fields(&self, node: &GritPredicateMaybe, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/predicate_not.rs b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_not.rs new file mode 100644 index 00000000000..2f8be0c994d --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_not.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPredicateNot; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPredicateNot; +impl FormatNodeRule for FormatGritPredicateNot { + fn fmt_fields(&self, node: &GritPredicateNot, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/predicate_not_equal.rs b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_not_equal.rs new file mode 100644 index 00000000000..e5c1fec5972 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_not_equal.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPredicateNotEqual; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPredicateNotEqual; +impl FormatNodeRule for FormatGritPredicateNotEqual { + fn fmt_fields(&self, node: &GritPredicateNotEqual, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/predicate_or.rs b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_or.rs new file mode 100644 index 00000000000..b1cfd14407e --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_or.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPredicateOr; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPredicateOr; +impl FormatNodeRule for FormatGritPredicateOr { + fn fmt_fields(&self, node: &GritPredicateOr, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/predicate_return.rs b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_return.rs new file mode 100644 index 00000000000..8780ce0313c --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_return.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPredicateReturn; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPredicateReturn; +impl FormatNodeRule for FormatGritPredicateReturn { + fn fmt_fields(&self, node: &GritPredicateReturn, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/predicate_rewrite.rs b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_rewrite.rs new file mode 100644 index 00000000000..b4c682600b9 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/predicate_rewrite.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPredicateRewrite; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPredicateRewrite; +impl FormatNodeRule for FormatGritPredicateRewrite { + fn fmt_fields(&self, node: &GritPredicateRewrite, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/regex_pattern.rs b/crates/biome_grit_formatter/src/grit/auxiliary/regex_pattern.rs new file mode 100644 index 00000000000..c5845bb12ea --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/regex_pattern.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritRegexPattern; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritRegexPattern; +impl FormatNodeRule for FormatGritRegexPattern { + fn fmt_fields(&self, node: &GritRegexPattern, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/regex_pattern_variables.rs b/crates/biome_grit_formatter/src/grit/auxiliary/regex_pattern_variables.rs new file mode 100644 index 00000000000..a850bb0470f --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/regex_pattern_variables.rs @@ -0,0 +1,14 @@ +use crate::prelude::*; +use biome_grit_syntax::GritRegexPatternVariables; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritRegexPatternVariables; +impl FormatNodeRule for FormatGritRegexPatternVariables { + fn fmt_fields( + &self, + node: &GritRegexPatternVariables, + f: &mut GritFormatter, + ) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/rewrite.rs b/crates/biome_grit_formatter/src/grit/auxiliary/rewrite.rs new file mode 100644 index 00000000000..a8df7af71a9 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/rewrite.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritRewrite; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritRewrite; +impl FormatNodeRule for FormatGritRewrite { + fn fmt_fields(&self, node: &GritRewrite, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/root.rs b/crates/biome_grit_formatter/src/grit/auxiliary/root.rs new file mode 100644 index 00000000000..cbcded68cb4 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/root.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritRoot; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritRoot; +impl FormatNodeRule for FormatGritRoot { + fn fmt_fields(&self, node: &GritRoot, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/sequential.rs b/crates/biome_grit_formatter/src/grit/auxiliary/sequential.rs new file mode 100644 index 00000000000..fd7152a66fb --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/sequential.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritSequential; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritSequential; +impl FormatNodeRule for FormatGritSequential { + fn fmt_fields(&self, node: &GritSequential, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/some.rs b/crates/biome_grit_formatter/src/grit/auxiliary/some.rs new file mode 100644 index 00000000000..556d3e225cf --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/some.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritSome; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritSome; +impl FormatNodeRule for FormatGritSome { + fn fmt_fields(&self, node: &GritSome, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/sub_operation.rs b/crates/biome_grit_formatter/src/grit/auxiliary/sub_operation.rs new file mode 100644 index 00000000000..92c3206cdc2 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/sub_operation.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritSubOperation; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritSubOperation; +impl FormatNodeRule for FormatGritSubOperation { + fn fmt_fields(&self, node: &GritSubOperation, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/underscore.rs b/crates/biome_grit_formatter/src/grit/auxiliary/underscore.rs new file mode 100644 index 00000000000..af433c860c7 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/underscore.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritUnderscore; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritUnderscore; +impl FormatNodeRule for FormatGritUnderscore { + fn fmt_fields(&self, node: &GritUnderscore, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/variable.rs b/crates/biome_grit_formatter/src/grit/auxiliary/variable.rs new file mode 100644 index 00000000000..efc5fd995f3 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/variable.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritVariable; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritVariable; +impl FormatNodeRule for FormatGritVariable { + fn fmt_fields(&self, node: &GritVariable, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/version.rs b/crates/biome_grit_formatter/src/grit/auxiliary/version.rs new file mode 100644 index 00000000000..ac956e35281 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/version.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritVersion; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritVersion; +impl FormatNodeRule for FormatGritVersion { + fn fmt_fields(&self, node: &GritVersion, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/auxiliary/within.rs b/crates/biome_grit_formatter/src/grit/auxiliary/within.rs new file mode 100644 index 00000000000..edc63b832e3 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/auxiliary/within.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritWithin; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritWithin; +impl FormatNodeRule for FormatGritWithin { + fn fmt_fields(&self, node: &GritWithin, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/bogus/bogus.rs b/crates/biome_grit_formatter/src/grit/bogus/bogus.rs new file mode 100644 index 00000000000..378918095a9 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/bogus/bogus.rs @@ -0,0 +1,5 @@ +use crate::FormatBogusNodeRule; +use biome_grit_syntax::GritBogus; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritBogus; +impl FormatBogusNodeRule for FormatGritBogus {} diff --git a/crates/biome_grit_formatter/src/grit/bogus/bogus_definition.rs b/crates/biome_grit_formatter/src/grit/bogus/bogus_definition.rs new file mode 100644 index 00000000000..062a7826491 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/bogus/bogus_definition.rs @@ -0,0 +1,5 @@ +use crate::FormatBogusNodeRule; +use biome_grit_syntax::GritBogusDefinition; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritBogusDefinition; +impl FormatBogusNodeRule for FormatGritBogusDefinition {} diff --git a/crates/biome_grit_formatter/src/grit/bogus/bogus_literal.rs b/crates/biome_grit_formatter/src/grit/bogus/bogus_literal.rs new file mode 100644 index 00000000000..993de53f0f8 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/bogus/bogus_literal.rs @@ -0,0 +1,5 @@ +use crate::FormatBogusNodeRule; +use biome_grit_syntax::GritBogusLiteral; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritBogusLiteral; +impl FormatBogusNodeRule for FormatGritBogusLiteral {} diff --git a/crates/biome_grit_formatter/src/grit/bogus/bogus_named_arg.rs b/crates/biome_grit_formatter/src/grit/bogus/bogus_named_arg.rs new file mode 100644 index 00000000000..47647eab61b --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/bogus/bogus_named_arg.rs @@ -0,0 +1,5 @@ +use crate::FormatBogusNodeRule; +use biome_grit_syntax::GritBogusNamedArg; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritBogusNamedArg; +impl FormatBogusNodeRule for FormatGritBogusNamedArg {} diff --git a/crates/biome_grit_formatter/src/grit/bogus/bogus_pattern.rs b/crates/biome_grit_formatter/src/grit/bogus/bogus_pattern.rs new file mode 100644 index 00000000000..3c72fd7ecca --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/bogus/bogus_pattern.rs @@ -0,0 +1,5 @@ +use crate::FormatBogusNodeRule; +use biome_grit_syntax::GritBogusPattern; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritBogusPattern; +impl FormatBogusNodeRule for FormatGritBogusPattern {} diff --git a/crates/biome_grit_formatter/src/grit/bogus/bogus_predicate.rs b/crates/biome_grit_formatter/src/grit/bogus/bogus_predicate.rs new file mode 100644 index 00000000000..8788a060ede --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/bogus/bogus_predicate.rs @@ -0,0 +1,5 @@ +use crate::FormatBogusNodeRule; +use biome_grit_syntax::GritBogusPredicate; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritBogusPredicate; +impl FormatBogusNodeRule for FormatGritBogusPredicate {} diff --git a/crates/biome_grit_formatter/src/grit/bogus/mod.rs b/crates/biome_grit_formatter/src/grit/bogus/mod.rs new file mode 100644 index 00000000000..501fc8accf9 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/bogus/mod.rs @@ -0,0 +1,9 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +#[allow(clippy::module_inception)] +pub(crate) mod bogus; +pub(crate) mod bogus_definition; +pub(crate) mod bogus_literal; +pub(crate) mod bogus_named_arg; +pub(crate) mod bogus_pattern; +pub(crate) mod bogus_predicate; diff --git a/crates/biome_grit_formatter/src/grit/lists/curly_predicate_list.rs b/crates/biome_grit_formatter/src/grit/lists/curly_predicate_list.rs new file mode 100644 index 00000000000..87720797fd5 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/lists/curly_predicate_list.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritCurlyPredicateList; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritCurlyPredicateList; +impl FormatNodeRule for FormatGritCurlyPredicateList { + fn fmt_fields(&self, node: &GritCurlyPredicateList, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/lists/definition_list.rs b/crates/biome_grit_formatter/src/grit/lists/definition_list.rs new file mode 100644 index 00000000000..78a127a982c --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/lists/definition_list.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritDefinitionList; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritDefinitionList; +impl FormatRule for FormatGritDefinitionList { + type Context = GritFormatContext; + fn fmt(&self, node: &GritDefinitionList, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/lists/language_flavor_list.rs b/crates/biome_grit_formatter/src/grit/lists/language_flavor_list.rs new file mode 100644 index 00000000000..08a09f6a353 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/lists/language_flavor_list.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritLanguageFlavorList; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritLanguageFlavorList; +impl FormatRule for FormatGritLanguageFlavorList { + type Context = GritFormatContext; + fn fmt(&self, node: &GritLanguageFlavorList, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/lists/list.rs b/crates/biome_grit_formatter/src/grit/lists/list.rs new file mode 100644 index 00000000000..368924c142a --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/lists/list.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritList; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritList; +impl FormatNodeRule for FormatGritList { + fn fmt_fields(&self, node: &GritList, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/lists/list_pattern_list.rs b/crates/biome_grit_formatter/src/grit/lists/list_pattern_list.rs new file mode 100644 index 00000000000..1ba7b069311 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/lists/list_pattern_list.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritListPatternList; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritListPatternList; +impl FormatRule for FormatGritListPatternList { + type Context = GritFormatContext; + fn fmt(&self, node: &GritListPatternList, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/lists/map_element_list.rs b/crates/biome_grit_formatter/src/grit/lists/map_element_list.rs new file mode 100644 index 00000000000..f86773e7bfd --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/lists/map_element_list.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritMapElementList; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritMapElementList; +impl FormatRule for FormatGritMapElementList { + type Context = GritFormatContext; + fn fmt(&self, node: &GritMapElementList, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/lists/mod.rs b/crates/biome_grit_formatter/src/grit/lists/mod.rs new file mode 100644 index 00000000000..89b64f0f10e --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/lists/mod.rs @@ -0,0 +1,13 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +pub(crate) mod curly_predicate_list; +pub(crate) mod definition_list; +pub(crate) mod language_flavor_list; +pub(crate) mod list; +pub(crate) mod list_pattern_list; +pub(crate) mod map_element_list; +pub(crate) mod named_arg_list; +pub(crate) mod pattern_arg_list; +pub(crate) mod pattern_list; +pub(crate) mod predicate_list; +pub(crate) mod variable_list; diff --git a/crates/biome_grit_formatter/src/grit/lists/named_arg_list.rs b/crates/biome_grit_formatter/src/grit/lists/named_arg_list.rs new file mode 100644 index 00000000000..014ecd30eba --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/lists/named_arg_list.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritNamedArgList; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritNamedArgList; +impl FormatRule for FormatGritNamedArgList { + type Context = GritFormatContext; + fn fmt(&self, node: &GritNamedArgList, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/lists/pattern_arg_list.rs b/crates/biome_grit_formatter/src/grit/lists/pattern_arg_list.rs new file mode 100644 index 00000000000..e15e8ccf23c --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/lists/pattern_arg_list.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPatternArgList; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPatternArgList; +impl FormatNodeRule for FormatGritPatternArgList { + fn fmt_fields(&self, node: &GritPatternArgList, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/lists/pattern_list.rs b/crates/biome_grit_formatter/src/grit/lists/pattern_list.rs new file mode 100644 index 00000000000..d9bc8cd6ae7 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/lists/pattern_list.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPatternList; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPatternList; +impl FormatRule for FormatGritPatternList { + type Context = GritFormatContext; + fn fmt(&self, node: &GritPatternList, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/lists/predicate_list.rs b/crates/biome_grit_formatter/src/grit/lists/predicate_list.rs new file mode 100644 index 00000000000..0a93e84841e --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/lists/predicate_list.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritPredicateList; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritPredicateList; +impl FormatRule for FormatGritPredicateList { + type Context = GritFormatContext; + fn fmt(&self, node: &GritPredicateList, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/lists/variable_list.rs b/crates/biome_grit_formatter/src/grit/lists/variable_list.rs new file mode 100644 index 00000000000..1d782f3ce3c --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/lists/variable_list.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritVariableList; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritVariableList; +impl FormatRule for FormatGritVariableList { + type Context = GritFormatContext; + fn fmt(&self, node: &GritVariableList, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/mod.rs b/crates/biome_grit_formatter/src/grit/mod.rs new file mode 100644 index 00000000000..f9caa8bedcd --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/mod.rs @@ -0,0 +1,7 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +pub(crate) mod any; +pub(crate) mod auxiliary; +pub(crate) mod bogus; +pub(crate) mod lists; +pub(crate) mod value; diff --git a/crates/biome_grit_formatter/src/grit/value/backtick_snippet_literal.rs b/crates/biome_grit_formatter/src/grit/value/backtick_snippet_literal.rs new file mode 100644 index 00000000000..bdb8caca1b6 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/value/backtick_snippet_literal.rs @@ -0,0 +1,14 @@ +use crate::prelude::*; +use biome_grit_syntax::GritBacktickSnippetLiteral; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritBacktickSnippetLiteral; +impl FormatNodeRule for FormatGritBacktickSnippetLiteral { + fn fmt_fields( + &self, + node: &GritBacktickSnippetLiteral, + f: &mut GritFormatter, + ) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/value/boolean_literal.rs b/crates/biome_grit_formatter/src/grit/value/boolean_literal.rs new file mode 100644 index 00000000000..e17bd51ddf2 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/value/boolean_literal.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritBooleanLiteral; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritBooleanLiteral; +impl FormatNodeRule for FormatGritBooleanLiteral { + fn fmt_fields(&self, node: &GritBooleanLiteral, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/value/double_literal.rs b/crates/biome_grit_formatter/src/grit/value/double_literal.rs new file mode 100644 index 00000000000..c8ea2905b22 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/value/double_literal.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritDoubleLiteral; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritDoubleLiteral; +impl FormatNodeRule for FormatGritDoubleLiteral { + fn fmt_fields(&self, node: &GritDoubleLiteral, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/value/int_literal.rs b/crates/biome_grit_formatter/src/grit/value/int_literal.rs new file mode 100644 index 00000000000..523db1268d0 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/value/int_literal.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritIntLiteral; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritIntLiteral; +impl FormatNodeRule for FormatGritIntLiteral { + fn fmt_fields(&self, node: &GritIntLiteral, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/value/mod.rs b/crates/biome_grit_formatter/src/grit/value/mod.rs new file mode 100644 index 00000000000..a841c234ffc --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/value/mod.rs @@ -0,0 +1,12 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +pub(crate) mod backtick_snippet_literal; +pub(crate) mod boolean_literal; +pub(crate) mod double_literal; +pub(crate) mod int_literal; +pub(crate) mod negative_int_literal; +pub(crate) mod raw_backtick_snippet_literal; +pub(crate) mod regex_literal; +pub(crate) mod snippet_regex_literal; +pub(crate) mod string_literal; +pub(crate) mod undefined_literal; diff --git a/crates/biome_grit_formatter/src/grit/value/negative_int_literal.rs b/crates/biome_grit_formatter/src/grit/value/negative_int_literal.rs new file mode 100644 index 00000000000..82e92cd7e85 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/value/negative_int_literal.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritNegativeIntLiteral; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritNegativeIntLiteral; +impl FormatNodeRule for FormatGritNegativeIntLiteral { + fn fmt_fields(&self, node: &GritNegativeIntLiteral, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/value/raw_backtick_snippet_literal.rs b/crates/biome_grit_formatter/src/grit/value/raw_backtick_snippet_literal.rs new file mode 100644 index 00000000000..e762178cd21 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/value/raw_backtick_snippet_literal.rs @@ -0,0 +1,14 @@ +use crate::prelude::*; +use biome_grit_syntax::GritRawBacktickSnippetLiteral; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritRawBacktickSnippetLiteral; +impl FormatNodeRule for FormatGritRawBacktickSnippetLiteral { + fn fmt_fields( + &self, + node: &GritRawBacktickSnippetLiteral, + f: &mut GritFormatter, + ) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/value/regex_literal.rs b/crates/biome_grit_formatter/src/grit/value/regex_literal.rs new file mode 100644 index 00000000000..c0948163aff --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/value/regex_literal.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritRegexLiteral; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritRegexLiteral; +impl FormatNodeRule for FormatGritRegexLiteral { + fn fmt_fields(&self, node: &GritRegexLiteral, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/value/snippet_regex_literal.rs b/crates/biome_grit_formatter/src/grit/value/snippet_regex_literal.rs new file mode 100644 index 00000000000..1079ea8541a --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/value/snippet_regex_literal.rs @@ -0,0 +1,14 @@ +use crate::prelude::*; +use biome_grit_syntax::GritSnippetRegexLiteral; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritSnippetRegexLiteral; +impl FormatNodeRule for FormatGritSnippetRegexLiteral { + fn fmt_fields( + &self, + node: &GritSnippetRegexLiteral, + f: &mut GritFormatter, + ) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/value/string_literal.rs b/crates/biome_grit_formatter/src/grit/value/string_literal.rs new file mode 100644 index 00000000000..36cbe6bc906 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/value/string_literal.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritStringLiteral; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritStringLiteral; +impl FormatNodeRule for FormatGritStringLiteral { + fn fmt_fields(&self, node: &GritStringLiteral, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/grit/value/undefined_literal.rs b/crates/biome_grit_formatter/src/grit/value/undefined_literal.rs new file mode 100644 index 00000000000..e324434db21 --- /dev/null +++ b/crates/biome_grit_formatter/src/grit/value/undefined_literal.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::GritUndefinedLiteral; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGritUndefinedLiteral; +impl FormatNodeRule for FormatGritUndefinedLiteral { + fn fmt_fields(&self, node: &GritUndefinedLiteral, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/js/any/curly_grit_pattern.rs b/crates/biome_grit_formatter/src/js/any/curly_grit_pattern.rs new file mode 100644 index 00000000000..9dfd74db0bc --- /dev/null +++ b/crates/biome_grit_formatter/src/js/any/curly_grit_pattern.rs @@ -0,0 +1,15 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +use crate::prelude::*; +use biome_grit_syntax::MaybeCurlyGritPattern; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatMaybeCurlyGritPattern; +impl FormatRule for FormatMaybeCurlyGritPattern { + type Context = GritFormatContext; + fn fmt(&self, node: &MaybeCurlyGritPattern, f: &mut GritFormatter) -> FormatResult<()> { + match node { + MaybeCurlyGritPattern::AnyGritPattern(node) => node.format().fmt(f), + MaybeCurlyGritPattern::CurlyGritPattern(node) => node.format().fmt(f), + } + } +} diff --git a/crates/biome_grit_formatter/src/js/any/mod.rs b/crates/biome_grit_formatter/src/js/any/mod.rs new file mode 100644 index 00000000000..048df033e59 --- /dev/null +++ b/crates/biome_grit_formatter/src/js/any/mod.rs @@ -0,0 +1,3 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +pub(crate) mod curly_grit_pattern; diff --git a/crates/biome_grit_formatter/src/js/expressions/grit_pattern.rs b/crates/biome_grit_formatter/src/js/expressions/grit_pattern.rs new file mode 100644 index 00000000000..d350764a92a --- /dev/null +++ b/crates/biome_grit_formatter/src/js/expressions/grit_pattern.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::BracketedGritPattern; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatBracketedGritPattern; +impl FormatNodeRule for FormatBracketedGritPattern { + fn fmt_fields(&self, node: &BracketedGritPattern, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/js/expressions/grit_predicate.rs b/crates/biome_grit_formatter/src/js/expressions/grit_predicate.rs new file mode 100644 index 00000000000..2e438b5d186 --- /dev/null +++ b/crates/biome_grit_formatter/src/js/expressions/grit_predicate.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; +use biome_grit_syntax::BracketedGritPredicate; +use biome_rowan::AstNode; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatBracketedGritPredicate; +impl FormatNodeRule for FormatBracketedGritPredicate { + fn fmt_fields(&self, node: &BracketedGritPredicate, f: &mut GritFormatter) -> FormatResult<()> { + format_verbatim_node(node.syntax()).fmt(f) + } +} diff --git a/crates/biome_grit_formatter/src/js/expressions/mod.rs b/crates/biome_grit_formatter/src/js/expressions/mod.rs new file mode 100644 index 00000000000..f26b5f07f8c --- /dev/null +++ b/crates/biome_grit_formatter/src/js/expressions/mod.rs @@ -0,0 +1,4 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +pub(crate) mod grit_pattern; +pub(crate) mod grit_predicate; diff --git a/crates/biome_grit_formatter/src/js/mod.rs b/crates/biome_grit_formatter/src/js/mod.rs new file mode 100644 index 00000000000..9e628107a07 --- /dev/null +++ b/crates/biome_grit_formatter/src/js/mod.rs @@ -0,0 +1,4 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +pub(crate) mod any; +pub(crate) mod expressions; diff --git a/xtask/codegen/src/formatter.rs b/xtask/codegen/src/formatter.rs index c8dee1b9e29..f2144a8fd79 100644 --- a/xtask/codegen/src/formatter.rs +++ b/xtask/codegen/src/formatter.rs @@ -558,6 +558,7 @@ enum NodeDialect { Jsx, Json, Css, + Grit, } impl NodeDialect { @@ -568,6 +569,7 @@ impl NodeDialect { NodeDialect::Jsx, NodeDialect::Json, NodeDialect::Css, + NodeDialect::Grit, ] } @@ -582,6 +584,7 @@ impl NodeDialect { NodeDialect::Jsx => "jsx", NodeDialect::Json => "json", NodeDialect::Css => "css", + NodeDialect::Grit => "grit", } } @@ -592,6 +595,7 @@ impl NodeDialect { "Ts" => NodeDialect::Ts, "Json" => NodeDialect::Json, "Css" => NodeDialect::Css, + "Grit" => NodeDialect::Grit, _ => { eprintln!("missing prefix {}", name); NodeDialect::Js @@ -784,6 +788,8 @@ fn get_node_concept( LanguageKind::Grit => match name { _ if name.starts_with("GritPattern") => NodeConcept::Expression, + _ if name.starts_with("GritPredicate") => NodeConcept::Expression, + "GritAssignmentAsPattern" | "GritPredicateAssignment" => NodeConcept::Assignment, _ if name.ends_with("BacktickSnippet") @@ -793,6 +799,8 @@ fn get_node_concept( NodeConcept::Value } + _ if name.ends_with("List") => NodeConcept::List, + _ => NodeConcept::Auxiliary, }, From 20f1672a179177565bf51b6a938827fcd3dcb44e Mon Sep 17 00:00:00 2001 From: "Arend van Beelen jr." Date: Tue, 27 Feb 2024 19:35:25 +0100 Subject: [PATCH 08/12] Implement GRIT_NODE_LIKE + improved error recovery --- .../src/generated/node_factory.rs | 54 ++- .../src/generated/syntax_factory.rs | 43 +-- crates/biome_grit_parser/src/parser/mod.rs | 85 +++-- .../src/parser/parse_error.rs | 23 ++ .../biome_grit_parser/src/parser/patterns.rs | 98 ++++- .../err/incorrect_engine.grit.snap | 28 +- .../err/invalid_language.grit.snap | 21 +- .../language_with_invalid_flavor.grit.snap | 42 ++- .../tests/grit_test_suite/ok/file_node.grit | 1 + .../grit_test_suite/ok/file_node.grit.snap | 90 +++++ .../grit_test_suite/ok/language.grit.snap | 4 +- .../ok/language_with_flavor.grit.snap | 6 +- .../ok/rewrite_in_where.grit.snap | 2 + .../biome_grit_syntax/src/generated/kind.rs | 2 - .../biome_grit_syntax/src/generated/macros.rs | 4 - .../biome_grit_syntax/src/generated/nodes.rs | 335 +++++++----------- .../src/generated/nodes_mut.rs | 22 +- crates/biome_grit_syntax/src/lib.rs | 2 +- xtask/codegen/gritql.ungram | 13 +- xtask/codegen/src/grit_kinds_src.rs | 2 - 20 files changed, 550 insertions(+), 327 deletions(-) create mode 100644 crates/biome_grit_parser/src/parser/parse_error.rs create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/file_node.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/file_node.grit.snap diff --git a/crates/biome_grit_factory/src/generated/node_factory.rs b/crates/biome_grit_factory/src/generated/node_factory.rs index f686db683da..ef63f85817f 100644 --- a/crates/biome_grit_factory/src/generated/node_factory.rs +++ b/crates/biome_grit_factory/src/generated/node_factory.rs @@ -338,6 +338,7 @@ pub fn grit_language_declaration( language_token, name, flavor: None, + grit_bogus: None, semicolon_token: None, } } @@ -345,6 +346,7 @@ pub struct GritLanguageDeclarationBuilder { language_token: SyntaxToken, name: GritLanguageName, flavor: Option, + grit_bogus: Option, semicolon_token: Option, } impl GritLanguageDeclarationBuilder { @@ -352,6 +354,10 @@ impl GritLanguageDeclarationBuilder { self.flavor = Some(flavor); self } + pub fn with_grit_bogus(mut self, grit_bogus: GritBogus) -> Self { + self.grit_bogus = Some(grit_bogus); + self + } pub fn with_semicolon_token(mut self, semicolon_token: SyntaxToken) -> Self { self.semicolon_token = Some(semicolon_token); self @@ -364,6 +370,8 @@ impl GritLanguageDeclarationBuilder { Some(SyntaxElement::Node(self.name.into_syntax())), self.flavor .map(|token| SyntaxElement::Node(token.into_syntax())), + self.grit_bogus + .map(|token| SyntaxElement::Node(token.into_syntax())), self.semicolon_token .map(|token| SyntaxElement::Token(token)), ], @@ -384,11 +392,31 @@ pub fn grit_language_flavor( ], )) } -pub fn grit_language_flavor_kind(flavor_kind_token: SyntaxToken) -> GritLanguageFlavorKind { - GritLanguageFlavorKind::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_LANGUAGE_FLAVOR_KIND, - [Some(SyntaxElement::Token(flavor_kind_token))], - )) +pub fn grit_language_flavor_kind(flavor_kind_token: SyntaxToken) -> GritLanguageFlavorKindBuilder { + GritLanguageFlavorKindBuilder { + flavor_kind_token, + grit_bogus: None, + } +} +pub struct GritLanguageFlavorKindBuilder { + flavor_kind_token: SyntaxToken, + grit_bogus: Option, +} +impl GritLanguageFlavorKindBuilder { + pub fn with_grit_bogus(mut self, grit_bogus: GritBogus) -> Self { + self.grit_bogus = Some(grit_bogus); + self + } + pub fn build(self) -> GritLanguageFlavorKind { + GritLanguageFlavorKind::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_LANGUAGE_FLAVOR_KIND, + [ + Some(SyntaxElement::Token(self.flavor_kind_token)), + self.grit_bogus + .map(|token| SyntaxElement::Node(token.into_syntax())), + ], + )) + } } pub fn grit_language_name(language_kind_token: SyntaxToken) -> GritLanguageName { GritLanguageName::unwrap_cast(SyntaxNode::new_detached( @@ -606,19 +634,13 @@ pub fn grit_name(grit_name_token: SyntaxToken) -> GritName { [Some(SyntaxElement::Token(grit_name_token))], )) } -pub fn grit_named_arg(name: GritName) -> GritNamedArg { - GritNamedArg::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_NAMED_ARG, - [Some(SyntaxElement::Node(name.into_syntax()))], - )) -} -pub fn grit_named_arg_with_default( +pub fn grit_named_arg( name: GritName, eq_token: SyntaxToken, pattern: AnyGritPattern, -) -> GritNamedArgWithDefault { - GritNamedArgWithDefault::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_NAMED_ARG_WITH_DEFAULT, +) -> GritNamedArg { + GritNamedArg::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_NAMED_ARG, [ Some(SyntaxElement::Node(name.into_syntax())), Some(SyntaxElement::Token(eq_token)), @@ -1915,7 +1937,7 @@ where } pub fn grit_named_arg_list(items: I, separators: S) -> GritNamedArgList where - I: IntoIterator, + I: IntoIterator, I::IntoIter: ExactSizeIterator, S: IntoIterator, S::IntoIter: ExactSizeIterator, diff --git a/crates/biome_grit_factory/src/generated/syntax_factory.rs b/crates/biome_grit_factory/src/generated/syntax_factory.rs index 1e4a1a2807f..8f8d8007832 100644 --- a/crates/biome_grit_factory/src/generated/syntax_factory.rs +++ b/crates/biome_grit_factory/src/generated/syntax_factory.rs @@ -602,7 +602,7 @@ impl SyntaxFactory for GritSyntaxFactory { } GRIT_LANGUAGE_DECLARATION => { let mut elements = (&children).into_iter(); - let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); + let mut slots: RawNodeSlots<5usize> = RawNodeSlots::default(); let mut current_element = elements.next(); if let Some(element) = ¤t_element { if element.kind() == T![language] { @@ -625,6 +625,13 @@ impl SyntaxFactory for GritSyntaxFactory { } } slots.next_slot(); + if let Some(element) = ¤t_element { + if GritBogus::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); if let Some(element) = ¤t_element { if element.kind() == T ! [;] { slots.mark_present(); @@ -675,7 +682,7 @@ impl SyntaxFactory for GritSyntaxFactory { } GRIT_LANGUAGE_FLAVOR_KIND => { let mut elements = (&children).into_iter(); - let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); let mut current_element = elements.next(); if let Some(element) = ¤t_element { if matches!(element.kind(), T![typescript] | T![jsx]) { @@ -684,6 +691,13 @@ impl SyntaxFactory for GritSyntaxFactory { } } slots.next_slot(); + if let Some(element) = ¤t_element { + if GritBogus::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( GRIT_LANGUAGE_FLAVOR_KIND.to_bogus(), @@ -1082,25 +1096,6 @@ impl SyntaxFactory for GritSyntaxFactory { slots.into_node(GRIT_NAME, children) } GRIT_NAMED_ARG => { - let mut elements = (&children).into_iter(); - let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); - let mut current_element = elements.next(); - if let Some(element) = ¤t_element { - if GritName::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if current_element.is_some() { - return RawSyntaxNode::new( - GRIT_NAMED_ARG.to_bogus(), - children.into_iter().map(Some), - ); - } - slots.into_node(GRIT_NAMED_ARG, children) - } - GRIT_NAMED_ARG_WITH_DEFAULT => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); let mut current_element = elements.next(); @@ -1127,11 +1122,11 @@ impl SyntaxFactory for GritSyntaxFactory { slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( - GRIT_NAMED_ARG_WITH_DEFAULT.to_bogus(), + GRIT_NAMED_ARG.to_bogus(), children.into_iter().map(Some), ); } - slots.into_node(GRIT_NAMED_ARG_WITH_DEFAULT, children) + slots.into_node(GRIT_NAMED_ARG, children) } GRIT_NEGATIVE_INT_LITERAL => { let mut elements = (&children).into_iter(); @@ -3101,7 +3096,7 @@ impl SyntaxFactory for GritSyntaxFactory { GRIT_NAMED_ARG_LIST => Self::make_separated_list_syntax( kind, children, - GritNamedArg::can_cast, + MaybeGritNamedArg::can_cast, T ! [,], true, ), diff --git a/crates/biome_grit_parser/src/parser/mod.rs b/crates/biome_grit_parser/src/parser/mod.rs index fdf98aabbae..6a1c0a5239a 100644 --- a/crates/biome_grit_parser/src/parser/mod.rs +++ b/crates/biome_grit_parser/src/parser/mod.rs @@ -1,4 +1,5 @@ mod literals; +mod parse_error; mod patterns; mod predicates; @@ -7,6 +8,7 @@ use biome_grit_syntax::GritSyntaxKind::{self, *}; use biome_grit_syntax::T; use biome_parser::diagnostic::merge_diagnostics; use biome_parser::event::Event; +use biome_parser::parse_recovery::ParseRecoveryTokenSet; use biome_parser::prelude::{ParsedSyntax::*, *}; use biome_parser::token_source::Trivia; use biome_parser::ParserContext; @@ -14,6 +16,12 @@ use biome_rowan::TextRange; use literals::parse_double_literal; use patterns::parse_pattern; +use self::parse_error::{expected_language_flavor, expected_language_name}; + +const LANGUAGE_NAME_RECOVERY_SET: TokenSet = token_set!(T!['('], T![;]); + +const LANGUAGE_FLAVOR_RECOVERY_SET: TokenSet = token_set!(T![')'], T![,], T![;]); + const SUPPORTED_LANGUAGE_SET: TokenSet = token_set![T![js], T![json], T![css], T![grit], T![html]]; @@ -126,16 +134,12 @@ fn parse_language(p: &mut GritParser) -> Option { let m = p.start(); p.bump(T![language]); - if p.at_ts(SUPPORTED_LANGUAGE_SET) { - let m = p.start(); - p.bump_ts(SUPPORTED_LANGUAGE_SET); - m.complete(p, GRIT_LANGUAGE_NAME); - } else { - p.error(p.err_builder( - "Expected a supported language; must be one of `js`, `json`, `css`, `html`, or `grit`", - p.cur_range(), - )) - } + let _ = parse_language_name(p).or_recover_with_token_set( + p, + &ParseRecoveryTokenSet::new(GRIT_BOGUS, LANGUAGE_NAME_RECOVERY_SET) + .enable_recovery_on_line_break(), + expected_language_name, + ); let _ = parse_language_flavor(p); @@ -146,6 +150,16 @@ fn parse_language(p: &mut GritParser) -> Option { Some(result) } +fn parse_language_name(p: &mut GritParser) -> ParsedSyntax { + if !p.at_ts(SUPPORTED_LANGUAGE_SET) { + return Absent; + } + + let m = p.start(); + p.bump_ts(SUPPORTED_LANGUAGE_SET); + Present(m.complete(p, GRIT_LANGUAGE_NAME)) +} + fn parse_language_flavor(p: &mut GritParser) -> ParsedSyntax { if !p.at(T!['(']) { return Absent; @@ -168,7 +182,12 @@ fn parse_language_flavor(p: &mut GritParser) -> ParsedSyntax { fn parse_language_flavor_list(p: &mut GritParser) -> ParsedSyntax { let m = p.start(); - let _ = parse_language_flavor_kind(p); + let _ = parse_language_flavor_kind(p).or_recover_with_token_set( + p, + &ParseRecoveryTokenSet::new(GRIT_BOGUS, LANGUAGE_FLAVOR_RECOVERY_SET) + .enable_recovery_on_line_break(), + expected_language_flavor, + ); while p.eat(T![,]) { let _ = parse_language_flavor_kind(p); @@ -178,19 +197,13 @@ fn parse_language_flavor_list(p: &mut GritParser) -> ParsedSyntax { } fn parse_language_flavor_kind(p: &mut GritParser) -> ParsedSyntax { - let m = p.start(); - - if p.at_ts(SUPPORTED_LANGUAGE_FLAVOR_SET) { - p.bump_ts(SUPPORTED_LANGUAGE_FLAVOR_SET); - Present(m.complete(p, GRIT_LANGUAGE_FLAVOR_KIND)) - } else { - p.error(p.err_builder( - "Expected a supported language flavor; must be one of `typescript` or `jsx`", - p.cur_range(), - )); - m.abandon(p); - Absent + if !p.at_ts(SUPPORTED_LANGUAGE_FLAVOR_SET) { + return Absent; } + + let m = p.start(); + p.bump_ts(SUPPORTED_LANGUAGE_FLAVOR_SET); + Present(m.complete(p, GRIT_LANGUAGE_FLAVOR_KIND)) } fn parse_definition_list(p: &mut GritParser) -> CompletedMarker { @@ -209,16 +222,38 @@ fn parse_definition_list(p: &mut GritParser) -> CompletedMarker { } #[inline] -fn parse_variable_list(p: &mut GritParser) -> ParsedSyntax { +fn parse_name(p: &mut GritParser) -> ParsedSyntax { + if !p.at(GRIT_NAME) { + return Absent; + } + + let m = p.start(); + p.bump(GRIT_NAME); + Present(m.complete(p, GRIT_NAME)) +} + +#[inline] +fn parse_variable(p: &mut GritParser) -> ParsedSyntax { if !p.at(GRIT_VARIABLE) { return Absent; } let m = p.start(); p.bump(GRIT_VARIABLE); + Present(m.complete(p, GRIT_VARIABLE)) +} + +#[inline] +fn parse_variable_list(p: &mut GritParser) -> ParsedSyntax { + if !p.at(GRIT_VARIABLE) { + return Absent; + } + + let m = p.start(); + let _ = parse_variable(p); while p.eat(T![,]) { - if !p.eat(GRIT_VARIABLE) { + if parse_variable(p) == Absent { break; } } diff --git a/crates/biome_grit_parser/src/parser/parse_error.rs b/crates/biome_grit_parser/src/parser/parse_error.rs new file mode 100644 index 00000000000..94c1fd8b3fe --- /dev/null +++ b/crates/biome_grit_parser/src/parser/parse_error.rs @@ -0,0 +1,23 @@ +use crate::parser::GritParser; +use biome_parser::diagnostic::expected_node; +use biome_parser::prelude::ParseDiagnostic; +use biome_parser::Parser; +use biome_rowan::TextRange; + +pub(crate) fn expected_language_name(p: &GritParser, range: TextRange) -> ParseDiagnostic { + p.err_builder( + "Expected a supported language; must be one of `js`, `json`, `css`, `html`, or `grit`", + range, + ) +} + +pub(crate) fn expected_language_flavor(p: &GritParser, range: TextRange) -> ParseDiagnostic { + p.err_builder( + "Expected a supported language flavor; must be one of `typescript` or `jsx`", + range, + ) +} + +pub(crate) fn expected_pattern(p: &GritParser, range: TextRange) -> ParseDiagnostic { + expected_node("pattern", range, p) +} diff --git a/crates/biome_grit_parser/src/parser/patterns.rs b/crates/biome_grit_parser/src/parser/patterns.rs index a01a4d0ddae..6630cd3accb 100644 --- a/crates/biome_grit_parser/src/parser/patterns.rs +++ b/crates/biome_grit_parser/src/parser/patterns.rs @@ -1,10 +1,14 @@ use super::literals::parse_literal; +use super::parse_error::expected_pattern; use super::predicates::parse_predicate; -use super::{parse_variable_list, GritParser}; +use super::{parse_name, parse_variable_list, GritParser}; use biome_grit_syntax::GritSyntaxKind::{self, *}; use biome_grit_syntax::T; +use biome_parser::parse_recovery::{ParseRecovery, ParseRecoveryTokenSet}; use biome_parser::prelude::{ParsedSyntax::*, *}; +const ARG_LIST_RECOVERY_SET: TokenSet = token_set!(T![,], T![')']); + const NOT_SET: TokenSet = token_set![NOT_KW, T![!]]; const REGEX_SET: TokenSet = token_set![GRIT_REGEX, GRIT_SNIPPET_REGEX]; @@ -24,7 +28,7 @@ pub(crate) fn parse_pattern(p: &mut GritParser) -> ParsedSyntax { BEFORE_KW => parse_pattern_before(p), WITHIN_KW => parse_pattern_within(p), BUBBLE_KW => parse_bubble(p), - // TODO: GritNodeLike => {} + GRIT_NAME => parse_node_like(p), // TODO: GritMapAccessor => {} // TODO: GritListAccessor => {} T![.] => parse_dot(p), @@ -255,21 +259,93 @@ fn parse_like_threshold(p: &mut GritParser) -> ParsedSyntax { #[inline] fn parse_maybe_curly_pattern(p: &mut GritParser) -> ParsedSyntax { - let m = p.start(); - - let result = if p.at(T!['{']) { + if p.at(T!['{']) { parse_curly_pattern(p) } else { parse_pattern(p) - }; + } +} - match result { - Present(_) => Present(m.complete(p, MAYBE_CURLY_GRIT_PATTERN)), - Absent => { - m.abandon(p); - Absent +struct ArgListParseRecovery; +impl ParseRecovery for ArgListParseRecovery { + type Kind = GritSyntaxKind; + type Parser<'source> = GritParser<'source>; + const RECOVERED_KIND: Self::Kind = GRIT_BOGUS; + + fn is_at_recovered(&self, p: &mut Self::Parser<'_>) -> bool { + p.at(T![')']) + } +} + +#[inline] +fn parse_maybe_named_arg(p: &mut GritParser) -> ParsedSyntax { + if p.at(GRIT_NAME) { + parse_named_arg(p) + } else { + parse_pattern(p) + .or_recover_with_token_set( + p, + &ParseRecoveryTokenSet::new(GRIT_BOGUS, ARG_LIST_RECOVERY_SET), + expected_pattern, + ) + .ok() + .into() + } +} + +#[inline] +fn parse_named_arg(p: &mut GritParser) -> ParsedSyntax { + if !p.at(GRIT_NAME) { + return Absent; + } + + let m = p.start(); + let _ = parse_name(p); + p.eat(T![=]); + let _ = parse_pattern(p).or_recover_with_token_set( + p, + &ParseRecoveryTokenSet::new(GRIT_BOGUS, ARG_LIST_RECOVERY_SET), + expected_pattern, + ); + Present(m.complete(p, GRIT_NAMED_ARG)) +} + +#[inline] +fn parse_named_arg_list(p: &mut GritParser) -> ParsedSyntax { + let m = p.start(); + + if parse_maybe_named_arg(p) == Absent { + m.abandon(p); + return Absent; + } + + while p.eat(T![,]) { + if p.at(T![')']) || parse_maybe_named_arg(p) == Absent { + break; } } + + Present(m.complete(p, GRIT_NAMED_ARG_LIST)) +} + +#[inline] +fn parse_node_like(p: &mut GritParser) -> ParsedSyntax { + if !p.at(GRIT_NAME) { + return Absent; + } + + let m = p.start(); + let _ = parse_name(p); + p.eat(T!['(']); + + if parse_named_arg_list(p) == Absent { + m.abandon(p); + return Absent; + } + + p.eat(T![')']); + + Present(m.complete(p, GRIT_NODE_LIKE)) } #[inline] diff --git a/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_engine.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_engine.grit.snap index 34985662e17..bf786b6959e 100644 --- a/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_engine.grit.snap +++ b/crates/biome_grit_parser/tests/grit_test_suite/err/incorrect_engine.grit.snap @@ -22,9 +22,20 @@ GritRoot { }, language: missing (optional), definitions: GritDefinitionList [], - pattern: missing (optional), + pattern: GritNodeLike { + name: GritName { + grit_name_token: GRIT_NAME@7..15 "marzano" [] [Whitespace(" ")], + }, + l_paren_token: L_PAREN@15..16 "(" [] [], + named_args: GritNamedArgList [ + GritDoubleLiteral { + value_token: GRIT_DOUBLE@16..19 "1.0" [] [], + }, + ], + r_paren_token: R_PAREN@19..20 ")" [] [], + }, definitions_continued: GritDefinitionList [], - eof_token: EOF@7..21 "marzano (1.0)\n" [] [], + eof_token: EOF@20..21 "" [Newline("\n")] [], } ``` @@ -41,9 +52,16 @@ GritRoot { 4: (empty) 2: (empty) 3: GRIT_DEFINITION_LIST@7..7 - 4: (empty) - 5: GRIT_DEFINITION_LIST@7..7 - 6: EOF@7..21 "marzano (1.0)\n" [] [] + 4: GRIT_NODE_LIKE@7..20 + 0: GRIT_NAME@7..15 + 0: GRIT_NAME@7..15 "marzano" [] [Whitespace(" ")] + 1: L_PAREN@15..16 "(" [] [] + 2: GRIT_NAMED_ARG_LIST@16..19 + 0: GRIT_DOUBLE_LITERAL@16..19 + 0: GRIT_DOUBLE@16..19 "1.0" [] [] + 3: R_PAREN@19..20 ")" [] [] + 5: GRIT_DEFINITION_LIST@20..20 + 6: EOF@20..21 "" [Newline("\n")] [] ``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/err/invalid_language.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/err/invalid_language.grit.snap index eb621283757..2f6850905b8 100644 --- a/crates/biome_grit_parser/tests/grit_test_suite/err/invalid_language.grit.snap +++ b/crates/biome_grit_parser/tests/grit_test_suite/err/invalid_language.grit.snap @@ -18,12 +18,17 @@ GritRoot { language_token: LANGUAGE_KW@0..9 "language" [] [Whitespace(" ")], name: missing (required), flavor: missing (optional), - semicolon_token: missing (optional), + grit_bogus: GritBogus { + items: [ + GRIT_NAME@9..21 "non_existing" [] [], + ], + }, + semicolon_token: SEMICOLON@21..22 ";" [] [], }, definitions: GritDefinitionList [], pattern: missing (optional), definitions_continued: GritDefinitionList [], - eof_token: EOF@9..23 "non_existing;\n" [] [], + eof_token: EOF@22..23 "" [Newline("\n")] [], } ``` @@ -33,15 +38,17 @@ GritRoot { 0: GRIT_ROOT@0..23 0: (empty) 1: (empty) - 2: GRIT_LANGUAGE_DECLARATION@0..9 + 2: GRIT_LANGUAGE_DECLARATION@0..22 0: LANGUAGE_KW@0..9 "language" [] [Whitespace(" ")] 1: (empty) 2: (empty) - 3: (empty) - 3: GRIT_DEFINITION_LIST@9..9 + 3: GRIT_BOGUS@9..21 + 0: GRIT_NAME@9..21 "non_existing" [] [] + 4: SEMICOLON@21..22 ";" [] [] + 3: GRIT_DEFINITION_LIST@22..22 4: (empty) - 5: GRIT_DEFINITION_LIST@9..9 - 6: EOF@9..23 "non_existing;\n" [] [] + 5: GRIT_DEFINITION_LIST@22..22 + 6: EOF@22..23 "" [Newline("\n")] [] ``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/err/language_with_invalid_flavor.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/err/language_with_invalid_flavor.grit.snap index b76271b89e8..429e17fcd42 100644 --- a/crates/biome_grit_parser/tests/grit_test_suite/err/language_with_invalid_flavor.grit.snap +++ b/crates/biome_grit_parser/tests/grit_test_suite/err/language_with_invalid_flavor.grit.snap @@ -19,17 +19,28 @@ GritRoot { name: GritLanguageName { language_kind: JS_KW@9..11 "js" [] [], }, - flavor: GritLanguageFlavor { - l_paren_token: L_PAREN@11..12 "(" [] [], - grit_language_flavor_list: GritLanguageFlavorList [], - r_paren_token: missing (required), + flavor: missing (optional), + grit_bogus: GritBogus { + items: [ + L_PAREN@11..12 "(" [] [], + GritBogus { + items: [ + GritBogus { + items: [ + GRIT_NAME@12..19 "vanilla" [] [], + ], + }, + ], + }, + R_PAREN@19..20 ")" [] [], + ], }, - semicolon_token: missing (optional), + semicolon_token: SEMICOLON@20..21 ";" [] [], }, definitions: GritDefinitionList [], pattern: missing (optional), definitions_continued: GritDefinitionList [], - eof_token: EOF@12..22 "vanilla);\n" [] [], + eof_token: EOF@21..22 "" [Newline("\n")] [], } ``` @@ -39,19 +50,22 @@ GritRoot { 0: GRIT_ROOT@0..22 0: (empty) 1: (empty) - 2: GRIT_LANGUAGE_DECLARATION@0..12 + 2: GRIT_LANGUAGE_DECLARATION@0..21 0: LANGUAGE_KW@0..9 "language" [] [Whitespace(" ")] 1: GRIT_LANGUAGE_NAME@9..11 0: JS_KW@9..11 "js" [] [] - 2: GRIT_LANGUAGE_FLAVOR@11..12 + 2: (empty) + 3: GRIT_BOGUS@11..20 0: L_PAREN@11..12 "(" [] [] - 1: GRIT_LANGUAGE_FLAVOR_LIST@12..12 - 2: (empty) - 3: (empty) - 3: GRIT_DEFINITION_LIST@12..12 + 1: GRIT_BOGUS@12..19 + 0: GRIT_BOGUS@12..19 + 0: GRIT_NAME@12..19 "vanilla" [] [] + 2: R_PAREN@19..20 ")" [] [] + 4: SEMICOLON@20..21 ";" [] [] + 3: GRIT_DEFINITION_LIST@21..21 4: (empty) - 5: GRIT_DEFINITION_LIST@12..12 - 6: EOF@12..22 "vanilla);\n" [] [] + 5: GRIT_DEFINITION_LIST@21..21 + 6: EOF@21..22 "" [Newline("\n")] [] ``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/file_node.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/file_node.grit new file mode 100644 index 00000000000..442779497a9 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/file_node.grit @@ -0,0 +1 @@ +file(body = contains `console.$method` => `println`) diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/file_node.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/file_node.grit.snap new file mode 100644 index 00000000000..13ce27cbb47 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/file_node.grit.snap @@ -0,0 +1,90 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +file(body = contains `console.$method` => `println`) + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: missing (optional), + definitions: GritDefinitionList [], + pattern: GritNodeLike { + name: GritName { + grit_name_token: GRIT_NAME@0..4 "file" [] [], + }, + l_paren_token: L_PAREN@4..5 "(" [] [], + named_args: GritNamedArgList [ + GritNamedArg { + name: GritName { + grit_name_token: GRIT_NAME@5..10 "body" [] [Whitespace(" ")], + }, + eq_token: EQ@10..12 "=" [] [Whitespace(" ")], + pattern: GritPatternContains { + contains_token: CONTAINS_KW@12..21 "contains" [] [Whitespace(" ")], + contains: GritRewrite { + left: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@21..39 "`console.$method`" [] [Whitespace(" ")], + }, + }, + annotation: missing (optional), + fat_arrow_token: FAT_ARROW@39..42 "=>" [] [Whitespace(" ")], + right: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@42..51 "`println`" [] [], + }, + }, + }, + grit_pattern_contains_until_clause: missing (optional), + }, + }, + ], + r_paren_token: R_PAREN@51..52 ")" [] [], + }, + definitions_continued: GritDefinitionList [], + eof_token: EOF@52..53 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..53 + 0: (empty) + 1: (empty) + 2: (empty) + 3: GRIT_DEFINITION_LIST@0..0 + 4: GRIT_NODE_LIKE@0..52 + 0: GRIT_NAME@0..4 + 0: GRIT_NAME@0..4 "file" [] [] + 1: L_PAREN@4..5 "(" [] [] + 2: GRIT_NAMED_ARG_LIST@5..51 + 0: GRIT_NAMED_ARG@5..51 + 0: GRIT_NAME@5..10 + 0: GRIT_NAME@5..10 "body" [] [Whitespace(" ")] + 1: EQ@10..12 "=" [] [Whitespace(" ")] + 2: GRIT_PATTERN_CONTAINS@12..51 + 0: CONTAINS_KW@12..21 "contains" [] [Whitespace(" ")] + 1: GRIT_REWRITE@21..51 + 0: GRIT_CODE_SNIPPET@21..39 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@21..39 + 0: GRIT_BACKTICK_SNIPPET@21..39 "`console.$method`" [] [Whitespace(" ")] + 1: (empty) + 2: FAT_ARROW@39..42 "=>" [] [Whitespace(" ")] + 3: GRIT_CODE_SNIPPET@42..51 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@42..51 + 0: GRIT_BACKTICK_SNIPPET@42..51 "`println`" [] [] + 2: (empty) + 3: R_PAREN@51..52 ")" [] [] + 5: GRIT_DEFINITION_LIST@52..52 + 6: EOF@52..53 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/language.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/language.grit.snap index 4e5f512fa46..93eb740380c 100644 --- a/crates/biome_grit_parser/tests/grit_test_suite/ok/language.grit.snap +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/language.grit.snap @@ -20,6 +20,7 @@ GritRoot { language_kind: JS_KW@9..11 "js" [] [], }, flavor: missing (optional), + grit_bogus: missing (optional), semicolon_token: SEMICOLON@11..12 ";" [] [], }, definitions: GritDefinitionList [], @@ -40,7 +41,8 @@ GritRoot { 1: GRIT_LANGUAGE_NAME@9..11 0: JS_KW@9..11 "js" [] [] 2: (empty) - 3: SEMICOLON@11..12 ";" [] [] + 3: (empty) + 4: SEMICOLON@11..12 ";" [] [] 3: GRIT_DEFINITION_LIST@12..12 4: (empty) 5: GRIT_DEFINITION_LIST@12..12 diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/language_with_flavor.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/language_with_flavor.grit.snap index c2ff293337c..d3beedd9e20 100644 --- a/crates/biome_grit_parser/tests/grit_test_suite/ok/language_with_flavor.grit.snap +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/language_with_flavor.grit.snap @@ -24,10 +24,12 @@ GritRoot { grit_language_flavor_list: GritLanguageFlavorList [ GritLanguageFlavorKind { flavor_kind: TYPESCRIPT_KW@12..22 "typescript" [] [], + grit_bogus: missing (optional), }, ], r_paren_token: R_PAREN@22..23 ")" [] [], }, + grit_bogus: missing (optional), semicolon_token: SEMICOLON@23..24 ";" [] [], }, definitions: GritDefinitionList [], @@ -52,8 +54,10 @@ GritRoot { 1: GRIT_LANGUAGE_FLAVOR_LIST@12..22 0: GRIT_LANGUAGE_FLAVOR_KIND@12..22 0: TYPESCRIPT_KW@12..22 "typescript" [] [] + 1: (empty) 2: R_PAREN@22..23 ")" [] [] - 3: SEMICOLON@23..24 ";" [] [] + 3: (empty) + 4: SEMICOLON@23..24 ";" [] [] 3: GRIT_DEFINITION_LIST@24..24 4: (empty) 5: GRIT_DEFINITION_LIST@24..24 diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/rewrite_in_where.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/rewrite_in_where.grit.snap index 7eef4cbed92..030369f910b 100644 --- a/crates/biome_grit_parser/tests/grit_test_suite/ok/rewrite_in_where.grit.snap +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/rewrite_in_where.grit.snap @@ -33,6 +33,7 @@ GritRoot { language_kind: JS_KW@27..29 "js" [] [], }, flavor: missing (optional), + grit_bogus: missing (optional), semicolon_token: missing (optional), }, definitions: GritDefinitionList [], @@ -100,6 +101,7 @@ GritRoot { 0: JS_KW@27..29 "js" [] [] 2: (empty) 3: (empty) + 4: (empty) 3: GRIT_DEFINITION_LIST@29..29 4: GRIT_PATTERN_WHERE@29..91 0: GRIT_CODE_SNIPPET@29..43 diff --git a/crates/biome_grit_syntax/src/generated/kind.rs b/crates/biome_grit_syntax/src/generated/kind.rs index da06da565a4..a5a582c5ad3 100644 --- a/crates/biome_grit_syntax/src/generated/kind.rs +++ b/crates/biome_grit_syntax/src/generated/kind.rs @@ -141,7 +141,6 @@ pub enum GritSyntaxKind { GRIT_BUBBLE_SCOPE, GRIT_BUBBLE, GRIT_NAMED_ARG, - GRIT_NAMED_ARG_WITH_DEFAULT, GRIT_NAMED_ARG_LIST, GRIT_NODE_LIKE, GRIT_LIKE, @@ -196,7 +195,6 @@ pub enum GritSyntaxKind { GRIT_CODE_SNIPPET, GRIT_NOT, GRIT_UNDERSCORE, - MAYBE_CURLY_GRIT_PATTERN, GRIT_BACKTICK_SNIPPET_LITERAL, GRIT_BOOLEAN_LITERAL, GRIT_UNDEFINED_LITERAL, diff --git a/crates/biome_grit_syntax/src/generated/macros.rs b/crates/biome_grit_syntax/src/generated/macros.rs index 608c471a057..316982ae6e9 100644 --- a/crates/biome_grit_syntax/src/generated/macros.rs +++ b/crates/biome_grit_syntax/src/generated/macros.rs @@ -162,10 +162,6 @@ macro_rules! map_syntax_node { let $pattern = unsafe { $crate::GritNamedArg::new_unchecked(node) }; $body } - $crate::GritSyntaxKind::GRIT_NAMED_ARG_WITH_DEFAULT => { - let $pattern = unsafe { $crate::GritNamedArgWithDefault::new_unchecked(node) }; - $body - } $crate::GritSyntaxKind::GRIT_NEGATIVE_INT_LITERAL => { let $pattern = unsafe { $crate::GritNegativeIntLiteral::new_unchecked(node) }; $body diff --git a/crates/biome_grit_syntax/src/generated/nodes.rs b/crates/biome_grit_syntax/src/generated/nodes.rs index 7dfbb426d37..5233395946e 100644 --- a/crates/biome_grit_syntax/src/generated/nodes.rs +++ b/crates/biome_grit_syntax/src/generated/nodes.rs @@ -908,6 +908,7 @@ impl GritLanguageDeclaration { language_token: self.language_token(), name: self.name(), flavor: self.flavor(), + grit_bogus: self.grit_bogus(), semicolon_token: self.semicolon_token(), } } @@ -920,8 +921,11 @@ impl GritLanguageDeclaration { pub fn flavor(&self) -> Option { support::node(&self.syntax, 2usize) } + pub fn grit_bogus(&self) -> Option { + support::node(&self.syntax, 3usize) + } pub fn semicolon_token(&self) -> Option { - support::token(&self.syntax, 3usize) + support::token(&self.syntax, 4usize) } } #[cfg(feature = "serde")] @@ -938,6 +942,7 @@ pub struct GritLanguageDeclarationFields { pub language_token: SyntaxResult, pub name: SyntaxResult, pub flavor: Option, + pub grit_bogus: Option, pub semicolon_token: Option, } #[derive(Clone, PartialEq, Eq, Hash)] @@ -1003,11 +1008,15 @@ impl GritLanguageFlavorKind { pub fn as_fields(&self) -> GritLanguageFlavorKindFields { GritLanguageFlavorKindFields { flavor_kind: self.flavor_kind(), + grit_bogus: self.grit_bogus(), } } pub fn flavor_kind(&self) -> SyntaxResult { support::required_token(&self.syntax, 0usize) } + pub fn grit_bogus(&self) -> Option { + support::node(&self.syntax, 1usize) + } } #[cfg(feature = "serde")] impl Serialize for GritLanguageFlavorKind { @@ -1021,6 +1030,7 @@ impl Serialize for GritLanguageFlavorKind { #[cfg_attr(feature = "serde", derive(Serialize))] pub struct GritLanguageFlavorKindFields { pub flavor_kind: SyntaxResult, + pub grit_bogus: Option, } #[derive(Clone, PartialEq, Eq, Hash)] pub struct GritLanguageName { @@ -1584,41 +1594,7 @@ impl GritNamedArg { Self { syntax } } pub fn as_fields(&self) -> GritNamedArgFields { - GritNamedArgFields { name: self.name() } - } - pub fn name(&self) -> SyntaxResult { - support::required_node(&self.syntax, 0usize) - } -} -#[cfg(feature = "serde")] -impl Serialize for GritNamedArg { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - self.as_fields().serialize(serializer) - } -} -#[cfg_attr(feature = "serde", derive(Serialize))] -pub struct GritNamedArgFields { - pub name: SyntaxResult, -} -#[derive(Clone, PartialEq, Eq, Hash)] -pub struct GritNamedArgWithDefault { - pub(crate) syntax: SyntaxNode, -} -impl GritNamedArgWithDefault { - #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] - #[doc = r""] - #[doc = r" # Safety"] - #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] - #[doc = r" or a match on [SyntaxNode::kind]"] - #[inline] - pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { - Self { syntax } - } - pub fn as_fields(&self) -> GritNamedArgWithDefaultFields { - GritNamedArgWithDefaultFields { + GritNamedArgFields { name: self.name(), eq_token: self.eq_token(), pattern: self.pattern(), @@ -1635,7 +1611,7 @@ impl GritNamedArgWithDefault { } } #[cfg(feature = "serde")] -impl Serialize for GritNamedArgWithDefault { +impl Serialize for GritNamedArg { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -1644,7 +1620,7 @@ impl Serialize for GritNamedArgWithDefault { } } #[cfg_attr(feature = "serde", derive(Serialize))] -pub struct GritNamedArgWithDefaultFields { +pub struct GritNamedArgFields { pub name: SyntaxResult, pub eq_token: SyntaxResult, pub pattern: SyntaxResult, @@ -4510,33 +4486,6 @@ impl AnyGritLiteral { } #[derive(Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize))] -pub enum AnyGritNamedArg { - GritBogusNamedArg(GritBogusNamedArg), - GritNamedArg(GritNamedArg), - GritNamedArgWithDefault(GritNamedArgWithDefault), -} -impl AnyGritNamedArg { - pub fn as_grit_bogus_named_arg(&self) -> Option<&GritBogusNamedArg> { - match &self { - AnyGritNamedArg::GritBogusNamedArg(item) => Some(item), - _ => None, - } - } - pub fn as_grit_named_arg(&self) -> Option<&GritNamedArg> { - match &self { - AnyGritNamedArg::GritNamedArg(item) => Some(item), - _ => None, - } - } - pub fn as_grit_named_arg_with_default(&self) -> Option<&GritNamedArgWithDefault> { - match &self { - AnyGritNamedArg::GritNamedArgWithDefault(item) => Some(item), - _ => None, - } - } -} -#[derive(Clone, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize))] pub enum AnyGritPattern { AnyGritLiteral(AnyGritLiteral), BracketedGritPattern(BracketedGritPattern), @@ -5141,6 +5090,33 @@ impl MaybeCurlyGritPattern { } } } +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub enum MaybeGritNamedArg { + AnyGritPattern(AnyGritPattern), + GritBogusNamedArg(GritBogusNamedArg), + GritNamedArg(GritNamedArg), +} +impl MaybeGritNamedArg { + pub fn as_any_grit_pattern(&self) -> Option<&AnyGritPattern> { + match &self { + MaybeGritNamedArg::AnyGritPattern(item) => Some(item), + _ => None, + } + } + pub fn as_grit_bogus_named_arg(&self) -> Option<&GritBogusNamedArg> { + match &self { + MaybeGritNamedArg::GritBogusNamedArg(item) => Some(item), + _ => None, + } + } + pub fn as_grit_named_arg(&self) -> Option<&GritNamedArg> { + match &self { + MaybeGritNamedArg::GritNamedArg(item) => Some(item), + _ => None, + } + } +} impl AstNode for BracketedGritPattern { type Language = Language; const KIND_SET: SyntaxKindSet = @@ -6050,6 +6026,10 @@ impl std::fmt::Debug for GritLanguageDeclaration { ) .field("name", &support::DebugSyntaxResult(self.name())) .field("flavor", &support::DebugOptionalElement(self.flavor())) + .field( + "grit_bogus", + &support::DebugOptionalElement(self.grit_bogus()), + ) .field( "semicolon_token", &support::DebugOptionalElement(self.semicolon_token()), @@ -6144,6 +6124,10 @@ impl std::fmt::Debug for GritLanguageFlavorKind { "flavor_kind", &support::DebugSyntaxResult(self.flavor_kind()), ) + .field( + "grit_bogus", + &support::DebugOptionalElement(self.grit_bogus()), + ) .finish() } } @@ -6712,6 +6696,8 @@ impl std::fmt::Debug for GritNamedArg { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("GritNamedArg") .field("name", &support::DebugSyntaxResult(self.name())) + .field("eq_token", &support::DebugSyntaxResult(self.eq_token())) + .field("pattern", &support::DebugSyntaxResult(self.pattern())) .finish() } } @@ -6725,46 +6711,6 @@ impl From for SyntaxElement { n.syntax.into() } } -impl AstNode for GritNamedArgWithDefault { - type Language = Language; - const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_NAMED_ARG_WITH_DEFAULT as u16)); - fn can_cast(kind: SyntaxKind) -> bool { - kind == GRIT_NAMED_ARG_WITH_DEFAULT - } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { - &self.syntax - } - fn into_syntax(self) -> SyntaxNode { - self.syntax - } -} -impl std::fmt::Debug for GritNamedArgWithDefault { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("GritNamedArgWithDefault") - .field("name", &support::DebugSyntaxResult(self.name())) - .field("eq_token", &support::DebugSyntaxResult(self.eq_token())) - .field("pattern", &support::DebugSyntaxResult(self.pattern())) - .finish() - } -} -impl From for SyntaxNode { - fn from(n: GritNamedArgWithDefault) -> SyntaxNode { - n.syntax - } -} -impl From for SyntaxElement { - fn from(n: GritNamedArgWithDefault) -> SyntaxElement { - n.syntax.into() - } -} impl AstNode for GritNegativeIntLiteral { type Language = Language; const KIND_SET: SyntaxKindSet = @@ -9773,84 +9719,6 @@ impl From for SyntaxElement { node.into() } } -impl From for AnyGritNamedArg { - fn from(node: GritBogusNamedArg) -> AnyGritNamedArg { - AnyGritNamedArg::GritBogusNamedArg(node) - } -} -impl From for AnyGritNamedArg { - fn from(node: GritNamedArg) -> AnyGritNamedArg { - AnyGritNamedArg::GritNamedArg(node) - } -} -impl From for AnyGritNamedArg { - fn from(node: GritNamedArgWithDefault) -> AnyGritNamedArg { - AnyGritNamedArg::GritNamedArgWithDefault(node) - } -} -impl AstNode for AnyGritNamedArg { - type Language = Language; - const KIND_SET: SyntaxKindSet = GritBogusNamedArg::KIND_SET - .union(GritNamedArg::KIND_SET) - .union(GritNamedArgWithDefault::KIND_SET); - fn can_cast(kind: SyntaxKind) -> bool { - matches!( - kind, - GRIT_BOGUS_NAMED_ARG | GRIT_NAMED_ARG | GRIT_NAMED_ARG_WITH_DEFAULT - ) - } - fn cast(syntax: SyntaxNode) -> Option { - let res = match syntax.kind() { - GRIT_BOGUS_NAMED_ARG => { - AnyGritNamedArg::GritBogusNamedArg(GritBogusNamedArg { syntax }) - } - GRIT_NAMED_ARG => AnyGritNamedArg::GritNamedArg(GritNamedArg { syntax }), - GRIT_NAMED_ARG_WITH_DEFAULT => { - AnyGritNamedArg::GritNamedArgWithDefault(GritNamedArgWithDefault { syntax }) - } - _ => return None, - }; - Some(res) - } - fn syntax(&self) -> &SyntaxNode { - match self { - AnyGritNamedArg::GritBogusNamedArg(it) => &it.syntax, - AnyGritNamedArg::GritNamedArg(it) => &it.syntax, - AnyGritNamedArg::GritNamedArgWithDefault(it) => &it.syntax, - } - } - fn into_syntax(self) -> SyntaxNode { - match self { - AnyGritNamedArg::GritBogusNamedArg(it) => it.syntax, - AnyGritNamedArg::GritNamedArg(it) => it.syntax, - AnyGritNamedArg::GritNamedArgWithDefault(it) => it.syntax, - } - } -} -impl std::fmt::Debug for AnyGritNamedArg { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - AnyGritNamedArg::GritBogusNamedArg(it) => std::fmt::Debug::fmt(it, f), - AnyGritNamedArg::GritNamedArg(it) => std::fmt::Debug::fmt(it, f), - AnyGritNamedArg::GritNamedArgWithDefault(it) => std::fmt::Debug::fmt(it, f), - } - } -} -impl From for SyntaxNode { - fn from(n: AnyGritNamedArg) -> SyntaxNode { - match n { - AnyGritNamedArg::GritBogusNamedArg(it) => it.into(), - AnyGritNamedArg::GritNamedArg(it) => it.into(), - AnyGritNamedArg::GritNamedArgWithDefault(it) => it.into(), - } - } -} -impl From for SyntaxElement { - fn from(n: AnyGritNamedArg) -> SyntaxElement { - let node: SyntaxNode = n.into(); - node.into() - } -} impl From for AnyGritPattern { fn from(node: BracketedGritPattern) -> AnyGritPattern { AnyGritPattern::BracketedGritPattern(node) @@ -11227,6 +11095,82 @@ impl From for SyntaxElement { node.into() } } +impl From for MaybeGritNamedArg { + fn from(node: GritBogusNamedArg) -> MaybeGritNamedArg { + MaybeGritNamedArg::GritBogusNamedArg(node) + } +} +impl From for MaybeGritNamedArg { + fn from(node: GritNamedArg) -> MaybeGritNamedArg { + MaybeGritNamedArg::GritNamedArg(node) + } +} +impl AstNode for MaybeGritNamedArg { + type Language = Language; + const KIND_SET: SyntaxKindSet = AnyGritPattern::KIND_SET + .union(GritBogusNamedArg::KIND_SET) + .union(GritNamedArg::KIND_SET); + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + GRIT_BOGUS_NAMED_ARG | GRIT_NAMED_ARG => true, + k if AnyGritPattern::can_cast(k) => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + GRIT_BOGUS_NAMED_ARG => { + MaybeGritNamedArg::GritBogusNamedArg(GritBogusNamedArg { syntax }) + } + GRIT_NAMED_ARG => MaybeGritNamedArg::GritNamedArg(GritNamedArg { syntax }), + _ => { + if let Some(any_grit_pattern) = AnyGritPattern::cast(syntax) { + return Some(MaybeGritNamedArg::AnyGritPattern(any_grit_pattern)); + } + return None; + } + }; + Some(res) + } + fn syntax(&self) -> &SyntaxNode { + match self { + MaybeGritNamedArg::GritBogusNamedArg(it) => &it.syntax, + MaybeGritNamedArg::GritNamedArg(it) => &it.syntax, + MaybeGritNamedArg::AnyGritPattern(it) => it.syntax(), + } + } + fn into_syntax(self) -> SyntaxNode { + match self { + MaybeGritNamedArg::GritBogusNamedArg(it) => it.syntax, + MaybeGritNamedArg::GritNamedArg(it) => it.syntax, + MaybeGritNamedArg::AnyGritPattern(it) => it.into_syntax(), + } + } +} +impl std::fmt::Debug for MaybeGritNamedArg { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + MaybeGritNamedArg::AnyGritPattern(it) => std::fmt::Debug::fmt(it, f), + MaybeGritNamedArg::GritBogusNamedArg(it) => std::fmt::Debug::fmt(it, f), + MaybeGritNamedArg::GritNamedArg(it) => std::fmt::Debug::fmt(it, f), + } + } +} +impl From for SyntaxNode { + fn from(n: MaybeGritNamedArg) -> SyntaxNode { + match n { + MaybeGritNamedArg::AnyGritPattern(it) => it.into(), + MaybeGritNamedArg::GritBogusNamedArg(it) => it.into(), + MaybeGritNamedArg::GritNamedArg(it) => it.into(), + } + } +} +impl From for SyntaxElement { + fn from(n: MaybeGritNamedArg) -> SyntaxElement { + let node: SyntaxNode = n.into(); + node.into() + } +} impl std::fmt::Display for AnyGritContainer { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -11247,11 +11191,6 @@ impl std::fmt::Display for AnyGritLiteral { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for AnyGritNamedArg { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} impl std::fmt::Display for AnyGritPattern { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -11302,6 +11241,11 @@ impl std::fmt::Display for MaybeCurlyGritPattern { std::fmt::Display::fmt(self.syntax(), f) } } +impl std::fmt::Display for MaybeGritNamedArg { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} impl std::fmt::Display for BracketedGritPattern { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -11482,11 +11426,6 @@ impl std::fmt::Display for GritNamedArg { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for GritNamedArgWithDefault { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} impl std::fmt::Display for GritNegativeIntLiteral { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -12511,7 +12450,7 @@ impl Serialize for GritNamedArgList { } impl AstSeparatedList for GritNamedArgList { type Language = Language; - type Node = GritNamedArg; + type Node = MaybeGritNamedArg; fn syntax_list(&self) -> &SyntaxList { &self.syntax_list } @@ -12526,15 +12465,15 @@ impl Debug for GritNamedArgList { } } impl IntoIterator for GritNamedArgList { - type Item = SyntaxResult; - type IntoIter = AstSeparatedListNodesIterator; + type Item = SyntaxResult; + type IntoIter = AstSeparatedListNodesIterator; fn into_iter(self) -> Self::IntoIter { self.iter() } } impl IntoIterator for &GritNamedArgList { - type Item = SyntaxResult; - type IntoIter = AstSeparatedListNodesIterator; + type Item = SyntaxResult; + type IntoIter = AstSeparatedListNodesIterator; fn into_iter(self) -> Self::IntoIter { self.iter() } diff --git a/crates/biome_grit_syntax/src/generated/nodes_mut.rs b/crates/biome_grit_syntax/src/generated/nodes_mut.rs index b5c9d54d03b..3f984ae0692 100644 --- a/crates/biome_grit_syntax/src/generated/nodes_mut.rs +++ b/crates/biome_grit_syntax/src/generated/nodes_mut.rs @@ -356,10 +356,16 @@ impl GritLanguageDeclaration { once(element.map(|element| element.into_syntax().into())), )) } + pub fn with_grit_bogus(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 3usize..=3usize, + once(element.map(|element| element.into_syntax().into())), + )) + } pub fn with_semicolon_token(self, element: Option) -> Self { Self::unwrap_cast( self.syntax - .splice_slots(3usize..=3usize, once(element.map(|element| element.into()))), + .splice_slots(4usize..=4usize, once(element.map(|element| element.into()))), ) } } @@ -390,6 +396,12 @@ impl GritLanguageFlavorKind { .splice_slots(0usize..=0usize, once(Some(element.into()))), ) } + pub fn with_grit_bogus(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 1usize..=1usize, + once(element.map(|element| element.into_syntax().into())), + )) + } } impl GritLanguageName { pub fn with_language_kind_token(self, element: SyntaxToken) -> Self { @@ -632,14 +644,6 @@ impl GritNamedArg { .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), ) } -} -impl GritNamedArgWithDefault { - pub fn with_name(self, element: GritName) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), - ) - } pub fn with_eq_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax diff --git a/crates/biome_grit_syntax/src/lib.rs b/crates/biome_grit_syntax/src/lib.rs index 700b2cd0b5c..6c3806871e8 100644 --- a/crates/biome_grit_syntax/src/lib.rs +++ b/crates/biome_grit_syntax/src/lib.rs @@ -63,8 +63,8 @@ impl biome_rowan::SyntaxKind for GritSyntaxKind { kind if AnyGritDefinition::can_cast(*kind) => GRIT_BOGUS_DEFINITION, kind if AnyGritPattern::can_cast(*kind) => GRIT_BOGUS_PATTERN, kind if AnyGritLiteral::can_cast(*kind) => GRIT_BOGUS_LITERAL, - kind if AnyGritNamedArg::can_cast(*kind) => GRIT_BOGUS_NAMED_ARG, kind if AnyGritPredicate::can_cast(*kind) => GRIT_BOGUS_PREDICATE, + kind if MaybeGritNamedArg::can_cast(*kind) => GRIT_BOGUS_NAMED_ARG, _ => GRIT_BOGUS, } diff --git a/xtask/codegen/gritql.ungram b/xtask/codegen/gritql.ungram index 1d42a3b6c84..cec5b40cbab 100644 --- a/xtask/codegen/gritql.ungram +++ b/xtask/codegen/gritql.ungram @@ -71,6 +71,7 @@ GritLanguageDeclaration = 'language' name: GritLanguageName flavor: GritLanguageFlavor? + GritBogus? ';'? GritLanguageFlavor = '(' GritLanguageFlavorList ')' @@ -80,6 +81,7 @@ GritLanguageFlavorKind = // JavaScript flavors: 'typescript' | 'jsx' ) + GritBogus? // --- patterns @@ -233,20 +235,17 @@ GritBubble = variables: GritBubbleScope? pattern: MaybeCurlyGritPattern -AnyGritNamedArg = - GritNamedArg - | GritNamedArgWithDefault +MaybeGritNamedArg = + AnyGritPattern + | GritNamedArg | GritBogusNamedArg GritNamedArg = name: GritName - -GritNamedArgWithDefault = - name: GritName '=' pattern: AnyGritPattern -GritNamedArgList = GritNamedArg (',' GritNamedArg)* ','? +GritNamedArgList = MaybeGritNamedArg (',' MaybeGritNamedArg)* ','? // maybe we should have a different fieldname for each choice? GritNodeLike = diff --git a/xtask/codegen/src/grit_kinds_src.rs b/xtask/codegen/src/grit_kinds_src.rs index d4b940528ce..095191b5cae 100644 --- a/xtask/codegen/src/grit_kinds_src.rs +++ b/xtask/codegen/src/grit_kinds_src.rs @@ -150,7 +150,6 @@ pub const GRIT_KINDS_SRC: KindsSrc = KindsSrc { "GRIT_BUBBLE_SCOPE", "GRIT_BUBBLE", "GRIT_NAMED_ARG", - "GRIT_NAMED_ARG_WITH_DEFAULT", "GRIT_NAMED_ARG_LIST", "GRIT_NODE_LIKE", "GRIT_LIKE", @@ -205,7 +204,6 @@ pub const GRIT_KINDS_SRC: KindsSrc = KindsSrc { "GRIT_CODE_SNIPPET", "GRIT_NOT", "GRIT_UNDERSCORE", - "MAYBE_CURLY_GRIT_PATTERN", // literal wrappers: "GRIT_BACKTICK_SNIPPET_LITERAL", "GRIT_BOOLEAN_LITERAL", From 89dbd44acf21c9167ef01cc949dea0ccec4064bb Mon Sep 17 00:00:00 2001 From: "Arend van Beelen jr." Date: Wed, 28 Feb 2024 20:22:59 +0100 Subject: [PATCH 09/12] Maps, lists, assignments and accumulate --- .../src/generated/node_factory.rs | 182 ++++++++++--- .../src/generated/syntax_factory.rs | 46 +++- crates/biome_grit_parser/src/lexer/mod.rs | 50 ++-- crates/biome_grit_parser/src/lexer/tests.rs | 2 +- crates/biome_grit_parser/src/lib.rs | 1 + .../biome_grit_parser/src/parser/constants.rs | 37 +++ .../biome_grit_parser/src/parser/literals.rs | 134 +++++++++- crates/biome_grit_parser/src/parser/mod.rs | 11 +- .../src/parser/parse_error.rs | 8 + .../biome_grit_parser/src/parser/patterns.rs | 251 +++++++++++++++--- .../src/parser/predicates.rs | 113 ++++---- .../grit_test_suite/ok/create_new_files.grit | 6 + .../ok/create_new_files.grit.snap | 199 ++++++++++++++ .../tests/grit_test_suite/ok/map.grit | 5 + .../tests/grit_test_suite/ok/map.grit.snap | 190 +++++++++++++ .../tests/grit_test_suite/ok/regex.grit | 1 + .../tests/grit_test_suite/ok/regex.grit.snap | 45 ++++ .../ok/rewrite_in_where.grit.snap | 2 + crates/biome_grit_parser/tests/spec_test.rs | 2 +- .../biome_grit_syntax/src/generated/kind.rs | 5 +- .../biome_grit_syntax/src/generated/macros.rs | 4 + .../biome_grit_syntax/src/generated/nodes.rs | 129 ++++++++- .../src/generated/nodes_mut.rs | 30 +++ xtask/codegen/gritql.ungram | 11 +- xtask/codegen/src/grit_kinds_src.rs | 5 +- 25 files changed, 1295 insertions(+), 174 deletions(-) create mode 100644 crates/biome_grit_parser/src/parser/constants.rs create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/create_new_files.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/create_new_files.grit.snap create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/map.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/map.grit.snap create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/regex.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/regex.grit.snap diff --git a/crates/biome_grit_factory/src/generated/node_factory.rs b/crates/biome_grit_factory/src/generated/node_factory.rs index ef63f85817f..48962cfca1f 100644 --- a/crates/biome_grit_factory/src/generated/node_factory.rs +++ b/crates/biome_grit_factory/src/generated/node_factory.rs @@ -532,16 +532,40 @@ pub fn grit_list_accessor( l_brack_token: SyntaxToken, index: GritListIndex, r_brack_token: SyntaxToken, -) -> GritListAccessor { - GritListAccessor::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_LIST_ACCESSOR, - [ - Some(SyntaxElement::Node(list.into_syntax())), - Some(SyntaxElement::Token(l_brack_token)), - Some(SyntaxElement::Node(index.into_syntax())), - Some(SyntaxElement::Token(r_brack_token)), - ], - )) +) -> GritListAccessorBuilder { + GritListAccessorBuilder { + list, + l_brack_token, + index, + r_brack_token, + grit_bogus: None, + } +} +pub struct GritListAccessorBuilder { + list: GritListAccessorSubject, + l_brack_token: SyntaxToken, + index: GritListIndex, + r_brack_token: SyntaxToken, + grit_bogus: Option, +} +impl GritListAccessorBuilder { + pub fn with_grit_bogus(mut self, grit_bogus: GritBogus) -> Self { + self.grit_bogus = Some(grit_bogus); + self + } + pub fn build(self) -> GritListAccessor { + GritListAccessor::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_LIST_ACCESSOR, + [ + Some(SyntaxElement::Node(self.list.into_syntax())), + Some(SyntaxElement::Token(self.l_brack_token)), + Some(SyntaxElement::Node(self.index.into_syntax())), + Some(SyntaxElement::Token(self.r_brack_token)), + self.grit_bogus + .map(|token| SyntaxElement::Node(token.into_syntax())), + ], + )) + } } pub fn grit_map(l_curly_token: SyntaxToken, r_curly_token: SyntaxToken) -> GritMapBuilder { GritMapBuilder { @@ -576,15 +600,37 @@ pub fn grit_map_accessor( map: GritMapAccessorSubject, dot_token: SyntaxToken, key: GritMapKey, -) -> GritMapAccessor { - GritMapAccessor::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_MAP_ACCESSOR, - [ - Some(SyntaxElement::Node(map.into_syntax())), - Some(SyntaxElement::Token(dot_token)), - Some(SyntaxElement::Node(key.into_syntax())), - ], - )) +) -> GritMapAccessorBuilder { + GritMapAccessorBuilder { + map, + dot_token, + key, + grit_bogus: None, + } +} +pub struct GritMapAccessorBuilder { + map: GritMapAccessorSubject, + dot_token: SyntaxToken, + key: GritMapKey, + grit_bogus: Option, +} +impl GritMapAccessorBuilder { + pub fn with_grit_bogus(mut self, grit_bogus: GritBogus) -> Self { + self.grit_bogus = Some(grit_bogus); + self + } + pub fn build(self) -> GritMapAccessor { + GritMapAccessor::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_MAP_ACCESSOR, + [ + Some(SyntaxElement::Node(self.map.into_syntax())), + Some(SyntaxElement::Token(self.dot_token)), + Some(SyntaxElement::Node(self.key.into_syntax())), + self.grit_bogus + .map(|token| SyntaxElement::Node(token.into_syntax())), + ], + )) + } } pub fn grit_map_element( key: GritName, @@ -1230,15 +1276,37 @@ pub fn grit_predicate_assignment( container: AnyGritContainer, eq_token: SyntaxToken, pattern: AnyGritPattern, -) -> GritPredicateAssignment { - GritPredicateAssignment::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_PREDICATE_ASSIGNMENT, - [ - Some(SyntaxElement::Node(container.into_syntax())), - Some(SyntaxElement::Token(eq_token)), - Some(SyntaxElement::Node(pattern.into_syntax())), - ], - )) +) -> GritPredicateAssignmentBuilder { + GritPredicateAssignmentBuilder { + container, + eq_token, + pattern, + grit_bogus: None, + } +} +pub struct GritPredicateAssignmentBuilder { + container: AnyGritContainer, + eq_token: SyntaxToken, + pattern: AnyGritPattern, + grit_bogus: Option, +} +impl GritPredicateAssignmentBuilder { + pub fn with_grit_bogus(mut self, grit_bogus: GritBogus) -> Self { + self.grit_bogus = Some(grit_bogus); + self + } + pub fn build(self) -> GritPredicateAssignment { + GritPredicateAssignment::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PREDICATE_ASSIGNMENT, + [ + Some(SyntaxElement::Node(self.container.into_syntax())), + Some(SyntaxElement::Token(self.eq_token)), + Some(SyntaxElement::Node(self.pattern.into_syntax())), + self.grit_bogus + .map(|token| SyntaxElement::Node(token.into_syntax())), + ], + )) + } } pub fn grit_predicate_call( name: GritName, @@ -1453,15 +1521,37 @@ pub fn grit_predicate_match( left: GritPredicateMatchSubject, match_token: SyntaxToken, right: AnyGritPattern, -) -> GritPredicateMatch { - GritPredicateMatch::unwrap_cast(SyntaxNode::new_detached( - GritSyntaxKind::GRIT_PREDICATE_MATCH, - [ - Some(SyntaxElement::Node(left.into_syntax())), - Some(SyntaxElement::Token(match_token)), - Some(SyntaxElement::Node(right.into_syntax())), - ], - )) +) -> GritPredicateMatchBuilder { + GritPredicateMatchBuilder { + left, + match_token, + right, + grit_bogus: None, + } +} +pub struct GritPredicateMatchBuilder { + left: GritPredicateMatchSubject, + match_token: SyntaxToken, + right: AnyGritPattern, + grit_bogus: Option, +} +impl GritPredicateMatchBuilder { + pub fn with_grit_bogus(mut self, grit_bogus: GritBogus) -> Self { + self.grit_bogus = Some(grit_bogus); + self + } + pub fn build(self) -> GritPredicateMatch { + GritPredicateMatch::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_PREDICATE_MATCH, + [ + Some(SyntaxElement::Node(self.left.into_syntax())), + Some(SyntaxElement::Token(self.match_token)), + Some(SyntaxElement::Node(self.right.into_syntax())), + self.grit_bogus + .map(|token| SyntaxElement::Node(token.into_syntax())), + ], + )) + } } pub fn grit_predicate_maybe( maybe_token: SyntaxToken, @@ -1556,6 +1646,7 @@ pub fn grit_predicate_rewrite( fat_arrow_token, right, annotation: None, + grit_bogus: None, } } pub struct GritPredicateRewriteBuilder { @@ -1563,12 +1654,17 @@ pub struct GritPredicateRewriteBuilder { fat_arrow_token: SyntaxToken, right: AnyGritPattern, annotation: Option, + grit_bogus: Option, } impl GritPredicateRewriteBuilder { pub fn with_annotation(mut self, annotation: GritAnnotation) -> Self { self.annotation = Some(annotation); self } + pub fn with_grit_bogus(mut self, grit_bogus: GritBogus) -> Self { + self.grit_bogus = Some(grit_bogus); + self + } pub fn build(self) -> GritPredicateRewrite { GritPredicateRewrite::unwrap_cast(SyntaxNode::new_detached( GritSyntaxKind::GRIT_PREDICATE_REWRITE, @@ -1578,6 +1674,8 @@ impl GritPredicateRewriteBuilder { .map(|token| SyntaxElement::Node(token.into_syntax())), Some(SyntaxElement::Token(self.fat_arrow_token)), Some(SyntaxElement::Node(self.right.into_syntax())), + self.grit_bogus + .map(|token| SyntaxElement::Node(token.into_syntax())), ], )) } @@ -2026,6 +2124,16 @@ where { GritBogus::unwrap_cast(SyntaxNode::new_detached(GritSyntaxKind::GRIT_BOGUS, slots)) } +pub fn grit_bogus_container(slots: I) -> GritBogusContainer +where + I: IntoIterator>, + I::IntoIter: ExactSizeIterator, +{ + GritBogusContainer::unwrap_cast(SyntaxNode::new_detached( + GritSyntaxKind::GRIT_BOGUS_CONTAINER, + slots, + )) +} pub fn grit_bogus_definition(slots: I) -> GritBogusDefinition where I: IntoIterator>, diff --git a/crates/biome_grit_factory/src/generated/syntax_factory.rs b/crates/biome_grit_factory/src/generated/syntax_factory.rs index 8f8d8007832..93c68b6bc8c 100644 --- a/crates/biome_grit_factory/src/generated/syntax_factory.rs +++ b/crates/biome_grit_factory/src/generated/syntax_factory.rs @@ -15,6 +15,7 @@ impl SyntaxFactory for GritSyntaxFactory { ) -> RawSyntaxNode { match kind { GRIT_BOGUS + | GRIT_BOGUS_CONTAINER | GRIT_BOGUS_DEFINITION | GRIT_BOGUS_LITERAL | GRIT_BOGUS_NAMED_ARG @@ -876,7 +877,7 @@ impl SyntaxFactory for GritSyntaxFactory { } GRIT_LIST_ACCESSOR => { let mut elements = (&children).into_iter(); - let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); + let mut slots: RawNodeSlots<5usize> = RawNodeSlots::default(); let mut current_element = elements.next(); if let Some(element) = ¤t_element { if GritListAccessorSubject::can_cast(element.kind()) { @@ -906,6 +907,13 @@ impl SyntaxFactory for GritSyntaxFactory { } } slots.next_slot(); + if let Some(element) = ¤t_element { + if GritBogus::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( GRIT_LIST_ACCESSOR.to_bogus(), @@ -946,7 +954,7 @@ impl SyntaxFactory for GritSyntaxFactory { } GRIT_MAP_ACCESSOR => { let mut elements = (&children).into_iter(); - let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); let mut current_element = elements.next(); if let Some(element) = ¤t_element { if GritMapAccessorSubject::can_cast(element.kind()) { @@ -969,6 +977,13 @@ impl SyntaxFactory for GritSyntaxFactory { } } slots.next_slot(); + if let Some(element) = ¤t_element { + if GritBogus::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( GRIT_MAP_ACCESSOR.to_bogus(), @@ -2006,7 +2021,7 @@ impl SyntaxFactory for GritSyntaxFactory { } GRIT_PREDICATE_ASSIGNMENT => { let mut elements = (&children).into_iter(); - let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); let mut current_element = elements.next(); if let Some(element) = ¤t_element { if AnyGritContainer::can_cast(element.kind()) { @@ -2029,6 +2044,13 @@ impl SyntaxFactory for GritSyntaxFactory { } } slots.next_slot(); + if let Some(element) = ¤t_element { + if GritBogus::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( GRIT_PREDICATE_ASSIGNMENT.to_bogus(), @@ -2378,7 +2400,7 @@ impl SyntaxFactory for GritSyntaxFactory { } GRIT_PREDICATE_MATCH => { let mut elements = (&children).into_iter(); - let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); let mut current_element = elements.next(); if let Some(element) = ¤t_element { if GritPredicateMatchSubject::can_cast(element.kind()) { @@ -2401,6 +2423,13 @@ impl SyntaxFactory for GritSyntaxFactory { } } slots.next_slot(); + if let Some(element) = ¤t_element { + if GritBogus::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( GRIT_PREDICATE_MATCH.to_bogus(), @@ -2562,7 +2591,7 @@ impl SyntaxFactory for GritSyntaxFactory { } GRIT_PREDICATE_REWRITE => { let mut elements = (&children).into_iter(); - let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); + let mut slots: RawNodeSlots<5usize> = RawNodeSlots::default(); let mut current_element = elements.next(); if let Some(element) = ¤t_element { if GritVariable::can_cast(element.kind()) { @@ -2592,6 +2621,13 @@ impl SyntaxFactory for GritSyntaxFactory { } } slots.next_slot(); + if let Some(element) = ¤t_element { + if GritBogus::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( GRIT_PREDICATE_REWRITE.to_bogus(), diff --git a/crates/biome_grit_parser/src/lexer/mod.rs b/crates/biome_grit_parser/src/lexer/mod.rs index 89c56b7a8be..d1669ea9d44 100644 --- a/crates/biome_grit_parser/src/lexer/mod.rs +++ b/crates/biome_grit_parser/src/lexer/mod.rs @@ -289,6 +289,9 @@ impl<'src> Lexer<'src> { b';' => self.eat_byte(T![;]), b'.' => self.eat_byte(T![.]), b',' => self.eat_byte(T![,]), + b'+' => self.eat_plus_or_acc(), + b'*' => self.eat_byte(T![*]), + b'%' => self.eat_byte(T![%]), b'[' => self.eat_byte(T!['[']), b']' => self.eat_byte(T![']']), b'{' => self.eat_byte(T!['{']), @@ -350,6 +353,19 @@ impl<'src> Lexer<'src> { } } + fn eat_plus_or_acc(&mut self) -> GritSyntaxKind { + assert_eq!(self.current_byte(), Some(b'+')); + self.advance(1); + + match self.current_byte() { + Some(b'=') => { + self.advance(1); + T![+=] + } + _ => T![+], + } + } + #[inline] fn eat_unexpected_character(&mut self) -> GritSyntaxKind { self.assert_at_char_boundary(); @@ -461,22 +477,10 @@ impl<'src> Lexer<'src> { } match state { - LexNumberState::IntegerPart => { - if first == b'-' { - GRIT_NEGATIVE_INT - } else { - GRIT_INT - } - } + LexNumberState::IntegerPart if first == b'-' => GRIT_NEGATIVE_INT, + LexNumberState::IntegerPart => GRIT_INT, LexNumberState::FractionalPart | LexNumberState::Exponent => GRIT_DOUBLE, - LexNumberState::FirstDigit => { - let err = ParseDiagnostic::new( - "Minus must be followed by a digit", - start..self.text_position(), - ); - self.diagnostics.push(err); - ERROR_TOKEN - } + LexNumberState::FirstDigit => MINUS, LexNumberState::Invalid { position, reason } => { let diagnostic = match reason { InvalidNumberReason::Fraction => ParseDiagnostic::new( @@ -946,7 +950,16 @@ impl<'src> Lexer<'src> { self.advance(1); // Skip the leading `$`. if self.current_byte() == Some(b'_') { - return GRIT_UNDERSCORE; + self.advance(1); + return DOLLAR_UNDERSCORE; + } + + if self.current_byte() == Some(b'.') + && self.byte_at(1) == Some(b'.') + && self.byte_at(2) == Some(b'.') + { + self.advance(3); + return DOLLAR_DOT3; } while let Some(byte) = self.current_byte() { @@ -1016,7 +1029,10 @@ impl<'src> Lexer<'src> { COMMENT } - _ => self.eat_unexpected_character(), + _ => { + self.advance(1); + T![/] + } } } } diff --git a/crates/biome_grit_parser/src/lexer/tests.rs b/crates/biome_grit_parser/src/lexer/tests.rs index 9a03be4aac8..84c20f412c9 100644 --- a/crates/biome_grit_parser/src/lexer/tests.rs +++ b/crates/biome_grit_parser/src/lexer/tests.rs @@ -142,7 +142,7 @@ fn negative() { fn minus_without_number() { assert_lex! { "-", - ERROR_TOKEN:1, + MINUS:1, EOF:0 } } diff --git a/crates/biome_grit_parser/src/lib.rs b/crates/biome_grit_parser/src/lib.rs index ff1d61e8c6c..44263787f3f 100644 --- a/crates/biome_grit_parser/src/lib.rs +++ b/crates/biome_grit_parser/src/lib.rs @@ -29,6 +29,7 @@ pub fn parse_grit_with_cache(source: &str, cache: &mut NodeCache) -> GritParse { let mut tree_sink = GritLosslessTreeSink::with_cache(source, &trivia, cache); biome_parser::event::process(&mut tree_sink, events, diagnostics); let (green, diagnostics) = tree_sink.finish(); + println!("{green:#?}"); GritParse::new(green, diagnostics) }) diff --git a/crates/biome_grit_parser/src/parser/constants.rs b/crates/biome_grit_parser/src/parser/constants.rs new file mode 100644 index 00000000000..5e4e6bb5afd --- /dev/null +++ b/crates/biome_grit_parser/src/parser/constants.rs @@ -0,0 +1,37 @@ +use biome_grit_syntax::GritSyntaxKind::{self, *}; +use biome_grit_syntax::T; +use biome_parser::{token_set, TokenSet}; + +pub(crate) const ACCESSOR_RECOVERY_SET: TokenSet = + token_set!(T![,], T![')'], T!['}'], T![']']); + +pub(crate) const ARG_LIST_RECOVERY_SET: TokenSet = token_set!(T![,], T![')']); + +pub(crate) const BOOLEAN_VALUE_SET: TokenSet = token_set![TRUE_KW, FALSE_KW]; + +pub(crate) const CODE_SNIPPET_SET: TokenSet = + SUPPORTED_LANGUAGE_SET.union(token_set![GRIT_BACKTICK_SNIPPET, GRIT_RAW_BACKTICK_SNIPPET]); + +pub(crate) const CONTAINER_SET: TokenSet = + token_set![GRIT_VARIABLE, GRIT_MAP_ACCESSOR, GRIT_LIST_ACCESSOR]; + +pub(crate) const ELEMENT_LIST_RECOVERY_SET: TokenSet = token_set!(T![,], T!['}']); + +pub(crate) const LANGUAGE_NAME_RECOVERY_SET: TokenSet = token_set!(T!['('], T![;]); + +pub(crate) const LANGUAGE_FLAVOR_RECOVERY_SET: TokenSet = + token_set!(T![')'], T![,], T![;]); + +pub(crate) const NOT_SET: TokenSet = token_set![NOT_KW, T![!]]; + +pub(crate) const PATTERN_RECOVERY_SET: TokenSet = token_set!(T![')'], EOF); + +pub(crate) const PREDICATE_RECOVERY_SET: TokenSet = token_set!(T![')']); + +pub(crate) const REGEX_SET: TokenSet = token_set![GRIT_REGEX, GRIT_SNIPPET_REGEX]; + +pub(crate) const SUPPORTED_LANGUAGE_SET: TokenSet = + token_set![T![js], T![json], T![css], T![grit], T![html]]; + +pub(crate) const SUPPORTED_LANGUAGE_FLAVOR_SET: TokenSet = + token_set![T![typescript], T![jsx]]; diff --git a/crates/biome_grit_parser/src/parser/literals.rs b/crates/biome_grit_parser/src/parser/literals.rs index fbfe6b40860..259d06df7a9 100644 --- a/crates/biome_grit_parser/src/parser/literals.rs +++ b/crates/biome_grit_parser/src/parser/literals.rs @@ -1,12 +1,13 @@ -use super::{GritParser, SUPPORTED_LANGUAGE_SET}; -use biome_grit_syntax::GritSyntaxKind::{self, *}; +use super::constants::*; +use super::parse_error::expected_pattern; +use super::parse_name; +use super::patterns::{parse_maybe_curly_pattern, parse_pattern}; +use super::GritParser; +use biome_grit_syntax::GritSyntaxKind::*; +use biome_grit_syntax::T; +use biome_parser::parse_recovery::ParseRecoveryTokenSet; use biome_parser::prelude::{ParsedSyntax::*, *}; -const BOOLEAN_VALUE_SET: TokenSet = token_set![TRUE_KW, FALSE_KW]; - -const CODE_SNIPPET_SET: TokenSet = - SUPPORTED_LANGUAGE_SET.union(token_set![GRIT_BACKTICK_SNIPPET, GRIT_RAW_BACKTICK_SNIPPET]); - pub(crate) fn parse_literal(p: &mut GritParser) -> ParsedSyntax { match p.cur() { TRUE_KW | FALSE_KW => parse_boolean_literal(p), @@ -15,9 +16,9 @@ pub(crate) fn parse_literal(p: &mut GritParser) -> ParsedSyntax { GRIT_NEGATIVE_INT => parse_negative_int_literal(p), GRIT_STRING => parse_string_literal(p), UNDEFINED_KW => parse_undefined_literal(p), + T!['{'] => parse_map(p), + GRIT_NAME | T!['['] => parse_list(p), kind if CODE_SNIPPET_SET.contains(kind) => parse_code_snippet(p), - // TODO: List - // TODO: Map _ => Absent, } } @@ -67,6 +68,18 @@ fn parse_code_snippet(p: &mut GritParser) -> ParsedSyntax { } } +#[inline] +fn parse_dotdotdot(p: &mut GritParser) -> ParsedSyntax { + if !p.at(DOLLAR_DOT3) { + return Absent; + } + + let m = p.start(); + p.bump(DOLLAR_DOT3); + let _ = parse_maybe_curly_pattern(p); + Present(m.complete(p, GRIT_DOTDOTDOT)) +} + #[inline] pub(crate) fn parse_double_literal(p: &mut GritParser) -> ParsedSyntax { if !p.at(GRIT_DOUBLE) { @@ -79,7 +92,7 @@ pub(crate) fn parse_double_literal(p: &mut GritParser) -> ParsedSyntax { } #[inline] -fn parse_int_literal(p: &mut GritParser) -> ParsedSyntax { +pub(crate) fn parse_int_literal(p: &mut GritParser) -> ParsedSyntax { if !p.at(GRIT_INT) { return Absent; } @@ -109,7 +122,106 @@ fn parse_language_specific_snippet(p: &mut GritParser) -> ParsedSyntax { } #[inline] -fn parse_negative_int_literal(p: &mut GritParser) -> ParsedSyntax { +pub(crate) fn parse_list(p: &mut GritParser) -> ParsedSyntax { + if !p.at(T!['[']) && !p.at(GRIT_NAME) { + return Absent; + } + + let m = p.start(); + let _ = parse_name(p); + + if !p.eat(T!['[']) { + m.abandon(p); + return Absent; + } + + let _ = parse_list_pattern_list(p); + + p.eat(T![']']); + Present(m.complete(p, GRIT_LIST)) +} + +#[inline] +fn parse_list_pattern_list(p: &mut GritParser) -> ParsedSyntax { + let m = p.start(); + + if parse_list_pattern(p) == Absent { + m.abandon(p); + return Absent; + } + + while p.eat(T![,]) { + if parse_list_pattern(p) == Absent { + break; + } + } + + Present(m.complete(p, GRIT_LIST_PATTERN_LIST)) +} + +#[inline] +fn parse_list_pattern(p: &mut GritParser) -> ParsedSyntax { + if p.at(DOLLAR_DOT3) { + parse_dotdotdot(p) + } else { + parse_literal(p) + } +} + +#[inline] +pub(crate) fn parse_map(p: &mut GritParser) -> ParsedSyntax { + if !p.at(T!['{']) { + return Absent; + } + + let m = p.start(); + p.bump(T!['{']); + + let _ = parse_map_element_list(p); + + p.eat(T!['}']); + Present(m.complete(p, GRIT_MAP)) +} + +#[inline] +fn parse_map_element_list(p: &mut GritParser) -> ParsedSyntax { + let m = p.start(); + + if parse_map_element(p) == Absent { + m.abandon(p); + return Absent; + } + + while p.eat(T![,]) { + if parse_map_element(p) == Absent { + break; + } + } + + Present(m.complete(p, GRIT_MAP_ELEMENT_LIST)) +} + +#[inline] +fn parse_map_element(p: &mut GritParser) -> ParsedSyntax { + if !p.at(GRIT_NAME) { + return Absent; + } + + let m = p.start(); + let _ = parse_name(p); + p.eat(T![:]); + + let _ = parse_pattern(p).or_recover_with_token_set( + p, + &ParseRecoveryTokenSet::new(GRIT_BOGUS, ELEMENT_LIST_RECOVERY_SET), + expected_pattern, + ); + + Present(m.complete(p, GRIT_MAP_ELEMENT)) +} + +#[inline] +pub(crate) fn parse_negative_int_literal(p: &mut GritParser) -> ParsedSyntax { if !p.at(GRIT_NEGATIVE_INT) { return Absent; } diff --git a/crates/biome_grit_parser/src/parser/mod.rs b/crates/biome_grit_parser/src/parser/mod.rs index 6a1c0a5239a..d721c0c4799 100644 --- a/crates/biome_grit_parser/src/parser/mod.rs +++ b/crates/biome_grit_parser/src/parser/mod.rs @@ -1,3 +1,4 @@ +mod constants; mod literals; mod parse_error; mod patterns; @@ -13,20 +14,12 @@ use biome_parser::prelude::{ParsedSyntax::*, *}; use biome_parser::token_source::Trivia; use biome_parser::ParserContext; use biome_rowan::TextRange; +use constants::*; use literals::parse_double_literal; use patterns::parse_pattern; use self::parse_error::{expected_language_flavor, expected_language_name}; -const LANGUAGE_NAME_RECOVERY_SET: TokenSet = token_set!(T!['('], T![;]); - -const LANGUAGE_FLAVOR_RECOVERY_SET: TokenSet = token_set!(T![')'], T![,], T![;]); - -const SUPPORTED_LANGUAGE_SET: TokenSet = - token_set![T![js], T![json], T![css], T![grit], T![html]]; - -const SUPPORTED_LANGUAGE_FLAVOR_SET: TokenSet = token_set![T![typescript], T![jsx]]; - pub(crate) struct GritParser<'source> { context: ParserContext, source: GritTokenSource<'source>, diff --git a/crates/biome_grit_parser/src/parser/parse_error.rs b/crates/biome_grit_parser/src/parser/parse_error.rs index 94c1fd8b3fe..244b4d5a661 100644 --- a/crates/biome_grit_parser/src/parser/parse_error.rs +++ b/crates/biome_grit_parser/src/parser/parse_error.rs @@ -18,6 +18,14 @@ pub(crate) fn expected_language_flavor(p: &GritParser, range: TextRange) -> Pars ) } +pub(crate) fn expected_list_index(p: &GritParser, range: TextRange) -> ParseDiagnostic { + expected_node("list index", range, p) +} + +pub(crate) fn expected_map_key(p: &GritParser, range: TextRange) -> ParseDiagnostic { + expected_node("map key", range, p) +} + pub(crate) fn expected_pattern(p: &GritParser, range: TextRange) -> ParseDiagnostic { expected_node("pattern", range, p) } diff --git a/crates/biome_grit_parser/src/parser/patterns.rs b/crates/biome_grit_parser/src/parser/patterns.rs index 6630cd3accb..86b8ad8e48c 100644 --- a/crates/biome_grit_parser/src/parser/patterns.rs +++ b/crates/biome_grit_parser/src/parser/patterns.rs @@ -1,18 +1,13 @@ -use super::literals::parse_literal; -use super::parse_error::expected_pattern; +use super::constants::*; +use super::literals::*; +use super::parse_error::{expected_list_index, expected_map_key, expected_pattern}; use super::predicates::parse_predicate; -use super::{parse_name, parse_variable_list, GritParser}; +use super::{parse_name, parse_variable, parse_variable_list, GritParser}; use biome_grit_syntax::GritSyntaxKind::{self, *}; use biome_grit_syntax::T; use biome_parser::parse_recovery::{ParseRecovery, ParseRecoveryTokenSet}; use biome_parser::prelude::{ParsedSyntax::*, *}; -const ARG_LIST_RECOVERY_SET: TokenSet = token_set!(T![,], T![')']); - -const NOT_SET: TokenSet = token_set![NOT_KW, T![!]]; - -const REGEX_SET: TokenSet = token_set![GRIT_REGEX, GRIT_SNIPPET_REGEX]; - pub(crate) fn parse_pattern(p: &mut GritParser) -> ParsedSyntax { let left = match p.cur() { NOT_KW | T![!] => parse_pattern_not(p), @@ -29,26 +24,12 @@ pub(crate) fn parse_pattern(p: &mut GritParser) -> ParsedSyntax { WITHIN_KW => parse_pattern_within(p), BUBBLE_KW => parse_bubble(p), GRIT_NAME => parse_node_like(p), - // TODO: GritMapAccessor => {} - // TODO: GritListAccessor => {} T![.] => parse_dot(p), SOME_KW => parse_some(p), EVERY_KW => parse_every(p), - GRIT_UNDERSCORE => { - let m = p.start(); - p.bump(GRIT_UNDERSCORE); - Present(m.complete(p, GRIT_UNDERSCORE)) - } - GRIT_VARIABLE => { - let m = p.start(); - p.bump(GRIT_VARIABLE); - Present(m.complete(p, GRIT_VARIABLE)) - } + GRIT_UNDERSCORE => parse_grit_undescore(p), + GRIT_VARIABLE => parse_variable(p), GRIT_REGEX | GRIT_SNIPPET_REGEX => parse_regex_pattern(p), - // TODO: GritPatternAs => {} - // TODO: GritPatternLimit => {} - // TODO: GritAssignmentAsPattern => {} - // TODO: GritPatternAccumulate => {} LIKE_KW => parse_like(p), // TODO: GritMulOperation => {} // TODO: GritDivOperation => {} @@ -61,15 +42,55 @@ pub(crate) fn parse_pattern(p: &mut GritParser) -> ParsedSyntax { _ => parse_literal(p), }; - if left == Absent { + let Present(left) = left else { return Absent; - } + }; - match p.cur() { + let left = match p.cur() { + AS_KW => parse_pattern_as(p, left), + _ => Present(left), + }; + + let Present(left) = left else { + return Absent; + }; + + let left = match p.cur() { T![=>] => parse_rewrite(p, left), + T![.] => parse_map_accessor(p, left), + T!['['] => parse_list_accessor(p, left), + LIMIT_KW => parse_pattern_limit(p, left), WHERE_KW => parse_pattern_where(p, left), - _ => left, + _ => Present(left), + }; + + let Present(left) = left else { + return Absent; + }; + + match p.cur() { + T![=] if CONTAINER_SET.contains(left.kind(p)) => parse_assignment_as_pattern(p, left), + T![+=] => parse_pattern_accumulate(p, left), + _ => Present(left), + } +} + +#[inline] +fn parse_assignment_as_pattern(p: &mut GritParser, left: CompletedMarker) -> ParsedSyntax { + if !p.at(T![=]) { + return Absent; } + + let m = left.precede(p); + p.bump(T![=]); + + let _ = parse_pattern(p).or_recover_with_token_set( + p, + &ParseRecoveryTokenSet::new(GRIT_BOGUS_PATTERN, PATTERN_RECOVERY_SET), + expected_pattern, + ); + + Present(m.complete(p, GRIT_ASSIGNMENT_AS_PATTERN)) } #[inline] @@ -134,6 +155,27 @@ fn parse_bubble_scope(p: &mut GritParser) -> ParsedSyntax { Present(m.complete(p, GRIT_BUBBLE)) } +#[inline] +pub(crate) fn parse_container(p: &mut GritParser) -> ParsedSyntax { + let left = match p.cur() { + GRIT_VARIABLE => parse_variable(p), + T!['{'] => parse_map(p), + GRIT_NAME | T!['['] => parse_list(p), + _ => Absent, + }; + + let Present(left) = left else { + return Absent; + }; + + match p.cur() { + T![.] => parse_map_accessor(p, left), + T!['['] => parse_list_accessor(p, left), + _ if left.kind(p) == GRIT_VARIABLE => Present(left), + _ => Absent, + } +} + #[inline] fn parse_curly_pattern(p: &mut GritParser) -> ParsedSyntax { if !p.at(T!['{']) { @@ -209,6 +251,17 @@ fn parse_files(p: &mut GritParser) -> ParsedSyntax { } } +#[inline] +fn parse_grit_undescore(p: &mut GritParser) -> ParsedSyntax { + if !p.at(GRIT_UNDERSCORE) { + return Absent; + } + + let m = p.start(); + p.bump(GRIT_UNDERSCORE); + Present(m.complete(p, GRIT_UNDERSCORE)) +} + #[inline] fn parse_like(p: &mut GritParser) -> ParsedSyntax { if !p.at(LIKE_KW) { @@ -258,7 +311,77 @@ fn parse_like_threshold(p: &mut GritParser) -> ParsedSyntax { } #[inline] -fn parse_maybe_curly_pattern(p: &mut GritParser) -> ParsedSyntax { +pub(crate) fn parse_list_accessor(p: &mut GritParser, left: CompletedMarker) -> ParsedSyntax { + if !p.at(T!['[']) { + return Absent; + } + + let m = left.precede(p); + p.bump(T!['[']); + + let _ = parse_list_index(p).or_recover_with_token_set( + p, + &ParseRecoveryTokenSet::new(GRIT_BOGUS, ACCESSOR_RECOVERY_SET), + expected_list_index, + ); + + p.eat(T![']']); + + // FIXME: We should check whether the accessor needs to be extended. + + Present(m.complete(p, GRIT_LIST_ACCESSOR)) +} + +#[inline] +fn parse_list_index(p: &mut GritParser) -> ParsedSyntax { + let m = p.start(); + + let _ = match p.cur() { + GRIT_INT => parse_int_literal(p), + GRIT_NEGATIVE_INT => parse_negative_int_literal(p), + _ => match parse_container(p) { + Present(syntax) => Present(syntax), + Absent => { + m.abandon(p); + return Absent; + } + }, + }; + + Present(m.complete(p, GRIT_LIST_INDEX)) +} + +#[inline] +pub(crate) fn parse_map_accessor(p: &mut GritParser, left: CompletedMarker) -> ParsedSyntax { + if !p.at(T![.]) { + return Absent; + } + + let m = left.precede(p); + p.bump(T![.]); + + let _ = parse_map_key(p).or_recover_with_token_set( + p, + &ParseRecoveryTokenSet::new(GRIT_BOGUS, ACCESSOR_RECOVERY_SET), + expected_map_key, + ); + + // FIXME: We should check whether the accessor needs to be extended. + + Present(m.complete(p, GRIT_MAP_ACCESSOR)) +} + +#[inline] +fn parse_map_key(p: &mut GritParser) -> ParsedSyntax { + match p.cur() { + GRIT_NAME => parse_name(p), + GRIT_VARIABLE => parse_variable(p), + _ => Absent, + } +} + +#[inline] +pub(crate) fn parse_maybe_curly_pattern(p: &mut GritParser) -> ParsedSyntax { if p.at(T!['{']) { parse_curly_pattern(p) } else { @@ -348,6 +471,24 @@ fn parse_node_like(p: &mut GritParser) -> ParsedSyntax { Present(m.complete(p, GRIT_NODE_LIKE)) } +#[inline] +fn parse_pattern_accumulate(p: &mut GritParser, left: CompletedMarker) -> ParsedSyntax { + if !p.at(T![+=]) { + return Absent; + } + + let m = left.precede(p); + p.bump(T![+=]); + + let _ = parse_pattern(p).or_recover_with_token_set( + p, + &ParseRecoveryTokenSet::new(GRIT_BOGUS_PATTERN, PATTERN_RECOVERY_SET), + expected_pattern, + ); + + Present(m.complete(p, GRIT_PATTERN_ACCUMULATE)) +} + #[inline] fn parse_pattern_after(p: &mut GritParser) -> ParsedSyntax { if !p.at(AFTER_KW) { @@ -431,6 +572,24 @@ fn parse_pattern_arg_list(p: &mut GritParser) -> ParsedSyntax { } } +#[inline] +fn parse_pattern_as(p: &mut GritParser, left: CompletedMarker) -> ParsedSyntax { + if !p.at(AS_KW) { + return Absent; + } + + let m = left.precede(p); + p.bump(AS_KW); + + match parse_variable(p) { + Present(_) => Present(m.complete(p, GRIT_PATTERN_AS)), + Absent => { + m.abandon(p); + Absent + } + } +} + #[inline] fn parse_pattern_before(p: &mut GritParser) -> ParsedSyntax { if !p.at(BEFORE_KW) { @@ -545,6 +704,24 @@ fn parse_pattern_includes(p: &mut GritParser) -> ParsedSyntax { } } +#[inline] +fn parse_pattern_limit(p: &mut GritParser, left: CompletedMarker) -> ParsedSyntax { + if !p.at(LIMIT_KW) { + return Absent; + } + + let m = left.precede(p); + p.bump(LIMIT_KW); + + match parse_int_literal(p) { + Present(_) => Present(m.complete(p, GRIT_PATTERN_LIMIT)), + Absent => { + m.abandon(p); + Absent + } + } +} + #[inline] fn parse_pattern_list(p: &mut GritParser) -> ParsedSyntax { let m = p.start(); @@ -642,7 +819,7 @@ fn parse_pattern_orelse(p: &mut GritParser) -> ParsedSyntax { } #[inline] -fn parse_pattern_where(p: &mut GritParser, left: ParsedSyntax) -> ParsedSyntax { +fn parse_pattern_where(p: &mut GritParser, left: CompletedMarker) -> ParsedSyntax { if !p.at(WHERE_KW) { return Absent; } @@ -684,7 +861,15 @@ fn parse_regex_pattern(p: &mut GritParser) -> ParsedSyntax { } let m = p.start(); - p.bump_ts(REGEX_SET); + if p.cur() == GRIT_REGEX { + let m = p.start(); + p.bump(GRIT_REGEX); + m.complete(p, GRIT_REGEX_LITERAL); + } else { + let m = p.start(); + p.bump(GRIT_SNIPPET_REGEX); + m.complete(p, GRIT_SNIPPET_REGEX_LITERAL); + } let _ = parse_regex_pattern_variables(p); @@ -708,7 +893,7 @@ fn parse_regex_pattern_variables(p: &mut GritParser) -> ParsedSyntax { } #[inline] -fn parse_rewrite(p: &mut GritParser, left: ParsedSyntax) -> ParsedSyntax { +fn parse_rewrite(p: &mut GritParser, left: CompletedMarker) -> ParsedSyntax { if !p.at(T![=>]) { return Absent; } diff --git a/crates/biome_grit_parser/src/parser/predicates.rs b/crates/biome_grit_parser/src/parser/predicates.rs index 2eccd910c14..53439668c5d 100644 --- a/crates/biome_grit_parser/src/parser/predicates.rs +++ b/crates/biome_grit_parser/src/parser/predicates.rs @@ -1,12 +1,13 @@ +use super::constants::*; use super::literals::{parse_boolean_literal, parse_literal}; -use super::patterns::parse_pattern; +use super::parse_error::expected_pattern; +use super::patterns::{parse_container, parse_pattern}; use super::GritParser; -use biome_grit_syntax::GritSyntaxKind::{self, *}; +use biome_grit_syntax::GritSyntaxKind::*; use biome_grit_syntax::T; +use biome_parser::parse_recovery::ParseRecoveryTokenSet; use biome_parser::prelude::{ParsedSyntax::*, *}; -const NOT_SET: TokenSet = token_set![NOT_KW, T![!]]; - pub(crate) fn parse_predicate(p: &mut GritParser) -> ParsedSyntax { match p.cur() { NOT_KW | T![!] => parse_predicate_not(p), @@ -15,8 +16,6 @@ pub(crate) fn parse_predicate(p: &mut GritParser) -> ParsedSyntax { OR_KW => parse_predicate_or(p), ANY_KW => parse_predicate_any(p), IF_KW => parse_predicate_if_else(p), - // TODO: GritPredicateAssignment => {} - // TODO: GritPredicateAccumulate => {} // TODO: GritPredicateRewrite => {} // TODO: GritPredicateGreater => {} // TODO: GritPredicateLess => {} @@ -28,7 +27,7 @@ pub(crate) fn parse_predicate(p: &mut GritParser) -> ParsedSyntax { T!['('] => parse_bracketed_predicate(p), T![true] | T![false] => parse_boolean_literal(p), // TODO: GritPredicateReturn => {} - _ => parse_predicate_match(p), + _ => parse_infix_predicate(p), } } @@ -54,6 +53,63 @@ fn parse_bracketed_predicate(p: &mut GritParser) -> ParsedSyntax { } } +enum InfixPredicateKind { + Accumulate, + Assignment, + Match, + Rewrite, +} + +/// Parses any of the infix predicates without need for backtracking. +#[inline] +fn parse_infix_predicate(p: &mut GritParser) -> ParsedSyntax { + let m = p.start(); + + let Present(mut subject) = parse_container(p).or_else(|| parse_literal(p)) else { + m.abandon(p); + return Absent; + }; + + use InfixPredicateKind::*; + let kind = match p.cur() { + T![+=] => Accumulate, + T![=] => Assignment, + T![<:] => Match, + T![=>] => Rewrite, + _ => { + m.abandon(p); + return Absent; + } + }; + + // Verify the subjects are allowed for the matched predicate kind: + match kind { + Accumulate | Rewrite if subject.kind(p) != GRIT_VARIABLE => { + subject.change_to_bogus(p); + } + Assignment if !CONTAINER_SET.contains(subject.kind(p)) => { + subject.change_to_bogus(p); + } + _ => {} + } + + p.bump_any(); + + let _ = parse_pattern(p).or_recover_with_token_set( + p, + &ParseRecoveryTokenSet::new(GRIT_BOGUS, PREDICATE_RECOVERY_SET), + expected_pattern, + ); + + let kind = match kind { + Accumulate => GRIT_PREDICATE_ACCUMULATE, + Assignment => GRIT_PREDICATE_ASSIGNMENT, + Match => GRIT_PREDICATE_MATCH, + Rewrite => GRIT_PREDICATE_REWRITE, + }; + Present(m.complete(p, kind)) +} + #[inline] fn parse_predicate_and(p: &mut GritParser) -> ParsedSyntax { if !p.at(AND_KW) && !p.at(T!['{']) { @@ -68,17 +124,11 @@ fn parse_predicate_and(p: &mut GritParser) -> ParsedSyntax { return Present(m.complete(p, GRIT_PREDICATE_AND)); } - let result = parse_predicate_list(p); + let _ = parse_predicate_list(p); p.eat(T!['}']); - match result { - Present(_) => Present(m.complete(p, GRIT_PREDICATE_AND)), - Absent => { - m.abandon(p); - Absent - } - } + Present(m.complete(p, GRIT_PREDICATE_AND)) } #[inline] @@ -165,39 +215,6 @@ fn parse_predicate_list(p: &mut GritParser) -> ParsedSyntax { Present(m.complete(p, GRIT_PREDICATE_LIST)) } -#[inline] -fn parse_predicate_match(p: &mut GritParser) -> ParsedSyntax { - let m = p.start(); - - if parse_predicate_match_subject(p) == Absent { - m.abandon(p); - return Absent; - } - - if !p.eat(T![<:]) { - m.abandon(p); - return Absent; - } - - let _ = parse_pattern(p); - - Present(m.complete(p, GRIT_PREDICATE_MATCH)) -} - -#[inline] -fn parse_predicate_match_subject(p: &mut GritParser) -> ParsedSyntax { - match p.cur() { - GRIT_VARIABLE => { - let m = p.start(); - p.bump(GRIT_VARIABLE); - Present(m.complete(p, GRIT_VARIABLE)) - } - // TODO: GritMapAccessor => {} - // TODO: GritListAccessor => {} - _ => parse_literal(p), - } -} - #[inline] fn parse_predicate_maybe(p: &mut GritParser) -> ParsedSyntax { if !p.at(MAYBE_KW) { diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/create_new_files.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/create_new_files.grit new file mode 100644 index 00000000000..68267a45df3 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/create_new_files.grit @@ -0,0 +1,6 @@ +`function $functionName($_) {$_}` as $f where { + $functionName <: r"test.*", + $f => ., + $new_file_name = `$functionName.test.js`, + $new_files += file(name = $new_file_name, body = $f) +} diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/create_new_files.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/create_new_files.grit.snap new file mode 100644 index 00000000000..39f5996e47a --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/create_new_files.grit.snap @@ -0,0 +1,199 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +`function $functionName($_) {$_}` as $f where { + $functionName <: r"test.*", + $f => ., + $new_file_name = `$functionName.test.js`, + $new_files += file(name = $new_file_name, body = $f) +} + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: missing (optional), + definitions: GritDefinitionList [], + pattern: GritPatternWhere { + pattern: GritPatternAs { + pattern: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@0..34 "`function $functionName($_) {$_}`" [] [Whitespace(" ")], + }, + }, + as_token: AS_KW@34..37 "as" [] [Whitespace(" ")], + variable: GritVariable { + grit_variable_token: GRIT_VARIABLE@37..40 "$f" [] [Whitespace(" ")], + }, + }, + where_token: WHERE_KW@40..46 "where" [] [Whitespace(" ")], + side_condition: GritPredicateAnd { + and_token: missing (optional), + l_curly_token: L_CURLY@46..47 "{" [] [], + predicates: GritPredicateList [ + GritPredicateMatch { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@47..64 "$functionName" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + match_token: MATCH@64..67 "<:" [] [Whitespace(" ")], + right: GritRegexPattern { + regex: GritRegexLiteral { + value_token: GRIT_REGEX@67..76 "r\"test.*\"" [] [], + }, + variables: missing (optional), + }, + grit_bogus: missing (optional), + }, + COMMA@76..77 "," [] [], + GritPredicateRewrite { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@77..83 "$f" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + annotation: missing (optional), + fat_arrow_token: FAT_ARROW@83..86 "=>" [] [Whitespace(" ")], + right: GritDot { + dot_token: DOT@86..87 "." [] [], + }, + grit_bogus: missing (optional), + }, + COMMA@87..88 "," [] [], + GritPredicateAssignment { + container: GritVariable { + grit_variable_token: GRIT_VARIABLE@88..106 "$new_file_name" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + eq_token: EQ@106..108 "=" [] [Whitespace(" ")], + pattern: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@108..131 "`$functionName.test.js`" [] [], + }, + }, + grit_bogus: missing (optional), + }, + COMMA@131..132 "," [] [], + GritPredicateAccumulate { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@132..146 "$new_files" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + add_assign_token: PLUSEQ@146..149 "+=" [] [Whitespace(" ")], + right: GritNodeLike { + name: GritName { + grit_name_token: GRIT_NAME@149..153 "file" [] [], + }, + l_paren_token: L_PAREN@153..154 "(" [] [], + named_args: GritNamedArgList [ + GritNamedArg { + name: GritName { + grit_name_token: GRIT_NAME@154..159 "name" [] [Whitespace(" ")], + }, + eq_token: EQ@159..161 "=" [] [Whitespace(" ")], + pattern: GritVariable { + grit_variable_token: GRIT_VARIABLE@161..175 "$new_file_name" [] [], + }, + }, + COMMA@175..177 "," [] [Whitespace(" ")], + GritNamedArg { + name: GritName { + grit_name_token: GRIT_NAME@177..182 "body" [] [Whitespace(" ")], + }, + eq_token: EQ@182..184 "=" [] [Whitespace(" ")], + pattern: GritVariable { + grit_variable_token: GRIT_VARIABLE@184..186 "$f" [] [], + }, + }, + ], + r_paren_token: R_PAREN@186..187 ")" [] [], + }, + }, + ], + r_curly_token: R_CURLY@187..189 "}" [Newline("\n")] [], + }, + }, + definitions_continued: GritDefinitionList [], + eof_token: EOF@189..190 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..190 + 0: (empty) + 1: (empty) + 2: (empty) + 3: GRIT_DEFINITION_LIST@0..0 + 4: GRIT_PATTERN_WHERE@0..189 + 0: GRIT_PATTERN_AS@0..40 + 0: GRIT_CODE_SNIPPET@0..34 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@0..34 + 0: GRIT_BACKTICK_SNIPPET@0..34 "`function $functionName($_) {$_}`" [] [Whitespace(" ")] + 1: AS_KW@34..37 "as" [] [Whitespace(" ")] + 2: GRIT_VARIABLE@37..40 + 0: GRIT_VARIABLE@37..40 "$f" [] [Whitespace(" ")] + 1: WHERE_KW@40..46 "where" [] [Whitespace(" ")] + 2: GRIT_PREDICATE_AND@46..189 + 0: (empty) + 1: L_CURLY@46..47 "{" [] [] + 2: GRIT_PREDICATE_LIST@47..187 + 0: GRIT_PREDICATE_MATCH@47..76 + 0: GRIT_VARIABLE@47..64 + 0: GRIT_VARIABLE@47..64 "$functionName" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: MATCH@64..67 "<:" [] [Whitespace(" ")] + 2: GRIT_REGEX_PATTERN@67..76 + 0: GRIT_REGEX_LITERAL@67..76 + 0: GRIT_REGEX@67..76 "r\"test.*\"" [] [] + 1: (empty) + 3: (empty) + 1: COMMA@76..77 "," [] [] + 2: GRIT_PREDICATE_REWRITE@77..87 + 0: GRIT_VARIABLE@77..83 + 0: GRIT_VARIABLE@77..83 "$f" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: (empty) + 2: FAT_ARROW@83..86 "=>" [] [Whitespace(" ")] + 3: GRIT_DOT@86..87 + 0: DOT@86..87 "." [] [] + 4: (empty) + 3: COMMA@87..88 "," [] [] + 4: GRIT_PREDICATE_ASSIGNMENT@88..131 + 0: GRIT_VARIABLE@88..106 + 0: GRIT_VARIABLE@88..106 "$new_file_name" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: EQ@106..108 "=" [] [Whitespace(" ")] + 2: GRIT_CODE_SNIPPET@108..131 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@108..131 + 0: GRIT_BACKTICK_SNIPPET@108..131 "`$functionName.test.js`" [] [] + 3: (empty) + 5: COMMA@131..132 "," [] [] + 6: GRIT_PREDICATE_ACCUMULATE@132..187 + 0: GRIT_VARIABLE@132..146 + 0: GRIT_VARIABLE@132..146 "$new_files" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: PLUSEQ@146..149 "+=" [] [Whitespace(" ")] + 2: GRIT_NODE_LIKE@149..187 + 0: GRIT_NAME@149..153 + 0: GRIT_NAME@149..153 "file" [] [] + 1: L_PAREN@153..154 "(" [] [] + 2: GRIT_NAMED_ARG_LIST@154..186 + 0: GRIT_NAMED_ARG@154..175 + 0: GRIT_NAME@154..159 + 0: GRIT_NAME@154..159 "name" [] [Whitespace(" ")] + 1: EQ@159..161 "=" [] [Whitespace(" ")] + 2: GRIT_VARIABLE@161..175 + 0: GRIT_VARIABLE@161..175 "$new_file_name" [] [] + 1: COMMA@175..177 "," [] [Whitespace(" ")] + 2: GRIT_NAMED_ARG@177..186 + 0: GRIT_NAME@177..182 + 0: GRIT_NAME@177..182 "body" [] [Whitespace(" ")] + 1: EQ@182..184 "=" [] [Whitespace(" ")] + 2: GRIT_VARIABLE@184..186 + 0: GRIT_VARIABLE@184..186 "$f" [] [] + 3: R_PAREN@186..187 ")" [] [] + 3: R_CURLY@187..189 "}" [Newline("\n")] [] + 5: GRIT_DEFINITION_LIST@189..189 + 6: EOF@189..190 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/map.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/map.grit new file mode 100644 index 00000000000..963562536df --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/map.grit @@ -0,0 +1,5 @@ +`const capital = $val` where { + $capitals = { england: `london`, ours: $val }, + $capitals.ours <: `paris`, + $val => $capitals.england, +} diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/map.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/map.grit.snap new file mode 100644 index 00000000000..93dea718217 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/map.grit.snap @@ -0,0 +1,190 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +`const capital = $val` where { + $capitals = { england: `london`, ours: $val }, + $capitals.ours <: `paris`, + $val => $capitals.england, +} + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: missing (optional), + definitions: GritDefinitionList [], + pattern: GritPatternWhere { + pattern: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@0..23 "`const capital = $val`" [] [Whitespace(" ")], + }, + }, + where_token: WHERE_KW@23..29 "where" [] [Whitespace(" ")], + side_condition: GritPredicateAnd { + and_token: missing (optional), + l_curly_token: L_CURLY@29..30 "{" [] [], + predicates: GritPredicateList [ + GritPredicateAssignment { + container: GritVariable { + grit_variable_token: GRIT_VARIABLE@30..43 "$capitals" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + eq_token: EQ@43..45 "=" [] [Whitespace(" ")], + pattern: GritMap { + l_curly_token: L_CURLY@45..47 "{" [] [Whitespace(" ")], + elements: GritMapElementList [ + GritMapElement { + key: GritName { + grit_name_token: GRIT_NAME@47..54 "england" [] [], + }, + colon_token: COLON@54..56 ":" [] [Whitespace(" ")], + value: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@56..64 "`london`" [] [], + }, + }, + }, + COMMA@64..66 "," [] [Whitespace(" ")], + GritMapElement { + key: GritName { + grit_name_token: GRIT_NAME@66..70 "ours" [] [], + }, + colon_token: COLON@70..72 ":" [] [Whitespace(" ")], + value: GritVariable { + grit_variable_token: GRIT_VARIABLE@72..77 "$val" [] [Whitespace(" ")], + }, + }, + ], + r_curly_token: R_CURLY@77..78 "}" [] [], + }, + grit_bogus: missing (optional), + }, + COMMA@78..79 "," [] [], + GritPredicateMatch { + left: GritMapAccessor { + map: GritVariable { + grit_variable_token: GRIT_VARIABLE@79..91 "$capitals" [Newline("\n"), Whitespace(" ")] [], + }, + dot_token: DOT@91..92 "." [] [], + key: GritName { + grit_name_token: GRIT_NAME@92..97 "ours" [] [Whitespace(" ")], + }, + grit_bogus: missing (optional), + }, + match_token: MATCH@97..100 "<:" [] [Whitespace(" ")], + right: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@100..107 "`paris`" [] [], + }, + }, + grit_bogus: missing (optional), + }, + COMMA@107..108 "," [] [], + GritPredicateRewrite { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@108..116 "$val" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + annotation: missing (optional), + fat_arrow_token: FAT_ARROW@116..119 "=>" [] [Whitespace(" ")], + right: GritMapAccessor { + map: GritVariable { + grit_variable_token: GRIT_VARIABLE@119..128 "$capitals" [] [], + }, + dot_token: DOT@128..129 "." [] [], + key: GritName { + grit_name_token: GRIT_NAME@129..136 "england" [] [], + }, + grit_bogus: missing (optional), + }, + grit_bogus: missing (optional), + }, + COMMA@136..137 "," [] [], + ], + r_curly_token: R_CURLY@137..139 "}" [Newline("\n")] [], + }, + }, + definitions_continued: GritDefinitionList [], + eof_token: EOF@139..140 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..140 + 0: (empty) + 1: (empty) + 2: (empty) + 3: GRIT_DEFINITION_LIST@0..0 + 4: GRIT_PATTERN_WHERE@0..139 + 0: GRIT_CODE_SNIPPET@0..23 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@0..23 + 0: GRIT_BACKTICK_SNIPPET@0..23 "`const capital = $val`" [] [Whitespace(" ")] + 1: WHERE_KW@23..29 "where" [] [Whitespace(" ")] + 2: GRIT_PREDICATE_AND@29..139 + 0: (empty) + 1: L_CURLY@29..30 "{" [] [] + 2: GRIT_PREDICATE_LIST@30..137 + 0: GRIT_PREDICATE_ASSIGNMENT@30..78 + 0: GRIT_VARIABLE@30..43 + 0: GRIT_VARIABLE@30..43 "$capitals" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: EQ@43..45 "=" [] [Whitespace(" ")] + 2: GRIT_MAP@45..78 + 0: L_CURLY@45..47 "{" [] [Whitespace(" ")] + 1: GRIT_MAP_ELEMENT_LIST@47..77 + 0: GRIT_MAP_ELEMENT@47..64 + 0: GRIT_NAME@47..54 + 0: GRIT_NAME@47..54 "england" [] [] + 1: COLON@54..56 ":" [] [Whitespace(" ")] + 2: GRIT_CODE_SNIPPET@56..64 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@56..64 + 0: GRIT_BACKTICK_SNIPPET@56..64 "`london`" [] [] + 1: COMMA@64..66 "," [] [Whitespace(" ")] + 2: GRIT_MAP_ELEMENT@66..77 + 0: GRIT_NAME@66..70 + 0: GRIT_NAME@66..70 "ours" [] [] + 1: COLON@70..72 ":" [] [Whitespace(" ")] + 2: GRIT_VARIABLE@72..77 + 0: GRIT_VARIABLE@72..77 "$val" [] [Whitespace(" ")] + 2: R_CURLY@77..78 "}" [] [] + 3: (empty) + 1: COMMA@78..79 "," [] [] + 2: GRIT_PREDICATE_MATCH@79..107 + 0: GRIT_MAP_ACCESSOR@79..97 + 0: GRIT_VARIABLE@79..91 + 0: GRIT_VARIABLE@79..91 "$capitals" [Newline("\n"), Whitespace(" ")] [] + 1: DOT@91..92 "." [] [] + 2: GRIT_NAME@92..97 + 0: GRIT_NAME@92..97 "ours" [] [Whitespace(" ")] + 3: (empty) + 1: MATCH@97..100 "<:" [] [Whitespace(" ")] + 2: GRIT_CODE_SNIPPET@100..107 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@100..107 + 0: GRIT_BACKTICK_SNIPPET@100..107 "`paris`" [] [] + 3: (empty) + 3: COMMA@107..108 "," [] [] + 4: GRIT_PREDICATE_REWRITE@108..136 + 0: GRIT_VARIABLE@108..116 + 0: GRIT_VARIABLE@108..116 "$val" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: (empty) + 2: FAT_ARROW@116..119 "=>" [] [Whitespace(" ")] + 3: GRIT_MAP_ACCESSOR@119..136 + 0: GRIT_VARIABLE@119..128 + 0: GRIT_VARIABLE@119..128 "$capitals" [] [] + 1: DOT@128..129 "." [] [] + 2: GRIT_NAME@129..136 + 0: GRIT_NAME@129..136 "england" [] [] + 3: (empty) + 4: (empty) + 5: COMMA@136..137 "," [] [] + 3: R_CURLY@137..139 "}" [Newline("\n")] [] + 5: GRIT_DEFINITION_LIST@139..139 + 6: EOF@139..140 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/regex.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/regex.grit new file mode 100644 index 00000000000..2a143f1b67c --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/regex.grit @@ -0,0 +1 @@ +r"test\\.*[^'\"]" diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/regex.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/regex.grit.snap new file mode 100644 index 00000000000..1d6e5848d47 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/regex.grit.snap @@ -0,0 +1,45 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +r"test\\.*[^'\"]" + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: missing (optional), + definitions: GritDefinitionList [], + pattern: GritRegexPattern { + regex: GritRegexLiteral { + value_token: GRIT_REGEX@0..17 "r\"test\\\\.*[^'\\\"]\"" [] [], + }, + variables: missing (optional), + }, + definitions_continued: GritDefinitionList [], + eof_token: EOF@17..18 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..18 + 0: (empty) + 1: (empty) + 2: (empty) + 3: GRIT_DEFINITION_LIST@0..0 + 4: GRIT_REGEX_PATTERN@0..17 + 0: GRIT_REGEX_LITERAL@0..17 + 0: GRIT_REGEX@0..17 "r\"test\\\\.*[^'\\\"]\"" [] [] + 1: (empty) + 5: GRIT_DEFINITION_LIST@17..17 + 6: EOF@17..18 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/rewrite_in_where.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/rewrite_in_where.grit.snap index 030369f910b..d4f42025fb9 100644 --- a/crates/biome_grit_parser/tests/grit_test_suite/ok/rewrite_in_where.grit.snap +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/rewrite_in_where.grit.snap @@ -73,6 +73,7 @@ GritRoot { }, }, }, + grit_bogus: missing (optional), }, ], r_curly_token: R_CURLY@89..91 "}" [Newline("\n")] [], @@ -129,6 +130,7 @@ GritRoot { 0: GRIT_LANGUAGE_NAME@81..83 0: JS_KW@81..83 "js" [] [] 1: GRIT_STRING@83..89 "\"test\"" [] [] + 3: (empty) 3: R_CURLY@89..91 "}" [Newline("\n")] [] 5: GRIT_DEFINITION_LIST@91..91 6: EOF@91..92 "" [Newline("\n")] [] diff --git a/crates/biome_grit_parser/tests/spec_test.rs b/crates/biome_grit_parser/tests/spec_test.rs index 546dab4e320..8f0fe59f241 100644 --- a/crates/biome_grit_parser/tests/spec_test.rs +++ b/crates/biome_grit_parser/tests/spec_test.rs @@ -97,7 +97,7 @@ pub fn run(test_case: &str, _snapshot_name: &str, test_directory: &str, outcome_ .descendants() .any(|node| node.kind().is_bogus()) { - panic!("Parsed tree of a 'OK' test case should not contain any missing required children or bogus nodes"); + panic!("Parsed tree of a 'OK' test case should not contain any missing required children or bogus nodes: \n {formatted_ast:#?} \n\n {}", formatted_ast); } } ExpectedOutcome::Fail => { diff --git a/crates/biome_grit_syntax/src/generated/kind.rs b/crates/biome_grit_syntax/src/generated/kind.rs index a5a582c5ad3..1398b719ac4 100644 --- a/crates/biome_grit_syntax/src/generated/kind.rs +++ b/crates/biome_grit_syntax/src/generated/kind.rs @@ -149,12 +149,9 @@ pub enum GritSyntaxKind { GRIT_MAP_ELEMENT_LIST, GRIT_MAP_ELEMENT, GRIT_MAP_ACCESSOR, - GRIT_MAP_ACCESSOR_SUBJECT, - GRIT_MAP_KEY, GRIT_LIST, GRIT_LIST_PATTERN_LIST, GRIT_LIST_ACCESSOR, - GRIT_LIST_ACCESSOR_SUBJECT, GRIT_LIST_INDEX, GRIT_DOT, GRIT_DOTDOTDOT, @@ -186,7 +183,6 @@ pub enum GritSyntaxKind { GRIT_PREDICATE_NOT_EQUAL, GRIT_PREDICATE_EQUAL, GRIT_PREDICATE_MATCH, - GRIT_PREDICATE_MATCH_SUBJECT, GRIT_PREDICATE_CALL, GRIT_PREDICATE_RETURN, GRIT_VARIABLE_LIST, @@ -206,6 +202,7 @@ pub enum GritSyntaxKind { GRIT_REGEX_LITERAL, GRIT_SNIPPET_REGEX_LITERAL, GRIT_BOGUS, + GRIT_BOGUS_CONTAINER, GRIT_BOGUS_DEFINITION, GRIT_BOGUS_PATTERN, GRIT_BOGUS_LITERAL, diff --git a/crates/biome_grit_syntax/src/generated/macros.rs b/crates/biome_grit_syntax/src/generated/macros.rs index 316982ae6e9..81c840ab5a5 100644 --- a/crates/biome_grit_syntax/src/generated/macros.rs +++ b/crates/biome_grit_syntax/src/generated/macros.rs @@ -407,6 +407,10 @@ macro_rules! map_syntax_node { let $pattern = unsafe { $crate::GritBogus::new_unchecked(node) }; $body } + $crate::GritSyntaxKind::GRIT_BOGUS_CONTAINER => { + let $pattern = unsafe { $crate::GritBogusContainer::new_unchecked(node) }; + $body + } $crate::GritSyntaxKind::GRIT_BOGUS_DEFINITION => { let $pattern = unsafe { $crate::GritBogusDefinition::new_unchecked(node) }; $body diff --git a/crates/biome_grit_syntax/src/generated/nodes.rs b/crates/biome_grit_syntax/src/generated/nodes.rs index 5233395946e..4a0b650d54c 100644 --- a/crates/biome_grit_syntax/src/generated/nodes.rs +++ b/crates/biome_grit_syntax/src/generated/nodes.rs @@ -1282,6 +1282,7 @@ impl GritListAccessor { l_brack_token: self.l_brack_token(), index: self.index(), r_brack_token: self.r_brack_token(), + grit_bogus: self.grit_bogus(), } } pub fn list(&self) -> SyntaxResult { @@ -1296,6 +1297,9 @@ impl GritListAccessor { pub fn r_brack_token(&self) -> SyntaxResult { support::required_token(&self.syntax, 3usize) } + pub fn grit_bogus(&self) -> Option { + support::node(&self.syntax, 4usize) + } } #[cfg(feature = "serde")] impl Serialize for GritListAccessor { @@ -1312,6 +1316,7 @@ pub struct GritListAccessorFields { pub l_brack_token: SyntaxResult, pub index: SyntaxResult, pub r_brack_token: SyntaxResult, + pub grit_bogus: Option, } #[derive(Clone, PartialEq, Eq, Hash)] pub struct GritMap { @@ -1378,6 +1383,7 @@ impl GritMapAccessor { map: self.map(), dot_token: self.dot_token(), key: self.key(), + grit_bogus: self.grit_bogus(), } } pub fn map(&self) -> SyntaxResult { @@ -1389,6 +1395,9 @@ impl GritMapAccessor { pub fn key(&self) -> SyntaxResult { support::required_node(&self.syntax, 2usize) } + pub fn grit_bogus(&self) -> Option { + support::node(&self.syntax, 3usize) + } } #[cfg(feature = "serde")] impl Serialize for GritMapAccessor { @@ -1404,6 +1413,7 @@ pub struct GritMapAccessorFields { pub map: SyntaxResult, pub dot_token: SyntaxResult, pub key: SyntaxResult, + pub grit_bogus: Option, } #[derive(Clone, PartialEq, Eq, Hash)] pub struct GritMapElement { @@ -2855,6 +2865,7 @@ impl GritPredicateAssignment { container: self.container(), eq_token: self.eq_token(), pattern: self.pattern(), + grit_bogus: self.grit_bogus(), } } pub fn container(&self) -> SyntaxResult { @@ -2866,6 +2877,9 @@ impl GritPredicateAssignment { pub fn pattern(&self) -> SyntaxResult { support::required_node(&self.syntax, 2usize) } + pub fn grit_bogus(&self) -> Option { + support::node(&self.syntax, 3usize) + } } #[cfg(feature = "serde")] impl Serialize for GritPredicateAssignment { @@ -2881,6 +2895,7 @@ pub struct GritPredicateAssignmentFields { pub container: SyntaxResult, pub eq_token: SyntaxResult, pub pattern: SyntaxResult, + pub grit_bogus: Option, } #[derive(Clone, PartialEq, Eq, Hash)] pub struct GritPredicateCall { @@ -3345,6 +3360,7 @@ impl GritPredicateMatch { left: self.left(), match_token: self.match_token(), right: self.right(), + grit_bogus: self.grit_bogus(), } } pub fn left(&self) -> SyntaxResult { @@ -3356,6 +3372,9 @@ impl GritPredicateMatch { pub fn right(&self) -> SyntaxResult { support::required_node(&self.syntax, 2usize) } + pub fn grit_bogus(&self) -> Option { + support::node(&self.syntax, 3usize) + } } #[cfg(feature = "serde")] impl Serialize for GritPredicateMatch { @@ -3371,6 +3390,7 @@ pub struct GritPredicateMatchFields { pub left: SyntaxResult, pub match_token: SyntaxResult, pub right: SyntaxResult, + pub grit_bogus: Option, } #[derive(Clone, PartialEq, Eq, Hash)] pub struct GritPredicateMaybe { @@ -3612,6 +3632,7 @@ impl GritPredicateRewrite { annotation: self.annotation(), fat_arrow_token: self.fat_arrow_token(), right: self.right(), + grit_bogus: self.grit_bogus(), } } pub fn left(&self) -> SyntaxResult { @@ -3626,6 +3647,9 @@ impl GritPredicateRewrite { pub fn right(&self) -> SyntaxResult { support::required_node(&self.syntax, 3usize) } + pub fn grit_bogus(&self) -> Option { + support::node(&self.syntax, 4usize) + } } #[cfg(feature = "serde")] impl Serialize for GritPredicateRewrite { @@ -3642,6 +3666,7 @@ pub struct GritPredicateRewriteFields { pub annotation: Option, pub fat_arrow_token: SyntaxResult, pub right: SyntaxResult, + pub grit_bogus: Option, } #[derive(Clone, PartialEq, Eq, Hash)] pub struct GritRawBacktickSnippetLiteral { @@ -4337,11 +4362,18 @@ pub struct GritWithinFields { #[derive(Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize))] pub enum AnyGritContainer { + GritBogusContainer(GritBogusContainer), GritListAccessor(GritListAccessor), GritMapAccessor(GritMapAccessor), GritVariable(GritVariable), } impl AnyGritContainer { + pub fn as_grit_bogus_container(&self) -> Option<&GritBogusContainer> { + match &self { + AnyGritContainer::GritBogusContainer(item) => Some(item), + _ => None, + } + } pub fn as_grit_list_accessor(&self) -> Option<&GritListAccessor> { match &self { AnyGritContainer::GritListAccessor(item) => Some(item), @@ -6405,6 +6437,10 @@ impl std::fmt::Debug for GritListAccessor { "r_brack_token", &support::DebugSyntaxResult(self.r_brack_token()), ) + .field( + "grit_bogus", + &support::DebugOptionalElement(self.grit_bogus()), + ) .finish() } } @@ -6491,6 +6527,10 @@ impl std::fmt::Debug for GritMapAccessor { .field("map", &support::DebugSyntaxResult(self.map())) .field("dot_token", &support::DebugSyntaxResult(self.dot_token())) .field("key", &support::DebugSyntaxResult(self.key())) + .field( + "grit_bogus", + &support::DebugOptionalElement(self.grit_bogus()), + ) .finish() } } @@ -7904,6 +7944,10 @@ impl std::fmt::Debug for GritPredicateAssignment { .field("container", &support::DebugSyntaxResult(self.container())) .field("eq_token", &support::DebugSyntaxResult(self.eq_token())) .field("pattern", &support::DebugSyntaxResult(self.pattern())) + .field( + "grit_bogus", + &support::DebugOptionalElement(self.grit_bogus()), + ) .finish() } } @@ -8361,6 +8405,10 @@ impl std::fmt::Debug for GritPredicateMatch { &support::DebugSyntaxResult(self.match_token()), ) .field("right", &support::DebugSyntaxResult(self.right())) + .field( + "grit_bogus", + &support::DebugOptionalElement(self.grit_bogus()), + ) .finish() } } @@ -8621,6 +8669,10 @@ impl std::fmt::Debug for GritPredicateRewrite { &support::DebugSyntaxResult(self.fat_arrow_token()), ) .field("right", &support::DebugSyntaxResult(self.right())) + .field( + "grit_bogus", + &support::DebugOptionalElement(self.grit_bogus()), + ) .finish() } } @@ -9337,6 +9389,11 @@ impl From for SyntaxElement { n.syntax.into() } } +impl From for AnyGritContainer { + fn from(node: GritBogusContainer) -> AnyGritContainer { + AnyGritContainer::GritBogusContainer(node) + } +} impl From for AnyGritContainer { fn from(node: GritListAccessor) -> AnyGritContainer { AnyGritContainer::GritListAccessor(node) @@ -9354,14 +9411,21 @@ impl From for AnyGritContainer { } impl AstNode for AnyGritContainer { type Language = Language; - const KIND_SET: SyntaxKindSet = GritListAccessor::KIND_SET + const KIND_SET: SyntaxKindSet = GritBogusContainer::KIND_SET + .union(GritListAccessor::KIND_SET) .union(GritMapAccessor::KIND_SET) .union(GritVariable::KIND_SET); fn can_cast(kind: SyntaxKind) -> bool { - matches!(kind, GRIT_LIST_ACCESSOR | GRIT_MAP_ACCESSOR | GRIT_VARIABLE) + matches!( + kind, + GRIT_BOGUS_CONTAINER | GRIT_LIST_ACCESSOR | GRIT_MAP_ACCESSOR | GRIT_VARIABLE + ) } fn cast(syntax: SyntaxNode) -> Option { let res = match syntax.kind() { + GRIT_BOGUS_CONTAINER => { + AnyGritContainer::GritBogusContainer(GritBogusContainer { syntax }) + } GRIT_LIST_ACCESSOR => AnyGritContainer::GritListAccessor(GritListAccessor { syntax }), GRIT_MAP_ACCESSOR => AnyGritContainer::GritMapAccessor(GritMapAccessor { syntax }), GRIT_VARIABLE => AnyGritContainer::GritVariable(GritVariable { syntax }), @@ -9371,6 +9435,7 @@ impl AstNode for AnyGritContainer { } fn syntax(&self) -> &SyntaxNode { match self { + AnyGritContainer::GritBogusContainer(it) => &it.syntax, AnyGritContainer::GritListAccessor(it) => &it.syntax, AnyGritContainer::GritMapAccessor(it) => &it.syntax, AnyGritContainer::GritVariable(it) => &it.syntax, @@ -9378,6 +9443,7 @@ impl AstNode for AnyGritContainer { } fn into_syntax(self) -> SyntaxNode { match self { + AnyGritContainer::GritBogusContainer(it) => it.syntax, AnyGritContainer::GritListAccessor(it) => it.syntax, AnyGritContainer::GritMapAccessor(it) => it.syntax, AnyGritContainer::GritVariable(it) => it.syntax, @@ -9387,6 +9453,7 @@ impl AstNode for AnyGritContainer { impl std::fmt::Debug for AnyGritContainer { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { + AnyGritContainer::GritBogusContainer(it) => std::fmt::Debug::fmt(it, f), AnyGritContainer::GritListAccessor(it) => std::fmt::Debug::fmt(it, f), AnyGritContainer::GritMapAccessor(it) => std::fmt::Debug::fmt(it, f), AnyGritContainer::GritVariable(it) => std::fmt::Debug::fmt(it, f), @@ -9396,6 +9463,7 @@ impl std::fmt::Debug for AnyGritContainer { impl From for SyntaxNode { fn from(n: AnyGritContainer) -> SyntaxNode { match n { + AnyGritContainer::GritBogusContainer(it) => it.into(), AnyGritContainer::GritListAccessor(it) => it.into(), AnyGritContainer::GritMapAccessor(it) => it.into(), AnyGritContainer::GritVariable(it) => it.into(), @@ -11780,6 +11848,63 @@ impl From for SyntaxElement { } #[derive(Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize))] +pub struct GritBogusContainer { + syntax: SyntaxNode, +} +impl GritBogusContainer { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn items(&self) -> SyntaxElementChildren { + support::elements(&self.syntax) + } +} +impl AstNode for GritBogusContainer { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(GRIT_BOGUS_CONTAINER as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == GRIT_BOGUS_CONTAINER + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for GritBogusContainer { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("GritBogusContainer") + .field("items", &DebugSyntaxElementChildren(self.items())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: GritBogusContainer) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: GritBogusContainer) -> SyntaxElement { + n.syntax.into() + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] pub struct GritBogusDefinition { syntax: SyntaxNode, } diff --git a/crates/biome_grit_syntax/src/generated/nodes_mut.rs b/crates/biome_grit_syntax/src/generated/nodes_mut.rs index 3f984ae0692..471cd33c6ba 100644 --- a/crates/biome_grit_syntax/src/generated/nodes_mut.rs +++ b/crates/biome_grit_syntax/src/generated/nodes_mut.rs @@ -528,6 +528,12 @@ impl GritListAccessor { .splice_slots(3usize..=3usize, once(Some(element.into()))), ) } + pub fn with_grit_bogus(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 4usize..=4usize, + once(element.map(|element| element.into_syntax().into())), + )) + } } impl GritMap { pub fn with_l_curly_token(self, element: SyntaxToken) -> Self { @@ -568,6 +574,12 @@ impl GritMapAccessor { .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), ) } + pub fn with_grit_bogus(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 3usize..=3usize, + once(element.map(|element| element.into_syntax().into())), + )) + } } impl GritMapElement { pub fn with_key(self, element: GritName) -> Self { @@ -1217,6 +1229,12 @@ impl GritPredicateAssignment { .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), ) } + pub fn with_grit_bogus(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 3usize..=3usize, + once(element.map(|element| element.into_syntax().into())), + )) + } } impl GritPredicateCall { pub fn with_name(self, element: GritName) -> Self { @@ -1453,6 +1471,12 @@ impl GritPredicateMatch { .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), ) } + pub fn with_grit_bogus(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 3usize..=3usize, + once(element.map(|element| element.into_syntax().into())), + )) + } } impl GritPredicateMaybe { pub fn with_maybe_token(self, element: SyntaxToken) -> Self { @@ -1567,6 +1591,12 @@ impl GritPredicateRewrite { .splice_slots(3usize..=3usize, once(Some(element.into_syntax().into()))), ) } + pub fn with_grit_bogus(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 4usize..=4usize, + once(element.map(|element| element.into_syntax().into())), + )) + } } impl GritRawBacktickSnippetLiteral { pub fn with_value_token(self, element: SyntaxToken) -> Self { diff --git a/xtask/codegen/gritql.ungram b/xtask/codegen/gritql.ungram index cec5b40cbab..49885f0bc06 100644 --- a/xtask/codegen/gritql.ungram +++ b/xtask/codegen/gritql.ungram @@ -38,6 +38,7 @@ SyntaxElement = SyntaxElement GritBogus = SyntaxElement* +GritBogusContainer = SyntaxElement* GritBogusDefinition = SyntaxElement* GritBogusPattern = SyntaxElement* GritBogusLiteral = SyntaxElement* @@ -133,7 +134,8 @@ CurlyGritPattern = '{' AnyGritPattern '}' GritPatternList = AnyGritPattern (',' AnyGritPattern)* ','? -AnyGritContainer = GritVariable | GritMapAccessor | GritListAccessor +AnyGritContainer = + GritVariable | GritMapAccessor | GritListAccessor | GritBogusContainer GritMulOperation = left: AnyGritPattern '*' right: AnyGritPattern @@ -282,6 +284,7 @@ GritMapAccessor = map: GritMapAccessorSubject '.' key: GritMapKey + GritBogus? GritMapAccessorSubject = GritMap | AnyGritContainer GritMapKey = GritName | GritVariable @@ -292,7 +295,7 @@ GritList = patterns: GritListPatternList? ']' -GritListPatternList = (AnyGritListPattern (',' AnyGritListPattern)* ','?) +GritListPatternList = AnyGritListPattern (',' AnyGritListPattern)* ','? AnyGritListPattern = AnyGritPattern | GritDotdotdot @@ -301,6 +304,7 @@ GritListAccessor = '[' index: GritListIndex ']' + GritBogus? GritListAccessorSubject = GritList | AnyGritContainer GritListIndex = AnyGritContainer | GritNegativeIntLiteral | GritIntLiteral @@ -439,11 +443,13 @@ GritPredicateRewrite = annotation: GritAnnotation? '=>' right: AnyGritPattern + GritBogus? GritPredicateAssignment = container: AnyGritContainer '=' pattern: AnyGritPattern + GritBogus? GritPredicateAccumulate = left: GritVariable @@ -484,6 +490,7 @@ GritPredicateMatch = left: GritPredicateMatchSubject match: '<:' right: AnyGritPattern + GritBogus? GritPredicateMatchSubject = AnyGritContainer | AnyGritLiteral diff --git a/xtask/codegen/src/grit_kinds_src.rs b/xtask/codegen/src/grit_kinds_src.rs index 095191b5cae..00f1edb3377 100644 --- a/xtask/codegen/src/grit_kinds_src.rs +++ b/xtask/codegen/src/grit_kinds_src.rs @@ -158,12 +158,9 @@ pub const GRIT_KINDS_SRC: KindsSrc = KindsSrc { "GRIT_MAP_ELEMENT_LIST", "GRIT_MAP_ELEMENT", "GRIT_MAP_ACCESSOR", - "GRIT_MAP_ACCESSOR_SUBJECT", - "GRIT_MAP_KEY", "GRIT_LIST", "GRIT_LIST_PATTERN_LIST", "GRIT_LIST_ACCESSOR", - "GRIT_LIST_ACCESSOR_SUBJECT", "GRIT_LIST_INDEX", "GRIT_DOT", "GRIT_DOTDOTDOT", @@ -195,7 +192,6 @@ pub const GRIT_KINDS_SRC: KindsSrc = KindsSrc { "GRIT_PREDICATE_NOT_EQUAL", "GRIT_PREDICATE_EQUAL", "GRIT_PREDICATE_MATCH", - "GRIT_PREDICATE_MATCH_SUBJECT", "GRIT_PREDICATE_CALL", "GRIT_PREDICATE_RETURN", "GRIT_VARIABLE_LIST", @@ -217,6 +213,7 @@ pub const GRIT_KINDS_SRC: KindsSrc = KindsSrc { "GRIT_SNIPPET_REGEX_LITERAL", // bogus nodes: "GRIT_BOGUS", + "GRIT_BOGUS_CONTAINER", "GRIT_BOGUS_DEFINITION", "GRIT_BOGUS_PATTERN", "GRIT_BOGUS_LITERAL", From 6224d443924d8f43ec2263813a1b51c5380b8352 Mon Sep 17 00:00:00 2001 From: "Arend van Beelen jr." Date: Wed, 28 Feb 2024 21:04:32 +0100 Subject: [PATCH 10/12] Another test + lookahead --- crates/biome_grit_parser/src/parser/mod.rs | 58 +++++- .../biome_grit_parser/src/parser/patterns.rs | 15 +- .../src/parser/predicates.rs | 42 ++++- crates/biome_grit_parser/src/token_source.rs | 76 +++++--- .../grit_test_suite/ok/if_else_pattern.grit | 7 + .../ok/if_else_pattern.grit.snap | 170 ++++++++++++++++++ 6 files changed, 328 insertions(+), 40 deletions(-) create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/if_else_pattern.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/if_else_pattern.grit.snap diff --git a/crates/biome_grit_parser/src/parser/mod.rs b/crates/biome_grit_parser/src/parser/mod.rs index d721c0c4799..806a60f003b 100644 --- a/crates/biome_grit_parser/src/parser/mod.rs +++ b/crates/biome_grit_parser/src/parser/mod.rs @@ -16,10 +16,9 @@ use biome_parser::ParserContext; use biome_rowan::TextRange; use constants::*; use literals::parse_double_literal; +use parse_error::{expected_language_flavor, expected_language_name, expected_pattern}; use patterns::parse_pattern; -use self::parse_error::{expected_language_flavor, expected_language_name}; - pub(crate) struct GritParser<'source> { context: ParserContext, source: GritTokenSource<'source>, @@ -33,6 +32,10 @@ impl<'source> GritParser<'source> { } } + pub fn lookahead(&mut self) -> GritSyntaxKind { + self.source.lookahead() + } + pub fn finish( self, ) -> ( @@ -214,6 +217,22 @@ fn parse_definition_list(p: &mut GritParser) -> CompletedMarker { m.complete(p, GRIT_DEFINITION_LIST) } +#[inline] +fn parse_maybe_named_arg(p: &mut GritParser) -> ParsedSyntax { + if p.at(GRIT_NAME) { + parse_named_arg(p) + } else { + parse_pattern(p) + .or_recover_with_token_set( + p, + &ParseRecoveryTokenSet::new(GRIT_BOGUS, ARG_LIST_RECOVERY_SET), + expected_pattern, + ) + .ok() + .into() + } +} + #[inline] fn parse_name(p: &mut GritParser) -> ParsedSyntax { if !p.at(GRIT_NAME) { @@ -225,6 +244,41 @@ fn parse_name(p: &mut GritParser) -> ParsedSyntax { Present(m.complete(p, GRIT_NAME)) } +#[inline] +fn parse_named_arg(p: &mut GritParser) -> ParsedSyntax { + if !p.at(GRIT_NAME) { + return Absent; + } + + let m = p.start(); + let _ = parse_name(p); + p.eat(T![=]); + let _ = parse_pattern(p).or_recover_with_token_set( + p, + &ParseRecoveryTokenSet::new(GRIT_BOGUS, ARG_LIST_RECOVERY_SET), + expected_pattern, + ); + Present(m.complete(p, GRIT_NAMED_ARG)) +} + +#[inline] +fn parse_named_arg_list(p: &mut GritParser) -> ParsedSyntax { + let m = p.start(); + + if parse_maybe_named_arg(p) == Absent { + m.abandon(p); + return Absent; + } + + while p.eat(T![,]) { + if p.at(T![')']) || parse_maybe_named_arg(p) == Absent { + break; + } + } + + Present(m.complete(p, GRIT_NAMED_ARG_LIST)) +} + #[inline] fn parse_variable(p: &mut GritParser) -> ParsedSyntax { if !p.at(GRIT_VARIABLE) { diff --git a/crates/biome_grit_parser/src/parser/patterns.rs b/crates/biome_grit_parser/src/parser/patterns.rs index 86b8ad8e48c..f9d093d0601 100644 --- a/crates/biome_grit_parser/src/parser/patterns.rs +++ b/crates/biome_grit_parser/src/parser/patterns.rs @@ -3,9 +3,9 @@ use super::literals::*; use super::parse_error::{expected_list_index, expected_map_key, expected_pattern}; use super::predicates::parse_predicate; use super::{parse_name, parse_variable, parse_variable_list, GritParser}; -use biome_grit_syntax::GritSyntaxKind::{self, *}; +use biome_grit_syntax::GritSyntaxKind::*; use biome_grit_syntax::T; -use biome_parser::parse_recovery::{ParseRecovery, ParseRecoveryTokenSet}; +use biome_parser::parse_recovery::ParseRecoveryTokenSet; use biome_parser::prelude::{ParsedSyntax::*, *}; pub(crate) fn parse_pattern(p: &mut GritParser) -> ParsedSyntax { @@ -389,17 +389,6 @@ pub(crate) fn parse_maybe_curly_pattern(p: &mut GritParser) -> ParsedSyntax { } } -struct ArgListParseRecovery; -impl ParseRecovery for ArgListParseRecovery { - type Kind = GritSyntaxKind; - type Parser<'source> = GritParser<'source>; - const RECOVERED_KIND: Self::Kind = GRIT_BOGUS; - - fn is_at_recovered(&self, p: &mut Self::Parser<'_>) -> bool { - p.at(T![')']) - } -} - #[inline] fn parse_maybe_named_arg(p: &mut GritParser) -> ParsedSyntax { if p.at(GRIT_NAME) { diff --git a/crates/biome_grit_parser/src/parser/predicates.rs b/crates/biome_grit_parser/src/parser/predicates.rs index 53439668c5d..29955650f77 100644 --- a/crates/biome_grit_parser/src/parser/predicates.rs +++ b/crates/biome_grit_parser/src/parser/predicates.rs @@ -1,8 +1,8 @@ -use super::constants::*; use super::literals::{parse_boolean_literal, parse_literal}; use super::parse_error::expected_pattern; use super::patterns::{parse_container, parse_pattern}; use super::GritParser; +use super::{constants::*, parse_named_arg_list}; use biome_grit_syntax::GritSyntaxKind::*; use biome_grit_syntax::T; use biome_parser::parse_recovery::ParseRecoveryTokenSet; @@ -16,17 +16,16 @@ pub(crate) fn parse_predicate(p: &mut GritParser) -> ParsedSyntax { OR_KW => parse_predicate_or(p), ANY_KW => parse_predicate_any(p), IF_KW => parse_predicate_if_else(p), - // TODO: GritPredicateRewrite => {} // TODO: GritPredicateGreater => {} // TODO: GritPredicateLess => {} // TODO: GritPredicateGreaterEqual => {} // TODO: GritPredicateLessEqual => {} // TODO: GritPredicateNotEqual => {} // TODO: GritPredicateEqual => {} - // TODO: GritPredicateCall => {} + GRIT_NAME if p.lookahead() == T!['('] => parse_predicate_call(p), T!['('] => parse_bracketed_predicate(p), T![true] | T![false] => parse_boolean_literal(p), - // TODO: GritPredicateReturn => {} + RETURN_KW => parse_predicate_return(p), _ => parse_infix_predicate(p), } } @@ -158,6 +157,23 @@ fn parse_predicate_any(p: &mut GritParser) -> ParsedSyntax { } } +#[inline] +fn parse_predicate_call(p: &mut GritParser) -> ParsedSyntax { + if !p.at(GRIT_NAME) { + return Absent; + } + + let m = p.start(); + p.bump(GRIT_NAME); + p.eat(T!['(']); + + let _ = parse_named_arg_list(p); + + p.eat(T![')']); + + Present(m.complete(p, GRIT_PREDICATE_CALL)) +} + #[inline] fn parse_predicate_if_else(p: &mut GritParser) -> ParsedSyntax { if !p.at(IF_KW) { @@ -271,3 +287,21 @@ fn parse_predicate_or(p: &mut GritParser) -> ParsedSyntax { } } } + +#[inline] +fn parse_predicate_return(p: &mut GritParser) -> ParsedSyntax { + if !p.at(RETURN_KW) { + return Absent; + } + + let m = p.start(); + p.bump(RETURN_KW); + + let _ = parse_pattern(p).or_recover_with_token_set( + p, + &ParseRecoveryTokenSet::new(GRIT_BOGUS, PREDICATE_RECOVERY_SET), + expected_pattern, + ); + + Present(m.complete(p, GRIT_PREDICATE_RETURN)) +} diff --git a/crates/biome_grit_parser/src/token_source.rs b/crates/biome_grit_parser/src/token_source.rs index bbff3951eca..6ef7169842b 100644 --- a/crates/biome_grit_parser/src/token_source.rs +++ b/crates/biome_grit_parser/src/token_source.rs @@ -1,4 +1,4 @@ -use crate::lexer::{Lexer, Token}; +use crate::lexer::Lexer; use biome_grit_syntax::GritSyntaxKind::{EOF, TOMBSTONE}; use biome_grit_syntax::{GritSyntaxKind, TextRange}; use biome_parser::diagnostic::ParseDiagnostic; @@ -9,11 +9,26 @@ use biome_rowan::TriviaPieceKind; pub(crate) struct GritTokenSource<'source> { lexer: Lexer<'source>, trivia: Vec, - current: GritSyntaxKind, - current_range: TextRange, + current: NonTriviaToken, + next: Option, +} + +struct NonTriviaToken { + kind: GritSyntaxKind, + range: TextRange, preceding_line_break: bool, } +impl Default for NonTriviaToken { + fn default() -> Self { + Self { + kind: TOMBSTONE, + range: TextRange::default(), + preceding_line_break: false, + } + } +} + impl<'source> GritTokenSource<'source> { pub fn from_str(source: &'source str) -> Self { let lexer = Lexer::from_str(source); @@ -21,32 +36,54 @@ impl<'source> GritTokenSource<'source> { let mut source = Self { lexer, trivia: Vec::new(), - current: TOMBSTONE, - current_range: TextRange::default(), - preceding_line_break: false, + current: NonTriviaToken::default(), + next: None, }; - source.next_non_trivia_token(true); + source.advance_to_next_non_trivia_token(true); source } - fn next_non_trivia_token(&mut self, first_token: bool) { + fn advance_to_next_non_trivia_token(&mut self, first_token: bool) { + self.current = match self.next.take() { + Some(next) => next, + None => self.next_non_trivia_token(first_token), + } + } + + pub fn lookahead(&mut self) -> GritSyntaxKind { + match self.next.as_ref() { + Some(next) => next.kind, + None if self.current.kind != EOF => { + let next_token = self.next_non_trivia_token(false); + let next_kind = next_token.kind; + self.next = Some(next_token); + next_kind + } + None => EOF, + } + } + + #[must_use] + fn next_non_trivia_token(&mut self, first_token: bool) -> NonTriviaToken { + let mut non_trivia_token = NonTriviaToken::default(); + let mut trailing = !first_token; - self.preceding_line_break = false; while let Some(token) = self.lexer.next_token() { let trivia_kind = TriviaPieceKind::try_from(token.kind()); match trivia_kind { Err(_) => { - self.set_current_token(token); // Not trivia + non_trivia_token.kind = token.kind(); + non_trivia_token.range = token.range(); break; } Ok(trivia_kind) => { if trivia_kind.is_newline() { trailing = false; - self.preceding_line_break = true; + non_trivia_token.preceding_line_break = true; } self.trivia @@ -54,11 +91,8 @@ impl<'source> GritTokenSource<'source> { } } } - } - fn set_current_token(&mut self, token: Token) { - self.current = token.kind(); - self.current_range = token.range() + non_trivia_token } } @@ -66,11 +100,11 @@ impl<'source> TokenSource for GritTokenSource<'source> { type Kind = GritSyntaxKind; fn current(&self) -> Self::Kind { - self.current + self.current.kind } fn current_range(&self) -> TextRange { - self.current_range + self.current.range } fn text(&self) -> &str { @@ -78,12 +112,12 @@ impl<'source> TokenSource for GritTokenSource<'source> { } fn has_preceding_line_break(&self) -> bool { - self.preceding_line_break + self.current.preceding_line_break } fn bump(&mut self) { - if self.current != EOF { - self.next_non_trivia_token(false) + if self.current.kind != EOF { + self.advance_to_next_non_trivia_token(false) } } @@ -95,7 +129,7 @@ impl<'source> TokenSource for GritTokenSource<'source> { false, )); - self.next_non_trivia_token(false) + self.advance_to_next_non_trivia_token(false) } } diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/if_else_pattern.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/if_else_pattern.grit new file mode 100644 index 00000000000..97bc4bb4f96 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/if_else_pattern.grit @@ -0,0 +1,7 @@ +`$method('$message')` where { + if ($message <: r"Hello, .*!") { + $method => `console.info` + } else { + $method => `console.warn` + } +} diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/if_else_pattern.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/if_else_pattern.grit.snap new file mode 100644 index 00000000000..0799b14cd12 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/if_else_pattern.grit.snap @@ -0,0 +1,170 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +`$method('$message')` where { + if ($message <: r"Hello, .*!") { + $method => `console.info` + } else { + $method => `console.warn` + } +} + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: missing (optional), + definitions: GritDefinitionList [], + pattern: GritPatternWhere { + pattern: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@0..22 "`$method('$message')`" [] [Whitespace(" ")], + }, + }, + where_token: WHERE_KW@22..28 "where" [] [Whitespace(" ")], + side_condition: GritPredicateAnd { + and_token: missing (optional), + l_curly_token: L_CURLY@28..29 "{" [] [], + predicates: GritPredicateList [ + GritPredicateIfElse { + if_token: IF_KW@29..35 "if" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + l_paren_token: L_PAREN@35..36 "(" [] [], + if_predicate: GritPredicateMatch { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@36..45 "$message" [] [Whitespace(" ")], + }, + match_token: MATCH@45..48 "<:" [] [Whitespace(" ")], + right: GritRegexPattern { + regex: GritRegexLiteral { + value_token: GRIT_REGEX@48..61 "r\"Hello, .*!\"" [] [], + }, + variables: missing (optional), + }, + grit_bogus: missing (optional), + }, + r_paren_token: R_PAREN@61..63 ")" [] [Whitespace(" ")], + then_predicate: GritPredicateAnd { + and_token: missing (optional), + l_curly_token: L_CURLY@63..64 "{" [] [], + predicates: GritPredicateList [ + GritPredicateRewrite { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@64..77 "$method" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + annotation: missing (optional), + fat_arrow_token: FAT_ARROW@77..80 "=>" [] [Whitespace(" ")], + right: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@80..94 "`console.info`" [] [], + }, + }, + grit_bogus: missing (optional), + }, + ], + r_curly_token: R_CURLY@94..99 "}" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + grit_predicate_else_clause: GritPredicateElseClause { + else_token: ELSE_KW@99..104 "else" [] [Whitespace(" ")], + else_predicate: GritPredicateAnd { + and_token: missing (optional), + l_curly_token: L_CURLY@104..105 "{" [] [], + predicates: GritPredicateList [ + GritPredicateRewrite { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@105..118 "$method" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + annotation: missing (optional), + fat_arrow_token: FAT_ARROW@118..121 "=>" [] [Whitespace(" ")], + right: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@121..135 "`console.warn`" [] [], + }, + }, + grit_bogus: missing (optional), + }, + ], + r_curly_token: R_CURLY@135..139 "}" [Newline("\n"), Whitespace(" ")] [], + }, + }, + }, + ], + r_curly_token: R_CURLY@139..141 "}" [Newline("\n")] [], + }, + }, + definitions_continued: GritDefinitionList [], + eof_token: EOF@141..142 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..142 + 0: (empty) + 1: (empty) + 2: (empty) + 3: GRIT_DEFINITION_LIST@0..0 + 4: GRIT_PATTERN_WHERE@0..141 + 0: GRIT_CODE_SNIPPET@0..22 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@0..22 + 0: GRIT_BACKTICK_SNIPPET@0..22 "`$method('$message')`" [] [Whitespace(" ")] + 1: WHERE_KW@22..28 "where" [] [Whitespace(" ")] + 2: GRIT_PREDICATE_AND@28..141 + 0: (empty) + 1: L_CURLY@28..29 "{" [] [] + 2: GRIT_PREDICATE_LIST@29..139 + 0: GRIT_PREDICATE_IF_ELSE@29..139 + 0: IF_KW@29..35 "if" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: L_PAREN@35..36 "(" [] [] + 2: GRIT_PREDICATE_MATCH@36..61 + 0: GRIT_VARIABLE@36..45 + 0: GRIT_VARIABLE@36..45 "$message" [] [Whitespace(" ")] + 1: MATCH@45..48 "<:" [] [Whitespace(" ")] + 2: GRIT_REGEX_PATTERN@48..61 + 0: GRIT_REGEX_LITERAL@48..61 + 0: GRIT_REGEX@48..61 "r\"Hello, .*!\"" [] [] + 1: (empty) + 3: (empty) + 3: R_PAREN@61..63 ")" [] [Whitespace(" ")] + 4: GRIT_PREDICATE_AND@63..99 + 0: (empty) + 1: L_CURLY@63..64 "{" [] [] + 2: GRIT_PREDICATE_LIST@64..94 + 0: GRIT_PREDICATE_REWRITE@64..94 + 0: GRIT_VARIABLE@64..77 + 0: GRIT_VARIABLE@64..77 "$method" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: (empty) + 2: FAT_ARROW@77..80 "=>" [] [Whitespace(" ")] + 3: GRIT_CODE_SNIPPET@80..94 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@80..94 + 0: GRIT_BACKTICK_SNIPPET@80..94 "`console.info`" [] [] + 4: (empty) + 3: R_CURLY@94..99 "}" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 5: GRIT_PREDICATE_ELSE_CLAUSE@99..139 + 0: ELSE_KW@99..104 "else" [] [Whitespace(" ")] + 1: GRIT_PREDICATE_AND@104..139 + 0: (empty) + 1: L_CURLY@104..105 "{" [] [] + 2: GRIT_PREDICATE_LIST@105..135 + 0: GRIT_PREDICATE_REWRITE@105..135 + 0: GRIT_VARIABLE@105..118 + 0: GRIT_VARIABLE@105..118 "$method" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: (empty) + 2: FAT_ARROW@118..121 "=>" [] [Whitespace(" ")] + 3: GRIT_CODE_SNIPPET@121..135 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@121..135 + 0: GRIT_BACKTICK_SNIPPET@121..135 "`console.warn`" [] [] + 4: (empty) + 3: R_CURLY@135..139 "}" [Newline("\n"), Whitespace(" ")] [] + 3: R_CURLY@139..141 "}" [Newline("\n")] [] + 5: GRIT_DEFINITION_LIST@141..141 + 6: EOF@141..142 "" [Newline("\n")] [] + +``` From 0c26f8f1b3c89fb35b11643462feb550fe15ad65 Mon Sep 17 00:00:00 2001 From: "Arend van Beelen jr." Date: Wed, 28 Feb 2024 22:23:15 +0100 Subject: [PATCH 11/12] Operators, fixes and tests --- .../src/generated/node_factory.rs | 25 +--- .../src/generated/syntax_factory.rs | 24 +-- crates/biome_grit_parser/src/lexer/mod.rs | 25 ++-- .../biome_grit_parser/src/parser/literals.rs | 6 +- crates/biome_grit_parser/src/parser/mod.rs | 11 ++ .../biome_grit_parser/src/parser/patterns.rs | 80 ++++++++-- .../src/parser/predicates.rs | 11 +- .../grit_test_suite/ok/dotdotdot_clause.grit | 3 + .../ok/dotdotdot_clause.grit.snap | 138 ++++++++++++++++++ .../grit_test_suite/ok/limit_clause.grit | 3 + .../grit_test_suite/ok/limit_clause.grit.snap | 115 +++++++++++++++ .../grit_test_suite/ok/list_pattern.grit | 3 + .../grit_test_suite/ok/list_pattern.grit.snap | 129 ++++++++++++++++ .../tests/grit_test_suite/ok/multiply.grit | 4 + .../grit_test_suite/ok/multiply.grit.snap | 116 +++++++++++++++ .../grit_test_suite/ok/not_condition.grit | 3 + .../ok/not_condition.grit.snap | 102 +++++++++++++ crates/biome_grit_parser/tests/spec_test.rs | 2 +- .../biome_grit_syntax/src/generated/kind.rs | 14 +- .../biome_grit_syntax/src/generated/nodes.rs | 41 ++---- .../src/generated/nodes_mut.rs | 18 +-- xtask/codegen/gritql.ungram | 8 +- xtask/codegen/src/grit_kinds_src.rs | 2 +- 23 files changed, 761 insertions(+), 122 deletions(-) create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/dotdotdot_clause.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/dotdotdot_clause.grit.snap create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/limit_clause.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/limit_clause.grit.snap create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/list_pattern.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/list_pattern.grit.snap create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/multiply.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/multiply.grit.snap create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/not_condition.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/not_condition.grit.snap diff --git a/crates/biome_grit_factory/src/generated/node_factory.rs b/crates/biome_grit_factory/src/generated/node_factory.rs index 48962cfca1f..1a3088fe43e 100644 --- a/crates/biome_grit_factory/src/generated/node_factory.rs +++ b/crates/biome_grit_factory/src/generated/node_factory.rs @@ -89,16 +89,10 @@ pub fn grit_backtick_snippet_literal(value_token: SyntaxToken) -> GritBacktickSn [Some(SyntaxElement::Token(value_token))], )) } -pub fn grit_boolean_literal( - true_token: SyntaxToken, - false_token: SyntaxToken, -) -> GritBooleanLiteral { +pub fn grit_boolean_literal(value_token: SyntaxToken) -> GritBooleanLiteral { GritBooleanLiteral::unwrap_cast(SyntaxNode::new_detached( GritSyntaxKind::GRIT_BOOLEAN_LITERAL, - [ - Some(SyntaxElement::Token(true_token)), - Some(SyntaxElement::Token(false_token)), - ], + [Some(SyntaxElement::Token(value_token))], )) } pub fn grit_bubble(bubble_token: SyntaxToken, pattern: MaybeCurlyGritPattern) -> GritBubbleBuilder { @@ -220,14 +214,14 @@ pub fn grit_dot(dot_token: SyntaxToken) -> GritDot { [Some(SyntaxElement::Token(dot_token))], )) } -pub fn grit_dotdotdot(dollar_dotdotdot_token: SyntaxToken) -> GritDotdotdotBuilder { +pub fn grit_dotdotdot(dotdotdot_token: SyntaxToken) -> GritDotdotdotBuilder { GritDotdotdotBuilder { - dollar_dotdotdot_token, + dotdotdot_token, maybe_curly_grit_pattern: None, } } pub struct GritDotdotdotBuilder { - dollar_dotdotdot_token: SyntaxToken, + dotdotdot_token: SyntaxToken, maybe_curly_grit_pattern: Option, } impl GritDotdotdotBuilder { @@ -242,7 +236,7 @@ impl GritDotdotdotBuilder { GritDotdotdot::unwrap_cast(SyntaxNode::new_detached( GritSyntaxKind::GRIT_DOTDOTDOT, [ - Some(SyntaxElement::Token(self.dollar_dotdotdot_token)), + Some(SyntaxElement::Token(self.dotdotdot_token)), self.maybe_curly_grit_pattern .map(|token| SyntaxElement::Node(token.into_syntax())), ], @@ -736,13 +730,10 @@ impl GritNodeLikeBuilder { )) } } -pub fn grit_not(not_token: SyntaxToken, excl_token: SyntaxToken) -> GritNot { +pub fn grit_not(token_token: SyntaxToken) -> GritNot { GritNot::unwrap_cast(SyntaxNode::new_detached( GritSyntaxKind::GRIT_NOT, - [ - Some(SyntaxElement::Token(not_token)), - Some(SyntaxElement::Token(excl_token)), - ], + [Some(SyntaxElement::Token(token_token))], )) } pub fn grit_pattern_accumulate( diff --git a/crates/biome_grit_factory/src/generated/syntax_factory.rs b/crates/biome_grit_factory/src/generated/syntax_factory.rs index 93c68b6bc8c..318e5daa85e 100644 --- a/crates/biome_grit_factory/src/generated/syntax_factory.rs +++ b/crates/biome_grit_factory/src/generated/syntax_factory.rs @@ -226,17 +226,10 @@ impl SyntaxFactory for GritSyntaxFactory { } GRIT_BOOLEAN_LITERAL => { let mut elements = (&children).into_iter(); - let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); let mut current_element = elements.next(); if let Some(element) = ¤t_element { - if element.kind() == T![true] { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if element.kind() == T![false] { + if matches!(element.kind(), T![true] | T![false]) { slots.mark_present(); current_element = elements.next(); } @@ -422,7 +415,7 @@ impl SyntaxFactory for GritSyntaxFactory { let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); let mut current_element = elements.next(); if let Some(element) = ¤t_element { - if element.kind() == T!["$..."] { + if element.kind() == T ! [...] { slots.mark_present(); current_element = elements.next(); } @@ -1204,17 +1197,10 @@ impl SyntaxFactory for GritSyntaxFactory { } GRIT_NOT => { let mut elements = (&children).into_iter(); - let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); let mut current_element = elements.next(); if let Some(element) = ¤t_element { - if element.kind() == T![not] { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if element.kind() == T![!] { + if matches!(element.kind(), T![not] | T![!]) { slots.mark_present(); current_element = elements.next(); } diff --git a/crates/biome_grit_parser/src/lexer/mod.rs b/crates/biome_grit_parser/src/lexer/mod.rs index d1669ea9d44..a835c3837d1 100644 --- a/crates/biome_grit_parser/src/lexer/mod.rs +++ b/crates/biome_grit_parser/src/lexer/mod.rs @@ -287,7 +287,7 @@ impl<'src> Lexer<'src> { b'>' => self.eat_gt(), b':' => self.eat_byte(T![:]), b';' => self.eat_byte(T![;]), - b'.' => self.eat_byte(T![.]), + b'.' => self.eat_dots(), b',' => self.eat_byte(T![,]), b'+' => self.eat_plus_or_acc(), b'*' => self.eat_byte(T![*]), @@ -299,6 +299,7 @@ impl<'src> Lexer<'src> { b'(' => self.eat_byte(T!['(']), b')' => self.eat_byte(T![')']), b'$' => self.lex_variable(), + b'!' => self.eat_byte(T![!]), _ if is_leading_identifier_byte(current) => self.lex_name(current), _ if (b'0'..=b'9').contains(¤t) || current == b'-' => self.lex_number(current), _ if self.position == 0 && self.consume_potential_bom().is_some() => UNICODE_BOM, @@ -306,6 +307,19 @@ impl<'src> Lexer<'src> { } } + fn eat_dots(&mut self) -> GritSyntaxKind { + assert_eq!(self.current_byte(), Some(b'.')); + self.advance(1); + + match self.current_byte() { + Some(b'.') if self.byte_at(1) == Some(b'.') => { + self.advance(2); + DOT3 + } + _ => T![.], + } + } + fn eat_equals_or_rewrite(&mut self) -> GritSyntaxKind { assert_eq!(self.current_byte(), Some(b'=')); self.advance(1); @@ -840,7 +854,6 @@ impl<'src> Lexer<'src> { b"html" => HTML_KW, b"typescript" => TYPESCRIPT_KW, b"jsx" => JSX_KW, - b"js_do_not_use" => JS_DO_NOT_USE_KW, b"as" => AS_KW, b"limit" => LIMIT_KW, b"where" => WHERE_KW, @@ -954,14 +967,6 @@ impl<'src> Lexer<'src> { return DOLLAR_UNDERSCORE; } - if self.current_byte() == Some(b'.') - && self.byte_at(1) == Some(b'.') - && self.byte_at(2) == Some(b'.') - { - self.advance(3); - return DOLLAR_DOT3; - } - while let Some(byte) = self.current_byte() { if is_identifier_byte(byte) { self.advance(1) diff --git a/crates/biome_grit_parser/src/parser/literals.rs b/crates/biome_grit_parser/src/parser/literals.rs index 259d06df7a9..37cb109d129 100644 --- a/crates/biome_grit_parser/src/parser/literals.rs +++ b/crates/biome_grit_parser/src/parser/literals.rs @@ -70,12 +70,12 @@ fn parse_code_snippet(p: &mut GritParser) -> ParsedSyntax { #[inline] fn parse_dotdotdot(p: &mut GritParser) -> ParsedSyntax { - if !p.at(DOLLAR_DOT3) { + if !p.at(DOT3) { return Absent; } let m = p.start(); - p.bump(DOLLAR_DOT3); + p.bump(DOT3); let _ = parse_maybe_curly_pattern(p); Present(m.complete(p, GRIT_DOTDOTDOT)) } @@ -161,7 +161,7 @@ fn parse_list_pattern_list(p: &mut GritParser) -> ParsedSyntax { #[inline] fn parse_list_pattern(p: &mut GritParser) -> ParsedSyntax { - if p.at(DOLLAR_DOT3) { + if p.at(DOT3) { parse_dotdotdot(p) } else { parse_literal(p) diff --git a/crates/biome_grit_parser/src/parser/mod.rs b/crates/biome_grit_parser/src/parser/mod.rs index 806a60f003b..db17566a007 100644 --- a/crates/biome_grit_parser/src/parser/mod.rs +++ b/crates/biome_grit_parser/src/parser/mod.rs @@ -279,6 +279,17 @@ fn parse_named_arg_list(p: &mut GritParser) -> ParsedSyntax { Present(m.complete(p, GRIT_NAMED_ARG_LIST)) } +#[inline] +fn parse_not(p: &mut GritParser) -> ParsedSyntax { + if !p.at_ts(NOT_SET) { + return Absent; + } + + let m = p.start(); + p.bump_ts(NOT_SET); + Present(m.complete(p, GRIT_NOT)) +} + #[inline] fn parse_variable(p: &mut GritParser) -> ParsedSyntax { if !p.at(GRIT_VARIABLE) { diff --git a/crates/biome_grit_parser/src/parser/patterns.rs b/crates/biome_grit_parser/src/parser/patterns.rs index f9d093d0601..cf07f176a1e 100644 --- a/crates/biome_grit_parser/src/parser/patterns.rs +++ b/crates/biome_grit_parser/src/parser/patterns.rs @@ -2,7 +2,8 @@ use super::constants::*; use super::literals::*; use super::parse_error::{expected_list_index, expected_map_key, expected_pattern}; use super::predicates::parse_predicate; -use super::{parse_name, parse_variable, parse_variable_list, GritParser}; +use super::{parse_name, parse_not, parse_variable, parse_variable_list, GritParser}; +use biome_grit_syntax::GritSyntaxKind; use biome_grit_syntax::GritSyntaxKind::*; use biome_grit_syntax::T; use biome_parser::parse_recovery::ParseRecoveryTokenSet; @@ -31,11 +32,6 @@ pub(crate) fn parse_pattern(p: &mut GritParser) -> ParsedSyntax { GRIT_VARIABLE => parse_variable(p), GRIT_REGEX | GRIT_SNIPPET_REGEX => parse_regex_pattern(p), LIKE_KW => parse_like(p), - // TODO: GritMulOperation => {} - // TODO: GritDivOperation => {} - // TODO: GritModOperation => {} - // TODO: GritAddOperation => {} - // TODO: GritSubOperation => {} SEQUENTIAL_KW => parse_sequential(p), MULTIFILE_KW => parse_files(p), T!['('] => parse_bracketed_pattern(p), @@ -46,6 +42,7 @@ pub(crate) fn parse_pattern(p: &mut GritParser) -> ParsedSyntax { return Absent; }; + // precedence: 10 let left = match p.cur() { AS_KW => parse_pattern_as(p, left), _ => Present(left), @@ -55,10 +52,44 @@ pub(crate) fn parse_pattern(p: &mut GritParser) -> ParsedSyntax { return Absent; }; + // precedence: 8 + let left = match p.cur() { + T![*] => parse_operator(p, left, T![*]), + T![/] => parse_operator(p, left, T![/]), + T![%] => parse_operator(p, left, T![%]), + _ => Present(left), + }; + + let Present(left) = left else { + return Absent; + }; + + // precedence: 7 + let left = match p.cur() { + T![+] => parse_operator(p, left, T![+]), + T![-] => parse_operator(p, left, T![-]), + _ => Present(left), + }; + + let Present(left) = left else { + return Absent; + }; + + // precedence: 3 let left = match p.cur() { T![=>] => parse_rewrite(p, left), + T![+=] => parse_pattern_accumulate(p, left), T![.] => parse_map_accessor(p, left), T!['['] => parse_list_accessor(p, left), + _ => Present(left), + }; + + let Present(left) = left else { + return Absent; + }; + + // precedence: 1 + let left = match p.cur() { LIMIT_KW => parse_pattern_limit(p, left), WHERE_KW => parse_pattern_where(p, left), _ => Present(left), @@ -68,9 +99,9 @@ pub(crate) fn parse_pattern(p: &mut GritParser) -> ParsedSyntax { return Absent; }; + // precedence: 0 match p.cur() { T![=] if CONTAINER_SET.contains(left.kind(p)) => parse_assignment_as_pattern(p, left), - T![+=] => parse_pattern_accumulate(p, left), _ => Present(left), } } @@ -460,6 +491,32 @@ fn parse_node_like(p: &mut GritParser) -> ParsedSyntax { Present(m.complete(p, GRIT_NODE_LIKE)) } +#[inline] +fn parse_operator( + p: &mut GritParser, + left: CompletedMarker, + operator: GritSyntaxKind, +) -> ParsedSyntax { + if !p.at(operator) { + return Absent; + } + + let m = left.precede(p); + p.bump(operator); + + let _ = parse_pattern(p); + + let kind = match operator { + T![*] => GRIT_MUL_OPERATION, + T![/] => GRIT_DIV_OPERATION, + T![%] => GRIT_MOD_OPERATION, + T![+] => GRIT_ADD_OPERATION, + T![-] => GRIT_SUB_OPERATION, + _ => unreachable!("invalid operator: {operator:?}"), + }; + Present(m.complete(p, kind)) +} + #[inline] fn parse_pattern_accumulate(p: &mut GritParser, left: CompletedMarker) -> ParsedSyntax { if !p.at(T![+=]) { @@ -748,12 +805,11 @@ fn parse_pattern_maybe(p: &mut GritParser) -> ParsedSyntax { #[inline] fn parse_pattern_not(p: &mut GritParser) -> ParsedSyntax { - if !p.at_ts(NOT_SET) { - return Absent; - } + let m = match parse_not(p) { + Present(syntax) => syntax.precede(p), + Absent => return Absent, + }; - let m = p.start(); - p.bump_ts(NOT_SET); match parse_pattern(p) { Present(_) => Present(m.complete(p, GRIT_PATTERN_NOT)), Absent => { diff --git a/crates/biome_grit_parser/src/parser/predicates.rs b/crates/biome_grit_parser/src/parser/predicates.rs index 29955650f77..a26c8c548f2 100644 --- a/crates/biome_grit_parser/src/parser/predicates.rs +++ b/crates/biome_grit_parser/src/parser/predicates.rs @@ -1,8 +1,8 @@ use super::literals::{parse_boolean_literal, parse_literal}; use super::parse_error::expected_pattern; use super::patterns::{parse_container, parse_pattern}; -use super::GritParser; use super::{constants::*, parse_named_arg_list}; +use super::{parse_not, GritParser}; use biome_grit_syntax::GritSyntaxKind::*; use biome_grit_syntax::T; use biome_parser::parse_recovery::ParseRecoveryTokenSet; @@ -250,12 +250,11 @@ fn parse_predicate_maybe(p: &mut GritParser) -> ParsedSyntax { #[inline] fn parse_predicate_not(p: &mut GritParser) -> ParsedSyntax { - if !p.at_ts(NOT_SET) { - return Absent; - } + let m = match parse_not(p) { + Present(syntax) => syntax.precede(p), + Absent => return Absent, + }; - let m = p.start(); - p.bump_ts(NOT_SET); match parse_predicate(p) { Present(_) => Present(m.complete(p, GRIT_PREDICATE_NOT)), Absent => { diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/dotdotdot_clause.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/dotdotdot_clause.grit new file mode 100644 index 00000000000..e5cff821792 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/dotdotdot_clause.grit @@ -0,0 +1,3 @@ +`var $x = [$numbers]` => `var firstPrimes = [$numbers]` where { + $numbers <: [ `2`, `3`, ..., `11` ] +} diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/dotdotdot_clause.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/dotdotdot_clause.grit.snap new file mode 100644 index 00000000000..05bb74f782b --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/dotdotdot_clause.grit.snap @@ -0,0 +1,138 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +`var $x = [$numbers]` => `var firstPrimes = [$numbers]` where { + $numbers <: [ `2`, `3`, ..., `11` ] +} + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: missing (optional), + definitions: GritDefinitionList [], + pattern: GritRewrite { + left: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@0..22 "`var $x = [$numbers]`" [] [Whitespace(" ")], + }, + }, + annotation: missing (optional), + fat_arrow_token: FAT_ARROW@22..25 "=>" [] [Whitespace(" ")], + right: GritPatternWhere { + pattern: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@25..56 "`var firstPrimes = [$numbers]`" [] [Whitespace(" ")], + }, + }, + where_token: WHERE_KW@56..62 "where" [] [Whitespace(" ")], + side_condition: GritPredicateAnd { + and_token: missing (optional), + l_curly_token: L_CURLY@62..63 "{" [] [], + predicates: GritPredicateList [ + GritPredicateMatch { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@63..75 "$numbers" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + match_token: MATCH@75..78 "<:" [] [Whitespace(" ")], + right: GritList { + grit_name: missing (optional), + l_brack_token: L_BRACK@78..80 "[" [] [Whitespace(" ")], + patterns: GritListPatternList [ + GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@80..83 "`2`" [] [], + }, + }, + COMMA@83..85 "," [] [Whitespace(" ")], + GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@85..88 "`3`" [] [], + }, + }, + COMMA@88..90 "," [] [Whitespace(" ")], + GritDotdotdot { + dotdotdot_token: DOT3@90..93 "..." [] [], + maybe_curly_grit_pattern: missing (optional), + }, + COMMA@93..95 "," [] [Whitespace(" ")], + GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@95..100 "`11`" [] [Whitespace(" ")], + }, + }, + ], + r_brack_token: R_BRACK@100..101 "]" [] [], + }, + grit_bogus: missing (optional), + }, + ], + r_curly_token: R_CURLY@101..103 "}" [Newline("\n")] [], + }, + }, + }, + definitions_continued: GritDefinitionList [], + eof_token: EOF@103..104 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..104 + 0: (empty) + 1: (empty) + 2: (empty) + 3: GRIT_DEFINITION_LIST@0..0 + 4: GRIT_REWRITE@0..103 + 0: GRIT_CODE_SNIPPET@0..22 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@0..22 + 0: GRIT_BACKTICK_SNIPPET@0..22 "`var $x = [$numbers]`" [] [Whitespace(" ")] + 1: (empty) + 2: FAT_ARROW@22..25 "=>" [] [Whitespace(" ")] + 3: GRIT_PATTERN_WHERE@25..103 + 0: GRIT_CODE_SNIPPET@25..56 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@25..56 + 0: GRIT_BACKTICK_SNIPPET@25..56 "`var firstPrimes = [$numbers]`" [] [Whitespace(" ")] + 1: WHERE_KW@56..62 "where" [] [Whitespace(" ")] + 2: GRIT_PREDICATE_AND@62..103 + 0: (empty) + 1: L_CURLY@62..63 "{" [] [] + 2: GRIT_PREDICATE_LIST@63..101 + 0: GRIT_PREDICATE_MATCH@63..101 + 0: GRIT_VARIABLE@63..75 + 0: GRIT_VARIABLE@63..75 "$numbers" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: MATCH@75..78 "<:" [] [Whitespace(" ")] + 2: GRIT_LIST@78..101 + 0: (empty) + 1: L_BRACK@78..80 "[" [] [Whitespace(" ")] + 2: GRIT_LIST_PATTERN_LIST@80..100 + 0: GRIT_CODE_SNIPPET@80..83 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@80..83 + 0: GRIT_BACKTICK_SNIPPET@80..83 "`2`" [] [] + 1: COMMA@83..85 "," [] [Whitespace(" ")] + 2: GRIT_CODE_SNIPPET@85..88 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@85..88 + 0: GRIT_BACKTICK_SNIPPET@85..88 "`3`" [] [] + 3: COMMA@88..90 "," [] [Whitespace(" ")] + 4: GRIT_DOTDOTDOT@90..93 + 0: DOT3@90..93 "..." [] [] + 1: (empty) + 5: COMMA@93..95 "," [] [Whitespace(" ")] + 6: GRIT_CODE_SNIPPET@95..100 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@95..100 + 0: GRIT_BACKTICK_SNIPPET@95..100 "`11`" [] [Whitespace(" ")] + 3: R_BRACK@100..101 "]" [] [] + 3: (empty) + 3: R_CURLY@101..103 "}" [Newline("\n")] [] + 5: GRIT_DEFINITION_LIST@103..103 + 6: EOF@103..104 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/limit_clause.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/limit_clause.grit new file mode 100644 index 00000000000..c708df102ce --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/limit_clause.grit @@ -0,0 +1,3 @@ +`console.$method($message)` => `console.warn($message)` where { + $method <: not `error` +} limit 2 // Only find 2 files diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/limit_clause.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/limit_clause.grit.snap new file mode 100644 index 00000000000..9d2cec945b8 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/limit_clause.grit.snap @@ -0,0 +1,115 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +`console.$method($message)` => `console.warn($message)` where { + $method <: not `error` +} limit 2 // Only find 2 files + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: missing (optional), + definitions: GritDefinitionList [], + pattern: GritPatternLimit { + pattern: GritRewrite { + left: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@0..28 "`console.$method($message)`" [] [Whitespace(" ")], + }, + }, + annotation: missing (optional), + fat_arrow_token: FAT_ARROW@28..31 "=>" [] [Whitespace(" ")], + right: GritPatternWhere { + pattern: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@31..56 "`console.warn($message)`" [] [Whitespace(" ")], + }, + }, + where_token: WHERE_KW@56..62 "where" [] [Whitespace(" ")], + side_condition: GritPredicateAnd { + and_token: missing (optional), + l_curly_token: L_CURLY@62..63 "{" [] [], + predicates: GritPredicateList [ + GritPredicateMatch { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@63..74 "$method" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + match_token: MATCH@74..77 "<:" [] [Whitespace(" ")], + right: GritPatternNot { + grit_not: GritNot { + token: NOT_KW@77..81 "not" [] [Whitespace(" ")], + }, + pattern: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@81..88 "`error`" [] [], + }, + }, + }, + grit_bogus: missing (optional), + }, + ], + r_curly_token: R_CURLY@88..91 "}" [Newline("\n")] [Whitespace(" ")], + }, + }, + }, + limit_token: LIMIT_KW@91..97 "limit" [] [Whitespace(" ")], + limit: GritIntLiteral { + value_token: GRIT_INT@97..119 "2" [] [Whitespace(" "), Comments("// Only find 2 files")], + }, + }, + definitions_continued: GritDefinitionList [], + eof_token: EOF@119..120 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..120 + 0: (empty) + 1: (empty) + 2: (empty) + 3: GRIT_DEFINITION_LIST@0..0 + 4: GRIT_PATTERN_LIMIT@0..119 + 0: GRIT_REWRITE@0..91 + 0: GRIT_CODE_SNIPPET@0..28 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@0..28 + 0: GRIT_BACKTICK_SNIPPET@0..28 "`console.$method($message)`" [] [Whitespace(" ")] + 1: (empty) + 2: FAT_ARROW@28..31 "=>" [] [Whitespace(" ")] + 3: GRIT_PATTERN_WHERE@31..91 + 0: GRIT_CODE_SNIPPET@31..56 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@31..56 + 0: GRIT_BACKTICK_SNIPPET@31..56 "`console.warn($message)`" [] [Whitespace(" ")] + 1: WHERE_KW@56..62 "where" [] [Whitespace(" ")] + 2: GRIT_PREDICATE_AND@62..91 + 0: (empty) + 1: L_CURLY@62..63 "{" [] [] + 2: GRIT_PREDICATE_LIST@63..88 + 0: GRIT_PREDICATE_MATCH@63..88 + 0: GRIT_VARIABLE@63..74 + 0: GRIT_VARIABLE@63..74 "$method" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: MATCH@74..77 "<:" [] [Whitespace(" ")] + 2: GRIT_PATTERN_NOT@77..88 + 0: GRIT_NOT@77..81 + 0: NOT_KW@77..81 "not" [] [Whitespace(" ")] + 1: GRIT_CODE_SNIPPET@81..88 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@81..88 + 0: GRIT_BACKTICK_SNIPPET@81..88 "`error`" [] [] + 3: (empty) + 3: R_CURLY@88..91 "}" [Newline("\n")] [Whitespace(" ")] + 1: LIMIT_KW@91..97 "limit" [] [Whitespace(" ")] + 2: GRIT_INT_LITERAL@97..119 + 0: GRIT_INT@97..119 "2" [] [Whitespace(" "), Comments("// Only find 2 files")] + 5: GRIT_DEFINITION_LIST@119..119 + 6: EOF@119..120 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/list_pattern.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/list_pattern.grit new file mode 100644 index 00000000000..66fc874747e --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/list_pattern.grit @@ -0,0 +1,3 @@ +`var $x = [$numbers]` => `var firstPrimes = [$numbers]` where { + $numbers <: [ `2`, `3`, `5` ] +} diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/list_pattern.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/list_pattern.grit.snap new file mode 100644 index 00000000000..8cbf9210ae4 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/list_pattern.grit.snap @@ -0,0 +1,129 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +`var $x = [$numbers]` => `var firstPrimes = [$numbers]` where { + $numbers <: [ `2`, `3`, `5` ] +} + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: missing (optional), + definitions: GritDefinitionList [], + pattern: GritRewrite { + left: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@0..22 "`var $x = [$numbers]`" [] [Whitespace(" ")], + }, + }, + annotation: missing (optional), + fat_arrow_token: FAT_ARROW@22..25 "=>" [] [Whitespace(" ")], + right: GritPatternWhere { + pattern: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@25..56 "`var firstPrimes = [$numbers]`" [] [Whitespace(" ")], + }, + }, + where_token: WHERE_KW@56..62 "where" [] [Whitespace(" ")], + side_condition: GritPredicateAnd { + and_token: missing (optional), + l_curly_token: L_CURLY@62..63 "{" [] [], + predicates: GritPredicateList [ + GritPredicateMatch { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@63..75 "$numbers" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + match_token: MATCH@75..78 "<:" [] [Whitespace(" ")], + right: GritList { + grit_name: missing (optional), + l_brack_token: L_BRACK@78..80 "[" [] [Whitespace(" ")], + patterns: GritListPatternList [ + GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@80..83 "`2`" [] [], + }, + }, + COMMA@83..85 "," [] [Whitespace(" ")], + GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@85..88 "`3`" [] [], + }, + }, + COMMA@88..90 "," [] [Whitespace(" ")], + GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@90..94 "`5`" [] [Whitespace(" ")], + }, + }, + ], + r_brack_token: R_BRACK@94..95 "]" [] [], + }, + grit_bogus: missing (optional), + }, + ], + r_curly_token: R_CURLY@95..97 "}" [Newline("\n")] [], + }, + }, + }, + definitions_continued: GritDefinitionList [], + eof_token: EOF@97..98 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..98 + 0: (empty) + 1: (empty) + 2: (empty) + 3: GRIT_DEFINITION_LIST@0..0 + 4: GRIT_REWRITE@0..97 + 0: GRIT_CODE_SNIPPET@0..22 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@0..22 + 0: GRIT_BACKTICK_SNIPPET@0..22 "`var $x = [$numbers]`" [] [Whitespace(" ")] + 1: (empty) + 2: FAT_ARROW@22..25 "=>" [] [Whitespace(" ")] + 3: GRIT_PATTERN_WHERE@25..97 + 0: GRIT_CODE_SNIPPET@25..56 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@25..56 + 0: GRIT_BACKTICK_SNIPPET@25..56 "`var firstPrimes = [$numbers]`" [] [Whitespace(" ")] + 1: WHERE_KW@56..62 "where" [] [Whitespace(" ")] + 2: GRIT_PREDICATE_AND@62..97 + 0: (empty) + 1: L_CURLY@62..63 "{" [] [] + 2: GRIT_PREDICATE_LIST@63..95 + 0: GRIT_PREDICATE_MATCH@63..95 + 0: GRIT_VARIABLE@63..75 + 0: GRIT_VARIABLE@63..75 "$numbers" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: MATCH@75..78 "<:" [] [Whitespace(" ")] + 2: GRIT_LIST@78..95 + 0: (empty) + 1: L_BRACK@78..80 "[" [] [Whitespace(" ")] + 2: GRIT_LIST_PATTERN_LIST@80..94 + 0: GRIT_CODE_SNIPPET@80..83 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@80..83 + 0: GRIT_BACKTICK_SNIPPET@80..83 "`2`" [] [] + 1: COMMA@83..85 "," [] [Whitespace(" ")] + 2: GRIT_CODE_SNIPPET@85..88 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@85..88 + 0: GRIT_BACKTICK_SNIPPET@85..88 "`3`" [] [] + 3: COMMA@88..90 "," [] [Whitespace(" ")] + 4: GRIT_CODE_SNIPPET@90..94 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@90..94 + 0: GRIT_BACKTICK_SNIPPET@90..94 "`5`" [] [Whitespace(" ")] + 3: R_BRACK@94..95 "]" [] [] + 3: (empty) + 3: R_CURLY@95..97 "}" [Newline("\n")] [] + 5: GRIT_DEFINITION_LIST@97..97 + 6: EOF@97..98 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/multiply.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/multiply.grit new file mode 100644 index 00000000000..34ad4457c8f --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/multiply.grit @@ -0,0 +1,4 @@ +js"multiply($x)" where { + $y = $x * 2, + $x => $y +} diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/multiply.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/multiply.grit.snap new file mode 100644 index 00000000000..4eeaf14834a --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/multiply.grit.snap @@ -0,0 +1,116 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +js"multiply($x)" where { + $y = $x * 2, + $x => $y +} + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: missing (optional), + definitions: GritDefinitionList [], + pattern: GritPatternWhere { + pattern: GritCodeSnippet { + source: GritLanguageSpecificSnippet { + language: GritLanguageName { + language_kind: JS_KW@0..2 "js" [] [], + }, + snippet_token: GRIT_STRING@2..17 "\"multiply($x)\"" [] [Whitespace(" ")], + }, + }, + where_token: WHERE_KW@17..23 "where" [] [Whitespace(" ")], + side_condition: GritPredicateAnd { + and_token: missing (optional), + l_curly_token: L_CURLY@23..24 "{" [] [], + predicates: GritPredicateList [ + GritPredicateAssignment { + container: GritVariable { + grit_variable_token: GRIT_VARIABLE@24..30 "$y" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + eq_token: EQ@30..32 "=" [] [Whitespace(" ")], + pattern: GritMulOperation { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@32..35 "$x" [] [Whitespace(" ")], + }, + star_token: STAR@35..37 "*" [] [Whitespace(" ")], + right: GritIntLiteral { + value_token: GRIT_INT@37..38 "2" [] [], + }, + }, + grit_bogus: missing (optional), + }, + COMMA@38..39 "," [] [], + GritPredicateRewrite { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@39..45 "$x" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + annotation: missing (optional), + fat_arrow_token: FAT_ARROW@45..48 "=>" [] [Whitespace(" ")], + right: GritVariable { + grit_variable_token: GRIT_VARIABLE@48..50 "$y" [] [], + }, + grit_bogus: missing (optional), + }, + ], + r_curly_token: R_CURLY@50..52 "}" [Newline("\n")] [], + }, + }, + definitions_continued: GritDefinitionList [], + eof_token: EOF@52..53 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..53 + 0: (empty) + 1: (empty) + 2: (empty) + 3: GRIT_DEFINITION_LIST@0..0 + 4: GRIT_PATTERN_WHERE@0..52 + 0: GRIT_CODE_SNIPPET@0..17 + 0: GRIT_LANGUAGE_SPECIFIC_SNIPPET@0..17 + 0: GRIT_LANGUAGE_NAME@0..2 + 0: JS_KW@0..2 "js" [] [] + 1: GRIT_STRING@2..17 "\"multiply($x)\"" [] [Whitespace(" ")] + 1: WHERE_KW@17..23 "where" [] [Whitespace(" ")] + 2: GRIT_PREDICATE_AND@23..52 + 0: (empty) + 1: L_CURLY@23..24 "{" [] [] + 2: GRIT_PREDICATE_LIST@24..50 + 0: GRIT_PREDICATE_ASSIGNMENT@24..38 + 0: GRIT_VARIABLE@24..30 + 0: GRIT_VARIABLE@24..30 "$y" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: EQ@30..32 "=" [] [Whitespace(" ")] + 2: GRIT_MUL_OPERATION@32..38 + 0: GRIT_VARIABLE@32..35 + 0: GRIT_VARIABLE@32..35 "$x" [] [Whitespace(" ")] + 1: STAR@35..37 "*" [] [Whitespace(" ")] + 2: GRIT_INT_LITERAL@37..38 + 0: GRIT_INT@37..38 "2" [] [] + 3: (empty) + 1: COMMA@38..39 "," [] [] + 2: GRIT_PREDICATE_REWRITE@39..50 + 0: GRIT_VARIABLE@39..45 + 0: GRIT_VARIABLE@39..45 "$x" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: (empty) + 2: FAT_ARROW@45..48 "=>" [] [Whitespace(" ")] + 3: GRIT_VARIABLE@48..50 + 0: GRIT_VARIABLE@48..50 "$y" [] [] + 4: (empty) + 3: R_CURLY@50..52 "}" [Newline("\n")] [] + 5: GRIT_DEFINITION_LIST@52..52 + 6: EOF@52..53 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/not_condition.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/not_condition.grit new file mode 100644 index 00000000000..e657317b599 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/not_condition.grit @@ -0,0 +1,3 @@ +`console.log('$message');` => `console.warn('$message');` where { + ! $message <: "Hello, world!" +} diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/not_condition.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/not_condition.grit.snap new file mode 100644 index 00000000000..31572b04ab7 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/not_condition.grit.snap @@ -0,0 +1,102 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +`console.log('$message');` => `console.warn('$message');` where { + ! $message <: "Hello, world!" +} + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: missing (optional), + definitions: GritDefinitionList [], + pattern: GritRewrite { + left: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@0..27 "`console.log('$message');`" [] [Whitespace(" ")], + }, + }, + annotation: missing (optional), + fat_arrow_token: FAT_ARROW@27..30 "=>" [] [Whitespace(" ")], + right: GritPatternWhere { + pattern: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@30..58 "`console.warn('$message');`" [] [Whitespace(" ")], + }, + }, + where_token: WHERE_KW@58..64 "where" [] [Whitespace(" ")], + side_condition: GritPredicateAnd { + and_token: missing (optional), + l_curly_token: L_CURLY@64..65 "{" [] [], + predicates: GritPredicateList [ + GritPredicateNot { + grit_not: GritNot { + token: BANG@65..70 "!" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + predicate: GritPredicateMatch { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@70..79 "$message" [] [Whitespace(" ")], + }, + match_token: MATCH@79..82 "<:" [] [Whitespace(" ")], + right: GritStringLiteral { + value_token: GRIT_STRING@82..97 "\"Hello, world!\"" [] [], + }, + grit_bogus: missing (optional), + }, + }, + ], + r_curly_token: R_CURLY@97..99 "}" [Newline("\n")] [], + }, + }, + }, + definitions_continued: GritDefinitionList [], + eof_token: EOF@99..100 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..100 + 0: (empty) + 1: (empty) + 2: (empty) + 3: GRIT_DEFINITION_LIST@0..0 + 4: GRIT_REWRITE@0..99 + 0: GRIT_CODE_SNIPPET@0..27 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@0..27 + 0: GRIT_BACKTICK_SNIPPET@0..27 "`console.log('$message');`" [] [Whitespace(" ")] + 1: (empty) + 2: FAT_ARROW@27..30 "=>" [] [Whitespace(" ")] + 3: GRIT_PATTERN_WHERE@30..99 + 0: GRIT_CODE_SNIPPET@30..58 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@30..58 + 0: GRIT_BACKTICK_SNIPPET@30..58 "`console.warn('$message');`" [] [Whitespace(" ")] + 1: WHERE_KW@58..64 "where" [] [Whitespace(" ")] + 2: GRIT_PREDICATE_AND@64..99 + 0: (empty) + 1: L_CURLY@64..65 "{" [] [] + 2: GRIT_PREDICATE_LIST@65..97 + 0: GRIT_PREDICATE_NOT@65..97 + 0: GRIT_NOT@65..70 + 0: BANG@65..70 "!" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: GRIT_PREDICATE_MATCH@70..97 + 0: GRIT_VARIABLE@70..79 + 0: GRIT_VARIABLE@70..79 "$message" [] [Whitespace(" ")] + 1: MATCH@79..82 "<:" [] [Whitespace(" ")] + 2: GRIT_STRING_LITERAL@82..97 + 0: GRIT_STRING@82..97 "\"Hello, world!\"" [] [] + 3: (empty) + 3: R_CURLY@97..99 "}" [Newline("\n")] [] + 5: GRIT_DEFINITION_LIST@99..99 + 6: EOF@99..100 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_grit_parser/tests/spec_test.rs b/crates/biome_grit_parser/tests/spec_test.rs index 8f0fe59f241..27ffd9061c9 100644 --- a/crates/biome_grit_parser/tests/spec_test.rs +++ b/crates/biome_grit_parser/tests/spec_test.rs @@ -97,7 +97,7 @@ pub fn run(test_case: &str, _snapshot_name: &str, test_directory: &str, outcome_ .descendants() .any(|node| node.kind().is_bogus()) { - panic!("Parsed tree of a 'OK' test case should not contain any missing required children or bogus nodes: \n {formatted_ast:#?} \n\n {}", formatted_ast); + panic!("Parsed tree of a 'OK' test case should not contain any missing required children or bogus nodes:\n{formatted_ast}"); } } ExpectedOutcome::Fail => { diff --git a/crates/biome_grit_syntax/src/generated/kind.rs b/crates/biome_grit_syntax/src/generated/kind.rs index 1398b719ac4..da2b5bd3139 100644 --- a/crates/biome_grit_syntax/src/generated/kind.rs +++ b/crates/biome_grit_syntax/src/generated/kind.rs @@ -13,7 +13,7 @@ pub enum GritSyntaxKind { #[doc = r" Any Unicode BOM character that may be present at the start of"] #[doc = r" a file."] UNICODE_BOM, - DOLLAR_DOT3, + DOT3, DOLLAR_UNDERSCORE, MATCH, SEMICOLON, @@ -215,10 +215,10 @@ use self::GritSyntaxKind::*; impl GritSyntaxKind { pub const fn is_punct(self) -> bool { match self { - DOLLAR_DOT3 | DOLLAR_UNDERSCORE | MATCH | SEMICOLON | COMMA | L_PAREN | R_PAREN - | L_CURLY | R_CURLY | L_BRACK | R_BRACK | L_ANGLE | R_ANGLE | PLUS | STAR | SLASH - | PERCENT | DOT | COLON | EQ | EQ2 | FAT_ARROW | BANG | NEQ | MINUS | LTEQ | GTEQ - | PLUSEQ | BACKTICK => true, + DOT3 | DOLLAR_UNDERSCORE | MATCH | SEMICOLON | COMMA | L_PAREN | R_PAREN | L_CURLY + | R_CURLY | L_BRACK | R_BRACK | L_ANGLE | R_ANGLE | PLUS | STAR | SLASH | PERCENT + | DOT | COLON | EQ | EQ2 | FAT_ARROW | BANG | NEQ | MINUS | LTEQ | GTEQ | PLUSEQ + | BACKTICK => true, _ => false, } } @@ -295,7 +295,7 @@ impl GritSyntaxKind { } pub const fn to_string(&self) -> Option<&'static str> { let tok = match self { - DOLLAR_DOT3 => "$...", + DOT3 => "...", DOLLAR_UNDERSCORE => "$_", MATCH => "<:", SEMICOLON => ";", @@ -374,4 +374,4 @@ impl GritSyntaxKind { } #[doc = r" Utility macro for creating a SyntaxKind through simple macro syntax"] #[macro_export] -macro_rules ! T { ["$..."] => { $ crate :: GritSyntaxKind :: DOLLAR_DOT3 } ; ["$_"] => { $ crate :: GritSyntaxKind :: DOLLAR_UNDERSCORE } ; [<:] => { $ crate :: GritSyntaxKind :: MATCH } ; [;] => { $ crate :: GritSyntaxKind :: SEMICOLON } ; [,] => { $ crate :: GritSyntaxKind :: COMMA } ; ['('] => { $ crate :: GritSyntaxKind :: L_PAREN } ; [')'] => { $ crate :: GritSyntaxKind :: R_PAREN } ; ['{'] => { $ crate :: GritSyntaxKind :: L_CURLY } ; ['}'] => { $ crate :: GritSyntaxKind :: R_CURLY } ; ['['] => { $ crate :: GritSyntaxKind :: L_BRACK } ; [']'] => { $ crate :: GritSyntaxKind :: R_BRACK } ; [<] => { $ crate :: GritSyntaxKind :: L_ANGLE } ; [>] => { $ crate :: GritSyntaxKind :: R_ANGLE } ; [+] => { $ crate :: GritSyntaxKind :: PLUS } ; [*] => { $ crate :: GritSyntaxKind :: STAR } ; [/] => { $ crate :: GritSyntaxKind :: SLASH } ; [%] => { $ crate :: GritSyntaxKind :: PERCENT } ; [.] => { $ crate :: GritSyntaxKind :: DOT } ; [:] => { $ crate :: GritSyntaxKind :: COLON } ; [=] => { $ crate :: GritSyntaxKind :: EQ } ; [==] => { $ crate :: GritSyntaxKind :: EQ2 } ; [=>] => { $ crate :: GritSyntaxKind :: FAT_ARROW } ; [!] => { $ crate :: GritSyntaxKind :: BANG } ; [!=] => { $ crate :: GritSyntaxKind :: NEQ } ; [-] => { $ crate :: GritSyntaxKind :: MINUS } ; [<=] => { $ crate :: GritSyntaxKind :: LTEQ } ; [>=] => { $ crate :: GritSyntaxKind :: GTEQ } ; [+=] => { $ crate :: GritSyntaxKind :: PLUSEQ } ; ['`'] => { $ crate :: GritSyntaxKind :: BACKTICK } ; [sequential] => { $ crate :: GritSyntaxKind :: SEQUENTIAL_KW } ; [multifile] => { $ crate :: GritSyntaxKind :: MULTIFILE_KW } ; [engine] => { $ crate :: GritSyntaxKind :: ENGINE_KW } ; [biome] => { $ crate :: GritSyntaxKind :: BIOME_KW } ; [language] => { $ crate :: GritSyntaxKind :: LANGUAGE_KW } ; [js] => { $ crate :: GritSyntaxKind :: JS_KW } ; [css] => { $ crate :: GritSyntaxKind :: CSS_KW } ; [json] => { $ crate :: GritSyntaxKind :: JSON_KW } ; [grit] => { $ crate :: GritSyntaxKind :: GRIT_KW } ; [html] => { $ crate :: GritSyntaxKind :: HTML_KW } ; [typescript] => { $ crate :: GritSyntaxKind :: TYPESCRIPT_KW } ; [jsx] => { $ crate :: GritSyntaxKind :: JSX_KW } ; [js_do_not_use] => { $ crate :: GritSyntaxKind :: JS_DO_NOT_USE_KW } ; [as] => { $ crate :: GritSyntaxKind :: AS_KW } ; [limit] => { $ crate :: GritSyntaxKind :: LIMIT_KW } ; [where] => { $ crate :: GritSyntaxKind :: WHERE_KW } ; [orelse] => { $ crate :: GritSyntaxKind :: ORELSE_KW } ; [maybe] => { $ crate :: GritSyntaxKind :: MAYBE_KW } ; [after] => { $ crate :: GritSyntaxKind :: AFTER_KW } ; [before] => { $ crate :: GritSyntaxKind :: BEFORE_KW } ; [contains] => { $ crate :: GritSyntaxKind :: CONTAINS_KW } ; [until] => { $ crate :: GritSyntaxKind :: UNTIL_KW } ; [includes] => { $ crate :: GritSyntaxKind :: INCLUDES_KW } ; [if] => { $ crate :: GritSyntaxKind :: IF_KW } ; [else] => { $ crate :: GritSyntaxKind :: ELSE_KW } ; [within] => { $ crate :: GritSyntaxKind :: WITHIN_KW } ; [bubble] => { $ crate :: GritSyntaxKind :: BUBBLE_KW } ; [not] => { $ crate :: GritSyntaxKind :: NOT_KW } ; [or] => { $ crate :: GritSyntaxKind :: OR_KW } ; [and] => { $ crate :: GritSyntaxKind :: AND_KW } ; [any] => { $ crate :: GritSyntaxKind :: ANY_KW } ; [some] => { $ crate :: GritSyntaxKind :: SOME_KW } ; [every] => { $ crate :: GritSyntaxKind :: EVERY_KW } ; [private] => { $ crate :: GritSyntaxKind :: PRIVATE_KW } ; [pattern] => { $ crate :: GritSyntaxKind :: PATTERN_KW } ; [predicate] => { $ crate :: GritSyntaxKind :: PREDICATE_KW } ; [function] => { $ crate :: GritSyntaxKind :: FUNCTION_KW } ; [true] => { $ crate :: GritSyntaxKind :: TRUE_KW } ; [false] => { $ crate :: GritSyntaxKind :: FALSE_KW } ; [undefined] => { $ crate :: GritSyntaxKind :: UNDEFINED_KW } ; [like] => { $ crate :: GritSyntaxKind :: LIKE_KW } ; [return] => { $ crate :: GritSyntaxKind :: RETURN_KW } ; [ident] => { $ crate :: GritSyntaxKind :: IDENT } ; [EOF] => { $ crate :: GritSyntaxKind :: EOF } ; [UNICODE_BOM] => { $ crate :: GritSyntaxKind :: UNICODE_BOM } ; [#] => { $ crate :: GritSyntaxKind :: HASH } ; } +macro_rules ! T { [...] => { $ crate :: GritSyntaxKind :: DOT3 } ; ["$_"] => { $ crate :: GritSyntaxKind :: DOLLAR_UNDERSCORE } ; [<:] => { $ crate :: GritSyntaxKind :: MATCH } ; [;] => { $ crate :: GritSyntaxKind :: SEMICOLON } ; [,] => { $ crate :: GritSyntaxKind :: COMMA } ; ['('] => { $ crate :: GritSyntaxKind :: L_PAREN } ; [')'] => { $ crate :: GritSyntaxKind :: R_PAREN } ; ['{'] => { $ crate :: GritSyntaxKind :: L_CURLY } ; ['}'] => { $ crate :: GritSyntaxKind :: R_CURLY } ; ['['] => { $ crate :: GritSyntaxKind :: L_BRACK } ; [']'] => { $ crate :: GritSyntaxKind :: R_BRACK } ; [<] => { $ crate :: GritSyntaxKind :: L_ANGLE } ; [>] => { $ crate :: GritSyntaxKind :: R_ANGLE } ; [+] => { $ crate :: GritSyntaxKind :: PLUS } ; [*] => { $ crate :: GritSyntaxKind :: STAR } ; [/] => { $ crate :: GritSyntaxKind :: SLASH } ; [%] => { $ crate :: GritSyntaxKind :: PERCENT } ; [.] => { $ crate :: GritSyntaxKind :: DOT } ; [:] => { $ crate :: GritSyntaxKind :: COLON } ; [=] => { $ crate :: GritSyntaxKind :: EQ } ; [==] => { $ crate :: GritSyntaxKind :: EQ2 } ; [=>] => { $ crate :: GritSyntaxKind :: FAT_ARROW } ; [!] => { $ crate :: GritSyntaxKind :: BANG } ; [!=] => { $ crate :: GritSyntaxKind :: NEQ } ; [-] => { $ crate :: GritSyntaxKind :: MINUS } ; [<=] => { $ crate :: GritSyntaxKind :: LTEQ } ; [>=] => { $ crate :: GritSyntaxKind :: GTEQ } ; [+=] => { $ crate :: GritSyntaxKind :: PLUSEQ } ; ['`'] => { $ crate :: GritSyntaxKind :: BACKTICK } ; [sequential] => { $ crate :: GritSyntaxKind :: SEQUENTIAL_KW } ; [multifile] => { $ crate :: GritSyntaxKind :: MULTIFILE_KW } ; [engine] => { $ crate :: GritSyntaxKind :: ENGINE_KW } ; [biome] => { $ crate :: GritSyntaxKind :: BIOME_KW } ; [language] => { $ crate :: GritSyntaxKind :: LANGUAGE_KW } ; [js] => { $ crate :: GritSyntaxKind :: JS_KW } ; [css] => { $ crate :: GritSyntaxKind :: CSS_KW } ; [json] => { $ crate :: GritSyntaxKind :: JSON_KW } ; [grit] => { $ crate :: GritSyntaxKind :: GRIT_KW } ; [html] => { $ crate :: GritSyntaxKind :: HTML_KW } ; [typescript] => { $ crate :: GritSyntaxKind :: TYPESCRIPT_KW } ; [jsx] => { $ crate :: GritSyntaxKind :: JSX_KW } ; [js_do_not_use] => { $ crate :: GritSyntaxKind :: JS_DO_NOT_USE_KW } ; [as] => { $ crate :: GritSyntaxKind :: AS_KW } ; [limit] => { $ crate :: GritSyntaxKind :: LIMIT_KW } ; [where] => { $ crate :: GritSyntaxKind :: WHERE_KW } ; [orelse] => { $ crate :: GritSyntaxKind :: ORELSE_KW } ; [maybe] => { $ crate :: GritSyntaxKind :: MAYBE_KW } ; [after] => { $ crate :: GritSyntaxKind :: AFTER_KW } ; [before] => { $ crate :: GritSyntaxKind :: BEFORE_KW } ; [contains] => { $ crate :: GritSyntaxKind :: CONTAINS_KW } ; [until] => { $ crate :: GritSyntaxKind :: UNTIL_KW } ; [includes] => { $ crate :: GritSyntaxKind :: INCLUDES_KW } ; [if] => { $ crate :: GritSyntaxKind :: IF_KW } ; [else] => { $ crate :: GritSyntaxKind :: ELSE_KW } ; [within] => { $ crate :: GritSyntaxKind :: WITHIN_KW } ; [bubble] => { $ crate :: GritSyntaxKind :: BUBBLE_KW } ; [not] => { $ crate :: GritSyntaxKind :: NOT_KW } ; [or] => { $ crate :: GritSyntaxKind :: OR_KW } ; [and] => { $ crate :: GritSyntaxKind :: AND_KW } ; [any] => { $ crate :: GritSyntaxKind :: ANY_KW } ; [some] => { $ crate :: GritSyntaxKind :: SOME_KW } ; [every] => { $ crate :: GritSyntaxKind :: EVERY_KW } ; [private] => { $ crate :: GritSyntaxKind :: PRIVATE_KW } ; [pattern] => { $ crate :: GritSyntaxKind :: PATTERN_KW } ; [predicate] => { $ crate :: GritSyntaxKind :: PREDICATE_KW } ; [function] => { $ crate :: GritSyntaxKind :: FUNCTION_KW } ; [true] => { $ crate :: GritSyntaxKind :: TRUE_KW } ; [false] => { $ crate :: GritSyntaxKind :: FALSE_KW } ; [undefined] => { $ crate :: GritSyntaxKind :: UNDEFINED_KW } ; [like] => { $ crate :: GritSyntaxKind :: LIKE_KW } ; [return] => { $ crate :: GritSyntaxKind :: RETURN_KW } ; [ident] => { $ crate :: GritSyntaxKind :: IDENT } ; [EOF] => { $ crate :: GritSyntaxKind :: EOF } ; [UNICODE_BOM] => { $ crate :: GritSyntaxKind :: UNICODE_BOM } ; [#] => { $ crate :: GritSyntaxKind :: HASH } ; } diff --git a/crates/biome_grit_syntax/src/generated/nodes.rs b/crates/biome_grit_syntax/src/generated/nodes.rs index 4a0b650d54c..6b55a5eb741 100644 --- a/crates/biome_grit_syntax/src/generated/nodes.rs +++ b/crates/biome_grit_syntax/src/generated/nodes.rs @@ -342,16 +342,12 @@ impl GritBooleanLiteral { } pub fn as_fields(&self) -> GritBooleanLiteralFields { GritBooleanLiteralFields { - true_token: self.true_token(), - false_token: self.false_token(), + value: self.value(), } } - pub fn true_token(&self) -> SyntaxResult { + pub fn value(&self) -> SyntaxResult { support::required_token(&self.syntax, 0usize) } - pub fn false_token(&self) -> SyntaxResult { - support::required_token(&self.syntax, 1usize) - } } #[cfg(feature = "serde")] impl Serialize for GritBooleanLiteral { @@ -364,8 +360,7 @@ impl Serialize for GritBooleanLiteral { } #[cfg_attr(feature = "serde", derive(Serialize))] pub struct GritBooleanLiteralFields { - pub true_token: SyntaxResult, - pub false_token: SyntaxResult, + pub value: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] pub struct GritBubble { @@ -639,11 +634,11 @@ impl GritDotdotdot { } pub fn as_fields(&self) -> GritDotdotdotFields { GritDotdotdotFields { - dollar_dotdotdot_token: self.dollar_dotdotdot_token(), + dotdotdot_token: self.dotdotdot_token(), maybe_curly_grit_pattern: self.maybe_curly_grit_pattern(), } } - pub fn dollar_dotdotdot_token(&self) -> SyntaxResult { + pub fn dotdotdot_token(&self) -> SyntaxResult { support::required_token(&self.syntax, 0usize) } pub fn maybe_curly_grit_pattern(&self) -> Option { @@ -661,7 +656,7 @@ impl Serialize for GritDotdotdot { } #[cfg_attr(feature = "serde", derive(Serialize))] pub struct GritDotdotdotFields { - pub dollar_dotdotdot_token: SyntaxResult, + pub dotdotdot_token: SyntaxResult, pub maybe_curly_grit_pattern: Option, } #[derive(Clone, PartialEq, Eq, Hash)] @@ -1738,16 +1733,12 @@ impl GritNot { } pub fn as_fields(&self) -> GritNotFields { GritNotFields { - not_token: self.not_token(), - excl_token: self.excl_token(), + token: self.token(), } } - pub fn not_token(&self) -> SyntaxResult { + pub fn token(&self) -> SyntaxResult { support::required_token(&self.syntax, 0usize) } - pub fn excl_token(&self) -> SyntaxResult { - support::required_token(&self.syntax, 1usize) - } } #[cfg(feature = "serde")] impl Serialize for GritNot { @@ -1760,8 +1751,7 @@ impl Serialize for GritNot { } #[cfg_attr(feature = "serde", derive(Serialize))] pub struct GritNotFields { - pub not_token: SyntaxResult, - pub excl_token: SyntaxResult, + pub token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] pub struct GritPatternAccumulate { @@ -5482,11 +5472,7 @@ impl AstNode for GritBooleanLiteral { impl std::fmt::Debug for GritBooleanLiteral { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("GritBooleanLiteral") - .field("true_token", &support::DebugSyntaxResult(self.true_token())) - .field( - "false_token", - &support::DebugSyntaxResult(self.false_token()), - ) + .field("value", &support::DebugSyntaxResult(self.value())) .finish() } } @@ -5782,8 +5768,8 @@ impl std::fmt::Debug for GritDotdotdot { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("GritDotdotdot") .field( - "dollar_dotdotdot_token", - &support::DebugSyntaxResult(self.dollar_dotdotdot_token()), + "dotdotdot_token", + &support::DebugSyntaxResult(self.dotdotdot_token()), ) .field( "maybe_curly_grit_pattern", @@ -6863,8 +6849,7 @@ impl AstNode for GritNot { impl std::fmt::Debug for GritNot { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("GritNot") - .field("not_token", &support::DebugSyntaxResult(self.not_token())) - .field("excl_token", &support::DebugSyntaxResult(self.excl_token())) + .field("token", &support::DebugSyntaxResult(self.token())) .finish() } } diff --git a/crates/biome_grit_syntax/src/generated/nodes_mut.rs b/crates/biome_grit_syntax/src/generated/nodes_mut.rs index 471cd33c6ba..a5de42bfd5c 100644 --- a/crates/biome_grit_syntax/src/generated/nodes_mut.rs +++ b/crates/biome_grit_syntax/src/generated/nodes_mut.rs @@ -120,18 +120,12 @@ impl GritBacktickSnippetLiteral { } } impl GritBooleanLiteral { - pub fn with_true_token(self, element: SyntaxToken) -> Self { + pub fn with_value_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax .splice_slots(0usize..=0usize, once(Some(element.into()))), ) } - pub fn with_false_token(self, element: SyntaxToken) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(1usize..=1usize, once(Some(element.into()))), - ) - } } impl GritBubble { pub fn with_bubble_token(self, element: SyntaxToken) -> Self { @@ -230,7 +224,7 @@ impl GritDot { } } impl GritDotdotdot { - pub fn with_dollar_dotdotdot_token(self, element: SyntaxToken) -> Self { + pub fn with_dotdotdot_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax .splice_slots(0usize..=0usize, once(Some(element.into()))), @@ -704,18 +698,12 @@ impl GritNodeLike { } } impl GritNot { - pub fn with_not_token(self, element: SyntaxToken) -> Self { + pub fn with_token_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax .splice_slots(0usize..=0usize, once(Some(element.into()))), ) } - pub fn with_excl_token(self, element: SyntaxToken) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(1usize..=1usize, once(Some(element.into()))), - ) - } } impl GritPatternAccumulate { pub fn with_left(self, element: AnyGritPattern) -> Self { diff --git a/xtask/codegen/gritql.ungram b/xtask/codegen/gritql.ungram index 49885f0bc06..804a507518f 100644 --- a/xtask/codegen/gritql.ungram +++ b/xtask/codegen/gritql.ungram @@ -315,7 +315,7 @@ GritSome = 'some' pattern: MaybeCurlyGritPattern GritEvery = 'every' pattern: MaybeCurlyGritPattern GritDotdotdot = - dollar_dotdotdot: '$...' + dotdotdot: '...' MaybeCurlyGritPattern? GritUnderscore = @@ -506,7 +506,8 @@ GritPredicateReturn = // --- tokens and lexical definitions -GritBooleanLiteral = 'true' | 'false' +GritBooleanLiteral = + value: ('true' | 'false') GritVariable = 'grit_variable' GritVariableList = GritVariable (',' GritVariable)* ','? @@ -537,7 +538,8 @@ GritCodeSnippetSource = | GritLanguageSpecificSnippet | GritRawBacktickSnippetLiteral -GritNot = 'not' | '!' +GritNot = + token: ('not' | '!') GritUndefinedLiteral = 'undefined' diff --git a/xtask/codegen/src/grit_kinds_src.rs b/xtask/codegen/src/grit_kinds_src.rs index 00f1edb3377..035202290c1 100644 --- a/xtask/codegen/src/grit_kinds_src.rs +++ b/xtask/codegen/src/grit_kinds_src.rs @@ -5,7 +5,7 @@ use crate::kind_src::KindsSrc; pub const GRIT_KINDS_SRC: KindsSrc = KindsSrc { punct: &[ - ("$...", "DOLLAR_DOT3"), + ("...", "DOT3"), ("$_", "DOLLAR_UNDERSCORE"), ("<:", "MATCH"), (";", "SEMICOLON"), From c948070a6325a4edbd63a53c39b505a49b427d56 Mon Sep 17 00:00:00 2001 From: "Arend van Beelen jr." Date: Thu, 29 Feb 2024 21:46:35 +0100 Subject: [PATCH 12/12] Definitions + more test cases --- .../src/parser/definitions.rs | 121 ++++ crates/biome_grit_parser/src/parser/mod.rs | 58 +- .../biome_grit_parser/src/parser/patterns.rs | 23 +- .../src/parser/predicates.rs | 37 +- .../tests/grit_test_suite/ok/as_modifier.grit | 4 + .../grit_test_suite/ok/as_modifier.grit.snap | 139 ++++ .../grit_test_suite/ok/bubble_clause.grit | 3 + .../ok/bubble_clause.grit.snap | 111 +++ .../ok/bubble_clause_arguments.grit | 3 + .../ok/bubble_clause_arguments.grit.snap | 124 ++++ .../grit_test_suite/ok/contains_operator.grit | 3 + .../ok/contains_operator.grit.snap | 89 +++ .../grit_test_suite/ok/every_clause.grit | 3 + .../grit_test_suite/ok/every_clause.grit.snap | 124 ++++ .../ok/function_definition.grit | 25 + .../ok/function_definition.grit.snap | 645 ++++++++++++++++++ .../grit_test_suite/ok/or_condition.grit | 6 + .../grit_test_suite/ok/or_condition.grit.snap | 131 ++++ .../ok/pattern_definition.grit | 4 + .../ok/pattern_definition.grit.snap | 134 ++++ .../ok/predicate_definition.grit | 6 + .../ok/predicate_definition.grit.snap | 148 ++++ .../grit_test_suite/ok/private_pattern.grit | 3 + .../ok/private_pattern.grit.snap | 78 +++ .../grit_test_suite/ok/until_modifier.grit | 3 + .../ok/until_modifier.grit.snap | 100 +++ .../grit_test_suite/ok/within_clause.grit | 3 + .../ok/within_clause.grit.snap | 87 +++ xtask/codegen/gritql.ungram | 5 - 29 files changed, 2152 insertions(+), 68 deletions(-) create mode 100644 crates/biome_grit_parser/src/parser/definitions.rs create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/as_modifier.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/as_modifier.grit.snap create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/bubble_clause.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/bubble_clause.grit.snap create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/bubble_clause_arguments.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/bubble_clause_arguments.grit.snap create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/contains_operator.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/contains_operator.grit.snap create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/every_clause.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/every_clause.grit.snap create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/function_definition.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/function_definition.grit.snap create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/or_condition.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/or_condition.grit.snap create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/pattern_definition.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/pattern_definition.grit.snap create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/predicate_definition.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/predicate_definition.grit.snap create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/private_pattern.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/private_pattern.grit.snap create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/until_modifier.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/until_modifier.grit.snap create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/within_clause.grit create mode 100644 crates/biome_grit_parser/tests/grit_test_suite/ok/within_clause.grit.snap diff --git a/crates/biome_grit_parser/src/parser/definitions.rs b/crates/biome_grit_parser/src/parser/definitions.rs new file mode 100644 index 00000000000..298c491a485 --- /dev/null +++ b/crates/biome_grit_parser/src/parser/definitions.rs @@ -0,0 +1,121 @@ +use super::patterns::parse_pattern_list; +use super::predicates::parse_predicate_list; +use super::{parse_language_declaration, parse_name, parse_variable_list, GritParser}; +use biome_grit_syntax::{GritSyntaxKind::*, T}; +use biome_parser::prelude::ParsedSyntax::*; +use biome_parser::{parsed_syntax::ParsedSyntax, Parser}; + +pub(crate) fn parse_definition_list(p: &mut GritParser) -> ParsedSyntax { + let m = p.start(); + + if parse_definition(p) != Absent { + loop { + if !p.has_preceding_line_break() || parse_definition(p) == Absent { + break; + } + } + } + + Present(m.complete(p, GRIT_DEFINITION_LIST)) +} + +#[inline] +fn parse_definition(p: &mut GritParser) -> ParsedSyntax { + match p.cur() { + FUNCTION_KW => parse_function_definition(p), + PATTERN_KW | PRIVATE_KW => parse_pattern_definition(p), + PREDICATE_KW => parse_predicate_definition(p), + _ => Absent, + } +} + +#[inline] +fn parse_function_definition(p: &mut GritParser) -> ParsedSyntax { + if !p.at(FUNCTION_KW) { + return Absent; + } + + let m = p.start(); + + p.bump(FUNCTION_KW); + let _ = parse_name(p); + p.eat(T!['(']); + let _ = parse_variable_list(p); + p.eat(T![')']); + let _ = parse_curly_predicate_list(p); + + Present(m.complete(p, GRIT_FUNCTION_DEFINITION)) +} + +#[inline] +fn parse_curly_predicate_list(p: &mut GritParser) -> ParsedSyntax { + if !p.at(T!['{']) { + return Absent; + } + + let m = p.start(); + + p.bump(T!['{']); + let _ = parse_predicate_list(p); + p.eat(T!['}']); + + Present(m.complete(p, GRIT_CURLY_PREDICATE_LIST)) +} + +#[inline] +fn parse_pattern_definition(p: &mut GritParser) -> ParsedSyntax { + if !p.at(PATTERN_KW) && (!p.at(PRIVATE_KW) || p.lookahead() != PATTERN_KW) { + return Absent; + } + + let m = p.start(); + + p.eat(PRIVATE_KW); + p.bump(PATTERN_KW); + let _ = parse_name(p); + p.eat(T!['(']); + let _ = parse_pattern_arg_list(p); + p.eat(T![')']); + let _ = parse_language_declaration(p); + let _ = parse_pattern_definition_body(p); + + Present(m.complete(p, GRIT_PATTERN_DEFINITION)) +} + +#[inline] +fn parse_pattern_arg_list(p: &mut GritParser) -> ParsedSyntax { + parse_variable_list(p).map(|syntax| syntax.precede(p).complete(p, GRIT_PATTERN_ARG_LIST)) +} + +#[inline] +fn parse_pattern_definition_body(p: &mut GritParser) -> ParsedSyntax { + if !p.at(T!['{']) { + return Absent; + } + + let m = p.start(); + + p.bump(T!['{']); + let _ = parse_pattern_list(p); + p.eat(T!['}']); + + Present(m.complete(p, GRIT_PATTERN_DEFINITION_BODY)) +} + +#[inline] +fn parse_predicate_definition(p: &mut GritParser) -> ParsedSyntax { + if !p.at(PREDICATE_KW) { + return Absent; + } + + let m = p.start(); + + p.bump(PREDICATE_KW); + let _ = parse_name(p); + p.eat(T!['(']); + let _ = parse_pattern_arg_list(p); + p.eat(T![')']); + let _ = parse_curly_predicate_list(p); + + Present(m.complete(p, GRIT_PREDICATE_DEFINITION)) +} diff --git a/crates/biome_grit_parser/src/parser/mod.rs b/crates/biome_grit_parser/src/parser/mod.rs index db17566a007..e64908548aa 100644 --- a/crates/biome_grit_parser/src/parser/mod.rs +++ b/crates/biome_grit_parser/src/parser/mod.rs @@ -1,4 +1,5 @@ mod constants; +mod definitions; mod literals; mod parse_error; mod patterns; @@ -15,6 +16,7 @@ use biome_parser::token_source::Trivia; use biome_parser::ParserContext; use biome_rowan::TextRange; use constants::*; +use definitions::parse_definition_list; use literals::parse_double_literal; use parse_error::{expected_language_flavor, expected_language_name, expected_pattern}; use patterns::parse_pattern; @@ -78,20 +80,20 @@ pub(crate) fn parse_root(p: &mut GritParser) -> CompletedMarker { p.eat(UNICODE_BOM); - parse_version(p); - parse_language(p); - parse_definition_list(p); + let _ = parse_version(p); + let _ = parse_language_declaration(p); + let _ = parse_definition_list(p); let _ = parse_pattern(p); - parse_definition_list(p); + let _ = parse_definition_list(p); p.eat(EOF); m.complete(p, GRIT_ROOT) } -fn parse_version(p: &mut GritParser) -> Option { +fn parse_version(p: &mut GritParser) -> ParsedSyntax { if !p.at(T![engine]) { - return None; + return Absent; } let m = p.start(); @@ -117,14 +119,12 @@ fn parse_version(p: &mut GritParser) -> Option { p.error(p.err_builder("Engine must be `biome`", engine_range)); } - let result = m.complete(p, GRIT_VERSION); - - Some(result) + Present(m.complete(p, GRIT_VERSION)) } -fn parse_language(p: &mut GritParser) -> Option { +fn parse_language_declaration(p: &mut GritParser) -> ParsedSyntax { if !p.at(T![language]) { - return None; + return Absent; } let m = p.start(); @@ -141,9 +141,7 @@ fn parse_language(p: &mut GritParser) -> Option { p.eat(T![;]); - let result = m.complete(p, GRIT_LANGUAGE_DECLARATION); - - Some(result) + Present(m.complete(p, GRIT_LANGUAGE_DECLARATION)) } fn parse_language_name(p: &mut GritParser) -> ParsedSyntax { @@ -202,34 +200,19 @@ fn parse_language_flavor_kind(p: &mut GritParser) -> ParsedSyntax { Present(m.complete(p, GRIT_LANGUAGE_FLAVOR_KIND)) } -fn parse_definition_list(p: &mut GritParser) -> CompletedMarker { - let m = p.start(); - - match p.cur() { - GRIT_BOGUS => { - let m = p.start(); - p.bump(GRIT_BOGUS); - m.complete(p, GRIT_BOGUS_DEFINITION); - } - _ => {} - } - - m.complete(p, GRIT_DEFINITION_LIST) -} - #[inline] fn parse_maybe_named_arg(p: &mut GritParser) -> ParsedSyntax { - if p.at(GRIT_NAME) { - parse_named_arg(p) - } else { - parse_pattern(p) + match p.cur() { + T![')'] => Absent, + GRIT_NAME => parse_named_arg(p), + _ => parse_pattern(p) .or_recover_with_token_set( p, &ParseRecoveryTokenSet::new(GRIT_BOGUS, ARG_LIST_RECOVERY_SET), expected_pattern, ) .ok() - .into() + .into(), } } @@ -265,13 +248,10 @@ fn parse_named_arg(p: &mut GritParser) -> ParsedSyntax { fn parse_named_arg_list(p: &mut GritParser) -> ParsedSyntax { let m = p.start(); - if parse_maybe_named_arg(p) == Absent { - m.abandon(p); - return Absent; - } + let _ = parse_maybe_named_arg(p); while p.eat(T![,]) { - if p.at(T![')']) || parse_maybe_named_arg(p) == Absent { + if parse_maybe_named_arg(p) == Absent { break; } } diff --git a/crates/biome_grit_parser/src/parser/patterns.rs b/crates/biome_grit_parser/src/parser/patterns.rs index cf07f176a1e..3af530ae950 100644 --- a/crates/biome_grit_parser/src/parser/patterns.rs +++ b/crates/biome_grit_parser/src/parser/patterns.rs @@ -54,9 +54,9 @@ pub(crate) fn parse_pattern(p: &mut GritParser) -> ParsedSyntax { // precedence: 8 let left = match p.cur() { - T![*] => parse_operator(p, left, T![*]), - T![/] => parse_operator(p, left, T![/]), - T![%] => parse_operator(p, left, T![%]), + T![*] => parse_pattern_operation(p, left, T![*]), + T![/] => parse_pattern_operation(p, left, T![/]), + T![%] => parse_pattern_operation(p, left, T![%]), _ => Present(left), }; @@ -66,8 +66,8 @@ pub(crate) fn parse_pattern(p: &mut GritParser) -> ParsedSyntax { // precedence: 7 let left = match p.cur() { - T![+] => parse_operator(p, left, T![+]), - T![-] => parse_operator(p, left, T![-]), + T![+] => parse_pattern_operation(p, left, T![+]), + T![-] => parse_pattern_operation(p, left, T![-]), _ => Present(left), }; @@ -183,7 +183,7 @@ fn parse_bubble_scope(p: &mut GritParser) -> ParsedSyntax { p.eat(T![')']); - Present(m.complete(p, GRIT_BUBBLE)) + Present(m.complete(p, GRIT_BUBBLE_SCOPE)) } #[inline] @@ -413,10 +413,9 @@ fn parse_map_key(p: &mut GritParser) -> ParsedSyntax { #[inline] pub(crate) fn parse_maybe_curly_pattern(p: &mut GritParser) -> ParsedSyntax { - if p.at(T!['{']) { - parse_curly_pattern(p) - } else { - parse_pattern(p) + match p.cur() { + T!['{'] => parse_curly_pattern(p), + _ => parse_pattern(p), } } @@ -492,7 +491,7 @@ fn parse_node_like(p: &mut GritParser) -> ParsedSyntax { } #[inline] -fn parse_operator( +fn parse_pattern_operation( p: &mut GritParser, left: CompletedMarker, operator: GritSyntaxKind, @@ -769,7 +768,7 @@ fn parse_pattern_limit(p: &mut GritParser, left: CompletedMarker) -> ParsedSynta } #[inline] -fn parse_pattern_list(p: &mut GritParser) -> ParsedSyntax { +pub(crate) fn parse_pattern_list(p: &mut GritParser) -> ParsedSyntax { let m = p.start(); if parse_pattern(p) == Absent { diff --git a/crates/biome_grit_parser/src/parser/predicates.rs b/crates/biome_grit_parser/src/parser/predicates.rs index a26c8c548f2..f569973f60a 100644 --- a/crates/biome_grit_parser/src/parser/predicates.rs +++ b/crates/biome_grit_parser/src/parser/predicates.rs @@ -1,7 +1,7 @@ use super::literals::{parse_boolean_literal, parse_literal}; use super::parse_error::expected_pattern; use super::patterns::{parse_container, parse_pattern}; -use super::{constants::*, parse_named_arg_list}; +use super::{constants::*, parse_name, parse_named_arg_list}; use super::{parse_not, GritParser}; use biome_grit_syntax::GritSyntaxKind::*; use biome_grit_syntax::T; @@ -16,12 +16,6 @@ pub(crate) fn parse_predicate(p: &mut GritParser) -> ParsedSyntax { OR_KW => parse_predicate_or(p), ANY_KW => parse_predicate_any(p), IF_KW => parse_predicate_if_else(p), - // TODO: GritPredicateGreater => {} - // TODO: GritPredicateLess => {} - // TODO: GritPredicateGreaterEqual => {} - // TODO: GritPredicateLessEqual => {} - // TODO: GritPredicateNotEqual => {} - // TODO: GritPredicateEqual => {} GRIT_NAME if p.lookahead() == T!['('] => parse_predicate_call(p), T!['('] => parse_bracketed_predicate(p), T![true] | T![false] => parse_boolean_literal(p), @@ -55,7 +49,13 @@ fn parse_bracketed_predicate(p: &mut GritParser) -> ParsedSyntax { enum InfixPredicateKind { Accumulate, Assignment, + Equal, + Greater, + GreaterEqual, + Less, + LessEqual, Match, + NotEqual, Rewrite, } @@ -73,7 +73,13 @@ fn parse_infix_predicate(p: &mut GritParser) -> ParsedSyntax { let kind = match p.cur() { T![+=] => Accumulate, T![=] => Assignment, + T![==] => Equal, + T![>] => Greater, + T![>=] => GreaterEqual, + T![<] => Less, + T![<=] => LessEqual, T![<:] => Match, + T![!=] => NotEqual, T![=>] => Rewrite, _ => { m.abandon(p); @@ -83,7 +89,9 @@ fn parse_infix_predicate(p: &mut GritParser) -> ParsedSyntax { // Verify the subjects are allowed for the matched predicate kind: match kind { - Accumulate | Rewrite if subject.kind(p) != GRIT_VARIABLE => { + Accumulate | Equal | Greater | GreaterEqual | Less | LessEqual | NotEqual | Rewrite + if subject.kind(p) != GRIT_VARIABLE => + { subject.change_to_bogus(p); } Assignment if !CONTAINER_SET.contains(subject.kind(p)) => { @@ -103,7 +111,13 @@ fn parse_infix_predicate(p: &mut GritParser) -> ParsedSyntax { let kind = match kind { Accumulate => GRIT_PREDICATE_ACCUMULATE, Assignment => GRIT_PREDICATE_ASSIGNMENT, + Equal => GRIT_PREDICATE_EQUAL, + Greater => GRIT_PREDICATE_GREATER, + GreaterEqual => GRIT_PREDICATE_GREATER_EQUAL, + Less => GRIT_PREDICATE_LESS, + LessEqual => GRIT_PREDICATE_LESS_EQUAL, Match => GRIT_PREDICATE_MATCH, + NotEqual => GRIT_PREDICATE_NOT_EQUAL, Rewrite => GRIT_PREDICATE_REWRITE, }; Present(m.complete(p, kind)) @@ -164,11 +178,10 @@ fn parse_predicate_call(p: &mut GritParser) -> ParsedSyntax { } let m = p.start(); - p.bump(GRIT_NAME); - p.eat(T!['(']); + let _ = parse_name(p); + p.eat(T!['(']); let _ = parse_named_arg_list(p); - p.eat(T![')']); Present(m.complete(p, GRIT_PREDICATE_CALL)) @@ -214,7 +227,7 @@ fn parse_predicate_else_clause(p: &mut GritParser) -> ParsedSyntax { } #[inline] -fn parse_predicate_list(p: &mut GritParser) -> ParsedSyntax { +pub(crate) fn parse_predicate_list(p: &mut GritParser) -> ParsedSyntax { let m = p.start(); if parse_predicate(p) == Absent { diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/as_modifier.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/as_modifier.grit new file mode 100644 index 00000000000..6582c97bd65 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/as_modifier.grit @@ -0,0 +1,4 @@ +`function $name ($args) { $body }` as $func where { + $func => `const $name = ($args) => { $body }`, + $args <: contains `apple` => `mango` +} diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/as_modifier.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/as_modifier.grit.snap new file mode 100644 index 00000000000..a338a2412b4 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/as_modifier.grit.snap @@ -0,0 +1,139 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +`function $name ($args) { $body }` as $func where { + $func => `const $name = ($args) => { $body }`, + $args <: contains `apple` => `mango` +} + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: missing (optional), + definitions: GritDefinitionList [], + pattern: GritPatternWhere { + pattern: GritPatternAs { + pattern: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@0..35 "`function $name ($args) { $body }`" [] [Whitespace(" ")], + }, + }, + as_token: AS_KW@35..38 "as" [] [Whitespace(" ")], + variable: GritVariable { + grit_variable_token: GRIT_VARIABLE@38..44 "$func" [] [Whitespace(" ")], + }, + }, + where_token: WHERE_KW@44..50 "where" [] [Whitespace(" ")], + side_condition: GritPredicateAnd { + and_token: missing (optional), + l_curly_token: L_CURLY@50..51 "{" [] [], + predicates: GritPredicateList [ + GritPredicateRewrite { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@51..60 "$func" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + annotation: missing (optional), + fat_arrow_token: FAT_ARROW@60..63 "=>" [] [Whitespace(" ")], + right: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@63..99 "`const $name = ($args) => { $body }`" [] [], + }, + }, + grit_bogus: missing (optional), + }, + COMMA@99..100 "," [] [], + GritPredicateMatch { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@100..109 "$args" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + match_token: MATCH@109..112 "<:" [] [Whitespace(" ")], + right: GritPatternContains { + contains_token: CONTAINS_KW@112..121 "contains" [] [Whitespace(" ")], + contains: GritRewrite { + left: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@121..129 "`apple`" [] [Whitespace(" ")], + }, + }, + annotation: missing (optional), + fat_arrow_token: FAT_ARROW@129..132 "=>" [] [Whitespace(" ")], + right: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@132..139 "`mango`" [] [], + }, + }, + }, + grit_pattern_contains_until_clause: missing (optional), + }, + grit_bogus: missing (optional), + }, + ], + r_curly_token: R_CURLY@139..141 "}" [Newline("\n")] [], + }, + }, + definitions_continued: GritDefinitionList [], + eof_token: EOF@141..142 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..142 + 0: (empty) + 1: (empty) + 2: (empty) + 3: GRIT_DEFINITION_LIST@0..0 + 4: GRIT_PATTERN_WHERE@0..141 + 0: GRIT_PATTERN_AS@0..44 + 0: GRIT_CODE_SNIPPET@0..35 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@0..35 + 0: GRIT_BACKTICK_SNIPPET@0..35 "`function $name ($args) { $body }`" [] [Whitespace(" ")] + 1: AS_KW@35..38 "as" [] [Whitespace(" ")] + 2: GRIT_VARIABLE@38..44 + 0: GRIT_VARIABLE@38..44 "$func" [] [Whitespace(" ")] + 1: WHERE_KW@44..50 "where" [] [Whitespace(" ")] + 2: GRIT_PREDICATE_AND@50..141 + 0: (empty) + 1: L_CURLY@50..51 "{" [] [] + 2: GRIT_PREDICATE_LIST@51..139 + 0: GRIT_PREDICATE_REWRITE@51..99 + 0: GRIT_VARIABLE@51..60 + 0: GRIT_VARIABLE@51..60 "$func" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: (empty) + 2: FAT_ARROW@60..63 "=>" [] [Whitespace(" ")] + 3: GRIT_CODE_SNIPPET@63..99 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@63..99 + 0: GRIT_BACKTICK_SNIPPET@63..99 "`const $name = ($args) => { $body }`" [] [] + 4: (empty) + 1: COMMA@99..100 "," [] [] + 2: GRIT_PREDICATE_MATCH@100..139 + 0: GRIT_VARIABLE@100..109 + 0: GRIT_VARIABLE@100..109 "$args" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: MATCH@109..112 "<:" [] [Whitespace(" ")] + 2: GRIT_PATTERN_CONTAINS@112..139 + 0: CONTAINS_KW@112..121 "contains" [] [Whitespace(" ")] + 1: GRIT_REWRITE@121..139 + 0: GRIT_CODE_SNIPPET@121..129 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@121..129 + 0: GRIT_BACKTICK_SNIPPET@121..129 "`apple`" [] [Whitespace(" ")] + 1: (empty) + 2: FAT_ARROW@129..132 "=>" [] [Whitespace(" ")] + 3: GRIT_CODE_SNIPPET@132..139 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@132..139 + 0: GRIT_BACKTICK_SNIPPET@132..139 "`mango`" [] [] + 2: (empty) + 3: (empty) + 3: R_CURLY@139..141 "}" [Newline("\n")] [] + 5: GRIT_DEFINITION_LIST@141..141 + 6: EOF@141..142 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/bubble_clause.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/bubble_clause.grit new file mode 100644 index 00000000000..539080c0a79 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/bubble_clause.grit @@ -0,0 +1,3 @@ +`function() { $body }` where { + $body <: contains bubble `console.log($message)`=> `console.warn($message)` +} diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/bubble_clause.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/bubble_clause.grit.snap new file mode 100644 index 00000000000..ae3b2a9747e --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/bubble_clause.grit.snap @@ -0,0 +1,111 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +`function() { $body }` where { + $body <: contains bubble `console.log($message)`=> `console.warn($message)` +} + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: missing (optional), + definitions: GritDefinitionList [], + pattern: GritPatternWhere { + pattern: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@0..23 "`function() { $body }`" [] [Whitespace(" ")], + }, + }, + where_token: WHERE_KW@23..29 "where" [] [Whitespace(" ")], + side_condition: GritPredicateAnd { + and_token: missing (optional), + l_curly_token: L_CURLY@29..30 "{" [] [], + predicates: GritPredicateList [ + GritPredicateMatch { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@30..39 "$body" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + match_token: MATCH@39..42 "<:" [] [Whitespace(" ")], + right: GritPatternContains { + contains_token: CONTAINS_KW@42..51 "contains" [] [Whitespace(" ")], + contains: GritBubble { + bubble_token: BUBBLE_KW@51..58 "bubble" [] [Whitespace(" ")], + variables: missing (optional), + pattern: GritRewrite { + left: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@58..81 "`console.log($message)`" [] [], + }, + }, + annotation: missing (optional), + fat_arrow_token: FAT_ARROW@81..84 "=>" [] [Whitespace(" ")], + right: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@84..108 "`console.warn($message)`" [] [], + }, + }, + }, + }, + grit_pattern_contains_until_clause: missing (optional), + }, + grit_bogus: missing (optional), + }, + ], + r_curly_token: R_CURLY@108..110 "}" [Newline("\n")] [], + }, + }, + definitions_continued: GritDefinitionList [], + eof_token: EOF@110..111 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..111 + 0: (empty) + 1: (empty) + 2: (empty) + 3: GRIT_DEFINITION_LIST@0..0 + 4: GRIT_PATTERN_WHERE@0..110 + 0: GRIT_CODE_SNIPPET@0..23 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@0..23 + 0: GRIT_BACKTICK_SNIPPET@0..23 "`function() { $body }`" [] [Whitespace(" ")] + 1: WHERE_KW@23..29 "where" [] [Whitespace(" ")] + 2: GRIT_PREDICATE_AND@29..110 + 0: (empty) + 1: L_CURLY@29..30 "{" [] [] + 2: GRIT_PREDICATE_LIST@30..108 + 0: GRIT_PREDICATE_MATCH@30..108 + 0: GRIT_VARIABLE@30..39 + 0: GRIT_VARIABLE@30..39 "$body" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: MATCH@39..42 "<:" [] [Whitespace(" ")] + 2: GRIT_PATTERN_CONTAINS@42..108 + 0: CONTAINS_KW@42..51 "contains" [] [Whitespace(" ")] + 1: GRIT_BUBBLE@51..108 + 0: BUBBLE_KW@51..58 "bubble" [] [Whitespace(" ")] + 1: (empty) + 2: GRIT_REWRITE@58..108 + 0: GRIT_CODE_SNIPPET@58..81 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@58..81 + 0: GRIT_BACKTICK_SNIPPET@58..81 "`console.log($message)`" [] [] + 1: (empty) + 2: FAT_ARROW@81..84 "=>" [] [Whitespace(" ")] + 3: GRIT_CODE_SNIPPET@84..108 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@84..108 + 0: GRIT_BACKTICK_SNIPPET@84..108 "`console.warn($message)`" [] [] + 2: (empty) + 3: (empty) + 3: R_CURLY@108..110 "}" [Newline("\n")] [] + 5: GRIT_DEFINITION_LIST@110..110 + 6: EOF@110..111 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/bubble_clause_arguments.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/bubble_clause_arguments.grit new file mode 100644 index 00000000000..ebd398caa88 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/bubble_clause_arguments.grit @@ -0,0 +1,3 @@ +`function $name() { $body }` where { + $body <: contains bubble($name) `console.log($message)` => `console.warn($message, $name)` +} diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/bubble_clause_arguments.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/bubble_clause_arguments.grit.snap new file mode 100644 index 00000000000..3ce427635e5 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/bubble_clause_arguments.grit.snap @@ -0,0 +1,124 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +`function $name() { $body }` where { + $body <: contains bubble($name) `console.log($message)` => `console.warn($message, $name)` +} + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: missing (optional), + definitions: GritDefinitionList [], + pattern: GritPatternWhere { + pattern: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@0..29 "`function $name() { $body }`" [] [Whitespace(" ")], + }, + }, + where_token: WHERE_KW@29..35 "where" [] [Whitespace(" ")], + side_condition: GritPredicateAnd { + and_token: missing (optional), + l_curly_token: L_CURLY@35..36 "{" [] [], + predicates: GritPredicateList [ + GritPredicateMatch { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@36..45 "$body" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + match_token: MATCH@45..48 "<:" [] [Whitespace(" ")], + right: GritPatternContains { + contains_token: CONTAINS_KW@48..57 "contains" [] [Whitespace(" ")], + contains: GritBubble { + bubble_token: BUBBLE_KW@57..63 "bubble" [] [], + variables: GritBubbleScope { + l_paren_token: L_PAREN@63..64 "(" [] [], + grit_variable_list: GritVariableList [ + GritVariable { + grit_variable_token: GRIT_VARIABLE@64..69 "$name" [] [], + }, + ], + r_paren_token: R_PAREN@69..71 ")" [] [Whitespace(" ")], + }, + pattern: GritRewrite { + left: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@71..95 "`console.log($message)`" [] [Whitespace(" ")], + }, + }, + annotation: missing (optional), + fat_arrow_token: FAT_ARROW@95..98 "=>" [] [Whitespace(" ")], + right: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@98..129 "`console.warn($message, $name)`" [] [], + }, + }, + }, + }, + grit_pattern_contains_until_clause: missing (optional), + }, + grit_bogus: missing (optional), + }, + ], + r_curly_token: R_CURLY@129..131 "}" [Newline("\n")] [], + }, + }, + definitions_continued: GritDefinitionList [], + eof_token: EOF@131..132 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..132 + 0: (empty) + 1: (empty) + 2: (empty) + 3: GRIT_DEFINITION_LIST@0..0 + 4: GRIT_PATTERN_WHERE@0..131 + 0: GRIT_CODE_SNIPPET@0..29 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@0..29 + 0: GRIT_BACKTICK_SNIPPET@0..29 "`function $name() { $body }`" [] [Whitespace(" ")] + 1: WHERE_KW@29..35 "where" [] [Whitespace(" ")] + 2: GRIT_PREDICATE_AND@35..131 + 0: (empty) + 1: L_CURLY@35..36 "{" [] [] + 2: GRIT_PREDICATE_LIST@36..129 + 0: GRIT_PREDICATE_MATCH@36..129 + 0: GRIT_VARIABLE@36..45 + 0: GRIT_VARIABLE@36..45 "$body" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: MATCH@45..48 "<:" [] [Whitespace(" ")] + 2: GRIT_PATTERN_CONTAINS@48..129 + 0: CONTAINS_KW@48..57 "contains" [] [Whitespace(" ")] + 1: GRIT_BUBBLE@57..129 + 0: BUBBLE_KW@57..63 "bubble" [] [] + 1: GRIT_BUBBLE_SCOPE@63..71 + 0: L_PAREN@63..64 "(" [] [] + 1: GRIT_VARIABLE_LIST@64..69 + 0: GRIT_VARIABLE@64..69 + 0: GRIT_VARIABLE@64..69 "$name" [] [] + 2: R_PAREN@69..71 ")" [] [Whitespace(" ")] + 2: GRIT_REWRITE@71..129 + 0: GRIT_CODE_SNIPPET@71..95 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@71..95 + 0: GRIT_BACKTICK_SNIPPET@71..95 "`console.log($message)`" [] [Whitespace(" ")] + 1: (empty) + 2: FAT_ARROW@95..98 "=>" [] [Whitespace(" ")] + 3: GRIT_CODE_SNIPPET@98..129 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@98..129 + 0: GRIT_BACKTICK_SNIPPET@98..129 "`console.warn($message, $name)`" [] [] + 2: (empty) + 3: (empty) + 3: R_CURLY@129..131 "}" [Newline("\n")] [] + 5: GRIT_DEFINITION_LIST@131..131 + 6: EOF@131..132 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/contains_operator.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/contains_operator.grit new file mode 100644 index 00000000000..d744d789c8e --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/contains_operator.grit @@ -0,0 +1,3 @@ +`function ($_) { $body }` where { + $body <: contains `console.log` +} diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/contains_operator.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/contains_operator.grit.snap new file mode 100644 index 00000000000..0fb52de2f70 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/contains_operator.grit.snap @@ -0,0 +1,89 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +`function ($_) { $body }` where { + $body <: contains `console.log` +} + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: missing (optional), + definitions: GritDefinitionList [], + pattern: GritPatternWhere { + pattern: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@0..26 "`function ($_) { $body }`" [] [Whitespace(" ")], + }, + }, + where_token: WHERE_KW@26..32 "where" [] [Whitespace(" ")], + side_condition: GritPredicateAnd { + and_token: missing (optional), + l_curly_token: L_CURLY@32..33 "{" [] [], + predicates: GritPredicateList [ + GritPredicateMatch { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@33..42 "$body" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + match_token: MATCH@42..45 "<:" [] [Whitespace(" ")], + right: GritPatternContains { + contains_token: CONTAINS_KW@45..54 "contains" [] [Whitespace(" ")], + contains: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@54..67 "`console.log`" [] [], + }, + }, + grit_pattern_contains_until_clause: missing (optional), + }, + grit_bogus: missing (optional), + }, + ], + r_curly_token: R_CURLY@67..69 "}" [Newline("\n")] [], + }, + }, + definitions_continued: GritDefinitionList [], + eof_token: EOF@69..70 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..70 + 0: (empty) + 1: (empty) + 2: (empty) + 3: GRIT_DEFINITION_LIST@0..0 + 4: GRIT_PATTERN_WHERE@0..69 + 0: GRIT_CODE_SNIPPET@0..26 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@0..26 + 0: GRIT_BACKTICK_SNIPPET@0..26 "`function ($_) { $body }`" [] [Whitespace(" ")] + 1: WHERE_KW@26..32 "where" [] [Whitespace(" ")] + 2: GRIT_PREDICATE_AND@32..69 + 0: (empty) + 1: L_CURLY@32..33 "{" [] [] + 2: GRIT_PREDICATE_LIST@33..67 + 0: GRIT_PREDICATE_MATCH@33..67 + 0: GRIT_VARIABLE@33..42 + 0: GRIT_VARIABLE@33..42 "$body" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: MATCH@42..45 "<:" [] [Whitespace(" ")] + 2: GRIT_PATTERN_CONTAINS@45..67 + 0: CONTAINS_KW@45..54 "contains" [] [Whitespace(" ")] + 1: GRIT_CODE_SNIPPET@54..67 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@54..67 + 0: GRIT_BACKTICK_SNIPPET@54..67 "`console.log`" [] [] + 2: (empty) + 3: (empty) + 3: R_CURLY@67..69 "}" [Newline("\n")] [] + 5: GRIT_DEFINITION_LIST@69..69 + 6: EOF@69..70 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/every_clause.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/every_clause.grit new file mode 100644 index 00000000000..8e83e3b09bc --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/every_clause.grit @@ -0,0 +1,3 @@ +`var $x = [$names]` => `var coolPeople = [$names]` where { + $names <: every or {`"andrew"`, `"alex"`} +} diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/every_clause.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/every_clause.grit.snap new file mode 100644 index 00000000000..25f44785d40 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/every_clause.grit.snap @@ -0,0 +1,124 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +`var $x = [$names]` => `var coolPeople = [$names]` where { + $names <: every or {`"andrew"`, `"alex"`} +} + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: missing (optional), + definitions: GritDefinitionList [], + pattern: GritRewrite { + left: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@0..20 "`var $x = [$names]`" [] [Whitespace(" ")], + }, + }, + annotation: missing (optional), + fat_arrow_token: FAT_ARROW@20..23 "=>" [] [Whitespace(" ")], + right: GritPatternWhere { + pattern: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@23..51 "`var coolPeople = [$names]`" [] [Whitespace(" ")], + }, + }, + where_token: WHERE_KW@51..57 "where" [] [Whitespace(" ")], + side_condition: GritPredicateAnd { + and_token: missing (optional), + l_curly_token: L_CURLY@57..58 "{" [] [], + predicates: GritPredicateList [ + GritPredicateMatch { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@58..68 "$names" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + match_token: MATCH@68..71 "<:" [] [Whitespace(" ")], + right: GritEvery { + every_token: EVERY_KW@71..77 "every" [] [Whitespace(" ")], + pattern: GritPatternOr { + or_token: OR_KW@77..80 "or" [] [Whitespace(" ")], + l_curly_token: L_CURLY@80..81 "{" [] [], + patterns: GritPatternList [ + GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@81..91 "`\"andrew\"`" [] [], + }, + }, + COMMA@91..93 "," [] [Whitespace(" ")], + GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@93..101 "`\"alex\"`" [] [], + }, + }, + ], + r_curly_token: R_CURLY@101..102 "}" [] [], + }, + }, + grit_bogus: missing (optional), + }, + ], + r_curly_token: R_CURLY@102..104 "}" [Newline("\n")] [], + }, + }, + }, + definitions_continued: GritDefinitionList [], + eof_token: EOF@104..105 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..105 + 0: (empty) + 1: (empty) + 2: (empty) + 3: GRIT_DEFINITION_LIST@0..0 + 4: GRIT_REWRITE@0..104 + 0: GRIT_CODE_SNIPPET@0..20 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@0..20 + 0: GRIT_BACKTICK_SNIPPET@0..20 "`var $x = [$names]`" [] [Whitespace(" ")] + 1: (empty) + 2: FAT_ARROW@20..23 "=>" [] [Whitespace(" ")] + 3: GRIT_PATTERN_WHERE@23..104 + 0: GRIT_CODE_SNIPPET@23..51 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@23..51 + 0: GRIT_BACKTICK_SNIPPET@23..51 "`var coolPeople = [$names]`" [] [Whitespace(" ")] + 1: WHERE_KW@51..57 "where" [] [Whitespace(" ")] + 2: GRIT_PREDICATE_AND@57..104 + 0: (empty) + 1: L_CURLY@57..58 "{" [] [] + 2: GRIT_PREDICATE_LIST@58..102 + 0: GRIT_PREDICATE_MATCH@58..102 + 0: GRIT_VARIABLE@58..68 + 0: GRIT_VARIABLE@58..68 "$names" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: MATCH@68..71 "<:" [] [Whitespace(" ")] + 2: GRIT_EVERY@71..102 + 0: EVERY_KW@71..77 "every" [] [Whitespace(" ")] + 1: GRIT_PATTERN_OR@77..102 + 0: OR_KW@77..80 "or" [] [Whitespace(" ")] + 1: L_CURLY@80..81 "{" [] [] + 2: GRIT_PATTERN_LIST@81..101 + 0: GRIT_CODE_SNIPPET@81..91 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@81..91 + 0: GRIT_BACKTICK_SNIPPET@81..91 "`\"andrew\"`" [] [] + 1: COMMA@91..93 "," [] [Whitespace(" ")] + 2: GRIT_CODE_SNIPPET@93..101 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@93..101 + 0: GRIT_BACKTICK_SNIPPET@93..101 "`\"alex\"`" [] [] + 3: R_CURLY@101..102 "}" [] [] + 3: (empty) + 3: R_CURLY@102..104 "}" [Newline("\n")] [] + 5: GRIT_DEFINITION_LIST@104..104 + 6: EOF@104..105 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/function_definition.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/function_definition.grit new file mode 100644 index 00000000000..744a7956ca0 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/function_definition.grit @@ -0,0 +1,25 @@ +// define a lines function +function lines($string) { + return split($string, separator=`\n`) +} + +// Define a my_todo function +function my_todo($target, $message) { + if($message <: undefined) { + $message = "This requires manual intervention." + }, + $lines = lines(string = $message), + $lines <: some bubble($result) $x where { + if ($result <: undefined) { + $result = `// TODO: $x` + } else { + $result += `\n// $x` + } + }, + $target_lines = lines(string = $target), + $target_lines <: some bubble($result) $x where { $result += `\n// $x` }, + return $result, +} + +// Use the my_todo function +`module.exports = $_` as $x => my_todo(target=$x, message=`Fix this\nAnd that`) diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/function_definition.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/function_definition.grit.snap new file mode 100644 index 00000000000..692d8e0c5bf --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/function_definition.grit.snap @@ -0,0 +1,645 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +// define a lines function +function lines($string) { + return split($string, separator=`\n`) +} + +// Define a my_todo function +function my_todo($target, $message) { + if($message <: undefined) { + $message = "This requires manual intervention." + }, + $lines = lines(string = $message), + $lines <: some bubble($result) $x where { + if ($result <: undefined) { + $result = `// TODO: $x` + } else { + $result += `\n// $x` + } + }, + $target_lines = lines(string = $target), + $target_lines <: some bubble($result) $x where { $result += `\n// $x` }, + return $result, +} + +// Use the my_todo function +`module.exports = $_` as $x => my_todo(target=$x, message=`Fix this\nAnd that`) + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: missing (optional), + definitions: GritDefinitionList [ + GritFunctionDefinition { + function_token: FUNCTION_KW@0..36 "function" [Comments("// define a lines fun ..."), Newline("\n")] [Whitespace(" ")], + name: GritName { + grit_name_token: GRIT_NAME@36..41 "lines" [] [], + }, + l_paren_token: L_PAREN@41..42 "(" [] [], + args: GritVariableList [ + GritVariable { + grit_variable_token: GRIT_VARIABLE@42..49 "$string" [] [], + }, + ], + r_paren_token: R_PAREN@49..51 ")" [] [Whitespace(" ")], + body: GritCurlyPredicateList { + l_curly_token: L_CURLY@51..52 "{" [] [], + predicates: GritPredicateList [ + GritPredicateReturn { + return_token: RETURN_KW@52..64 "return" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + pattern: GritNodeLike { + name: GritName { + grit_name_token: GRIT_NAME@64..69 "split" [] [], + }, + l_paren_token: L_PAREN@69..70 "(" [] [], + named_args: GritNamedArgList [ + GritVariable { + grit_variable_token: GRIT_VARIABLE@70..77 "$string" [] [], + }, + COMMA@77..79 "," [] [Whitespace(" ")], + GritNamedArg { + name: GritName { + grit_name_token: GRIT_NAME@79..88 "separator" [] [], + }, + eq_token: EQ@88..89 "=" [] [], + pattern: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@89..93 "`\\n`" [] [], + }, + }, + }, + ], + r_paren_token: R_PAREN@93..94 ")" [] [], + }, + }, + ], + r_curly_token: R_CURLY@94..96 "}" [Newline("\n")] [], + }, + }, + missing separator, + GritFunctionDefinition { + function_token: FUNCTION_KW@96..136 "function" [Newline("\n"), Newline("\n"), Comments("// Define a my_todo f ..."), Newline("\n")] [Whitespace(" ")], + name: GritName { + grit_name_token: GRIT_NAME@136..143 "my_todo" [] [], + }, + l_paren_token: L_PAREN@143..144 "(" [] [], + args: GritVariableList [ + GritVariable { + grit_variable_token: GRIT_VARIABLE@144..151 "$target" [] [], + }, + COMMA@151..153 "," [] [Whitespace(" ")], + GritVariable { + grit_variable_token: GRIT_VARIABLE@153..161 "$message" [] [], + }, + ], + r_paren_token: R_PAREN@161..163 ")" [] [Whitespace(" ")], + body: GritCurlyPredicateList { + l_curly_token: L_CURLY@163..164 "{" [] [], + predicates: GritPredicateList [ + GritPredicateIfElse { + if_token: IF_KW@164..170 "if" [Newline("\n"), Whitespace(" ")] [], + l_paren_token: L_PAREN@170..171 "(" [] [], + if_predicate: GritPredicateMatch { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@171..180 "$message" [] [Whitespace(" ")], + }, + match_token: MATCH@180..183 "<:" [] [Whitespace(" ")], + right: GritUndefinedLiteral { + undefined_token: UNDEFINED_KW@183..192 "undefined" [] [], + }, + grit_bogus: missing (optional), + }, + r_paren_token: R_PAREN@192..194 ")" [] [Whitespace(" ")], + then_predicate: GritPredicateAnd { + and_token: missing (optional), + l_curly_token: L_CURLY@194..195 "{" [] [], + predicates: GritPredicateList [ + GritPredicateAssignment { + container: GritVariable { + grit_variable_token: GRIT_VARIABLE@195..212 "$message" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + eq_token: EQ@212..214 "=" [] [Whitespace(" ")], + pattern: GritStringLiteral { + value_token: GRIT_STRING@214..250 "\"This requires manual intervention.\"" [] [], + }, + grit_bogus: missing (optional), + }, + ], + r_curly_token: R_CURLY@250..255 "}" [Newline("\n"), Whitespace(" ")] [], + }, + grit_predicate_else_clause: missing (optional), + }, + COMMA@255..256 "," [] [], + GritPredicateAssignment { + container: GritVariable { + grit_variable_token: GRIT_VARIABLE@256..267 "$lines" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + eq_token: EQ@267..269 "=" [] [Whitespace(" ")], + pattern: GritNodeLike { + name: GritName { + grit_name_token: GRIT_NAME@269..274 "lines" [] [], + }, + l_paren_token: L_PAREN@274..275 "(" [] [], + named_args: GritNamedArgList [ + GritNamedArg { + name: GritName { + grit_name_token: GRIT_NAME@275..282 "string" [] [Whitespace(" ")], + }, + eq_token: EQ@282..284 "=" [] [Whitespace(" ")], + pattern: GritVariable { + grit_variable_token: GRIT_VARIABLE@284..292 "$message" [] [], + }, + }, + ], + r_paren_token: R_PAREN@292..293 ")" [] [], + }, + grit_bogus: missing (optional), + }, + COMMA@293..294 "," [] [], + GritPredicateMatch { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@294..305 "$lines" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + match_token: MATCH@305..308 "<:" [] [Whitespace(" ")], + right: GritSome { + some_token: SOME_KW@308..313 "some" [] [Whitespace(" ")], + pattern: GritBubble { + bubble_token: BUBBLE_KW@313..319 "bubble" [] [], + variables: GritBubbleScope { + l_paren_token: L_PAREN@319..320 "(" [] [], + grit_variable_list: GritVariableList [ + GritVariable { + grit_variable_token: GRIT_VARIABLE@320..327 "$result" [] [], + }, + ], + r_paren_token: R_PAREN@327..329 ")" [] [Whitespace(" ")], + }, + pattern: GritPatternWhere { + pattern: GritVariable { + grit_variable_token: GRIT_VARIABLE@329..332 "$x" [] [Whitespace(" ")], + }, + where_token: WHERE_KW@332..338 "where" [] [Whitespace(" ")], + side_condition: GritPredicateAnd { + and_token: missing (optional), + l_curly_token: L_CURLY@338..339 "{" [] [], + predicates: GritPredicateList [ + GritPredicateIfElse { + if_token: IF_KW@339..350 "if" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + l_paren_token: L_PAREN@350..351 "(" [] [], + if_predicate: GritPredicateMatch { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@351..359 "$result" [] [Whitespace(" ")], + }, + match_token: MATCH@359..362 "<:" [] [Whitespace(" ")], + right: GritUndefinedLiteral { + undefined_token: UNDEFINED_KW@362..371 "undefined" [] [], + }, + grit_bogus: missing (optional), + }, + r_paren_token: R_PAREN@371..373 ")" [] [Whitespace(" ")], + then_predicate: GritPredicateAnd { + and_token: missing (optional), + l_curly_token: L_CURLY@373..374 "{" [] [], + predicates: GritPredicateList [ + GritPredicateAssignment { + container: GritVariable { + grit_variable_token: GRIT_VARIABLE@374..395 "$result" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + eq_token: EQ@395..397 "=" [] [Whitespace(" ")], + pattern: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@397..410 "`// TODO: $x`" [] [], + }, + }, + grit_bogus: missing (optional), + }, + ], + r_curly_token: R_CURLY@410..421 "}" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + grit_predicate_else_clause: GritPredicateElseClause { + else_token: ELSE_KW@421..426 "else" [] [Whitespace(" ")], + else_predicate: GritPredicateAnd { + and_token: missing (optional), + l_curly_token: L_CURLY@426..427 "{" [] [], + predicates: GritPredicateList [ + GritPredicateAccumulate { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@427..448 "$result" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + add_assign_token: PLUSEQ@448..451 "+=" [] [Whitespace(" ")], + right: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@451..460 "`\\n// $x`" [] [], + }, + }, + }, + ], + r_curly_token: R_CURLY@460..470 "}" [Newline("\n"), Whitespace(" ")] [], + }, + }, + }, + ], + r_curly_token: R_CURLY@470..475 "}" [Newline("\n"), Whitespace(" ")] [], + }, + }, + }, + }, + grit_bogus: missing (optional), + }, + COMMA@475..476 "," [] [], + GritPredicateAssignment { + container: GritVariable { + grit_variable_token: GRIT_VARIABLE@476..494 "$target_lines" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + eq_token: EQ@494..496 "=" [] [Whitespace(" ")], + pattern: GritNodeLike { + name: GritName { + grit_name_token: GRIT_NAME@496..501 "lines" [] [], + }, + l_paren_token: L_PAREN@501..502 "(" [] [], + named_args: GritNamedArgList [ + GritNamedArg { + name: GritName { + grit_name_token: GRIT_NAME@502..509 "string" [] [Whitespace(" ")], + }, + eq_token: EQ@509..511 "=" [] [Whitespace(" ")], + pattern: GritVariable { + grit_variable_token: GRIT_VARIABLE@511..518 "$target" [] [], + }, + }, + ], + r_paren_token: R_PAREN@518..519 ")" [] [], + }, + grit_bogus: missing (optional), + }, + COMMA@519..520 "," [] [], + GritPredicateMatch { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@520..538 "$target_lines" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + match_token: MATCH@538..541 "<:" [] [Whitespace(" ")], + right: GritSome { + some_token: SOME_KW@541..546 "some" [] [Whitespace(" ")], + pattern: GritBubble { + bubble_token: BUBBLE_KW@546..552 "bubble" [] [], + variables: GritBubbleScope { + l_paren_token: L_PAREN@552..553 "(" [] [], + grit_variable_list: GritVariableList [ + GritVariable { + grit_variable_token: GRIT_VARIABLE@553..560 "$result" [] [], + }, + ], + r_paren_token: R_PAREN@560..562 ")" [] [Whitespace(" ")], + }, + pattern: GritPatternWhere { + pattern: GritVariable { + grit_variable_token: GRIT_VARIABLE@562..565 "$x" [] [Whitespace(" ")], + }, + where_token: WHERE_KW@565..571 "where" [] [Whitespace(" ")], + side_condition: GritPredicateAnd { + and_token: missing (optional), + l_curly_token: L_CURLY@571..573 "{" [] [Whitespace(" ")], + predicates: GritPredicateList [ + GritPredicateAccumulate { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@573..581 "$result" [] [Whitespace(" ")], + }, + add_assign_token: PLUSEQ@581..584 "+=" [] [Whitespace(" ")], + right: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@584..594 "`\\n// $x`" [] [Whitespace(" ")], + }, + }, + }, + ], + r_curly_token: R_CURLY@594..595 "}" [] [], + }, + }, + }, + }, + grit_bogus: missing (optional), + }, + COMMA@595..596 "," [] [], + GritPredicateReturn { + return_token: RETURN_KW@596..607 "return" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + pattern: GritVariable { + grit_variable_token: GRIT_VARIABLE@607..614 "$result" [] [], + }, + }, + COMMA@614..615 "," [] [], + ], + r_curly_token: R_CURLY@615..617 "}" [Newline("\n")] [], + }, + }, + ], + pattern: GritRewrite { + left: GritPatternAs { + pattern: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@617..669 "`module.exports = $_`" [Newline("\n"), Newline("\n"), Comments("// Use the my_todo fu ..."), Newline("\n")] [Whitespace(" ")], + }, + }, + as_token: AS_KW@669..672 "as" [] [Whitespace(" ")], + variable: GritVariable { + grit_variable_token: GRIT_VARIABLE@672..675 "$x" [] [Whitespace(" ")], + }, + }, + annotation: missing (optional), + fat_arrow_token: FAT_ARROW@675..678 "=>" [] [Whitespace(" ")], + right: GritNodeLike { + name: GritName { + grit_name_token: GRIT_NAME@678..685 "my_todo" [] [], + }, + l_paren_token: L_PAREN@685..686 "(" [] [], + named_args: GritNamedArgList [ + GritNamedArg { + name: GritName { + grit_name_token: GRIT_NAME@686..692 "target" [] [], + }, + eq_token: EQ@692..693 "=" [] [], + pattern: GritVariable { + grit_variable_token: GRIT_VARIABLE@693..695 "$x" [] [], + }, + }, + COMMA@695..697 "," [] [Whitespace(" ")], + GritNamedArg { + name: GritName { + grit_name_token: GRIT_NAME@697..704 "message" [] [], + }, + eq_token: EQ@704..705 "=" [] [], + pattern: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@705..725 "`Fix this\\nAnd that`" [] [], + }, + }, + }, + ], + r_paren_token: R_PAREN@725..726 ")" [] [], + }, + }, + definitions_continued: GritDefinitionList [], + eof_token: EOF@726..727 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..727 + 0: (empty) + 1: (empty) + 2: (empty) + 3: GRIT_DEFINITION_LIST@0..617 + 0: GRIT_FUNCTION_DEFINITION@0..96 + 0: FUNCTION_KW@0..36 "function" [Comments("// define a lines fun ..."), Newline("\n")] [Whitespace(" ")] + 1: GRIT_NAME@36..41 + 0: GRIT_NAME@36..41 "lines" [] [] + 2: L_PAREN@41..42 "(" [] [] + 3: GRIT_VARIABLE_LIST@42..49 + 0: GRIT_VARIABLE@42..49 + 0: GRIT_VARIABLE@42..49 "$string" [] [] + 4: R_PAREN@49..51 ")" [] [Whitespace(" ")] + 5: GRIT_CURLY_PREDICATE_LIST@51..96 + 0: L_CURLY@51..52 "{" [] [] + 1: GRIT_PREDICATE_LIST@52..94 + 0: GRIT_PREDICATE_RETURN@52..94 + 0: RETURN_KW@52..64 "return" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: GRIT_NODE_LIKE@64..94 + 0: GRIT_NAME@64..69 + 0: GRIT_NAME@64..69 "split" [] [] + 1: L_PAREN@69..70 "(" [] [] + 2: GRIT_NAMED_ARG_LIST@70..93 + 0: GRIT_VARIABLE@70..77 + 0: GRIT_VARIABLE@70..77 "$string" [] [] + 1: COMMA@77..79 "," [] [Whitespace(" ")] + 2: GRIT_NAMED_ARG@79..93 + 0: GRIT_NAME@79..88 + 0: GRIT_NAME@79..88 "separator" [] [] + 1: EQ@88..89 "=" [] [] + 2: GRIT_CODE_SNIPPET@89..93 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@89..93 + 0: GRIT_BACKTICK_SNIPPET@89..93 "`\\n`" [] [] + 3: R_PAREN@93..94 ")" [] [] + 2: R_CURLY@94..96 "}" [Newline("\n")] [] + 1: (empty) + 2: GRIT_FUNCTION_DEFINITION@96..617 + 0: FUNCTION_KW@96..136 "function" [Newline("\n"), Newline("\n"), Comments("// Define a my_todo f ..."), Newline("\n")] [Whitespace(" ")] + 1: GRIT_NAME@136..143 + 0: GRIT_NAME@136..143 "my_todo" [] [] + 2: L_PAREN@143..144 "(" [] [] + 3: GRIT_VARIABLE_LIST@144..161 + 0: GRIT_VARIABLE@144..151 + 0: GRIT_VARIABLE@144..151 "$target" [] [] + 1: COMMA@151..153 "," [] [Whitespace(" ")] + 2: GRIT_VARIABLE@153..161 + 0: GRIT_VARIABLE@153..161 "$message" [] [] + 4: R_PAREN@161..163 ")" [] [Whitespace(" ")] + 5: GRIT_CURLY_PREDICATE_LIST@163..617 + 0: L_CURLY@163..164 "{" [] [] + 1: GRIT_PREDICATE_LIST@164..615 + 0: GRIT_PREDICATE_IF_ELSE@164..255 + 0: IF_KW@164..170 "if" [Newline("\n"), Whitespace(" ")] [] + 1: L_PAREN@170..171 "(" [] [] + 2: GRIT_PREDICATE_MATCH@171..192 + 0: GRIT_VARIABLE@171..180 + 0: GRIT_VARIABLE@171..180 "$message" [] [Whitespace(" ")] + 1: MATCH@180..183 "<:" [] [Whitespace(" ")] + 2: GRIT_UNDEFINED_LITERAL@183..192 + 0: UNDEFINED_KW@183..192 "undefined" [] [] + 3: (empty) + 3: R_PAREN@192..194 ")" [] [Whitespace(" ")] + 4: GRIT_PREDICATE_AND@194..255 + 0: (empty) + 1: L_CURLY@194..195 "{" [] [] + 2: GRIT_PREDICATE_LIST@195..250 + 0: GRIT_PREDICATE_ASSIGNMENT@195..250 + 0: GRIT_VARIABLE@195..212 + 0: GRIT_VARIABLE@195..212 "$message" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: EQ@212..214 "=" [] [Whitespace(" ")] + 2: GRIT_STRING_LITERAL@214..250 + 0: GRIT_STRING@214..250 "\"This requires manual intervention.\"" [] [] + 3: (empty) + 3: R_CURLY@250..255 "}" [Newline("\n"), Whitespace(" ")] [] + 5: (empty) + 1: COMMA@255..256 "," [] [] + 2: GRIT_PREDICATE_ASSIGNMENT@256..293 + 0: GRIT_VARIABLE@256..267 + 0: GRIT_VARIABLE@256..267 "$lines" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: EQ@267..269 "=" [] [Whitespace(" ")] + 2: GRIT_NODE_LIKE@269..293 + 0: GRIT_NAME@269..274 + 0: GRIT_NAME@269..274 "lines" [] [] + 1: L_PAREN@274..275 "(" [] [] + 2: GRIT_NAMED_ARG_LIST@275..292 + 0: GRIT_NAMED_ARG@275..292 + 0: GRIT_NAME@275..282 + 0: GRIT_NAME@275..282 "string" [] [Whitespace(" ")] + 1: EQ@282..284 "=" [] [Whitespace(" ")] + 2: GRIT_VARIABLE@284..292 + 0: GRIT_VARIABLE@284..292 "$message" [] [] + 3: R_PAREN@292..293 ")" [] [] + 3: (empty) + 3: COMMA@293..294 "," [] [] + 4: GRIT_PREDICATE_MATCH@294..475 + 0: GRIT_VARIABLE@294..305 + 0: GRIT_VARIABLE@294..305 "$lines" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: MATCH@305..308 "<:" [] [Whitespace(" ")] + 2: GRIT_SOME@308..475 + 0: SOME_KW@308..313 "some" [] [Whitespace(" ")] + 1: GRIT_BUBBLE@313..475 + 0: BUBBLE_KW@313..319 "bubble" [] [] + 1: GRIT_BUBBLE_SCOPE@319..329 + 0: L_PAREN@319..320 "(" [] [] + 1: GRIT_VARIABLE_LIST@320..327 + 0: GRIT_VARIABLE@320..327 + 0: GRIT_VARIABLE@320..327 "$result" [] [] + 2: R_PAREN@327..329 ")" [] [Whitespace(" ")] + 2: GRIT_PATTERN_WHERE@329..475 + 0: GRIT_VARIABLE@329..332 + 0: GRIT_VARIABLE@329..332 "$x" [] [Whitespace(" ")] + 1: WHERE_KW@332..338 "where" [] [Whitespace(" ")] + 2: GRIT_PREDICATE_AND@338..475 + 0: (empty) + 1: L_CURLY@338..339 "{" [] [] + 2: GRIT_PREDICATE_LIST@339..470 + 0: GRIT_PREDICATE_IF_ELSE@339..470 + 0: IF_KW@339..350 "if" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: L_PAREN@350..351 "(" [] [] + 2: GRIT_PREDICATE_MATCH@351..371 + 0: GRIT_VARIABLE@351..359 + 0: GRIT_VARIABLE@351..359 "$result" [] [Whitespace(" ")] + 1: MATCH@359..362 "<:" [] [Whitespace(" ")] + 2: GRIT_UNDEFINED_LITERAL@362..371 + 0: UNDEFINED_KW@362..371 "undefined" [] [] + 3: (empty) + 3: R_PAREN@371..373 ")" [] [Whitespace(" ")] + 4: GRIT_PREDICATE_AND@373..421 + 0: (empty) + 1: L_CURLY@373..374 "{" [] [] + 2: GRIT_PREDICATE_LIST@374..410 + 0: GRIT_PREDICATE_ASSIGNMENT@374..410 + 0: GRIT_VARIABLE@374..395 + 0: GRIT_VARIABLE@374..395 "$result" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: EQ@395..397 "=" [] [Whitespace(" ")] + 2: GRIT_CODE_SNIPPET@397..410 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@397..410 + 0: GRIT_BACKTICK_SNIPPET@397..410 "`// TODO: $x`" [] [] + 3: (empty) + 3: R_CURLY@410..421 "}" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 5: GRIT_PREDICATE_ELSE_CLAUSE@421..470 + 0: ELSE_KW@421..426 "else" [] [Whitespace(" ")] + 1: GRIT_PREDICATE_AND@426..470 + 0: (empty) + 1: L_CURLY@426..427 "{" [] [] + 2: GRIT_PREDICATE_LIST@427..460 + 0: GRIT_PREDICATE_ACCUMULATE@427..460 + 0: GRIT_VARIABLE@427..448 + 0: GRIT_VARIABLE@427..448 "$result" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: PLUSEQ@448..451 "+=" [] [Whitespace(" ")] + 2: GRIT_CODE_SNIPPET@451..460 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@451..460 + 0: GRIT_BACKTICK_SNIPPET@451..460 "`\\n// $x`" [] [] + 3: R_CURLY@460..470 "}" [Newline("\n"), Whitespace(" ")] [] + 3: R_CURLY@470..475 "}" [Newline("\n"), Whitespace(" ")] [] + 3: (empty) + 5: COMMA@475..476 "," [] [] + 6: GRIT_PREDICATE_ASSIGNMENT@476..519 + 0: GRIT_VARIABLE@476..494 + 0: GRIT_VARIABLE@476..494 "$target_lines" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: EQ@494..496 "=" [] [Whitespace(" ")] + 2: GRIT_NODE_LIKE@496..519 + 0: GRIT_NAME@496..501 + 0: GRIT_NAME@496..501 "lines" [] [] + 1: L_PAREN@501..502 "(" [] [] + 2: GRIT_NAMED_ARG_LIST@502..518 + 0: GRIT_NAMED_ARG@502..518 + 0: GRIT_NAME@502..509 + 0: GRIT_NAME@502..509 "string" [] [Whitespace(" ")] + 1: EQ@509..511 "=" [] [Whitespace(" ")] + 2: GRIT_VARIABLE@511..518 + 0: GRIT_VARIABLE@511..518 "$target" [] [] + 3: R_PAREN@518..519 ")" [] [] + 3: (empty) + 7: COMMA@519..520 "," [] [] + 8: GRIT_PREDICATE_MATCH@520..595 + 0: GRIT_VARIABLE@520..538 + 0: GRIT_VARIABLE@520..538 "$target_lines" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: MATCH@538..541 "<:" [] [Whitespace(" ")] + 2: GRIT_SOME@541..595 + 0: SOME_KW@541..546 "some" [] [Whitespace(" ")] + 1: GRIT_BUBBLE@546..595 + 0: BUBBLE_KW@546..552 "bubble" [] [] + 1: GRIT_BUBBLE_SCOPE@552..562 + 0: L_PAREN@552..553 "(" [] [] + 1: GRIT_VARIABLE_LIST@553..560 + 0: GRIT_VARIABLE@553..560 + 0: GRIT_VARIABLE@553..560 "$result" [] [] + 2: R_PAREN@560..562 ")" [] [Whitespace(" ")] + 2: GRIT_PATTERN_WHERE@562..595 + 0: GRIT_VARIABLE@562..565 + 0: GRIT_VARIABLE@562..565 "$x" [] [Whitespace(" ")] + 1: WHERE_KW@565..571 "where" [] [Whitespace(" ")] + 2: GRIT_PREDICATE_AND@571..595 + 0: (empty) + 1: L_CURLY@571..573 "{" [] [Whitespace(" ")] + 2: GRIT_PREDICATE_LIST@573..594 + 0: GRIT_PREDICATE_ACCUMULATE@573..594 + 0: GRIT_VARIABLE@573..581 + 0: GRIT_VARIABLE@573..581 "$result" [] [Whitespace(" ")] + 1: PLUSEQ@581..584 "+=" [] [Whitespace(" ")] + 2: GRIT_CODE_SNIPPET@584..594 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@584..594 + 0: GRIT_BACKTICK_SNIPPET@584..594 "`\\n// $x`" [] [Whitespace(" ")] + 3: R_CURLY@594..595 "}" [] [] + 3: (empty) + 9: COMMA@595..596 "," [] [] + 10: GRIT_PREDICATE_RETURN@596..614 + 0: RETURN_KW@596..607 "return" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: GRIT_VARIABLE@607..614 + 0: GRIT_VARIABLE@607..614 "$result" [] [] + 11: COMMA@614..615 "," [] [] + 2: R_CURLY@615..617 "}" [Newline("\n")] [] + 4: GRIT_REWRITE@617..726 + 0: GRIT_PATTERN_AS@617..675 + 0: GRIT_CODE_SNIPPET@617..669 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@617..669 + 0: GRIT_BACKTICK_SNIPPET@617..669 "`module.exports = $_`" [Newline("\n"), Newline("\n"), Comments("// Use the my_todo fu ..."), Newline("\n")] [Whitespace(" ")] + 1: AS_KW@669..672 "as" [] [Whitespace(" ")] + 2: GRIT_VARIABLE@672..675 + 0: GRIT_VARIABLE@672..675 "$x" [] [Whitespace(" ")] + 1: (empty) + 2: FAT_ARROW@675..678 "=>" [] [Whitespace(" ")] + 3: GRIT_NODE_LIKE@678..726 + 0: GRIT_NAME@678..685 + 0: GRIT_NAME@678..685 "my_todo" [] [] + 1: L_PAREN@685..686 "(" [] [] + 2: GRIT_NAMED_ARG_LIST@686..725 + 0: GRIT_NAMED_ARG@686..695 + 0: GRIT_NAME@686..692 + 0: GRIT_NAME@686..692 "target" [] [] + 1: EQ@692..693 "=" [] [] + 2: GRIT_VARIABLE@693..695 + 0: GRIT_VARIABLE@693..695 "$x" [] [] + 1: COMMA@695..697 "," [] [Whitespace(" ")] + 2: GRIT_NAMED_ARG@697..725 + 0: GRIT_NAME@697..704 + 0: GRIT_NAME@697..704 "message" [] [] + 1: EQ@704..705 "=" [] [] + 2: GRIT_CODE_SNIPPET@705..725 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@705..725 + 0: GRIT_BACKTICK_SNIPPET@705..725 "`Fix this\\nAnd that`" [] [] + 3: R_PAREN@725..726 ")" [] [] + 5: GRIT_DEFINITION_LIST@726..726 + 6: EOF@726..727 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/or_condition.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/or_condition.grit new file mode 100644 index 00000000000..1decef6cafd --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/or_condition.grit @@ -0,0 +1,6 @@ +`console.$method('$message');` => `console.warn('$message');` where { + or { + $message <: "Hello, world!", + $method <: `error` + } +} diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/or_condition.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/or_condition.grit.snap new file mode 100644 index 00000000000..a2a4db3ad65 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/or_condition.grit.snap @@ -0,0 +1,131 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +`console.$method('$message');` => `console.warn('$message');` where { + or { + $message <: "Hello, world!", + $method <: `error` + } +} + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: missing (optional), + definitions: GritDefinitionList [], + pattern: GritRewrite { + left: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@0..31 "`console.$method('$message');`" [] [Whitespace(" ")], + }, + }, + annotation: missing (optional), + fat_arrow_token: FAT_ARROW@31..34 "=>" [] [Whitespace(" ")], + right: GritPatternWhere { + pattern: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@34..62 "`console.warn('$message');`" [] [Whitespace(" ")], + }, + }, + where_token: WHERE_KW@62..68 "where" [] [Whitespace(" ")], + side_condition: GritPredicateAnd { + and_token: missing (optional), + l_curly_token: L_CURLY@68..69 "{" [] [], + predicates: GritPredicateList [ + GritPredicateOr { + or_token: OR_KW@69..75 "or" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + l_curly_token: L_CURLY@75..76 "{" [] [], + predicates: GritPredicateList [ + GritPredicateMatch { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@76..90 "$message" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + match_token: MATCH@90..93 "<:" [] [Whitespace(" ")], + right: GritStringLiteral { + value_token: GRIT_STRING@93..108 "\"Hello, world!\"" [] [], + }, + grit_bogus: missing (optional), + }, + COMMA@108..109 "," [] [], + GritPredicateMatch { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@109..122 "$method" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + match_token: MATCH@122..125 "<:" [] [Whitespace(" ")], + right: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@125..132 "`error`" [] [], + }, + }, + grit_bogus: missing (optional), + }, + ], + r_curly_token: R_CURLY@132..136 "}" [Newline("\n"), Whitespace(" ")] [], + }, + ], + r_curly_token: R_CURLY@136..138 "}" [Newline("\n")] [], + }, + }, + }, + definitions_continued: GritDefinitionList [], + eof_token: EOF@138..139 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..139 + 0: (empty) + 1: (empty) + 2: (empty) + 3: GRIT_DEFINITION_LIST@0..0 + 4: GRIT_REWRITE@0..138 + 0: GRIT_CODE_SNIPPET@0..31 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@0..31 + 0: GRIT_BACKTICK_SNIPPET@0..31 "`console.$method('$message');`" [] [Whitespace(" ")] + 1: (empty) + 2: FAT_ARROW@31..34 "=>" [] [Whitespace(" ")] + 3: GRIT_PATTERN_WHERE@34..138 + 0: GRIT_CODE_SNIPPET@34..62 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@34..62 + 0: GRIT_BACKTICK_SNIPPET@34..62 "`console.warn('$message');`" [] [Whitespace(" ")] + 1: WHERE_KW@62..68 "where" [] [Whitespace(" ")] + 2: GRIT_PREDICATE_AND@68..138 + 0: (empty) + 1: L_CURLY@68..69 "{" [] [] + 2: GRIT_PREDICATE_LIST@69..136 + 0: GRIT_PREDICATE_OR@69..136 + 0: OR_KW@69..75 "or" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: L_CURLY@75..76 "{" [] [] + 2: GRIT_PREDICATE_LIST@76..132 + 0: GRIT_PREDICATE_MATCH@76..108 + 0: GRIT_VARIABLE@76..90 + 0: GRIT_VARIABLE@76..90 "$message" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: MATCH@90..93 "<:" [] [Whitespace(" ")] + 2: GRIT_STRING_LITERAL@93..108 + 0: GRIT_STRING@93..108 "\"Hello, world!\"" [] [] + 3: (empty) + 1: COMMA@108..109 "," [] [] + 2: GRIT_PREDICATE_MATCH@109..132 + 0: GRIT_VARIABLE@109..122 + 0: GRIT_VARIABLE@109..122 "$method" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: MATCH@122..125 "<:" [] [Whitespace(" ")] + 2: GRIT_CODE_SNIPPET@125..132 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@125..132 + 0: GRIT_BACKTICK_SNIPPET@125..132 "`error`" [] [] + 3: (empty) + 3: R_CURLY@132..136 "}" [Newline("\n"), Whitespace(" ")] [] + 3: R_CURLY@136..138 "}" [Newline("\n")] [] + 5: GRIT_DEFINITION_LIST@138..138 + 6: EOF@138..139 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/pattern_definition.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/pattern_definition.grit new file mode 100644 index 00000000000..e03ea437115 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/pattern_definition.grit @@ -0,0 +1,4 @@ +pattern console_method_to_info($method) { + `console.$method($message)` => `console.info($message)` +} +console_method_to_info(method = `log`) diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/pattern_definition.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/pattern_definition.grit.snap new file mode 100644 index 00000000000..35db32b0c64 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/pattern_definition.grit.snap @@ -0,0 +1,134 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +pattern console_method_to_info($method) { + `console.$method($message)` => `console.info($message)` +} +console_method_to_info(method = `log`) + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: missing (optional), + definitions: GritDefinitionList [ + GritPatternDefinition { + visibility_token: missing (optional), + pattern_token: PATTERN_KW@0..8 "pattern" [] [Whitespace(" ")], + name: GritName { + grit_name_token: GRIT_NAME@8..30 "console_method_to_info" [] [], + }, + l_paren_token: L_PAREN@30..31 "(" [] [], + args: GritPatternArgList { + grit_variable_list: GritVariableList [ + GritVariable { + grit_variable_token: GRIT_VARIABLE@31..38 "$method" [] [], + }, + ], + }, + r_paren_token: R_PAREN@38..40 ")" [] [Whitespace(" ")], + language: missing (optional), + body: GritPatternDefinitionBody { + l_curly_token: L_CURLY@40..41 "{" [] [], + patterns: GritPatternList [ + GritRewrite { + left: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@41..72 "`console.$method($message)`" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + }, + annotation: missing (optional), + fat_arrow_token: FAT_ARROW@72..75 "=>" [] [Whitespace(" ")], + right: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@75..99 "`console.info($message)`" [] [], + }, + }, + }, + ], + r_curly_token: R_CURLY@99..101 "}" [Newline("\n")] [], + }, + }, + ], + pattern: GritNodeLike { + name: GritName { + grit_name_token: GRIT_NAME@101..124 "console_method_to_info" [Newline("\n")] [], + }, + l_paren_token: L_PAREN@124..125 "(" [] [], + named_args: GritNamedArgList [ + GritNamedArg { + name: GritName { + grit_name_token: GRIT_NAME@125..132 "method" [] [Whitespace(" ")], + }, + eq_token: EQ@132..134 "=" [] [Whitespace(" ")], + pattern: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@134..139 "`log`" [] [], + }, + }, + }, + ], + r_paren_token: R_PAREN@139..140 ")" [] [], + }, + definitions_continued: GritDefinitionList [], + eof_token: EOF@140..141 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..141 + 0: (empty) + 1: (empty) + 2: (empty) + 3: GRIT_DEFINITION_LIST@0..101 + 0: GRIT_PATTERN_DEFINITION@0..101 + 0: (empty) + 1: PATTERN_KW@0..8 "pattern" [] [Whitespace(" ")] + 2: GRIT_NAME@8..30 + 0: GRIT_NAME@8..30 "console_method_to_info" [] [] + 3: L_PAREN@30..31 "(" [] [] + 4: GRIT_PATTERN_ARG_LIST@31..38 + 0: GRIT_VARIABLE_LIST@31..38 + 0: GRIT_VARIABLE@31..38 + 0: GRIT_VARIABLE@31..38 "$method" [] [] + 5: R_PAREN@38..40 ")" [] [Whitespace(" ")] + 6: (empty) + 7: GRIT_PATTERN_DEFINITION_BODY@40..101 + 0: L_CURLY@40..41 "{" [] [] + 1: GRIT_PATTERN_LIST@41..99 + 0: GRIT_REWRITE@41..99 + 0: GRIT_CODE_SNIPPET@41..72 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@41..72 + 0: GRIT_BACKTICK_SNIPPET@41..72 "`console.$method($message)`" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: (empty) + 2: FAT_ARROW@72..75 "=>" [] [Whitespace(" ")] + 3: GRIT_CODE_SNIPPET@75..99 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@75..99 + 0: GRIT_BACKTICK_SNIPPET@75..99 "`console.info($message)`" [] [] + 2: R_CURLY@99..101 "}" [Newline("\n")] [] + 4: GRIT_NODE_LIKE@101..140 + 0: GRIT_NAME@101..124 + 0: GRIT_NAME@101..124 "console_method_to_info" [Newline("\n")] [] + 1: L_PAREN@124..125 "(" [] [] + 2: GRIT_NAMED_ARG_LIST@125..139 + 0: GRIT_NAMED_ARG@125..139 + 0: GRIT_NAME@125..132 + 0: GRIT_NAME@125..132 "method" [] [Whitespace(" ")] + 1: EQ@132..134 "=" [] [Whitespace(" ")] + 2: GRIT_CODE_SNIPPET@134..139 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@134..139 + 0: GRIT_BACKTICK_SNIPPET@134..139 "`log`" [] [] + 3: R_PAREN@139..140 ")" [] [] + 5: GRIT_DEFINITION_LIST@140..140 + 6: EOF@140..141 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/predicate_definition.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/predicate_definition.grit new file mode 100644 index 00000000000..f78a0e009f0 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/predicate_definition.grit @@ -0,0 +1,6 @@ +predicate program_contains_logger() { + $program <: contains `logger` +} +`console.log` => `logger.info` where { + program_contains_logger() +} diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/predicate_definition.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/predicate_definition.grit.snap new file mode 100644 index 00000000000..00197cfcccb --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/predicate_definition.grit.snap @@ -0,0 +1,148 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +predicate program_contains_logger() { + $program <: contains `logger` +} +`console.log` => `logger.info` where { + program_contains_logger() +} + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: missing (optional), + definitions: GritDefinitionList [ + GritPredicateDefinition { + predicate_token: PREDICATE_KW@0..10 "predicate" [] [Whitespace(" ")], + name: GritName { + grit_name_token: GRIT_NAME@10..33 "program_contains_logger" [] [], + }, + l_paren_token: L_PAREN@33..34 "(" [] [], + args: missing (optional), + r_paren_token: R_PAREN@34..36 ")" [] [Whitespace(" ")], + body: GritCurlyPredicateList { + l_curly_token: L_CURLY@36..37 "{" [] [], + predicates: GritPredicateList [ + GritPredicateMatch { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@37..49 "$program" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + match_token: MATCH@49..52 "<:" [] [Whitespace(" ")], + right: GritPatternContains { + contains_token: CONTAINS_KW@52..61 "contains" [] [Whitespace(" ")], + contains: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@61..69 "`logger`" [] [], + }, + }, + grit_pattern_contains_until_clause: missing (optional), + }, + grit_bogus: missing (optional), + }, + ], + r_curly_token: R_CURLY@69..71 "}" [Newline("\n")] [], + }, + }, + ], + pattern: GritRewrite { + left: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@71..86 "`console.log`" [Newline("\n")] [Whitespace(" ")], + }, + }, + annotation: missing (optional), + fat_arrow_token: FAT_ARROW@86..89 "=>" [] [Whitespace(" ")], + right: GritPatternWhere { + pattern: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@89..103 "`logger.info`" [] [Whitespace(" ")], + }, + }, + where_token: WHERE_KW@103..109 "where" [] [Whitespace(" ")], + side_condition: GritPredicateAnd { + and_token: missing (optional), + l_curly_token: L_CURLY@109..110 "{" [] [], + predicates: GritPredicateList [ + GritPredicateCall { + name: GritName { + grit_name_token: GRIT_NAME@110..136 "program_contains_logger" [Newline("\n"), Whitespace(" ")] [], + }, + l_paren_token: L_PAREN@136..137 "(" [] [], + named_args: GritNamedArgList [], + r_paren_token: R_PAREN@137..138 ")" [] [], + }, + ], + r_curly_token: R_CURLY@138..140 "}" [Newline("\n")] [], + }, + }, + }, + definitions_continued: GritDefinitionList [], + eof_token: EOF@140..141 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..141 + 0: (empty) + 1: (empty) + 2: (empty) + 3: GRIT_DEFINITION_LIST@0..71 + 0: GRIT_PREDICATE_DEFINITION@0..71 + 0: PREDICATE_KW@0..10 "predicate" [] [Whitespace(" ")] + 1: GRIT_NAME@10..33 + 0: GRIT_NAME@10..33 "program_contains_logger" [] [] + 2: L_PAREN@33..34 "(" [] [] + 3: (empty) + 4: R_PAREN@34..36 ")" [] [Whitespace(" ")] + 5: GRIT_CURLY_PREDICATE_LIST@36..71 + 0: L_CURLY@36..37 "{" [] [] + 1: GRIT_PREDICATE_LIST@37..69 + 0: GRIT_PREDICATE_MATCH@37..69 + 0: GRIT_VARIABLE@37..49 + 0: GRIT_VARIABLE@37..49 "$program" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: MATCH@49..52 "<:" [] [Whitespace(" ")] + 2: GRIT_PATTERN_CONTAINS@52..69 + 0: CONTAINS_KW@52..61 "contains" [] [Whitespace(" ")] + 1: GRIT_CODE_SNIPPET@61..69 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@61..69 + 0: GRIT_BACKTICK_SNIPPET@61..69 "`logger`" [] [] + 2: (empty) + 3: (empty) + 2: R_CURLY@69..71 "}" [Newline("\n")] [] + 4: GRIT_REWRITE@71..140 + 0: GRIT_CODE_SNIPPET@71..86 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@71..86 + 0: GRIT_BACKTICK_SNIPPET@71..86 "`console.log`" [Newline("\n")] [Whitespace(" ")] + 1: (empty) + 2: FAT_ARROW@86..89 "=>" [] [Whitespace(" ")] + 3: GRIT_PATTERN_WHERE@89..140 + 0: GRIT_CODE_SNIPPET@89..103 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@89..103 + 0: GRIT_BACKTICK_SNIPPET@89..103 "`logger.info`" [] [Whitespace(" ")] + 1: WHERE_KW@103..109 "where" [] [Whitespace(" ")] + 2: GRIT_PREDICATE_AND@109..140 + 0: (empty) + 1: L_CURLY@109..110 "{" [] [] + 2: GRIT_PREDICATE_LIST@110..138 + 0: GRIT_PREDICATE_CALL@110..138 + 0: GRIT_NAME@110..136 + 0: GRIT_NAME@110..136 "program_contains_logger" [Newline("\n"), Whitespace(" ")] [] + 1: L_PAREN@136..137 "(" [] [] + 2: GRIT_NAMED_ARG_LIST@137..137 + 3: R_PAREN@137..138 ")" [] [] + 3: R_CURLY@138..140 "}" [Newline("\n")] [] + 5: GRIT_DEFINITION_LIST@140..140 + 6: EOF@140..141 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/private_pattern.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/private_pattern.grit new file mode 100644 index 00000000000..2ce01b2610c --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/private_pattern.grit @@ -0,0 +1,3 @@ +private pattern this_pattern_is_hidden() { + `console` +} diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/private_pattern.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/private_pattern.grit.snap new file mode 100644 index 00000000000..9d266ccd76d --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/private_pattern.grit.snap @@ -0,0 +1,78 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +private pattern this_pattern_is_hidden() { + `console` +} + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: missing (optional), + definitions: GritDefinitionList [ + GritPatternDefinition { + visibility_token: PRIVATE_KW@0..8 "private" [] [Whitespace(" ")], + pattern_token: PATTERN_KW@8..16 "pattern" [] [Whitespace(" ")], + name: GritName { + grit_name_token: GRIT_NAME@16..38 "this_pattern_is_hidden" [] [], + }, + l_paren_token: L_PAREN@38..39 "(" [] [], + args: missing (optional), + r_paren_token: R_PAREN@39..41 ")" [] [Whitespace(" ")], + language: missing (optional), + body: GritPatternDefinitionBody { + l_curly_token: L_CURLY@41..42 "{" [] [], + patterns: GritPatternList [ + GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@42..54 "`console`" [Newline("\n"), Whitespace(" ")] [], + }, + }, + ], + r_curly_token: R_CURLY@54..56 "}" [Newline("\n")] [], + }, + }, + ], + pattern: missing (optional), + definitions_continued: GritDefinitionList [], + eof_token: EOF@56..57 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..57 + 0: (empty) + 1: (empty) + 2: (empty) + 3: GRIT_DEFINITION_LIST@0..56 + 0: GRIT_PATTERN_DEFINITION@0..56 + 0: PRIVATE_KW@0..8 "private" [] [Whitespace(" ")] + 1: PATTERN_KW@8..16 "pattern" [] [Whitespace(" ")] + 2: GRIT_NAME@16..38 + 0: GRIT_NAME@16..38 "this_pattern_is_hidden" [] [] + 3: L_PAREN@38..39 "(" [] [] + 4: (empty) + 5: R_PAREN@39..41 ")" [] [Whitespace(" ")] + 6: (empty) + 7: GRIT_PATTERN_DEFINITION_BODY@41..56 + 0: L_CURLY@41..42 "{" [] [] + 1: GRIT_PATTERN_LIST@42..54 + 0: GRIT_CODE_SNIPPET@42..54 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@42..54 + 0: GRIT_BACKTICK_SNIPPET@42..54 "`console`" [Newline("\n"), Whitespace(" ")] [] + 2: R_CURLY@54..56 "}" [Newline("\n")] [] + 4: (empty) + 5: GRIT_DEFINITION_LIST@56..56 + 6: EOF@56..57 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/until_modifier.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/until_modifier.grit new file mode 100644 index 00000000000..c2349438bb9 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/until_modifier.grit @@ -0,0 +1,3 @@ +`console.$_($content)` where { + $content <: contains `secret` until `sanitized($_)` +} diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/until_modifier.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/until_modifier.grit.snap new file mode 100644 index 00000000000..83a1e46257a --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/until_modifier.grit.snap @@ -0,0 +1,100 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +`console.$_($content)` where { + $content <: contains `secret` until `sanitized($_)` +} + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: missing (optional), + definitions: GritDefinitionList [], + pattern: GritPatternWhere { + pattern: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@0..23 "`console.$_($content)`" [] [Whitespace(" ")], + }, + }, + where_token: WHERE_KW@23..29 "where" [] [Whitespace(" ")], + side_condition: GritPredicateAnd { + and_token: missing (optional), + l_curly_token: L_CURLY@29..30 "{" [] [], + predicates: GritPredicateList [ + GritPredicateMatch { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@30..42 "$content" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + match_token: MATCH@42..45 "<:" [] [Whitespace(" ")], + right: GritPatternContains { + contains_token: CONTAINS_KW@45..54 "contains" [] [Whitespace(" ")], + contains: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@54..63 "`secret`" [] [Whitespace(" ")], + }, + }, + grit_pattern_contains_until_clause: GritPatternContainsUntilClause { + until_token: UNTIL_KW@63..69 "until" [] [Whitespace(" ")], + until: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@69..84 "`sanitized($_)`" [] [], + }, + }, + }, + }, + grit_bogus: missing (optional), + }, + ], + r_curly_token: R_CURLY@84..86 "}" [Newline("\n")] [], + }, + }, + definitions_continued: GritDefinitionList [], + eof_token: EOF@86..87 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..87 + 0: (empty) + 1: (empty) + 2: (empty) + 3: GRIT_DEFINITION_LIST@0..0 + 4: GRIT_PATTERN_WHERE@0..86 + 0: GRIT_CODE_SNIPPET@0..23 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@0..23 + 0: GRIT_BACKTICK_SNIPPET@0..23 "`console.$_($content)`" [] [Whitespace(" ")] + 1: WHERE_KW@23..29 "where" [] [Whitespace(" ")] + 2: GRIT_PREDICATE_AND@29..86 + 0: (empty) + 1: L_CURLY@29..30 "{" [] [] + 2: GRIT_PREDICATE_LIST@30..84 + 0: GRIT_PREDICATE_MATCH@30..84 + 0: GRIT_VARIABLE@30..42 + 0: GRIT_VARIABLE@30..42 "$content" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: MATCH@42..45 "<:" [] [Whitespace(" ")] + 2: GRIT_PATTERN_CONTAINS@45..84 + 0: CONTAINS_KW@45..54 "contains" [] [Whitespace(" ")] + 1: GRIT_CODE_SNIPPET@54..63 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@54..63 + 0: GRIT_BACKTICK_SNIPPET@54..63 "`secret`" [] [Whitespace(" ")] + 2: GRIT_PATTERN_CONTAINS_UNTIL_CLAUSE@63..84 + 0: UNTIL_KW@63..69 "until" [] [Whitespace(" ")] + 1: GRIT_CODE_SNIPPET@69..84 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@69..84 + 0: GRIT_BACKTICK_SNIPPET@69..84 "`sanitized($_)`" [] [] + 3: (empty) + 3: R_CURLY@84..86 "}" [Newline("\n")] [] + 5: GRIT_DEFINITION_LIST@86..86 + 6: EOF@86..87 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/within_clause.grit b/crates/biome_grit_parser/tests/grit_test_suite/ok/within_clause.grit new file mode 100644 index 00000000000..a6e0e586ad2 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/within_clause.grit @@ -0,0 +1,3 @@ +`console.log($arg)` where { + $arg <: within `if (DEBUG) { $_ }` +} diff --git a/crates/biome_grit_parser/tests/grit_test_suite/ok/within_clause.grit.snap b/crates/biome_grit_parser/tests/grit_test_suite/ok/within_clause.grit.snap new file mode 100644 index 00000000000..e7a4bc56593 --- /dev/null +++ b/crates/biome_grit_parser/tests/grit_test_suite/ok/within_clause.grit.snap @@ -0,0 +1,87 @@ +--- +source: crates/biome_grit_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```grit +`console.log($arg)` where { + $arg <: within `if (DEBUG) { $_ }` +} + +``` + +## AST + +``` +GritRoot { + bom_token: missing (optional), + version: missing (optional), + language: missing (optional), + definitions: GritDefinitionList [], + pattern: GritPatternWhere { + pattern: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@0..20 "`console.log($arg)`" [] [Whitespace(" ")], + }, + }, + where_token: WHERE_KW@20..26 "where" [] [Whitespace(" ")], + side_condition: GritPredicateAnd { + and_token: missing (optional), + l_curly_token: L_CURLY@26..27 "{" [] [], + predicates: GritPredicateList [ + GritPredicateMatch { + left: GritVariable { + grit_variable_token: GRIT_VARIABLE@27..35 "$arg" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")], + }, + match_token: MATCH@35..38 "<:" [] [Whitespace(" ")], + right: GritWithin { + within_token: WITHIN_KW@38..45 "within" [] [Whitespace(" ")], + pattern: GritCodeSnippet { + source: GritBacktickSnippetLiteral { + value_token: GRIT_BACKTICK_SNIPPET@45..64 "`if (DEBUG) { $_ }`" [] [], + }, + }, + }, + grit_bogus: missing (optional), + }, + ], + r_curly_token: R_CURLY@64..66 "}" [Newline("\n")] [], + }, + }, + definitions_continued: GritDefinitionList [], + eof_token: EOF@66..67 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRIT_ROOT@0..67 + 0: (empty) + 1: (empty) + 2: (empty) + 3: GRIT_DEFINITION_LIST@0..0 + 4: GRIT_PATTERN_WHERE@0..66 + 0: GRIT_CODE_SNIPPET@0..20 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@0..20 + 0: GRIT_BACKTICK_SNIPPET@0..20 "`console.log($arg)`" [] [Whitespace(" ")] + 1: WHERE_KW@20..26 "where" [] [Whitespace(" ")] + 2: GRIT_PREDICATE_AND@26..66 + 0: (empty) + 1: L_CURLY@26..27 "{" [] [] + 2: GRIT_PREDICATE_LIST@27..64 + 0: GRIT_PREDICATE_MATCH@27..64 + 0: GRIT_VARIABLE@27..35 + 0: GRIT_VARIABLE@27..35 "$arg" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")] + 1: MATCH@35..38 "<:" [] [Whitespace(" ")] + 2: GRIT_WITHIN@38..64 + 0: WITHIN_KW@38..45 "within" [] [Whitespace(" ")] + 1: GRIT_CODE_SNIPPET@45..64 + 0: GRIT_BACKTICK_SNIPPET_LITERAL@45..64 + 0: GRIT_BACKTICK_SNIPPET@45..64 "`if (DEBUG) { $_ }`" [] [] + 3: (empty) + 3: R_CURLY@64..66 "}" [Newline("\n")] [] + 5: GRIT_DEFINITION_LIST@66..66 + 6: EOF@66..67 "" [Newline("\n")] [] + +``` diff --git a/xtask/codegen/gritql.ungram b/xtask/codegen/gritql.ungram index 804a507518f..fee7ec4ff00 100644 --- a/xtask/codegen/gritql.ungram +++ b/xtask/codegen/gritql.ungram @@ -330,11 +330,6 @@ GritRegexPatternVariables = GritPatternArgList? ')' -// node api does not have good support for fields (big sad) -// I double checked by priniting out a JSON stringified -// version of the object and it does not have the necessary -// fields. so in order to hide _pattern we create this intermediate -// value to extract the patternDefinitionBody. GritPatternDefinitionBody = '{' patterns: GritPatternList?