aboutsummaryrefslogtreecommitdiff
path: root/src/parser/event_parser
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser/event_parser')
-rw-r--r--src/parser/event_parser/grammar.rs6
-rw-r--r--src/parser/event_parser/mod.rs1
-rw-r--r--src/parser/event_parser/parser.rs22
3 files changed, 23 insertions, 6 deletions
diff --git a/src/parser/event_parser/grammar.rs b/src/parser/event_parser/grammar.rs
index 5219ed535..0896506fb 100644
--- a/src/parser/event_parser/grammar.rs
+++ b/src/parser/event_parser/grammar.rs
@@ -40,6 +40,12 @@ fn mod_items(p: &mut Parser) {
40fn item(p: &mut Parser) -> Result { 40fn item(p: &mut Parser) -> Result {
41 outer_attributes(p)?; 41 outer_attributes(p)?;
42 visibility(p)?; 42 visibility(p)?;
43 if p.current_is(STRUCT_KW) {
44 p.start(STRUCT_ITEM);
45 p.bump();
46 p.finish();
47 return OK;
48 }
43 ERR 49 ERR
44} 50}
45 51
diff --git a/src/parser/event_parser/mod.rs b/src/parser/event_parser/mod.rs
index bdfd23974..1228236a9 100644
--- a/src/parser/event_parser/mod.rs
+++ b/src/parser/event_parser/mod.rs
@@ -4,6 +4,7 @@ use syntax_kinds::*;
4mod grammar; 4mod grammar;
5mod parser; 5mod parser;
6 6
7#[derive(Debug)]
7pub(crate) enum Event { 8pub(crate) enum Event {
8 Start { kind: SyntaxKind }, 9 Start { kind: SyntaxKind },
9 Finish, 10 Finish,
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 }