Skip to content
This repository was archived by the owner on Nov 3, 2025. It is now read-only.

Commit 67bdb84

Browse files
Antonio Ochoa Solanofrankeld
andauthored
Simplify embedded_braced_expression (#29)
* Simplify embedded_braced_expression * Separate heredoc variables in almost test * Add external node _embedded_opening_brace * Update build files Co-authored-by: David Frankel <42774874+frankeld@users.noreply.github.com>
1 parent aca58a7 commit 67bdb84

20 files changed

+201435
-201613
lines changed

grammar.js

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -150,35 +150,23 @@ const rules = {
150150
'<<<',
151151
$._heredoc_start,
152152
opt(alias($._heredoc_start_newline, '\n')),
153-
rep(choice($._heredoc_body, $.variable, $.embedded_brace_expression)),
153+
rep(choice($._heredoc_body, $.variable, $.embedded_braced_expression)),
154154
opt(alias($._heredoc_end_newline, '\n')),
155155
$._heredoc_end,
156156
),
157157

158-
embedded_brace_expression: $ => seq($._embedded_brace_expression, '}'),
159-
160-
_embedded_brace_expression: $ =>
161-
choice(
162-
alias(token(seq('{$', identifier)), $.variable),
163-
alias($._embedded_brace_call_expression, $.call_expression),
164-
alias($._embedded_brace_subscript_expression, $.subscript_expression),
165-
alias($._embedded_brace_selection_expression, $.selection_expression),
166-
),
167-
168-
_embedded_brace_call_expression: $ =>
169-
seq($._embedded_brace_expression, $.arguments),
170-
171-
_embedded_brace_subscript_expression: $ =>
172-
seq($._embedded_brace_expression, '[', opt($._expression), ']'),
173-
174-
_embedded_brace_selection_expression: $ =>
175-
prec(
176-
-1,
177-
seq(
178-
$._embedded_brace_expression,
179-
field('selection_operator', choice('?->', '->')),
180-
$._variablish,
158+
embedded_braced_expression: $ =>
159+
seq(
160+
// Use an external scanner for the opening brace so we can restrict embedded braced
161+
// expressions to ones that start with a $.variable.
162+
alias($._embedded_opening_brace, '{'),
163+
choice(
164+
$.variable,
165+
$.call_expression,
166+
$.subscript_expression,
167+
$.selection_expression,
181168
),
169+
'}',
182170
),
183171

184172
braced_expression: $ => seq('{', $._expression, '}'),
@@ -1250,6 +1238,7 @@ module.exports = grammar({
12501238
$._heredoc_body,
12511239
$._heredoc_end_newline,
12521240
$._heredoc_end,
1241+
$._embedded_opening_brace,
12531242
],
12541243

12551244
supertypes: $ => [

src/grammar.json

Lines changed: 21 additions & 120 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/node-types.json

Lines changed: 5 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)