aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src/parser.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-09-09 23:06:25 +0100
committerGitHub <[email protected]>2019-09-09 23:06:25 +0100
commite2ebb467bdf3ebb7d29260adb95c56594c6db282 (patch)
treee0c25226d8a13b3ff2a13d1100315e8455ea98bd /crates/ra_parser/src/parser.rs
parentc3d96f64ef1b2a5ded9cf5950f8e0f5798de4e1b (diff)
parentd8aa9a1d81529cdc39e8353f2915c3c4d04ac263 (diff)
Merge #1803
1803: introduce bump as a better-checked alternative to bump_any r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_parser/src/parser.rs')
-rw-r--r--crates/ra_parser/src/parser.rs12
1 files changed, 9 insertions, 3 deletions
diff --git a/crates/ra_parser/src/parser.rs b/crates/ra_parser/src/parser.rs
index 393586561..d8567e84b 100644
--- a/crates/ra_parser/src/parser.rs
+++ b/crates/ra_parser/src/parser.rs
@@ -148,7 +148,7 @@ impl<'t> Parser<'t> {
148 } 148 }
149 149
150 /// Advances the parser by one token with composite puncts handled 150 /// Advances the parser by one token with composite puncts handled
151 pub(crate) fn bump(&mut self) { 151 pub(crate) fn bump_any(&mut self) {
152 let kind = self.nth(0); 152 let kind = self.nth(0);
153 if kind == EOF { 153 if kind == EOF {
154 return; 154 return;
@@ -170,6 +170,12 @@ impl<'t> Parser<'t> {
170 } 170 }
171 } 171 }
172 172
173 /// Advances the parser by one token, asserting that it is exactly the expected token
174 pub(crate) fn bump(&mut self, expected: SyntaxKind) {
175 debug_assert!(self.nth(0) == expected);
176 self.bump_any()
177 }
178
173 /// Advances the parser by one token, remapping its kind. 179 /// Advances the parser by one token, remapping its kind.
174 /// This is useful to create contextual keywords from 180 /// This is useful to create contextual keywords from
175 /// identifiers. For example, the lexer creates an `union` 181 /// identifiers. For example, the lexer creates an `union`
@@ -205,7 +211,7 @@ impl<'t> Parser<'t> {
205 if !self.at(kind) { 211 if !self.at(kind) {
206 return false; 212 return false;
207 } 213 }
208 self.bump(); 214 self.bump_any();
209 true 215 true
210 } 216 }
211 217
@@ -231,7 +237,7 @@ impl<'t> Parser<'t> {
231 } else { 237 } else {
232 let m = self.start(); 238 let m = self.start();
233 self.error(message); 239 self.error(message);
234 self.bump(); 240 self.bump_any();
235 m.complete(self, ERROR); 241 m.complete(self, ERROR);
236 }; 242 };
237 } 243 }