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

[PHP] Add support for Enum #3004

Merged
merged 4 commits into from
Feb 18, 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Language grammar improvements:
- enh(php) Add `Stringable`, `UnhandledMatchError`, and `WeakMap` classes/interfaces (#2997) [Ayesh][]
- enh(php) Add `mixed` to list of keywords (#2997) [Ayesh][]
- enh(php) Add support binary, octal, hex and scientific numerals with underscore separator support (#2997) [Ayesh][]
- enh(php) Add support for Enums (#3004) [Ayesh][]

API:

Expand Down
8 changes: 5 additions & 3 deletions src/languages/php.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default function(hljs) {
// <https://www.php.net/manual/en/reserved.php>
// <https://www.php.net/manual/en/language.types.type-juggling.php>
'array abstract and as binary bool boolean break callable case catch class clone const continue declare ' +
'default do double else elseif empty enddeclare endfor endforeach endif endswitch endwhile eval extends ' +
'default do double else elseif empty enddeclare endfor endforeach endif endswitch endwhile enum eval extends ' +
'final finally float for foreach from global goto if implements instanceof insteadof int integer interface ' +
'isset iterable list match|0 mixed new object or private protected public real return string switch throw trait ' +
'try unset use var void while xor yield',
Expand Down Expand Up @@ -170,11 +170,13 @@ export default function(hljs) {
},
{
className: 'class',
beginKeywords: 'class interface trait',
variants: [
{ beginKeywords: "enum", illegal: /[($"]/ },
{ beginKeywords: "class interface trait", illegal: /[:($"]/ }
],
relevance: 0,
end: /\{/,
excludeEnd: true,
illegal: /[:($"]/,
contains: [
{beginKeywords: 'extends implements'},
hljs.UNDERSCORE_TITLE_MODE
Expand Down
12 changes: 12 additions & 0 deletions test/detect/php/default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ match ($key) {
[1] => 'Array [1]',
};

enum Foo: string {
case Test = 'test';
}

match ($key) {
1 => 'Integer 1',
'1' => 'String 1',
true => 'Bool true',
[] => 'Empty array',
[1] => 'Array [1]',
};

echo URI::ME . URI::$st1;

__halt_compiler () ; datahere
Expand Down
3 changes: 3 additions & 0 deletions test/markup/php/php80.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@
[<span class="hljs-number">1</span>] =&gt; <span class="hljs-string">&#x27;Array [1]&#x27;</span>,
};

<span class="hljs-class"><span class="hljs-keyword">enum</span> <span class="hljs-title">Foo</span>: <span class="hljs-title">string</span> </span>{
<span class="hljs-keyword">case</span> Test = <span class="hljs-string">&#x27;test&#x27;</span>;
}
4 changes: 4 additions & 0 deletions test/markup/php/php80.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ match ($key) {
[] => 'Empty array',
[1] => 'Array [1]',
};

enum Foo: string {
case Test = 'test';
}