Add expect_identifier function
For utility
This commit is contained in:
parent
1af1589550
commit
06c3999430
@ -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<AST> {
|
fn parse(&mut self) -> ParseResult<AST> {
|
||||||
let r = self.expr();
|
let r = self.expr();
|
||||||
try!(self.expect(Token::Separator));
|
try!(self.expect(Token::Separator));
|
||||||
|
Loading…
Reference in New Issue
Block a user