-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(Perl) No support for m
style regex with arbitrary delimiters
#2952
Comments
|
This is valid Perl code.
//EDIT: |
Ok. But in a case like m#...# how would one escape a literal # inside the regex? Or is that not possible? In a normal regex evidently a backslash escape may be used (assuming our grammar is correct):
So how do I write:
Where the inside # is part of the regex? |
m
style regex with arbitrary delimiters
Ok, in this case i guess |
That would be simple enough. Could you confirm your guess? |
Regular case is to escape the opening or closing char if part of a regex. I will come back the next days if i know more on special syntax of Perl quoting. |
I was following this right up until the end. What is the last part trying to say? I thought I was following along with "skipped" until they said "nothing is skipped" and then changed to using "removed". |
The last sentence describes a separate process, and the sentence before that is a special case: If you use |
On using
Indeed, Here's a compilation of some common and some annoying Perl delimiters. Perl's substitution s/a/b/ is challenging because it allows for an odd number of delimiters, in particular with quotes as delimiters. GitHub's highlighting seems to get almost all of them right: use 5.020;
use strict;
use warnings;
sub saeaoagr () {
print "foo";
qr/x/;
}
# Those are the most popular
say ("fee" =~ s/e/o/gr . "bar");
say ("fee" =~ s!e!o!gr . "bar");
say ("fee" =~ s|e|o|gr . "bar");
say ("fee" =~ s{e}{o}gr . "bar");
say ("fee" =~ s(e)(o)gr . "bar");
say ("fee" =~ s[e][o]gr . "bar");
# Those have syntactic significance
say ("fee" =~ s?e?o?gr . "bar");
say ("fee" =~ s'e'o'gr . "bar"); # ' # quote to fix
# Those are valid, but infrequent (and weird)
say ("fee" =~ s"e"o"gr . "bar"); # " # quote to fix
say ("fee" =~ s aeaoagr . "bar");
say ("fee" =~ s#e#o#gr . "bar");
# Those must not be confused with the previous two
say ("fee" =~ saeaoagr . "bar"); # calls saeaoagr()
say ("fee" =~ s #e#o#gr that's a comment, not a regex
(e)(o)gr . "bar"); # and here's the regex.
|
Are are all those delimiters valid for all regex "types"/operations (not sure what to call them)?
|
Yes, they are. Perl calls the whole lot "Quote and Quote-like operators". |
Describe the issue
Regex detection after keyword
m
fails if having a slash f.ex.$d .= '/' if $d !~ m(/$);
Which language seems to have the issue?
Perl
Are you using
highlight
orhighlightAuto
?initHighlightingOnLoad
Sample Code to Reproduce
https://jsfiddle.net/0t6zh59g/
Screenshot
Expected behavior
Only
/$
is hilighted as regex.Additional context
Perl's match operator allows a unescaped / , the regex parser of HLJS should detect this.
More valid regex are f.ex.
m|/$|
orm#/$#
orm{/$}
Same issue happens with
$d .= '/' if $d !~ qr(/$);
and other regexes as parameters for Regexp Quote Like OperatorsThe text was updated successfully, but these errors were encountered: