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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Presence of bare word strings makes addition of new keyword in expression position a breaking change #12767

Open
sholderbach opened this issue May 4, 2024 · 2 comments
Labels
needs-design this feature requires design stability-concern Design so we can evolve Nu w/o breaking code post 1.0-stability. syntax Changes to the grammar or syntax beyond parser bugfixes
Milestone

Comments

@sholderbach
Copy link
Member

Nushell is allowing the user to provide a string in expression positions without quotes (i.e. not command position, e.g. in argument position, inside a list expression etc.)

e.g.

[foo bar baz]

If in the future (post 1.0 stability) we would decide foo should become a keyword you can use to work with expressions and accept it in expression position this would break existing code and possibly existing NUON data.

For existing keywords we have special logic requiring you to quote them in NUON data, behave already differently when executing existing code and perform the necessary quoting for to nuon

Possible mitigations

  1. pre-reserve potential keywords that may be used in an expression way. (e.g. use prior art and create a list of potential future keywords that will require you to quote them even before reaching 1.0, examples without giving it much thought typeof, async, lambda, switch,...)
  2. commit to never adding keywords that can be used in expression position (some keywords may only ever exist in statement position or special syntax forms e.g. else)
  3. if adding a keyword that will be a breaking change (requiring a Major version bump, political decision if we are willing to accept that) restrict its keyword properties on strict grammar form and as long as those requirements are not met treat it as a string, which will limit the breaking potential but also the quality of error messages we can provide and how well syntax highlighting works.
@sholderbach sholderbach added needs-design this feature requires design syntax Changes to the grammar or syntax beyond parser bugfixes labels May 4, 2024
@sholderbach sholderbach added this to the 1.0 milestone May 4, 2024
@sholderbach sholderbach added the stability-concern Design so we can evolve Nu w/o breaking code post 1.0-stability. label May 4, 2024
@IanManske
Copy link
Member

IanManske commented May 4, 2024

Expressions in lists and records usually require parentheses anyways, so I'm not sure if adding new keywords would break your example.

For example, these examples are currently interpreted as lists of bare words (or expressions):

[not false]

[if true {1} else {0}]

The argument position should also be able to be handled by the parser. The command position, on the other hand, I think could be an issue.

@sholderbach
Copy link
Member Author

Good point @IanManske that our current parse_list_expression is already more restrictive.
Any attempts to relax those semantics to allow additional expressivity (or avoid parens) will also have to conclude pre-1.0.

We should at least think about other places where (math) expressions are currently used to verify those restrictions.

false in your example still is a keyword, so before 1.0 we need to pin down the list of literals/sentinel values etc. that could be used like that.

For the command call position I opened #12768

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-design this feature requires design stability-concern Design so we can evolve Nu w/o breaking code post 1.0-stability. syntax Changes to the grammar or syntax beyond parser bugfixes
Projects
None yet
Development

No branches or pull requests

2 participants