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),
|
||||
}
|
||||
|
||||
impl Location {
|
||||
pub fn new_variable(name: impl Into<String>) -> Self {
|
||||
Self::Variable { name: name.into() }
|
||||
}
|
||||
}
|
||||
|
||||
impl Expression {
|
||||
pub fn new_constant(value: impl Into<Constant>) -> Self {
|
||||
Self::Constant(value.into())
|
||||
}
|
||||
|
||||
pub fn new_variable(name: impl Into<String>) -> Self {
|
||||
Self::Variable(Location::new_variable(name))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<()> for Constant {
|
||||
|
|
|
|||
|
|
@ -407,7 +407,7 @@ mod tests {
|
|||
args: vec![],
|
||||
body: vec![
|
||||
Statement::Assign {
|
||||
target: Location::Variable { name: "x".into() },
|
||||
target: Location::new_variable("x"),
|
||||
source: Box::new(Expression::new_constant(1)),
|
||||
},
|
||||
Statement::Local {
|
||||
|
|
@ -415,13 +415,11 @@ mod tests {
|
|||
init: Some(Box::new(Expression::new_constant(2))),
|
||||
},
|
||||
Statement::Assign {
|
||||
target: Location::Variable { name: "x".into() },
|
||||
target: Location::new_variable("x"),
|
||||
source: Box::new(Expression::new_constant(3)),
|
||||
},
|
||||
],
|
||||
ret: Some(Box::new(Expression::Variable(Location::Variable {
|
||||
name: "x".into(),
|
||||
}))),
|
||||
ret: Some(Box::new(Expression::new_variable("x"))),
|
||||
};
|
||||
let env = crate::types::Table::default();
|
||||
let testee = build(&testee);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user