|
1 | 1 | (function (Prism) {
|
2 |
| - // Functions to construct regular expressions |
3 |
| - // simple form |
4 |
| - // e.g. (interactive ... or (interactive) |
| 2 | + /** |
| 3 | + * Functions to construct regular expressions |
| 4 | + * e.g. (interactive ... or (interactive) |
| 5 | + * |
| 6 | + * @param {string} name |
| 7 | + * @returns {RegExp} |
| 8 | + */ |
5 | 9 | function simple_form(name) {
|
6 |
| - return RegExp('(\\()' + name + '(?=[\\s\\)])'); |
| 10 | + return RegExp(/(\()/.source + '(?:' + name + ')' + /(?=[\s\)])/.source); |
7 | 11 | }
|
8 |
| - // booleans and numbers |
| 12 | + /** |
| 13 | + * booleans and numbers |
| 14 | + * |
| 15 | + * @param {string} pattern |
| 16 | + * @returns {RegExp} |
| 17 | + */ |
9 | 18 | function primitive(pattern) {
|
10 |
| - return RegExp('([\\s([])' + pattern + '(?=[\\s)])'); |
| 19 | + return RegExp(/([\s([])/.source + '(?:' + pattern + ')' + /(?=[\s)])/.source); |
11 | 20 | }
|
12 | 21 |
|
13 | 22 | // Patterns in regular expressions
|
14 | 23 |
|
15 | 24 | // Symbol name. See https://www.gnu.org/software/emacs/manual/html_node/elisp/Symbol-Type.html
|
16 | 25 | // & and : are excluded as they are usually used for special purposes
|
17 |
| - var symbol = '[-+*/~!@$%^=<>{}\\w]+'; |
| 26 | + var symbol = /(?!\d)[-+*/~!@$%^=<>{}\w]+/.source; |
18 | 27 | // symbol starting with & used in function arguments
|
19 | 28 | var marker = '&' + symbol;
|
20 | 29 | // Open parenthesis for look-behind
|
21 | 30 | var par = '(\\()';
|
22 | 31 | var endpar = '(?=\\))';
|
23 | 32 | // End the pattern with look-ahead space
|
24 | 33 | var space = '(?=\\s)';
|
| 34 | + var nestedPar = /(?:[^()]|\((?:[^()]|\((?:[^()]|\((?:[^()]|\((?:[^()]|\([^()]*\))*\))*\))*\))*\))*/.source; |
25 | 35 |
|
26 | 36 | var language = {
|
27 | 37 | // Three or four semicolons are considered a heading.
|
|
68 | 78 | },
|
69 | 79 | ],
|
70 | 80 | declare: {
|
71 |
| - pattern: simple_form('declare'), |
| 81 | + pattern: simple_form(/declare/.source), |
72 | 82 | lookbehind: true,
|
73 | 83 | alias: 'keyword'
|
74 | 84 | },
|
75 | 85 | interactive: {
|
76 |
| - pattern: simple_form('interactive'), |
| 86 | + pattern: simple_form(/interactive/.source), |
77 | 87 | lookbehind: true,
|
78 | 88 | alias: 'keyword'
|
79 | 89 | },
|
80 | 90 | boolean: {
|
81 |
| - pattern: primitive('(?:t|nil)'), |
| 91 | + pattern: primitive(/nil|t/.source), |
82 | 92 | lookbehind: true
|
83 | 93 | },
|
84 | 94 | number: {
|
85 |
| - pattern: primitive('[-+]?\\d+(?:\\.\\d*)?'), |
| 95 | + pattern: primitive(/[-+]?\d+(?:\.\d*)?/.source), |
86 | 96 | lookbehind: true
|
87 | 97 | },
|
88 | 98 | defvar: {
|
|
94 | 104 | }
|
95 | 105 | },
|
96 | 106 | defun: {
|
97 |
| - pattern: RegExp( |
98 |
| - par + |
99 |
| - '(?:cl-)?(?:defmacro|defun\\*?)\\s+' + |
100 |
| - symbol + |
101 |
| - '\\s+\\([\\s\\S]*?\\)' |
102 |
| - ), |
| 107 | + pattern: RegExp(par + /(?:cl-)?(?:defmacro|defun\*?)\s+/.source + symbol + /\s+\(/.source + nestedPar + /\)/.source), |
103 | 108 | lookbehind: true,
|
| 109 | + greedy: true, |
104 | 110 | inside: {
|
105 | 111 | keyword: /^(?:cl-)?def\S+/,
|
106 | 112 | // See below, this property needs to be defined later so that it can
|
|
116 | 122 | lambda: {
|
117 | 123 | pattern: RegExp(par + 'lambda\\s+\\(\\s*(?:&?' + symbol + '(?:\\s+&?' + symbol + ')*\\s*)?\\)'),
|
118 | 124 | lookbehind: true,
|
| 125 | + greedy: true, |
119 | 126 | inside: {
|
120 | 127 | keyword: /^lambda/,
|
121 | 128 | // See below, this property needs to be defined later so that it can
|
|
141 | 148 |
|
142 | 149 | var arg = {
|
143 | 150 | 'lisp-marker': RegExp(marker),
|
144 |
| - rest: { |
145 |
| - argument: { |
146 |
| - pattern: RegExp(symbol), |
147 |
| - alias: 'variable' |
148 |
| - }, |
149 |
| - varform: { |
150 |
| - pattern: RegExp(par + symbol + '\\s+\\S[\\s\\S]*' + endpar), |
151 |
| - lookbehind: true, |
152 |
| - inside: { |
153 |
| - string: language.string, |
154 |
| - boolean: language.boolean, |
155 |
| - number: language.number, |
156 |
| - symbol: language.symbol, |
157 |
| - punctuation: /[()]/ |
158 |
| - } |
159 |
| - } |
160 |
| - } |
| 151 | + 'varform': { |
| 152 | + pattern: RegExp(/\(/.source + symbol + /\s+(?=\S)/.source + nestedPar + /\)/.source), |
| 153 | + inside: language |
| 154 | + }, |
| 155 | + 'argument': { |
| 156 | + pattern: RegExp(/(^|[\s(])/.source + symbol), |
| 157 | + lookbehind: true, |
| 158 | + alias: 'variable' |
| 159 | + }, |
| 160 | + rest: language |
161 | 161 | };
|
162 | 162 |
|
163 | 163 | var forms = '\\S+(?:\\s+\\S+)*';
|
164 | 164 |
|
165 | 165 | var arglist = {
|
166 |
| - pattern: RegExp(par + '[\\s\\S]*' + endpar), |
| 166 | + pattern: RegExp(par + nestedPar + endpar), |
167 | 167 | lookbehind: true,
|
168 | 168 | inside: {
|
169 | 169 | 'rest-vars': {
|
|
0 commit comments