You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#2036 introduces a new syntax to explicitly specify the format of an imported file. Before, this would be just guessed from the extension of the file, which has obvious limits.
This issue aims at bikeshedding the final syntax of imports with an explicit format. The one proposed in the original PR is like:
let
html = import 'Raw "foo.html",
foo = import 'Json "foo.json.hidden",
in
...
However some flaws were reported during further discussions,, in particular that this makes it look like import is just a standard function, while it's not. Typically you can't partially apply it and you can't even apply it further if the stuff that is imported is a function, as in import 'Nickel "foo.ncl" some_value. This was precisely done to allow the kind of syntax extension discussed here without breaking backward-compat (we could have decided to go with import "foo.html" 'Raw for example, which is totally possible today)
Another proposed syntax was to use as, for example:
let
html = import "foo.html" as raw,
foo = import "foo.json.hidden" as json,
in
...
It reads quite naturally, and should be doable without introducing new keywords (once again, thanks to making import special in the parser some time ago). A variant would be to use some form of qualifier, like a protocol, for example import json:"foo.json"
What other languages do
Most other config languages (Jsonnet, CUE, KCL, Nix, etc.) that we looked at usually have a read or readFile builtin that first reads the whole thing as a string, and then they just use a deserialization/unmarshaling/parsing function in a second step (would correspond to Nickel' std.deserialize).
Webpack has something similar, with the following syntax: import 'file.txt?raw'. However there's an obvious risk of collision with filenames that contain ?. We can also imagine allowing URLs one day, and the collision will even be worse, so it's probably better to keep the format specification well separated from the file name.
The text was updated successfully, but these errors were encountered:
#2036 introduces a new syntax to explicitly specify the format of an imported file. Before, this would be just guessed from the extension of the file, which has obvious limits.
This issue aims at bikeshedding the final syntax of imports with an explicit format. The one proposed in the original PR is like:
However some flaws were reported during further discussions,, in particular that this makes it look like
import
is just a standard function, while it's not. Typically you can't partially apply it and you can't even apply it further if the stuff that is imported is a function, as inimport 'Nickel "foo.ncl" some_value
. This was precisely done to allow the kind of syntax extension discussed here without breaking backward-compat (we could have decided to go withimport "foo.html" 'Raw
for example, which is totally possible today)Another proposed syntax was to use
as
, for example:It reads quite naturally, and should be doable without introducing new keywords (once again, thanks to making
import
special in the parser some time ago). A variant would be to use some form of qualifier, like a protocol, for exampleimport json:"foo.json"
What other languages do
Most other config languages (Jsonnet, CUE, KCL, Nix, etc.) that we looked at usually have a
read
orreadFile
builtin that first reads the whole thing as a string, and then they just use a deserialization/unmarshaling/parsing function in a second step (would correspond to Nickel'std.deserialize
).Dhall seems to be the only one with a proper import syntax (or at least something similar to guide the interpretation of an imported blob), and they use the
as
keyword as well: https://docs.dhall-lang.org/tutorials/Language-Tour.html#importing-raw-text.Webpack has something similar, with the following syntax:
import 'file.txt?raw'
. However there's an obvious risk of collision with filenames that contain?
. We can also imagine allowing URLs one day, and the collision will even be worse, so it's probably better to keep the format specification well separated from the file name.The text was updated successfully, but these errors were encountered: