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] Modify throw to an expression keyword #4027

Merged
merged 1 commit into from
Aug 8, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions PHP/PHP Source.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ variables:
| {{class_modifier}}
| {{static_modifier}}
| {{builtin_variables}}
| {{expression_keywords}}
| function\b
| as\b
| yield\b
)

keywords: |-
Expand All @@ -72,9 +71,11 @@ variables:
(?xi: case | catch | default | do | (?: end )? (?: for(?:each)? | if | switch | while )
| else | elseif | finally | switch | try )\b
flow_keywords: |-
(?xi: break | continue | die | exit | finally | goto | return | throw )\b
(?xi: break | continue | die | exit | finally | goto | return )\b

# Expression Level Keywords
expression_keywords: |-
(?xi: as | throw | yield )\b
builtin_functions: |-
(?xi: echo | print | empty | eval | isset | list | unset )\b
builtin_variables: |-
Expand Down Expand Up @@ -1308,8 +1309,6 @@ contexts:
scope: keyword.control.flow.panic.php
- match: (?i:return)\b
scope: keyword.control.flow.return.php
- match: (?i:throw)\b
scope: keyword.control.flow.throw.php

goto-label:
- match: '{{guarded_identifier}}'
Expand Down Expand Up @@ -2191,6 +2190,9 @@ contexts:
scope: keyword.other.clone.php
- match: (?i:insteadof)\b
scope: keyword.other.insteadof.php
# throw is an expression keyword as of PHP8
- match: (?i:throw)\b
scope: keyword.control.flow.throw.php
# yield from ( http://php.net/manual/en/language.generators.syntax.php#control-structures.yield.from )
- match: (?i:yield)\b
scope: keyword.control.flow.yield.php
Expand Down
17 changes: 17 additions & 0 deletions PHP/tests/syntax_test_php.php
Original file line number Diff line number Diff line change
Expand Up @@ -2020,6 +2020,23 @@ function array_values_from_keys($arr, $keys) {
// ^ punctuation.section.group.end.php
// ^ punctuation.section.block.begin.php

some_function(fn() => throw $exception);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.arguments.php meta.group.php
// ^^^^^^^^^^^^^^^^ meta.function.anonymous.php
// ^^^^^ keyword.control.flow.throw.php
// ^^^^^^^^^^ variable.other.php
// ^ punctuation.section.group.end.php

some_function(fn() => throw $exception, 'some other argument');
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.arguments.php meta.group.php
// ^^^^^^^^^^^^^^^^ meta.function.anonymous.php
// ^^^^^^^^^^^^^^^^^^^^^^^^ - meta.function.anonymous
// ^^^^^ keyword.control.flow.throw.php
// ^^^^^^^^^^ variable.other.php
// ^ punctuation.separator.sequence.php
// ^^^^^^^^^^^^^^^^^^^^^ meta.string.php string.quoted.single.php
// ^ punctuation.section.group.end.php

};
// <- meta.function.php meta.block.php punctuation.section.block.end.php

Expand Down