add ::new_variable
This commit is contained in:
parent
0c01a4a958
commit
febe0e9dd8
10
src/ast.rs
10
src/ast.rs
|
|
@ -55,10 +55,20 @@ pub enum Constant {
|
||||||
String(String),
|
String(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Location {
|
||||||
|
pub fn new_variable(name: impl Into<String>) -> Self {
|
||||||
|
Self::Variable { name: name.into() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Expression {
|
impl Expression {
|
||||||
pub fn new_constant(value: impl Into<Constant>) -> Self {
|
pub fn new_constant(value: impl Into<Constant>) -> Self {
|
||||||
Self::Constant(value.into())
|
Self::Constant(value.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_variable(name: impl Into<String>) -> Self {
|
||||||
|
Self::Variable(Location::new_variable(name))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<()> for Constant {
|
impl From<()> for Constant {
|
||||||
|
|
|
||||||
|
|
@ -407,7 +407,7 @@ mod tests {
|
||||||
args: vec![],
|
args: vec![],
|
||||||
body: vec![
|
body: vec![
|
||||||
Statement::Assign {
|
Statement::Assign {
|
||||||
target: Location::Variable { name: "x".into() },
|
target: Location::new_variable("x"),
|
||||||
source: Box::new(Expression::new_constant(1)),
|
source: Box::new(Expression::new_constant(1)),
|
||||||
},
|
},
|
||||||
Statement::Local {
|
Statement::Local {
|
||||||
|
|
@ -415,13 +415,11 @@ mod tests {
|
||||||
init: Some(Box::new(Expression::new_constant(2))),
|
init: Some(Box::new(Expression::new_constant(2))),
|
||||||
},
|
},
|
||||||
Statement::Assign {
|
Statement::Assign {
|
||||||
target: Location::Variable { name: "x".into() },
|
target: Location::new_variable("x"),
|
||||||
source: Box::new(Expression::new_constant(3)),
|
source: Box::new(Expression::new_constant(3)),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
ret: Some(Box::new(Expression::Variable(Location::Variable {
|
ret: Some(Box::new(Expression::new_variable("x"))),
|
||||||
name: "x".into(),
|
|
||||||
}))),
|
|
||||||
};
|
};
|
||||||
let env = crate::types::Table::default();
|
let env = crate::types::Table::default();
|
||||||
let testee = build(&testee);
|
let testee = build(&testee);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user