|
48 | 48 | lookbehind: true,
|
49 | 49 | alias: 'class-name'
|
50 | 50 | },
|
| 51 | + 'function-definition': { |
| 52 | + pattern: /(\bfunction\s+)[a-z_]\w*(?=\s*\()/i, |
| 53 | + lookbehind: true, |
| 54 | + alias: 'function' |
| 55 | + }, |
51 | 56 | 'keyword': [
|
52 | 57 | {
|
53 | 58 | pattern: /(\(\s*)\b(?:bool|boolean|int|integer|float|string|object|array)\b(?=\s*\))/i,
|
|
95 | 100 | alias: 'static-context',
|
96 | 101 | greedy: true
|
97 | 102 | },
|
98 |
| - /\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|enum|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|match|new|or|parent|print|private|protected|public|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i |
| 103 | + { |
| 104 | + // yield from |
| 105 | + pattern: /(\byield\s+)from\b/i, |
| 106 | + lookbehind: true |
| 107 | + }, |
| 108 | + // `class` is always a keyword unlike other keywords |
| 109 | + /\bclass\b/i, |
| 110 | + { |
| 111 | + // https://www.php.net/manual/en/reserved.keywords.php |
| 112 | + // |
| 113 | + // keywords cannot be preceded by "->" |
| 114 | + // the complex lookbehind means `(?<!(?:->|::)\s*)` |
| 115 | + pattern: /((?:^|[^\s>:]|(?:^|[^-])>|(?:^|[^:]):)\s*)\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|enum|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|match|new|or|parent|print|private|protected|public|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i, |
| 116 | + lookbehind: true |
| 117 | + } |
99 | 118 | ],
|
100 | 119 | 'argument-name': {
|
101 | 120 | pattern: /([(,]\s+)\b[a-z_]\w*(?=\s*:(?!:))/i,
|
|
200 | 219 | }
|
201 | 220 | ],
|
202 | 221 | 'constant': constant,
|
203 |
| - 'function': /\w+\s*(?=\()/, |
| 222 | + 'function': /\b\w+(?=\s*\()/, |
204 | 223 | 'property': {
|
205 |
| - pattern: /(->)[\w]+/, |
| 224 | + pattern: /(->\s*)\w+/, |
206 | 225 | lookbehind: true
|
207 | 226 | },
|
208 | 227 | 'number': number,
|
|
243 | 262 | 'punctuation': /^<<<"?|[";]$/
|
244 | 263 | }
|
245 | 264 | },
|
246 |
| - 'interpolation': string_interpolation // See below |
| 265 | + 'interpolation': string_interpolation |
247 | 266 | }
|
248 | 267 | },
|
249 | 268 | {
|
|
261 | 280 | alias: 'double-quoted-string',
|
262 | 281 | greedy: true,
|
263 | 282 | inside: {
|
264 |
| - 'interpolation': string_interpolation // See below |
| 283 | + 'interpolation': string_interpolation |
265 | 284 | }
|
266 | 285 | }
|
267 | 286 | ];
|
268 | 287 |
|
269 | 288 | Prism.languages.insertBefore('php', 'variable', {
|
270 | 289 | 'string': string,
|
271 |
| - }); |
272 |
| - |
273 |
| - Prism.languages.insertBefore('php', 'variable', { |
274 | 290 | 'attribute': {
|
275 | 291 | pattern: /#\[(?:[^"'\/#]|\/(?![*/])|\/\/.*$|#(?!\[).*$|\/\*(?:[^*]|\*(?!\/))*\*\/|"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*')+\](?=\s*[a-z$#])/mi,
|
276 | 292 | greedy: true,
|
|
316 | 332 | },
|
317 | 333 | });
|
318 | 334 |
|
319 |
| - Prism.hooks.add('before-tokenize', function(env) { |
| 335 | + Prism.hooks.add('before-tokenize', function (env) { |
320 | 336 | if (!/<\?/.test(env.code)) {
|
321 | 337 | return;
|
322 | 338 | }
|
|
325 | 341 | Prism.languages['markup-templating'].buildPlaceholders(env, 'php', phpPattern);
|
326 | 342 | });
|
327 | 343 |
|
328 |
| - Prism.hooks.add('after-tokenize', function(env) { |
| 344 | + Prism.hooks.add('after-tokenize', function (env) { |
329 | 345 | Prism.languages['markup-templating'].tokenizePlaceholders(env, 'php');
|
330 | 346 | });
|
331 | 347 |
|
|
0 commit comments