Is there a specification in the form of a perl regular expression that will match all perl regular expression literals?
Failing that, is there a specification in any language for all perl regular expression literals?
Ideally, it should include regular expression modifiers like /x and regular expression operators like s/, but I could tack those on later.
Specifications that match after variable interpolation are ideal, but before is fine too.
Context: I am writing in perl (Actually, using Parse::RecDescent) a metalanguage that compiles into perl, and want to identify regular expression literals and pass them on to perl.
Those operators can contain arbitrary Perl code, and there’s no specification for that.
For example, in
and
EXPRcan be almost any valid Perl expression.However, I don’t think you actually need to know how to parse it. You just need to know where it ends. And that’s rather easy. Perl also needs to be able to do that before it can parse the operator, so it disallows certain code patterns. (Thus the “almost” above.)
Any occurrences of the delimiter must be preceded by an odd number of “
\“.As an exception to the above, when the delimiter is
(),[]or{}, the delimiters may appear unescaped as long as they are balanced.Notes:
'» as a delimiter.\» as a delimiter, but I don’t think you should support that.