new prefix operator "!" as logic NOT

This commit is contained in:
Celestino Amoroso 2025-01-04 17:47:59 +01:00
parent 760c1ee6da
commit 6b3351b324
2 changed files with 3 additions and 3 deletions

View File

@ -444,8 +444,7 @@ func (parser *parser) parseGeneral(scanner *scanner, ctx parserContext, termSymb
} else if tk.IsSymbol(SymStar) { } else if tk.IsSymbol(SymStar) {
tk.SetSymbol(SymDereference) tk.SetSymbol(SymDereference)
} else if tk.IsSymbol(SymExclamation) { } else if tk.IsSymbol(SymExclamation) {
err = tk.Errorf("postfix opertor %q requires an operand on its left side", tk) tk.SetSymbol(SymNot)
break
} }
firstToken = false firstToken = false
} }

View File

@ -26,12 +26,13 @@ func TestBool(t *testing.T) {
/* 12 */ {`true or false`, true, nil}, /* 12 */ {`true or false`, true, nil},
/* 13 */ {`true or []`, true, nil}, /* 13 */ {`true or []`, true, nil},
/* 14 */ {`[] or false`, nil, errors.New(`got list as left operand type of 'OR' operator, it must be bool`)}, /* 14 */ {`[] or false`, nil, errors.New(`got list as left operand type of 'OR' operator, it must be bool`)},
/* 15 */ {`!true`, false, nil},
/* 13 */ //{`true or []`, nil, errors.New(`[1:8] left operand 'true' [bool] and right operand '[]' [list] are not compatible with operator "OR"`)}, /* 13 */ //{`true or []`, nil, errors.New(`[1:8] left operand 'true' [bool] and right operand '[]' [list] are not compatible with operator "OR"`)},
} }
// t.Setenv("EXPR_PATH", ".") // t.Setenv("EXPR_PATH", ".")
// runTestSuiteSpec(t, section, inputs, 1) // runTestSuiteSpec(t, section, inputs, 15)
runTestSuite(t, section, inputs) runTestSuite(t, section, inputs)
} }