diff options
Diffstat (limited to 'src/parser/event_parser/grammar/mod.rs')
-rw-r--r-- | src/parser/event_parser/grammar/mod.rs | 83 |
1 files changed, 29 insertions, 54 deletions
diff --git a/src/parser/event_parser/grammar/mod.rs b/src/parser/event_parser/grammar/mod.rs index 1097344c0..0c775bb25 100644 --- a/src/parser/event_parser/grammar/mod.rs +++ b/src/parser/event_parser/grammar/mod.rs | |||
@@ -10,37 +10,39 @@ mod types; | |||
10 | mod paths; | 10 | mod paths; |
11 | 11 | ||
12 | pub(crate) fn file(p: &mut Parser) { | 12 | pub(crate) fn file(p: &mut Parser) { |
13 | node(p, FILE, |p| { | 13 | p.start(FILE); |
14 | p.eat(SHEBANG); | 14 | p.eat(SHEBANG); |
15 | items::mod_contents(p); | 15 | items::mod_contents(p); |
16 | }) | 16 | p.finish() |
17 | } | 17 | } |
18 | 18 | ||
19 | fn visibility(p: &mut Parser) { | 19 | fn visibility(p: &mut Parser) { |
20 | node_if(p, PUB_KW, VISIBILITY, |p| { | 20 | if p.at(PUB_KW) { |
21 | if p.current() != L_PAREN { | 21 | p.start(VISIBILITY); |
22 | return | 22 | p.bump(); |
23 | } | 23 | if p.at(L_PAREN) { |
24 | match p.raw_lookahead(1) { | 24 | match p.raw_lookahead(1) { |
25 | CRATE_KW | SELF_KW | SUPER_KW => { | 25 | CRATE_KW | SELF_KW | SUPER_KW | IN_KW => { |
26 | p.bump(); | 26 | p.bump(); |
27 | p.bump(); | 27 | if p.bump() == IN_KW { |
28 | } | 28 | paths::use_path(p); |
29 | IN_KW => { | 29 | } |
30 | p.bump(); | 30 | p.expect(R_PAREN); |
31 | p.bump(); | 31 | } |
32 | paths::use_path(p); | 32 | _ => () |
33 | } | 33 | } |
34 | _ => return | ||
35 | } | 34 | } |
36 | p.expect(R_PAREN); | 35 | p.finish(); |
37 | }); | 36 | } |
38 | } | 37 | } |
39 | 38 | ||
40 | fn alias(p: &mut Parser) -> bool { | 39 | fn alias(p: &mut Parser) -> bool { |
41 | node_if(p, AS_KW, ALIAS, |p| { | 40 | if p.at(AS_KW) { |
41 | p.start(ALIAS); | ||
42 | p.bump(); | ||
42 | p.expect(IDENT); | 43 | p.expect(IDENT); |
43 | }); | 44 | p.finish(); |
45 | } | ||
44 | true //FIXME: return false if three are errors | 46 | true //FIXME: return false if three are errors |
45 | } | 47 | } |
46 | 48 | ||
@@ -92,40 +94,13 @@ fn comma_list<F: Fn(&mut Parser) -> bool>(p: &mut Parser, end: SyntaxKind, f: F) | |||
92 | } | 94 | } |
93 | 95 | ||
94 | 96 | ||
95 | fn skip_to_first<C, F>(p: &mut Parser, cond: C, f: F, message: &str) -> bool | 97 | impl<'p> Parser<'p> { |
96 | where | 98 | fn at(&self, kind: SyntaxKind) -> bool { |
97 | C: Fn(&Parser) -> bool, | 99 | self.current() == kind |
98 | F: FnOnce(&mut Parser), | ||
99 | { | ||
100 | let mut skipped = false; | ||
101 | loop { | ||
102 | if cond(p) { | ||
103 | if skipped { | ||
104 | p.finish(); | ||
105 | } | ||
106 | f(p); | ||
107 | return true; | ||
108 | } | ||
109 | if p.current() == EOF { | ||
110 | if skipped { | ||
111 | p.finish(); | ||
112 | } | ||
113 | return false; | ||
114 | } | ||
115 | if !skipped { | ||
116 | p.start(ERROR); | ||
117 | p.error() | ||
118 | .message(message) | ||
119 | .emit(); | ||
120 | } | ||
121 | p.bump(); | ||
122 | skipped = true; | ||
123 | } | 100 | } |
124 | } | ||
125 | 101 | ||
126 | impl<'p> Parser<'p> { | ||
127 | pub(crate) fn expect(&mut self, kind: SyntaxKind) -> bool { | 102 | pub(crate) fn expect(&mut self, kind: SyntaxKind) -> bool { |
128 | if self.current() == kind { | 103 | if self.at(kind) { |
129 | self.bump(); | 104 | self.bump(); |
130 | true | 105 | true |
131 | } else { | 106 | } else { |
@@ -195,4 +170,4 @@ impl<'a> Lookahead for AnyOf<'a> { | |||
195 | p.bump(); | 170 | p.bump(); |
196 | } | 171 | } |
197 | 172 | ||
198 | } \ No newline at end of file | 173 | } |