parseAndEval evaluates a simple expression string with literals and operators. Supports: +, -, *, /, %, ==, !=, <, >, <=, >=, &&, ||, !
(expr string, targetType workflow.DataType)
| 15 | // parseAndEval evaluates a simple expression string with literals |
| 16 | // and operators. Supports: +, -, *, /, %, ==, !=, <, >, <=, >=, &&, ||, ! |
| 17 | func parseAndEval(expr string, targetType workflowapi.DataType) (Value, error) { |
| 18 | p := &parser{input: expr, pos: 0} |
| 19 | val, err := p.parseOr() |
| 20 | if err != nil { |
| 21 | return Value{}, fmt.Errorf("evaluating %q: %w", expr, err) |
| 22 | } |
| 23 | return val.Cast(targetType), nil |
| 24 | } |
| 25 | |
| 26 | // Minimal recursive-descent expression parser/evaluator. |
| 27 | type parser struct { |
no test coverage detected