AST - Function call expression node

This commit is contained in:
Emmanuel BENOîT 2023-01-02 15:05:41 +01:00
parent a317e54426
commit 2e7a897c47

View file

@ -73,6 +73,17 @@ pub enum ExprNode {
/// A reference to a variable.
Variable { name: Token },
/// A function call.
Call {
/// Token that contains the name of the function.
name: Token,
/// Right parenthesis that closes the list of arguments. Used to
/// report errors.
right_paren: Token,
/// The list of function arguments.
arguments: Vec<ExprNode>,
},
}
/* -------------------------------- *
@ -189,6 +200,25 @@ impl AstDumper for ExprNode {
panic!("Unexpected token type for token {:#?}", value)
}
}
ExprNode::Call {
name,
right_paren: _,
arguments,
} => {
if arguments.len() > 0 {
format!(
"( call {} {} )",
name.lexeme,
arguments
.iter()
.map(|arg| arg.dump())
.collect::<Vec<String>>()
.join(" ")
)
} else {
format!("( call {} )", name.lexeme)
}
}
}
}
}