aboutsummaryrefslogtreecommitdiff
path: root/src/parser/event_parser
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-01-28 11:26:24 +0000
committerAleksey Kladov <[email protected]>2018-01-28 11:26:24 +0000
commit3cd2b2473b034f290d65e3dc839c0530e55de75b (patch)
treeccd93c44154bd5bace13e40f68e40f0d15e1a450 /src/parser/event_parser
parent7a6fa6504c5458dcc32e24327ba0ec597222fc63 (diff)
Drop curly_block
closes #13
Diffstat (limited to 'src/parser/event_parser')
-rw-r--r--src/parser/event_parser/grammar/items.rs18
-rw-r--r--src/parser/event_parser/parser.rs45
2 files changed, 21 insertions, 42 deletions
diff --git a/src/parser/event_parser/grammar/items.rs b/src/parser/event_parser/grammar/items.rs
index 0638e3093..812e407d1 100644
--- a/src/parser/event_parser/grammar/items.rs
+++ b/src/parser/event_parser/grammar/items.rs
@@ -235,5 +235,21 @@ fn fn_item(p: &mut Parser) {
235 assert!(p.at(FN_KW)); 235 assert!(p.at(FN_KW));
236 p.bump(); 236 p.bump();
237 237
238 p.expect(IDENT) && p.expect(L_PAREN) && p.expect(R_PAREN) && p.curly_block(|_| ()); 238 p.expect(IDENT);
239 if p.at(L_PAREN) {
240 fn_value_parameters(p);
241 } else {
242 p.error().message("expected function arguments").emit();
243 }
244
245 if p.at(L_CURLY) {
246 p.expect(L_CURLY);
247 p.expect(R_CURLY);
248 }
249
250 fn fn_value_parameters(p: &mut Parser) {
251 assert!(p.at(L_PAREN));
252 p.bump();
253 p.expect(R_PAREN);
254 }
239} 255}
diff --git a/src/parser/event_parser/parser.rs b/src/parser/event_parser/parser.rs
index 573e3d73a..d19663865 100644
--- a/src/parser/event_parser/parser.rs
+++ b/src/parser/event_parser/parser.rs
@@ -1,7 +1,7 @@
1use {SyntaxKind, TextUnit, Token}; 1use {SyntaxKind, TextUnit, Token};
2use super::Event; 2use super::Event;
3use super::super::is_insignificant; 3use super::super::is_insignificant;
4use SyntaxKind::{EOF, ERROR, L_CURLY, R_CURLY, TOMBSTONE}; 4use SyntaxKind::{EOF, TOMBSTONE};
5 5
6pub(crate) struct Marker { 6pub(crate) struct Marker {
7 pos: u32, 7 pos: u32,
@@ -106,9 +106,6 @@ pub(crate) struct Parser<'t> {
106 106
107 pos: usize, 107 pos: usize,
108 events: Vec<Event>, 108 events: Vec<Event>,
109
110 curly_level: i32,
111 curly_limit: Option<i32>,
112} 109}
113 110
114impl<'t> Parser<'t> { 111impl<'t> Parser<'t> {
@@ -131,13 +128,10 @@ impl<'t> Parser<'t> {
131 128
132 pos: 0, 129 pos: 0,
133 events: Vec::new(), 130 events: Vec::new(),
134 curly_level: 0,
135 curly_limit: None,
136 } 131 }
137 } 132 }
138 133
139 pub(crate) fn into_events(self) -> Vec<Event> { 134 pub(crate) fn into_events(self) -> Vec<Event> {
140 assert!(self.curly_limit.is_none());
141 assert_eq!(self.current(), EOF); 135 assert_eq!(self.current(), EOF);
142 self.events 136 self.events
143 } 137 }
@@ -146,13 +140,7 @@ impl<'t> Parser<'t> {
146 if self.pos == self.tokens.len() { 140 if self.pos == self.tokens.len() {
147 return EOF; 141 return EOF;
148 } 142 }
149 let token = self.tokens[self.pos]; 143 self.tokens[self.pos].kind
150 if let Some(limit) = self.curly_limit {
151 if limit == self.curly_level && token.kind == R_CURLY {
152 return EOF;
153 }
154 }
155 token.kind
156 } 144 }
157 145
158 pub(crate) fn start(&mut self) -> Marker { 146 pub(crate) fn start(&mut self) -> Marker {
@@ -172,11 +160,8 @@ impl<'t> Parser<'t> {
172 160
173 pub(crate) fn bump(&mut self) -> SyntaxKind { 161 pub(crate) fn bump(&mut self) -> SyntaxKind {
174 let kind = self.current(); 162 let kind = self.current();
175 match kind { 163 if kind == EOF {
176 L_CURLY => self.curly_level += 1, 164 return EOF;
177 R_CURLY => self.curly_level -= 1,
178 EOF => return EOF,
179 _ => (),
180 } 165 }
181 self.pos += 1; 166 self.pos += 1;
182 self.event(Event::Token { 167 self.event(Event::Token {
@@ -190,28 +175,6 @@ impl<'t> Parser<'t> {
190 self.tokens.get(self.pos + n).map(|t| t.kind).unwrap_or(EOF) 175 self.tokens.get(self.pos + n).map(|t| t.kind).unwrap_or(EOF)
191 } 176 }
192 177
193 pub(crate) fn curly_block<F: FnOnce(&mut Parser)>(&mut self, f: F) -> bool {
194 let old_level = self.curly_level;
195 let old_limit = self.curly_limit;
196 if !self.expect(L_CURLY) {
197 return false;
198 }
199 self.curly_limit = Some(self.curly_level);
200 f(self);
201 assert!(self.curly_level > old_level);
202 self.curly_limit = old_limit;
203 if !self.expect(R_CURLY) {
204 let err = self.start();
205 while self.curly_level > old_level {
206 if self.bump() == EOF {
207 break;
208 }
209 }
210 err.complete(self, ERROR);
211 }
212 true
213 }
214
215 fn event(&mut self, event: Event) { 178 fn event(&mut self, event: Event) {
216 self.events.push(event) 179 self.events.push(event)
217 } 180 }