From 60725def49834bb7dfd46c1a7b84d86f810e1d03 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 28 Jan 2018 14:30:59 +0300 Subject: Simplify --- src/parser/event_parser/grammar/mod.rs | 22 +--------------------- src/parser/event_parser/parser.rs | 11 ++++------- 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> { err.complete(self, ERROR); } - pub(crate) fn expect(&mut self, kind: SyntaxKind) -> bool { + fn expect(&mut self, kind: SyntaxKind) -> bool { if self.at(kind) { self.bump(); true @@ -77,40 +77,24 @@ impl<'p> Parser<'p> { trait Lookahead: Copy { fn is_ahead(self, p: &Parser) -> bool; - fn consume(p: &mut Parser); } impl Lookahead for SyntaxKind { fn is_ahead(self, p: &Parser) -> bool { p.current() == self } - - fn consume(p: &mut Parser) { - p.bump(); - } } impl Lookahead for [SyntaxKind; 2] { fn is_ahead(self, p: &Parser) -> bool { p.current() == self[0] && p.raw_lookahead(1) == self[1] } - - fn consume(p: &mut Parser) { - p.bump(); - p.bump(); - } } impl Lookahead for [SyntaxKind; 3] { fn is_ahead(self, p: &Parser) -> bool { p.current() == self[0] && p.raw_lookahead(1) == self[1] && p.raw_lookahead(2) == self[2] } - - fn consume(p: &mut Parser) { - p.bump(); - p.bump(); - p.bump(); - } } #[derive(Clone, Copy)] @@ -121,8 +105,4 @@ impl<'a> Lookahead for AnyOf<'a> { let curr = p.current(); self.0.iter().any(|&k| k == curr) } - - fn consume(p: &mut Parser) { - p.bump(); - } } 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> { self.events } - pub(crate) fn current(&self) -> SyntaxKind { - if self.pos == self.tokens.len() { - return EOF; - } - self.tokens[self.pos].kind - } - pub(crate) fn start(&mut self) -> Marker { let m = Marker { pos: self.events.len() as u32, @@ -175,6 +168,10 @@ impl<'t> Parser<'t> { self.tokens.get(self.pos + n).map(|t| t.kind).unwrap_or(EOF) } + pub(crate) fn current(&self) -> SyntaxKind { + self.raw_lookahead(0) + } + fn event(&mut self, event: Event) { self.events.push(event) } -- cgit v1.2.3