Skip to content

Perl syntax highlighting issue - s{foo}{bar} if $baz;  #49

@alexr00

Description

@alexr00

Originally from @NorthboundTrain in microsoft/vscode#131322

Issue Type: Bug

Perl's regex operators can use any pair of matching characters as delimiters (see https://perldoc.perl.org/perlop#Regexp-Quote-Like-Operators). When using a bracketing character as the delimiter, e.g. ({[, then the matching closing bracket can be used to close the operator, e.g. m<foo> or s{foo}{bar}. The bug only occurs when using the substitution operator (s///), and only when using bracketing delimiters, and only with a statement modifier (a trailing if, while, etc).

Screen Shot 2021-08-21 at 12 25 02 PM

s/foo/bar/; # OK
s/foo/bar/ unless $baz; # OK
s/foo/bar/ if $baz; # OK

s{foo}{bar}; # OK
s{foo}{bar} if $baz; # BROKEN
# lasts until a scalar variable is given; neither an @array nor a %hash works,
# but the $scalar does (but the remainder of the line is still FUBAR)
# next line is OK, though

s(foo)(bar) if $baz; # BROKEN - $clear;
s[foo][bar] if $baz; # BROKEN - $clear;
s<foo><bar> if $baz; # BROKEN - $clear;
s:foo:bar: if $baz; # OK
s#foo#bar# if $baz; # OK

# other statement modifiers
s(foo)(bar) for $baz; # BROKEN differently
s(foo)(bar) foreach $baz; # BROKEN - $clear
s(foo)(bar) unless $baz; # OK
s(foo)(bar) until $baz; # BROKEN differently
s(foo)(bar) when $baz; # BROKEN differently
s(foo)(bar) while $baz; # BROKEN differently

# other regex/quote-like operators are OK:
m/foo/ if $baz; # OK
m{foo} if $baz; # OK
q/foo/ if $baz; # OK
q{foo} if $baz; # OK
qq/foo/ if $baz; # OK
qq{foo} if $baz; # OK
qw/foo/ if $baz; # OK
qw{foo} if $baz; # OK

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions