From b8d2678435548e5ece24d1e1c7c95b318c3c5b2c Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 22 Jul 2026 08:51:00 +0200 Subject: [PATCH] fix(grammar): reject "=" and "!=" as unary test prefix operators fixes #99 --- src/feel.grammar | 1 - test/expressions.txt | 17 ++++++++++++++--- test/unary-tests.txt | 21 +++++++++++++++++---- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/feel.grammar b/src/feel.grammar index d495da5..56c0b3d 100644 --- a/src/feel.grammar +++ b/src/feel.grammar @@ -185,7 +185,6 @@ Comparison { } SimplePositiveUnaryTest { - CompareOp<"=" | "!="> endpoint | CompareOp<">" | ">=" | "<" | "<="> endpoint | Interval } diff --git a/test/expressions.txt b/test/expressions.txt index 5ce2a2e..d8ae14e 100644 --- a/test/expressions.txt +++ b/test/expressions.txt @@ -159,9 +159,9 @@ Expressions( # Comparison (simple positive unary tests) { "top": "Expressions" } -(=10) = [10..10]; -(=10) = (=10); -(!=10) = (!=10) +(<10) = [10..10]; +(<10) = (<10); +(>=10) = (>=10) ==> @@ -2694,6 +2694,17 @@ Expressions( ) +# Simple Positive Unary Test (error, "=" and "!=" are not valid prefix operators) + += "foo" + +==> + +Expression( + ⚠(CompareOp),StringLiteral +) + + # VariableName (contextual) { "context": { "foo'a **": 1, "aa**": 1, "a - b": 1, "a * b": 1, "what if?": 1, "Profit and loss": 1 }, "top": "Expressions" } foo'a **; diff --git a/test/unary-tests.txt b/test/unary-tests.txt index 8ea15c8..fd24021 100644 --- a/test/unary-tests.txt +++ b/test/unary-tests.txt @@ -88,8 +88,6 @@ UnaryTests( # Comparison { "top": "UnaryTests" } -= 10, -!= 10, < 10, <= 10, > 10, @@ -98,8 +96,6 @@ UnaryTests( ==> UnaryTests(PositiveUnaryTests( - PositiveUnaryTest(...), - PositiveUnaryTest(...), PositiveUnaryTest(...), PositiveUnaryTest(...), PositiveUnaryTest(...), @@ -107,6 +103,23 @@ UnaryTests(PositiveUnaryTests( )) +# Comparison (error, "=" and "!=" are not valid unary test operators) { "top": "UnaryTests" } + += 10, +!= 10 + +==> + +UnaryTests( + ⚠(CompareOp), + PositiveUnaryTests( + PositiveUnaryTest(NumericLiteral), + ⚠(CompareOp), + PositiveUnaryTest(NumericLiteral) + ) +) + + # Negation { "top": "UnaryTests" } not(a)