UNPKG

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