From d8aa9a1d81529cdc39e8353f2915c3c4d04ac263 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 10 Sep 2019 01:03:00 +0300 Subject: introduce bump as a better-checked alternative to bump_any --- crates/ra_parser/src/grammar.rs | 4 ++-- crates/ra_parser/src/parser.rs | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs index 89f4b63ec..4e6f2f558 100644 --- a/crates/ra_parser/src/grammar.rs +++ b/crates/ra_parser/src/grammar.rs @@ -126,7 +126,7 @@ pub(crate) mod fragments { while !p.at(EOF) { if p.at(T![;]) { - p.bump_any(); + p.bump(T![;]); continue; } @@ -179,7 +179,7 @@ fn opt_visibility(p: &mut Parser) -> bool { match p.current() { T![pub] => { let m = p.start(); - p.bump_any(); + p.bump(T![pub]); if p.at(T!['(']) { match p.nth(1) { // test crate_visibility diff --git a/crates/ra_parser/src/parser.rs b/crates/ra_parser/src/parser.rs index ccacaacad..d8567e84b 100644 --- a/crates/ra_parser/src/parser.rs +++ b/crates/ra_parser/src/parser.rs @@ -170,6 +170,12 @@ impl<'t> Parser<'t> { } } + /// Advances the parser by one token, asserting that it is exactly the expected token + pub(crate) fn bump(&mut self, expected: SyntaxKind) { + debug_assert!(self.nth(0) == expected); + self.bump_any() + } + /// Advances the parser by one token, remapping its kind. /// This is useful to create contextual keywords from /// identifiers. For example, the lexer creates an `union` -- cgit v1.2.3