-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Include --options-with-hyphens in statement regex #3863
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
64f504c
Include --options-with-hyphens in statement regex
nabeelsherazi a2b9755
Apply suggestion from @JoeKar
nabeelsherazi 19d203e
Apply suggestion from @niten94
nabeelsherazi a087b27
Update sh.yaml
nabeelsherazi 1053d93
Update runtime/syntax/sh.yaml
nabeelsherazi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Single-letter options like
--aare no longer matched. I assume it is not intentional?Also nit: use the same order of alphanumerics in both parts of the regex, i.e. either
0-9A-Za-zin both orA-Za-z0-9in both?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depends, see this comment. At least
--aisn't really posix compliant and depends on the implementation of the invoked command and its argument list.Usually single-letter arguments should be single-hyphened and multi-letter arguments double-hyphened.
Yes, purely cosmetic, but I agree. Makes it more comprehensible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by "not posix compliant"? POSIX doesn't define any double-hyphened arguments for its standard commands, but doesn't forbid them either, right?
Does getopt_long(), for example, allow single-letter double-hyphened arguments or not?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you're right1. It was a GNU extension2.
Realizing that the special
--argument is missing that way.Yes it does, because it doesn't care about.
Long story short:
?
Edit:
Considered in suggestion.
Footnotes
https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap12.html ↩
https://www.gnu.org/prep/standards/html_node/Command_002dLine-Interfaces.html ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want it to be matched as well, can't the entire regex be much simpler:
"\\s+(-[\\w-]+)"?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Especially since the value could have a lot of possible formats, am I right that this doesn't really need to be addressed currently or in this PR?
I don't think
\Bat the beginning is appropiate, since(...)below is highlighted (if any):\B:not-option(--opt1) -(--opt2)(\s|^):not-option--opt1 ---opt2An illustration of what
\Bmatches is shown in this StackOverflow answer, but the explanation there doesn't cover the example above.To explain shortly for example,
\Bmatches the empty string betweennand-because there isn't any non-word character, according to the description under "Empty strings" in documentation.Maybe we shouldn't match
--anymore since it's hard to do so, and there are situations to write something likewrapper -- --opt-of-other-cmd.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hahaha, I think in general the problem is we are trying to write a parser in regex, which is famously recommended against.
I would say let not the perfect be the enemy of the good -- what we have now is still an improvement over what was there before. The correct way to handle this is likely a syntax highlighting mechanism a bit more sophisticated than regex. Shall we merge what we have and then circle back on this when someone has cycles?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @niten94 that we should just not match
--if it causes problems. It might even be better for readability if it has a different color than "normal" options.In this case the problem is more that there is no universal syntax for arguments as it is entirely up to the invoked program to parse them. From the shell's perspective they are all just arbitrary strings.
I agree, this is a lot of bikeshedding while just expanding the character groups without any of the special handling for edge cases would already be a nice improvement. Let's get that part merged and if someone wants to craft a perfect regex later that can happen in a separate PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree. There is no good solution for this, just some hacks.
Which one exactly? 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the part @Andriamanitra meant is expanding the character group used to highlight
--long-opt. Anyways, I think we can finally decide on this pattern which is lastly based on @dmaluka's suggestion: