MCPcopy Index your code
hub / github.com/bazelbuild/bazel / evalExpr

Method evalExpr

src/test/java/net/starlark/java/eval/Examples.java:65–79  ·  view source on GitHub ↗

This example evaluates a Starlark expression in the specified environment and returns its value.

(String expr, ImmutableMap<String, Object> env)

Source from the content-addressed store, hash-verified

63 * value.
64 */
65 Object evalExpr(String expr, ImmutableMap<String, Object> env)
66 throws SyntaxError.Exception, EvalException, InterruptedException {
67 // The apparent file name (for error messages) will be "<expr>".
68 ParserInput input = ParserInput.fromString(expr, "<expr>");
69
70 // Create the module in which the expression is evaluated.
71 // It may define additional predeclared environment bindings.
72 Module module = Module.withPredeclared(StarlarkSemantics.DEFAULT, env);
73
74 // Resolve, compile, and execute the expression.
75 try (Mutability mu = Mutability.create(input.getFile())) {
76 StarlarkThread thread = StarlarkThread.createTransient(mu, StarlarkSemantics.DEFAULT);
77 return Starlark.eval(input, FileOptions.DEFAULT, module, thread);
78 }
79 }
80
81 /**
82 * This advanced example reads, parses, and compiles a Starlark file to a Program, then later

Callers

nothing calls this directly

Calls 6

fromStringMethod · 0.95
withPredeclaredMethod · 0.95
createMethod · 0.95
getFileMethod · 0.95
createTransientMethod · 0.95
evalMethod · 0.95

Tested by

no test coverage detected