Highlighting of split
Closed this issue · 2 comments
The highligting of certain split statements with regular expressions is not correct.
my $string = 'aa, bb,cc, dd , ee';
my $result = [ split /\s*[,\s]\s*/, $string ];
say join ', ',$result->@*;
perl-navigator 0.5.1 2023-01-16
vscodium 1.85.1
perl v5.38.0
added this ticket just for reference once you decide to override default syntax highlighting
Thanks @maros! I think this is the most important Perl syntax highlighting issue in Perl textmate grammars. I'll elaborate:
There are a fixed set of words and characters that will start a regex if followed by a slash. Some examples (using github highlighting since it uses the same grammars):
print "good" if /foo/;
print "good" unless /foo/;
print "good" if( /foo/ && /bar/ || /baz/ );
my $result = [ split /foo/, $string ]; # Broken highlighting
This is because of one TextMate line that specifies that /
regexes start after (|{~$
, newline, and if/unless. That line is shown here:
https://github.com/textmate/perl.tmbundle/blob/a85927a902d6e5d7805f56a653f324d34dfad53a/Syntaxes/Perl.plist#L1174
That single line of TextMate generates lots of issues. Examples:
Regexes start after &&
but not after and
: textmate/perl.tmbundle#32
Regexes don't start after split
: textmate/perl.tmbundle#27 textmate/perl.tmbundle#28, textmate/perl.tmbundle#45,
Regexes don't start after grep
: textmate/perl.tmbundle#21
Regexes don't start after =
: textmate/perl.tmbundle#52, textmate/perl.tmbundle#44
Regexes incorrectly trigger on //= on newlines: textmate/perl.tmbundle#29
Regexes don't start after !
: richterger/Perl-LanguageServer#192
I think a great start for improving syntax highlighting would be overriding the default highlighting and fixing just this one line. TextMate grammars will never be perfect, but this would be a great start.
Hi @maros, this is now resolved.
In addition to highlighting regexes correctly after split
, it should also be fixed for all the other outstanding issues I mentioned above as well.
Additionally, I made a variety of other fixes while I was in there. For example, although %hash
is a valid perl variable, hashes don't interpolate in strings or regex, unless a value is accessed. Other bug fixes as well shown below: