source: node_modules/refractor/lang/perl.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 4.8 KB
RevLine 
[d24f17c]1'use strict'
2
3module.exports = perl
4perl.displayName = 'perl'
5perl.aliases = []
6function perl(Prism) {
7 ;(function (Prism) {
8 var brackets =
9 /(?:\((?:[^()\\]|\\[\s\S])*\)|\{(?:[^{}\\]|\\[\s\S])*\}|\[(?:[^[\]\\]|\\[\s\S])*\]|<(?:[^<>\\]|\\[\s\S])*>)/
10 .source
11 Prism.languages.perl = {
12 comment: [
13 {
14 // POD
15 pattern: /(^\s*)=\w[\s\S]*?=cut.*/m,
16 lookbehind: true,
17 greedy: true
18 },
19 {
20 pattern: /(^|[^\\$])#.*/,
21 lookbehind: true,
22 greedy: true
23 }
24 ],
25 // TODO Could be nice to handle Heredoc too.
26 string: [
27 {
28 pattern: RegExp(
29 /\b(?:q|qq|qw|qx)(?![a-zA-Z0-9])\s*/.source +
30 '(?:' +
31 [
32 // q/.../
33 /([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source, // q a...a
34 // eslint-disable-next-line regexp/strict
35 /([a-zA-Z0-9])(?:(?!\2)[^\\]|\\[\s\S])*\2/.source, // q(...)
36 // q{...}
37 // q[...]
38 // q<...>
39 brackets
40 ].join('|') +
41 ')'
42 ),
43 greedy: true
44 }, // "...", `...`
45 {
46 pattern: /("|`)(?:(?!\1)[^\\]|\\[\s\S])*\1/,
47 greedy: true
48 }, // '...'
49 // FIXME Multi-line single-quoted strings are not supported as they would break variables containing '
50 {
51 pattern: /'(?:[^'\\\r\n]|\\.)*'/,
52 greedy: true
53 }
54 ],
55 regex: [
56 {
57 pattern: RegExp(
58 /\b(?:m|qr)(?![a-zA-Z0-9])\s*/.source +
59 '(?:' +
60 [
61 // m/.../
62 /([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source, // m a...a
63 // eslint-disable-next-line regexp/strict
64 /([a-zA-Z0-9])(?:(?!\2)[^\\]|\\[\s\S])*\2/.source, // m(...)
65 // m{...}
66 // m[...]
67 // m<...>
68 brackets
69 ].join('|') +
70 ')' +
71 /[msixpodualngc]*/.source
72 ),
73 greedy: true
74 }, // The lookbehinds prevent -s from breaking
75 {
76 pattern: RegExp(
77 /(^|[^-])\b(?:s|tr|y)(?![a-zA-Z0-9])\s*/.source +
78 '(?:' +
79 [
80 // s/.../.../
81 // eslint-disable-next-line regexp/strict
82 /([^a-zA-Z0-9\s{(\[<])(?:(?!\2)[^\\]|\\[\s\S])*\2(?:(?!\2)[^\\]|\\[\s\S])*\2/
83 .source, // s a...a...a
84 // eslint-disable-next-line regexp/strict
85 /([a-zA-Z0-9])(?:(?!\3)[^\\]|\\[\s\S])*\3(?:(?!\3)[^\\]|\\[\s\S])*\3/
86 .source, // s(...)(...)
87 // s{...}{...}
88 // s[...][...]
89 // s<...><...>
90 // s(...)[...]
91 brackets + /\s*/.source + brackets
92 ].join('|') +
93 ')' +
94 /[msixpodualngcer]*/.source
95 ),
96 lookbehind: true,
97 greedy: true
98 }, // /.../
99 // The look-ahead tries to prevent two divisions on
100 // the same line from being highlighted as regex.
101 // This does not support multi-line regex.
102 {
103 pattern:
104 /\/(?:[^\/\\\r\n]|\\.)*\/[msixpodualngc]*(?=\s*(?:$|[\r\n,.;})&|\-+*~<>!?^]|(?:and|cmp|eq|ge|gt|le|lt|ne|not|or|x|xor)\b))/,
105 greedy: true
106 }
107 ],
108 // FIXME Not sure about the handling of ::, ', and #
109 variable: [
110 // ${^POSTMATCH}
111 /[&*$@%]\{\^[A-Z]+\}/, // $^V
112 /[&*$@%]\^[A-Z_]/, // ${...}
113 /[&*$@%]#?(?=\{)/, // $foo
114 /[&*$@%]#?(?:(?:::)*'?(?!\d)[\w$]+(?![\w$]))+(?:::)*/, // $1
115 /[&*$@%]\d+/, // $_, @_, %!
116 // The negative lookahead prevents from breaking the %= operator
117 /(?!%=)[$@%][!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/
118 ],
119 filehandle: {
120 // <>, <FOO>, _
121 pattern: /<(?![<=])\S*?>|\b_\b/,
122 alias: 'symbol'
123 },
124 'v-string': {
125 // v1.2, 1.2.3
126 pattern: /v\d+(?:\.\d+)*|\d+(?:\.\d+){2,}/,
127 alias: 'string'
128 },
129 function: {
130 pattern: /(\bsub[ \t]+)\w+/,
131 lookbehind: true
132 },
133 keyword:
134 /\b(?:any|break|continue|default|delete|die|do|else|elsif|eval|for|foreach|given|goto|if|last|local|my|next|our|package|print|redo|require|return|say|state|sub|switch|undef|unless|until|use|when|while)\b/,
135 number:
136 /\b(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0b[01](?:_?[01])*|(?:(?:\d(?:_?\d)*)?\.)?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)\b/,
137 operator:
138 /-[rwxoRWXOezsfdlpSbctugkTBMAC]\b|\+[+=]?|-[-=>]?|\*\*?=?|\/\/?=?|=[=~>]?|~[~=]?|\|\|?=?|&&?=?|<(?:=>?|<=?)?|>>?=?|![~=]?|[%^]=?|\.(?:=|\.\.?)?|[\\?]|\bx(?:=|\b)|\b(?:and|cmp|eq|ge|gt|le|lt|ne|not|or|xor)\b/,
139 punctuation: /[{}[\];(),:]/
140 }
141 })(Prism)
142}
Note: See TracBrowser for help on using the repository browser.