Skip to content

Commit

Permalink
[ShellScript] Improve test expression and pattern matching highlighti…
Browse files Browse the repository at this point in the history
…ng (#3827)

* [ShellScript] Fix regexp group highlighting

Fixes #3825

* [ShellScript] Improve shell patterns and POSIX ERE

This commit...

1. separates implementation of basic Bash pattern matching an posix extended
   regular expressions to more accurately scope them.

2. adjusts [[ ... ]] implementation to make use of both pattern types:
   a) after `==` or `!=` => basic pattern matching
   b) after `=~` => posix extended regular expressions

3. implements various variants of pattern contexts to correctly handle
   bailouts depending on where patterns occur.
   (e.g.: test expressions, parameter expansions, case patterns, ...)

4. fine tunes rules to follow language specifications more closely.

POSIX Extended Regular Expressions are based on `RegExp (Basic)` but have been
simplified by removing all the modifiers and (?x) regexp matching as it is not
supported. Related context are included directly into Bash.sublime-syntax as
they share various contexts with basic pattern matching and it may reduce
friction in case Bash is inherited by a 3rd-party syntax (e.g.: Makefile).

* [ShellScript] Drop unsupported parens in test args

This commit removes support for parentheses within test command arguments,
as those are not supported by Bash or Zsh.

* [ShellScript] Separate contexts for [ ... ] and [[ ... ]]

This commit distinguishes builtin test expressions `[ ... ]` and compound test
expressions `[[ ... ]]` to respect the different features supported.

Builtin test expressions support same limited test arguments as `test` command,
only.

* [ShellScript] Fix comparison operator scope in test expressions

This commit...

1. scopes single `=` as comparison operator as it is equal to `==`.
2. scopes -ot, -ne, ... as comparison operators

* [ShellScript] Tweak compound test context names

This commit renames some contexts to make it more obvious where they belong to.
  • Loading branch information
deathaxe authored Sep 11, 2023
1 parent 886f926 commit b58ab9d
Show file tree
Hide file tree
Showing 2 changed files with 1,478 additions and 436 deletions.
Loading

0 comments on commit b58ab9d

Please sign in to comment.