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

enh(php) add PHP 8.1 keywords #3429

Merged
merged 2 commits into from Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -13,6 +13,7 @@ These changes should be for the better and should not be super noticeable but if

Grammars:

- enh(php) add PHP 8.1 keywords [Wojciech Kania][]
- enh(php) support First-class Callable Syntax (#3427) [Wojciech Kania][]
- enh(php) support class constructor call (#3427) [Wojciech Kania][]
- enh(php) support function invoke (#3427) [Wojciech Kania][]
Expand Down
27 changes: 16 additions & 11 deletions src/languages/php.js
Expand Up @@ -13,22 +13,22 @@ Category: common
export default function(hljs) {
const regex = hljs.regex;
const VARIABLE = {
className: 'variable',
begin: '\\$+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*' +
scope: 'variable',
match: '\\$+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*' +
// negative look-ahead tries to avoid matching patterns that are not
// Perl at all like $ident$, @ident@, etc.
`(?![A-Za-z0-9])(?![$])`
};
const PREPROCESSOR = {
className: 'meta',
scope: 'meta',
variants: [
{ begin: /<\?php/, relevance: 10 }, // boost for obvious PHP
{ begin: /<\?[=]?/ },
{ begin: /\?>/ } // end php tag
]
};
const SUBST = {
className: 'subst',
scope: 'subst',
variants: [
{ begin: /\$\w+/ },
{ begin: /\{\$/, end: /\}/ }
Expand All @@ -49,15 +49,15 @@ export default function(hljs) {
// list of valid whitespaces because non-breaking space might be part of a name
const WHITESPACE = '[ \t\n]';
const STRING = {
className: 'string',
scope: 'string',
variants: [
DOUBLE_QUOTED,
SINGLE_QUOTED,
HEREDOC
]
};
const NUMBER = {
className: 'number',
scope: 'number',
variants: [
{ begin: `\\b0[bB][01]+(?:_[01]+)*\\b` }, // Binary w/ underscore support
{ begin: `\\b0[oO][0-7]+(?:_[0-7]+)*\\b` }, // Octals w/ underscore support
Expand Down Expand Up @@ -151,11 +151,13 @@ export default function(hljs) {
"match|0",
"mixed",
"new",
"never",
"object",
"or",
"private",
"protected",
"public",
"readonly",
"real",
"return",
"string",
Expand Down Expand Up @@ -245,14 +247,17 @@ export default function(hljs) {
// Reserved interfaces:
// <https://www.php.net/manual/en/reserved.interfaces.php>
"ArrayAccess",
"BackedEnum",
"Closure",
"Fiber",
"Generator",
"Iterator",
"IteratorAggregate",
"Serializable",
"Stringable",
"Throwable",
"Traversable",
"UnitEnum",
"WeakReference",
"WeakMap",
// Reserved classes:
Expand Down Expand Up @@ -369,8 +374,8 @@ export default function(hljs) {
},
PREPROCESSOR,
{
className: 'variable.language',
begin: /\$this\b/
scope: 'variable.language',
match: /\$this\b/
},
VARIABLE,
FUNCTION_INVOKE,
Expand All @@ -385,7 +390,7 @@ export default function(hljs) {
},
CONSTRUCTOR_CALL,
{
className: 'function',
scope: 'function',
relevance: 0,
beginKeywords: 'fn function', end: /[;{]/, excludeEnd: true,
illegal: '[$%\\[]',
Expand All @@ -399,7 +404,7 @@ export default function(hljs) {
endsParent: true
},
{
className: 'params',
scope: 'params',
begin: '\\(', end: '\\)',
excludeBegin: true,
excludeEnd: true,
Expand All @@ -415,7 +420,7 @@ export default function(hljs) {
]
},
{
className: 'class',
scope: 'class',
variants: [
{ beginKeywords: "enum", illegal: /[($"]/ },
{ beginKeywords: "class interface trait", illegal: /[:($"]/ }
Expand Down