Expression parantheses nesting
This commit is contained in:
parent
24e5ac2aef
commit
1d7007ab9a
13
src/parse.rs
13
src/parse.rs
|
@ -244,6 +244,7 @@ pub enum Expr<'a> {
|
|||
Literal(Literal<'a>),
|
||||
Local(&'a str),
|
||||
Member(&'a str),
|
||||
Group(Box<Expr<'a>>),
|
||||
FuncCall(&'a str, Vec<Expr<'a>>),
|
||||
If {
|
||||
test_expr: Box<Expr<'a>>,
|
||||
|
@ -257,6 +258,13 @@ impl<'a> Expr<'a> {
|
|||
let lhs = match tok {
|
||||
Token::Identifier => Self::Local(lexer.slice()),
|
||||
Token::Dot => Self::Member(lexer.eat_expect_id()),
|
||||
Token::ParanOpen => {
|
||||
let (inner, next) = Self::build(lexer);
|
||||
if next != Token::ParanClose {
|
||||
lexer.panic_message("Expected closing parantheses");
|
||||
}
|
||||
Self::Group(Box::new(inner.unwrap()))
|
||||
}
|
||||
Token::BinaryInteger => Self::Literal(Literal::BinaryInteger(lexer.slice())),
|
||||
Token::OctalInteger => Self::Literal(Literal::OctalInteger(lexer.slice())),
|
||||
Token::HexInteger => Self::Literal(Literal::HexInteger(lexer.slice())),
|
||||
|
@ -443,6 +451,11 @@ mod tests {
|
|||
parse_expr("local1 + local2 - local3;");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nesting() {
|
||||
parse_expr("(1 + 2) * (3 / (4 + 5));")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn members() {
|
||||
parse_expr(".member1 * .member2;");
|
||||
|
|
Loading…
Reference in New Issue