Skip to content

Commit

Permalink
PHP: Removed useless keyword tokens (#3121)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Oct 5, 2021
1 parent dc1e808 commit ee62a08
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
16 changes: 2 additions & 14 deletions components/prism-php.js
Expand Up @@ -66,31 +66,19 @@
greedy: true,
lookbehind: true
},
{
pattern: /([(,?]\s*[\w|]\|\s*)(?:false|null)\b(?=\s*\$)/i,
alias: 'type-hint',
greedy: true,
lookbehind: true
},
{
pattern: /(\)\s*:\s*(?:\?\s*)?)\b(?:array(?!\s*\()|bool|callable|(?:false|null)(?=\s*\|)|float|int|iterable|mixed|object|self|static|string|void)\b/i,
alias: 'return-type',
greedy: true,
lookbehind: true
},
{
pattern: /(\)\s*:\s*(?:\?\s*)?[\w|]\|\s*)(?:false|null)\b/i,
alias: 'return-type',
greedy: true,
lookbehind: true
},
{
pattern: /\b(?:array(?!\s*\()|bool|(?:false|null)(?=\s*\|)|float|int|iterable|mixed|object|string|void)\b/i,
pattern: /\b(?:array(?!\s*\()|bool|float|int|iterable|mixed|object|string|void)\b/i,
alias: 'type-declaration',
greedy: true
},
{
pattern: /(\|\s*)(?:false|null)\b/i,
pattern: /(\|\s*)(?:false|null)\b|\b(?:false|null)(?=\s*\|)/i,
alias: 'type-declaration',
greedy: true,
lookbehind: true
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.

33 changes: 33 additions & 0 deletions tests/languages/php/class-name_feature.test
Expand Up @@ -16,6 +16,9 @@ function f($variable): ?Foo {}

function f(Foo|Bar $variable): Foo|Bar {}

function f(Foo|false $variable): Foo|Bar {}
function f(Foo|null $variable): Foo|Bar {}

function f(\Package\Foo|\Package\Bar $variable): \Package\Foo|\Package\Bar {}

class Foo extends Bar implements Baz {}
Expand Down Expand Up @@ -134,6 +137,36 @@ class Foo extends \Package\Bar implements App\Baz {}
["punctuation", "{"],
["punctuation", "}"],

["keyword", "function"],
["function-definition", "f"],
["punctuation", "("],
["class-name", "Foo"],
["operator", "|"],
["keyword", "false"],
["variable", "$variable"],
["punctuation", ")"],
["punctuation", ":"],
["class-name", "Foo"],
["operator", "|"],
["class-name", "Bar"],
["punctuation", "{"],
["punctuation", "}"],

["keyword", "function"],
["function-definition", "f"],
["punctuation", "("],
["class-name", "Foo"],
["operator", "|"],
["keyword", "null"],
["variable", "$variable"],
["punctuation", ")"],
["punctuation", ":"],
["class-name", "Foo"],
["operator", "|"],
["class-name", "Bar"],
["punctuation", "{"],
["punctuation", "}"],

["keyword", "function"],
["function-definition", "f"],
["punctuation", "("],
Expand Down

0 comments on commit ee62a08

Please sign in to comment.