Implement paren expressions
This commit is contained in:
parent
819fb3f58f
commit
971ab9ba21
@ -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::*;
|
||||||
Ok(AST::Number(n))
|
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))
|
||||||
|
},
|
||||||
|
_ => Err(ParseError { err: format!("Expected LParen or NumLiteral") })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user