AST - Print statement keeps track of the print token

This commit is contained in:
Emmanuel BENOîT 2023-01-19 19:03:25 +01:00
parent 8e938db4f9
commit 79033b78b9
5 changed files with 6 additions and 6 deletions

View file

@ -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<StmtNode>),
/// A conditional statement.

View file

@ -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), ";");
}

View file

@ -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,

View file

@ -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()
}

View file

@ -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: _,