diff --git a/adana-script/src/ast.rs b/adana-script/src/ast.rs index f6c36d6..cbaf1e7 100644 --- a/adana-script/src/ast.rs +++ b/adana-script/src/ast.rs @@ -401,9 +401,6 @@ pub fn to_ast( Ok(TreeNodeValue::MultiDepthVariableAssign{root: *root, next_keys}) } else { - // FIXME for my future self. x.y.z or x[0][1] is not yet supported - // for assignment - // We need Primitive::Ref to make it happen Err(anyhow::Error::msg(format!( "AST ERROR: invalid variable expression {name:?} => {expr:?}", ))) diff --git a/adana-script/src/parser.rs b/adana-script/src/parser.rs index d5a52af..af9c59b 100644 --- a/adana-script/src/parser.rs +++ b/adana-script/src/parser.rs @@ -480,10 +480,25 @@ fn parse_struct_expr(s: &str) -> Res { ))(s) } pub(super) fn parse_struct(s: &str) -> Res { - let pair_key_value = |p| { + use nom::character::complete::char as charParser; + let parse_key = |p| { + preceded( + multispace0, + terminated( + map( + preceded( + opt(charParser('"')), + terminated(parse_key_struct, opt(charParser('"'))), + ), + String::from, + ), + multispace0, + ), + )(p) + }; + let pair_key_value = move|p| { separated_pair( - preceded(multispace0, terminated(map(preceded(opt(nom::character::complete::char('"')),terminated(parse_key_struct, - opt(nom::character::complete::char('"')))), String::from), multispace0)), + parse_key, tag_no_space(":"), preceded(opt(comments),parse_struct_expr)) }(p); diff --git a/adana-script/src/tests/test_chaining.rs b/adana-script/src/tests/test_chaining.rs index 3004d2a..6542bdb 100644 --- a/adana-script/src/tests/test_chaining.rs +++ b/adana-script/src/tests/test_chaining.rs @@ -28,7 +28,7 @@ fn complex_struct_array_struct() { m: 12, y: ["hello", 3, struct {n: "world"}] } - x = x.y[0] + " " + x.y[2]["n"] # FIXME HACKY + x = x.y[0] + " " + x.y[2]["n"] "#; let mut ctx = BTreeMap::new(); @@ -122,7 +122,7 @@ fn complex_struct_struct_struct_other() { fn simple_array_two_depth() { let expr = r#" z = [0, 2, "hello", [3," ", "world"]] - x = (z[2] + z[3][1] + z[3][2]) # FIXME requires parenthesises + x = z[2] + z[3][1] + z[3][2] "#; let mut ctx = BTreeMap::new(); let res = compute(expr, &mut ctx, "N/A").unwrap();