diff --git a/parser/src/sexpr.rs b/parser/src/sexpr.rs index f221e2e..eaefc88 100644 --- a/parser/src/sexpr.rs +++ b/parser/src/sexpr.rs @@ -267,7 +267,7 @@ impl Debug for Place<'_> { match self { Self::Record(expr) => write!(f, "(Record {expr:?})"), Self::Variable(var) => <_ as Debug>::fmt(var, f), - Self::ArrayElement(var, index) => write!(f, "(index {var:?} {index:?})"), + Self::ArrayElement(var, index) => write!(f, "(ArrayAccess {var:?} {index:?})"), } } } diff --git a/parser/src/tests.rs b/parser/src/tests.rs index 8c942f9..dfbfd48 100644 --- a/parser/src/tests.rs +++ b/parser/src/tests.rs @@ -214,3 +214,27 @@ fn test_parser_relaxed_assignments() { } ); } + +#[test] +fn test_parser_inc_dec() { + let source = r#" + { ++a $0-- } + { --a[2] ++$(1 + 1) } + { a++ a["x"]-- } + { --a $"a"++ } + "#; + test_parser!(source => { + rules: [ + (None, Some("(body (Concat (IncrementL awk::a) (DecrementR (Record 0))))")), + ( + None, + Some("(body (Concat (DecrementL (ArrayAccess awk::a 2)) (IncrementL (Record (Add 1 1)))))") + ), + (None, Some("(body (Concat (IncrementR awk::a) (DecrementR (ArrayAccess awk::a \"x\"))))")), + (None, Some("(body (Concat (DecrementL awk::a) (IncrementR (Record \"a\"))))")), + ], + }); + // these should parse as (Cat (--L (++R $0)) a), or otherwise error out. + // FIXME: not treated as errors yet. + // test_parser!(is_err!("{ $0++ --a }", "{ ++$0 ++a }")); +}