aboutsummaryrefslogtreecommitdiff
path: root/src/parser/event_parser/parser.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser/event_parser/parser.rs')
-rw-r--r--src/parser/event_parser/parser.rs22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/parser/event_parser/parser.rs b/src/parser/event_parser/parser.rs
index 0e4d44b79..2d5418a29 100644
--- a/src/parser/event_parser/parser.rs
+++ b/src/parser/event_parser/parser.rs
@@ -1,5 +1,6 @@
1use {Token, SyntaxKind, TextUnit}; 1use {Token, SyntaxKind, TextUnit};
2use super::Event; 2use super::{Event};
3use super::super::is_insignificant;
3use syntax_kinds::{WHITESPACE, COMMENT}; 4use syntax_kinds::{WHITESPACE, COMMENT};
4 5
5pub struct Parser<'t> { 6pub struct Parser<'t> {
@@ -16,9 +17,8 @@ impl<'t> Parser<'t> {
16 let mut non_ws_tokens = Vec::new(); 17 let mut non_ws_tokens = Vec::new();
17 let mut len = TextUnit::new(0); 18 let mut len = TextUnit::new(0);
18 for (idx, &token) in raw_tokens.iter().enumerate() { 19 for (idx, &token) in raw_tokens.iter().enumerate() {
19 match token.kind { 20 if !is_insignificant(token.kind) {
20 WHITESPACE | COMMENT => (), 21 non_ws_tokens.push((idx, len))
21 _ => non_ws_tokens.push((idx, len)),
22 } 22 }
23 len += token.len; 23 len += token.len;
24 } 24 }
@@ -50,15 +50,25 @@ impl<'t> Parser<'t> {
50 self.event(Event::Finish); 50 self.event(Event::Finish);
51 } 51 }
52 52
53 pub(crate) fn bump(&mut self) -> Option<SyntaxKind> { 53 pub(crate) fn current(&self) -> Option<SyntaxKind> {
54 if self.is_eof() { 54 if self.is_eof() {
55 return None; 55 return None;
56 } 56 }
57 let idx = self.non_ws_tokens[self.pos].0; 57 let idx = self.non_ws_tokens[self.pos].0;
58 self.pos += 1;
59 Some(self.raw_tokens[idx].kind) 58 Some(self.raw_tokens[idx].kind)
60 } 59 }
61 60
61 pub(crate) fn current_is(&self, kind: SyntaxKind) -> bool {
62 self.current() == Some(kind)
63 }
64
65 pub(crate) fn bump(&mut self) -> Option<SyntaxKind> {
66 let kind = self.current()?;
67 self.pos += 1;
68 self.event(Event::Token { kind, n_raw_tokens: 1 });
69 Some(kind)
70 }
71
62 fn event(&mut self, event: Event) { 72 fn event(&mut self, event: Event) {
63 self.events.push(event) 73 self.events.push(event)
64 } 74 }