Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃敟 Assignments and aliases conflicts with default arguments #379

Closed
casey opened this issue Nov 29, 2018 · 6 comments
Closed

馃敟 Assignments and aliases conflicts with default arguments #379

casey opened this issue Nov 29, 2018 · 6 comments
Milestone

Comments

@casey
Copy link
Owner

casey commented Nov 29, 2018

:= has been added as a synonym for = in assignments, aliases and exports, and = is deprecated in those same contexts and will be removed in a future update, most likely v0.5.0.

Since this is a disruptive change, I think it's a good idea to explain the rationale.

Currently, = is used in assignments, aliases, exports, and default arguments:

alias b = build
foo = "bar"
export var = "val"

build module="rob":
  ./build --module {{module}} 

The just language doesn't have keywords in the conventional sense, so the parser uses lookahead to disambiguate conflicting constructs.

However, lookahead is limited and messy, and some conflicts cannot be resolved. So for example, these constructs fail to parse:

# the parser thinks that this is an export
export foo = "bar":
  echo {{foo}}

# the parser thinks that this is an alias:
bar = "baz"
alias foo = bar:
  echo {{foo}}

Also, there are additional constructs that I'd like to add that will produce further conflicts, like settings: set setting = value.

In order to fix this, there are a few options:

A. Use more lookahead to disambiguate expressions
B. Use a token other than = to introduce default arguments to recipes
C. Use a token other than = in assignments, exports and aliases

Using more lookahead, as in A, gets messy very quickly, especially as it's extended to longer and more complex constructs, which would limit extension of the grammar in the future, so I think ruling that out is reasonable.

B is reasonable, but I don't think that there is a good alternative to = for default argument values. : is already used to end recipe argument lists.

On the other hand, := is a good alternative for assignments, exports, aliases, and a future set setting := value notation. := is used in make, which just is most similar to, and is also used for assignment in Go and Algol. So, I think C is the best choice.

My current plan is to release this as v0.4.3, and follow up after some time has passed with a version, probably v0.5.0 that removes the old meaning of =. I don't know what the most popular ways of getting just are, but I'd like to give v0.4.3 a chance to appear in package managers so that nobody is in the unfortunate situation of needing to run the same justfile on < 0.4.3 and >= 0.5.0, and not having a construct available that will work on both.

@casey casey added the bug label Nov 29, 2018
@casey casey changed the title Can't have a recipe called export with arguments 馃敟 Assignments and aliases conflicts with default arguments Apr 13, 2019
@casey
Copy link
Owner Author

casey commented Apr 13, 2019

The reason this happens is because both export, alias, default arguments use =. I'd like to introduce set SETTING = VALUE items, which will extend the issue to recipes named set as well.

The solution that I'm now leaning towards is to change export, alias, and vanilla assignment to use the Algol/Go/Make-style :=:

baz := "bob"

export foo := "bar"

alias b := build

Settings would also use :=:

set shell := ["sh", "-u", "-c"]

Changing the token that introduces a default argument is also possible, but I don't know of any alternatives to = that are in use in other languages. Additionally, := is already used in makefiles, and is actually the type of assignment in make that most closely matches the semantics of assignment in just.

The new := notation could be introduced immediately or gradually. If introduced immediately, no justfiles would unexpectedly change behavior, they'll just fail to parse and need to be corrected.

However, a phased introduction might be more user friendly:

  1. := is accepted as a synonym to =
  2. = in assignments, exports, and aliases generates a warning
  3. = in assignments, exports, and aliases becomes a parse error
  4. = loses its old meaning, and now only introduces default arguments

Combining phases 1 and 2 is reasonable, as is skipping phase 3. A misplaced = could give an error message like Did you mean `:=`? in perpetuity, since it's likely to be a common mistake.

@runeimp
Copy link

runeimp commented Apr 14, 2019

I like the idea of being friendly with the phases but in all honesty who is it for? I'm still waiting on v0.4.0 to drop in Homebrew. I'd imagine people jumping on alias and set from downloaded releases will not have already created hundreds or even tens of Justfiles that would need updating. If this is to be done I'd imagine it's early enough to just make the change and let users update there Justfiles as is obvious and necessary. It's just a quick interactive search and replace.

@runeimp
Copy link

runeimp commented Apr 14, 2019

But I'd personally rather see the parser updated for those two cases. Oh, yeah, forcing := on export and variables could have massive consequences too. Didn't think of that in my last post. But I understand that updating the parser could be its own bag of troubles.

@casey
Copy link
Owner Author

casey commented Apr 14, 2019

Yeah, the phase-out of = would primarily be for existing exports and assignments.

It would be pretty easy to supply a --fix flag, which could update a justfile in-place to fix warnings.

@casey
Copy link
Owner Author

casey commented Apr 18, 2019

Just updated the issue with my comments from the PR, so that if people follow the link in the deprecation warning, they'll find this issue.

@casey casey added enhancement and removed bug labels May 15, 2019
DrSensor added a commit to DrSensor/scdlang that referenced this issue May 25, 2019
@casey casey modified the milestones: soon, 1.0 May 27, 2019
@casey
Copy link
Owner Author

casey commented Mar 29, 2021

It is done! I just released just v0.9.0, which turns the deprecation warning into a hard error. Eventually, the code that checks for and produces that error will be removed, which will allow creating recipes named export and alias with a parameter with a default value. This is tracked in #782.

@casey casey closed this as completed Mar 29, 2021
ngirard added a commit to ngirard/rust-cli-boilerplate that referenced this issue Apr 18, 2021
Recent versions of Just choke on this justfile with this message:
```
error: `=` in assignments, exports, and aliases has been phased out on favor of `:=`
Please see this issue for more details: casey/just#379
```
This PR fixes that.

Cheers, and thanks for your work !
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants