diff options
author | Aleksey Kladov <[email protected]> | 2018-01-09 20:32:18 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-01-09 20:32:18 +0000 |
commit | 5ea7e5fb7ab9f9ed762c8b5220ba01a29796a871 (patch) | |
tree | e67b91e3fe1d046d886bce5e896bb045e327169e /src/parser/event_parser/grammar | |
parent | 1544e89c49c67df00fc72d841f3e39be792cbe2b (diff) |
G: simplest use items
Diffstat (limited to 'src/parser/event_parser/grammar')
-rw-r--r-- | src/parser/event_parser/grammar/items.rs | 8 | ||||
-rw-r--r-- | src/parser/event_parser/grammar/mod.rs | 9 | ||||
-rw-r--r-- | src/parser/event_parser/grammar/paths.rs | 15 |
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 | ||
13 | fn item_first(p: &Parser) -> bool { | 13 | fn 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 | ||
70 | fn use_item(p: &mut Parser) { | ||
71 | paths::use_path(p); | ||
72 | p.expect(SEMI); | ||
73 | } | ||
74 | |||
69 | fn struct_field(p: &mut Parser) -> bool { | 75 | fn 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::*; | |||
6 | mod items; | 6 | mod items; |
7 | mod attributes; | 7 | mod attributes; |
8 | mod expressions; | 8 | mod expressions; |
9 | mod paths; | ||
9 | 10 | ||
10 | pub(crate) fn file(p: &mut Parser) { | 11 | pub(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 @@ | |||
1 | use super::*; | ||
2 | |||
3 | pub(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 | |||
13 | fn path_segment(p: &mut Parser) -> bool { | ||
14 | node_if(p, IDENT, PATH_SEGMENT, |p| ()) | ||
15 | } \ No newline at end of file | ||