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/mod.rs22
-rw-r--r--src/parser/event_parser/parser.rs11
2 files changed, 5 insertions, 28 deletions
diff --git a/src/parser/event_parser/grammar/mod.rs b/src/parser/event_parser/grammar/mod.rs
index b87f3ca8a..79a4c10d3 100644
--- a/src/parser/event_parser/grammar/mod.rs
+++ b/src/parser/event_parser/grammar/mod.rs
@@ -57,7 +57,7 @@ impl<'p> Parser<'p> {
57 err.complete(self, ERROR); 57 err.complete(self, ERROR);
58 } 58 }
59 59
60 pub(crate) fn expect(&mut self, kind: SyntaxKind) -> bool { 60 fn expect(&mut self, kind: SyntaxKind) -> bool {
61 if self.at(kind) { 61 if self.at(kind) {
62 self.bump(); 62 self.bump();
63 true 63 true
@@ -77,40 +77,24 @@ impl<'p> Parser<'p> {
77 77
78trait Lookahead: Copy { 78trait Lookahead: Copy {
79 fn is_ahead(self, p: &Parser) -> bool; 79 fn is_ahead(self, p: &Parser) -> bool;
80 fn consume(p: &mut Parser);
81} 80}
82 81
83impl Lookahead for SyntaxKind { 82impl Lookahead for SyntaxKind {
84 fn is_ahead(self, p: &Parser) -> bool { 83 fn is_ahead(self, p: &Parser) -> bool {
85 p.current() == self 84 p.current() == self
86 } 85 }
87
88 fn consume(p: &mut Parser) {
89 p.bump();
90 }
91} 86}
92 87
93impl Lookahead for [SyntaxKind; 2] { 88impl Lookahead for [SyntaxKind; 2] {
94 fn is_ahead(self, p: &Parser) -> bool { 89 fn is_ahead(self, p: &Parser) -> bool {
95 p.current() == self[0] && p.raw_lookahead(1) == self[1] 90 p.current() == self[0] && p.raw_lookahead(1) == self[1]
96 } 91 }
97
98 fn consume(p: &mut Parser) {
99 p.bump();
100 p.bump();
101 }
102} 92}
103 93
104impl Lookahead for [SyntaxKind; 3] { 94impl Lookahead for [SyntaxKind; 3] {
105 fn is_ahead(self, p: &Parser) -> bool { 95 fn is_ahead(self, p: &Parser) -> bool {
106 p.current() == self[0] && p.raw_lookahead(1) == self[1] && p.raw_lookahead(2) == self[2] 96 p.current() == self[0] && p.raw_lookahead(1) == self[1] && p.raw_lookahead(2) == self[2]
107 } 97 }
108
109 fn consume(p: &mut Parser) {
110 p.bump();
111 p.bump();
112 p.bump();
113 }
114} 98}
115 99
116#[derive(Clone, Copy)] 100#[derive(Clone, Copy)]
@@ -121,8 +105,4 @@ impl<'a> Lookahead for AnyOf<'a> {
121 let curr = p.current(); 105 let curr = p.current();
122 self.0.iter().any(|&k| k == curr) 106 self.0.iter().any(|&k| k == curr)
123 } 107 }
124
125 fn consume(p: &mut Parser) {
126 p.bump();
127 }
128} 108}
diff --git a/src/parser/event_parser/parser.rs b/src/parser/event_parser/parser.rs
index d19663865..2507af6bf 100644
--- a/src/parser/event_parser/parser.rs
+++ b/src/parser/event_parser/parser.rs
@@ -136,13 +136,6 @@ impl<'t> Parser<'t> {
136 self.events 136 self.events
137 } 137 }
138 138
139 pub(crate) fn current(&self) -> SyntaxKind {
140 if self.pos == self.tokens.len() {
141 return EOF;
142 }
143 self.tokens[self.pos].kind
144 }
145
146 pub(crate) fn start(&mut self) -> Marker { 139 pub(crate) fn start(&mut self) -> Marker {
147 let m = Marker { 140 let m = Marker {
148 pos: self.events.len() as u32, 141 pos: self.events.len() as u32,
@@ -175,6 +168,10 @@ impl<'t> Parser<'t> {
175 self.tokens.get(self.pos + n).map(|t| t.kind).unwrap_or(EOF) 168 self.tokens.get(self.pos + n).map(|t| t.kind).unwrap_or(EOF)
176 } 169 }
177 170
171 pub(crate) fn current(&self) -> SyntaxKind {
172 self.raw_lookahead(0)
173 }
174
178 fn event(&mut self, event: Event) { 175 fn event(&mut self, event: Event) {
179 self.events.push(event) 176 self.events.push(event)
180 } 177 }