AST - Function call expression node
This commit is contained in:
parent
a317e54426
commit
2e7a897c47
1 changed files with 30 additions and 0 deletions
30
src/ast.rs
30
src/ast.rs
|
@ -73,6 +73,17 @@ pub enum ExprNode {
|
||||||
|
|
||||||
/// A reference to a variable.
|
/// A reference to a variable.
|
||||||
Variable { name: Token },
|
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)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue