From 977fd9a8a86e45fcd7243aa281697b8375e7541d Mon Sep 17 00:00:00 2001 From: Seymur Bagirov Date: Sun, 5 Jan 2025 05:12:20 +0400 Subject: [PATCH] fix: actually finish challeng #2(ch.6) I didn't implement the scanner and the printer lol --- src/printer.rs | 10 ++++++++++ src/scanner.rs | 2 ++ 2 files changed, 12 insertions(+) diff --git a/src/printer.rs b/src/printer.rs index deaf8bd..0650b37 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -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], + ), } } diff --git a/src/scanner.rs b/src/scanner.rs index 3c441df..0accbe7 100644 --- a/src/scanner.rs +++ b/src/scanner.rs @@ -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') {