Skip to content

Commit ffb3496

Browse files
committed
Revert hash and array literal syntax to align parse errors with Handlebars.js 4.7.8
Reverted changes from handlebars-lang/handlebars-parser#15
1 parent b770389 commit ffb3496

4 files changed

Lines changed: 105 additions & 183 deletions

File tree

grammar/handlebars.y

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,7 @@ mustache:
173173
// Parsing out the '&' escape token at AST level saves ~500 bytes after min due to the removal of one parser node.
174174
// This also allows for handler unification as all mustache node instances can utilize the same handler
175175
// See https://github.com/handlebars-lang/handlebars-parser/blob/master/lib/parse.js
176-
OPEN hash CLOSE {
177-
$$ = $this->prepareMustache(
178-
path: new HashLiteral($2->pairs, $2->loc),
179-
params: [],
180-
hash: null,
181-
open: $1,
182-
strip: $this->stripFlags($1, $3),
183-
loc: locInfo(),
184-
);
185-
}
186-
| OPEN expr expr_list optional_hash CLOSE {
176+
OPEN expr expr_list optional_hash CLOSE {
187177
$$ = $this->prepareMustache(
188178
path: $2,
189179
params: $3,
@@ -244,17 +234,11 @@ expr_list:
244234

245235
expr:
246236
helperName { $$ = $1; }
247-
| exprHead { $$ = $1; }
248-
;
249-
250-
exprHead:
251-
arrayLiteral { $$ = $1; }
252237
| sexpr { $$ = $1; }
253238
;
254239

255240
sexpr:
256-
OPEN_SEXPR hash CLOSE_SEXPR { $$ = new HashLiteral($2->pairs, $2->loc); }
257-
| OPEN_SEXPR expr expr_list optional_hash CLOSE_SEXPR {
241+
OPEN_SEXPR expr expr_list optional_hash CLOSE_SEXPR {
258242
$$ = new SubExpression(
259243
path: $2,
260244
params: $3,
@@ -288,11 +272,6 @@ hashSegment:
288272
);
289273
};
290274

291-
arrayLiteral:
292-
OPEN_ARRAY expr_list CLOSE_ARRAY {
293-
$$ = new ArrayLiteral($2, locInfo());
294-
};
295-
296275
optional_blockParams:
297276
blockParams
298277
| /* empty */ { init(); }
@@ -334,7 +313,7 @@ sep:
334313
;
335314

336315
path:
337-
exprHead sep pathSegments {
316+
sexpr sep pathSegments {
338317
$$ = $this->preparePath(
339318
data: false,
340319
sexpr: $1,

src/Ast/HashLiteral.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/Lexer.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ final class Lexer extends Phlexer
4949
public function __construct()
5050
{
5151
$LEFT_STRIP = $RIGHT_STRIP = '~';
52-
$LOOKAHEAD = '[=~}\\s\\/.)\\]|]';
53-
$LITERAL_LOOKAHEAD = '[~}\\s)\\]]';
52+
$LOOKAHEAD = '[=~}\\s\\/.)|]';
53+
$LITERAL_LOOKAHEAD = '[~}\\s)]';
5454

5555
/*
5656
* ID is the inverse of control characters.
@@ -113,15 +113,6 @@ public function __construct()
113113
new Rule(['mu'], '\\(', fn() => self::T_OPEN_SEXPR),
114114
new Rule(['mu'], '\\)', fn() => self::T_CLOSE_SEXPR),
115115

116-
new Rule(['mu'], '\\[', function () {
117-
// Assuming yy.syntax.square === 'string'. OPEN_ARRAY option not handled
118-
$this->rewind(strlen($this->yytext));
119-
// escaped literal
120-
$this->pushState('escl');
121-
return null;
122-
}),
123-
new Rule(['mu'], ']', fn() => self::T_CLOSE_ARRAY),
124-
125116
new Rule(['mu'], '{{{{', fn() => self::T_OPEN_RAW_BLOCK),
126117
new Rule(['mu'], '}}}}', function () {
127118
$this->popState();
@@ -193,9 +184,8 @@ public function __construct()
193184

194185
new Rule(['mu'], $ID, fn() => self::T_ID),
195186

196-
new Rule(['escl'], '\\[(\\\\\\]|[^\\]])*\\]', function () {
187+
new Rule(['mu'], '\\[(\\\\\\]|[^\\]])*\\]', function () {
197188
$this->replace('/\\\\([\\\\\\]])/', '$1');
198-
$this->popState();
199189
return self::T_ID;
200190
}),
201191

0 commit comments

Comments
 (0)