This allows configuration of a VM with an external code variable that has been pre-parsed into an AST node.
This allows a caller to pre-parse a large object into a node and re-use that for multiple VMs. The cost
of converting the object to an ast.Node is incurred only once by the caller as opposed to having this
eagerly incurred (whether or not the object is used) before the eval.
Allow reset of ext and TLA vars for VM reuse
Currently ext and TLA vars can be set but not reset. This makes
re-using VMs that have different variables impossible.
Add VM methods to be able to reset ext and TLA vars
We used to treat dummy paths like <stdin>, <std>, <extvar> as
real import locations, which causes obvious problem for importers.
After this change we consistently pass "" (an empty string) as location
for non-imported paths.
We exposed new functions to properly handle all paths.
The first function family, EvaluateFile* which allow evaluating
a Jsonnet program at a specified importable path. It should
be used in most cases.
The second function family, EvaluateAnonymousSnippet* allows evaluating
a snippet without an importable path. It should be used for situations
like the code passed as a commandline argument, stdin, etc.
The old function family, EvaluateSnippet* is now deprecated, but
works the same as before, i.e. the passed filenames are treated
as imported paths.
Changes are required to custom importers to make sure they satisfy
the refined contract.
Fixes#329.
* It adds new API which allows using VM for importing
files in external tools "just as Jsonnet would". This is
primarily intended for use in static analysis tools.
* Imports are now cached between evaluate calls. This may improve
performance significantly for some users. I would like to add
some way of achieving this with commandline in the future.
* Additional layer of caching was internally added - AST level.
This was necessary so that Jsonnet could always return the same
exact AST when asked multiple times (meaning the same pointers).
Current go-jsonnet is not really 0.12.1 - it even
reports 0.12.0. This brings all the good stuff
from recent cpp-jsonnet commits and actually syncs
the version.
* Add test support for multi-file output.
* Add -update support for multi-file output tests.
* Add support for string output in multi-file output mode.
* Rename 'stringOutput' to 'stringOutputMode' to better express what it does
* Refactor main_test to make it less nested.
This also causes the -update flag to output a list of files which
have been updated. This does not include the paths which are deleted
for multi-file tests.
EvaluateSnippetMulti comment was copied from another function by mistake.
Add a space between the license and the package name.
Add a few periods after the comments.
Fixesgoogle/go-jsonnet#160
The imports in "_gen.go" were not used, compiled, or
apparently useful so remove.
The color field in the ErrorFormatter was never set
to true and never used. This brought in many unused
dependencies including x/sys/unix that aren't ever
used. Move the color dependencies to the jsonnet main
package and set the colorized output there. Turn the
exported ErrorFormatter into an interface. In the future
it could be used to export JSON or HTML output.
Fixesgoogle/go-jsonnet#131
Currently, `jsonnet.VM#NativeFunction` takes a single argument of type
`jsonnet.nativeFunction`. This is ok for internal use, but because this
type is private to the `jsonnet` package, it is not possible for a
third party to call this function (since it can't instantiate the type).
This commit makes this type public to remedy this problem.
* Location, error formatting and stack trace improvements
* Static context for AST nodes
* Thunks no longer need `name`
* Prototype for showing snippets in error messages (old format still
available)
* Use ast.Function to represent methods and local function sugar.
* Change tests so that the error output is pretty