* Gracefully handle encountered regular expression when running jsonnetfmt, adding tests.
* Do not validate verbatim strings.
* Also do not validate string blocks.
* Change golden prefix for formatter tests to fmt.golden to be consistant with cpp version.
* Export FormatNode so external users can pretty print an AST
Signed-off-by: Tom Wilkie <tom@grafana.com>
* Expose RawAST function.
Signed-off-by: Tom Wilkie <tom@grafana.com>
* Add comment
Signed-off-by: Tom Wilkie <tom@grafana.com>
---------
Signed-off-by: Tom Wilkie <tom@grafana.com>
Co-authored-by: Tom Wilkie <tom@grafana.com>
Fixes multiple issues with stack traces leading to missing
stack trace lines. Also, we no longer put builtin context
on the line which *calls* the builtin as if it was a part
of the builtin itself.
Code for stack trace handling was centralized. We no longer
need traceElement argument in ~every function. Now the stack
trace state is kept solely in the interpreter.
Desugar the locals in object comprehensions
"traditionally" instead of handling them manually.
Object comprehensions allow the locals to depend
on the index variable which means that they are separate
for each field. It doesn't make sense to treat them as
a property of the whole object.
Fixes#358.
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.
TestSdumpLargeDefinition is depnding on a global state change in
TestSdumpReusedPointers. It can't pass if it runs in the wrong order.
Fixes internal auto-filled bug.
Exposes what I consider a good public API from the `internal/formatter`
package.
Having a go-native formatter is an awesome thing, especially because it
allows shipping the formatter as part of other projects. It's also fair
to keep the formatter's code in `internal`, yet third party projects
should have a way to use relevant parts of it.
* Extract some test utilities to a separate package.
* Rename some test utilities.
* Internally expose DirectChildren.
* Add LocationRange to some non-expr AST parts,
such as local binds, parameters and object fields.
* Add end-of-file-reached testcases.
There is no reason for external users to directly depend
on parser. It had a few random things exported as well,
namely errors and "children" functions (helpers for AST
traversal).
It was easy to extract the errors package, but I needed to leave
children in parser for now. The errors package was also
made internal, but it's a candidate for making it public
again potentially (if someone wants to display error messages
just like us). For now it's probably too incomplete anyway.
This change has a potential of breaking the existing users
since we technically remove public APIs. These were not needed
or even helpful for actually running Jsonnet code, but perhaps
someone used them anyway.