Skip to content

Commit 015a00c

Browse files
committed
(chore) add php IDENT_RE
1 parent 2e344f5 commit 015a00c

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/languages/php.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ Category: common
1212
* */
1313
export default function(hljs) {
1414
const regex = hljs.regex;
15+
const IDENT_RE = '([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*' +
16+
// negative look-ahead tries to avoid matching patterns that are not
17+
// Perl at all like $ident$, @ident@, etc.
18+
'(?![A-Za-z0-9])(?![$]))';
1519
const VARIABLE = {
1620
scope: 'variable',
17-
match: '\\$+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*' +
18-
// negative look-ahead tries to avoid matching patterns that are not
19-
// Perl at all like $ident$, @ident@, etc.
20-
`(?![A-Za-z0-9])(?![$])`
21+
match: '\\$+' + IDENT_RE,
2122
};
2223
const PREPROCESSOR = {
2324
scope: 'meta',
@@ -313,7 +314,7 @@ export default function(hljs) {
313314
regex.concat(WHITESPACE, "+"),
314315
// to prevent built ins from being confused as the class constructor call
315316
regex.concat("(?!", normalizeKeywords(BUILT_INS).join("\\b|"), "\\b)"),
316-
/\\?\w+/,
317+
regex.concat("\\\\?", IDENT_RE, "+"),
317318
regex.concat(WHITESPACE, "*\\("),
318319
],
319320
scope: {
@@ -330,7 +331,7 @@ export default function(hljs) {
330331
/\b/,
331332
// to prevent keywords from being confused as the function title
332333
regex.concat("(?!fn\\b|function\\b|", normalizeKeywords(KWS).join("\\b|"), "|", normalizeKeywords(BUILT_INS).join("\\b|"), "\\b)"),
333-
/\w+/,
334+
regex.concat(IDENT_RE, "+"),
334335
regex.concat(WHITESPACE, "*"),
335336
regex.lookahead(/(?=\()/)
336337
],
@@ -351,8 +352,8 @@ export default function(hljs) {
351352
{
352353
contains: [
353354
{
354-
className: 'doctag',
355-
begin: '@[A-Za-z]+'
355+
scope: 'doctag',
356+
match: '@[A-Za-z]+'
356357
}
357358
]
358359
}
@@ -382,9 +383,9 @@ export default function(hljs) {
382383
{
383384
// swallow composed identifiers to avoid parsing them as keywords
384385
match: regex.concat(
385-
/(::|->)+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/,
386-
regex.concat("(?!", WHITESPACE, "*\\()"),
387-
/(?![a-zA-Z0-9_\x7f-\xff])/
386+
/(::|->)+/,
387+
IDENT_RE,
388+
regex.concat("(?!", WHITESPACE, "*\\()")
388389
),
389390
// scope:"wrong"
390391
},

0 commit comments

Comments
 (0)