Add table expression constructor
This commit is contained in:
parent
ead7ac054d
commit
b131d40702
11
src/ast.rs
11
src/ast.rs
|
|
@ -88,6 +88,17 @@ impl Expression {
|
||||||
pub fn new_variable(name: impl Into<String>) -> Self {
|
pub fn new_variable(name: impl Into<String>) -> Self {
|
||||||
Self::Variable(Location::new_variable(name))
|
Self::Variable(Location::new_variable(name))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_table<'a>(fields: impl Iterator<Item = (&'a str, Expression)>) -> Self {
|
||||||
|
Self::Table(Table {
|
||||||
|
fields: fields
|
||||||
|
.map(|(key, value)| Field {
|
||||||
|
name: Expression::new_constant(key),
|
||||||
|
init: value,
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<()> for Constant {
|
impl From<()> for Constant {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user