Skip to content

Commit

Permalink
PHP: Added never return type + minor fix of named arguments (#3421)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomPavelec committed Apr 1, 2022
1 parent 11c5462 commit 4ffab52
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
6 changes: 3 additions & 3 deletions components/prism-php.js
Expand Up @@ -67,7 +67,7 @@
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,
pattern: /(\)\s*:\s*(?:\?\s*)?)\b(?:array(?!\s*\()|bool|callable|(?:false|null)(?=\s*\|)|float|int|iterable|mixed|never|object|self|static|string|void)\b/i,
alias: 'return-type',
greedy: true,
lookbehind: true
Expand Down Expand Up @@ -100,12 +100,12 @@
//
// keywords cannot be preceded by "->"
// the complex lookbehind means `(?<!(?:->|::)\s*)`
pattern: /((?:^|[^\s>:]|(?:^|[^-])>|(?:^|[^:]):)\s*)\b(?: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|fn|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|match|namespace|new|or|parent|print|private|protected|public|readonly|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield|__halt_compiler)\b/i,
pattern: /((?:^|[^\s>:]|(?:^|[^-])>|(?:^|[^:]):)\s*)\b(?: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|fn|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|match|namespace|never|new|or|parent|print|private|protected|public|readonly|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield|__halt_compiler)\b/i,
lookbehind: true
}
],
'argument-name': {
pattern: /([(,]\s+)\b[a-z_]\w*(?=\s*:(?!:))/i,
pattern: /([(,]\s*)\b[a-z_]\w*(?=\s*:(?!:))/i,
lookbehind: true
},
'class-name': [
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.

18 changes: 18 additions & 0 deletions tests/languages/php/argument-name_feature.test
Expand Up @@ -3,9 +3,27 @@ foo(
qux: 'baz'
);

foo(a: 'bar', qux: 'baz' );

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

[
["function", ["foo"]],
["punctuation", "("],

["argument-name", "a"],
["punctuation", ":"],
["string", "'bar'"],
["punctuation", ","],

["argument-name", "qux"],
["punctuation", ":"],
["string", "'baz'"],

["punctuation", ")"],
["punctuation", ";"],


["function", ["foo"]],
["punctuation", "("],

Expand Down
4 changes: 4 additions & 0 deletions tests/languages/php/keyword_feature.test
Expand Up @@ -47,6 +47,7 @@ isset
list
namespace;
match
never
new;
or
parent
Expand All @@ -71,6 +72,7 @@ try
unset
use;
var
void
while
xor
yield
Expand Down Expand Up @@ -128,6 +130,7 @@ yield from
["keyword", "list"],
["keyword", "namespace"], ["punctuation", ";"],
["keyword", "match"],
["keyword", "never"],
["keyword", "new"], ["punctuation", ";"],
["keyword", "or"],
["keyword", "parent"],
Expand All @@ -152,6 +155,7 @@ yield from
["keyword", "unset"],
["keyword", "use"], ["punctuation", ";"],
["keyword", "var"],
["keyword", "void"],
["keyword", "while"],
["keyword", "xor"],
["keyword", "yield"],
Expand Down

0 comments on commit 4ffab52

Please sign in to comment.