databricks / sjsonnet

Apache License 2.0
267 stars 55 forks source link

sjsonnet allows computed imports unlike go-jsonnet #138

Closed nicklan closed 1 year ago

nicklan commented 3 years ago

Sample file:

local i = import "a" + import "b";
0

go-jsonnet:

$ jsonnet foo.jsonnet
foo.jsonnet:1:18-34 Computed imports are not allowed

local i = import "a" + import "b";

sjsonnet:

$ sjsonnet foo.jsonnet
0
szeiger commented 2 years ago

This looks like a precedence problem. import should have lower precedence than + but Sjsonnet treats it as higher. We see the same for . (local buiApiServerReleasePipeline = import "./release-pipeline.jsonnet.TEMPLATE".buiApiServerReleasePipeline;)

szeiger commented 2 years ago

From https://jsonnet.org/ref/spec.html:

Everything is left associative. In the case of assert, error, function, if, import, importstr, and local, ambiguity is resolved by consuming as many tokens as possible on the right hand side.

But the grammar contains

import string

and this is what Sjsonnet implements. The intention is probably to parse as import expr and then assert that the expr is a string.