InterpretString interprets a string of go code and returns the result.
(exprStr string)
| 189 | |
| 190 | // InterpretString interprets a string of go code and returns the result. |
| 191 | func (scope *Scope) InterpretString(exprStr string) (v interface{}, err error) { |
| 192 | defer func() { |
| 193 | if r := recover(); r != nil { |
| 194 | err = errors.Errorf("interpreting %q: %s", exprStr, fmt.Sprint(r)) |
| 195 | } |
| 196 | }() |
| 197 | |
| 198 | node, _, err := scope.ParseString(exprStr) |
| 199 | if err != nil { |
| 200 | return node, err |
| 201 | } |
| 202 | errs := scope.CheckStatement(node) |
| 203 | if len(errs) > 0 { |
| 204 | return node, errs[0] |
| 205 | } |
| 206 | return scope.Interpret(node) |
| 207 | } |
| 208 | |
| 209 | // Interpret interprets an ast.Node and returns the value. |
| 210 | func (scope *Scope) Interpret(expr ast.Node) (interface{}, error) { |