diff options
Diffstat (limited to 'crates/ra_parser/src/parser.rs')
-rw-r--r-- | crates/ra_parser/src/parser.rs | 73 |
1 files changed, 17 insertions, 56 deletions
diff --git a/crates/ra_parser/src/parser.rs b/crates/ra_parser/src/parser.rs index e7281123b..a2ac363fb 100644 --- a/crates/ra_parser/src/parser.rs +++ b/crates/ra_parser/src/parser.rs | |||
@@ -5,7 +5,7 @@ use drop_bomb::DropBomb; | |||
5 | use crate::{ | 5 | use crate::{ |
6 | event::Event, | 6 | event::Event, |
7 | ParseError, | 7 | ParseError, |
8 | SyntaxKind::{self, EOF, ERROR, TOMBSTONE}, | 8 | SyntaxKind::{self, EOF, ERROR, L_DOLLAR, R_DOLLAR, TOMBSTONE}, |
9 | TokenSet, TokenSource, T, | 9 | TokenSet, TokenSource, T, |
10 | }; | 10 | }; |
11 | 11 | ||
@@ -211,19 +211,26 @@ impl<'t> Parser<'t> { | |||
211 | 211 | ||
212 | /// Create an error node and consume the next token. | 212 | /// Create an error node and consume the next token. |
213 | pub(crate) fn err_recover(&mut self, message: &str, recovery: TokenSet) { | 213 | pub(crate) fn err_recover(&mut self, message: &str, recovery: TokenSet) { |
214 | if self.at(T!['{']) || self.at(T!['}']) || self.at_ts(recovery) { | 214 | match self.current() { |
215 | self.error(message); | 215 | T!['{'] | T!['}'] | L_DOLLAR | R_DOLLAR => { |
216 | } else { | 216 | self.error(message); |
217 | let m = self.start(); | 217 | return; |
218 | } | ||
219 | _ => (), | ||
220 | } | ||
221 | |||
222 | if self.at_ts(recovery) { | ||
218 | self.error(message); | 223 | self.error(message); |
219 | self.bump_any(); | 224 | return; |
220 | m.complete(self, ERROR); | 225 | } |
221 | }; | 226 | |
227 | let m = self.start(); | ||
228 | self.error(message); | ||
229 | self.bump_any(); | ||
230 | m.complete(self, ERROR); | ||
222 | } | 231 | } |
223 | 232 | ||
224 | fn do_bump(&mut self, kind: SyntaxKind, n_raw_tokens: u8) { | 233 | fn do_bump(&mut self, kind: SyntaxKind, n_raw_tokens: u8) { |
225 | // self.eat_dollars(); | ||
226 | |||
227 | for _ in 0..n_raw_tokens { | 234 | for _ in 0..n_raw_tokens { |
228 | self.token_source.bump(); | 235 | self.token_source.bump(); |
229 | } | 236 | } |
@@ -234,52 +241,6 @@ impl<'t> Parser<'t> { | |||
234 | fn push_event(&mut self, event: Event) { | 241 | fn push_event(&mut self, event: Event) { |
235 | self.events.push(event) | 242 | self.events.push(event) |
236 | } | 243 | } |
237 | |||
238 | pub(crate) fn eat_l_dollars(&mut self) -> usize { | ||
239 | let mut ate_count = 0; | ||
240 | loop { | ||
241 | match self.token_source.current().kind { | ||
242 | k @ SyntaxKind::L_DOLLAR => { | ||
243 | self.token_source.bump(); | ||
244 | self.push_event(Event::Token { kind: k, n_raw_tokens: 1 }); | ||
245 | ate_count += 1; | ||
246 | } | ||
247 | _ => { | ||
248 | return ate_count; | ||
249 | } | ||
250 | } | ||
251 | } | ||
252 | } | ||
253 | |||
254 | pub(crate) fn eat_r_dollars(&mut self, max_count: usize) -> usize { | ||
255 | let mut ate_count = 0; | ||
256 | loop { | ||
257 | match self.token_source.current().kind { | ||
258 | k @ SyntaxKind::R_DOLLAR => { | ||
259 | self.token_source.bump(); | ||
260 | self.push_event(Event::Token { kind: k, n_raw_tokens: 1 }); | ||
261 | ate_count += 1; | ||
262 | |||
263 | if max_count >= ate_count { | ||
264 | return ate_count; | ||
265 | } | ||
266 | } | ||
267 | _ => { | ||
268 | return ate_count; | ||
269 | } | ||
270 | } | ||
271 | } | ||
272 | } | ||
273 | |||
274 | pub(crate) fn at_l_dollar(&self) -> bool { | ||
275 | let kind = self.token_source.current().kind; | ||
276 | (kind == SyntaxKind::L_DOLLAR) | ||
277 | } | ||
278 | |||
279 | pub(crate) fn at_r_dollar(&self) -> bool { | ||
280 | let kind = self.token_source.current().kind; | ||
281 | (kind == SyntaxKind::R_DOLLAR) | ||
282 | } | ||
283 | } | 244 | } |
284 | 245 | ||
285 | /// See `Parser::start`. | 246 | /// See `Parser::start`. |