diff --git a/src/ast.rs b/src/ast.rs index 7326ef5..3e2961e 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -4,9 +4,7 @@ use crate::token::{LiteralType, Token}; pub enum Expr { Ternary { first: Box, - first_op: Token, second: Box, - second_op: Token, third: Box, }, Binary { diff --git a/src/parser.rs b/src/parser.rs index f4b6ce2..6ef9667 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -50,15 +50,12 @@ impl Parser<'_> { let expr = self.equality()?; if self.match_token(&[Question]) { - let first_op = self.previous().clone(); let second = self.expression()?; - let second_op = self.consume(Colon, "Expected : after ternary operator ?")?; + let _ = self.consume(Colon, "Expected : after ternary operator ?")?; let third = self.ternary()?; return Ok(Expr::Ternary { first: Box::new(expr), - first_op, second: Box::new(second), - second_op, third: Box::new(third), }); } diff --git a/src/printer.rs b/src/printer.rs index d10bb76..e2e48cc 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -13,14 +13,9 @@ pub fn pretty_print(expr: &Expr) -> 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], - ), + } => parenthesize("?:", &[first, second, third]), } }