Skip to content

Commit

Permalink
fixed a bug in ast eval and fixed type mismatched after desrialization
Browse files Browse the repository at this point in the history
  • Loading branch information
ARMy4D committed Dec 7, 2019
1 parent 696d34f commit 20d081e
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func New(funcMap, inputMap, outputMap map[string]interface{}) (e *Evaluator, err
}

func (e *Evaluator) Eval(ast parse.AST) (map[string]interface{}, error) {
return e.eval(ast)
return e.eval(ast.Node)
}

func (e *Evaluator) eval(node parse.Node) (res map[string]interface{}, err error) {
Expand Down Expand Up @@ -92,6 +92,12 @@ func (e *Evaluator) evalEngine(node parse.Node) (map[string]interface{}, error)
return nil, err
}
}
case parse.EngineNode:
for _, nr := range n.Rules {
if err := e.evalRuleNode(&nr); err != nil {
return nil, err
}
}
default:
return nil, fmt.Errorf("unknown command %T", node)
}
Expand Down Expand Up @@ -151,22 +157,40 @@ func (e *Evaluator) evalExpression(node parse.Node) (interface{}, error) {
switch n := node.(type) {
case *parse.ExpressionNode:
return e.evalExpression(n.Expression)
case parse.ExpressionNode:
return e.evalExpression(n.Expression)
case *parse.NumberNode:
return e.evalNumber(n)
case parse.NumberNode:
return e.evalNumber(&n)
case *parse.StringNode:
return e.evalString(n)
case parse.StringNode:
return e.evalString(&n)
case *parse.BoolNode:
return e.evalBool(n)
case parse.BoolNode:
return e.evalBool(&n)
case *parse.NotNode:
return e.evalNot(n)
case parse.NotNode:
return e.evalNot(&n)
case *parse.IdentifierNode:
return e.evalIdentifier(n)
case parse.IdentifierNode:
return e.evalIdentifier(&n)
case *parse.FunctionNode:
return e.evalFunction(n)
case parse.FunctionNode:
return e.evalFunction(&n)
case *parse.MathExpressionNode:
return e.evalMathExpression(n)
case parse.MathExpressionNode:
return e.evalMathExpression(&n)
case *parse.ConditionalExpressionNode:
return e.evalConditionalExpression(n)
case parse.ConditionalExpressionNode:
return e.evalConditionalExpression(&n)
default:
return nil, fmt.Errorf("unknown command %T", node)
}
Expand Down

0 comments on commit 20d081e

Please sign in to comment.