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

Add, move commands in shell syntax file #3270

Merged
merged 2 commits into from May 22, 2024

Conversation

niten94
Copy link
Contributor

@niten94 niten94 commented Apr 25, 2024

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 in sh implementations so they can be looked up in reference pages of those implementations.

@@ -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"
Copy link
Collaborator

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.

Copy link
Contributor Author

@niten94 niten94 Apr 30, 2024

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.

Copy link
Collaborator

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.

Copy link
Collaborator

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".

Copy link
Collaborator

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.

Copy link
Contributor Author

@niten94 niten94 May 22, 2024

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.

@niten94
Copy link
Contributor Author

niten94 commented May 3, 2024

eval was highlighted as a keyword because commands like exit can be run using it, but such commands are not usually run using eval so I have moved it to "Shell commands". I was also thinking about the same with command so the note about command in the pull request description has been removed.

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.
Add `break`, `command`, `continue`, `eval`, `exec`, `getopt`, `getopts`,
`trap` and `wait` command in shell syntax file.
@niten94 niten94 changed the title Add commands in shell syntax file Add, move commands in shell syntax file May 22, 2024
@dmaluka
Copy link
Collaborator

dmaluka commented May 22, 2024

LGTM. @JoeKar WDYT?

@JoeKar JoeKar merged commit e9bd1b3 into zyedidia:master May 22, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants