Skip to content

Commit

Permalink
[ShellScript] Fix ZSH case clause termination (#4096)
Browse files Browse the repository at this point in the history
This commit implements different sets of case clause terminators supported
by each shell script dialect:

  Bash: `;;`, `;&` and `;;&`
  ZSH:  `;;`, `;&` and `;|`
  • Loading branch information
deathaxe authored Nov 17, 2024
1 parent 5b342a7 commit fd5d06d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion ShellScript/Bash.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ contexts:
- include: statements

case-clause-end:
- match: ;;&?|;&
- match: '{{case_clause_end}}'
scope: meta.clause.shell punctuation.terminator.clause.shell
pop: 1

Expand Down Expand Up @@ -3113,6 +3113,8 @@ variables:
# in embed...escape statements.
no_escape_behind: (?<![^\\]\\)(?<![\\]{3})

case_clause_end: ;;&?|;&

# Parameter expansions
is_interpolation: (?=\$[({{{identifier_char}}{{special_variables}}]|`)
parameter_switch: '[AEKLPQUaku]'
Expand Down
4 changes: 3 additions & 1 deletion ShellScript/Zsh.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ contexts:
- meta_scope: meta.clause.patterns.shell
# comment, end of clause or end of line
# indicate pattern being enclosed in balanced parentheses
- match: (?=(?:$|;;&?|;&|}|esac{{cmd_break}})|\s+#)
- match: (?=(?:$|}|{{case_clause_end}}|esac{{cmd_break}})|\s+#)
fail: case-clause-paren-pattern
- include: case-clause-pattern-body

Expand Down Expand Up @@ -1114,6 +1114,8 @@ variables:
hex_digit: '[\h_]'
oct_digit: '[0-7_]'

case_clause_end: ;[;&|]

# Parameter expansions
is_interpolation: (?=\$[({\[{{identifier_char}}{{special_variables}}]|`)

Expand Down
4 changes: 2 additions & 2 deletions ShellScript/Zsh/tests/syntax_test_scope.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ case $word {
;;
# ^^ punctuation.terminator.clause.shell

((foo|bar)baz) cmd arg ;;
((foo|bar)baz) cmd arg ;|
# ^ meta.clause.patterns.shell - meta.string - string
# ^^^^^^^^^ meta.clause.patterns.shell meta.string.glob.shell meta.group.regexp.shell string.unquoted.shell
# ^^^ meta.clause.patterns.shell meta.string.glob.shell string.unquoted.shell
Expand All @@ -556,7 +556,7 @@ case $word {
# ^^^ meta.string.glob.shell string.unquoted.shell
# ^^ punctuation.terminator.clause.shell
(foo|bar)baz) cmd arg ;;
(foo|bar)baz) cmd arg ;&
# ^^^^^^^^^ meta.clause.patterns.shell meta.string.glob.shell meta.group.regexp.shell string.unquoted.shell
# ^^^ meta.clause.patterns.shell meta.string.glob.shell string.unquoted.shell
# ^ meta.clause.patterns.shell - meta.string - string
Expand Down

0 comments on commit fd5d06d

Please sign in to comment.