1 | (function (Prism) {
|
2 |
|
3 | var specialEscape = {
|
4 | pattern: /\\[\\(){}[\]^$+*?|.]/,
|
5 | alias: 'escape'
|
6 | };
|
7 | var escape = /\\(?:x[\da-fA-F]{2}|u[\da-fA-F]{4}|u\{[\da-fA-F]+\}|c[a-zA-Z]|0[0-7]{0,2}|[123][0-7]{2}|.)/;
|
8 | var charClass = {
|
9 | pattern: /\.|\\[wsd]|\\p{[^{}]+}/i,
|
10 | alias: 'class-name'
|
11 | };
|
12 | var charClassWithoutDot = {
|
13 | pattern: /\\[wsd]|\\p{[^{}]+}/i,
|
14 | alias: 'class-name'
|
15 | };
|
16 |
|
17 | var rangeChar = '(?:[^\\\\-]|' + escape.source + ')';
|
18 | var range = RegExp(rangeChar + '-' + rangeChar);
|
19 |
|
20 |
|
21 | var groupName = {
|
22 | pattern: /(<|')[^<>']+(?=[>']$)/,
|
23 | lookbehind: true,
|
24 | alias: 'variable'
|
25 | };
|
26 |
|
27 | Prism.languages.regex = {
|
28 | 'charset': {
|
29 | pattern: /((?:^|[^\\])(?:\\\\)*)\[(?:[^\\\]]|\\[\s\S])*\]/,
|
30 | lookbehind: true,
|
31 | inside: {
|
32 | 'charset-negation': {
|
33 | pattern: /(^\[)\^/,
|
34 | lookbehind: true,
|
35 | alias: 'operator'
|
36 | },
|
37 | 'charset-punctuation': {
|
38 | pattern: /^\[|\]$/,
|
39 | alias: 'punctuation'
|
40 | },
|
41 | 'range': {
|
42 | pattern: range,
|
43 | inside: {
|
44 | 'escape': escape,
|
45 | 'range-punctuation': {
|
46 | pattern: /-/,
|
47 | alias: 'operator'
|
48 | }
|
49 | }
|
50 | },
|
51 | 'special-escape': specialEscape,
|
52 | 'charclass': charClassWithoutDot,
|
53 | 'escape': escape
|
54 | }
|
55 | },
|
56 | 'special-escape': specialEscape,
|
57 | 'charclass': charClass,
|
58 | 'backreference': [
|
59 | {
|
60 |
|
61 | pattern: /\\(?![123][0-7]{2})[1-9]/,
|
62 | alias: 'keyword'
|
63 | },
|
64 | {
|
65 | pattern: /\\k<[^<>']+>/,
|
66 | alias: 'keyword',
|
67 | inside: {
|
68 | 'group-name': groupName
|
69 | }
|
70 | }
|
71 | ],
|
72 | 'anchor': {
|
73 | pattern: /[$^]|\\[ABbGZz]/,
|
74 | alias: 'function'
|
75 | },
|
76 | 'escape': escape,
|
77 | 'group': [
|
78 | {
|
79 |
|
80 |
|
81 |
|
82 |
|
83 | pattern: /\((?:\?(?:<[^<>']+>|'[^<>']+'|[>:]|<?[=!]|[idmnsuxU]+(?:-[idmnsuxU]+)?:?))?/,
|
84 | alias: 'punctuation',
|
85 | inside: {
|
86 | 'group-name': groupName
|
87 | }
|
88 | },
|
89 | {
|
90 | pattern: /\)/,
|
91 | alias: 'punctuation'
|
92 | }
|
93 | ],
|
94 | 'quantifier': {
|
95 | pattern: /(?:[+*?]|\{(?:\d+,?\d*)\})[?+]?/,
|
96 | alias: 'number'
|
97 | },
|
98 | 'alternation': {
|
99 | pattern: /\|/,
|
100 | alias: 'keyword'
|
101 | }
|
102 | };
|
103 |
|
104 | }(Prism))
|