Skip to content

Commit b98c087

Browse files
authored
fix(parser-js): don't track bracket depth inside template content lines (#10)
* fix(parser-js): don't track bracket depth inside template content lines Unmatched parentheses in template text (e.g. "(for example, questions such as 'Is it down?'") were incrementing bracketDepth, which suppressed INDENT/DEDENT emission and caused the template to absorb all subsequent sibling blocks. Guard bracketDepth changes with !onTemplateLine — parens in template content are literal text, not structural delimiters. * add json test
1 parent 38221b0 commit b98c087

3 files changed

Lines changed: 96 additions & 3 deletions

File tree

packages/parser-javascript/src/lexer.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,12 +407,15 @@ export class Lexer {
407407
this.indentStack[this.indentStack.length - 1]!;
408408
break;
409409
// Track parenthesis depth to suppress structural tokens inside
410-
// multi-line call expressions
410+
// multi-line call expressions. Skip when inside a template line —
411+
// parens in template content are literal text and must not suppress
412+
// INDENT/DEDENT emission (unmatched parens would eat the rest of
413+
// the file).
411414
case TokenKind.LPAREN:
412-
this.bracketDepth++;
415+
if (!this.onTemplateLine) this.bracketDepth++;
413416
break;
414417
case TokenKind.RPAREN:
415-
this.bracketDepth--;
418+
if (!this.onTemplateLine) this.bracketDepth--;
416419
break;
417420
// Track brace depth inside {!...} template expressions so that nested
418421
// braces (e.g. JSON objects) don't prematurely close the expression.
Binary file not shown.

packages/parser-javascript/test/corpus/template_edge_cases.txt

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,93 @@ config:
285285
(id))
286286
colinear_value: (template
287287
(template_content)))))))
288+
================
289+
Template: unmatched open paren in template does not absorb sibling blocks
290+
================
291+
reasoning:
292+
instructions: ->
293+
| Use this topic if the user is asking (for example, questions such as 'Is it down?'
294+
More text here.
295+
296+
actions:
297+
SomeAction: @actions.SomeAction
298+
---
299+
(source_file
300+
(mapping
301+
(mapping_element
302+
key: (key
303+
(id))
304+
block_value: (mapping
305+
(mapping_element
306+
key: (key
307+
(id))
308+
block_value: (procedure
309+
(template
310+
(template_content))))
311+
(mapping_element
312+
key: (key
313+
(id))
314+
block_value: (mapping
315+
(mapping_element
316+
key: (key
317+
(id))
318+
colinear_value: (expression_with_to
319+
expression: (expression
320+
(member_expression
321+
(expression
322+
(atom
323+
(at_id
324+
(id))))
325+
(id)))))))))))
326+
================
327+
Template: full JSON body in procedure does not absorb sibling blocks
328+
================
329+
reasoning:
330+
instructions: ->
331+
| {
332+
| "name": "Example",
333+
| "enabled": true,
334+
| "items": [1, 2, 3],
335+
| "nested": {"key": "value"}
336+
| }
337+
338+
actions:
339+
SomeAction: @actions.SomeAction
340+
---
341+
(source_file
342+
(mapping
343+
(mapping_element
344+
key: (key
345+
(id))
346+
block_value: (mapping
347+
(mapping_element
348+
key: (key
349+
(id))
350+
block_value: (procedure
351+
(template
352+
(template_content))
353+
(template
354+
(template_content))
355+
(template
356+
(template_content))
357+
(template
358+
(template_content))
359+
(template
360+
(template_content))
361+
(template
362+
(template_content))))
363+
(mapping_element
364+
key: (key
365+
(id))
366+
block_value: (mapping
367+
(mapping_element
368+
key: (key
369+
(id))
370+
colinear_value: (expression_with_to
371+
expression: (expression
372+
(member_expression
373+
(expression
374+
(atom
375+
(at_id
376+
(id))))
377+
(id)))))))))))

0 commit comments

Comments
 (0)