diff --git a/crates/cairo-lang-defs/src/db.rs b/crates/cairo-lang-defs/src/db.rs index 60a8545a95a..1326b9c59e0 100644 --- a/crates/cairo-lang-defs/src/db.rs +++ b/crates/cairo-lang-defs/src/db.rs @@ -549,6 +549,7 @@ fn priv_module_data(db: &dyn DefsGroup, module_id: ModuleId) -> Maybe todo!(), ast::ModuleItem::HeaderDoc(_) => {} ast::ModuleItem::Missing(_) => {} } diff --git a/crates/cairo-lang-parser/src/lexer.rs b/crates/cairo-lang-parser/src/lexer.rs index f729e5c4ff8..62cafa49858 100644 --- a/crates/cairo-lang-parser/src/lexer.rs +++ b/crates/cairo-lang-parser/src/lexer.rs @@ -213,6 +213,7 @@ impl<'a> Lexer<'a> { "let" => TokenKind::Let, "return" => TokenKind::Return, "match" => TokenKind::Match, + "macro" => TokenKind::Macro, "if" => TokenKind::If, "loop" => TokenKind::Loop, "continue" => TokenKind::Continue, @@ -276,6 +277,7 @@ impl<'a> Lexer<'a> { '%' => self.pick_kind('=', TokenKind::ModEq, TokenKind::Mod), '+' => self.pick_kind('=', TokenKind::PlusEq, TokenKind::Plus), '#' => self.take_token_of_kind(TokenKind::Hash), + '$' => self.take_token_of_kind(TokenKind::Dollar), '-' => { self.take(); match self.peek() { @@ -375,6 +377,7 @@ enum TokenKind { Let, Return, Match, + Macro, If, While, For, @@ -420,6 +423,7 @@ enum TokenKind { Colon, ColonColon, Comma, + Dollar, Dot, DotDot, Eq, @@ -474,6 +478,7 @@ fn token_kind_to_terminal_syntax_kind(kind: TokenKind) -> SyntaxKind { TokenKind::Implicits => SyntaxKind::TerminalImplicits, TokenKind::NoPanic => SyntaxKind::TerminalNoPanic, TokenKind::Pub => SyntaxKind::TerminalPub, + TokenKind::Macro => SyntaxKind::TerminalMacro, TokenKind::And => SyntaxKind::TerminalAnd, TokenKind::AndAnd => SyntaxKind::TerminalAndAnd, TokenKind::At => SyntaxKind::TerminalAt, @@ -501,6 +506,7 @@ fn token_kind_to_terminal_syntax_kind(kind: TokenKind) -> SyntaxKind { TokenKind::Colon => SyntaxKind::TerminalColon, TokenKind::ColonColon => SyntaxKind::TerminalColonColon, TokenKind::Comma => SyntaxKind::TerminalComma, + TokenKind::Dollar => SyntaxKind::TerminalDollar, TokenKind::Dot => SyntaxKind::TerminalDot, TokenKind::DotDot => SyntaxKind::TerminalDotDot, TokenKind::Eq => SyntaxKind::TerminalEq, diff --git a/crates/cairo-lang-parser/src/parser.rs b/crates/cairo-lang-parser/src/parser.rs index 12d744e9187..b74b24fa789 100644 --- a/crates/cairo-lang-parser/src/parser.rs +++ b/crates/cairo-lang-parser/src/parser.rs @@ -41,6 +41,8 @@ pub struct Parser<'a> { diagnostics: &'a mut DiagnosticsBuilder, /// An accumulating vector of pending skipped tokens diagnostics. pending_skipped_token_diagnostics: Vec, + /// An indicator of whether to allow placeholders exprs. + allow_placeholder_exprs: bool, } /// The possible results of a try_parse_* function failing to parse. @@ -120,6 +122,7 @@ impl<'a> Parser<'a> { last_trivia_length: Default::default(), diagnostics, pending_skipped_token_diagnostics: Vec::new(), + allow_placeholder_exprs: false, } } @@ -242,6 +245,9 @@ impl<'a> Parser<'a> { SyntaxKind::TerminalUse => Ok(self.expect_item_use(attributes, visibility).into()), SyntaxKind::TerminalTrait => Ok(self.expect_item_trait(attributes, visibility).into()), SyntaxKind::TerminalImpl => Ok(self.expect_module_item_impl(attributes, visibility)), + SyntaxKind::TerminalMacro => { + Ok(self.expect_item_macro_declaration(attributes, visibility).into()) + } SyntaxKind::TerminalIdentifier => { // We take the identifier to check if the next token is a `!`. If it is, we assume // that a macro is following and handle it similarly to any other module item. If @@ -566,6 +572,48 @@ impl<'a> Parser<'a> { ItemUse::new_green(self.db, attributes, visibility, use_kw, use_path, semicolon) } + /// Assumes the current token is Macro. + /// Expected pattern: `macro{}` + fn expect_item_macro_declaration( + &mut self, + attributes: AttributeListGreen, + visibility: VisibilityGreen, + ) -> ItemMacroDeclarationGreen { + let macro_kw = self.take::(); + let name = self.parse_identifier(); + let lbrace = self.parse_token::(); + let macro_rules = MacroRulesList::new_green( + self.db, + self.parse_list(Self::try_parse_macro_rule, is_of_kind!(rbrace), "macro rule"), + ); + let rbrace = self.parse_token::(); + ItemMacroDeclaration::new_green( + self.db, + attributes, + visibility, + macro_kw, + name, + lbrace, + macro_rules, + rbrace, + ) + } + + /// Returns a GreenId of a node with a MacroRule kind or TryParseFailure if a macro rule can't + /// be parsed. + fn try_parse_macro_rule(&mut self) -> TryParseResult { + match self.peek().kind { + SyntaxKind::TerminalLParen => { + let lhs = self.parse_token_tree_node(); + let arrow = self.parse_token::(); + let rhs = self.parse_block_with_placeholders(); + let semicolon = self.parse_token::(); + Ok(MacroRule::new_green(self.db, lhs, arrow, rhs, semicolon)) + } + _ => Err(TryParseFailure::SkipToken), + } + } + /// Returns a GreenId of a node with a UsePath kind or TryParseFailure if can't parse a UsePath. fn try_parse_use_path(&mut self) -> TryParseResult { if !matches!(self.peek().kind, SyntaxKind::TerminalLBrace | SyntaxKind::TerminalIdentifier) @@ -1244,7 +1292,9 @@ impl<'a> Parser<'a> { SyntaxKind::TerminalOrOr if lbrace_allowed == LbraceAllowed::Allow => { Ok(self.expect_closure_expr_nullary().into()) } - + SyntaxKind::TerminalDollar if self.allow_placeholder_exprs => { + Ok(self.expect_placeholder_expr().into()) + } _ => { // TODO(yuval): report to diagnostics. Err(TryParseFailure::SkipToken) @@ -1434,6 +1484,7 @@ impl<'a> Parser<'a> { SyntaxKind::TerminalComma => self.take::().into(), SyntaxKind::TerminalDiv => self.take::().into(), SyntaxKind::TerminalDivEq => self.take::().into(), + SyntaxKind::TerminalDollar => self.take::().into(), SyntaxKind::TerminalDot => self.take::().into(), SyntaxKind::TerminalDotDot => self.take::().into(), SyntaxKind::TerminalEndOfFile => self.take::().into(), @@ -1805,6 +1856,13 @@ impl<'a> Parser<'a> { ExprBlock::new_green(self.db, lbrace, statements, rbrace) } + fn parse_block_with_placeholders(&mut self) -> ExprBlockGreen { + let prev_allow_placeholder_exprs = self.allow_placeholder_exprs; + self.allow_placeholder_exprs = true; + let block = self.parse_block(); + self.allow_placeholder_exprs = prev_allow_placeholder_exprs; + block + } /// Assumes the current token is `Match`. /// Expected pattern: `match \{*\}` fn expect_match_expr(&mut self) -> ExprMatchGreen { @@ -1971,6 +2029,14 @@ impl<'a> Parser<'a> { ) } + /// Assumes the current token is Dollar. + /// Expected pattern: `$`. + fn expect_placeholder_expr(&mut self) -> ExprPlaceholderGreen { + let dollar = self.take::(); + let name = self.parse_identifier(); + ExprPlaceholder::new_green(self.db, dollar, name) + } + /// Returns a GreenId of a node with a MatchArm kind or TryParseFailure if a match arm can't be /// parsed. pub fn try_parse_match_arm(&mut self) -> TryParseResult { @@ -2705,7 +2771,12 @@ impl<'a> Parser<'a> { expected_element: &str, ) -> Vec { let mut children: Vec = Vec::new(); + let mut c = 0; loop { + if c > 10000 { + break; + } + c += 1; let parse_result = try_parse_list_element(self); match parse_result { Ok(element_green) => { diff --git a/crates/cairo-lang-parser/src/parser_test.rs b/crates/cairo-lang-parser/src/parser_test.rs index f75fb7659fa..7315252affc 100644 --- a/crates/cairo-lang-parser/src/parser_test.rs +++ b/crates/cairo-lang-parser/src/parser_test.rs @@ -193,6 +193,7 @@ cairo_lang_test_utils::test_file_test!( range: "range", use_: "use", type_alias: "type_alias", + macro_declaration: "macro_declaration", }, test_partial_parser_tree ); diff --git a/crates/cairo-lang-parser/src/parser_test_data/partial_trees/item_inline_macro b/crates/cairo-lang-parser/src/parser_test_data/partial_trees/item_inline_macro index 7461cf3d59c..fef7a929508 100644 --- a/crates/cairo-lang-parser/src/parser_test_data/partial_trees/item_inline_macro +++ b/crates/cairo-lang-parser/src/parser_test_data/partial_trees/item_inline_macro @@ -317,7 +317,7 @@ identifier test_partial_parser_tree(expect_diagnostics: true) //! > cairo_code -macro! +a_macro! fn foo() {} //! > top_level_kind @@ -328,20 +328,20 @@ FunctionWithBody //! > expected_diagnostics error: Missing tokens. Expected an argument list wrapped in either parentheses, brackets, or braces. - --> dummy_file.cairo:1:7 -macro! - ^ + --> dummy_file.cairo:1:9 +a_macro! + ^ error: Missing token TerminalSemicolon. - --> dummy_file.cairo:1:7 -macro! - ^ + --> dummy_file.cairo:1:9 +a_macro! + ^ //! > expected_tree └── Top level kind: ModuleItemList ├── child #0 (kind: ItemInlineMacro) │ ├── attributes (kind: AttributeList) [] - │ ├── name (kind: TokenIdentifier): 'macro' + │ ├── name (kind: TokenIdentifier): 'a_macro' │ ├── bang (kind: TokenNot): '!' │ ├── arguments (kind: TokenTreeNode) │ │ └── subtree (kind: WrappedTokenTreeMissing) [] diff --git a/crates/cairo-lang-parser/src/parser_test_data/partial_trees/macro_declaration b/crates/cairo-lang-parser/src/parser_test_data/partial_trees/macro_declaration new file mode 100644 index 00000000000..72056d1fdcc --- /dev/null +++ b/crates/cairo-lang-parser/src/parser_test_data/partial_trees/macro_declaration @@ -0,0 +1,195 @@ +//! > Test simple macro definition + +//! > test_runner_name +test_partial_parser_tree(expect_diagnostics: false) + +//! > cairo_code +macro macro_name {() => { + 2 + $ placeholder +}; } + +//! > top_level_kind + +//! > ignored_kinds + +//! > expected_diagnostics + +//! > expected_tree +└── root (kind: SyntaxFile) + ├── items (kind: ModuleItemList) + │ └── child #0 (kind: ItemMacroDeclaration) + │ ├── attributes (kind: AttributeList) [] + │ ├── visibility (kind: VisibilityDefault) [] + │ ├── macro_kw (kind: TokenMacro): 'macro' + │ ├── name (kind: TokenIdentifier): 'macro_name' + │ ├── lbrace (kind: TokenLBrace): '{' + │ ├── rules (kind: MacroRulesList) + │ │ └── child #0 (kind: MacroRule) + │ │ ├── lhs (kind: TokenTreeNode) + │ │ │ └── subtree (kind: ParenthesizedTokenTree) + │ │ │ ├── lparen (kind: TokenLParen): '(' + │ │ │ ├── tokens (kind: TokenList) [] + │ │ │ └── rparen (kind: TokenRParen): ')' + │ │ ├── fat_arrow (kind: TokenMatchArrow): '=>' + │ │ ├── rhs (kind: ExprBlock) + │ │ │ ├── lbrace (kind: TokenLBrace): '{' + │ │ │ ├── statements (kind: StatementList) + │ │ │ │ └── child #0 (kind: StatementExpr) + │ │ │ │ ├── attributes (kind: AttributeList) [] + │ │ │ │ ├── expr (kind: ExprBinary) + │ │ │ │ │ ├── lhs (kind: TokenLiteralNumber): '2' + │ │ │ │ │ ├── op (kind: TokenPlus): '+' + │ │ │ │ │ └── rhs (kind: ExprPlaceholder) + │ │ │ │ │ ├── dollar (kind: TokenDollar): '$' + │ │ │ │ │ └── name (kind: TokenIdentifier): 'placeholder' + │ │ │ │ └── semicolon (kind: OptionTerminalSemicolonEmpty) [] + │ │ │ └── rbrace (kind: TokenRBrace): '}' + │ │ └── semicolon (kind: TokenSemicolon): ';' + │ └── rbrace (kind: TokenRBrace): '}' + └── eof (kind: TokenEndOfFile). + +//! > ========================================================================== + +//! > Test macro definition with several rules + +//! > test_runner_name +test_partial_parser_tree(expect_diagnostics: false) + +//! > cairo_code +macro macro_name {() => { + 2 + $ placeholder +}; ($ x: ident) => { + 2 + $ x +}; } + +//! > top_level_kind + +//! > ignored_kinds + +//! > expected_diagnostics + +//! > expected_tree +└── root (kind: SyntaxFile) + ├── items (kind: ModuleItemList) + │ └── child #0 (kind: ItemMacroDeclaration) + │ ├── attributes (kind: AttributeList) [] + │ ├── visibility (kind: VisibilityDefault) [] + │ ├── macro_kw (kind: TokenMacro): 'macro' + │ ├── name (kind: TokenIdentifier): 'macro_name' + │ ├── lbrace (kind: TokenLBrace): '{' + │ ├── rules (kind: MacroRulesList) + │ │ ├── child #0 (kind: MacroRule) + │ │ │ ├── lhs (kind: TokenTreeNode) + │ │ │ │ └── subtree (kind: ParenthesizedTokenTree) + │ │ │ │ ├── lparen (kind: TokenLParen): '(' + │ │ │ │ ├── tokens (kind: TokenList) [] + │ │ │ │ └── rparen (kind: TokenRParen): ')' + │ │ │ ├── fat_arrow (kind: TokenMatchArrow): '=>' + │ │ │ ├── rhs (kind: ExprBlock) + │ │ │ │ ├── lbrace (kind: TokenLBrace): '{' + │ │ │ │ ├── statements (kind: StatementList) + │ │ │ │ │ └── child #0 (kind: StatementExpr) + │ │ │ │ │ ├── attributes (kind: AttributeList) [] + │ │ │ │ │ ├── expr (kind: ExprBinary) + │ │ │ │ │ │ ├── lhs (kind: TokenLiteralNumber): '2' + │ │ │ │ │ │ ├── op (kind: TokenPlus): '+' + │ │ │ │ │ │ └── rhs (kind: ExprPlaceholder) + │ │ │ │ │ │ ├── dollar (kind: TokenDollar): '$' + │ │ │ │ │ │ └── name (kind: TokenIdentifier): 'placeholder' + │ │ │ │ │ └── semicolon (kind: OptionTerminalSemicolonEmpty) [] + │ │ │ │ └── rbrace (kind: TokenRBrace): '}' + │ │ │ └── semicolon (kind: TokenSemicolon): ';' + │ │ └── child #1 (kind: MacroRule) + │ │ ├── lhs (kind: TokenTreeNode) + │ │ │ └── subtree (kind: ParenthesizedTokenTree) + │ │ │ ├── lparen (kind: TokenLParen): '(' + │ │ │ ├── tokens (kind: TokenList) + │ │ │ │ ├── child #0 (kind: TokenTreeLeaf) + │ │ │ │ │ └── leaf (kind: TokenDollar): '$' + │ │ │ │ ├── child #1 (kind: TokenTreeLeaf) + │ │ │ │ │ └── leaf (kind: TokenIdentifier): 'x' + │ │ │ │ ├── child #2 (kind: TokenTreeLeaf) + │ │ │ │ │ └── leaf (kind: TokenColon): ':' + │ │ │ │ └── child #3 (kind: TokenTreeLeaf) + │ │ │ │ └── leaf (kind: TokenIdentifier): 'ident' + │ │ │ └── rparen (kind: TokenRParen): ')' + │ │ ├── fat_arrow (kind: TokenMatchArrow): '=>' + │ │ ├── rhs (kind: ExprBlock) + │ │ │ ├── lbrace (kind: TokenLBrace): '{' + │ │ │ ├── statements (kind: StatementList) + │ │ │ │ └── child #0 (kind: StatementExpr) + │ │ │ │ ├── attributes (kind: AttributeList) [] + │ │ │ │ ├── expr (kind: ExprBinary) + │ │ │ │ │ ├── lhs (kind: TokenLiteralNumber): '2' + │ │ │ │ │ ├── op (kind: TokenPlus): '+' + │ │ │ │ │ └── rhs (kind: ExprPlaceholder) + │ │ │ │ │ ├── dollar (kind: TokenDollar): '$' + │ │ │ │ │ └── name (kind: TokenIdentifier): 'x' + │ │ │ │ └── semicolon (kind: OptionTerminalSemicolonEmpty) [] + │ │ │ └── rbrace (kind: TokenRBrace): '}' + │ │ └── semicolon (kind: TokenSemicolon): ';' + │ └── rbrace (kind: TokenRBrace): '}' + └── eof (kind: TokenEndOfFile). + +//! > ========================================================================== + +//! > Test expr placeholder outside of macro definition + +//! > test_runner_name +test_partial_parser_tree(expect_diagnostics: true) + +//! > cairo_code +fn foo() { + 2 + $ placeholder +} + +//! > top_level_kind + +//! > ignored_kinds + +//! > expected_diagnostics +error: Missing tokens. Expected an expression. + --> dummy_file.cairo:2:8 + 2 + $ placeholder + ^ + +error: Skipped tokens. Expected: statement. + --> dummy_file.cairo:2:9 + 2 + $ placeholder + ^ + +//! > expected_tree +└── root (kind: SyntaxFile) + ├── items (kind: ModuleItemList) + │ └── child #0 (kind: FunctionWithBody) + │ ├── attributes (kind: AttributeList) [] + │ ├── visibility (kind: VisibilityDefault) [] + │ ├── declaration (kind: FunctionDeclaration) + │ │ ├── function_kw (kind: TokenFunction): 'fn' + │ │ ├── name (kind: TokenIdentifier): 'foo' + │ │ ├── generic_params (kind: OptionWrappedGenericParamListEmpty) [] + │ │ └── signature (kind: FunctionSignature) + │ │ ├── lparen (kind: TokenLParen): '(' + │ │ ├── parameters (kind: ParamList) [] + │ │ ├── rparen (kind: TokenRParen): ')' + │ │ ├── ret_ty (kind: OptionReturnTypeClauseEmpty) [] + │ │ ├── implicits_clause (kind: OptionImplicitsClauseEmpty) [] + │ │ └── optional_no_panic (kind: OptionTerminalNoPanicEmpty) [] + │ └── body (kind: ExprBlock) + │ ├── lbrace (kind: TokenLBrace): '{' + │ ├── statements (kind: StatementList) + │ │ ├── child #0 (kind: StatementExpr) + │ │ │ ├── attributes (kind: AttributeList) [] + │ │ │ ├── expr (kind: ExprBinary) + │ │ │ │ ├── lhs (kind: TokenLiteralNumber): '2' + │ │ │ │ ├── op (kind: TokenPlus): '+' + │ │ │ │ └── rhs: Missing [] + │ │ │ └── semicolon (kind: OptionTerminalSemicolonEmpty) [] + │ │ └── child #1 (kind: StatementExpr) + │ │ ├── attributes (kind: AttributeList) [] + │ │ ├── expr (kind: ExprPath) + │ │ │ └── item #0 (kind: PathSegmentSimple) + │ │ │ └── ident (kind: TokenIdentifier): 'placeholder' + │ │ └── semicolon (kind: OptionTerminalSemicolonEmpty) [] + │ └── rbrace (kind: TokenRBrace): '}' + └── eof (kind: TokenEndOfFile). diff --git a/crates/cairo-lang-parser/src/parser_test_data/partial_trees_with_trivia/attribute_errors b/crates/cairo-lang-parser/src/parser_test_data/partial_trees_with_trivia/attribute_errors index e5817467ac4..c1df9a4d550 100644 --- a/crates/cairo-lang-parser/src/parser_test_data/partial_trees_with_trivia/attribute_errors +++ b/crates/cairo-lang-parser/src/parser_test_data/partial_trees_with_trivia/attribute_errors @@ -1259,7 +1259,7 @@ test_partial_parser_tree_with_trivia(expect_diagnostics: *) //! > cairo_code // TODO(Gil): handle multiline diagnostics. #[bbb] -macro +a_macro //! > top_level_kind @@ -1306,7 +1306,7 @@ error: Skipped tokens. Expected: Const/Enum/ExternFunction/ExternType/Function/I │ │ │ └── trailing_trivia (kind: Trivia) [] │ │ ├── arguments (kind: OptionArgListParenthesizedEmpty) [] │ │ └── rbrack (kind: TerminalRBrack) - │ └── child #1 (kind: TokenSkipped): 'macro' + │ └── child #1 (kind: TokenSkipped): 'a_macro' ├── token (kind: TokenEndOfFile). └── trailing_trivia (kind: Trivia) [] @@ -1363,7 +1363,7 @@ pub // trailing. test_partial_parser_tree_with_trivia(expect_diagnostics: *) //! > cairo_code -pub macro +pub a_macro //! > top_level_kind @@ -1379,8 +1379,8 @@ TerminalSemicolon //! > expected_diagnostics error: Skipped tokens. Expected: Const/Enum/ExternFunction/ExternType/Function/Impl/InlineMacro/Module/Struct/Trait/TypeAlias/Use or an attribute. --> dummy_file.cairo:1:4 -pub macro - ^****^ +pub a_macro + ^******^ //! > expected_tree └── root (kind: SyntaxFile) @@ -1395,7 +1395,7 @@ pub macro │ │ │ └── trailing_trivia (kind: Trivia) │ │ │ └── child #0 (kind: TokenWhitespace). │ │ └── argument_clause (kind: OptionVisibilityPubArgumentClauseEmpty) [] - │ └── child #1 (kind: TokenSkipped): 'macro' + │ └── child #1 (kind: TokenSkipped): 'a_macro' ├── token (kind: TokenEndOfFile). └── trailing_trivia (kind: Trivia) [] @@ -1473,7 +1473,7 @@ test_partial_parser_tree_with_trivia(expect_diagnostics: *) //! > cairo_code #[attr] -pub macro +pub a_macro //! > top_level_kind @@ -1521,6 +1521,6 @@ error: Skipped tokens. Expected: Const/Enum/ExternFunction/ExternType/Function/I │ │ │ └── trailing_trivia (kind: Trivia) │ │ │ └── child #0 (kind: TokenWhitespace). │ │ └── argument_clause (kind: OptionVisibilityPubArgumentClauseEmpty) [] - │ └── child #2 (kind: TokenSkipped): 'macro' + │ └── child #2 (kind: TokenSkipped): 'a_macro' ├── token (kind: TokenEndOfFile). └── trailing_trivia (kind: Trivia) [] diff --git a/crates/cairo-lang-semantic/src/expr/compute.rs b/crates/cairo-lang-semantic/src/expr/compute.rs index 424428e6e5d..3ac7425d65c 100644 --- a/crates/cairo-lang-semantic/src/expr/compute.rs +++ b/crates/cairo-lang-semantic/src/expr/compute.rs @@ -424,6 +424,7 @@ pub fn maybe_compute_expr_semantic( ast::Expr::FixedSizeArray(expr) => compute_expr_fixed_size_array_semantic(ctx, expr), ast::Expr::For(expr) => compute_expr_for_semantic(ctx, expr), ast::Expr::Closure(expr) => compute_expr_closure_semantic(ctx, expr), + ast::Expr::Placeholder(_) => todo!(), } } @@ -3669,6 +3670,7 @@ pub fn compute_statement_semantic( ast::ModuleItem::InlineMacro(_) => unreachable!("InlineMacro type not supported."), ast::ModuleItem::HeaderDoc(_) => unreachable!("HeaderDoc type not supported."), ast::ModuleItem::Missing(_) => unreachable!("Missing type not supported."), + ast::ModuleItem::MacroDeclaration(_) => todo!(), } semantic::Statement::Item(semantic::StatementItem { stable_ptr: syntax.stable_ptr() }) } diff --git a/crates/cairo-lang-starknet/src/plugin/starknet_module/mod.rs b/crates/cairo-lang-starknet/src/plugin/starknet_module/mod.rs index 97f8f2e0273..a33c0f5e9a8 100644 --- a/crates/cairo-lang-starknet/src/plugin/starknet_module/mod.rs +++ b/crates/cairo-lang-starknet/src/plugin/starknet_module/mod.rs @@ -279,6 +279,7 @@ fn maybe_add_extra_use( | ast::ModuleItem::Missing(_) | ast::ModuleItem::InlineMacro(_) | ast::ModuleItem::HeaderDoc(_) => None, + ast::ModuleItem::MacroDeclaration(_) => todo!(), } { extra_uses.entry(ident.text(db)).or_insert_with_key(|ident| format!("super::{}", ident)); } diff --git a/crates/cairo-lang-syntax-codegen/src/cairo_spec.rs b/crates/cairo-lang-syntax-codegen/src/cairo_spec.rs index 7ecb667d07f..87bfc3cce3c 100644 --- a/crates/cairo-lang-syntax-codegen/src/cairo_spec.rs +++ b/crates/cairo-lang-syntax-codegen/src/cairo_spec.rs @@ -41,6 +41,7 @@ pub fn get_spec() -> Vec { .node("Indexed") .node("InlineMacro") .node("FixedSizeArray") + .node("Placeholder") ) .add_separated_list("ExprList", "Expr", "TerminalComma") .add_struct(StructBuilder::new("Arg") @@ -243,6 +244,10 @@ pub fn get_spec() -> Vec { .node("params", "ParamList") .node("rightor", "TerminalOr") ) + .add_struct(StructBuilder::new("ExprPlaceholder") + .node("dollar", "TerminalDollar") + .node("name", "TerminalIdentifier") + ) // --- Struct ctor --- .add_struct(StructBuilder::new("StructArgExpr") .node("colon", "TerminalColon") @@ -461,6 +466,7 @@ pub fn get_spec() -> Vec { .node_with_explicit_kind("Enum", "ItemEnum") .node_with_explicit_kind("TypeAlias", "ItemTypeAlias") .node_with_explicit_kind("InlineMacro", "ItemInlineMacro") + .node_with_explicit_kind("MacroDeclaration", "ItemMacroDeclaration") .node_with_explicit_kind("HeaderDoc", "ItemHeaderDoc") ) .add_list("ModuleItemList", "ModuleItem") @@ -834,6 +840,22 @@ pub fn get_spec() -> Vec { .node("bang", "TerminalNot") .node("arguments", "TokenTreeNode") .node("semicolon", "TerminalSemicolon")) + .add_struct(StructBuilder::new("ItemMacroDeclaration") + .node("attributes" ,"AttributeList") + .node("visibility", "Visibility") + .node("macro_kw", "TerminalMacro") + .key_node("name", "TerminalIdentifier") + .node("lbrace", "TerminalLBrace") + .node("rules", "MacroRulesList") + .node("rbrace", "TerminalRBrace") + ) + .add_list("MacroRulesList", "MacroRule") + .add_struct(StructBuilder::new("MacroRule") + .node("lhs", "TokenTreeNode") + .node("fat_arrow", "TerminalMatchArrow") + .node("rhs", "ExprBlock") + .node("semicolon", "TerminalSemicolon") + ) // TODO .add_struct(StructBuilder::new("LegacyExprInlineMacro") .node("path", "ExprPath") @@ -875,6 +897,7 @@ pub fn get_spec() -> Vec { .add_keyword_token_and_terminal("Impl") .add_keyword_token_and_terminal("Implicits") .add_keyword_token_and_terminal("Let") + .add_keyword_token_and_terminal("Macro") .add_keyword_token_and_terminal("Match") .add_keyword_token_and_terminal("Module") .add_keyword_token_and_terminal("Mut") @@ -900,6 +923,7 @@ pub fn get_spec() -> Vec { .add_token_and_terminal("Comma") .add_token_and_terminal("Div") .add_token_and_terminal("DivEq") + .add_token_and_terminal("Dollar") .add_token_and_terminal("Dot") .add_token_and_terminal("DotDot") .add_token_and_terminal("EndOfFile") diff --git a/crates/cairo-lang-syntax/src/node/ast.rs b/crates/cairo-lang-syntax/src/node/ast.rs index d1cdf0ca3d4..4166afb86a9 100644 --- a/crates/cairo-lang-syntax/src/node/ast.rs +++ b/crates/cairo-lang-syntax/src/node/ast.rs @@ -277,6 +277,7 @@ pub enum Expr { Indexed(ExprIndexed), InlineMacro(ExprInlineMacro), FixedSizeArray(ExprFixedSizeArray), + Placeholder(ExprPlaceholder), Missing(ExprMissing), } #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] @@ -415,6 +416,11 @@ impl From for ExprPtr { Self(value.0) } } +impl From for ExprPtr { + fn from(value: ExprPlaceholderPtr) -> Self { + Self(value.0) + } +} impl From for ExprPtr { fn from(value: ExprMissingPtr) -> Self { Self(value.0) @@ -540,6 +546,11 @@ impl From for ExprGreen { Self(value.0) } } +impl From for ExprGreen { + fn from(value: ExprPlaceholderGreen) -> Self { + Self(value.0) + } +} impl From for ExprGreen { fn from(value: ExprMissingGreen) -> Self { Self(value.0) @@ -601,6 +612,9 @@ impl TypedSyntaxNode for Expr { SyntaxKind::ExprFixedSizeArray => { Expr::FixedSizeArray(ExprFixedSizeArray::from_syntax_node(db, node)) } + SyntaxKind::ExprPlaceholder => { + Expr::Placeholder(ExprPlaceholder::from_syntax_node(db, node)) + } SyntaxKind::ExprMissing => Expr::Missing(ExprMissing::from_syntax_node(db, node)), _ => panic!("Unexpected syntax kind {:?} when constructing {}.", kind, "Expr"), } @@ -631,6 +645,7 @@ impl TypedSyntaxNode for Expr { Expr::Indexed(x) => x.as_syntax_node(), Expr::InlineMacro(x) => x.as_syntax_node(), Expr::FixedSizeArray(x) => x.as_syntax_node(), + Expr::Placeholder(x) => x.as_syntax_node(), Expr::Missing(x) => x.as_syntax_node(), } } @@ -672,6 +687,7 @@ impl Expr { | SyntaxKind::ExprIndexed | SyntaxKind::ExprInlineMacro | SyntaxKind::ExprFixedSizeArray + | SyntaxKind::ExprPlaceholder | SyntaxKind::ExprMissing ) } @@ -5800,6 +5816,100 @@ impl From<&ClosureParamWrapperNAry> for SyntaxStablePtrId { } } #[derive(Clone, Debug, Eq, Hash, PartialEq)] +pub struct ExprPlaceholder { + node: SyntaxNode, + children: Arc<[SyntaxNode]>, +} +impl ExprPlaceholder { + pub const INDEX_DOLLAR: usize = 0; + pub const INDEX_NAME: usize = 1; + pub fn new_green( + db: &dyn SyntaxGroup, + dollar: TerminalDollarGreen, + name: TerminalIdentifierGreen, + ) -> ExprPlaceholderGreen { + let children: Vec = vec![dollar.0, name.0]; + let width = children.iter().copied().map(|id| id.lookup_intern(db).width()).sum(); + ExprPlaceholderGreen( + Arc::new(GreenNode { + kind: SyntaxKind::ExprPlaceholder, + details: GreenNodeDetails::Node { children, width }, + }) + .intern(db), + ) + } +} +impl ExprPlaceholder { + pub fn dollar(&self, db: &dyn SyntaxGroup) -> TerminalDollar { + TerminalDollar::from_syntax_node(db, self.children[0].clone()) + } + pub fn name(&self, db: &dyn SyntaxGroup) -> TerminalIdentifier { + TerminalIdentifier::from_syntax_node(db, self.children[1].clone()) + } +} +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +pub struct ExprPlaceholderPtr(pub SyntaxStablePtrId); +impl ExprPlaceholderPtr {} +impl TypedStablePtr for ExprPlaceholderPtr { + type SyntaxNode = ExprPlaceholder; + fn untyped(&self) -> SyntaxStablePtrId { + self.0 + } + fn lookup(&self, db: &dyn SyntaxGroup) -> ExprPlaceholder { + ExprPlaceholder::from_syntax_node(db, self.0.lookup(db)) + } +} +impl From for SyntaxStablePtrId { + fn from(ptr: ExprPlaceholderPtr) -> Self { + ptr.untyped() + } +} +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +pub struct ExprPlaceholderGreen(pub GreenId); +impl TypedSyntaxNode for ExprPlaceholder { + const OPTIONAL_KIND: Option = Some(SyntaxKind::ExprPlaceholder); + type StablePtr = ExprPlaceholderPtr; + type Green = ExprPlaceholderGreen; + fn missing(db: &dyn SyntaxGroup) -> Self::Green { + ExprPlaceholderGreen( + Arc::new(GreenNode { + kind: SyntaxKind::ExprPlaceholder, + details: GreenNodeDetails::Node { + children: vec![ + TerminalDollar::missing(db).0, + TerminalIdentifier::missing(db).0, + ], + width: TextWidth::default(), + }, + }) + .intern(db), + ) + } + fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { + let kind = node.kind(db); + assert_eq!( + kind, + SyntaxKind::ExprPlaceholder, + "Unexpected SyntaxKind {:?}. Expected {:?}.", + kind, + SyntaxKind::ExprPlaceholder + ); + let children = db.get_children(node.clone()); + Self { node, children } + } + fn as_syntax_node(&self) -> SyntaxNode { + self.node.clone() + } + fn stable_ptr(&self) -> Self::StablePtr { + ExprPlaceholderPtr(self.node.0.stable_ptr) + } +} +impl From<&ExprPlaceholder> for SyntaxStablePtrId { + fn from(node: &ExprPlaceholder) -> Self { + node.stable_ptr().untyped() + } +} +#[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct StructArgExpr { node: SyntaxNode, children: Arc<[SyntaxNode]>, @@ -11589,6 +11699,7 @@ pub enum ModuleItem { Enum(ItemEnum), TypeAlias(ItemTypeAlias), InlineMacro(ItemInlineMacro), + MacroDeclaration(ItemMacroDeclaration), HeaderDoc(ItemHeaderDoc), Missing(ModuleItemMissing), } @@ -11673,6 +11784,11 @@ impl From for ModuleItemPtr { Self(value.0) } } +impl From for ModuleItemPtr { + fn from(value: ItemMacroDeclarationPtr) -> Self { + Self(value.0) + } +} impl From for ModuleItemPtr { fn from(value: ItemHeaderDocPtr) -> Self { Self(value.0) @@ -11748,6 +11864,11 @@ impl From for ModuleItemGreen { Self(value.0) } } +impl From for ModuleItemGreen { + fn from(value: ItemMacroDeclarationGreen) -> Self { + Self(value.0) + } +} impl From for ModuleItemGreen { fn from(value: ItemHeaderDocGreen) -> Self { Self(value.0) @@ -11797,6 +11918,9 @@ impl TypedSyntaxNode for ModuleItem { SyntaxKind::ItemInlineMacro => { ModuleItem::InlineMacro(ItemInlineMacro::from_syntax_node(db, node)) } + SyntaxKind::ItemMacroDeclaration => { + ModuleItem::MacroDeclaration(ItemMacroDeclaration::from_syntax_node(db, node)) + } SyntaxKind::ItemHeaderDoc => { ModuleItem::HeaderDoc(ItemHeaderDoc::from_syntax_node(db, node)) } @@ -11821,6 +11945,7 @@ impl TypedSyntaxNode for ModuleItem { ModuleItem::Enum(x) => x.as_syntax_node(), ModuleItem::TypeAlias(x) => x.as_syntax_node(), ModuleItem::InlineMacro(x) => x.as_syntax_node(), + ModuleItem::MacroDeclaration(x) => x.as_syntax_node(), ModuleItem::HeaderDoc(x) => x.as_syntax_node(), ModuleItem::Missing(x) => x.as_syntax_node(), } @@ -11852,6 +11977,7 @@ impl ModuleItem { | SyntaxKind::ItemEnum | SyntaxKind::ItemTypeAlias | SyntaxKind::ItemInlineMacro + | SyntaxKind::ItemMacroDeclaration | SyntaxKind::ItemHeaderDoc | SyntaxKind::ModuleItemMissing ) @@ -19812,6 +19938,315 @@ impl From<&ItemInlineMacro> for SyntaxStablePtrId { } } #[derive(Clone, Debug, Eq, Hash, PartialEq)] +pub struct ItemMacroDeclaration { + node: SyntaxNode, + children: Arc<[SyntaxNode]>, +} +impl ItemMacroDeclaration { + pub const INDEX_ATTRIBUTES: usize = 0; + pub const INDEX_VISIBILITY: usize = 1; + pub const INDEX_MACRO_KW: usize = 2; + pub const INDEX_NAME: usize = 3; + pub const INDEX_LBRACE: usize = 4; + pub const INDEX_RULES: usize = 5; + pub const INDEX_RBRACE: usize = 6; + pub fn new_green( + db: &dyn SyntaxGroup, + attributes: AttributeListGreen, + visibility: VisibilityGreen, + macro_kw: TerminalMacroGreen, + name: TerminalIdentifierGreen, + lbrace: TerminalLBraceGreen, + rules: MacroRulesListGreen, + rbrace: TerminalRBraceGreen, + ) -> ItemMacroDeclarationGreen { + let children: Vec = + vec![attributes.0, visibility.0, macro_kw.0, name.0, lbrace.0, rules.0, rbrace.0]; + let width = children.iter().copied().map(|id| id.lookup_intern(db).width()).sum(); + ItemMacroDeclarationGreen( + Arc::new(GreenNode { + kind: SyntaxKind::ItemMacroDeclaration, + details: GreenNodeDetails::Node { children, width }, + }) + .intern(db), + ) + } +} +impl ItemMacroDeclaration { + pub fn attributes(&self, db: &dyn SyntaxGroup) -> AttributeList { + AttributeList::from_syntax_node(db, self.children[0].clone()) + } + pub fn visibility(&self, db: &dyn SyntaxGroup) -> Visibility { + Visibility::from_syntax_node(db, self.children[1].clone()) + } + pub fn macro_kw(&self, db: &dyn SyntaxGroup) -> TerminalMacro { + TerminalMacro::from_syntax_node(db, self.children[2].clone()) + } + pub fn name(&self, db: &dyn SyntaxGroup) -> TerminalIdentifier { + TerminalIdentifier::from_syntax_node(db, self.children[3].clone()) + } + pub fn lbrace(&self, db: &dyn SyntaxGroup) -> TerminalLBrace { + TerminalLBrace::from_syntax_node(db, self.children[4].clone()) + } + pub fn rules(&self, db: &dyn SyntaxGroup) -> MacroRulesList { + MacroRulesList::from_syntax_node(db, self.children[5].clone()) + } + pub fn rbrace(&self, db: &dyn SyntaxGroup) -> TerminalRBrace { + TerminalRBrace::from_syntax_node(db, self.children[6].clone()) + } +} +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +pub struct ItemMacroDeclarationPtr(pub SyntaxStablePtrId); +impl ItemMacroDeclarationPtr { + pub fn name_green(self, db: &dyn SyntaxGroup) -> TerminalIdentifierGreen { + let ptr = self.0.lookup_intern(db); + if let SyntaxStablePtr::Child { key_fields, .. } = ptr { + TerminalIdentifierGreen(key_fields[0]) + } else { + panic!("Unexpected key field query on root."); + } + } +} +impl TypedStablePtr for ItemMacroDeclarationPtr { + type SyntaxNode = ItemMacroDeclaration; + fn untyped(&self) -> SyntaxStablePtrId { + self.0 + } + fn lookup(&self, db: &dyn SyntaxGroup) -> ItemMacroDeclaration { + ItemMacroDeclaration::from_syntax_node(db, self.0.lookup(db)) + } +} +impl From for SyntaxStablePtrId { + fn from(ptr: ItemMacroDeclarationPtr) -> Self { + ptr.untyped() + } +} +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +pub struct ItemMacroDeclarationGreen(pub GreenId); +impl TypedSyntaxNode for ItemMacroDeclaration { + const OPTIONAL_KIND: Option = Some(SyntaxKind::ItemMacroDeclaration); + type StablePtr = ItemMacroDeclarationPtr; + type Green = ItemMacroDeclarationGreen; + fn missing(db: &dyn SyntaxGroup) -> Self::Green { + ItemMacroDeclarationGreen( + Arc::new(GreenNode { + kind: SyntaxKind::ItemMacroDeclaration, + details: GreenNodeDetails::Node { + children: vec![ + AttributeList::missing(db).0, + Visibility::missing(db).0, + TerminalMacro::missing(db).0, + TerminalIdentifier::missing(db).0, + TerminalLBrace::missing(db).0, + MacroRulesList::missing(db).0, + TerminalRBrace::missing(db).0, + ], + width: TextWidth::default(), + }, + }) + .intern(db), + ) + } + fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { + let kind = node.kind(db); + assert_eq!( + kind, + SyntaxKind::ItemMacroDeclaration, + "Unexpected SyntaxKind {:?}. Expected {:?}.", + kind, + SyntaxKind::ItemMacroDeclaration + ); + let children = db.get_children(node.clone()); + Self { node, children } + } + fn as_syntax_node(&self) -> SyntaxNode { + self.node.clone() + } + fn stable_ptr(&self) -> Self::StablePtr { + ItemMacroDeclarationPtr(self.node.0.stable_ptr) + } +} +impl From<&ItemMacroDeclaration> for SyntaxStablePtrId { + fn from(node: &ItemMacroDeclaration) -> Self { + node.stable_ptr().untyped() + } +} +#[derive(Clone, Debug, Eq, Hash, PartialEq)] +pub struct MacroRulesList(ElementList); +impl Deref for MacroRulesList { + type Target = ElementList; + fn deref(&self) -> &Self::Target { + &self.0 + } +} +impl MacroRulesList { + pub fn new_green(db: &dyn SyntaxGroup, children: Vec) -> MacroRulesListGreen { + let width = children.iter().map(|id| id.0.lookup_intern(db).width()).sum(); + MacroRulesListGreen( + Arc::new(GreenNode { + kind: SyntaxKind::MacroRulesList, + details: GreenNodeDetails::Node { + children: children.iter().map(|x| x.0).collect(), + width, + }, + }) + .intern(db), + ) + } +} +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +pub struct MacroRulesListPtr(pub SyntaxStablePtrId); +impl TypedStablePtr for MacroRulesListPtr { + type SyntaxNode = MacroRulesList; + fn untyped(&self) -> SyntaxStablePtrId { + self.0 + } + fn lookup(&self, db: &dyn SyntaxGroup) -> MacroRulesList { + MacroRulesList::from_syntax_node(db, self.0.lookup(db)) + } +} +impl From for SyntaxStablePtrId { + fn from(ptr: MacroRulesListPtr) -> Self { + ptr.untyped() + } +} +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +pub struct MacroRulesListGreen(pub GreenId); +impl TypedSyntaxNode for MacroRulesList { + const OPTIONAL_KIND: Option = Some(SyntaxKind::MacroRulesList); + type StablePtr = MacroRulesListPtr; + type Green = MacroRulesListGreen; + fn missing(db: &dyn SyntaxGroup) -> Self::Green { + MacroRulesListGreen( + Arc::new(GreenNode { + kind: SyntaxKind::MacroRulesList, + details: GreenNodeDetails::Node { children: vec![], width: TextWidth::default() }, + }) + .intern(db), + ) + } + fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { + Self(ElementList::new(node)) + } + fn as_syntax_node(&self) -> SyntaxNode { + self.node.clone() + } + fn stable_ptr(&self) -> Self::StablePtr { + MacroRulesListPtr(self.node.0.stable_ptr) + } +} +impl From<&MacroRulesList> for SyntaxStablePtrId { + fn from(node: &MacroRulesList) -> Self { + node.stable_ptr().untyped() + } +} +#[derive(Clone, Debug, Eq, Hash, PartialEq)] +pub struct MacroRule { + node: SyntaxNode, + children: Arc<[SyntaxNode]>, +} +impl MacroRule { + pub const INDEX_LHS: usize = 0; + pub const INDEX_FAT_ARROW: usize = 1; + pub const INDEX_RHS: usize = 2; + pub const INDEX_SEMICOLON: usize = 3; + pub fn new_green( + db: &dyn SyntaxGroup, + lhs: TokenTreeNodeGreen, + fat_arrow: TerminalMatchArrowGreen, + rhs: ExprBlockGreen, + semicolon: TerminalSemicolonGreen, + ) -> MacroRuleGreen { + let children: Vec = vec![lhs.0, fat_arrow.0, rhs.0, semicolon.0]; + let width = children.iter().copied().map(|id| id.lookup_intern(db).width()).sum(); + MacroRuleGreen( + Arc::new(GreenNode { + kind: SyntaxKind::MacroRule, + details: GreenNodeDetails::Node { children, width }, + }) + .intern(db), + ) + } +} +impl MacroRule { + pub fn lhs(&self, db: &dyn SyntaxGroup) -> TokenTreeNode { + TokenTreeNode::from_syntax_node(db, self.children[0].clone()) + } + pub fn fat_arrow(&self, db: &dyn SyntaxGroup) -> TerminalMatchArrow { + TerminalMatchArrow::from_syntax_node(db, self.children[1].clone()) + } + pub fn rhs(&self, db: &dyn SyntaxGroup) -> ExprBlock { + ExprBlock::from_syntax_node(db, self.children[2].clone()) + } + pub fn semicolon(&self, db: &dyn SyntaxGroup) -> TerminalSemicolon { + TerminalSemicolon::from_syntax_node(db, self.children[3].clone()) + } +} +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +pub struct MacroRulePtr(pub SyntaxStablePtrId); +impl MacroRulePtr {} +impl TypedStablePtr for MacroRulePtr { + type SyntaxNode = MacroRule; + fn untyped(&self) -> SyntaxStablePtrId { + self.0 + } + fn lookup(&self, db: &dyn SyntaxGroup) -> MacroRule { + MacroRule::from_syntax_node(db, self.0.lookup(db)) + } +} +impl From for SyntaxStablePtrId { + fn from(ptr: MacroRulePtr) -> Self { + ptr.untyped() + } +} +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +pub struct MacroRuleGreen(pub GreenId); +impl TypedSyntaxNode for MacroRule { + const OPTIONAL_KIND: Option = Some(SyntaxKind::MacroRule); + type StablePtr = MacroRulePtr; + type Green = MacroRuleGreen; + fn missing(db: &dyn SyntaxGroup) -> Self::Green { + MacroRuleGreen( + Arc::new(GreenNode { + kind: SyntaxKind::MacroRule, + details: GreenNodeDetails::Node { + children: vec![ + TokenTreeNode::missing(db).0, + TerminalMatchArrow::missing(db).0, + ExprBlock::missing(db).0, + TerminalSemicolon::missing(db).0, + ], + width: TextWidth::default(), + }, + }) + .intern(db), + ) + } + fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { + let kind = node.kind(db); + assert_eq!( + kind, + SyntaxKind::MacroRule, + "Unexpected SyntaxKind {:?}. Expected {:?}.", + kind, + SyntaxKind::MacroRule + ); + let children = db.get_children(node.clone()); + Self { node, children } + } + fn as_syntax_node(&self) -> SyntaxNode { + self.node.clone() + } + fn stable_ptr(&self) -> Self::StablePtr { + MacroRulePtr(self.node.0.stable_ptr) + } +} +impl From<&MacroRule> for SyntaxStablePtrId { + fn from(node: &MacroRule) -> Self { + node.stable_ptr().untyped() + } +} +#[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct LegacyExprInlineMacro { node: SyntaxNode, children: Arc<[SyntaxNode]>, @@ -23377,6 +23812,183 @@ impl From<&TerminalLet> for SyntaxStablePtrId { } } #[derive(Clone, Debug, Eq, Hash, PartialEq)] +pub struct TokenMacro { + node: SyntaxNode, +} +impl Token for TokenMacro { + fn new_green(db: &dyn SyntaxGroup, text: SmolStr) -> Self::Green { + TokenMacroGreen( + Arc::new(GreenNode { + kind: SyntaxKind::TokenMacro, + details: GreenNodeDetails::Token(text), + }) + .intern(db), + ) + } + fn text(&self, db: &dyn SyntaxGroup) -> SmolStr { + extract_matches!(&self.node.0.green.lookup_intern(db).details, GreenNodeDetails::Token) + .clone() + } +} +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +pub struct TokenMacroPtr(pub SyntaxStablePtrId); +impl TypedStablePtr for TokenMacroPtr { + type SyntaxNode = TokenMacro; + fn untyped(&self) -> SyntaxStablePtrId { + self.0 + } + fn lookup(&self, db: &dyn SyntaxGroup) -> TokenMacro { + TokenMacro::from_syntax_node(db, self.0.lookup(db)) + } +} +impl From for SyntaxStablePtrId { + fn from(ptr: TokenMacroPtr) -> Self { + ptr.untyped() + } +} +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +pub struct TokenMacroGreen(pub GreenId); +impl TokenMacroGreen { + pub fn text(&self, db: &dyn SyntaxGroup) -> SmolStr { + extract_matches!(&self.0.lookup_intern(db).details, GreenNodeDetails::Token).clone() + } +} +impl TypedSyntaxNode for TokenMacro { + const OPTIONAL_KIND: Option = Some(SyntaxKind::TokenMacro); + type StablePtr = TokenMacroPtr; + type Green = TokenMacroGreen; + fn missing(db: &dyn SyntaxGroup) -> Self::Green { + TokenMacroGreen( + Arc::new(GreenNode { + kind: SyntaxKind::TokenMissing, + details: GreenNodeDetails::Token("".into()), + }) + .intern(db), + ) + } + fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Self { node }, + GreenNodeDetails::Node { .. } => { + panic!("Expected a token {:?}, not an internal node", SyntaxKind::TokenMacro) + } + } + } + fn as_syntax_node(&self) -> SyntaxNode { + self.node.clone() + } + fn stable_ptr(&self) -> Self::StablePtr { + TokenMacroPtr(self.node.0.stable_ptr) + } +} +impl From<&TokenMacro> for SyntaxStablePtrId { + fn from(node: &TokenMacro) -> Self { + node.stable_ptr().untyped() + } +} +#[derive(Clone, Debug, Eq, Hash, PartialEq)] +pub struct TerminalMacro { + node: SyntaxNode, + children: Arc<[SyntaxNode]>, +} +impl Terminal for TerminalMacro { + const KIND: SyntaxKind = SyntaxKind::TerminalMacro; + type TokenType = TokenMacro; + fn new_green( + db: &dyn SyntaxGroup, + leading_trivia: TriviaGreen, + token: <::TokenType as TypedSyntaxNode>::Green, + trailing_trivia: TriviaGreen, + ) -> Self::Green { + let children: Vec = vec![leading_trivia.0, token.0, trailing_trivia.0]; + let width = children.iter().copied().map(|id| id.lookup_intern(db).width()).sum(); + TerminalMacroGreen( + Arc::new(GreenNode { + kind: SyntaxKind::TerminalMacro, + details: GreenNodeDetails::Node { children, width }, + }) + .intern(db), + ) + } + fn text(&self, db: &dyn SyntaxGroup) -> SmolStr { + self.token(db).text(db) + } +} +impl TerminalMacro { + pub fn leading_trivia(&self, db: &dyn SyntaxGroup) -> Trivia { + Trivia::from_syntax_node(db, self.children[0].clone()) + } + pub fn token(&self, db: &dyn SyntaxGroup) -> TokenMacro { + TokenMacro::from_syntax_node(db, self.children[1].clone()) + } + pub fn trailing_trivia(&self, db: &dyn SyntaxGroup) -> Trivia { + Trivia::from_syntax_node(db, self.children[2].clone()) + } +} +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +pub struct TerminalMacroPtr(pub SyntaxStablePtrId); +impl TerminalMacroPtr {} +impl TypedStablePtr for TerminalMacroPtr { + type SyntaxNode = TerminalMacro; + fn untyped(&self) -> SyntaxStablePtrId { + self.0 + } + fn lookup(&self, db: &dyn SyntaxGroup) -> TerminalMacro { + TerminalMacro::from_syntax_node(db, self.0.lookup(db)) + } +} +impl From for SyntaxStablePtrId { + fn from(ptr: TerminalMacroPtr) -> Self { + ptr.untyped() + } +} +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +pub struct TerminalMacroGreen(pub GreenId); +impl TypedSyntaxNode for TerminalMacro { + const OPTIONAL_KIND: Option = Some(SyntaxKind::TerminalMacro); + type StablePtr = TerminalMacroPtr; + type Green = TerminalMacroGreen; + fn missing(db: &dyn SyntaxGroup) -> Self::Green { + TerminalMacroGreen( + Arc::new(GreenNode { + kind: SyntaxKind::TerminalMacro, + details: GreenNodeDetails::Node { + children: vec![ + Trivia::missing(db).0, + TokenMacro::missing(db).0, + Trivia::missing(db).0, + ], + width: TextWidth::default(), + }, + }) + .intern(db), + ) + } + fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { + let kind = node.kind(db); + assert_eq!( + kind, + SyntaxKind::TerminalMacro, + "Unexpected SyntaxKind {:?}. Expected {:?}.", + kind, + SyntaxKind::TerminalMacro + ); + let children = db.get_children(node.clone()); + Self { node, children } + } + fn as_syntax_node(&self) -> SyntaxNode { + self.node.clone() + } + fn stable_ptr(&self) -> Self::StablePtr { + TerminalMacroPtr(self.node.0.stable_ptr) + } +} +impl From<&TerminalMacro> for SyntaxStablePtrId { + fn from(node: &TerminalMacro) -> Self { + node.stable_ptr().untyped() + } +} +#[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct TokenMatch { node: SyntaxNode, } @@ -27803,6 +28415,183 @@ impl From<&TerminalDivEq> for SyntaxStablePtrId { } } #[derive(Clone, Debug, Eq, Hash, PartialEq)] +pub struct TokenDollar { + node: SyntaxNode, +} +impl Token for TokenDollar { + fn new_green(db: &dyn SyntaxGroup, text: SmolStr) -> Self::Green { + TokenDollarGreen( + Arc::new(GreenNode { + kind: SyntaxKind::TokenDollar, + details: GreenNodeDetails::Token(text), + }) + .intern(db), + ) + } + fn text(&self, db: &dyn SyntaxGroup) -> SmolStr { + extract_matches!(&self.node.0.green.lookup_intern(db).details, GreenNodeDetails::Token) + .clone() + } +} +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +pub struct TokenDollarPtr(pub SyntaxStablePtrId); +impl TypedStablePtr for TokenDollarPtr { + type SyntaxNode = TokenDollar; + fn untyped(&self) -> SyntaxStablePtrId { + self.0 + } + fn lookup(&self, db: &dyn SyntaxGroup) -> TokenDollar { + TokenDollar::from_syntax_node(db, self.0.lookup(db)) + } +} +impl From for SyntaxStablePtrId { + fn from(ptr: TokenDollarPtr) -> Self { + ptr.untyped() + } +} +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +pub struct TokenDollarGreen(pub GreenId); +impl TokenDollarGreen { + pub fn text(&self, db: &dyn SyntaxGroup) -> SmolStr { + extract_matches!(&self.0.lookup_intern(db).details, GreenNodeDetails::Token).clone() + } +} +impl TypedSyntaxNode for TokenDollar { + const OPTIONAL_KIND: Option = Some(SyntaxKind::TokenDollar); + type StablePtr = TokenDollarPtr; + type Green = TokenDollarGreen; + fn missing(db: &dyn SyntaxGroup) -> Self::Green { + TokenDollarGreen( + Arc::new(GreenNode { + kind: SyntaxKind::TokenMissing, + details: GreenNodeDetails::Token("".into()), + }) + .intern(db), + ) + } + fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Self { node }, + GreenNodeDetails::Node { .. } => { + panic!("Expected a token {:?}, not an internal node", SyntaxKind::TokenDollar) + } + } + } + fn as_syntax_node(&self) -> SyntaxNode { + self.node.clone() + } + fn stable_ptr(&self) -> Self::StablePtr { + TokenDollarPtr(self.node.0.stable_ptr) + } +} +impl From<&TokenDollar> for SyntaxStablePtrId { + fn from(node: &TokenDollar) -> Self { + node.stable_ptr().untyped() + } +} +#[derive(Clone, Debug, Eq, Hash, PartialEq)] +pub struct TerminalDollar { + node: SyntaxNode, + children: Arc<[SyntaxNode]>, +} +impl Terminal for TerminalDollar { + const KIND: SyntaxKind = SyntaxKind::TerminalDollar; + type TokenType = TokenDollar; + fn new_green( + db: &dyn SyntaxGroup, + leading_trivia: TriviaGreen, + token: <::TokenType as TypedSyntaxNode>::Green, + trailing_trivia: TriviaGreen, + ) -> Self::Green { + let children: Vec = vec![leading_trivia.0, token.0, trailing_trivia.0]; + let width = children.iter().copied().map(|id| id.lookup_intern(db).width()).sum(); + TerminalDollarGreen( + Arc::new(GreenNode { + kind: SyntaxKind::TerminalDollar, + details: GreenNodeDetails::Node { children, width }, + }) + .intern(db), + ) + } + fn text(&self, db: &dyn SyntaxGroup) -> SmolStr { + self.token(db).text(db) + } +} +impl TerminalDollar { + pub fn leading_trivia(&self, db: &dyn SyntaxGroup) -> Trivia { + Trivia::from_syntax_node(db, self.children[0].clone()) + } + pub fn token(&self, db: &dyn SyntaxGroup) -> TokenDollar { + TokenDollar::from_syntax_node(db, self.children[1].clone()) + } + pub fn trailing_trivia(&self, db: &dyn SyntaxGroup) -> Trivia { + Trivia::from_syntax_node(db, self.children[2].clone()) + } +} +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +pub struct TerminalDollarPtr(pub SyntaxStablePtrId); +impl TerminalDollarPtr {} +impl TypedStablePtr for TerminalDollarPtr { + type SyntaxNode = TerminalDollar; + fn untyped(&self) -> SyntaxStablePtrId { + self.0 + } + fn lookup(&self, db: &dyn SyntaxGroup) -> TerminalDollar { + TerminalDollar::from_syntax_node(db, self.0.lookup(db)) + } +} +impl From for SyntaxStablePtrId { + fn from(ptr: TerminalDollarPtr) -> Self { + ptr.untyped() + } +} +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +pub struct TerminalDollarGreen(pub GreenId); +impl TypedSyntaxNode for TerminalDollar { + const OPTIONAL_KIND: Option = Some(SyntaxKind::TerminalDollar); + type StablePtr = TerminalDollarPtr; + type Green = TerminalDollarGreen; + fn missing(db: &dyn SyntaxGroup) -> Self::Green { + TerminalDollarGreen( + Arc::new(GreenNode { + kind: SyntaxKind::TerminalDollar, + details: GreenNodeDetails::Node { + children: vec![ + Trivia::missing(db).0, + TokenDollar::missing(db).0, + Trivia::missing(db).0, + ], + width: TextWidth::default(), + }, + }) + .intern(db), + ) + } + fn from_syntax_node(db: &dyn SyntaxGroup, node: SyntaxNode) -> Self { + let kind = node.kind(db); + assert_eq!( + kind, + SyntaxKind::TerminalDollar, + "Unexpected SyntaxKind {:?}. Expected {:?}.", + kind, + SyntaxKind::TerminalDollar + ); + let children = db.get_children(node.clone()); + Self { node, children } + } + fn as_syntax_node(&self) -> SyntaxNode { + self.node.clone() + } + fn stable_ptr(&self) -> Self::StablePtr { + TerminalDollarPtr(self.node.0.stable_ptr) + } +} +impl From<&TerminalDollar> for SyntaxStablePtrId { + fn from(node: &TerminalDollar) -> Self { + node.stable_ptr().untyped() + } +} +#[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct TokenDot { node: SyntaxNode, } @@ -34636,6 +35425,7 @@ pub enum TokenNode { TerminalImpl(TerminalImpl), TerminalImplicits(TerminalImplicits), TerminalLet(TerminalLet), + TerminalMacro(TerminalMacro), TerminalMatch(TerminalMatch), TerminalModule(TerminalModule), TerminalMut(TerminalMut), @@ -34661,6 +35451,7 @@ pub enum TokenNode { TerminalComma(TerminalComma), TerminalDiv(TerminalDiv), TerminalDivEq(TerminalDivEq), + TerminalDollar(TerminalDollar), TerminalDot(TerminalDot), TerminalDotDot(TerminalDotDot), TerminalEndOfFile(TerminalEndOfFile), @@ -34803,6 +35594,11 @@ impl From for TokenNodePtr { Self(value.0) } } +impl From for TokenNodePtr { + fn from(value: TerminalMacroPtr) -> Self { + Self(value.0) + } +} impl From for TokenNodePtr { fn from(value: TerminalMatchPtr) -> Self { Self(value.0) @@ -34928,6 +35724,11 @@ impl From for TokenNodePtr { Self(value.0) } } +impl From for TokenNodePtr { + fn from(value: TerminalDollarPtr) -> Self { + Self(value.0) + } +} impl From for TokenNodePtr { fn from(value: TerminalDotPtr) -> Self { Self(value.0) @@ -35193,6 +35994,11 @@ impl From for TokenNodeGreen { Self(value.0) } } +impl From for TokenNodeGreen { + fn from(value: TerminalMacroGreen) -> Self { + Self(value.0) + } +} impl From for TokenNodeGreen { fn from(value: TerminalMatchGreen) -> Self { Self(value.0) @@ -35318,6 +36124,11 @@ impl From for TokenNodeGreen { Self(value.0) } } +impl From for TokenNodeGreen { + fn from(value: TerminalDollarGreen) -> Self { + Self(value.0) + } +} impl From for TokenNodeGreen { fn from(value: TerminalDotGreen) -> Self { Self(value.0) @@ -35555,6 +36366,9 @@ impl TypedSyntaxNode for TokenNode { SyntaxKind::TerminalLet => { TokenNode::TerminalLet(TerminalLet::from_syntax_node(db, node)) } + SyntaxKind::TerminalMacro => { + TokenNode::TerminalMacro(TerminalMacro::from_syntax_node(db, node)) + } SyntaxKind::TerminalMatch => { TokenNode::TerminalMatch(TerminalMatch::from_syntax_node(db, node)) } @@ -35626,6 +36440,9 @@ impl TypedSyntaxNode for TokenNode { SyntaxKind::TerminalDivEq => { TokenNode::TerminalDivEq(TerminalDivEq::from_syntax_node(db, node)) } + SyntaxKind::TerminalDollar => { + TokenNode::TerminalDollar(TerminalDollar::from_syntax_node(db, node)) + } SyntaxKind::TerminalDot => { TokenNode::TerminalDot(TerminalDot::from_syntax_node(db, node)) } @@ -35742,6 +36559,7 @@ impl TypedSyntaxNode for TokenNode { TokenNode::TerminalImpl(x) => x.as_syntax_node(), TokenNode::TerminalImplicits(x) => x.as_syntax_node(), TokenNode::TerminalLet(x) => x.as_syntax_node(), + TokenNode::TerminalMacro(x) => x.as_syntax_node(), TokenNode::TerminalMatch(x) => x.as_syntax_node(), TokenNode::TerminalModule(x) => x.as_syntax_node(), TokenNode::TerminalMut(x) => x.as_syntax_node(), @@ -35767,6 +36585,7 @@ impl TypedSyntaxNode for TokenNode { TokenNode::TerminalComma(x) => x.as_syntax_node(), TokenNode::TerminalDiv(x) => x.as_syntax_node(), TokenNode::TerminalDivEq(x) => x.as_syntax_node(), + TokenNode::TerminalDollar(x) => x.as_syntax_node(), TokenNode::TerminalDot(x) => x.as_syntax_node(), TokenNode::TerminalDotDot(x) => x.as_syntax_node(), TokenNode::TerminalEndOfFile(x) => x.as_syntax_node(), @@ -35836,6 +36655,7 @@ impl TokenNode { | SyntaxKind::TerminalImpl | SyntaxKind::TerminalImplicits | SyntaxKind::TerminalLet + | SyntaxKind::TerminalMacro | SyntaxKind::TerminalMatch | SyntaxKind::TerminalModule | SyntaxKind::TerminalMut @@ -35861,6 +36681,7 @@ impl TokenNode { | SyntaxKind::TerminalComma | SyntaxKind::TerminalDiv | SyntaxKind::TerminalDivEq + | SyntaxKind::TerminalDollar | SyntaxKind::TerminalDot | SyntaxKind::TerminalDotDot | SyntaxKind::TerminalEndOfFile diff --git a/crates/cairo-lang-syntax/src/node/helpers.rs b/crates/cairo-lang-syntax/src/node/helpers.rs index 712077c4e2b..ab41c112a76 100644 --- a/crates/cairo-lang-syntax/src/node/helpers.rs +++ b/crates/cairo-lang-syntax/src/node/helpers.rs @@ -4,11 +4,11 @@ use smol_str::SmolStr; use super::ast::{ self, FunctionDeclaration, FunctionDeclarationGreen, FunctionWithBody, FunctionWithBodyPtr, ImplItem, ItemConstant, ItemEnum, ItemExternFunction, ItemExternFunctionPtr, ItemExternType, - ItemImpl, ItemImplAlias, ItemInlineMacro, ItemModule, ItemStruct, ItemTrait, ItemTypeAlias, - ItemUse, Member, Modifier, ModuleItem, OptionArgListParenthesized, Statement, StatementBreak, - StatementContinue, StatementExpr, StatementLet, StatementReturn, TerminalIdentifierGreen, - TokenIdentifierGreen, TraitItem, TraitItemConstant, TraitItemFunction, TraitItemFunctionPtr, - TraitItemImpl, TraitItemType, UsePathLeaf, Variant, WrappedArgList, + ItemImpl, ItemImplAlias, ItemInlineMacro, ItemMacroDeclaration, ItemModule, ItemStruct, + ItemTrait, ItemTypeAlias, ItemUse, Member, Modifier, ModuleItem, OptionArgListParenthesized, + Statement, StatementBreak, StatementContinue, StatementExpr, StatementLet, StatementReturn, + TerminalIdentifierGreen, TokenIdentifierGreen, TraitItem, TraitItemConstant, TraitItemFunction, + TraitItemFunctionPtr, TraitItemImpl, TraitItemType, UsePathLeaf, Variant, WrappedArgList, }; use super::db::SyntaxGroup; use super::ids::SyntaxStablePtrId; @@ -275,6 +275,11 @@ impl QueryAttrs for ItemTypeAlias { self.attributes(db).elements(db) } } +impl QueryAttrs for ItemMacroDeclaration { + fn attributes_elements(&self, db: &dyn SyntaxGroup) -> Vec { + self.attributes(db).elements(db) + } +} impl QueryAttrs for TraitItemFunction { fn attributes_elements(&self, db: &dyn SyntaxGroup) -> Vec { self.attributes(db).elements(db) @@ -331,6 +336,9 @@ impl QueryAttrs for ModuleItem { ModuleItem::InlineMacro(item) => item.attributes_elements(db), ModuleItem::Missing(_) => vec![], ModuleItem::HeaderDoc(_) => vec![], + ModuleItem::MacroDeclaration(macro_declaration) => { + macro_declaration.attributes_elements(db) + } } } } diff --git a/crates/cairo-lang-syntax/src/node/key_fields.rs b/crates/cairo-lang-syntax/src/node/key_fields.rs index 566f91280ca..3524f48c3b0 100644 --- a/crates/cairo-lang-syntax/src/node/key_fields.rs +++ b/crates/cairo-lang-syntax/src/node/key_fields.rs @@ -120,6 +120,9 @@ pub fn get_key_fields(kind: SyntaxKind, children: &[GreenId]) -> Vec { SyntaxKind::ClosureParamWrapperNAry => { vec![] } + SyntaxKind::ExprPlaceholder => { + vec![] + } SyntaxKind::StructArgExpr => { vec![] } @@ -408,6 +411,13 @@ pub fn get_key_fields(kind: SyntaxKind, children: &[GreenId]) -> Vec { SyntaxKind::ItemInlineMacro => { vec![] } + SyntaxKind::ItemMacroDeclaration => { + vec![/* name */ children[3]] + } + SyntaxKind::MacroRulesList => vec![], + SyntaxKind::MacroRule => { + vec![] + } SyntaxKind::LegacyExprInlineMacro => { vec![] } @@ -489,6 +499,10 @@ pub fn get_key_fields(kind: SyntaxKind, children: &[GreenId]) -> Vec { SyntaxKind::TerminalLet => { vec![] } + SyntaxKind::TokenMacro => vec![], + SyntaxKind::TerminalMacro => { + vec![] + } SyntaxKind::TokenMatch => vec![], SyntaxKind::TerminalMatch => { vec![] @@ -589,6 +603,10 @@ pub fn get_key_fields(kind: SyntaxKind, children: &[GreenId]) -> Vec { SyntaxKind::TerminalDivEq => { vec![] } + SyntaxKind::TokenDollar => vec![], + SyntaxKind::TerminalDollar => { + vec![] + } SyntaxKind::TokenDot => vec![], SyntaxKind::TerminalDot => { vec![] diff --git a/crates/cairo-lang-syntax/src/node/kind.rs b/crates/cairo-lang-syntax/src/node/kind.rs index 41eef1ec0a7..84f988f84a7 100644 --- a/crates/cairo-lang-syntax/src/node/kind.rs +++ b/crates/cairo-lang-syntax/src/node/kind.rs @@ -43,6 +43,7 @@ pub enum SyntaxKind { OptionFixedSizeArraySizeEmpty, ExprClosure, ClosureParamWrapperNAry, + ExprPlaceholder, StructArgExpr, OptionStructArgExprEmpty, StructArgSingle, @@ -151,6 +152,9 @@ pub enum SyntaxKind { BracketedTokenTree, ExprInlineMacro, ItemInlineMacro, + ItemMacroDeclaration, + MacroRulesList, + MacroRule, LegacyExprInlineMacro, LegacyItemInlineMacro, TriviumSkippedNode, @@ -190,6 +194,8 @@ pub enum SyntaxKind { TerminalImplicits, TokenLet, TerminalLet, + TokenMacro, + TerminalMacro, TokenMatch, TerminalMatch, TokenModule, @@ -240,6 +246,8 @@ pub enum SyntaxKind { TerminalDiv, TokenDivEq, TerminalDivEq, + TokenDollar, + TerminalDollar, TokenDot, TerminalDot, TokenDotDot, @@ -341,6 +349,7 @@ impl SyntaxKind { | SyntaxKind::TokenImpl | SyntaxKind::TokenImplicits | SyntaxKind::TokenLet + | SyntaxKind::TokenMacro | SyntaxKind::TokenMatch | SyntaxKind::TokenModule | SyntaxKind::TokenMut @@ -366,6 +375,7 @@ impl SyntaxKind { | SyntaxKind::TokenComma | SyntaxKind::TokenDiv | SyntaxKind::TokenDivEq + | SyntaxKind::TokenDollar | SyntaxKind::TokenDot | SyntaxKind::TokenDotDot | SyntaxKind::TokenEndOfFile @@ -431,6 +441,7 @@ impl SyntaxKind { | SyntaxKind::TerminalImpl | SyntaxKind::TerminalImplicits | SyntaxKind::TerminalLet + | SyntaxKind::TerminalMacro | SyntaxKind::TerminalMatch | SyntaxKind::TerminalModule | SyntaxKind::TerminalMut @@ -456,6 +467,7 @@ impl SyntaxKind { | SyntaxKind::TerminalComma | SyntaxKind::TerminalDiv | SyntaxKind::TerminalDivEq + | SyntaxKind::TerminalDollar | SyntaxKind::TerminalDot | SyntaxKind::TerminalDotDot | SyntaxKind::TerminalEndOfFile @@ -510,6 +522,7 @@ impl SyntaxKind { | SyntaxKind::TokenImpl | SyntaxKind::TokenImplicits | SyntaxKind::TokenLet + | SyntaxKind::TokenMacro | SyntaxKind::TokenMatch | SyntaxKind::TokenModule | SyntaxKind::TokenMut @@ -544,6 +557,7 @@ impl SyntaxKind { | SyntaxKind::TerminalImpl | SyntaxKind::TerminalImplicits | SyntaxKind::TerminalLet + | SyntaxKind::TerminalMacro | SyntaxKind::TerminalMatch | SyntaxKind::TerminalModule | SyntaxKind::TerminalMut