From 5562931e4f3c6c57e9122c3ce34d941fb1ff6e5b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 7 Jan 2018 21:09:05 +0300 Subject: Introduce EOF token --- src/parser/event_parser/grammar.rs | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'src/parser/event_parser/grammar.rs') diff --git a/src/parser/event_parser/grammar.rs b/src/parser/event_parser/grammar.rs index f676a183c..64c6718cb 100644 --- a/src/parser/event_parser/grammar.rs +++ b/src/parser/event_parser/grammar.rs @@ -1,5 +1,6 @@ use super::parser::Parser; use {SyntaxKind}; +use tree::EOF; use syntax_kinds::*; // Items // @@ -18,11 +19,7 @@ pub(crate) fn file(p: &mut Parser) { } fn item_first(p: &Parser) -> bool { - let current = match p.current() { - Some(c) => c, - None => return false, - }; - match current { + match p.current() { STRUCT_KW | FN_KW => true, _ => false, } @@ -79,7 +76,7 @@ fn visibility(_: &mut Parser) { // Error recovery and high-order utils // fn node_if(p: &mut Parser, first: SyntaxKind, node_kind: SyntaxKind, rest: F) -> bool { - p.current_is(first) && { node(p, node_kind, |p| { p.bump(); rest(p); }); true } + p.current() == first && { node(p, node_kind, |p| { p.bump(); rest(p); }); true } } fn node(p: &mut Parser, node_kind: SyntaxKind, rest: F) { @@ -95,7 +92,7 @@ fn many bool>(p: &mut Parser, f: F) { fn comma_list bool>(p: &mut Parser, f: F) { many(p, |p| { f(p); - if p.is_eof() { + if p.current() == EOF { false } else { p.expect(COMMA); @@ -119,7 +116,7 @@ where f(p); return true; } - if p.is_eof() { + if p.current() == EOF { if skipped { p.finish(); } @@ -131,18 +128,14 @@ where .message(message) .emit(); } - p.bump().unwrap(); + p.bump(); skipped = true; } } impl<'p> Parser<'p> { - fn current_is(&self, kind: SyntaxKind) -> bool { - self.current() == Some(kind) - } - pub(crate) fn expect(&mut self, kind: SyntaxKind) -> bool { - if self.current_is(kind) { + if self.current() == kind { self.bump(); true } else { @@ -154,7 +147,7 @@ impl<'p> Parser<'p> { } fn optional(&mut self, kind: SyntaxKind) { - if self.current_is(kind) { + if self.current() == kind { self.bump(); } } -- cgit v1.2.3