Skip to content

Commit

Permalink
[ShellScript] Improve builtin "read" argument highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
deathaxe committed Aug 18, 2024
1 parent 8fa9304 commit 81662d2
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 24 deletions.
28 changes: 25 additions & 3 deletions ShellScript/Bash.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ contexts:
- include: cmd-export
- include: cmd-historic
- include: cmd-mapfile
- include: cmd-read
- include: cmd-readonly
- include: cmd-sudo
- include: cmd-test
Expand Down Expand Up @@ -570,6 +571,27 @@ contexts:
push: cmd-args-option-maybe-value
- include: cmd-args-end-of-options-then-variables-literal-values

###[ MAPFILE BUILTINS ]########################################################

cmd-read:
- match: read{{cmd_break}}
scope:
meta.function-call.identifier.shell
support.function.shell
set:
- cmd-args-meta
- cmd-read-args

cmd-read-args:
- match: ([-+])[cdiNnOpstu]+{{opt_break}}
scope:
meta.parameter.option.shell
variable.parameter.option.shell
captures:
1: punctuation.definition.parameter.shell
push: cmd-args-option-maybe-value
- include: cmd-args-end-of-options-then-variables-literal-values

###[ READONLY BUILTINS ]#######################################################

cmd-readonly:
Expand Down Expand Up @@ -3030,9 +3052,9 @@ variables:
# Note: Contains thosw, which are not present as dedicated context
builtin_cmds: |-
(?x: \. | \: | bg | bind | caller | cd | disown | enable | eval | fg
| getopts | hash | help | jobs | kill | logout | printf | pwd
| read | set | shift | shopt | source | su | suspend | times
| type | ulimit | umask | wait ){{cmd_break}}
| getopts | hash | help | jobs | kill | logout | printf | pwd | set
| shift | shopt | source | su | suspend | times | type | ulimit | umask
| wait ){{cmd_break}}
modifier_cmds: |-
(?x: builtin ){{cmd_break}}
Expand Down
85 changes: 64 additions & 21 deletions ShellScript/Bash/tests/syntax_test_scope.bash
Original file line number Diff line number Diff line change
Expand Up @@ -519,27 +519,6 @@ set -e -- -o {str,ing}
# ^^ - variable.parameter.option
# ^^^^^^^^^ meta.interpolation.brace.shell

read -d '' -sn 1 -t1 -- -t1 10
#^^^ meta.function-call.identifier.shell
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.arguments.shell
# ^ - meta.parameter
# ^^ meta.parameter.option.shell
# ^^^^ - meta.parameter
# ^^^ meta.parameter.option.shell
# ^^^ - meta.parameter
# ^^^ meta.parameter.option.shell
# ^^^^^^^^^^ - meta.parameter
#^^^ support.function.shell
# ^ variable.parameter.option.shell punctuation.definition.parameter.shell
# ^ variable.parameter.option.shell - punctuation
# ^^ string.quoted.single.shell
# ^^^ variable.parameter.option.shell
# ^ meta.number.integer.decimal.shell constant.numeric.value.shell
# ^^^ variable.parameter.option.shell
# ^^ keyword.operator.end-of-options.shell
# ^^^^ - constant - variable
# ^^ constant.numeric.value.shell

shift 2 --
#^^^^ meta.function-call.identifier.shell support.function.shell
# ^^^^^ meta.function-call.arguments.shell
Expand Down Expand Up @@ -11067,6 +11046,70 @@ mapfile -d ";" -n 10 -O $origin -s 5 -t -u 20 -C callback -c 10 array
# ^^^^^ variable.other.readwrite.shell


###############################################################################
# 4.2 Bash Builtin Commands (readarray) #
# https://www.gnu.org/software/bash/manual/bash.html#index-readarray #
# read [-ers] [-a aname] [-d delim] [-i text] [-n nchars] #
# [-N nchars] [-p prompt] [-t timeout] [-u fd] [name …] #
###############################################################################

read
# <- meta.function-call.identifier.shell support.function.shell
#^^^ meta.function-call.identifier.shell support.function.shell
# ^ - meta.function-call

read data
# <- meta.function-call.identifier.shell support.function.shell
#^^^ meta.function-call.identifier.shell support.function.shell
# ^^^^^ meta.function-call.arguments.shell
# ^^^^ variable.other.readwrite.shell
# ^ - meta.function-call

read -d '' -sn 1 -t1 -- -t1 10 data
#^^^ meta.function-call.identifier.shell
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.arguments.shell
# ^ - meta.parameter
# ^^ meta.parameter.option.shell
# ^^^^ - meta.parameter
# ^^^ meta.parameter.option.shell
# ^^^ - meta.parameter
# ^^^ meta.parameter.option.shell
# ^^^^^^^^^^ - meta.parameter
#^^^ support.function.shell
# ^ variable.parameter.option.shell punctuation.definition.parameter.shell
# ^ variable.parameter.option.shell - punctuation
# ^^ string.quoted.single.shell
# ^^^ variable.parameter.option.shell
# ^ meta.number.integer.decimal.shell constant.numeric.value.shell
# ^^^ variable.parameter.option.shell
# ^^ keyword.operator.end-of-options.shell
# ^^^ invalid.illegal.unexpected-token.shell
# ^^ invalid.illegal.unexpected-token.shell
# ^^^^ variable.other.readwrite.shell

read -ers -a aname -d ";" -i text -n 1 -N 2 -p prompt -t 10 -u 103 data
# <- meta.function-call.identifier.shell support.function.shell
#^^^ meta.function-call.identifier.shell support.function.shell
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.arguments.shell
# ^^^^ variable.parameter.option.shell
# ^^ variable.parameter.option.shell
# ^^^^^ variable.other.readwrite.shell
# ^^ variable.parameter.option.shell
# ^^^ string.quoted.double.shell
# ^^ variable.parameter.option.shell
# ^^^^ string.unquoted.shell
# ^^ variable.parameter.option.shell
# ^ constant.numeric.value.shell
# ^^ variable.parameter.option.shell
# ^ constant.numeric.value.shell
# ^^ variable.parameter.option.shell
# ^^^^^^ string.unquoted.shell
# ^^ variable.parameter.option.shell
# ^^ constant.numeric.value.shell
# ^^ variable.parameter.option.shell
# ^^^ constant.numeric.value.shell
# ^^^^ variable.other.readwrite.shell

###############################################################################
# 4.2 Bash Builtin Commands (readarray) #
# https://www.gnu.org/software/bash/manual/bash.html#index-readarray #
Expand Down
1 change: 1 addition & 0 deletions ShellScript/Zsh.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ contexts:
- cmd-args-end-of-options-then-function-references

cmd-mapfile: []
cmd-read: []

###[ COMMANDS ]################################################################

Expand Down

0 comments on commit 81662d2

Please sign in to comment.