aboutsummaryrefslogtreecommitdiff
path: root/src/parser
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser')
-rw-r--r--src/parser/event_parser/grammar/items.rs8
-rw-r--r--src/parser/event_parser/grammar/mod.rs9
-rw-r--r--src/parser/event_parser/grammar/paths.rs15
3 files changed, 24 insertions, 8 deletions
diff --git a/src/parser/event_parser/grammar/items.rs b/src/parser/event_parser/grammar/items.rs
index e775db14b..950e02a4d 100644
--- a/src/parser/event_parser/grammar/items.rs
+++ b/src/parser/event_parser/grammar/items.rs
@@ -12,7 +12,7 @@ pub(super) fn mod_contents(p: &mut Parser) {
12 12
13fn item_first(p: &Parser) -> bool { 13fn item_first(p: &Parser) -> bool {
14 match p.current() { 14 match p.current() {
15 STRUCT_KW | FN_KW | EXTERN_KW | MOD_KW => true, 15 STRUCT_KW | FN_KW | EXTERN_KW | MOD_KW | USE_KW => true,
16 _ => false, 16 _ => false,
17 } 17 }
18} 18}
@@ -43,6 +43,7 @@ fn item(p: &mut Parser) -> bool {
43 // || node_if(p, TYPE_KW, TYPE_ITEM, type_item) 43 // || node_if(p, TYPE_KW, TYPE_ITEM, type_item)
44 node_if(p, [EXTERN_KW, CRATE_KW], EXTERN_CRATE_ITEM, extern_crate_item) 44 node_if(p, [EXTERN_KW, CRATE_KW], EXTERN_CRATE_ITEM, extern_crate_item)
45 || node_if(p, MOD_KW, MOD_ITEM, mod_item) 45 || node_if(p, MOD_KW, MOD_ITEM, mod_item)
46 || node_if(p, USE_KW, USE_ITEM, use_item)
46 || node_if(p, STRUCT_KW, STRUCT_ITEM, struct_item) 47 || node_if(p, STRUCT_KW, STRUCT_ITEM, struct_item)
47 || node_if(p, FN_KW, FN_ITEM, fn_item) 48 || node_if(p, FN_KW, FN_ITEM, fn_item)
48} 49}
@@ -66,6 +67,11 @@ fn mod_item(p: &mut Parser) {
66 p.curly_block(mod_contents); 67 p.curly_block(mod_contents);
67} 68}
68 69
70fn use_item(p: &mut Parser) {
71 paths::use_path(p);
72 p.expect(SEMI);
73}
74
69fn struct_field(p: &mut Parser) -> bool { 75fn struct_field(p: &mut Parser) -> bool {
70 node_if(p, IDENT, STRUCT_FIELD, |p| { 76 node_if(p, IDENT, STRUCT_FIELD, |p| {
71 p.expect(COLON) && p.expect(IDENT); 77 p.expect(COLON) && p.expect(IDENT);
diff --git a/src/parser/event_parser/grammar/mod.rs b/src/parser/event_parser/grammar/mod.rs
index 6d1cd7ec3..60458ce70 100644
--- a/src/parser/event_parser/grammar/mod.rs
+++ b/src/parser/event_parser/grammar/mod.rs
@@ -6,10 +6,11 @@ use syntax_kinds::*;
6mod items; 6mod items;
7mod attributes; 7mod attributes;
8mod expressions; 8mod expressions;
9mod paths;
9 10
10pub(crate) fn file(p: &mut Parser) { 11pub(crate) fn file(p: &mut Parser) {
11 node(p, FILE, |p| { 12 node(p, FILE, |p| {
12 p.optional(SHEBANG); 13 p.eat(SHEBANG);
13 items::mod_contents(p); 14 items::mod_contents(p);
14 }) 15 })
15} 16}
@@ -99,12 +100,6 @@ impl<'p> Parser<'p> {
99 } 100 }
100 } 101 }
101 102
102 fn optional(&mut self, kind: SyntaxKind) {
103 if self.current() == kind {
104 self.bump();
105 }
106 }
107
108 fn eat(&mut self, kind: SyntaxKind) -> bool { 103 fn eat(&mut self, kind: SyntaxKind) -> bool {
109 self.current() == kind && { self.bump(); true } 104 self.current() == kind && { self.bump(); true }
110 } 105 }
diff --git a/src/parser/event_parser/grammar/paths.rs b/src/parser/event_parser/grammar/paths.rs
new file mode 100644
index 000000000..96966b380
--- /dev/null
+++ b/src/parser/event_parser/grammar/paths.rs
@@ -0,0 +1,15 @@
1use super::*;
2
3pub(crate) fn use_path(p: &mut Parser) {
4 if !AnyOf(&[IDENT, COLONCOLON]).is_ahead(p) {
5 return;
6 }
7 node(p, PATH, |p| {
8 p.eat(COLONCOLON);
9 path_segment(p);
10 })
11}
12
13fn path_segment(p: &mut Parser) -> bool {
14 node_if(p, IDENT, PATH_SEGMENT, |p| ())
15} \ No newline at end of file