ast: Require --help to parse more keywords as decorated statement#10000
Merged
Conversation
ridiculousfish
approved these changes
Sep 17, 2023
Member
ridiculousfish
left a comment
There was a problem hiding this comment.
LGTM. I think this can also be extended this to begin.
Recall that begin, for historical reasons, doesn't need a statement terminator. This is OK:
begin echo hello; end
Today begin --foo; end fails with the same "end outside of a block" but I think it should enjoy your nice fix here too.
This makes it so
```fish
if -e foo
# do something
end
```
complains about `-e` not being a command instead of `end` being used
outside of an if-block.
That means both that `-e` could now be used as a command name (it
already can outside of `if`!) *and* that we get a better error!
The only way to get `if` to be a decorated statement now is to use `if
-h` or `if --help` specifically (with a literal option).
The same goes for switch and while.
It would be possible, alternatively, to disallow `if -e` and point
towards using `test` instead, but the "unknown command" message should
already point towards using `test` more than pointing at the
"end" (that might be quite far away).
b448e4e to
b1b60e4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This makes it so
complains about
-enot being a command instead ofendbeing used outside of an if-block.That means both that
-ecould now be used as a command name (it already can outside ofif!) and that we get a better error!The only way to get
ifto be a decorated statement now is to useif -horif --helpspecifically (with a literal option).The same goes for switch and while.
It would be possible, alternatively, to disallow
if -eand point towards usingtestinstead, but the "unknown command" message should already point towards usingtestmore than pointing at the "end" (that might be quite far away).TODOs: