Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added support for PHP 8.1 enums #2770

Merged
merged 3 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions components/prism-php.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,25 @@
pattern: /\b(?:false|true)\b/i,
alias: 'boolean'
},
/\b[A-Z_][A-Z0-9_]*\b(?!\s*\()/,
{
pattern: /(::\s*)\b[a-z_]\w*\b(?!\s*\()/i,
greedy: true,
lookbehind: true,
},
{
pattern: /(\bcase\s+)\b[a-z_]\w*(?=\s*[;=])/i,
alias: 'enum-definition',
greedy: true,
lookbehind: true,
},
{
pattern: /(\bconst\s+)\b[a-z_]\w*(?=\s*[;=])/i,
alias: 'class-constant-definition',
greedy: true,
lookbehind: true,
},
/\b(?:null)\b/i,
/\b[A-Z_][A-Z0-9_]*\b(?!\s*\()/,
];
var number = /\b0b[01]+(?:_[01]+)*\b|\b0o[0-7]+(?:_[0-7]+)*\b|\b0x[\da-f]+(?:_[\da-f]+)*\b|(?:\b\d+(?:_\d+)*\.?(?:\d+(?:_\d+)*)?|\B\.\d+)(?:e[+-]?\d+)?/i;
var operator = /<?=>|\?\?=?|\.{3}|\??->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||<<|>>|[?~]|[/^|%*&<>.+-]=?/;
Expand Down Expand Up @@ -87,7 +104,10 @@
},
/\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
],
'argument-name': /\b[a-z_]\w*(?=\s*:(?!:))/i,
'argument-name': {
pattern: /([(,]\s+)\b[a-z_]\w*(?=\s*:(?!:))/i,
lookbehind: true
},
'class-name': [
{
pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s*\()\b[a-z_]\w*(?!\\)\b/i,
Expand Down
2 changes: 1 addition & 1 deletion components/prism-php.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/languages/latte/html_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
["tag", [["tag", [["punctuation", "<"], "a"]],
["attr-name", ["href"]], ["attr-value", [["punctuation", "="], ["punctuation", "\""],
["latte", [["ld", [["punctuation", "{"], ["tag", "link"]]],
["php", [["argument-name", "Post"], ["punctuation", ":"], ["class-name", "show"], ["variable", "$post"], ["operator", "->"], ["property", "id"]]],
["php", ["Post", ["punctuation", ":"], ["class-name", "show"], ["variable", "$post"], ["operator", "->"], ["property", "id"]]],
["rd", [["punctuation", "}"]]]]],
["punctuation", "\""]]], ["punctuation", ">"]]],
["latte", [["ld", [["punctuation", "{"]]], ["php", [["variable", "$post"], ["operator", "->"], ["property", "title"]]], ["rd", [["punctuation", "}"]]]]],
Expand Down
4 changes: 2 additions & 2 deletions tests/languages/latte/n-attr_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
[
["tag", [["tag", [["punctuation", "<"], "a"]],
["n-attr", [["attr-name", "n:href"],
["attr-value", [["punctuation", "="], ["punctuation", "\""], ["php", [["argument-name", "Post"], ["punctuation", ":"], ["class-name", "show"], ["variable", "$post"], ["operator", "->"], ["property", "id"]]], ["punctuation", "\""]]]]],
["attr-value", [["punctuation", "="], ["punctuation", "\""], ["php", ["Post", ["punctuation", ":"], ["class-name", "show"], ["variable", "$post"], ["operator", "->"], ["property", "id"]]], ["punctuation", "\""]]]]],
["punctuation", ">"]]],
"link", ["tag", [["tag", [["punctuation", "</"], "a"]], ["punctuation", ">"]]],

["tag", [["tag", [["punctuation", "<"], "a"]],
["n-attr", [["attr-name", "n:href"],
["attr-value", [["punctuation", "="], ["punctuation", "\""], ["php", [["argument-name", "Post"], ["punctuation", ":"], ["class-name", "show"], ["variable", "$post"], ["operator", "->"], ["property", "id"]]], ["punctuation", "\""]]]]],
["attr-value", [["punctuation", "="], ["punctuation", "\""], ["php", ["Post", ["punctuation", ":"], ["class-name", "show"], ["variable", "$post"], ["operator", "->"], ["property", "id"]]], ["punctuation", "\""]]]]],
["punctuation", ">"]]],
"link", ["tag", [["tag", [["punctuation", "</"], "a"]], ["punctuation", ">"]]],

Expand Down
9 changes: 0 additions & 9 deletions tests/languages/php/class-name_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class Foo extends Bar implements Baz {}

class Foo extends \Package\Bar implements App\Baz {}

enum Foo implements Bar {}

----------------------------------------------------

[
Expand Down Expand Up @@ -196,13 +194,6 @@ enum Foo implements Bar {}
"Baz"
]],
["punctuation", "{"],
["punctuation", "}"],

["keyword", "enum"],
["class-name-definition", "Foo"],
["keyword", "implements"],
["class-name", "Bar"],
["punctuation", "{"],
["punctuation", "}"]
]

Expand Down
54 changes: 53 additions & 1 deletion tests/languages/php/constant_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ AZ
PRISM
FOOBAR_42

class Foo{
const BAR = 1;
const baz = 2;
}

Foo::BAR;
Foo::baz;


switch ($i) {
case NULL:
break;
case X:
break;
}

----------------------------------------------------

[
Expand All @@ -13,7 +29,43 @@ FOOBAR_42
["constant", "X"],
["constant", "AZ"],
["constant", "PRISM"],
["constant", "FOOBAR_42"]
["constant", "FOOBAR_42"],

["keyword", "class"],
["class-name-definition", "Foo"],
["punctuation", "{"],
["keyword", "const"],
["constant", "BAR"],
["operator", "="],
["number", "1"],
["punctuation", ";"],
["keyword", "const"],
["constant", "baz"],
["operator", "="],
["number", "2"],
["punctuation", ";"],
["punctuation", "}"],

["class-name", "Foo"], ["operator", "::"], ["constant", "BAR"], ["punctuation", ";"],
["class-name", "Foo"], ["operator", "::"], ["constant", "baz"], ["punctuation", ";"],

["keyword", "switch"],
["punctuation", "("],
["variable", "$i"],
["punctuation", ")"],
["punctuation", "{"],
["keyword", "case"],
["constant", "NULL"],
["punctuation", ":"],
["keyword", "break"],
["punctuation", ";"],
["keyword", "case"],
["constant", "X"],
["punctuation", ":"],
["keyword", "break"],
["punctuation", ";"],
["punctuation", "}"]

]

----------------------------------------------------
Expand Down
52 changes: 52 additions & 0 deletions tests/languages/php/enum_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
enum Foo implements Bar {}

enum Suit {
case Hearts;
case Diamonds = 'D';
}

$val = Suit::Diamonds;

Suit::Spades->name;

----------------------------------------------------

[
["keyword", "enum"],
["class-name-definition", "Foo"],
["keyword", "implements"],
["class-name", "Bar"],
["punctuation", "{"],
["punctuation", "}"],

["keyword", "enum"],
["class-name-definition", "Suit"],
["punctuation", "{"],
["keyword", "case"],
["constant", "Hearts"],
["punctuation", ";"],
["keyword", "case"],
["constant", "Diamonds"],
["operator", "="],
["string", "'D'"],
["punctuation", ";"],
["punctuation", "}"],

["variable", "$val"],
["operator", "="],
["class-name", "Suit"],
["operator", "::"],
["constant", "Diamonds"],
["punctuation", ";"],

["class-name", "Suit"],
["operator", "::"],
["constant", "Spades"],
["operator", "->"],
["property", "name"],
["punctuation", ";"]
]

----------------------------------------------------

Checks for enums.