Skip to content

Commit d7e884b

Browse files
committed
[PHP] Modify throw to an expression keyword
Fixes #4026 Implements RFC https://wiki.php.net/rfc/throw_expression Note: Creates an `expression_keywords` variable to group it together with other expression-level keywords.
1 parent 4dc9b5f commit d7e884b

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

PHP/PHP Source.sublime-syntax

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ variables:
5151
| {{class_modifier}}
5252
| {{static_modifier}}
5353
| {{builtin_variables}}
54+
| {{expression_keywords}}
5455
| function\b
55-
| as\b
56-
| yield\b
5756
)
5857
5958
keywords: |-
@@ -72,9 +71,11 @@ variables:
7271
(?xi: case | catch | default | do | (?: end )? (?: for(?:each)? | if | switch | while )
7372
| else | elseif | finally | switch | try )\b
7473
flow_keywords: |-
75-
(?xi: break | continue | die | exit | finally | goto | return | throw )\b
74+
(?xi: break | continue | die | exit | finally | goto | return )\b
7675
7776
# Expression Level Keywords
77+
expression_keywords: |-
78+
(?xi: as | throw | yield )\b
7879
builtin_functions: |-
7980
(?xi: echo | print | empty | eval | isset | list | unset )\b
8081
builtin_variables: |-
@@ -1308,8 +1309,6 @@ contexts:
13081309
scope: keyword.control.flow.panic.php
13091310
- match: (?i:return)\b
13101311
scope: keyword.control.flow.return.php
1311-
- match: (?i:throw)\b
1312-
scope: keyword.control.flow.throw.php
13131312

13141313
goto-label:
13151314
- match: '{{guarded_identifier}}'
@@ -2191,6 +2190,9 @@ contexts:
21912190
scope: keyword.other.clone.php
21922191
- match: (?i:insteadof)\b
21932192
scope: keyword.other.insteadof.php
2193+
# throw is an expression keyword as of PHP8
2194+
- match: (?i:throw)\b
2195+
scope: keyword.control.flow.throw.php
21942196
# yield from ( http://php.net/manual/en/language.generators.syntax.php#control-structures.yield.from )
21952197
- match: (?i:yield)\b
21962198
scope: keyword.control.flow.yield.php

PHP/tests/syntax_test_php.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,6 +2020,23 @@ function array_values_from_keys($arr, $keys) {
20202020
// ^ punctuation.section.group.end.php
20212021
// ^ punctuation.section.block.begin.php
20222022

2023+
some_function(fn() => throw $exception);
2024+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.arguments.php meta.group.php
2025+
// ^^^^^^^^^^^^^^^^ meta.function.anonymous.php
2026+
// ^^^^^ keyword.control.flow.throw.php
2027+
// ^^^^^^^^^^ variable.other.php
2028+
// ^ punctuation.section.group.end.php
2029+
2030+
some_function(fn() => throw $exception, 'some other argument');
2031+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.arguments.php meta.group.php
2032+
// ^^^^^^^^^^^^^^^^ meta.function.anonymous.php
2033+
// ^^^^^^^^^^^^^^^^^^^^^^^^ - meta.function.anonymous
2034+
// ^^^^^ keyword.control.flow.throw.php
2035+
// ^^^^^^^^^^ variable.other.php
2036+
// ^ punctuation.separator.sequence.php
2037+
// ^^^^^^^^^^^^^^^^^^^^^ meta.string.php string.quoted.single.php
2038+
// ^ punctuation.section.group.end.php
2039+
20232040
};
20242041
// <- meta.function.php meta.block.php punctuation.section.block.end.php
20252042

0 commit comments

Comments
 (0)