Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/parser-javascript/src/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,12 +407,15 @@ export class Lexer {
this.indentStack[this.indentStack.length - 1]!;
break;
// Track parenthesis depth to suppress structural tokens inside
// multi-line call expressions
// multi-line call expressions. Skip when inside a template line —
// parens in template content are literal text and must not suppress
// INDENT/DEDENT emission (unmatched parens would eat the rest of
// the file).
case TokenKind.LPAREN:
this.bracketDepth++;
if (!this.onTemplateLine) this.bracketDepth++;
break;
case TokenKind.RPAREN:
this.bracketDepth--;
if (!this.onTemplateLine) this.bracketDepth--;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haa, I had to do something similar for LLMs producing incorrect JSON.

break;
// Track brace depth inside {!...} template expressions so that nested
// braces (e.g. JSON objects) don't prematurely close the expression.
Expand Down
Binary file not shown.
90 changes: 90 additions & 0 deletions packages/parser-javascript/test/corpus/template_edge_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,93 @@ config:
(id))
colinear_value: (template
(template_content)))))))
================
Template: unmatched open paren in template does not absorb sibling blocks
================
reasoning:
instructions: ->
| Use this topic if the user is asking (for example, questions such as 'Is it down?'
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test with full JSON?

More text here.

actions:
SomeAction: @actions.SomeAction
---
(source_file
(mapping
(mapping_element
key: (key
(id))
block_value: (mapping
(mapping_element
key: (key
(id))
block_value: (procedure
(template
(template_content))))
(mapping_element
key: (key
(id))
block_value: (mapping
(mapping_element
key: (key
(id))
colinear_value: (expression_with_to
expression: (expression
(member_expression
(expression
(atom
(at_id
(id))))
(id)))))))))))
================
Template: full JSON body in procedure does not absorb sibling blocks
================
reasoning:
instructions: ->
| {
| "name": "Example",
| "enabled": true,
| "items": [1, 2, 3],
| "nested": {"key": "value"}
| }

actions:
SomeAction: @actions.SomeAction
---
(source_file
(mapping
(mapping_element
key: (key
(id))
block_value: (mapping
(mapping_element
key: (key
(id))
block_value: (procedure
(template
(template_content))
(template
(template_content))
(template
(template_content))
(template
(template_content))
(template
(template_content))
(template
(template_content))))
(mapping_element
key: (key
(id))
block_value: (mapping
(mapping_element
key: (key
(id))
colinear_value: (expression_with_to
expression: (expression
(member_expression
(expression
(atom
(at_id
(id))))
(id)))))))))))
Loading