diff options
Diffstat (limited to 'src/parser/event_parser/grammar.rs')
-rw-r--r-- | src/parser/event_parser/grammar.rs | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/src/parser/event_parser/grammar.rs b/src/parser/event_parser/grammar.rs index f676a183c..64c6718cb 100644 --- a/src/parser/event_parser/grammar.rs +++ b/src/parser/event_parser/grammar.rs | |||
@@ -1,5 +1,6 @@ | |||
1 | use super::parser::Parser; | 1 | use super::parser::Parser; |
2 | use {SyntaxKind}; | 2 | use {SyntaxKind}; |
3 | use tree::EOF; | ||
3 | use syntax_kinds::*; | 4 | use syntax_kinds::*; |
4 | 5 | ||
5 | // Items // | 6 | // Items // |
@@ -18,11 +19,7 @@ pub(crate) fn file(p: &mut Parser) { | |||
18 | } | 19 | } |
19 | 20 | ||
20 | fn item_first(p: &Parser) -> bool { | 21 | fn item_first(p: &Parser) -> bool { |
21 | let current = match p.current() { | 22 | match p.current() { |
22 | Some(c) => c, | ||
23 | None => return false, | ||
24 | }; | ||
25 | match current { | ||
26 | STRUCT_KW | FN_KW => true, | 23 | STRUCT_KW | FN_KW => true, |
27 | _ => false, | 24 | _ => false, |
28 | } | 25 | } |
@@ -79,7 +76,7 @@ fn visibility(_: &mut Parser) { | |||
79 | // Error recovery and high-order utils // | 76 | // Error recovery and high-order utils // |
80 | 77 | ||
81 | fn node_if<F: FnOnce(&mut Parser)>(p: &mut Parser, first: SyntaxKind, node_kind: SyntaxKind, rest: F) -> bool { | 78 | fn node_if<F: FnOnce(&mut Parser)>(p: &mut Parser, first: SyntaxKind, node_kind: SyntaxKind, rest: F) -> bool { |
82 | p.current_is(first) && { node(p, node_kind, |p| { p.bump(); rest(p); }); true } | 79 | p.current() == first && { node(p, node_kind, |p| { p.bump(); rest(p); }); true } |
83 | } | 80 | } |
84 | 81 | ||
85 | fn node<F: FnOnce(&mut Parser)>(p: &mut Parser, node_kind: SyntaxKind, rest: F) { | 82 | fn node<F: FnOnce(&mut Parser)>(p: &mut Parser, node_kind: SyntaxKind, rest: F) { |
@@ -95,7 +92,7 @@ fn many<F: Fn(&mut Parser) -> bool>(p: &mut Parser, f: F) { | |||
95 | fn comma_list<F: Fn(&mut Parser) -> bool>(p: &mut Parser, f: F) { | 92 | fn comma_list<F: Fn(&mut Parser) -> bool>(p: &mut Parser, f: F) { |
96 | many(p, |p| { | 93 | many(p, |p| { |
97 | f(p); | 94 | f(p); |
98 | if p.is_eof() { | 95 | if p.current() == EOF { |
99 | false | 96 | false |
100 | } else { | 97 | } else { |
101 | p.expect(COMMA); | 98 | p.expect(COMMA); |
@@ -119,7 +116,7 @@ where | |||
119 | f(p); | 116 | f(p); |
120 | return true; | 117 | return true; |
121 | } | 118 | } |
122 | if p.is_eof() { | 119 | if p.current() == EOF { |
123 | if skipped { | 120 | if skipped { |
124 | p.finish(); | 121 | p.finish(); |
125 | } | 122 | } |
@@ -131,18 +128,14 @@ where | |||
131 | .message(message) | 128 | .message(message) |
132 | .emit(); | 129 | .emit(); |
133 | } | 130 | } |
134 | p.bump().unwrap(); | 131 | p.bump(); |
135 | skipped = true; | 132 | skipped = true; |
136 | } | 133 | } |
137 | } | 134 | } |
138 | 135 | ||
139 | impl<'p> Parser<'p> { | 136 | impl<'p> Parser<'p> { |
140 | fn current_is(&self, kind: SyntaxKind) -> bool { | ||
141 | self.current() == Some(kind) | ||
142 | } | ||
143 | |||
144 | pub(crate) fn expect(&mut self, kind: SyntaxKind) -> bool { | 137 | pub(crate) fn expect(&mut self, kind: SyntaxKind) -> bool { |
145 | if self.current_is(kind) { | 138 | if self.current() == kind { |
146 | self.bump(); | 139 | self.bump(); |
147 | true | 140 | true |
148 | } else { | 141 | } else { |
@@ -154,7 +147,7 @@ impl<'p> Parser<'p> { | |||
154 | } | 147 | } |
155 | 148 | ||
156 | fn optional(&mut self, kind: SyntaxKind) { | 149 | fn optional(&mut self, kind: SyntaxKind) { |
157 | if self.current_is(kind) { | 150 | if self.current() == kind { |
158 | self.bump(); | 151 | self.bump(); |
159 | } | 152 | } |
160 | } | 153 | } |