Implement paren expressions

This commit is contained in:
greg 2015-12-30 21:14:23 -08:00
parent 819fb3f58f
commit 971ab9ba21

View File

@ -145,8 +145,20 @@ impl Parser {
} }
fn factor(&mut self) -> ParseResult<AST> { fn factor(&mut self) -> ParseResult<AST> {
let n = try!(self.expect_num_literal()); use tokenizer::Token::*;
match self.lookahead() {
Some(LParen) => {
self.next();
let expr = try!(self.expr());
try!(self.expect(RParen));
Ok(expr)
},
Some(NumLiteral(n)) => {
self.next();
Ok(AST::Number(n)) Ok(AST::Number(n))
},
_ => Err(ParseError { err: format!("Expected LParen or NumLiteral") })
}
} }
} }