mirror of
https://github.com/TheM1Stery/izanami.git
synced 2025-05-07 14:10:11 +00:00
fix: actually finish challeng #2(ch.6)
I didn't implement the scanner and the printer lol
This commit is contained in:
parent
e54e1b1b27
commit
977fd9a8a8
@ -12,6 +12,16 @@ pub fn pretty_print(expr: &Expr) -> String {
|
|||||||
None => "None".to_string(),
|
None => "None".to_string(),
|
||||||
},
|
},
|
||||||
Expr::Unary { op, right } => parenthesize(&op.lexeme, &[right]),
|
Expr::Unary { op, right } => parenthesize(&op.lexeme, &[right]),
|
||||||
|
Expr::Ternary {
|
||||||
|
first,
|
||||||
|
first_op,
|
||||||
|
second,
|
||||||
|
second_op,
|
||||||
|
third,
|
||||||
|
} => parenthesize(
|
||||||
|
&format!("{}{}", first_op.lexeme, second_op.lexeme),
|
||||||
|
&[first, second, third],
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,6 +99,8 @@ impl Scanner {
|
|||||||
'<' => self.add_token(TokenType::Less),
|
'<' => self.add_token(TokenType::Less),
|
||||||
'>' if self.peek_and_match('=') => self.add_token(TokenType::GreaterEqual),
|
'>' if self.peek_and_match('=') => self.add_token(TokenType::GreaterEqual),
|
||||||
'>' => self.add_token(TokenType::Greater),
|
'>' => self.add_token(TokenType::Greater),
|
||||||
|
'?' => self.add_token(TokenType::Question),
|
||||||
|
':' => self.add_token(TokenType::Colon),
|
||||||
// checking for comments and just advance the iterator if it's a comment
|
// checking for comments and just advance the iterator if it's a comment
|
||||||
'/' if self.peek_and_match('/') => {
|
'/' if self.peek_and_match('/') => {
|
||||||
while self.peek().is_some_and(|x| x != '\n') {
|
while self.peek().is_some_and(|x| x != '\n') {
|
||||||
|
Loading…
Reference in New Issue
Block a user