Browse Source

fix: nested expression parsing

fixes: #8, #18
master
Garrit Franke 2 years ago
parent
commit
f58ec04ec3
  1. 6
      src/parser/rules.rs
  2. 2
      src/parser/tests.rs

6
src/parser/rules.rs

@ -180,6 +180,7 @@ impl Parser {
let token = self.peek()?;
match &token.kind {
TokenKind::CurlyBracesOpen => self.parse_block(),
TokenKind::BraceOpen => Ok(Statement::Exp(self.parse_expression()?)),
TokenKind::Keyword(Keyword::Let) => self.parse_declare(),
TokenKind::Keyword(Keyword::Return) => self.parse_return(),
TokenKind::Keyword(Keyword::If) => self.parse_conditional_statement(),
@ -292,7 +293,10 @@ impl Parser {
TokenKind::BraceOpen => {
let expr = self.parse_expression()?;
self.match_token(TokenKind::BraceClose)?;
expr
match BinOp::try_from(self.peek()?.kind) {
Ok(_) => self.parse_bin_op(Some(expr))?,
Err(_) => expr,
}
}
TokenKind::Keyword(Keyword::Boolean) => match BinOp::try_from(self.peek()?.kind) {
Ok(_) => self.parse_bin_op(None)?,

2
src/parser/tests.rs

@ -747,7 +747,6 @@ fn test_break() {
}
#[test]
#[ignore]
fn test_complex_nested_expressions() {
let raw = "
fn main() {
@ -800,7 +799,6 @@ fn test_struct_initialization() {
}
#[test]
#[ignore]
fn test_arithmetic() {
// These should pass
let raw = "fn main() {1*1}";

Loading…
Cancel
Save