Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: lexing

29.11.2015, 18:26, "Ray Andrews" <rayandrews@xxxxxxxxxxx>:
> Gentlemen:
> The syntax highlighting in my editors makes the predictable mistake when
> it bumps into these:
> (#b)
> (#c1,2)
> (#a3)
> because the lexing mostly follows bash rules. The people who write the
> highlighter are interested in fixing that for zsh, but they want a
> rigorous description of the rule. As far as I know the only rule there
> is that if the hash is preceded by an open parenthesis then it is not a
> comment. Is that sufficient or are there further subtleties?

With `setopt extendedglob` `echo ech#test` errors with `zsh: no match`: AFAIR this is something like `*` in PCRE (and `##` is `+` in PCRE). With `unsetopt extendedglob` `echo ech#test` echoes `ech#test`, `interactivecomments` option is set in both cases. So the rule I think would be that `#` starts a comment if it is preceded by a whitespace.


1. ${(kv#)var}
2. ${#var}: usual thing, also in POSIX shells
3. $#var
4. ${(s. # .)var}
5. $(( #var )) (usually causes Vim highlighting to fail) (also $[ #var ])
6. ${var// # /test}
7. ${var//# /test} (hash means different thing here)
8. ${var%#}, ${var:-#}, etc (POSIX)
9. '#', "#", \# (POSIX, ways of escaping hash)

Note that `posh -c 'echo foo#bar'` (also bash, dash, busybox and ksh) echoes `foo#bar`. So without `setopt extendedglob` this is not zsh-specific. So if they show a “predictable mistake” in this case as well then they are false regardless of the shell they write highlighting for.

Messages sorted by: Reverse Date, Date, Thread, Author