MCPcopy
hub / github.com/d4l3k/go-pry / InterpretString

Method InterpretString

pry/interpreter.go:191–207  ·  view source on GitHub ↗

InterpretString interprets a string of go code and returns the result.

(exprStr string)

Source from the content-addressed store, hash-verified

189
190// InterpretString interprets a string of go code and returns the result.
191func (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.
210func (scope *Scope) Interpret(expr ast.Node) (interface{}, error) {

Callers 15

FuzzFunction · 0.95
TestEmptyStringFunction · 0.95
TestStringLiteralFunction · 0.95
TestIntLiteralFunction · 0.95
TestHexIntLiteralFunction · 0.95
TestOctalIntLiteralFunction · 0.95
TestCharLiteralFunction · 0.95
TestArrayLiteralFunction · 0.95
TestFixedArrayLiteralFunction · 0.95
TestFixedArrayFunction · 0.95
TestFixedArraySetFunction · 0.95
TestArraySetFunction · 0.95

Calls 3

ParseStringMethod · 0.95
CheckStatementMethod · 0.95
InterpretMethod · 0.95

Tested by 15

TestEmptyStringFunction · 0.76
TestStringLiteralFunction · 0.76
TestIntLiteralFunction · 0.76
TestHexIntLiteralFunction · 0.76
TestOctalIntLiteralFunction · 0.76
TestCharLiteralFunction · 0.76
TestArrayLiteralFunction · 0.76
TestFixedArrayLiteralFunction · 0.76
TestFixedArrayFunction · 0.76
TestFixedArraySetFunction · 0.76
TestArraySetFunction · 0.76
TestMapLiteralFunction · 0.76