feat: finish challenge #1 from chapter 6

This commit is contained in:
Seymur Bagirov 2025-01-03 03:20:09 +04:00
parent 91cfc0b938
commit 4fd04e8fd3

View File

@ -1,5 +1,3 @@
use std::fmt::Display;
use crate::{ use crate::{
ast::Expr, ast::Expr,
token::{LiteralType, Token, TokenType}, token::{LiteralType, Token, TokenType},
@ -26,7 +24,13 @@ impl Parser<'_> {
} }
fn expression(&mut self) -> Result<Expr, ParseError> { fn expression(&mut self) -> Result<Expr, ParseError> {
self.equality() self.comma()
}
// Challenge #1. We're writing comma before equality, because it has the lowest precedence
fn comma(&mut self) -> Result<Expr, ParseError> {
use TokenType::*;
self.left_association_binary(&[Comma], Parser::equality)
} }
fn equality(&mut self) -> Result<Expr, ParseError> { fn equality(&mut self) -> Result<Expr, ParseError> {