cairo-lang-parser 2.18.0

Cairo parser.
Documentation
//! > Test +=, -=, *=, /=, %=

//! > test_runner_name
test_partial_parser_tree(expect_diagnostics: false)

//! > cairo_code
fn foo() {
    let mut x = 3;
    x += 5;
    x -= 5;
    x *= 5;
    x /= 5;
    x %= 5;
    x = 5;
}

//! > top_level_kind
StatementList

//! > ignored_kinds
StatementLet

//! > expected_diagnostics

//! > expected_tree
└── Top level kind: StatementList
    ├── child #0 (kind: StatementLet) <ignored>
    ├── child #1 (kind: StatementExpr)
    │   ├── attributes (kind: AttributeList) []
    │   ├── expr (kind: ExprBinary)
    │   │   ├── lhs (kind: ExprPath)
    │   │   │   ├── dollar (kind: OptionTerminalDollarEmpty) []
    │   │   │   └── segments (kind: ExprPathInner)
    │   │   │       └── item #0 (kind: PathSegmentSimple)
    │   │   │           └── ident (kind: TokenIdentifier): 'x'
    │   │   ├── op (kind: TokenPlusEq): '+='
    │   │   └── rhs (kind: TokenLiteralNumber): '5'
    │   └── semicolon (kind: TokenSemicolon): ';'
    ├── child #2 (kind: StatementExpr)
    │   ├── attributes (kind: AttributeList) []
    │   ├── expr (kind: ExprBinary)
    │   │   ├── lhs (kind: ExprPath)
    │   │   │   ├── dollar (kind: OptionTerminalDollarEmpty) []
    │   │   │   └── segments (kind: ExprPathInner)
    │   │   │       └── item #0 (kind: PathSegmentSimple)
    │   │   │           └── ident (kind: TokenIdentifier): 'x'
    │   │   ├── op (kind: TokenMinusEq): '-='
    │   │   └── rhs (kind: TokenLiteralNumber): '5'
    │   └── semicolon (kind: TokenSemicolon): ';'
    ├── child #3 (kind: StatementExpr)
    │   ├── attributes (kind: AttributeList) []
    │   ├── expr (kind: ExprBinary)
    │   │   ├── lhs (kind: ExprPath)
    │   │   │   ├── dollar (kind: OptionTerminalDollarEmpty) []
    │   │   │   └── segments (kind: ExprPathInner)
    │   │   │       └── item #0 (kind: PathSegmentSimple)
    │   │   │           └── ident (kind: TokenIdentifier): 'x'
    │   │   ├── op (kind: TokenMulEq): '*='
    │   │   └── rhs (kind: TokenLiteralNumber): '5'
    │   └── semicolon (kind: TokenSemicolon): ';'
    ├── child #4 (kind: StatementExpr)
    │   ├── attributes (kind: AttributeList) []
    │   ├── expr (kind: ExprBinary)
    │   │   ├── lhs (kind: ExprPath)
    │   │   │   ├── dollar (kind: OptionTerminalDollarEmpty) []
    │   │   │   └── segments (kind: ExprPathInner)
    │   │   │       └── item #0 (kind: PathSegmentSimple)
    │   │   │           └── ident (kind: TokenIdentifier): 'x'
    │   │   ├── op (kind: TokenDivEq): '/='
    │   │   └── rhs (kind: TokenLiteralNumber): '5'
    │   └── semicolon (kind: TokenSemicolon): ';'
    ├── child #5 (kind: StatementExpr)
    │   ├── attributes (kind: AttributeList) []
    │   ├── expr (kind: ExprBinary)
    │   │   ├── lhs (kind: ExprPath)
    │   │   │   ├── dollar (kind: OptionTerminalDollarEmpty) []
    │   │   │   └── segments (kind: ExprPathInner)
    │   │   │       └── item #0 (kind: PathSegmentSimple)
    │   │   │           └── ident (kind: TokenIdentifier): 'x'
    │   │   ├── op (kind: TokenModEq): '%='
    │   │   └── rhs (kind: TokenLiteralNumber): '5'
    │   └── semicolon (kind: TokenSemicolon): ';'
    └── child #6 (kind: StatementExpr)
        ├── attributes (kind: AttributeList) []
        ├── expr (kind: ExprBinary)
        │   ├── lhs (kind: ExprPath)
        │   │   ├── dollar (kind: OptionTerminalDollarEmpty) []
        │   │   └── segments (kind: ExprPathInner)
        │   │       └── item #0 (kind: PathSegmentSimple)
        │   │           └── ident (kind: TokenIdentifier): 'x'
        │   ├── op (kind: TokenEq): '='
        │   └── rhs (kind: TokenLiteralNumber): '5'
        └── semicolon (kind: TokenSemicolon): ';'

//! > ==========================================================================

//! > Test error of `+=` with `let`.

//! > test_runner_name
test_partial_parser_tree(expect_diagnostics: true)

//! > cairo_code
fn foo() {
    let x += 5;
}

//! > top_level_kind
StatementList

//! > ignored_kinds

//! > expected_diagnostics
error[E1001]: Missing token '='.
 --> dummy_file.cairo:2:10
    let x += 5;
         ^

error[E1002]: Missing tokens. Expected an expression.
 --> dummy_file.cairo:2:10
    let x += 5;
         ^

error[E1001]: Missing token ';'.
 --> dummy_file.cairo:2:10
    let x += 5;
         ^

error[E1000]: Skipped tokens. Expected: statement.
 --> dummy_file.cairo:2:11
    let x += 5;
          ^^

//! > expected_tree
└── Top level kind: StatementList
    ├── child #0 (kind: StatementLet)
    │   ├── attributes (kind: AttributeList) []
    │   ├── let_kw (kind: TokenLet): 'let'
    │   ├── pattern (kind: ExprPath)
    │   │   ├── dollar (kind: OptionTerminalDollarEmpty) []
    │   │   └── segments (kind: ExprPathInner)
    │   │       └── item #0 (kind: PathSegmentSimple)
    │   │           └── ident (kind: TokenIdentifier): 'x'
    │   ├── type_clause (kind: OptionTypeClauseEmpty) []
    │   ├── eq: Missing
    │   ├── rhs: Missing []
    │   ├── let_else_clause (kind: OptionLetElseClauseEmpty) []
    │   └── semicolon: Missing
    └── child #1 (kind: StatementExpr)
        ├── attributes (kind: AttributeList) []
        ├── expr (kind: TokenLiteralNumber): '5'
        └── semicolon (kind: TokenSemicolon): ';'