This example evaluates a Starlark expression in the specified environment and returns its value.
(String expr, ImmutableMap<String, Object> env)
| 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 |
nothing calls this directly
no test coverage detected