From 2747749c37ba1db7c5ebefaa326fcb42f9b9d4ad Mon Sep 17 00:00:00 2001 From: numzero Date: Sat, 19 Apr 2025 14:39:19 +0300 Subject: [PATCH] change Location::Field::table to Expression MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It doesn’t need to be a location --- src/ast.rs | 2 +- src/run.rs | 8 ++++++-- src/twopass.rs | 6 +++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index 79aeb6f..39354de 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -19,7 +19,7 @@ pub enum Location { name: Ident, }, Field { - table: Box, + table: Box, index: Box, }, } diff --git a/src/run.rs b/src/run.rs index 9632f93..5707c67 100644 --- a/src/run.rs +++ b/src/run.rs @@ -183,7 +183,9 @@ mod tests { fn test_fields() { let mut scope = Scope::default(); 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( "bar".into(), ))), @@ -249,7 +251,9 @@ mod tests { assert_eq!(bar.get("bar".into()), None); ast::Statement::Assign { 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( "bar".into(), ))), diff --git a/src/twopass.rs b/src/twopass.rs index 2b29286..27b9200 100644 --- a/src/twopass.rs +++ b/src/twopass.rs @@ -37,7 +37,7 @@ enum Location { id: Ident, }, Field { - table: Box, + table: Box, index: Box, }, } @@ -156,12 +156,12 @@ fn lookup(scope: &BuildContext<'_>, loc: &ast::Location) -> Location { .request(&"_ENV".into()) .expect("_ENV must be always available"); 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()))), } } 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)); Location::Field { table, index } }