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, move commands in shell syntax file #3270
Conversation
runtime/syntax/sh.yaml
Outdated
@@ -30,12 +30,12 @@ rules: | |||
# Numbers | |||
- constant.number: "\\b[0-9]+\\b" | |||
# Conditionals and control flow | |||
- statement: "\\b(case|do|done|elif|else|esac|exit|fi|for|function|if|in|local|read|return|select|shift|then|time|until|while)\\b" | |||
- statement: "\\b(break|case|continue|do|done|elif|else|esac|eval|exec|exit|fi|for|function|getopts|if|in|local|read|return|select|shift|then|time|trap|until|while)\\b" |
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.
Strictly speaking, eval
, exec
, getopts
and trap
are builtins, not keywords, so perhaps it's better to move them to the "Shell commands" group below? (The same actually applies to exit
, read
, shift
and time
.)
I'm actually not against highlighting them as keywords, if that's more practical. But then it's not clear why e.g. exec
and exit
are highlighted as keywords but e.g. export
and set
are not.
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 wrote that most of the commands added are builtin commands so that it would be known where the commands can be looked up when using something like man
.
I do not know why time
would be highlighted as a keyword but I was thinking that commands like exec
and exit
would be highlighted as such because they are used with control flow.
I think read
and shift
are also highlighted as keywords because they are sometimes used in loops. I realized that I have not seen eval
being used with control flow so I am thinking about moving it to "Shell commands".
I do not mind much about how commands and keywords are highlighted so I do not know if moving builtin commands to "Shell commands" would be better, but I still do not think people would mind that much.
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 think now I understand what should be the criteria: "Conditionals and control flow" should include those commands that actually affect control flow, not just are often used in loops. I.e. break
, continue
, return
- as I've realized, technically these are not keywords (i.e. not special syntax constructs), but they affect the control flow, i.e. they determine which command will be executed next, so they should be highlighted as "Conditionals and control flow" together with keywords.
See for example the Flow-Control Constructs
section in https://linux.die.net/man/1/dash.
exec
, exit
- arguably these also can be considered as control-flow commands, as they affect execution of the entire script.
But getopts
, read
, shift
, time
and trap
- these should be moved to "Shell commands", it seems.
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.
Well, trap
might be an exception: it does affect the execution flow of the script (although not immediately), so we may leave it in "Conditionals and control flow".
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.
Also I'm not quite sure what to do with local
, which is also technically a command, not a keyword.
local
, let
, set
, export
and read
are all related to setting shell variables, so it might make sense to highlight them all the same way.
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 think local
was in "Conditionals and control flow" because the value of specified variables where the function is run is not modified.
I think it would be better moving getopts
, local
, read
, shift
and time
to "Shell commands" because control flow is not affected when they are run, but I will move them in this pull request.
Edit: I have also added wait
.
The pull request description has also been edited so that it would be a bit more clear why some commands were added in "Conditionals and control flow". |
Move `local`, `read`, `shift` and `time` to "Shell commands" in shell syntax file.
c8d7a9f
to
3f65498
Compare
Add `break`, `command`, `continue`, `eval`, `exec`, `getopt`, `getopts`, `trap` and `wait` command in shell syntax file.
3f65498
to
4911a56
Compare
LGTM. @JoeKar WDYT? |
The commands below are added in this pull request:
break
command
continue
eval
exec
- There are times the command is used with replacing the shell process and other commands in a script are not run when it is replaced, so it is added in the "Conditionals and control flow" group.getopt
getopts
trap
- It is usually used with running a command when a signal is received so it is added in the "Conditionals and control flow" group.wait
- The command returns when commands in background have finished running so it is added in the "Conditionals and control flow" group.The commands below are highlighted using a different color group in this pull request:
local
read
shift
time
The commands that are added and moved except
getopt
are usually builtin commands insh
implementations so they can be looked up in reference pages of those implementations.