//! > Test an FunctionWithBody syntax tree
//! > test_runner_name
test_partial_parser_tree(expect_diagnostics: false)
//! > cairo_code
#[attr1]
#[with_args(arg1, arg2)]
#[attr2]
fn foo(a: int) -> felt252 {
return a;
}
//! > top_level_kind
FunctionWithBody
//! > ignored_kinds
ExprBlock
FunctionSignature
//! > expected_diagnostics
//! > expected_tree
└── Top level kind: FunctionWithBody
├── attributes (kind: AttributeList)
│ ├── child #0 (kind: Attribute)
│ │ ├── hash (kind: TokenHash): '#'
│ │ ├── lbrack (kind: TokenLBrack): '['
│ │ ├── attr (kind: ExprPath)
│ │ │ └── item #0 (kind: PathSegmentSimple)
│ │ │ └── ident (kind: TokenIdentifier): 'attr1'
│ │ ├── arguments (kind: OptionArgListParenthesizedEmpty) []
│ │ └── rbrack (kind: TokenRBrack): ']'
│ ├── child #1 (kind: Attribute)
│ │ ├── hash (kind: TokenHash): '#'
│ │ ├── lbrack (kind: TokenLBrack): '['
│ │ ├── attr (kind: ExprPath)
│ │ │ └── item #0 (kind: PathSegmentSimple)
│ │ │ └── ident (kind: TokenIdentifier): 'with_args'
│ │ ├── arguments (kind: ArgListParenthesized)
│ │ │ ├── lparen (kind: TokenLParen): '('
│ │ │ ├── arguments (kind: ArgList)
│ │ │ │ ├── item #0 (kind: Arg)
│ │ │ │ │ ├── modifiers (kind: ModifierList) []
│ │ │ │ │ └── arg_clause (kind: ArgClauseUnnamed)
│ │ │ │ │ └── value (kind: ExprPath)
│ │ │ │ │ └── item #0 (kind: PathSegmentSimple)
│ │ │ │ │ └── ident (kind: TokenIdentifier): 'arg1'
│ │ │ │ ├── separator #0 (kind: TokenComma): ','
│ │ │ │ └── item #1 (kind: Arg)
│ │ │ │ ├── modifiers (kind: ModifierList) []
│ │ │ │ └── arg_clause (kind: ArgClauseUnnamed)
│ │ │ │ └── value (kind: ExprPath)
│ │ │ │ └── item #0 (kind: PathSegmentSimple)
│ │ │ │ └── ident (kind: TokenIdentifier): 'arg2'
│ │ │ └── rparen (kind: TokenRParen): ')'
│ │ └── rbrack (kind: TokenRBrack): ']'
│ └── child #2 (kind: Attribute)
│ ├── hash (kind: TokenHash): '#'
│ ├── lbrack (kind: TokenLBrack): '['
│ ├── attr (kind: ExprPath)
│ │ └── item #0 (kind: PathSegmentSimple)
│ │ └── ident (kind: TokenIdentifier): 'attr2'
│ ├── arguments (kind: OptionArgListParenthesizedEmpty) []
│ └── rbrack (kind: TokenRBrack): ']'
├── visibility (kind: VisibilityDefault) []
├── declaration (kind: FunctionDeclaration)
│ ├── function_kw (kind: TokenFunction): 'fn'
│ ├── name (kind: TokenIdentifier): 'foo'
│ ├── generic_params (kind: OptionWrappedGenericParamListEmpty) []
│ └── signature (kind: FunctionSignature) <ignored>
└── body (kind: ExprBlock) <ignored>
//! > ==========================================================================
//! > Invalid tokens in return type.
//! > test_runner_name
test_partial_parser_tree(expect_diagnostics: true)
//! > cairo_code
fn foo() -> Aaaaa Bbb + Cc {
}
//! > top_level_kind
FunctionWithBody
//! > ignored_kinds
//! > expected_diagnostics
error: Skipped tokens. Expected: '{'.
--> dummy_file.cairo:1:20
fn foo() -> Aaaaa Bbb + Cc {
^******^
//! > expected_tree
└── Top level 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: ReturnTypeClause)
│ │ ├── arrow (kind: TokenArrow): '->'
│ │ └── ty (kind: ExprPath)
│ │ └── item #0 (kind: PathSegmentSimple)
│ │ └── ident (kind: TokenIdentifier): 'Aaaaa'
│ ├── implicits_clause (kind: OptionImplicitsClauseEmpty) []
│ └── optional_no_panic (kind: OptionTerminalNoPanicEmpty) []
└── body (kind: ExprBlock)
├── lbrace (kind: TokenLBrace): '{'
├── statements (kind: StatementList) []
└── rbrace (kind: TokenRBrace): '}'
//! > ==========================================================================
//! > Missing left brace
//! > test_runner_name
test_partial_parser_tree(expect_diagnostics: true)
//! > cairo_code
fn foo() -> Aaaaa Bbb + Cc; let x = 0; }
//! > top_level_kind
FunctionWithBody
//! > ignored_kinds
FunctionDeclaration
//! > expected_diagnostics
error: Skipped tokens. Expected: '{'.
--> dummy_file.cairo:1:20
fn foo() -> Aaaaa Bbb + Cc; let x = 0; }
^*******^
//! > expected_tree
└── Top level kind: FunctionWithBody
├── attributes (kind: AttributeList) []
├── visibility (kind: VisibilityDefault) []
├── declaration (kind: FunctionDeclaration) <ignored>
└── body (kind: ExprBlock)
├── lbrace: Missing
├── statements (kind: StatementList)
│ └── child #0 (kind: StatementLet)
│ ├── attributes (kind: AttributeList) []
│ ├── let_kw (kind: TokenLet): 'let'
│ ├── pattern (kind: ExprPath)
│ │ └── item #0 (kind: PathSegmentSimple)
│ │ └── ident (kind: TokenIdentifier): 'x'
│ ├── type_clause (kind: OptionTypeClauseEmpty) []
│ ├── eq (kind: TokenEq): '='
│ ├── rhs (kind: TokenLiteralNumber): '0'
│ └── semicolon (kind: TokenSemicolon): ';'
└── rbrace (kind: TokenRBrace): '}'