]>
luflow.net public git repositories - flow-web.git/blob - static/highlight/languages/perl.js
1 /*! `perl` grammar compiled for Highlight.js 11.11.1 */
3 var hljsGrammar
= (function () {
8 Author: Peter Leonov <gojpeg@yandex.ru>
9 Website: https://www.perl.org
13 /** @type LanguageFn */
15 const regex
= hljs
.regex
;
252 // https://perldoc.perl.org/perlre#Modifiers
253 const REGEX_MODIFIERS
= /[dualxmsipngr]{0,12}/; // aa and xx are valid, making max length 12
254 const PERL_KEYWORDS
= {
256 keyword: KEYWORDS
.join(" ")
262 keywords: PERL_KEYWORDS
267 // contains defined later
271 match: /\s+:\s*\w+(\s*\(.*?\))?/,
277 { begin: regex
.concat(
278 /[$%@](?!")(\^\w\b|#\w+(::\w+)*|\{\w+\}|\w+(::\w*)*)/,
279 // negative look-ahead tries to avoid matching patterns that are not
280 // Perl at all like $ident$, @ident@, etc.
281 `(?![A-Za-z])(?![@$%])`
285 // Only $= is a special Perl variable and one can't declare @= or %=.
286 begin: /[$%@](?!")[^\s\w{=]|\$=/,
296 // include the case where a number starts with a dot (eg. .9), and
297 // the leading 0? avoids mixing the first and second match on 0.x cases
298 { match: /0?\.[0-9][0-9_]+\b/ },
299 // include the special versioned number (eg. v5.38)
300 { match: /\bv?(0|[1-9][0-9_]*(\.[0-9_]+)?|[1-9][0-9_]*)\b/ },
301 // non-decimal numbers:
302 { match: /\b0[0-7][0-7_]*\b/ },
303 { match: /\b0x[0-9a-fA-F][0-9a-fA-F_]*\b/ },
304 { match: /\b0b[0-1][0-1_]*\b/ },
308 const STRING_CONTAINS
= [
309 hljs
.BACKSLASH_ESCAPE
,
313 const REGEX_DELIMS
= [
319 /"/, // valid but infrequent and weird
320 /#/ // valid but infrequent and weird
323 * @param {string|RegExp} prefix
324 * @param {string|RegExp} open
325 * @param {string|RegExp} close
327 const PAIRED_DOUBLE_RE = (prefix, open, close = '\\1') => {
328 const middle = (close === '\\1')
330 : regex.concat(close, open);
332 regex.concat("(?:", prefix, ")"),
342 * @param {string|RegExp} prefix
343 * @param {string|RegExp} open
344 * @param {string|RegExp} close
346 const PAIRED_RE = (prefix, open, close) => {
348 regex.concat("(?:", prefix, ")"),
355 const PERL_DEFAULT_CONTAINS = [
357 hljs.HASH_COMMENT_MODE,
361 { endsWithParent: true }
366 contains: STRING_CONTAINS,
369 begin: 'q
[qwxr
]?\\s
*\\(',
374 begin: 'q
[qwxr
]?\\s
*\\[',
379 begin: 'q
[qwxr
]?\\s
*\\{',
384 begin: 'q
[qwxr
]?\\s
*\\|',
389 begin: 'q
[qwxr
]?\\s
*<',
401 contains: [ hljs.BACKSLASH_ESCAPE ]
410 contains: [ hljs.BACKSLASH_ESCAPE ]
417 begin: '-?\\w
+\\s
*=>',
423 { // regexp container
424 begin: '(\\/\\/|' + hljs.RE_STARTERS_RE + '|\\b(split
|return|print
|reverse
|grep
)\\b
)\\s
*',
425 keywords: 'split
return print reverse grep
',
428 hljs.HASH_COMMENT_MODE,
432 // allow matching common delimiters
433 { begin: PAIRED_DOUBLE_RE("s|tr|y", regex.either(...REGEX_DELIMS, { capture: true })) },
434 // and then paired delmis
435 { begin: PAIRED_DOUBLE_RE("s|tr|y", "\\(", "\\)") },
436 { begin: PAIRED_DOUBLE_RE("s|tr|y", "\\[", "\\]") },
437 { begin: PAIRED_DOUBLE_RE("s|tr|y", "\\{", "\\}") }
445 // could be a comment in many languages so do not count
450 // prefix is optional with /regex/
451 { begin: PAIRED_RE("(?:m|qr)?", /\//, /\//) },
452 // allow matching common delimiters
453 { begin: PAIRED_RE("m|qr", regex.either(...REGEX_DELIMS, { capture: true }), /\1/) },
454 // allow common paired delmins
455 { begin: PAIRED_RE("m|qr", /\(/, /\)/) },
456 { begin: PAIRED_RE("m|qr", /\[/, /\]/) },
457 { begin: PAIRED_RE("m|qr", /\{/, /\}/) }
463 className: 'function',
464 beginKeywords: 'sub method
',
465 end: '(\\s
*\\(.*?\\))?[;{]',
468 contains: [ hljs.TITLE_MODE, ATTR ]
472 beginKeywords: 'class',
476 contains: [ hljs.TITLE_MODE, ATTR, NUMBER ]
485 subLanguage: 'mojolicious
',
495 SUBST.contains = PERL_DEFAULT_CONTAINS;
496 METHOD.contains = PERL_DEFAULT_CONTAINS;
504 keywords: PERL_KEYWORDS,
505 contains: PERL_DEFAULT_CONTAINS
513 hljs.registerLanguage('perl
', hljsGrammar);