fix: actually finish challeng #2(ch.6)

I didn't implement the scanner and the printer lol
This commit is contained in:
Seymur Bagirov 2025-01-05 05:12:20 +04:00
parent e54e1b1b27
commit 977fd9a8a8
2 changed files with 12 additions and 0 deletions

View File

@ -12,6 +12,16 @@ pub fn pretty_print(expr: &Expr) -> String {
None => "None".to_string(),
},
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],
),
}
}

View File

@ -99,6 +99,8 @@ impl Scanner {
'<' => self.add_token(TokenType::Less),
'>' if self.peek_and_match('=') => self.add_token(TokenType::GreaterEqual),
'>' => 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
'/' if self.peek_and_match('/') => {
while self.peek().is_some_and(|x| x != '\n') {