Skip to content

Commit

Permalink
[ShellScript] Arithmetic expansions in subscriptions
Browse files Browse the repository at this point in the history
Variable subscriptions undergo arithmetic expansion.
  • Loading branch information
deathaxe committed Sep 22, 2024
1 parent d243ff2 commit ab67b7d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
4 changes: 2 additions & 2 deletions ShellScript/Bash.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,12 @@ contexts:
variable-subscription-body:
- meta_include_prototype: false
- meta_scope: meta.item-access.shell
- meta_content_scope: meta.string.shell string.unquoted.shell
- meta_content_scope: meta.arithmetic.shell
- match: \]
scope: punctuation.section.item-access.end.shell
pop: 1
- include: eoc-pop
- include: string-unquoted-content
- include: expression-content

assignment-value-meta:
- meta_include_prototype: false
Expand Down
41 changes: 23 additions & 18 deletions ShellScript/Bash/tests/syntax_test_scope.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3621,64 +3621,69 @@ array=([one]== ["two"]='what' [4+5]=qux [five]=0 [six]=0s)
declare -a array
array[500]=value
#<- meta.assignment.l-value.shell variable.other.readwrite.shell
#^^^^ meta.assignment.l-value.shell - meta.sequence
#^^^^ meta.assignment.l-value.shell - meta.item-access
# ^^^^^ meta.assignment.l-value.shell meta.item-access.shell
# ^ meta.assignment.shell - meta.sequence
# ^ meta.assignment.shell - meta.item-access
# ^^^^^ meta.assignment.r-value.shell meta.string.glob.shell string.unquoted.shell
# ^ - meta
#^^^^ variable.other.readwrite.shell
# ^ punctuation.section.item-access.begin.shell
# ^^^ meta.string.shell string.unquoted.shell
# ^^^ meta.number.integer.decimal.shell constant.numeric.value.shell
# ^ punctuation.section.item-access.end.shell
# ^ keyword.operator.assignment
# ^^^^^ meta.string.glob.shell string.unquoted.shell

array["foo"]=bar
#<- meta.assignment.l-value.shell variable.other.readwrite.shell
#^^^^ meta.assignment.l-value.shell - meta.sequence
# ^^^^^^^ meta.assignment.l-value.shell meta.item-access.shell
# ^ meta.assignment.shell - meta.sequence
#^^^^ meta.assignment.l-value.shell - meta.item-access
# ^ meta.assignment.l-value.shell meta.item-access.shell - meta.arithmetic
# ^^^^^ meta.assignment.l-value.shell meta.item-access.shell meta.arithmetic.shell
# ^ meta.assignment.l-value.shell meta.item-access.shell - meta.arithmetic
# ^ meta.assignment.shell - meta.item-access
# ^^^ meta.assignment.r-value.shell meta.string.glob.shell string.unquoted.shell
# ^ - meta
#^^^^ variable.other.readwrite.shell
# ^^^^^^^ meta.item-access.shell - variable
# ^ punctuation.section.item-access.begin.shell
# ^^^^^ string.quoted.double.shell
# ^ punctuation.definition.quoted.begin.shell
# ^^^ variable.other.readwrite.shell
# ^ punctuation.definition.quoted.end.shell
# ^ punctuation.section.item-access.end.shell
# ^ keyword.operator.assignment.shell
# ^^^ meta.string.glob.shell string.unquoted.shell

array[foo]=bar
#<- meta.assignment.l-value.shell variable.other.readwrite.shell
#^^^^ meta.assignment.l-value.shell - meta.sequence
#^^^^ meta.assignment.l-value.shell - meta.item-access
# ^^^^^ meta.assignment.l-value.shell meta.item-access.shell
# ^ meta.assignment.shell - meta.sequence
# ^ meta.assignment.shell - meta.item-access
# ^^^ meta.assignment.r-value.shell meta.string.glob.shell string.unquoted.shell
# ^ - meta
# ^^^^^ meta.item-access.shell
# ^ punctuation.section.item-access.begin.shell - variable
# ^^^ meta.string.shell string.unquoted.shell
# ^^^ meta.arithmetic.shell variable.other.readwrite.shell
# ^ punctuation.section.item-access.end.shell - variable
# ^ keyword.operator.assignment.shell
# ^^^ meta.string.glob.shell string.unquoted.shell

