Skip to content

Commit c8f5d10

Browse files
committed
'main': Highlight backslash escape sequences outside quotes.
Fixes #631. WIP: test expectations should be updated (12 failures including cthulhu)
1 parent 6fd92e1 commit c8f5d10

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

docs/highlighters/main.md

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ This highlighter defines the following styles:
5656
* `dollar-quoted-argument-unclosed` - unclosed dollar-quoted arguments (`` $'foo ``)
5757
* `rc-quote` - two single quotes inside single quotes when the `RC_QUOTES` option is set (`` 'foo''bar' ``)
5858
* `dollar-double-quoted-argument` - parameter expansion inside double quotes (`$foo` inside `""`)
59+
* `back-un-quoted-argument` - backslash escape sequences outside quotes (`\"` in `print -r \"bar\"`)
5960
* `back-double-quoted-argument` - backslash escape sequences inside double-quoted arguments (`\"` in `"foo\"bar"`)
6061
* `back-dollar-quoted-argument` - backslash escape sequences inside dollar-quoted arguments (`\x` in `$'\x48'`)
6162
* `assign` - parameter assignments (`x=foo` and `x=( )`)

highlighters/main/main-highlighter.zsh

+8-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
: ${ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]:=fg=yellow}
5656
: ${ZSH_HIGHLIGHT_STYLES[rc-quote]:=fg=cyan}
5757
: ${ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]:=fg=cyan}
58+
: ${ZSH_HIGHLIGHT_STYLES[back-un-quoted-argument]:=fg=cyan}
5859
: ${ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]:=fg=cyan}
5960
: ${ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]:=fg=cyan}
6061
: ${ZSH_HIGHLIGHT_STYLES[assign]:=none}
@@ -1328,7 +1329,13 @@ _zsh_highlight_main_highlighter_highlight_argument()
13281329
i=${arg[(ib.i.)[\\\'\"\`\$\<\>\*\?]]}
13291330
case "$arg[$i]" in
13301331
"") break;;
1331-
"\\") (( i += 1 )); continue;;
1332+
"\\")
1333+
highlights+=(
1334+
$(( start_pos + i - 1 )) $((start_pos + i + 1)) back-un-quoted-argument
1335+
)
1336+
(( i += 1 ))
1337+
continue
1338+
;;
13321339
"'")
13331340
_zsh_highlight_main_highlighter_highlight_single_quote $i
13341341
(( i = REPLY ))

highlighters/main/test-data/backslash-continuation2.zsh

+1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ expected_region_highlight=(
3434
'1 4 builtin' # echo
3535
'6 18 default "issue #705"' # foo\\\nbar"baz"
3636
'14 18 double-quoted-argument "issue #705"' # "baz"
37+
# TODO: when fixing this, see if we can highlight the backslash-newline sequence as a comment.
3738
)

0 commit comments

Comments
 (0)