Skip to content

Commit 27f6023

Browse files
mszabo-wikiaClaude
andcommitted
fix: highlight indented heredoc strings correctly
The attribute-matching lookahead `(?=^\s*<<)` in the grammar was incorrectly capturing indented heredoc syntax `<<<END` as attribute opening `<<`, breaking highlighting for the heredoc and all subsequent code. Narrow the lookahead to `(?=^\s*<<[^<])` so it only matches attribute syntax and not heredocs. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
1 parent fa4ef0f commit 27f6023

3 files changed

Lines changed: 106 additions & 1 deletion

File tree

syntaxes/hack.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@
683683
"include": "#comments"
684684
},
685685
{
686-
"begin": "(?=^\\s*<<)",
686+
"begin": "(?=^\\s*<<[^<])",
687687
"end": "(?<=>>)",
688688
"patterns": [
689689
{

test/grammar/heredoc.hack

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function _(): void {
2+
$not_heredoc = "<<<END";
3+
$either = "END";
4+
$unindented = Str\format(<<<END
5+
END
6+
);
7+
$indented = Str\format(
8+
<<<END
9+
END
10+
);
11+
$y = '';
12+
Cls::someMethod();
13+
}

test/grammar/heredoc.hack.snap

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
>function _(): void {
2+
#^^^^^^^^ source.hack meta.function.php storage.type.function.php
3+
# ^ source.hack meta.function.php
4+
# ^ source.hack meta.function.php entity.name.function.php
5+
# ^ source.hack meta.function.php punctuation.definition.parameters.begin.php
6+
# ^ source.hack meta.function.php punctuation.definition.parameters.end.php
7+
# ^ source.hack meta.function.php punctuation.definition.type.php
8+
# ^ source.hack meta.function.php
9+
# ^^^^ source.hack meta.function.php support.class.php
10+
# ^ source.hack meta.function.php
11+
# ^ source.hack punctuation.section.scope.begin.php
12+
> $not_heredoc = "<<<END";
13+
#^^ source.hack
14+
# ^ source.hack variable.other.php punctuation.definition.variable.php
15+
# ^^^^^^^^^^^ source.hack variable.other.php
16+
# ^ source.hack
17+
# ^ source.hack keyword.operator.assignment.php
18+
# ^ source.hack
19+
# ^ source.hack string.quoted.double.php punctuation.definition.string.begin.php
20+
# ^^^^^^ source.hack string.quoted.double.php meta.string-contents.quoted.double.php
21+
# ^ source.hack string.quoted.double.php punctuation.definition.string.end.php
22+
# ^ source.hack punctuation.terminator.expression.php
23+
> $either = "END";
24+
#^^ source.hack
25+
# ^ source.hack variable.other.php punctuation.definition.variable.php
26+
# ^^^^^^ source.hack variable.other.php
27+
# ^ source.hack
28+
# ^ source.hack keyword.operator.assignment.php
29+
# ^ source.hack
30+
# ^ source.hack string.quoted.double.php punctuation.definition.string.begin.php
31+
# ^^^ source.hack string.quoted.double.php meta.string-contents.quoted.double.php
32+
# ^ source.hack string.quoted.double.php punctuation.definition.string.end.php
33+
# ^ source.hack punctuation.terminator.expression.php
34+
> $unindented = Str\format(<<<END
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 meta.function-call.php support.other.namespace.php entity.name.type.namespace.php
42+
# ^ source.hack meta.function-call.php support.other.namespace.php punctuation.separator.inheritance.php
43+
# ^^^^^^ source.hack meta.function-call.php entity.name.function.php
44+
# ^ source.hack
45+
# ^^^ source.hack string.unquoted.heredoc.php
46+
# ^^^ source.hack string.unquoted.heredoc.php keyword.operator.heredoc.php
47+
>END
48+
#^^^ source.hack string.unquoted.heredoc.php keyword.operator.heredoc.php
49+
>);
50+
#^ source.hack
51+
# ^ source.hack punctuation.terminator.expression.php
52+
> $indented = Str\format(
53+
#^^ source.hack
54+
# ^ source.hack variable.other.php punctuation.definition.variable.php
55+
# ^^^^^^^^ source.hack variable.other.php
56+
# ^ source.hack
57+
# ^ source.hack keyword.operator.assignment.php
58+
# ^ source.hack
59+
# ^^^ source.hack meta.function-call.php support.other.namespace.php entity.name.type.namespace.php
60+
# ^ source.hack meta.function-call.php support.other.namespace.php punctuation.separator.inheritance.php
61+
# ^^^^^^ source.hack meta.function-call.php entity.name.function.php
62+
# ^^ source.hack
63+
> <<<END
64+
#^^^^ source.hack
65+
# ^^^ source.hack string.unquoted.heredoc.php
66+
# ^^^ source.hack string.unquoted.heredoc.php keyword.operator.heredoc.php
67+
>END
68+
#^^^ source.hack string.unquoted.heredoc.php keyword.operator.heredoc.php
69+
>);
70+
#^ source.hack
71+
# ^ source.hack punctuation.terminator.expression.php
72+
> $y = '';
73+
#^^ source.hack
74+
# ^ source.hack variable.other.php punctuation.definition.variable.php
75+
# ^ source.hack variable.other.php
76+
# ^ source.hack
77+
# ^ source.hack keyword.operator.assignment.php
78+
# ^ source.hack
79+
# ^ source.hack string.quoted.single.php punctuation.definition.string.begin.php
80+
# ^ source.hack string.quoted.single.php punctuation.definition.string.end.php
81+
# ^ source.hack punctuation.terminator.expression.php
82+
> Cls::someMethod();
83+
#^^ source.hack
84+
# ^^^ source.hack support.class.php
85+
# ^^ source.hack keyword.operator.class.php
86+
# ^^^^^^^^^^ source.hack meta.function-call.static.php
87+
# ^ source.hack
88+
# ^ source.hack
89+
# ^ source.hack punctuation.terminator.expression.php
90+
>}
91+
#^ source.hack punctuation.section.scope.end.php
92+
>

0 commit comments

Comments
 (0)