Drop curly_block

closes #13
This commit is contained in:
Aleksey Kladov 2018-01-28 14:26:24 +03:00
parent 7a6fa6504c
commit 3cd2b2473b
2 changed files with 21 additions and 42 deletions

View File

@ -235,5 +235,21 @@ fn fn_item(p: &mut Parser) {
assert!(p.at(FN_KW));
p.bump();
p.expect(IDENT) && p.expect(L_PAREN) && p.expect(R_PAREN) && p.curly_block(|_| ());
p.expect(IDENT);
if p.at(L_PAREN) {
fn_value_parameters(p);
} else {
p.error().message("expected function arguments").emit();
}
if p.at(L_CURLY) {
p.expect(L_CURLY);
p.expect(R_CURLY);
}
fn fn_value_parameters(p: &mut Parser) {
assert!(p.at(L_PAREN));
p.bump();
p.expect(R_PAREN);
}
}

View File

@ -1,7 +1,7 @@
use {SyntaxKind, TextUnit, Token};
use super::Event;
use super::super::is_insignificant;
use SyntaxKind::{EOF, ERROR, L_CURLY, R_CURLY, TOMBSTONE};
use SyntaxKind::{EOF, TOMBSTONE};
pub(crate) struct Marker {
pos: u32,
@ -106,9 +106,6 @@ pub(crate) struct Parser<'t> {
pos: usize,
events: Vec<Event>,
curly_level: i32,
curly_limit: Option<i32>,
}
impl<'t> Parser<'t> {
@ -131,13 +128,10 @@ impl<'t> Parser<'t> {
pos: 0,
events: Vec::new(),
curly_level: 0,
curly_limit: None,
}
}
pub(crate) fn into_events(self) -> Vec<Event> {
assert!(self.curly_limit.is_none());
assert_eq!(self.current(), EOF);
self.events
}
@ -146,13 +140,7 @@ impl<'t> Parser<'t> {
if self.pos == self.tokens.len() {
return EOF;
}
let token = self.tokens[self.pos];
if let Some(limit) = self.curly_limit {
if limit == self.curly_level && token.kind == R_CURLY {
return EOF;
}
}
token.kind
self.tokens[self.pos].kind
}
pub(crate) fn start(&mut self) -> Marker {
@ -172,11 +160,8 @@ impl<'t> Parser<'t> {
pub(crate) fn bump(&mut self) -> SyntaxKind {
let kind = self.current();
match kind {
L_CURLY => self.curly_level += 1,
R_CURLY => self.curly_level -= 1,
EOF => return EOF,
_ => (),
if kind == EOF {
return EOF;
}
self.pos += 1;
self.event(Event::Token {
@ -190,28 +175,6 @@ impl<'t> Parser<'t> {
self.tokens.get(self.pos + n).map(|t| t.kind).unwrap_or(EOF)
}
pub(crate) fn curly_block<F: FnOnce(&mut Parser)>(&mut self, f: F) -> bool {
let old_level = self.curly_level;
let old_limit = self.curly_limit;
if !self.expect(L_CURLY) {
return false;
}
self.curly_limit = Some(self.curly_level);
f(self);
assert!(self.curly_level > old_level);
self.curly_limit = old_limit;
if !self.expect(R_CURLY) {
let err = self.start();
while self.curly_level > old_level {
if self.bump() == EOF {
break;
}
}
err.complete(self, ERROR);
}
true
}
fn event(&mut self, event: Event) {
self.events.push(event)
}