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));