zsh-syntax-highlighting
zsh-syntax-highlighting copied to clipboard
Arithmetic Evaluation context has no comments
This is a mirror issue of the sublimehq/Packages#2635.
Summary
Arithmetic Evaluation context is not subject to comments.
Description
Syntax highlighting engine treats # symbol inside an Arithmetic Evaluation context as the beginning of a comment. Which is incorrect, because # in that context could be one of several operators but not a comment.
According to zsh documentation at http://zsh.sourceforge.net/Doc/Release/Arithmetic-Evaluation.html#Arithmetic-Evaluation:
An expression of the form ‘##x’ where x is any character sequence such as ‘a’, ‘^A’, or ‘\M-\C-x’ gives the value of this character and an expression of the form ‘#name’ gives the value of the first character of the contents of the parameter name.
Steps to reproduce
Neither of the expressions below contain a single comment, regardless of the interactive_comments zsh option.
: $(( # word ))
: $(( #word ))
Expected result
The # operator should be highlighted as an operator, and word is its argument. Although, $(( # word )) is not valid expression either: there should be no space after #, so zsh would just bail out with an error:
: $(( # word ))
zsh: bad math expression: operator expected at `word '`
Observed result
The # symbol and everything after it gets highlighted as a comment.

Additional information
- OS: Arch Linux
- zsh-syntax-highlighting: 0.7.1-1
- zsh: 5.8-1
Related issues: #607 #649 #704 #714
Current master recognizes arithmetic expansions and does not treat # (or in general $histchars[3]) as introducing a comment. It could, however, be expanded to recognize when # is invalid.
(Please retitle/label as needed, thanks :))
I'm not sure I follow the discussion...
@ratijas tl;dr Already fixed in master; possible further enhancement: highlight the arithmetic expansion syntax error as such. (Someone please cross-reference the issue about unknown-token being overloaded, thanks!)