diff --git a/src/ast.rs b/src/ast.rs index 14faee3..59c5166 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -55,7 +55,7 @@ pub enum StmtNode { /// An single expression Expression(ExprNode), /// The print statement - Print(ExprNode), + Print(Token, ExprNode), /// A block containing multiple statements. Block(Vec), /// A conditional statement. diff --git a/src/dumper.rs b/src/dumper.rs index a9b09b1..ca1c1ec 100644 --- a/src/dumper.rs +++ b/src/dumper.rs @@ -117,7 +117,7 @@ fn dump_statement(dumper: &mut Dumper, stmt: &StmtNode) { dumper.integrate("", dump_expression(expr), ";"); } - StmtNode::Print(expr) => { + StmtNode::Print(_, expr) => { dumper.integrate("print ", dump_expression(expr), ";"); } diff --git a/src/interpreter/interpretable.rs b/src/interpreter/interpretable.rs index f752f25..ad095a7 100644 --- a/src/interpreter/interpretable.rs +++ b/src/interpreter/interpretable.rs @@ -152,7 +152,7 @@ impl Interpretable for StmtNode { StmtNode::FunDecl(decl) => on_fun_decl(es, decl), StmtNode::ClassDecl(decl) => on_class_decl(es, decl), StmtNode::Expression(expr) => expr.interpret(es), - StmtNode::Print(expr) => on_print(es, expr), + StmtNode::Print(_, expr) => on_print(es, expr), StmtNode::Block(statements) => on_block(es, statements), StmtNode::If { condition, diff --git a/src/parser.rs b/src/parser.rs index cbf02a7..7845422 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -178,10 +178,10 @@ impl Parser { self.parse_loop_control_statement(&lcs) } else if let Some(ret) = self.expect(&[TokenType::Return]) { self.parse_return_statement(&ret) - } else if self.expect(&[TokenType::Print]).is_some() { + } else if let Some(print) = self.expect(&[TokenType::Print]) { let expression = self.parse_expression()?; self.consume(&TokenType::Semicolon, "expected ';' after value")?; - Ok(StmtNode::Print(expression)) + Ok(StmtNode::Print(print, expression)) } else { self.parse_expression_stmt() } diff --git a/src/resolver.rs b/src/resolver.rs index ea65cbd..e5710b2 100644 --- a/src/resolver.rs +++ b/src/resolver.rs @@ -522,7 +522,7 @@ impl VarResolver for StmtNode { }, StmtNode::Expression(expr) => expr.resolve(rs), - StmtNode::Print(expr) => expr.resolve(rs), + StmtNode::Print(_, expr) => expr.resolve(rs), StmtNode::LoopControl { is_break: _, loop_name: _,