luochen1990 / rainbow

Rainbow Parentheses Improved, shorter code, no level limit, smooth and fast, powerful configuration.
Apache License 2.0
1.78k stars 95 forks source link

Divide parentheses into kinds so as to match languages with complex parentheses syntax #175

Closed 91khr closed 2 years ago

91khr commented 2 years ago

Inspired by and thus fixes #174

Some languages like shell (and maybe Agda) have a somehow complex syntax:

(echo hello; echo hi) | cat  # Subshells in single quote
(((1+2)+3-$((6)))); echo $?  # Arithmetic expression

Handling this is not so easy as it seems to be: outside of the arithmetic expression, only single parentheses can be matched, otherwise we can't match the parentheses for the arithmetic expressions, but inside the arithmetic expression, single parentheses should always be matched as-is since the expression can't be nested. In vim's origin design, this is solved by contained etc.; but since Rainbow generates lots of syntax rules to highlight parentheses at different levels, unfortunately vim provides no mechanism to deal with them.

This is one possible approach of solving the problem: bundle different parentheses into 'kind's like vim bundle syntax clusters, so that the parentheses can cascade correctly.

CoelacanthusHex commented 2 years ago

Bash and POSIX sh use same parenthese syntax, so these should use same setting. But I see the author disabled this plugin for ft=sh. @luochen1990 Is this caused by this syntax? If it is, please use same setting for sh and bash as well.

CoelacanthusHex commented 2 years ago

BTW, POSIX compatible shell like ash and dash (bash and zsh as well) also using same syntax, but csh/tcsh use single parenthese syntax for arithmetic operations and fish use a math built-in command, so csh/tcsh/fish shouldn't use same setting, normal setting is enough for them.

91khr commented 2 years ago

Well, there's something more than the arithmetic expressions' double quotes. Maybe the dollar sign before the substitutions should be matched as a part of the parentheses? And... Should the backtick command substitution be matched... ?