-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add antiquotations to paths #5066
Conversation
LGTM, can you add some documentation about this to |
I don't think this changes the way any program would behave, but it's a cleaner internal representation.
The failure on ubuntu seems to be due to some unrelated issue with recursive nix and network connection? I could be misinterpreting that though. |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/tweag-nix-dev-update-17/15037/1 |
Note that this assertion in the docs is wrong:
The This is actually how my https://github.com/cstrahan/tree-sitter-nix grammar parses this as well, so I don't really mind -- I think it's a reasonable parse, after all. I think it makes sense that the second I discovered this while adding another test case (inspired by the docs):
turns out, the actual parse looks like:
|
@cstrahan Oh, you're totally right. It doesn't get parsed as a single path, but it also does not get parsed as a division. I'm not sure exactly how to clarify that in the docs without introducing more confusion. Unfortunately, I think what makes the most sense is indeed to parse - Antiquotation is supported in any paths except those in angle brackets.
- `./${foo}-${bar}.nix` is a more convenient way of writing
- `./. + "/" + foo + "-" + bar + ".nix"` or `./. + "/${foo}-${bar}.nix"`. At
- least one slash must appear *before* any antiquotations for this to be
- recognized as a path. `a.${foo}/b.${bar}` is a syntactically valid division
- operation. `./a.${foo}/b.${bar}` is a path.
+ Antiquotation is supported in any paths except those in angle brackets.
+ `./${foo}-${bar}.nix` is a more convenient way of writing
+ `./. + "/" + foo + "-" + bar + ".nix"` or `./. + "/${foo}-${bar}.nix"`. At
+ least one slash must appear *before* any antiquotations for this to be
+ recognized as a path. For backward compatibility, `a.${foo}/bar` is
+ parsed as `a.${foo}` applied to the path `/bar`. To make a single path,
+ you can always prepend a slash: `/a.${foo}/bar`. |
This enables you to write something like
Without this one has to write
Which is less ergonomic. The other intuitive approaches
and
Are semantically different, and usually not what one wants. Adding this syntax provides an obvious, and usually correct way of accessing paths that depend on a variable.
This also affects HPATHs e.g.
~/${foo}/bar
It does not affect SPATHs e.g.
<nixpkgs/${foo}>
is not valid, even with this PR.I couldn't figure out any way to do SPATHs without changing the lex of things like
3<a.${foo}
, which is currently a valid lex. In theory anything that ends in>
would be an error anyways, but in order to find that out one needs to parse the whole expression, including arbitrary nix code in the antiquotation. Given that flakes don't support SPATHs anyways, this seems like a minor sacrifice.This change shouldn't affect anything that currently passes the lexer. All the tests pass without modification, and the generated nixpkgs derivations are identical.