From e0ad9ce8c4bd450601115eaa31966dcdefeed0eb Mon Sep 17 00:00:00 2001 From: cairoIover <193099744+cairoIover@users.noreply.github.com> Date: Sat, 4 Jan 2025 03:00:33 +0100 Subject: [PATCH 01/12] feat: add dotdoteq in parser --- .../src/node_properties.rs | 6 +- .../cairo-lang-parser/src/colored_printer.rs | 1 + crates/cairo-lang-parser/src/lexer.rs | 16 +- crates/cairo-lang-parser/src/lexer_test.rs | 2 + crates/cairo-lang-parser/src/operators.rs | 2 +- crates/cairo-lang-parser/src/parser.rs | 1 + .../partial_trees/range_inclusive | 68 +++++ crates/cairo-lang-semantic/src/corelib.rs | 3 + .../src/cairo_spec.rs | 2 + crates/cairo-lang-syntax/src/node/ast.rs | 279 ++++++++++++++++++ .../cairo-lang-syntax/src/node/key_fields.rs | 10 + crates/cairo-lang-syntax/src/node/kind.rs | 5 + 12 files changed, 390 insertions(+), 5 deletions(-) create mode 100644 crates/cairo-lang-parser/src/parser_test_data/partial_trees/range_inclusive diff --git a/crates/cairo-lang-formatter/src/node_properties.rs b/crates/cairo-lang-formatter/src/node_properties.rs index 014266a7bee..b5068390e78 100644 --- a/crates/cairo-lang-formatter/src/node_properties.rs +++ b/crates/cairo-lang-formatter/src/node_properties.rs @@ -103,7 +103,7 @@ impl SyntaxNodeFormat for SyntaxNode { | SyntaxKind::TokenLParen | SyntaxKind::TokenLBrack | SyntaxKind::TokenImplicits => true, - SyntaxKind::TerminalDotDot + SyntaxKind::TerminalDotDot | SyntaxKind::TerminalDotDotEq if matches!(parent_kind(db, self), Some(SyntaxKind::ExprBinary)) => { true @@ -171,7 +171,7 @@ impl SyntaxNodeFormat for SyntaxNode { { true } - SyntaxKind::TokenDotDot + SyntaxKind::TokenDotDot | SyntaxKind::TokenDotDotEq if grandparent_kind(db, self) == Some(SyntaxKind::StructArgTail) => { true @@ -761,7 +761,7 @@ impl SyntaxNodeFormat for SyntaxNode { true, )) } - SyntaxKind::TerminalDotDot + SyntaxKind::TerminalDotDot | SyntaxKind::TerminalDotDotEq if matches!(parent_kind(db, self), Some(SyntaxKind::ExprBinary)) => { BreakLinePointsPositions::Leading(BreakLinePointProperties::new( diff --git a/crates/cairo-lang-parser/src/colored_printer.rs b/crates/cairo-lang-parser/src/colored_printer.rs index 4fdfcc3328f..a584b313a82 100644 --- a/crates/cairo-lang-parser/src/colored_printer.rs +++ b/crates/cairo-lang-parser/src/colored_printer.rs @@ -94,6 +94,7 @@ fn set_color(text: SmolStr, kind: SyntaxKind) -> ColoredString { | SyntaxKind::TokenColon | SyntaxKind::TokenColonColon | SyntaxKind::TokenDotDot + | SyntaxKind::TokenDotDotEq | SyntaxKind::TokenSemicolon | SyntaxKind::TokenAnd | SyntaxKind::TokenAndAnd diff --git a/crates/cairo-lang-parser/src/lexer.rs b/crates/cairo-lang-parser/src/lexer.rs index a90c6367c2f..672296b4b8e 100644 --- a/crates/cairo-lang-parser/src/lexer.rs +++ b/crates/cairo-lang-parser/src/lexer.rs @@ -270,7 +270,19 @@ impl<'a> Lexer<'a> { ']' => self.take_token_of_kind(TokenKind::RBrack), '(' => self.take_token_of_kind(TokenKind::LParen), ')' => self.take_token_of_kind(TokenKind::RParen), - '.' => self.pick_kind('.', TokenKind::DotDot, TokenKind::Dot), + '.' => { + self.take(); + match self.peek() { + Some('.') => { + self.take(); + match self.peek() { + Some('=') => self.take_token_of_kind(TokenKind::DotDotEq), + _ => TokenKind::DotDot, + } + } + _ => TokenKind::Dot, + } + } '*' => self.pick_kind('=', TokenKind::MulEq, TokenKind::Mul), '/' => self.pick_kind('=', TokenKind::DivEq, TokenKind::Div), '%' => self.pick_kind('=', TokenKind::ModEq, TokenKind::Mod), @@ -422,6 +434,7 @@ enum TokenKind { Comma, Dot, DotDot, + DotDotEq, Eq, Hash, Semicolon, @@ -503,6 +516,7 @@ fn token_kind_to_terminal_syntax_kind(kind: TokenKind) -> SyntaxKind { TokenKind::Comma => SyntaxKind::TerminalComma, TokenKind::Dot => SyntaxKind::TerminalDot, TokenKind::DotDot => SyntaxKind::TerminalDotDot, + TokenKind::DotDotEq => SyntaxKind::TerminalDotDotEq, TokenKind::Eq => SyntaxKind::TerminalEq, TokenKind::Hash => SyntaxKind::TerminalHash, TokenKind::Semicolon => SyntaxKind::TerminalSemicolon, diff --git a/crates/cairo-lang-parser/src/lexer_test.rs b/crates/cairo-lang-parser/src/lexer_test.rs index f55101ebfd3..0e9acfd1d02 100644 --- a/crates/cairo-lang-parser/src/lexer_test.rs +++ b/crates/cairo-lang-parser/src/lexer_test.rs @@ -71,6 +71,7 @@ fn terminal_kind_to_text(kind: SyntaxKind) -> Vec<&'static str> { SyntaxKind::TerminalModEq => vec!["%="], SyntaxKind::TerminalDot => vec!["."], SyntaxKind::TerminalDotDot => vec![".."], + SyntaxKind::TerminalDotDotEq => vec!["..="], SyntaxKind::TerminalEq => vec!["="], SyntaxKind::TerminalEqEq => vec!["=="], SyntaxKind::TerminalGE => vec![">="], @@ -162,6 +163,7 @@ fn terminal_kinds() -> Vec { SyntaxKind::TerminalComma, SyntaxKind::TerminalDot, SyntaxKind::TerminalDotDot, + SyntaxKind::TerminalDotDotEq, SyntaxKind::TerminalEq, SyntaxKind::TerminalSemicolon, SyntaxKind::TerminalQuestionMark, diff --git a/crates/cairo-lang-parser/src/operators.rs b/crates/cairo-lang-parser/src/operators.rs index 723d8c57944..887bb33b746 100644 --- a/crates/cairo-lang-parser/src/operators.rs +++ b/crates/cairo-lang-parser/src/operators.rs @@ -29,7 +29,7 @@ pub fn get_post_operator_precedence(kind: SyntaxKind) -> Option { | SyntaxKind::TerminalGE => Some(7), SyntaxKind::TerminalAndAnd => Some(8), SyntaxKind::TerminalOrOr => Some(9), - SyntaxKind::TerminalDotDot => Some(10), + SyntaxKind::TerminalDotDot | SyntaxKind::TerminalDotDotEq => Some(10), // unsure about this? SyntaxKind::TerminalEq | SyntaxKind::TerminalPlusEq | SyntaxKind::TerminalMinusEq diff --git a/crates/cairo-lang-parser/src/parser.rs b/crates/cairo-lang-parser/src/parser.rs index 5aeb4c57d96..efdc006a62f 100644 --- a/crates/cairo-lang-parser/src/parser.rs +++ b/crates/cairo-lang-parser/src/parser.rs @@ -1183,6 +1183,7 @@ impl<'a> Parser<'a> { SyntaxKind::TerminalOr => self.take::().into(), SyntaxKind::TerminalXor => self.take::().into(), SyntaxKind::TerminalDotDot => self.take::().into(), + SyntaxKind::TerminalDotDotEq => self.take::().into(), _ => unreachable!(), } } diff --git a/crates/cairo-lang-parser/src/parser_test_data/partial_trees/range_inclusive b/crates/cairo-lang-parser/src/parser_test_data/partial_trees/range_inclusive new file mode 100644 index 00000000000..7756a315164 --- /dev/null +++ b/crates/cairo-lang-parser/src/parser_test_data/partial_trees/range_inclusive @@ -0,0 +1,68 @@ +//! > test_runner_name +test_partial_parser_tree(expect_diagnostics: false) + +//! > cairo_code +fn f() { + for i in 1..=x {} +} + +//! > top_level_kind +ExprFor + +//! > ignored_kinds + +//! > expected_diagnostics + +//! > expected_tree +└── Top level kind: ExprFor + ├── for_kw (kind: TokenFor): 'for' + ├── pattern (kind: ExprPath) + │ └── item #0 (kind: PathSegmentSimple) + │ └── ident (kind: TokenIdentifier): 'i' + ├── identifier (kind: TokenIdentifier): 'in' + ├── expr (kind: ExprBinary) + │ ├── lhs (kind: TokenLiteralNumber): '1' + │ ├── op (kind: TokenDotDotEq): '..=' + │ └── rhs (kind: ExprPath) + │ └── item #0 (kind: PathSegmentSimple) + │ └── ident (kind: TokenIdentifier): 'x' + └── body (kind: ExprBlock) + ├── lbrace (kind: TokenLBrace): '{' + ├── statements (kind: StatementList) [] + └── rbrace (kind: TokenRBrace): '}' + +//! > ========================================================================== + +//! > Test range inclusive operator precedence + +//! > test_runner_name +test_partial_parser_tree(expect_diagnostics: false) + +//! > cairo_code +fn f() { + x += false && true..=1 + 2 +} + +//! > top_level_kind +ExprBinary + +//! > ignored_kinds + +//! > expected_diagnostics + +//! > expected_tree +└── Top level kind: ExprBinary + ├── lhs (kind: ExprPath) + │ └── item #0 (kind: PathSegmentSimple) + │ └── ident (kind: TokenIdentifier): 'x' + ├── op (kind: TokenPlusEq): '+=' + └── rhs (kind: ExprBinary) + ├── lhs (kind: ExprBinary) + │ ├── lhs (kind: TokenFalse): 'false' + │ ├── op (kind: TokenAndAnd): '&&' + │ └── rhs (kind: TokenTrue): 'true' + ├── op (kind: TokenDotDotEq): '..=' + └── rhs (kind: ExprBinary) + ├── lhs (kind: TokenLiteralNumber): '1' + ├── op (kind: TokenPlus): '+' + └── rhs (kind: TokenLiteralNumber): '2' diff --git a/crates/cairo-lang-semantic/src/corelib.rs b/crates/cairo-lang-semantic/src/corelib.rs index fd996d065a0..f1a5c18379c 100644 --- a/crates/cairo-lang-semantic/src/corelib.rs +++ b/crates/cairo-lang-semantic/src/corelib.rs @@ -523,6 +523,9 @@ pub fn core_binary_operator( BinaryOperator::Or(_) => ("BitOr", "bitor", false, CoreTraitContext::TopLevel), BinaryOperator::Xor(_) => ("BitXor", "bitxor", false, CoreTraitContext::TopLevel), BinaryOperator::DotDot(_) => ("RangeOp", "range", false, CoreTraitContext::Ops), + BinaryOperator::DotDotEq(_) => { + ("RangeInclusiveOp", "range_inclusive", false, CoreTraitContext::Ops) + } _ => return Ok(Err(SemanticDiagnosticKind::UnknownBinaryOperator)), }; Ok(Ok(( diff --git a/crates/cairo-lang-syntax-codegen/src/cairo_spec.rs b/crates/cairo-lang-syntax-codegen/src/cairo_spec.rs index 9f71ddd6535..8a8fe3b2c72 100644 --- a/crates/cairo-lang-syntax-codegen/src/cairo_spec.rs +++ b/crates/cairo-lang-syntax-codegen/src/cairo_spec.rs @@ -122,6 +122,7 @@ pub fn get_spec() -> Vec { .node_with_explicit_kind("LT", "TerminalLT") .node_with_explicit_kind("GT", "TerminalGT") .node_with_explicit_kind("DotDot", "TerminalDotDot") + .node_with_explicit_kind("DotDotEq", "TerminalDotDotEq") ) .add_struct(StructBuilder::new("ExprListParenthesized") .node("lparen", "TerminalLParen") @@ -870,6 +871,7 @@ pub fn get_spec() -> Vec { .add_token_and_terminal("DivEq") .add_token_and_terminal("Dot") .add_token_and_terminal("DotDot") + .add_token_and_terminal("DotDotEq") .add_token_and_terminal("EndOfFile") .add_token_and_terminal("Eq") .add_token_and_terminal("EqEq") diff --git a/crates/cairo-lang-syntax/src/node/ast.rs b/crates/cairo-lang-syntax/src/node/ast.rs index ea4aca9380b..4824d57bebf 100644 --- a/crates/cairo-lang-syntax/src/node/ast.rs +++ b/crates/cairo-lang-syntax/src/node/ast.rs @@ -1,4 +1,5 @@ // Autogenerated file. To regenerate, please run `cargo run --bin generate-syntax`. + #![allow(clippy::match_single_binding)] #![allow(clippy::too_many_arguments)] #![allow(dead_code)] @@ -17,12 +18,14 @@ use super::{ GreenId, GreenNode, SyntaxGroup, SyntaxNode, SyntaxStablePtr, SyntaxStablePtrId, Terminal, Token, TypedStablePtr, TypedSyntaxNode, }; + #[path = "ast_ext.rs"] mod ast_ext; #[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct Trivia(ElementList); impl Deref for Trivia { type Target = ElementList; + fn deref(&self) -> &Self::Target { &self.0 } @@ -268,6 +271,7 @@ impl From<&Trivium> for SyntaxStablePtrId { } impl Trivium { /// Checks if a kind of a variant of [Trivium]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -730,6 +734,7 @@ impl From<&Expr> for SyntaxStablePtrId { } impl Expr { /// Checks if a kind of a variant of [Expr]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -765,6 +770,7 @@ impl Expr { pub struct ExprList(ElementList); impl Deref for ExprList { type Target = ElementList; + fn deref(&self) -> &Self::Target { &self.0 } @@ -1067,6 +1073,7 @@ impl From<&ArgClause> for SyntaxStablePtrId { } impl ArgClause { /// Checks if a kind of a variant of [ArgClause]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -1475,6 +1482,7 @@ impl From<&ExprFieldInitShorthand> for SyntaxStablePtrId { pub struct ArgList(ElementList); impl Deref for ArgList { type Target = ElementList; + fn deref(&self) -> &Self::Target { &self.0 } @@ -1739,6 +1747,7 @@ impl From<&PathSegment> for SyntaxStablePtrId { } impl PathSegment { /// Checks if a kind of a variant of [PathSegment]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::PathSegmentWithGenericArgs | SyntaxKind::PathSegmentSimple) } @@ -1931,6 +1940,7 @@ impl From<&OptionTerminalColonColon> for SyntaxStablePtrId { } impl OptionTerminalColonColon { /// Checks if a kind of a variant of [OptionTerminalColonColon]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::OptionTerminalColonColonEmpty | SyntaxKind::TerminalColonColon) } @@ -2130,6 +2140,7 @@ impl From<&PathSegmentWithGenericArgs> for SyntaxStablePtrId { pub struct ExprPath(ElementList); impl Deref for ExprPath { type Target = ElementList; + fn deref(&self) -> &Self::Target { &self.0 } @@ -2572,6 +2583,7 @@ impl From<&UnaryOperator> for SyntaxStablePtrId { } impl UnaryOperator { /// Checks if a kind of a variant of [UnaryOperator]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -2714,6 +2726,7 @@ pub enum BinaryOperator { LT(TerminalLT), GT(TerminalGT), DotDot(TerminalDotDot), + DotDotEq(TerminalDotDotEq), } #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] pub struct BinaryOperatorPtr(pub SyntaxStablePtrId); @@ -2856,6 +2869,11 @@ impl From for BinaryOperatorPtr { Self(value.0) } } +impl From for BinaryOperatorPtr { + fn from(value: TerminalDotDotEqPtr) -> Self { + Self(value.0) + } +} impl From for BinaryOperatorGreen { fn from(value: TerminalDotGreen) -> Self { Self(value.0) @@ -2981,6 +2999,11 @@ impl From for BinaryOperatorGreen { Self(value.0) } } +impl From for BinaryOperatorGreen { + fn from(value: TerminalDotDotEqGreen) -> Self { + Self(value.0) + } +} #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] pub struct BinaryOperatorGreen(pub GreenId); impl TypedSyntaxNode for BinaryOperator { @@ -3040,6 +3063,9 @@ impl TypedSyntaxNode for BinaryOperator { SyntaxKind::TerminalDotDot => { BinaryOperator::DotDot(TerminalDotDot::from_syntax_node(db, node)) } + SyntaxKind::TerminalDotDotEq => { + BinaryOperator::DotDotEq(TerminalDotDotEq::from_syntax_node(db, node)) + } _ => { panic!("Unexpected syntax kind {:?} when constructing {}.", kind, "BinaryOperator") } @@ -3153,6 +3179,7 @@ impl TypedSyntaxNode for BinaryOperator { BinaryOperator::LT(x) => x.as_syntax_node(), BinaryOperator::GT(x) => x.as_syntax_node(), BinaryOperator::DotDot(x) => x.as_syntax_node(), + BinaryOperator::DotDotEq(x) => x.as_syntax_node(), } } fn stable_ptr(&self) -> Self::StablePtr { @@ -3166,6 +3193,7 @@ impl From<&BinaryOperator> for SyntaxStablePtrId { } impl BinaryOperator { /// Checks if a kind of a variant of [BinaryOperator]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -3194,6 +3222,7 @@ impl BinaryOperator { | SyntaxKind::TerminalLT | SyntaxKind::TerminalGT | SyntaxKind::TerminalDotDot + | SyntaxKind::TerminalDotDotEq ) } } @@ -3608,6 +3637,7 @@ impl From<&OptionArgListParenthesized> for SyntaxStablePtrId { } impl OptionArgListParenthesized { /// Checks if a kind of a variant of [OptionArgListParenthesized]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -4129,6 +4159,7 @@ impl From<&ExprMatch> for SyntaxStablePtrId { pub struct MatchArms(ElementList); impl Deref for MatchArms { type Target = ElementList; + fn deref(&self) -> &Self::Target { &self.0 } @@ -4528,6 +4559,7 @@ impl From<&Condition> for SyntaxStablePtrId { } impl Condition { /// Checks if a kind of a variant of [Condition]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::ConditionLet | SyntaxKind::ConditionExpr) } @@ -4816,6 +4848,7 @@ impl From<&BlockOrIf> for SyntaxStablePtrId { } impl BlockOrIf { /// Checks if a kind of a variant of [BlockOrIf]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::ExprBlock | SyntaxKind::ExprIf) } @@ -5341,6 +5374,7 @@ impl From<&OptionElseClause> for SyntaxStablePtrId { } impl OptionElseClause { /// Checks if a kind of a variant of [OptionElseClause]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::OptionElseClauseEmpty | SyntaxKind::ElseClause) } @@ -6052,6 +6086,7 @@ impl From<&OptionFixedSizeArraySize> for SyntaxStablePtrId { } impl OptionFixedSizeArraySize { /// Checks if a kind of a variant of [OptionFixedSizeArraySize]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::OptionFixedSizeArraySizeEmpty | SyntaxKind::FixedSizeArraySize) } @@ -6343,6 +6378,7 @@ impl From<&ClosureParamWrapper> for SyntaxStablePtrId { } impl ClosureParamWrapper { /// Checks if a kind of a variant of [ClosureParamWrapper]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::TerminalOrOr | SyntaxKind::ClosureParamWrapperNAry) } @@ -6648,6 +6684,7 @@ impl From<&OptionStructArgExpr> for SyntaxStablePtrId { } impl OptionStructArgExpr { /// Checks if a kind of a variant of [OptionStructArgExpr]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::OptionStructArgExprEmpty | SyntaxKind::StructArgExpr) } @@ -7036,6 +7073,7 @@ impl From<&StructArg> for SyntaxStablePtrId { } impl StructArg { /// Checks if a kind of a variant of [StructArg]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::StructArgSingle | SyntaxKind::StructArgTail) } @@ -7044,6 +7082,7 @@ impl StructArg { pub struct StructArgList(ElementList); impl Deref for StructArgList { type Target = ElementList; + fn deref(&self) -> &Self::Target { &self.0 } @@ -7487,6 +7526,7 @@ impl From<&WrappedArgList> for SyntaxStablePtrId { } impl WrappedArgList { /// Checks if a kind of a variant of [WrappedArgList]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -7835,6 +7875,7 @@ impl From<&Pattern> for SyntaxStablePtrId { } impl Pattern { /// Checks if a kind of a variant of [Pattern]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -8079,6 +8120,7 @@ impl From<&PatternStruct> for SyntaxStablePtrId { pub struct PatternStructParamList(ElementList); impl Deref for PatternStructParamList { type Target = ElementList; + fn deref(&self) -> &Self::Target { &self.0 } @@ -8393,6 +8435,7 @@ impl From<&PatternFixedSizeArray> for SyntaxStablePtrId { pub struct PatternList(ElementList); impl Deref for PatternList { type Target = ElementList; + fn deref(&self) -> &Self::Target { &self.0 } @@ -8495,6 +8538,7 @@ impl From<&PatternList> for SyntaxStablePtrId { pub struct PatternListOr(ElementList); impl Deref for PatternListOr { type Target = ElementList; + fn deref(&self) -> &Self::Target { &self.0 } @@ -8705,6 +8749,7 @@ impl From<&PatternStructParam> for SyntaxStablePtrId { } impl PatternStructParam { /// Checks if a kind of a variant of [PatternStructParam]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -9134,6 +9179,7 @@ impl From<&OptionPatternEnumInnerPattern> for SyntaxStablePtrId { } impl OptionPatternEnumInnerPattern { /// Checks if a kind of a variant of [OptionPatternEnumInnerPattern]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -9413,6 +9459,7 @@ impl From<&OptionTypeClause> for SyntaxStablePtrId { } impl OptionTypeClause { /// Checks if a kind of a variant of [OptionTypeClause]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::OptionTypeClauseEmpty | SyntaxKind::TypeClause) } @@ -9693,6 +9740,7 @@ impl From<&OptionReturnTypeClause> for SyntaxStablePtrId { } impl OptionReturnTypeClause { /// Checks if a kind of a variant of [OptionReturnTypeClause]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::OptionReturnTypeClauseEmpty | SyntaxKind::ReturnTypeClause) } @@ -9955,6 +10003,7 @@ impl From<&Statement> for SyntaxStablePtrId { } impl Statement { /// Checks if a kind of a variant of [Statement]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -9972,6 +10021,7 @@ impl Statement { pub struct StatementList(ElementList); impl Deref for StatementList { type Target = ElementList; + fn deref(&self) -> &Self::Target { &self.0 } @@ -10359,6 +10409,7 @@ impl From<&OptionTerminalSemicolon> for SyntaxStablePtrId { } impl OptionTerminalSemicolon { /// Checks if a kind of a variant of [OptionTerminalSemicolon]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::OptionTerminalSemicolonEmpty | SyntaxKind::TerminalSemicolon) } @@ -10843,6 +10894,7 @@ impl From<&OptionExprClause> for SyntaxStablePtrId { } impl OptionExprClause { /// Checks if a kind of a variant of [OptionExprClause]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::OptionExprClauseEmpty | SyntaxKind::ExprClause) } @@ -11366,6 +11418,7 @@ impl From<&Param> for SyntaxStablePtrId { pub struct ModifierList(ElementList); impl Deref for ModifierList { type Target = ElementList; + fn deref(&self) -> &Self::Target { &self.0 } @@ -11521,6 +11574,7 @@ impl From<&Modifier> for SyntaxStablePtrId { } impl Modifier { /// Checks if a kind of a variant of [Modifier]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::TerminalRef | SyntaxKind::TerminalMut) } @@ -11529,6 +11583,7 @@ impl Modifier { pub struct ParamList(ElementList); impl Deref for ParamList { type Target = ElementList; + fn deref(&self) -> &Self::Target { &self.0 } @@ -11745,6 +11800,7 @@ impl From<&ImplicitsClause> for SyntaxStablePtrId { pub struct ImplicitsList(ElementList); impl Deref for ImplicitsList { type Target = ElementList; + fn deref(&self) -> &Self::Target { &self.0 } @@ -11937,6 +11993,7 @@ impl From<&OptionImplicitsClause> for SyntaxStablePtrId { } impl OptionImplicitsClause { /// Checks if a kind of a variant of [OptionImplicitsClause]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::OptionImplicitsClauseEmpty | SyntaxKind::ImplicitsClause) } @@ -12118,6 +12175,7 @@ impl From<&OptionTerminalNoPanic> for SyntaxStablePtrId { } impl OptionTerminalNoPanic { /// Checks if a kind of a variant of [OptionTerminalNoPanic]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::OptionTerminalNoPanicEmpty | SyntaxKind::TerminalNoPanic) } @@ -12642,6 +12700,7 @@ impl From<&Member> for SyntaxStablePtrId { pub struct MemberList(ElementList); impl Deref for MemberList { type Target = ElementList; + fn deref(&self) -> &Self::Target { &self.0 } @@ -12857,6 +12916,7 @@ impl From<&Variant> for SyntaxStablePtrId { pub struct VariantList(ElementList); impl Deref for VariantList { type Target = ElementList; + fn deref(&self) -> &Self::Target { &self.0 } @@ -13260,6 +13320,7 @@ impl From<&ModuleItem> for SyntaxStablePtrId { } impl ModuleItem { /// Checks if a kind of a variant of [ModuleItem]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -13285,6 +13346,7 @@ impl ModuleItem { pub struct ModuleItemList(ElementList); impl Deref for ModuleItemList { type Target = ElementList; + fn deref(&self) -> &Self::Target { &self.0 } @@ -13560,6 +13622,7 @@ impl From<&Attribute> for SyntaxStablePtrId { pub struct AttributeList(ElementList); impl Deref for AttributeList { type Target = ElementList; + fn deref(&self) -> &Self::Target { &self.0 } @@ -13925,6 +13988,7 @@ impl From<&OptionVisibilityPubArgumentClause> for SyntaxStablePtrId { } impl OptionVisibilityPubArgumentClause { /// Checks if a kind of a variant of [OptionVisibilityPubArgumentClause]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -14208,6 +14272,7 @@ impl From<&Visibility> for SyntaxStablePtrId { } impl Visibility { /// Checks if a kind of a variant of [Visibility]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::VisibilityDefault | SyntaxKind::VisibilityPub) } @@ -14428,6 +14493,7 @@ impl From<&MaybeModuleBody> for SyntaxStablePtrId { } impl MaybeModuleBody { /// Checks if a kind of a variant of [MaybeModuleBody]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::ModuleBody | SyntaxKind::TerminalSemicolon) } @@ -15443,6 +15509,7 @@ impl From<&MaybeTraitBody> for SyntaxStablePtrId { } impl MaybeTraitBody { /// Checks if a kind of a variant of [MaybeTraitBody]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::TraitBody | SyntaxKind::TerminalSemicolon) } @@ -15555,6 +15622,7 @@ impl From<&TraitBody> for SyntaxStablePtrId { pub struct TraitItemList(ElementList); impl Deref for TraitItemList { type Target = ElementList; + fn deref(&self) -> &Self::Target { &self.0 } @@ -15768,6 +15836,7 @@ impl From<&TraitItem> for SyntaxStablePtrId { } impl TraitItem { /// Checks if a kind of a variant of [TraitItem]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -16469,6 +16538,7 @@ impl From<&MaybeTraitFunctionBody> for SyntaxStablePtrId { } impl MaybeTraitFunctionBody { /// Checks if a kind of a variant of [MaybeTraitFunctionBody]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::ExprBlock | SyntaxKind::TerminalSemicolon) } @@ -16923,6 +16993,7 @@ impl From<&MaybeImplBody> for SyntaxStablePtrId { } impl MaybeImplBody { /// Checks if a kind of a variant of [MaybeImplBody]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::ImplBody | SyntaxKind::TerminalSemicolon) } @@ -17035,6 +17106,7 @@ impl From<&ImplBody> for SyntaxStablePtrId { pub struct ImplItemList(ElementList); impl Deref for ImplItemList { type Target = ElementList; + fn deref(&self) -> &Self::Target { &self.0 } @@ -17358,6 +17430,7 @@ impl From<&ImplItem> for SyntaxStablePtrId { } impl ImplItem { /// Checks if a kind of a variant of [ImplItem]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -18316,6 +18389,7 @@ impl From<&UsePath> for SyntaxStablePtrId { } impl UsePath { /// Checks if a kind of a variant of [UsePath]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -18741,6 +18815,7 @@ impl From<&UsePathStar> for SyntaxStablePtrId { pub struct UsePathList(ElementList); impl Deref for UsePathList { type Target = ElementList; + fn deref(&self) -> &Self::Target { &self.0 } @@ -19037,6 +19112,7 @@ impl From<&OptionAliasClause> for SyntaxStablePtrId { } impl OptionAliasClause { /// Checks if a kind of a variant of [OptionAliasClause]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::OptionAliasClauseEmpty | SyntaxKind::AliasClause) } @@ -19215,6 +19291,7 @@ impl From<&GenericArg> for SyntaxStablePtrId { } impl GenericArg { /// Checks if a kind of a variant of [GenericArg]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::GenericArgUnnamed | SyntaxKind::GenericArgNamed) } @@ -19511,6 +19588,7 @@ impl From<&GenericArgValue> for SyntaxStablePtrId { } impl GenericArgValue { /// Checks if a kind of a variant of [GenericArgValue]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::GenericArgValueExpr | SyntaxKind::TerminalUnderscore) } @@ -19714,6 +19792,7 @@ impl From<&GenericArgs> for SyntaxStablePtrId { pub struct GenericArgList(ElementList); impl Deref for GenericArgList { type Target = ElementList; + fn deref(&self) -> &Self::Target { &self.0 } @@ -20035,6 +20114,7 @@ impl From<&AssociatedItemConstraints> for SyntaxStablePtrId { pub struct AssociatedItemConstraintList(ElementList); impl Deref for AssociatedItemConstraintList { type Target = ElementList; + fn deref(&self) -> &Self::Target { &self.0 } @@ -20235,6 +20315,7 @@ impl From<&OptionAssociatedItemConstraints> for SyntaxStablePtrId { } impl OptionAssociatedItemConstraints { /// Checks if a kind of a variant of [OptionAssociatedItemConstraints]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -20427,6 +20508,7 @@ impl From<&OptionWrappedGenericParamList> for SyntaxStablePtrId { } impl OptionWrappedGenericParamList { /// Checks if a kind of a variant of [OptionWrappedGenericParamList]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -20629,6 +20711,7 @@ impl From<&WrappedGenericParamList> for SyntaxStablePtrId { pub struct GenericParamList(ElementList); impl Deref for GenericParamList { type Target = ElementList; + fn deref(&self) -> &Self::Target { &self.0 } @@ -20872,6 +20955,7 @@ impl From<&GenericParam> for SyntaxStablePtrId { } impl GenericParam { /// Checks if a kind of a variant of [GenericParam]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -21625,6 +21709,7 @@ impl From<&SkippedNode> for SyntaxStablePtrId { } impl SkippedNode { /// Checks if a kind of a variant of [SkippedNode]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::AttributeList | SyntaxKind::VisibilityPub) } @@ -30151,6 +30236,183 @@ impl From<&TerminalDotDot> for SyntaxStablePtrId { } } #[derive(Clone, Debug, Eq, Hash, PartialEq)] +pub struct TokenDotDotEq { + node: SyntaxNode, +} +impl Token for TokenDotDotEq { + fn new_green(db: &dyn SyntaxGroup, text: SmolStr) -> Self::Green { + TokenDotDotEqGreen( + Arc::new(GreenNode { + kind: SyntaxKind::TokenDotDotEq, + 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 TokenDotDotEqPtr(pub SyntaxStablePtrId); +impl TypedStablePtr for TokenDotDotEqPtr { + type SyntaxNode = TokenDotDotEq; + fn untyped(&self) -> SyntaxStablePtrId { + self.0 + } + fn lookup(&self, db: &dyn SyntaxGroup) -> TokenDotDotEq { + TokenDotDotEq::from_syntax_node(db, self.0.lookup(db)) + } +} +impl From for SyntaxStablePtrId { + fn from(ptr: TokenDotDotEqPtr) -> Self { + ptr.untyped() + } +} +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +pub struct TokenDotDotEqGreen(pub GreenId); +impl TokenDotDotEqGreen { + pub fn text(&self, db: &dyn SyntaxGroup) -> SmolStr { + extract_matches!(&self.0.lookup_intern(db).details, GreenNodeDetails::Token).clone() + } +} +impl TypedSyntaxNode for TokenDotDotEq { + const OPTIONAL_KIND: Option = Some(SyntaxKind::TokenDotDotEq); + type StablePtr = TokenDotDotEqPtr; + type Green = TokenDotDotEqGreen; + fn missing(db: &dyn SyntaxGroup) -> Self::Green { + TokenDotDotEqGreen( + 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::TokenDotDotEq) + } + } + } + fn as_syntax_node(&self) -> SyntaxNode { + self.node.clone() + } + fn stable_ptr(&self) -> Self::StablePtr { + TokenDotDotEqPtr(self.node.0.stable_ptr) + } +} +impl From<&TokenDotDotEq> for SyntaxStablePtrId { + fn from(node: &TokenDotDotEq) -> Self { + node.stable_ptr().untyped() + } +} +#[derive(Clone, Debug, Eq, Hash, PartialEq)] +pub struct TerminalDotDotEq { + node: SyntaxNode, + children: Arc<[SyntaxNode]>, +} +impl Terminal for TerminalDotDotEq { + const KIND: SyntaxKind = SyntaxKind::TerminalDotDotEq; + type TokenType = TokenDotDotEq; + 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(); + TerminalDotDotEqGreen( + Arc::new(GreenNode { + kind: SyntaxKind::TerminalDotDotEq, + details: GreenNodeDetails::Node { children, width }, + }) + .intern(db), + ) + } + fn text(&self, db: &dyn SyntaxGroup) -> SmolStr { + self.token(db).text(db) + } +} +impl TerminalDotDotEq { + 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) -> TokenDotDotEq { + TokenDotDotEq::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 TerminalDotDotEqPtr(pub SyntaxStablePtrId); +impl TerminalDotDotEqPtr {} +impl TypedStablePtr for TerminalDotDotEqPtr { + type SyntaxNode = TerminalDotDotEq; + fn untyped(&self) -> SyntaxStablePtrId { + self.0 + } + fn lookup(&self, db: &dyn SyntaxGroup) -> TerminalDotDotEq { + TerminalDotDotEq::from_syntax_node(db, self.0.lookup(db)) + } +} +impl From for SyntaxStablePtrId { + fn from(ptr: TerminalDotDotEqPtr) -> Self { + ptr.untyped() + } +} +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +pub struct TerminalDotDotEqGreen(pub GreenId); +impl TypedSyntaxNode for TerminalDotDotEq { + const OPTIONAL_KIND: Option = Some(SyntaxKind::TerminalDotDotEq); + type StablePtr = TerminalDotDotEqPtr; + type Green = TerminalDotDotEqGreen; + fn missing(db: &dyn SyntaxGroup) -> Self::Green { + TerminalDotDotEqGreen( + Arc::new(GreenNode { + kind: SyntaxKind::TerminalDotDotEq, + details: GreenNodeDetails::Node { + children: vec![ + Trivia::missing(db).0, + TokenDotDotEq::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::TerminalDotDotEq, + "Unexpected SyntaxKind {:?}. Expected {:?}.", + kind, + SyntaxKind::TerminalDotDotEq + ); + 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 { + TerminalDotDotEqPtr(self.node.0.stable_ptr) + } +} +impl From<&TerminalDotDotEq> for SyntaxStablePtrId { + fn from(node: &TerminalDotDotEq) -> Self { + node.stable_ptr().untyped() + } +} +#[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct TokenEndOfFile { node: SyntaxNode, } @@ -37105,6 +37367,7 @@ pub enum TokenNode { TerminalDivEq(TerminalDivEq), TerminalDot(TerminalDot), TerminalDotDot(TerminalDotDot), + TerminalDotDotEq(TerminalDotDotEq), TerminalEndOfFile(TerminalEndOfFile), TerminalEq(TerminalEq), TerminalEqEq(TerminalEqEq), @@ -37380,6 +37643,11 @@ impl From for TokenNodePtr { Self(value.0) } } +impl From for TokenNodePtr { + fn from(value: TerminalDotDotEqPtr) -> Self { + Self(value.0) + } +} impl From for TokenNodePtr { fn from(value: TerminalEndOfFilePtr) -> Self { Self(value.0) @@ -37770,6 +38038,11 @@ impl From for TokenNodeGreen { Self(value.0) } } +impl From for TokenNodeGreen { + fn from(value: TerminalDotDotEqGreen) -> Self { + Self(value.0) + } +} impl From for TokenNodeGreen { fn from(value: TerminalEndOfFileGreen) -> Self { Self(value.0) @@ -38074,6 +38347,9 @@ impl TypedSyntaxNode for TokenNode { SyntaxKind::TerminalDotDot => { TokenNode::TerminalDotDot(TerminalDotDot::from_syntax_node(db, node)) } + SyntaxKind::TerminalDotDotEq => { + TokenNode::TerminalDotDotEq(TerminalDotDotEq::from_syntax_node(db, node)) + } SyntaxKind::TerminalEndOfFile => { TokenNode::TerminalEndOfFile(TerminalEndOfFile::from_syntax_node(db, node)) } @@ -38451,6 +38727,7 @@ impl TypedSyntaxNode for TokenNode { TokenNode::TerminalDivEq(x) => x.as_syntax_node(), TokenNode::TerminalDot(x) => x.as_syntax_node(), TokenNode::TerminalDotDot(x) => x.as_syntax_node(), + TokenNode::TerminalDotDotEq(x) => x.as_syntax_node(), TokenNode::TerminalEndOfFile(x) => x.as_syntax_node(), TokenNode::TerminalEq(x) => x.as_syntax_node(), TokenNode::TerminalEqEq(x) => x.as_syntax_node(), @@ -38497,6 +38774,7 @@ impl From<&TokenNode> for SyntaxStablePtrId { } impl TokenNode { /// Checks if a kind of a variant of [TokenNode]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -38545,6 +38823,7 @@ impl TokenNode { | SyntaxKind::TerminalDivEq | SyntaxKind::TerminalDot | SyntaxKind::TerminalDotDot + | SyntaxKind::TerminalDotDotEq | SyntaxKind::TerminalEndOfFile | SyntaxKind::TerminalEq | SyntaxKind::TerminalEqEq diff --git a/crates/cairo-lang-syntax/src/node/key_fields.rs b/crates/cairo-lang-syntax/src/node/key_fields.rs index b870015ea47..94e4ea6b6f9 100644 --- a/crates/cairo-lang-syntax/src/node/key_fields.rs +++ b/crates/cairo-lang-syntax/src/node/key_fields.rs @@ -1,10 +1,16 @@ // Autogenerated file. To regenerate, please run `cargo run --bin generate-syntax`. + use super::ids::GreenId; use super::kind::SyntaxKind; + /// Gets the vector of children ids that are the indexing key for this SyntaxKind. + /// + /// Each SyntaxKind has some children that are defined in the spec to be its indexing key + /// for its stable pointer. See [super::stable_ptr]. + pub fn get_key_fields(kind: SyntaxKind, children: &[GreenId]) -> Vec { match kind { SyntaxKind::Trivia => vec![], @@ -585,6 +591,10 @@ pub fn get_key_fields(kind: SyntaxKind, children: &[GreenId]) -> Vec { SyntaxKind::TerminalDotDot => { vec![] } + SyntaxKind::TokenDotDotEq => vec![], + SyntaxKind::TerminalDotDotEq => { + vec![] + } SyntaxKind::TokenEndOfFile => vec![], SyntaxKind::TerminalEndOfFile => { vec![] diff --git a/crates/cairo-lang-syntax/src/node/kind.rs b/crates/cairo-lang-syntax/src/node/kind.rs index 4614e8977a4..d2136eae609 100644 --- a/crates/cairo-lang-syntax/src/node/kind.rs +++ b/crates/cairo-lang-syntax/src/node/kind.rs @@ -1,4 +1,5 @@ // Autogenerated file. To regenerate, please run `cargo run --bin generate-syntax`. + use core::fmt; #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] pub enum SyntaxKind { @@ -240,6 +241,8 @@ pub enum SyntaxKind { TerminalDot, TokenDotDot, TerminalDotDot, + TokenDotDotEq, + TerminalDotDotEq, TokenEndOfFile, TerminalEndOfFile, TokenEq, @@ -364,6 +367,7 @@ impl SyntaxKind { | SyntaxKind::TokenDivEq | SyntaxKind::TokenDot | SyntaxKind::TokenDotDot + | SyntaxKind::TokenDotDotEq | SyntaxKind::TokenEndOfFile | SyntaxKind::TokenEq | SyntaxKind::TokenEqEq @@ -454,6 +458,7 @@ impl SyntaxKind { | SyntaxKind::TerminalDivEq | SyntaxKind::TerminalDot | SyntaxKind::TerminalDotDot + | SyntaxKind::TerminalDotDotEq | SyntaxKind::TerminalEndOfFile | SyntaxKind::TerminalEq | SyntaxKind::TerminalEqEq From 228cbe7dc072410a03b427263306b01bec0f7105 Mon Sep 17 00:00:00 2001 From: cairoIover <193099744+cairoIover@users.noreply.github.com> Date: Sat, 4 Jan 2025 03:00:33 +0100 Subject: [PATCH 02/12] feat: add RangeInclusive in corelib --- corelib/src/ops.cairo | 6 +- corelib/src/ops/range.cairo | 64 +++++++++++++++++++ corelib/src/test/range_test.cairo | 10 +++ crates/cairo-lang-parser/src/operators.rs | 2 +- .../expr/semantic_test_data/range_inclusive | 40 ++++++++++++ 5 files changed, 118 insertions(+), 4 deletions(-) create mode 100644 crates/cairo-lang-semantic/src/expr/semantic_test_data/range_inclusive diff --git a/corelib/src/ops.cairo b/corelib/src/ops.cairo index 2f238ace4e0..36b953cde38 100644 --- a/corelib/src/ops.cairo +++ b/corelib/src/ops.cairo @@ -67,7 +67,7 @@ pub mod index; pub use index::{Index, IndexView}; mod range; -// `RangeOp` is used internally by the compiler. +// `RangeOp` and `RangeInclusiveOp` are used internally by the compiler. #[allow(unused_imports)] -use range::RangeOp; -pub use range::{Range, RangeIterator, RangeTrait}; +use range::{RangeOp, RangeInclusiveOp}; +pub use range::{Range, RangeInclusive, RangeInclusiveIterator, RangeIterator, RangeTrait}; diff --git a/corelib/src/ops/range.cairo b/corelib/src/ops/range.cairo index df4f2a938e9..eaf8b9ee4c2 100644 --- a/corelib/src/ops/range.cairo +++ b/corelib/src/ops/range.cairo @@ -139,6 +139,70 @@ impl RangeIntoIterator< } } +/// Represents the range [start, end]. +#[derive(Clone, Drop)] +pub struct RangeInclusive { + /// The lower bound of the range (inclusive). + pub start: T, + /// The upper bound of the range (inclusive). + pub end: T, +} + +#[derive(Clone, Drop)] +pub struct RangeInclusiveIterator { + /// The current value of the iterator. + cur: T, + /// The upper bound of the range (inclusive). + end: T, +} + +/// Handles the range inclusive operator (`..=`). +#[generate_trait] +pub impl RangeInclusiveOpImpl of RangeInclusiveOp { + /// Handles the `..=` operator. Returns the value of the expression `start..=end`. + fn range_inclusive(start: T, end: T) -> RangeInclusive { + RangeInclusive { start, end } + } +} + +impl RangeInclusiveIteratorImpl< + T, impl OneT: One, +Add, +Copy, +Drop, +PartialEq, +PartialOrd, +> of Iterator> { + type Item = T; + + fn next(ref self: RangeInclusiveIterator) -> Option { + if self.cur <= self.end { + let value = self.cur; + self.cur = value + OneT::one(); + Option::Some(value) + } else { + Option::None + } + } +} + +pub impl RangeInclusiveIntoIterator< + T, + impl OneT: One, + +Add, + +Copy, + +Drop, + +PartialEq, + +PartialOrd, + -SierraIntRangeSupport, +> of IntoIterator> { + type IntoIter = RangeInclusiveIterator; + + fn into_iter(self: RangeInclusive) -> Self::IntoIter { + if self.start <= self.end { + Self::IntoIter { cur: self.start, end: self.end } + } else { + let oob = self.end + OneT::one(); + Self::IntoIter { cur: oob, end: self.end } + } + } +} + // Sierra optimization. mod internal { diff --git a/corelib/src/test/range_test.cairo b/corelib/src/test/range_test.cairo index fd7b9fe65de..be0b69e60d9 100644 --- a/corelib/src/test/range_test.cairo +++ b/corelib/src/test/range_test.cairo @@ -22,3 +22,13 @@ fn test_range_contains() { fn test_range_format() { assert!(format!("{:?}", 1..5) == "1..5"); } + +#[test] +fn test_range_inclusive_iterator_working() { + let x = (1_usize..=3); + let mut iter = x.into_iter(); + assert!(iter.next() == Option::Some(1)); + assert!(iter.next() == Option::Some(2)); + assert!(iter.next() == Option::Some(3)); + assert!(iter.next() == Option::None); +} diff --git a/crates/cairo-lang-parser/src/operators.rs b/crates/cairo-lang-parser/src/operators.rs index 887bb33b746..85000a15fab 100644 --- a/crates/cairo-lang-parser/src/operators.rs +++ b/crates/cairo-lang-parser/src/operators.rs @@ -29,7 +29,7 @@ pub fn get_post_operator_precedence(kind: SyntaxKind) -> Option { | SyntaxKind::TerminalGE => Some(7), SyntaxKind::TerminalAndAnd => Some(8), SyntaxKind::TerminalOrOr => Some(9), - SyntaxKind::TerminalDotDot | SyntaxKind::TerminalDotDotEq => Some(10), // unsure about this? + SyntaxKind::TerminalDotDot | SyntaxKind::TerminalDotDotEq => Some(10), SyntaxKind::TerminalEq | SyntaxKind::TerminalPlusEq | SyntaxKind::TerminalMinusEq diff --git a/crates/cairo-lang-semantic/src/expr/semantic_test_data/range_inclusive b/crates/cairo-lang-semantic/src/expr/semantic_test_data/range_inclusive new file mode 100644 index 00000000000..f81c041accd --- /dev/null +++ b/crates/cairo-lang-semantic/src/expr/semantic_test_data/range_inclusive @@ -0,0 +1,40 @@ +//! > Test range + +//! > test_runner_name +test_expr_semantics(expect_diagnostics: false) + +//! > function_body + +//! > expr_code +1..=10_u8 + +//! > module_code + +//! > expected_semantics +FunctionCall( + ExprFunctionCall { + function: core::ops::range::RangeInclusiveOpImpl::::range_inclusive, + args: [ + Value( + Literal( + ExprLiteral { + value: 1, + ty: core::integer::u8, + }, + ), + ), + Value( + Literal( + ExprLiteral { + value: 10, + ty: core::integer::u8, + }, + ), + ), + ], + coupon_arg: None, + ty: core::ops::range::RangeInclusive::, + }, +) + +//! > expected_diagnostics From 04b9e1400ae915d6592e9fab0b02d63166afe495 Mon Sep 17 00:00:00 2001 From: cairoIover <193099744+cairoIover@users.noreply.github.com> Date: Sat, 4 Jan 2025 23:35:23 +0100 Subject: [PATCH 03/12] suggestions --- corelib/src/ops.cairo | 14 +++--- corelib/src/ops/range.cairo | 44 ++++++++++++------- corelib/src/test/range_test.cairo | 22 ++++++++-- crates/cairo-lang-parser/src/lexer.rs | 8 +--- .../cairo-lang-syntax/src/node/key_fields.rs | 6 --- crates/cairo-lang-syntax/src/node/kind.rs | 1 - 6 files changed, 55 insertions(+), 40 deletions(-) diff --git a/corelib/src/ops.cairo b/corelib/src/ops.cairo index 36b953cde38..1f918fd47cb 100644 --- a/corelib/src/ops.cairo +++ b/corelib/src/ops.cairo @@ -56,18 +56,18 @@ mod arith; pub use arith::{AddAssign, DivAssign, MulAssign, RemAssign, SubAssign}; mod deref; -pub use deref::Deref; #[feature("deref_mut")] pub use deref::DerefMut; +pub use deref::Deref; + +mod range; +pub use range::{Range, RangeInclusive, RangeInclusiveIterator, RangeIterator, RangeTrait}; +// `RangeOp` and `RangeInclusiveOp` are used internally by the compiler. +#[allow(unused_imports)] +use range::{RangeInclusiveOp, RangeOp}; mod function; pub use function::{Fn, FnOnce}; pub mod index; pub use index::{Index, IndexView}; - -mod range; -// `RangeOp` and `RangeInclusiveOp` are used internally by the compiler. -#[allow(unused_imports)] -use range::{RangeOp, RangeInclusiveOp}; -pub use range::{Range, RangeInclusive, RangeInclusiveIterator, RangeIterator, RangeTrait}; diff --git a/corelib/src/ops/range.cairo b/corelib/src/ops/range.cairo index eaf8b9ee4c2..9c4c56ef5bb 100644 --- a/corelib/src/ops/range.cairo +++ b/corelib/src/ops/range.cairo @@ -151,9 +151,16 @@ pub struct RangeInclusive { #[derive(Clone, Drop)] pub struct RangeInclusiveIterator { /// The current value of the iterator. - cur: T, + pub(crate) cur: T, /// The upper bound of the range (inclusive). - end: T, + pub(crate) end: T, + // This field is: + // - `false` upon construction + // - `false` when iteration has yielded an element and the iterator is not exhausted + // - `true` when iteration has been used to exhaust the iterator + // + // This is required to differentiate bewteen the last element and the end of the range. + pub(crate) exhausted: bool, } /// Handles the range inclusive operator (`..=`). @@ -166,24 +173,32 @@ pub impl RangeInclusiveOpImpl of RangeInclusiveOp { } impl RangeInclusiveIteratorImpl< - T, impl OneT: One, +Add, +Copy, +Drop, +PartialEq, +PartialOrd, + T, +One, +Add, +Copy, +Drop, +PartialEq, +PartialOrd, > of Iterator> { type Item = T; fn next(ref self: RangeInclusiveIterator) -> Option { - if self.cur <= self.end { - let value = self.cur; - self.cur = value + OneT::one(); - Option::Some(value) - } else { - Option::None + if self.exhausted { + return Option::None; } + + let current = self.cur; + + // If this is the last element, mark as exhausted for next iteration + if current == self.end { + self.exhausted = true; + return Option::Some(current); + } + + // We know current < self.end here, because the iterator is not exhausted + self.cur = current + One::one(); + Option::Some(current) } } pub impl RangeInclusiveIntoIterator< T, - impl OneT: One, + +One, +Add, +Copy, +Drop, @@ -194,15 +209,12 @@ pub impl RangeInclusiveIntoIterator< type IntoIter = RangeInclusiveIterator; fn into_iter(self: RangeInclusive) -> Self::IntoIter { - if self.start <= self.end { - Self::IntoIter { cur: self.start, end: self.end } - } else { - let oob = self.end + OneT::one(); - Self::IntoIter { cur: oob, end: self.end } - } + let exhausted = self.start > self.end; + Self::IntoIter { cur: self.start, end: self.end, exhausted } } } + // Sierra optimization. mod internal { diff --git a/corelib/src/test/range_test.cairo b/corelib/src/test/range_test.cairo index be0b69e60d9..7dd5ef8c6c5 100644 --- a/corelib/src/test/range_test.cairo +++ b/corelib/src/test/range_test.cairo @@ -24,11 +24,27 @@ fn test_range_format() { } #[test] -fn test_range_inclusive_iterator_working() { - let x = (1_usize..=3); - let mut iter = x.into_iter(); +fn test_range_inclusive_iterator() { + let mut iter = (1_usize..=3).into_iter(); assert!(iter.next() == Option::Some(1)); assert!(iter.next() == Option::Some(2)); assert!(iter.next() == Option::Some(3)); assert!(iter.next() == Option::None); } + +#[test] +fn test_range_inclusive_iterator_range_end() { + let mut iter = (253_u8..=255).into_iter(); + assert!(iter.next() == Option::Some(253)); + assert!(iter.next() == Option::Some(254)); + assert!(iter.next() == Option::Some(255)); + assert!(iter.next() == Option::None); +} + +#[test] +fn test_range_inclusive_empty_ranges() { + let mut iter = (255_u8..=125).into_iter(); + assert!(iter.next() == Option::None); + let mut iter = (255_u8..=0).into_iter(); + assert!(iter.next() == Option::None); +} diff --git a/crates/cairo-lang-parser/src/lexer.rs b/crates/cairo-lang-parser/src/lexer.rs index 672296b4b8e..d95eb389a51 100644 --- a/crates/cairo-lang-parser/src/lexer.rs +++ b/crates/cairo-lang-parser/src/lexer.rs @@ -273,13 +273,7 @@ impl<'a> Lexer<'a> { '.' => { self.take(); match self.peek() { - Some('.') => { - self.take(); - match self.peek() { - Some('=') => self.take_token_of_kind(TokenKind::DotDotEq), - _ => TokenKind::DotDot, - } - } + Some('.') => self.pick_kind('=', TokenKind::DotDotEq, TokenKind::DotDot), _ => TokenKind::Dot, } } diff --git a/crates/cairo-lang-syntax/src/node/key_fields.rs b/crates/cairo-lang-syntax/src/node/key_fields.rs index 94e4ea6b6f9..025ad081e3d 100644 --- a/crates/cairo-lang-syntax/src/node/key_fields.rs +++ b/crates/cairo-lang-syntax/src/node/key_fields.rs @@ -1,16 +1,10 @@ // Autogenerated file. To regenerate, please run `cargo run --bin generate-syntax`. - use super::ids::GreenId; use super::kind::SyntaxKind; - /// Gets the vector of children ids that are the indexing key for this SyntaxKind. - /// - /// Each SyntaxKind has some children that are defined in the spec to be its indexing key - /// for its stable pointer. See [super::stable_ptr]. - pub fn get_key_fields(kind: SyntaxKind, children: &[GreenId]) -> Vec { match kind { SyntaxKind::Trivia => vec![], diff --git a/crates/cairo-lang-syntax/src/node/kind.rs b/crates/cairo-lang-syntax/src/node/kind.rs index d2136eae609..de170ed12a9 100644 --- a/crates/cairo-lang-syntax/src/node/kind.rs +++ b/crates/cairo-lang-syntax/src/node/kind.rs @@ -1,5 +1,4 @@ // Autogenerated file. To regenerate, please run `cargo run --bin generate-syntax`. - use core::fmt; #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] pub enum SyntaxKind { From 229f25249366f9d15666c58da1f17a618b5e8e6f Mon Sep 17 00:00:00 2001 From: cairoIover <193099744+cairoIover@users.noreply.github.com> Date: Sat, 4 Jan 2025 23:47:00 +0100 Subject: [PATCH 04/12] add PartialEq derive --- corelib/src/ops/range.cairo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/corelib/src/ops/range.cairo b/corelib/src/ops/range.cairo index 9c4c56ef5bb..77e784da614 100644 --- a/corelib/src/ops/range.cairo +++ b/corelib/src/ops/range.cairo @@ -140,7 +140,7 @@ impl RangeIntoIterator< } /// Represents the range [start, end]. -#[derive(Clone, Drop)] +#[derive(Clone, Drop, PartialEq)] pub struct RangeInclusive { /// The lower bound of the range (inclusive). pub start: T, From efb68a77280d2d8ec5139feac7c4ce056dd6c94c Mon Sep 17 00:00:00 2001 From: cairoIover <193099744+cairoIover@users.noreply.github.com> Date: Sat, 4 Jan 2025 23:48:16 +0100 Subject: [PATCH 05/12] add debug impl --- corelib/src/ops/range.cairo | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/corelib/src/ops/range.cairo b/corelib/src/ops/range.cairo index 77e784da614..757ae16700c 100644 --- a/corelib/src/ops/range.cairo +++ b/corelib/src/ops/range.cairo @@ -172,6 +172,15 @@ pub impl RangeInclusiveOpImpl of RangeInclusiveOp { } } +impl RangeInclusiveDebug> of crate::fmt::Debug> { + fn fmt(self: @RangeInclusive, ref f: crate::fmt::Formatter) -> Result<(), crate::fmt::Error> { + self.start.fmt(ref f)?; + write!(f, "..=")?; + self.end.fmt(ref f)?; + Result::Ok(()) + } +} + impl RangeInclusiveIteratorImpl< T, +One, +Add, +Copy, +Drop, +PartialEq, +PartialOrd, > of Iterator> { From ed97fe92b2ff84ba06b1c6cfee3dc4762ce71e57 Mon Sep 17 00:00:00 2001 From: cairoIover <193099744+cairoIover@users.noreply.github.com> Date: Thu, 9 Jan 2025 14:13:07 +0100 Subject: [PATCH 06/12] remove SierraIntRangeSupport --- corelib/src/ops/range.cairo | 1 - 1 file changed, 1 deletion(-) diff --git a/corelib/src/ops/range.cairo b/corelib/src/ops/range.cairo index 757ae16700c..ba7815c30c7 100644 --- a/corelib/src/ops/range.cairo +++ b/corelib/src/ops/range.cairo @@ -213,7 +213,6 @@ pub impl RangeInclusiveIntoIterator< +Drop, +PartialEq, +PartialOrd, - -SierraIntRangeSupport, > of IntoIterator> { type IntoIter = RangeInclusiveIterator; From 5cbbf440218296d6f49b6c98ec769cb84dcf9f8d Mon Sep 17 00:00:00 2001 From: cairoIover <193099744+cairoIover@users.noreply.github.com> Date: Thu, 9 Jan 2025 14:18:09 +0100 Subject: [PATCH 07/12] rebase reordering --- corelib/src/ops.cairo | 14 +++++++------- corelib/src/ops/range.cairo | 16 +++++++--------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/corelib/src/ops.cairo b/corelib/src/ops.cairo index 1f918fd47cb..9f0d882fd29 100644 --- a/corelib/src/ops.cairo +++ b/corelib/src/ops.cairo @@ -56,18 +56,18 @@ mod arith; pub use arith::{AddAssign, DivAssign, MulAssign, RemAssign, SubAssign}; mod deref; +pub use deref::Deref; #[feature("deref_mut")] pub use deref::DerefMut; -pub use deref::Deref; - -mod range; -pub use range::{Range, RangeInclusive, RangeInclusiveIterator, RangeIterator, RangeTrait}; -// `RangeOp` and `RangeInclusiveOp` are used internally by the compiler. -#[allow(unused_imports)] -use range::{RangeInclusiveOp, RangeOp}; mod function; pub use function::{Fn, FnOnce}; pub mod index; pub use index::{Index, IndexView}; + +mod range; +// `RangeOp` and `RangeInclusiveOp` are used internally by the compiler. +#[allow(unused_imports)] +use range::{RangeInclusiveOp, RangeOp}; +pub use range::{Range, RangeInclusive, RangeInclusiveIterator, RangeIterator, RangeTrait}; diff --git a/corelib/src/ops/range.cairo b/corelib/src/ops/range.cairo index ba7815c30c7..2ace1050e62 100644 --- a/corelib/src/ops/range.cairo +++ b/corelib/src/ops/range.cairo @@ -172,8 +172,12 @@ pub impl RangeInclusiveOpImpl of RangeInclusiveOp { } } -impl RangeInclusiveDebug> of crate::fmt::Debug> { - fn fmt(self: @RangeInclusive, ref f: crate::fmt::Formatter) -> Result<(), crate::fmt::Error> { +impl RangeInclusiveDebug< + T, impl TDebug: crate::fmt::Debug, +> of crate::fmt::Debug> { + fn fmt( + self: @RangeInclusive, ref f: crate::fmt::Formatter, + ) -> Result<(), crate::fmt::Error> { self.start.fmt(ref f)?; write!(f, "..=")?; self.end.fmt(ref f)?; @@ -206,13 +210,7 @@ impl RangeInclusiveIteratorImpl< } pub impl RangeInclusiveIntoIterator< - T, - +One, - +Add, - +Copy, - +Drop, - +PartialEq, - +PartialOrd, + T, +One, +Add, +Copy, +Drop, +PartialEq, +PartialOrd, > of IntoIterator> { type IntoIter = RangeInclusiveIterator; From 447ead8ad06a8cc970c118816366aac3bc222931 Mon Sep 17 00:00:00 2001 From: cairoIover <193099744+cairoIover@users.noreply.github.com> Date: Mon, 13 Jan 2025 11:34:46 +0100 Subject: [PATCH 08/12] re-gen syntax, typos fix, format --- corelib/src/ops.cairo | 2 +- corelib/src/ops/range.cairo | 2 +- crates/cairo-lang-syntax/src/node/ast.rs | 1 + crates/cairo-lang-syntax/src/node/key_fields.rs | 6 ++++++ crates/cairo-lang-syntax/src/node/kind.rs | 1 + 5 files changed, 10 insertions(+), 2 deletions(-) diff --git a/corelib/src/ops.cairo b/corelib/src/ops.cairo index 9f0d882fd29..ca4c975d53f 100644 --- a/corelib/src/ops.cairo +++ b/corelib/src/ops.cairo @@ -67,7 +67,7 @@ pub mod index; pub use index::{Index, IndexView}; mod range; +pub use range::{Range, RangeInclusive, RangeInclusiveIterator, RangeIterator, RangeTrait}; // `RangeOp` and `RangeInclusiveOp` are used internally by the compiler. #[allow(unused_imports)] use range::{RangeInclusiveOp, RangeOp}; -pub use range::{Range, RangeInclusive, RangeInclusiveIterator, RangeIterator, RangeTrait}; diff --git a/corelib/src/ops/range.cairo b/corelib/src/ops/range.cairo index 2ace1050e62..7645203fbf0 100644 --- a/corelib/src/ops/range.cairo +++ b/corelib/src/ops/range.cairo @@ -159,7 +159,7 @@ pub struct RangeInclusiveIterator { // - `false` when iteration has yielded an element and the iterator is not exhausted // - `true` when iteration has been used to exhaust the iterator // - // This is required to differentiate bewteen the last element and the end of the range. + // This is required to differentiate between the last element and the end of the range. pub(crate) exhausted: bool, } diff --git a/crates/cairo-lang-syntax/src/node/ast.rs b/crates/cairo-lang-syntax/src/node/ast.rs index 4824d57bebf..4110af210a2 100644 --- a/crates/cairo-lang-syntax/src/node/ast.rs +++ b/crates/cairo-lang-syntax/src/node/ast.rs @@ -12357,6 +12357,7 @@ impl From<&OptionTerminalConst> for SyntaxStablePtrId { } impl OptionTerminalConst { /// Checks if a kind of a variant of [OptionTerminalConst]. + pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::OptionTerminalConstEmpty | SyntaxKind::TerminalConst) } diff --git a/crates/cairo-lang-syntax/src/node/key_fields.rs b/crates/cairo-lang-syntax/src/node/key_fields.rs index 025ad081e3d..94e4ea6b6f9 100644 --- a/crates/cairo-lang-syntax/src/node/key_fields.rs +++ b/crates/cairo-lang-syntax/src/node/key_fields.rs @@ -1,10 +1,16 @@ // Autogenerated file. To regenerate, please run `cargo run --bin generate-syntax`. + use super::ids::GreenId; use super::kind::SyntaxKind; + /// Gets the vector of children ids that are the indexing key for this SyntaxKind. + /// + /// Each SyntaxKind has some children that are defined in the spec to be its indexing key + /// for its stable pointer. See [super::stable_ptr]. + pub fn get_key_fields(kind: SyntaxKind, children: &[GreenId]) -> Vec { match kind { SyntaxKind::Trivia => vec![], diff --git a/crates/cairo-lang-syntax/src/node/kind.rs b/crates/cairo-lang-syntax/src/node/kind.rs index de170ed12a9..d2136eae609 100644 --- a/crates/cairo-lang-syntax/src/node/kind.rs +++ b/crates/cairo-lang-syntax/src/node/kind.rs @@ -1,4 +1,5 @@ // Autogenerated file. To regenerate, please run `cargo run --bin generate-syntax`. + use core::fmt; #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] pub enum SyntaxKind { From 2aae0e78a73b37faec8668069c60af1be4249398 Mon Sep 17 00:00:00 2001 From: cairoIover <193099744+cairoIover@users.noreply.github.com> Date: Mon, 13 Jan 2025 11:35:43 +0100 Subject: [PATCH 09/12] fmt generated file --- crates/cairo-lang-syntax/src/node/key_fields.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/crates/cairo-lang-syntax/src/node/key_fields.rs b/crates/cairo-lang-syntax/src/node/key_fields.rs index 94e4ea6b6f9..9aa1ecc5472 100644 --- a/crates/cairo-lang-syntax/src/node/key_fields.rs +++ b/crates/cairo-lang-syntax/src/node/key_fields.rs @@ -1,16 +1,11 @@ // Autogenerated file. To regenerate, please run `cargo run --bin generate-syntax`. - use super::ids::GreenId; use super::kind::SyntaxKind; /// Gets the vector of children ids that are the indexing key for this SyntaxKind. - /// - /// Each SyntaxKind has some children that are defined in the spec to be its indexing key - /// for its stable pointer. See [super::stable_ptr]. - pub fn get_key_fields(kind: SyntaxKind, children: &[GreenId]) -> Vec { match kind { SyntaxKind::Trivia => vec![], From fdf1ca38e6ca74a9ae1b1dd14c4ce009dbbaf29b Mon Sep 17 00:00:00 2001 From: cairoIover <193099744+cairoIover@users.noreply.github.com> Date: Mon, 13 Jan 2025 12:11:00 +0100 Subject: [PATCH 10/12] rebased --- crates/cairo-lang-syntax/src/node/ast.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/crates/cairo-lang-syntax/src/node/ast.rs b/crates/cairo-lang-syntax/src/node/ast.rs index 4110af210a2..1a020780079 100644 --- a/crates/cairo-lang-syntax/src/node/ast.rs +++ b/crates/cairo-lang-syntax/src/node/ast.rs @@ -3149,6 +3149,9 @@ impl TypedSyntaxNode for BinaryOperator { SyntaxKind::TerminalDotDot => { Some(BinaryOperator::DotDot(TerminalDotDot::from_syntax_node(db, node))) } + SyntaxKind::TerminalDotDotEq => { + Some(BinaryOperator::DotDotEq(TerminalDotDotEq::from_syntax_node(db, node))) + } _ => None, } } @@ -30299,6 +30302,12 @@ impl TypedSyntaxNode for TokenDotDotEq { } } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + match node.0.green.lookup_intern(db).details { + GreenNodeDetails::Token(_) => Some(Self { node }), + GreenNodeDetails::Node { .. } => None, + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -30401,6 +30410,14 @@ impl TypedSyntaxNode for TerminalDotDotEq { let children = db.get_children(node.clone()); Self { node, children } } + fn cast(db: &dyn SyntaxGroup, node: SyntaxNode) -> Option { + let kind = node.kind(db); + if kind == SyntaxKind::TerminalDotDotEq { + Some(Self::from_syntax_node(db, node)) + } else { + None + } + } fn as_syntax_node(&self) -> SyntaxNode { self.node.clone() } @@ -38579,6 +38596,9 @@ impl TypedSyntaxNode for TokenNode { SyntaxKind::TerminalDotDot => { Some(TokenNode::TerminalDotDot(TerminalDotDot::from_syntax_node(db, node))) } + SyntaxKind::TerminalDotDotEq => { + Some(TokenNode::TerminalDotDotEq(TerminalDotDotEq::from_syntax_node(db, node))) + } SyntaxKind::TerminalEndOfFile => { Some(TokenNode::TerminalEndOfFile(TerminalEndOfFile::from_syntax_node(db, node))) } From 216a4a3cb8af5ef558229cb72de20acdb0e9babf Mon Sep 17 00:00:00 2001 From: cairoIover <193099744+cairoIover@users.noreply.github.com> Date: Mon, 13 Jan 2025 12:33:23 +0100 Subject: [PATCH 11/12] re-generated syntax with correct rust env --- crates/cairo-lang-syntax/src/node/ast.rs | 71 ------------------- .../cairo-lang-syntax/src/node/key_fields.rs | 1 - crates/cairo-lang-syntax/src/node/kind.rs | 1 - 3 files changed, 73 deletions(-) diff --git a/crates/cairo-lang-syntax/src/node/ast.rs b/crates/cairo-lang-syntax/src/node/ast.rs index 1a020780079..4886be1c05c 100644 --- a/crates/cairo-lang-syntax/src/node/ast.rs +++ b/crates/cairo-lang-syntax/src/node/ast.rs @@ -1,5 +1,4 @@ // Autogenerated file. To regenerate, please run `cargo run --bin generate-syntax`. - #![allow(clippy::match_single_binding)] #![allow(clippy::too_many_arguments)] #![allow(dead_code)] @@ -18,14 +17,12 @@ use super::{ GreenId, GreenNode, SyntaxGroup, SyntaxNode, SyntaxStablePtr, SyntaxStablePtrId, Terminal, Token, TypedStablePtr, TypedSyntaxNode, }; - #[path = "ast_ext.rs"] mod ast_ext; #[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct Trivia(ElementList); impl Deref for Trivia { type Target = ElementList; - fn deref(&self) -> &Self::Target { &self.0 } @@ -271,7 +268,6 @@ impl From<&Trivium> for SyntaxStablePtrId { } impl Trivium { /// Checks if a kind of a variant of [Trivium]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -734,7 +730,6 @@ impl From<&Expr> for SyntaxStablePtrId { } impl Expr { /// Checks if a kind of a variant of [Expr]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -770,7 +765,6 @@ impl Expr { pub struct ExprList(ElementList); impl Deref for ExprList { type Target = ElementList; - fn deref(&self) -> &Self::Target { &self.0 } @@ -1073,7 +1067,6 @@ impl From<&ArgClause> for SyntaxStablePtrId { } impl ArgClause { /// Checks if a kind of a variant of [ArgClause]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -1482,7 +1475,6 @@ impl From<&ExprFieldInitShorthand> for SyntaxStablePtrId { pub struct ArgList(ElementList); impl Deref for ArgList { type Target = ElementList; - fn deref(&self) -> &Self::Target { &self.0 } @@ -1747,7 +1739,6 @@ impl From<&PathSegment> for SyntaxStablePtrId { } impl PathSegment { /// Checks if a kind of a variant of [PathSegment]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::PathSegmentWithGenericArgs | SyntaxKind::PathSegmentSimple) } @@ -1940,7 +1931,6 @@ impl From<&OptionTerminalColonColon> for SyntaxStablePtrId { } impl OptionTerminalColonColon { /// Checks if a kind of a variant of [OptionTerminalColonColon]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::OptionTerminalColonColonEmpty | SyntaxKind::TerminalColonColon) } @@ -2140,7 +2130,6 @@ impl From<&PathSegmentWithGenericArgs> for SyntaxStablePtrId { pub struct ExprPath(ElementList); impl Deref for ExprPath { type Target = ElementList; - fn deref(&self) -> &Self::Target { &self.0 } @@ -2583,7 +2572,6 @@ impl From<&UnaryOperator> for SyntaxStablePtrId { } impl UnaryOperator { /// Checks if a kind of a variant of [UnaryOperator]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -3196,7 +3184,6 @@ impl From<&BinaryOperator> for SyntaxStablePtrId { } impl BinaryOperator { /// Checks if a kind of a variant of [BinaryOperator]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -3640,7 +3627,6 @@ impl From<&OptionArgListParenthesized> for SyntaxStablePtrId { } impl OptionArgListParenthesized { /// Checks if a kind of a variant of [OptionArgListParenthesized]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -4162,7 +4148,6 @@ impl From<&ExprMatch> for SyntaxStablePtrId { pub struct MatchArms(ElementList); impl Deref for MatchArms { type Target = ElementList; - fn deref(&self) -> &Self::Target { &self.0 } @@ -4562,7 +4547,6 @@ impl From<&Condition> for SyntaxStablePtrId { } impl Condition { /// Checks if a kind of a variant of [Condition]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::ConditionLet | SyntaxKind::ConditionExpr) } @@ -4851,7 +4835,6 @@ impl From<&BlockOrIf> for SyntaxStablePtrId { } impl BlockOrIf { /// Checks if a kind of a variant of [BlockOrIf]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::ExprBlock | SyntaxKind::ExprIf) } @@ -5377,7 +5360,6 @@ impl From<&OptionElseClause> for SyntaxStablePtrId { } impl OptionElseClause { /// Checks if a kind of a variant of [OptionElseClause]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::OptionElseClauseEmpty | SyntaxKind::ElseClause) } @@ -6089,7 +6071,6 @@ impl From<&OptionFixedSizeArraySize> for SyntaxStablePtrId { } impl OptionFixedSizeArraySize { /// Checks if a kind of a variant of [OptionFixedSizeArraySize]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::OptionFixedSizeArraySizeEmpty | SyntaxKind::FixedSizeArraySize) } @@ -6381,7 +6362,6 @@ impl From<&ClosureParamWrapper> for SyntaxStablePtrId { } impl ClosureParamWrapper { /// Checks if a kind of a variant of [ClosureParamWrapper]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::TerminalOrOr | SyntaxKind::ClosureParamWrapperNAry) } @@ -6687,7 +6667,6 @@ impl From<&OptionStructArgExpr> for SyntaxStablePtrId { } impl OptionStructArgExpr { /// Checks if a kind of a variant of [OptionStructArgExpr]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::OptionStructArgExprEmpty | SyntaxKind::StructArgExpr) } @@ -7076,7 +7055,6 @@ impl From<&StructArg> for SyntaxStablePtrId { } impl StructArg { /// Checks if a kind of a variant of [StructArg]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::StructArgSingle | SyntaxKind::StructArgTail) } @@ -7085,7 +7063,6 @@ impl StructArg { pub struct StructArgList(ElementList); impl Deref for StructArgList { type Target = ElementList; - fn deref(&self) -> &Self::Target { &self.0 } @@ -7529,7 +7506,6 @@ impl From<&WrappedArgList> for SyntaxStablePtrId { } impl WrappedArgList { /// Checks if a kind of a variant of [WrappedArgList]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -7878,7 +7854,6 @@ impl From<&Pattern> for SyntaxStablePtrId { } impl Pattern { /// Checks if a kind of a variant of [Pattern]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -8123,7 +8098,6 @@ impl From<&PatternStruct> for SyntaxStablePtrId { pub struct PatternStructParamList(ElementList); impl Deref for PatternStructParamList { type Target = ElementList; - fn deref(&self) -> &Self::Target { &self.0 } @@ -8438,7 +8412,6 @@ impl From<&PatternFixedSizeArray> for SyntaxStablePtrId { pub struct PatternList(ElementList); impl Deref for PatternList { type Target = ElementList; - fn deref(&self) -> &Self::Target { &self.0 } @@ -8541,7 +8514,6 @@ impl From<&PatternList> for SyntaxStablePtrId { pub struct PatternListOr(ElementList); impl Deref for PatternListOr { type Target = ElementList; - fn deref(&self) -> &Self::Target { &self.0 } @@ -8752,7 +8724,6 @@ impl From<&PatternStructParam> for SyntaxStablePtrId { } impl PatternStructParam { /// Checks if a kind of a variant of [PatternStructParam]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -9182,7 +9153,6 @@ impl From<&OptionPatternEnumInnerPattern> for SyntaxStablePtrId { } impl OptionPatternEnumInnerPattern { /// Checks if a kind of a variant of [OptionPatternEnumInnerPattern]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -9462,7 +9432,6 @@ impl From<&OptionTypeClause> for SyntaxStablePtrId { } impl OptionTypeClause { /// Checks if a kind of a variant of [OptionTypeClause]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::OptionTypeClauseEmpty | SyntaxKind::TypeClause) } @@ -9743,7 +9712,6 @@ impl From<&OptionReturnTypeClause> for SyntaxStablePtrId { } impl OptionReturnTypeClause { /// Checks if a kind of a variant of [OptionReturnTypeClause]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::OptionReturnTypeClauseEmpty | SyntaxKind::ReturnTypeClause) } @@ -10006,7 +9974,6 @@ impl From<&Statement> for SyntaxStablePtrId { } impl Statement { /// Checks if a kind of a variant of [Statement]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -10024,7 +9991,6 @@ impl Statement { pub struct StatementList(ElementList); impl Deref for StatementList { type Target = ElementList; - fn deref(&self) -> &Self::Target { &self.0 } @@ -10412,7 +10378,6 @@ impl From<&OptionTerminalSemicolon> for SyntaxStablePtrId { } impl OptionTerminalSemicolon { /// Checks if a kind of a variant of [OptionTerminalSemicolon]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::OptionTerminalSemicolonEmpty | SyntaxKind::TerminalSemicolon) } @@ -10897,7 +10862,6 @@ impl From<&OptionExprClause> for SyntaxStablePtrId { } impl OptionExprClause { /// Checks if a kind of a variant of [OptionExprClause]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::OptionExprClauseEmpty | SyntaxKind::ExprClause) } @@ -11421,7 +11385,6 @@ impl From<&Param> for SyntaxStablePtrId { pub struct ModifierList(ElementList); impl Deref for ModifierList { type Target = ElementList; - fn deref(&self) -> &Self::Target { &self.0 } @@ -11577,7 +11540,6 @@ impl From<&Modifier> for SyntaxStablePtrId { } impl Modifier { /// Checks if a kind of a variant of [Modifier]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::TerminalRef | SyntaxKind::TerminalMut) } @@ -11586,7 +11548,6 @@ impl Modifier { pub struct ParamList(ElementList); impl Deref for ParamList { type Target = ElementList; - fn deref(&self) -> &Self::Target { &self.0 } @@ -11803,7 +11764,6 @@ impl From<&ImplicitsClause> for SyntaxStablePtrId { pub struct ImplicitsList(ElementList); impl Deref for ImplicitsList { type Target = ElementList; - fn deref(&self) -> &Self::Target { &self.0 } @@ -11996,7 +11956,6 @@ impl From<&OptionImplicitsClause> for SyntaxStablePtrId { } impl OptionImplicitsClause { /// Checks if a kind of a variant of [OptionImplicitsClause]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::OptionImplicitsClauseEmpty | SyntaxKind::ImplicitsClause) } @@ -12178,7 +12137,6 @@ impl From<&OptionTerminalNoPanic> for SyntaxStablePtrId { } impl OptionTerminalNoPanic { /// Checks if a kind of a variant of [OptionTerminalNoPanic]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::OptionTerminalNoPanicEmpty | SyntaxKind::TerminalNoPanic) } @@ -12360,7 +12318,6 @@ impl From<&OptionTerminalConst> for SyntaxStablePtrId { } impl OptionTerminalConst { /// Checks if a kind of a variant of [OptionTerminalConst]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::OptionTerminalConstEmpty | SyntaxKind::TerminalConst) } @@ -12704,7 +12661,6 @@ impl From<&Member> for SyntaxStablePtrId { pub struct MemberList(ElementList); impl Deref for MemberList { type Target = ElementList; - fn deref(&self) -> &Self::Target { &self.0 } @@ -12920,7 +12876,6 @@ impl From<&Variant> for SyntaxStablePtrId { pub struct VariantList(ElementList); impl Deref for VariantList { type Target = ElementList; - fn deref(&self) -> &Self::Target { &self.0 } @@ -13324,7 +13279,6 @@ impl From<&ModuleItem> for SyntaxStablePtrId { } impl ModuleItem { /// Checks if a kind of a variant of [ModuleItem]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -13350,7 +13304,6 @@ impl ModuleItem { pub struct ModuleItemList(ElementList); impl Deref for ModuleItemList { type Target = ElementList; - fn deref(&self) -> &Self::Target { &self.0 } @@ -13626,7 +13579,6 @@ impl From<&Attribute> for SyntaxStablePtrId { pub struct AttributeList(ElementList); impl Deref for AttributeList { type Target = ElementList; - fn deref(&self) -> &Self::Target { &self.0 } @@ -13992,7 +13944,6 @@ impl From<&OptionVisibilityPubArgumentClause> for SyntaxStablePtrId { } impl OptionVisibilityPubArgumentClause { /// Checks if a kind of a variant of [OptionVisibilityPubArgumentClause]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -14276,7 +14227,6 @@ impl From<&Visibility> for SyntaxStablePtrId { } impl Visibility { /// Checks if a kind of a variant of [Visibility]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::VisibilityDefault | SyntaxKind::VisibilityPub) } @@ -14497,7 +14447,6 @@ impl From<&MaybeModuleBody> for SyntaxStablePtrId { } impl MaybeModuleBody { /// Checks if a kind of a variant of [MaybeModuleBody]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::ModuleBody | SyntaxKind::TerminalSemicolon) } @@ -15513,7 +15462,6 @@ impl From<&MaybeTraitBody> for SyntaxStablePtrId { } impl MaybeTraitBody { /// Checks if a kind of a variant of [MaybeTraitBody]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::TraitBody | SyntaxKind::TerminalSemicolon) } @@ -15626,7 +15574,6 @@ impl From<&TraitBody> for SyntaxStablePtrId { pub struct TraitItemList(ElementList); impl Deref for TraitItemList { type Target = ElementList; - fn deref(&self) -> &Self::Target { &self.0 } @@ -15840,7 +15787,6 @@ impl From<&TraitItem> for SyntaxStablePtrId { } impl TraitItem { /// Checks if a kind of a variant of [TraitItem]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -16542,7 +16488,6 @@ impl From<&MaybeTraitFunctionBody> for SyntaxStablePtrId { } impl MaybeTraitFunctionBody { /// Checks if a kind of a variant of [MaybeTraitFunctionBody]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::ExprBlock | SyntaxKind::TerminalSemicolon) } @@ -16997,7 +16942,6 @@ impl From<&MaybeImplBody> for SyntaxStablePtrId { } impl MaybeImplBody { /// Checks if a kind of a variant of [MaybeImplBody]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::ImplBody | SyntaxKind::TerminalSemicolon) } @@ -17110,7 +17054,6 @@ impl From<&ImplBody> for SyntaxStablePtrId { pub struct ImplItemList(ElementList); impl Deref for ImplItemList { type Target = ElementList; - fn deref(&self) -> &Self::Target { &self.0 } @@ -17434,7 +17377,6 @@ impl From<&ImplItem> for SyntaxStablePtrId { } impl ImplItem { /// Checks if a kind of a variant of [ImplItem]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -18393,7 +18335,6 @@ impl From<&UsePath> for SyntaxStablePtrId { } impl UsePath { /// Checks if a kind of a variant of [UsePath]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -18819,7 +18760,6 @@ impl From<&UsePathStar> for SyntaxStablePtrId { pub struct UsePathList(ElementList); impl Deref for UsePathList { type Target = ElementList; - fn deref(&self) -> &Self::Target { &self.0 } @@ -19116,7 +19056,6 @@ impl From<&OptionAliasClause> for SyntaxStablePtrId { } impl OptionAliasClause { /// Checks if a kind of a variant of [OptionAliasClause]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::OptionAliasClauseEmpty | SyntaxKind::AliasClause) } @@ -19295,7 +19234,6 @@ impl From<&GenericArg> for SyntaxStablePtrId { } impl GenericArg { /// Checks if a kind of a variant of [GenericArg]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::GenericArgUnnamed | SyntaxKind::GenericArgNamed) } @@ -19592,7 +19530,6 @@ impl From<&GenericArgValue> for SyntaxStablePtrId { } impl GenericArgValue { /// Checks if a kind of a variant of [GenericArgValue]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::GenericArgValueExpr | SyntaxKind::TerminalUnderscore) } @@ -19796,7 +19733,6 @@ impl From<&GenericArgs> for SyntaxStablePtrId { pub struct GenericArgList(ElementList); impl Deref for GenericArgList { type Target = ElementList; - fn deref(&self) -> &Self::Target { &self.0 } @@ -20118,7 +20054,6 @@ impl From<&AssociatedItemConstraints> for SyntaxStablePtrId { pub struct AssociatedItemConstraintList(ElementList); impl Deref for AssociatedItemConstraintList { type Target = ElementList; - fn deref(&self) -> &Self::Target { &self.0 } @@ -20319,7 +20254,6 @@ impl From<&OptionAssociatedItemConstraints> for SyntaxStablePtrId { } impl OptionAssociatedItemConstraints { /// Checks if a kind of a variant of [OptionAssociatedItemConstraints]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -20512,7 +20446,6 @@ impl From<&OptionWrappedGenericParamList> for SyntaxStablePtrId { } impl OptionWrappedGenericParamList { /// Checks if a kind of a variant of [OptionWrappedGenericParamList]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -20715,7 +20648,6 @@ impl From<&WrappedGenericParamList> for SyntaxStablePtrId { pub struct GenericParamList(ElementList); impl Deref for GenericParamList { type Target = ElementList; - fn deref(&self) -> &Self::Target { &self.0 } @@ -20959,7 +20891,6 @@ impl From<&GenericParam> for SyntaxStablePtrId { } impl GenericParam { /// Checks if a kind of a variant of [GenericParam]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, @@ -21713,7 +21644,6 @@ impl From<&SkippedNode> for SyntaxStablePtrId { } impl SkippedNode { /// Checks if a kind of a variant of [SkippedNode]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!(kind, SyntaxKind::AttributeList | SyntaxKind::VisibilityPub) } @@ -38795,7 +38725,6 @@ impl From<&TokenNode> for SyntaxStablePtrId { } impl TokenNode { /// Checks if a kind of a variant of [TokenNode]. - pub fn is_variant(kind: SyntaxKind) -> bool { matches!( kind, diff --git a/crates/cairo-lang-syntax/src/node/key_fields.rs b/crates/cairo-lang-syntax/src/node/key_fields.rs index 9aa1ecc5472..025ad081e3d 100644 --- a/crates/cairo-lang-syntax/src/node/key_fields.rs +++ b/crates/cairo-lang-syntax/src/node/key_fields.rs @@ -1,7 +1,6 @@ // Autogenerated file. To regenerate, please run `cargo run --bin generate-syntax`. use super::ids::GreenId; use super::kind::SyntaxKind; - /// Gets the vector of children ids that are the indexing key for this SyntaxKind. /// /// Each SyntaxKind has some children that are defined in the spec to be its indexing key diff --git a/crates/cairo-lang-syntax/src/node/kind.rs b/crates/cairo-lang-syntax/src/node/kind.rs index d2136eae609..de170ed12a9 100644 --- a/crates/cairo-lang-syntax/src/node/kind.rs +++ b/crates/cairo-lang-syntax/src/node/kind.rs @@ -1,5 +1,4 @@ // Autogenerated file. To regenerate, please run `cargo run --bin generate-syntax`. - use core::fmt; #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] pub enum SyntaxKind { From 4ed347ae79e8ac4efde174f6a7b6dc0699424595 Mon Sep 17 00:00:00 2001 From: cairoIover <193099744+cairoIover@users.noreply.github.com> Date: Mon, 13 Jan 2025 15:56:22 +0100 Subject: [PATCH 12/12] 'dotdot' requires separator when combined with 'eq' --- crates/cairo-lang-parser/src/lexer_test.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/cairo-lang-parser/src/lexer_test.rs b/crates/cairo-lang-parser/src/lexer_test.rs index 0e9acfd1d02..a374a3d67f0 100644 --- a/crates/cairo-lang-parser/src/lexer_test.rs +++ b/crates/cairo-lang-parser/src/lexer_test.rs @@ -220,7 +220,7 @@ fn need_separator( || (text0 == "." && text1.starts_with('.')) || (text0 == "-" && (text1.starts_with('>') || text1.starts_with('='))) || ((text0 == "+" || text0 == "*" || text0 == "/" || text0 == "%") - && text1.starts_with('=')) + || (text0 == "..") && text1.starts_with('=')) || (kind0 == SyntaxKind::TerminalLiteralNumber && kind0 == kind1) { return true; @@ -297,7 +297,6 @@ fn test_lex_double_token() { for separator in separators { let text = format!("{text0}{separator}{text1}"); let mut lexer = Lexer::from_text(db, text.as_str()); - let terminal = lexer.next().unwrap(); let token_text = terminal.text; assert_eq!(