Skip to content

Commit b52d949

Browse files
mszabo-wikiaClaude
andcommitted
fix: highlight upcast as a keyword in grammar
Add `upcast` to the `as|is` keyword patterns so it is tokenized as `keyword.operator.type.php` instead of `constant.other.php`. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
1 parent 7a3aaca commit b52d949

3 files changed

Lines changed: 71 additions & 2 deletions

File tree

syntaxes/hack.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,7 @@
13761376
"name": "keyword.operator.logical.php"
13771377
},
13781378
{
1379-
"begin": "(?i)\\b(as|is)\\b\\s+(?=[\\\\$a-z_])",
1379+
"begin": "(?i)\\b(as|is|upcast)\\b\\s+(?=[\\\\$a-z_~?])",
13801380
"beginCaptures": {
13811381
"1": {
13821382
"name": "keyword.operator.type.php"
@@ -1393,7 +1393,7 @@
13931393
]
13941394
},
13951395
{
1396-
"match": "(?i)\\b(is|as)\\b",
1396+
"match": "(?i)\\b(is|as|upcast)\\b",
13971397
"name": "keyword.operator.type.php"
13981398
},
13991399
{

test/grammar/upcast.hack

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
type upcast_test_t = shape('x' => string);
2+
3+
function upcast_test(dynamic $b): void {
4+
$var = $b upcast ~int;
5+
$upcast = 'test';
6+
}

test/grammar/upcast.hack.snap

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# SYNTAX TEST "source.hack" "autogenerated snapshot test"
2+
>type upcast_test_t = shape('x' => string);
3+
#^^^^ source.hack meta.typedecl.php storage.type.typedecl.php
4+
# ^ source.hack meta.typedecl.php
5+
# ^^^^^^^^^^^^^ source.hack meta.typedecl.php entity.name.type.typedecl.php
6+
# ^ source.hack meta.typedecl.php
7+
# ^ source.hack meta.typedecl.php keyword.operator.assignment.php
8+
# ^ source.hack meta.typedecl.php
9+
# ^^^^^^ source.hack meta.typedecl.php storage.type.shape.php
10+
# ^ source.hack meta.typedecl.php storage.type.shape.php string.quoted.single.php punctuation.definition.string.begin.php
11+
# ^ source.hack meta.typedecl.php storage.type.shape.php string.quoted.single.php meta.string-contents.quoted.single.php
12+
# ^ source.hack meta.typedecl.php storage.type.shape.php string.quoted.single.php punctuation.definition.string.end.php
13+
# ^^^^ source.hack meta.typedecl.php storage.type.shape.php
14+
# ^^^^^^ source.hack meta.typedecl.php storage.type.shape.php support.type.php
15+
# ^ source.hack meta.typedecl.php storage.type.shape.php keyword.operator.key.php
16+
# ^ source.hack meta.typedecl.php punctuation.termination.expression.php
17+
>
18+
#^ source.hack
19+
>function upcast_test(dynamic $b): void {
20+
#^^^^^^^^ source.hack meta.function.php storage.type.function.php
21+
# ^ source.hack meta.function.php
22+
# ^^^^^^^^^^^ source.hack meta.function.php entity.name.function.php
23+
# ^ source.hack meta.function.php punctuation.definition.parameters.begin.php
24+
# ^^^^^^^ source.hack meta.function.php meta.function.arguments.php support.class.php
25+
# ^ source.hack meta.function.php meta.function.arguments.php
26+
# ^ source.hack meta.function.php meta.function.arguments.php variable.other.php punctuation.definition.variable.php
27+
# ^ source.hack meta.function.php meta.function.arguments.php variable.other.php
28+
# ^ source.hack meta.function.php punctuation.definition.parameters.end.php
29+
# ^ source.hack meta.function.php punctuation.definition.type.php
30+
# ^ source.hack meta.function.php
31+
# ^^^^ source.hack meta.function.php support.class.php
32+
# ^ source.hack meta.function.php
33+
# ^ source.hack punctuation.section.scope.begin.php
34+
> $var = $b upcast ~int;
35+
#^^^^ source.hack
36+
# ^ source.hack variable.other.php punctuation.definition.variable.php
37+
# ^^^ source.hack variable.other.php
38+
# ^ source.hack
39+
# ^ source.hack keyword.operator.assignment.php
40+
# ^ source.hack
41+
# ^ source.hack variable.other.php punctuation.definition.variable.php
42+
# ^ source.hack variable.other.php
43+
# ^ source.hack
44+
# ^^^^^^ source.hack keyword.operator.type.php
45+
# ^ source.hack
46+
# ^ source.hack keyword.operator.bitwise.php
47+
# ^^^ source.hack support.type.php
48+
# ^ source.hack punctuation.terminator.expression.php
49+
> $upcast = 'test';
50+
#^^^^ source.hack
51+
# ^ source.hack variable.other.php punctuation.definition.variable.php
52+
# ^^^^^^ source.hack variable.other.php
53+
# ^ source.hack
54+
# ^ source.hack keyword.operator.assignment.php
55+
# ^ source.hack
56+
# ^ source.hack string.quoted.single.php punctuation.definition.string.begin.php
57+
# ^^^^ source.hack string.quoted.single.php meta.string-contents.quoted.single.php
58+
# ^ source.hack string.quoted.single.php punctuation.definition.string.end.php
59+
# ^ source.hack punctuation.terminator.expression.php
60+
>}
61+
#^ source.hack punctuation.section.scope.end.php
62+
>
63+
#^ source.hack

0 commit comments

Comments
 (0)