zsh-syntax-highlighting icon indicating copy to clipboard operation
zsh-syntax-highlighting copied to clipboard

Arithmetic Evaluation context has no comments

Open ratijas opened this issue 4 years ago • 5 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.

Screenshot_20201124_025951

Additional information

  • OS: Arch Linux
  • zsh-syntax-highlighting: 0.7.1-1
  • zsh: 5.8-1

ratijas avatar Nov 24 '20 00:11 ratijas

Related issues: #607 #649 #704 #714

ratijas avatar Nov 24 '20 00:11 ratijas

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.

phy1729 avatar Nov 24 '20 04:11 phy1729

(Please retitle/label as needed, thanks :))

danielshahaf avatar Nov 25 '20 01:11 danielshahaf

I'm not sure I follow the discussion...

ratijas avatar Nov 25 '20 01:11 ratijas

@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!)

danielshahaf avatar Nov 25 '20 10:11 danielshahaf