From 06c3999430747fa6dea70d2218917eb13fdc313b Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 28 Dec 2015 23:11:26 -0800 Subject: [PATCH] Add expect_identifier function For utility --- src/parser.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/parser.rs b/src/parser.rs index aacbca1..455fc69 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -56,6 +56,21 @@ impl Parser { } } + fn expect_identifier(&mut self, identifier_str: &str) -> ParseResult<()> { + use tokenizer::Token::*; + match self.next() { + Some(Identifier(ref s)) if s == identifier_str => Ok(()), + Some(next) => { + let err = format!("Expected identifier `{}` but got {:?}", identifier_str, next); + Err(ParseError { err: err }) + } + None => { + let err = format!("Expected identifier `{}` but got end of input", identifier_str); + Err(ParseError { err: err }) + } + } + } + fn parse(&mut self) -> ParseResult { let r = self.expr(); try!(self.expect(Token::Separator));