mirror of
https://github.com/TheM1Stery/izanami.git
synced 2025-04-19 16:31:11 +00:00
fix: fix comma precedence
it should be lower than assignement. Now we can do stuff like a = 10, b = 30(before this commit we couldn't this was a bug)
This commit is contained in:
parent
31e348643f
commit
129d03b74d
@ -111,11 +111,18 @@ impl Parser<'_> {
|
||||
}
|
||||
|
||||
fn expression(&mut self) -> Result<Expr, ParseError> {
|
||||
self.assignment()
|
||||
self.comma()
|
||||
}
|
||||
|
||||
// Challenge #1. We're writing comma before equality, because it has the lowest precedence
|
||||
// comma -> equality ("," equality)* ; // expression grammar
|
||||
fn comma(&mut self) -> Result<Expr, ParseError> {
|
||||
use TokenType::*;
|
||||
self.left_association_binary(&[Comma], Self::assignment)
|
||||
}
|
||||
|
||||
fn assignment(&mut self) -> Result<Expr, ParseError> {
|
||||
let expr = self.comma()?;
|
||||
let expr = self.ternary()?;
|
||||
|
||||
if self.match_token(&[TokenType::Equal]) {
|
||||
let value = self.assignment()?;
|
||||
@ -136,13 +143,6 @@ impl Parser<'_> {
|
||||
Ok(expr)
|
||||
}
|
||||
|
||||
// Challenge #1. We're writing comma before equality, because it has the lowest precedence
|
||||
// comma -> equality ("," equality)* ; // expression grammar
|
||||
fn comma(&mut self) -> Result<Expr, ParseError> {
|
||||
use TokenType::*;
|
||||
self.left_association_binary(&[Comma], Self::ternary)
|
||||
}
|
||||
|
||||
// ternary -> equality ("?" expression : ternary)? // expression grammar
|
||||
fn ternary(&mut self) -> Result<Expr, ParseError> {
|
||||
use TokenType::*;
|
||||
|
Loading…
Reference in New Issue
Block a user