(function (Prism) {
var brackets =
/(?:\((?:[^()\\]|\\[\s\S])*\)|\{(?:[^{}\\]|\\[\s\S])*\}|\[(?:[^[\]\\]|\\[\s\S])*\]|<(?:[^<>\\]|\\[\s\S])*>)/
.source;
Prism.languages.perl = {
comment: [
{
// POD
pattern: /(^\s*)=\w[\s\S]*?=cut.*/m,
lookbehind: true,
greedy: true,
},
{
pattern: /(^|[^\\$])#.*/,
lookbehind: true,
greedy: true,
},
],
// TODO Could be nice to handle Heredoc too.
string: [
{
pattern: RegExp(
/\b(?:q|qq|qw|qx)(?![a-zA-Z0-9])\s*/.source +
'(?:' +
[
// q/.../
/([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source,
// q a...a
// eslint-disable-next-line regexp/strict
/([a-zA-Z0-9])(?:(?!\2)[^\\]|\\[\s\S])*\2/.source,
// q(...)
// q{...}
// q[...]
// q<...>
brackets,
].join('|') +
')'
),
greedy: true,
},
// "...", `...`
{
pattern: /("|`)(?:(?!\1)[^\\]|\\[\s\S])*\1/,
greedy: true,
},
// '...'
// FIXME Multi-line single-quoted strings are not supported as they would break variables containing '
{
pattern: /'(?:[^'\\\r\n]|\\.)*'/,
greedy: true,
},
],
regex: [
{
pattern: RegExp(
/\b(?:m|qr)(?![a-zA-Z0-9])\s*/.source +
'(?:' +
[
// m/.../
/([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source,
// m a...a
// eslint-disable-next-line regexp/strict
/([a-zA-Z0-9])(?:(?!\2)[^\\]|\\[\s\S])*\2/.source,
// m(...)
// m{...}
// m[...]
// m<...>
brackets,
].join('|') +
')' +
/[msixpodualngc]*/.source
),
greedy: true,
},
// The lookbehinds prevent -s from breaking
{
pattern: RegExp(
/(^|[^-])\b(?:s|tr|y)(?![a-zA-Z0-9])\s*/.source +
'(?:' +
[
// s/.../.../
// eslint-disable-next-line regexp/strict
/([^a-zA-Z0-9\s{(\[<])(?:(?!\2)[^\\]|\\[\s\S])*\2(?:(?!\2)[^\\]|\\[\s\S])*\2/
.source,