Skip to content

Commit

Permalink
'main': Highlight backslash escape sequences outside quotes.
Browse files Browse the repository at this point in the history
Fixes #631.

WIP: test expectations should be updated (12 failures including cthulhu)
  • Loading branch information
danielshahaf committed Mar 19, 2020
1 parent dfc4112 commit ad8358c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/highlighters/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ This highlighter defines the following styles:
* `dollar-quoted-argument-unclosed` - unclosed dollar-quoted arguments (`` $'foo ``)
* `rc-quote` - two single quotes inside single quotes when the `RC_QUOTES` option is set (`` 'foo''bar' ``)
* `dollar-double-quoted-argument` - parameter expansion inside double quotes (`$foo` inside `""`)
* `back-un-quoted-argument` - backslash escape sequences outside quotes (`\"` in `print -r \"bar\"`)
* `back-double-quoted-argument` - backslash escape sequences inside double-quoted arguments (`\"` in `"foo\"bar"`)
* `back-dollar-quoted-argument` - backslash escape sequences inside dollar-quoted arguments (`\x` in `$'\x48'`)
* `assign` - parameter assignments (`x=foo` and `x=( )`)
Expand Down
11 changes: 9 additions & 2 deletions highlighters/main/main-highlighter.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
: ${ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]:=fg=yellow}
: ${ZSH_HIGHLIGHT_STYLES[rc-quote]:=fg=cyan}
: ${ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]:=fg=cyan}
: ${ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]:=fg=cyan}
: ${ZSH_HIGHLIGHT_STYLES[back-un-quoted-argument]:=fg=cyan}
: ${ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]:=fg=cyan,underline}
: ${ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]:=fg=cyan}
: ${ZSH_HIGHLIGHT_STYLES[assign]:=none}
: ${ZSH_HIGHLIGHT_STYLES[redirection]:=fg=yellow}
Expand Down Expand Up @@ -1202,7 +1203,13 @@ _zsh_highlight_main_highlighter_highlight_argument()

for (( ; i <= $#arg ; i += 1 )); do
case "$arg[$i]" in
"\\") (( i += 1 )); continue;;
"\\")
highlights+=(
$(( start_pos + i - 1 )) $((start_pos + i + 1)) back-double-quoted-argument
)
(( i += 1 ))
continue
;;
"'")
_zsh_highlight_main_highlighter_highlight_single_quote $i
(( i = REPLY ))
Expand Down
1 change: 1 addition & 0 deletions highlighters/main/test-data/backslash-continuation2.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ expected_region_highlight=(
'1 4 builtin' # echo
'6 18 default "issue #705"' # foo\\\nbar"baz"
'14 18 double-quoted-argument "issue #705"' # "baz"
# TODO: when fixing this, see if we can highlight the backslash-newline sequence as a comment.
)

0 comments on commit ad8358c

Please sign in to comment.