aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src/parser_api.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libsyntax2/src/parser_api.rs')
-rw-r--r--crates/libsyntax2/src/parser_api.rs19
1 files changed, 15 insertions, 4 deletions
diff --git a/crates/libsyntax2/src/parser_api.rs b/crates/libsyntax2/src/parser_api.rs
index 0a3b29b70..10b9b64ac 100644
--- a/crates/libsyntax2/src/parser_api.rs
+++ b/crates/libsyntax2/src/parser_api.rs
@@ -12,6 +12,8 @@ fn mask(kind: SyntaxKind) -> u128 {
12} 12}
13 13
14impl TokenSet { 14impl TokenSet {
15 const EMPTY: TokenSet = TokenSet(0);
16
15 pub fn contains(&self, kind: SyntaxKind) -> bool { 17 pub fn contains(&self, kind: SyntaxKind) -> bool {
16 self.0 & mask(kind) != 0 18 self.0 & mask(kind) != 0
17 } 19 }
@@ -139,12 +141,21 @@ impl<'t> Parser<'t> {
139 141
140 /// Create an error node and consume the next token. 142 /// Create an error node and consume the next token.
141 pub(crate) fn err_and_bump(&mut self, message: &str) { 143 pub(crate) fn err_and_bump(&mut self, message: &str) {
142 let m = self.start(); 144 self.err_recover(message, TokenSet::EMPTY);
143 self.error(message); 145 }
144 if !self.at(SyntaxKind::L_CURLY) && !self.at(SyntaxKind::R_CURLY) { 146
147 /// Create an error node and consume the next token.
148 pub(crate) fn err_recover(&mut self, message: &str, recovery_set: TokenSet) {
149 if self.at(SyntaxKind::L_CURLY)
150 || self.at(SyntaxKind::R_CURLY)
151 || recovery_set.contains(self.current()) {
152 self.error(message);
153 } else {
154 let m = self.start();
155 self.error(message);
145 self.bump(); 156 self.bump();
157 m.complete(self, ERROR);
146 } 158 }
147 m.complete(self, ERROR);
148 } 159 }
149} 160}
150 161