ast: now supports espression forest (multi expressions)

This commit is contained in:
2024-03-31 05:57:02 +02:00
parent aa705e68bf
commit 4e361f938e
4 changed files with 41 additions and 8 deletions
+4 -4
View File
@@ -65,7 +65,7 @@ func TestParser(t *testing.T) {
/* 39 */ {`(((1)))`, int64(1), nil},
/* 40 */ {`"uno_" + var2`, `uno_abc`, nil},
/* 41 */ {`0 || 0.0 && "hello"`, false, nil},
/* 42 */ {`"s" + true`, nil, errors.New(`left operand 's' [string] is not compatible with right operand 'true' [bool] with respect to operator "+"`)},
/* 42 */ {`"s" + true`, nil, errors.New(`left operand 's' [string] and right operand 'true' [bool] are not compatible with operator "+"`)},
/* 43 */ {`+false`, nil, errors.New(`prefix/postfix operator "+" do not support operand 'false' [bool]`)},
/* 44 */ {`false // very simple expression`, false, nil},
/* 45 */ {`1 + // Missing right operator`, nil, errors.New(`infix operator "+" requires two operands, got 1`)},
@@ -108,7 +108,7 @@ func TestParser(t *testing.T) {
/* 82 */ {`5 % 2`, int64(1), nil},
/* 83 */ {`5 % (-2)`, int64(1), nil},
/* 84 */ {`-5 % 2`, int64(-1), nil},
/* 85 */ {`5 % 2.0`, nil, errors.New(`left operand '5' [int64] is not compatible with right operand '2' [float64] with respect to operator "%"`)},
/* 85 */ {`5 % 2.0`, nil, errors.New(`left operand '5' [int64] and right operand '2' [float64] are not compatible with operator "%"`)},
/* 86 */ {`"a" < "b" AND NOT (2 < 1)`, true, nil},
/* 87 */ {`"a" < "b" AND NOT (2 == 1)`, true, nil},
/* 88 */ {`"a" < "b" AND ~ 2 == 1`, true, nil},
@@ -147,7 +147,7 @@ func TestParser(t *testing.T) {
good := true
if expr, gotErr = parser.parse(scanner); gotErr == nil {
gotResult, gotErr = expr.eval(ctx)
gotResult, gotErr = expr.Eval(ctx)
}
if gotResult != input.wantResult {
@@ -221,7 +221,7 @@ func NoTestListParser(t *testing.T) {
good := true
if expr, gotErr = parser.parse(scanner); gotErr == nil {
gotResult, gotErr = expr.eval(ctx)
gotResult, gotErr = expr.Eval(ctx)
}
if (gotResult == nil && input.wantResult != nil) || (gotResult != nil && input.wantResult == nil) {