diff --git a/pkg/interpreter/interpreter.go b/pkg/interpreter/interpreter.go index 0cd0c19..fdaa9ee 100644 --- a/pkg/interpreter/interpreter.go +++ b/pkg/interpreter/interpreter.go @@ -121,24 +121,35 @@ func (intr *treeInterpreter) execute(node parsing.ASTNode, value interface{}, fu case parsing.TOKNE: return !util.ObjsEqual(left, right), nil } - leftNum, ok := util.ToNumber(left) - if !ok { - return nil, nil - } - rightNum, ok := util.ToNumber(right) - if !ok { - return nil, nil + if leftStr, ok := left.(string); ok { + if rightStr, ok := right.(string); ok { + switch node.Value { + case parsing.TOKGT: + return leftStr > rightStr, nil + case parsing.TOKGTE: + return leftStr >= rightStr, nil + case parsing.TOKLT: + return leftStr < rightStr, nil + case parsing.TOKLTE: + return leftStr <= rightStr, nil + } + } } - switch node.Value { - case parsing.TOKGT: - return leftNum > rightNum, nil - case parsing.TOKGTE: - return leftNum >= rightNum, nil - case parsing.TOKLT: - return leftNum < rightNum, nil - case parsing.TOKLTE: - return leftNum <= rightNum, nil + if leftNum, ok := util.ToNumber(left); ok { + if rightNum, ok := util.ToNumber(right); ok { + switch node.Value { + case parsing.TOKGT: + return leftNum > rightNum, nil + case parsing.TOKGTE: + return leftNum >= rightNum, nil + case parsing.TOKLT: + return leftNum < rightNum, nil + case parsing.TOKLTE: + return leftNum <= rightNum, nil + } + } } + return nil, nil case parsing.ASTExpRef: return func(data interface{}) (interface{}, error) { return intr.execute(node.Children[0], data, functionCaller)