change Location::Field::table to Expression
It doesn’t need to be a location
This commit is contained in:
parent
febe0e9dd8
commit
2747749c37
|
|
@ -19,7 +19,7 @@ pub enum Location {
|
||||||
name: Ident,
|
name: Ident,
|
||||||
},
|
},
|
||||||
Field {
|
Field {
|
||||||
table: Box<Location>,
|
table: Box<Expression>,
|
||||||
index: Box<Expression>,
|
index: Box<Expression>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,9 @@ mod tests {
|
||||||
fn test_fields() {
|
fn test_fields() {
|
||||||
let mut scope = Scope::default();
|
let mut scope = Scope::default();
|
||||||
let loc = ast::Location::Field {
|
let loc = ast::Location::Field {
|
||||||
table: Box::new(ast::Location::Variable { name: "foo".into() }),
|
table: Box::new(ast::Expression::Variable(ast::Location::Variable {
|
||||||
|
name: "foo".into(),
|
||||||
|
})),
|
||||||
index: Box::new(ast::Expression::Constant(ast::Constant::String(
|
index: Box::new(ast::Expression::Constant(ast::Constant::String(
|
||||||
"bar".into(),
|
"bar".into(),
|
||||||
))),
|
))),
|
||||||
|
|
@ -249,7 +251,9 @@ mod tests {
|
||||||
assert_eq!(bar.get("bar".into()), None);
|
assert_eq!(bar.get("bar".into()), None);
|
||||||
ast::Statement::Assign {
|
ast::Statement::Assign {
|
||||||
target: ast::Location::Field {
|
target: ast::Location::Field {
|
||||||
table: Box::new(ast::Location::Variable { name: "foo".into() }),
|
table: Box::new(ast::Expression::Variable(ast::Location::Variable {
|
||||||
|
name: "foo".into(),
|
||||||
|
})),
|
||||||
index: Box::new(ast::Expression::Constant(ast::Constant::String(
|
index: Box::new(ast::Expression::Constant(ast::Constant::String(
|
||||||
"bar".into(),
|
"bar".into(),
|
||||||
))),
|
))),
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ enum Location {
|
||||||
id: Ident,
|
id: Ident,
|
||||||
},
|
},
|
||||||
Field {
|
Field {
|
||||||
table: Box<Location>,
|
table: Box<Expression>,
|
||||||
index: Box<Expression>,
|
index: Box<Expression>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -156,12 +156,12 @@ fn lookup(scope: &BuildContext<'_>, loc: &ast::Location) -> Location {
|
||||||
.request(&"_ENV".into())
|
.request(&"_ENV".into())
|
||||||
.expect("_ENV must be always available");
|
.expect("_ENV must be always available");
|
||||||
Location::Field {
|
Location::Field {
|
||||||
table: Box::new(Location::Variable { id: env }),
|
table: Box::new(Expression::Variable(Location::Variable { id: env })),
|
||||||
index: Box::new(Expression::Constant(ast::Constant::String(name.clone()))),
|
index: Box::new(Expression::Constant(ast::Constant::String(name.clone()))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast::Location::Field { table, index } => {
|
ast::Location::Field { table, index } => {
|
||||||
let table = Box::new(lookup(scope, &table));
|
let table = Box::new(build_expression(scope, &table));
|
||||||
let index = Box::new(build_expression(scope, &index));
|
let index = Box::new(build_expression(scope, &index));
|
||||||
Location::Field { table, index }
|
Location::Field { table, index }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user