]>
luflow.net public git repositories - flow-web.git/blob - static/highlight/es/languages/perl.js
1 /*! `perl` grammar compiled for Highlight.js 11.11.1 */
2 var hljsGrammar
= (function () {
7 Author: Peter Leonov <gojpeg@yandex.ru>
8 Website: https://www.perl.org
12 /** @type LanguageFn */
14 const regex
= hljs
.regex
;
251 // https://perldoc.perl.org/perlre#Modifiers
252 const REGEX_MODIFIERS
= /[dualxmsipngr]{0,12}/; // aa and xx are valid, making max length 12
253 const PERL_KEYWORDS
= {
255 keyword: KEYWORDS
.join(" ")
261 keywords: PERL_KEYWORDS
266 // contains defined later
270 match: /\s+:\s*\w+(\s*\(.*?\))?/,
276 { begin: regex
.concat(
277 /[$%@](?!")(\^\w\b|#\w+(::\w+)*|\{\w+\}|\w+(::\w*)*)/,
278 // negative look-ahead tries to avoid matching patterns that are not
279 // Perl at all like $ident$, @ident@, etc.
280 `(?![A-Za-z])(?![@$%])`
284 // Only $= is a special Perl variable and one can't declare @= or %=.
285 begin: /[$%@](?!")[^\s\w{=]|\$=/,
295 // include the case where a number starts with a dot (eg. .9), and
296 // the leading 0? avoids mixing the first and second match on 0.x cases
297 { match: /0?\.[0-9][0-9_]+\b/ },
298 // include the special versioned number (eg. v5.38)
299 { match: /\bv?(0|[1-9][0-9_]*(\.[0-9_]+)?|[1-9][0-9_]*)\b/ },
300 // non-decimal numbers:
301 { match: /\b0[0-7][0-7_]*\b/ },
302 { match: /\b0x[0-9a-fA-F][0-9a-fA-F_]*\b/ },
303 { match: /\b0b[0-1][0-1_]*\b/ },
307 const STRING_CONTAINS
= [
308 hljs
.BACKSLASH_ESCAPE
,
312 const REGEX_DELIMS
= [
318 /"/, // valid but infrequent and weird
319 /#/ // valid but infrequent and weird
322 * @param {string|RegExp} prefix
323 * @param {string|RegExp} open
324 * @param {string|RegExp} close
326 const PAIRED_DOUBLE_RE = (prefix, open, close = '\\1') => {
327 const middle = (close === '\\1')
329 : regex.concat(close, open);
331 regex.concat("(?:", prefix, ")"),
341 * @param {string|RegExp} prefix
342 * @param {string|RegExp} open
343 * @param {string|RegExp} close
345 const PAIRED_RE = (prefix, open, close) => {
347 regex.concat("(?:", prefix, ")"),
354 const PERL_DEFAULT_CONTAINS = [
356 hljs.HASH_COMMENT_MODE,
360 { endsWithParent: true }
365 contains: STRING_CONTAINS,
368 begin: 'q
[qwxr
]?\\s
*\\(',
373 begin: 'q
[qwxr
]?\\s
*\\[',
378 begin: 'q
[qwxr
]?\\s
*\\{',
383 begin: 'q
[qwxr
]?\\s
*\\|',
388 begin: 'q
[qwxr
]?\\s
*<',
400 contains: [ hljs.BACKSLASH_ESCAPE ]
409 contains: [ hljs.BACKSLASH_ESCAPE ]
416 begin: '-?\\w
+\\s
*=>',
422 { // regexp container
423 begin: '(\\/\\/|' + hljs.RE_STARTERS_RE + '|\\b(split
|return|print
|reverse
|grep
)\\b
)\\s
*',
424 keywords: 'split
return print reverse grep
',
427 hljs.HASH_COMMENT_MODE,
431 // allow matching common delimiters
432 { begin: PAIRED_DOUBLE_RE("s|tr|y", regex.either(...REGEX_DELIMS, { capture: true })) },
433 // and then paired delmis
434 { begin: PAIRED_DOUBLE_RE("s|tr|y", "\\(", "\\)") },
435 { begin: PAIRED_DOUBLE_RE("s|tr|y", "\\[", "\\]") },
436 { begin: PAIRED_DOUBLE_RE("s|tr|y", "\\{", "\\}") }
444 // could be a comment in many languages so do not count
449 // prefix is optional with /regex/
450 { begin: PAIRED_RE("(?:m|qr)?", /\//, /\//) },
451 // allow matching common delimiters
452 { begin: PAIRED_RE("m|qr", regex.either(...REGEX_DELIMS, { capture: true }), /\1/) },
453 // allow common paired delmins
454 { begin: PAIRED_RE("m|qr", /\(/, /\)/) },
455 { begin: PAIRED_RE("m|qr", /\[/, /\]/) },
456 { begin: PAIRED_RE("m|qr", /\{/, /\}/) }
462 className: 'function',
463 beginKeywords: 'sub method
',
464 end: '(\\s
*\\(.*?\\))?[;{]',
467 contains: [ hljs.TITLE_MODE, ATTR ]
471 beginKeywords: 'class',
475 contains: [ hljs.TITLE_MODE, ATTR, NUMBER ]
484 subLanguage: 'mojolicious
',
494 SUBST.contains = PERL_DEFAULT_CONTAINS;
495 METHOD.contains = PERL_DEFAULT_CONTAINS;
503 keywords: PERL_KEYWORDS,
504 contains: PERL_DEFAULT_CONTAINS
512 export default hljsGrammar;