mirror of
https://github.com/TheM1Stery/izanami.git
synced 2025-04-19 16:31:11 +00:00
feat: implement #3 challenge for ch6
i kinda cheated, i was checking the answers and then stumbled upon the grammar. Sorry :(
This commit is contained in:
parent
977fd9a8a8
commit
9f903556f9
@ -90,6 +90,11 @@ impl Parser<'_> {
|
||||
self.primary()
|
||||
}
|
||||
|
||||
/* error boundaries:
|
||||
("!=" | "==") equality
|
||||
| (">" | ">=" | "<" | "<=") comparison
|
||||
| ("+") term
|
||||
| ("/" | "*") factor ; */
|
||||
fn primary(&mut self) -> Result<Expr, ParseError> {
|
||||
use LiteralType::*;
|
||||
use TokenType::*;
|
||||
@ -123,6 +128,38 @@ impl Parser<'_> {
|
||||
});
|
||||
}
|
||||
|
||||
if self.match_token(&[Equal, BangEqual]) {
|
||||
let _ = self.equality();
|
||||
return Err(ParseError {
|
||||
token: self.previous().clone(),
|
||||
msg: "Missing left-hand operand.".to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
if self.match_token(&[Greater, GreaterEqual, Less, LessEqual]) {
|
||||
let _ = self.comparison();
|
||||
return Err(ParseError {
|
||||
token: self.previous().clone(),
|
||||
msg: "Missing left-hand operand.".to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
if self.match_token(&[Plus]) {
|
||||
let _ = self.term();
|
||||
return Err(ParseError {
|
||||
token: self.previous().clone(),
|
||||
msg: "Missing left-hand operand.".to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
if self.match_token(&[Star, Slash]) {
|
||||
let _ = self.factor();
|
||||
return Err(ParseError {
|
||||
token: self.previous().clone(),
|
||||
msg: "Missing left-hand operand.".to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
Err(ParseError {
|
||||
token: self.peek().clone(),
|
||||
msg: "Expect expression.".to_string(),
|
||||
|
Loading…
Reference in New Issue
Block a user