Skip to content

Commit

Permalink
enh(php) Left and right-side of double colon
Browse files Browse the repository at this point in the history
  • Loading branch information
wkania committed Dec 19, 2021
1 parent 01d91db commit e929ec6
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/languages/php.js
Expand Up @@ -340,6 +340,62 @@ export default function(hljs) {
}
};

// This will not detect camelCase classes
const PASCAL_CASE_CLASS_NAME = regex.concat("[A-Z]", IDENT_RE);

const CONSTANT_REFERENCE = regex.concat(IDENT_RE, "\\b(?!\\()");

const LEFT_AND_RIGHT_SIDE_OF_DOUBLE_COLON = {
variants: [
{
match: [
regex.concat(
/::/,
regex.lookahead(/(?!class\b)/)
),
CONSTANT_REFERENCE,
],
scope: {
2: "variable",
},
},
{
match: [
PASCAL_CASE_CLASS_NAME,
regex.concat(
"::",
regex.lookahead(/(?!class\b)/)
),
CONSTANT_REFERENCE,
],
scope: {
1: "title.class",
3: "variable",
},
},
{
match: [
/::/,
/class/,
],
scope: {
2: "variable.language",
},
},
{
match: [
PASCAL_CASE_CLASS_NAME,
/::/,
/class/,
],
scope: {
1: "title.class",
3: "variable.language",
},
}
]
};

return {
case_insensitive: false,
keywords: KEYWORDS,
Expand Down Expand Up @@ -380,6 +436,7 @@ export default function(hljs) {
},
VARIABLE,
FUNCTION_INVOKE,
LEFT_AND_RIGHT_SIDE_OF_DOUBLE_COLON,
{
match: [
/const/,
Expand Down Expand Up @@ -425,6 +482,7 @@ export default function(hljs) {
contains: [
'self',
VARIABLE,
LEFT_AND_RIGHT_SIDE_OF_DOUBLE_COLON,
hljs.C_BLOCK_COMMENT_MODE,
STRING,
NUMBER
Expand Down

0 comments on commit e929ec6

Please sign in to comment.