foo[${j}+10]="`foo`"
#<- meta.assignment.l-value.shell variable.other.readwrite.shell
#^^^ meta.assignment.l-value.shell - meta.sequence
# ^^^^^^^^^ meta.assignment.l-value.shell meta.item-access.shell
# ^ meta.assignment.shell - meta.sequence
#^^ meta.assignment.l-value.shell - meta.item-access
# ^ meta.assignment.l-value.shell meta.item-access.shell - meta.arithmetic
# ^^^^^^^ meta.assignment.l-value.shell meta.item-access.shell meta.arithmetic.shell
# ^ meta.assignment.l-value.shell meta.item-access.shell - meta.arithmetic
# ^ meta.assignment.shell - meta.item-access
# ^ meta.assignment.r-value.shell meta.string.glob.shell - meta.interpolation
# ^^^^^ meta.assignment.r-value.shell meta.string.glob.shell meta.interpolation.command.shell
# ^ meta.assignment.r-value.shell meta.string.glob.shell - meta.interpolation
# ^ - meta
#^^ variable.other.readwrite.shell
# ^ punctuation.section.item-access.begin.shell
# ^^^^ meta.string.shell meta.interpolation.parameter.shell
# ^^^^ meta.interpolation.parameter.shell
# ^ punctuation.definition.variable.shell
# ^ punctuation.section.interpolation.begin.shell
# ^ variable.other.readwrite.shell
# ^ punctuation.section.interpolation.end.shell
# ^^^ meta.string.shell string.unquoted.shell
# ^ keyword.operator.arithmetic.shell
# ^^ meta.number.integer.decimal.shell constant.numeric.value.shell
# ^ punctuation.section.item-access.end.shell
# ^ keyword.operator.assignment.shell
# ^ string.quoted.double.shell punctuation.definition.string.begin.shell
Expand Down Expand Up @@ -11175,7 +11180,7 @@ let var[10]=5*(20+$idx)
# ^^^ variable.other.readwrite.shell
# ^^^^ meta.item-access.shell
# ^ punctuation.section.item-access.begin.shell
# ^^ meta.string.shell string.unquoted.shell
# ^^ constant.numeric.value.shell
# ^ punctuation.section.item-access.end.shell
# ^ keyword.operator.assignment.shell
# ^ meta.number.integer.decimal.shell constant.numeric.value.shell
Expand Down
12 changes: 6 additions & 6 deletions ShellScript/Zsh/tests/syntax_test_scope.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -5781,9 +5781,9 @@ var[1]=Hello
# <- variable.other.readwrite.shell
#^^ variable.other.readwrite.shell
# ^^^ meta.item-access.shell
# ^ punctuation.section.item-access.begin.shell - meta.string - string
# ^ meta.string.shell string.unquoted.shell - punctuation
# ^ punctuation.section.item-access.end.shell - meta.string - string
# ^ punctuation.section.item-access.begin.shell
# ^ meta.arithmetic.shell meta.number.integer.decimal.shell constant.numeric.value.shell
# ^ punctuation.section.item-access.end.shell
# ^ keyword.operator.assignment.shell
# ^^^^^ meta.string.glob.shell string.unquoted.shell
Expand All @@ -5793,9 +5793,9 @@ echo $var[1] World
# ^^^^^^^^^^^^^^ meta.function-call.arguments.shell
# ^^^^^^^ meta.string.glob.shell meta.interpolation.parameter.shell
# ^^^ meta.item-access.shell - variable
# ^ punctuation.section.item-access.begin.shell - string
# ^ meta.string.glob.shell string.unquoted.shell
# ^ punctuation.section.item-access.end.shell - string
# ^ punctuation.section.item-access.begin.shell
# ^ meta.arithmetic.shell meta.number.integer.decimal.shell constant.numeric.value.shell
# ^ punctuation.section.item-access.end.shell
# ^^^^^ meta.string.glob.shell string.unquoted.shell - meta.interpolation
Expand Down

0 comments on commit ab67b7d

Please sign in to comment.