Skip to content

Commit

Permalink
use items to parser (#6304)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomer-StarkWare authored Aug 29, 2024
1 parent 2750788 commit 037e731
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
6 changes: 6 additions & 0 deletions crates/cairo-lang-parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1996,6 +1996,12 @@ impl<'a> Parser<'a> {
.into(),
)
.into()),
SyntaxKind::TerminalUse => Ok(StatementItem::new_green(
self.db,
self.expect_item_use(attributes, VisibilityDefault::new_green(self.db).into())
.into(),
)
.into()),
_ => match self.try_parse_expr() {
Ok(expr) => {
let optional_semicolon = if self.peek().kind == SyntaxKind::TerminalSemicolon {
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-parser/src/parser_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ cairo_lang_test_utils::test_file_test!(
while_: "while",
for_: "for",
range: "range",
use_: "use",
},
test_partial_parser_tree
);
Expand Down
74 changes: 74 additions & 0 deletions crates/cairo-lang-parser/src/parser_test_data/partial_trees/use
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//! > Test use simple

//! > test_runner_name
test_partial_parser_tree(expect_diagnostics: false)

//! > cairo_code
fn foo() {
use X::Y;
}

//! > top_level_kind
ItemUse

//! > ignored_kinds

//! > expected_diagnostics

//! > expected_tree
└── Top level kind: ItemUse
├── attributes (kind: AttributeList) []
├── visibility (kind: VisibilityDefault) []
├── use_kw (kind: TokenUse): 'use'
├── use_path (kind: UsePathSingle)
│ ├── ident (kind: PathSegmentSimple)
│ │ └── ident (kind: TokenIdentifier): 'X'
│ ├── colon_colon (kind: TokenColonColon): '::'
│ └── use_path (kind: UsePathLeaf)
│ ├── ident (kind: PathSegmentSimple)
│ │ └── ident (kind: TokenIdentifier): 'Y'
│ └── alias_clause (kind: OptionAliasClauseEmpty) []
└── semicolon (kind: TokenSemicolon): ';'

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

//! > Test use attributes.

//! > test_runner_name
test_partial_parser_tree(expect_diagnostics: false)

//! > cairo_code
fn foo() {
#[attribute]
use X::Y;
}

//! > top_level_kind
ItemUse

//! > ignored_kinds

//! > expected_diagnostics

//! > expected_tree
└── Top level kind: ItemUse
├── attributes (kind: AttributeList)
│ └── child #0 (kind: Attribute)
│ ├── hash (kind: TokenHash): '#'
│ ├── lbrack (kind: TokenLBrack): '['
│ ├── attr (kind: ExprPath)
│ │ └── item #0 (kind: PathSegmentSimple)
│ │ └── ident (kind: TokenIdentifier): 'attribute'
│ ├── arguments (kind: OptionArgListParenthesizedEmpty) []
│ └── rbrack (kind: TokenRBrack): ']'
├── visibility (kind: VisibilityDefault) []
├── use_kw (kind: TokenUse): 'use'
├── use_path (kind: UsePathSingle)
│ ├── ident (kind: PathSegmentSimple)
│ │ └── ident (kind: TokenIdentifier): 'X'
│ ├── colon_colon (kind: TokenColonColon): '::'
│ └── use_path (kind: UsePathLeaf)
│ ├── ident (kind: PathSegmentSimple)
│ │ └── ident (kind: TokenIdentifier): 'Y'
│ └── alias_clause (kind: OptionAliasClauseEmpty) []
└── semicolon (kind: TokenSemicolon): ';'

0 comments on commit 037e731

Please sign in to comment.