I discovered a bug that, when there are multiple percentages, the highlighting of variable names would be problematic:
%var%3
- expected:
%var%
3 (only %var%
be highlighted)
- actual:
%var%3
%%i do echo %b%
- expected:
%%i
do echo %b%
- actual:
%%i do echo %
b%
The reason is that the %<name>%
rule in line 21 doesn't care about word-boundaries. Therefore, it would highlight %var%3
despite that %3
had already been highlighted by another rule. It's the same for the second test case.
|
color brightred "%([[:alpha:]`~@#$*(){}:',.?+=_-]|\[|\])([[:alnum:]`~@#$*(){}:',.?\ +=_-]|\[|\])*%" |
|
color brightred "!([[:alnum:]`~@#$%*(){}:',.?+=_-]|\[|\])([[:alnum:]`~@#$%*(){}:',.?\ +=_-]|\[|\])*!" |
|
|
|
# Parameter names for arguments and loop. |
|
color brightred "%(~[[:alpha:]$]*)?[0-9*]\>" "%%(~[[:alpha:]$]*)?[[:alpha:]]\>" |
As for the solution, the ideal solution is by using lookahead or lookafter regex syntax to rule out special cases for %<name>%
rule. However, Posix Extended Regex doesn't support this feature. So, I have set a limit that no spaces can be within variable names to avoid this problem.