Skip to content

fix: batch_design accepts multi-line ops and # / // comments (#228) - #229

Merged
vicmaster merged 1 commit into
masterfrom
fix-batch-design-multiline-ops
Oct 23, 2026
Merged

vicmaster merged 1 commit into
masterfrom
fix-batch-design-multiline-ops

Conversation

@vicmaster

Copy link
Copy Markdown
Owner

Fixes #228.

Problem

batch_design split its operations string on every newline. The README formats its chart and donut examples across several lines, so pasting them as written failed with Unmatched parentheses. The intro example uses # comment lines, and each of those failed with Invalid operation. The line-chart example's trailing // actual comments would have been parsed as part of the arguments.

Change

  • A new splitOperations scanner in src/operations.ts replaces the split('\n'). A newline ends an op only when every (, { and [ is closed. Newlines inside an open op become spaces, so the existing single-line parsing keeps working unchanged.
  • Between ops, a line whose first character is # is a comment. Outside a quoted string, // comments out the rest of its line, at any depth.
  • Quoted strings are skipped, so "#RRGGBB" fills, https:// URLs, and brackets inside content are left alone.
  • extractArgs and parseJsonArg now skip quoted strings too. Before, a single-line op whose content held an unbalanced paren, such as "Total (incl. tax", failed for the same reason.
  • An op with unbalanced brackets still fails with the existing Unmatched parentheses error. Execution still stops at the first error.

Docs

The new contract is stated in the README batch_design section, the batch_design tool docstring and its operations parameter description, a new gotcha in the server instructions, and docs/GUIDELINES.md. All of them note that a # line inside an open bracket is not a comment, and that // is the comment to use there.

Tests

test-ops-parser.ts adds seven cases:

  • the README donut shape
  • # comment lines between ops, including one with an apostrophe
  • trailing // comments inside a multi-line op
  • # and // inside strings
  • unbalanced brackets inside a string
  • single-line ops still parsing one per line
  • an unbalanced op still raising Unmatched parentheses

The fast suite passes 72/72 and test-discoverability.ts passes 117/117.

The operations parser split on every newline, so the README's own
multi-line chart/donut examples failed with 'Unmatched parentheses' and
its '# comment' lines failed with 'Invalid operation'. A scanner now ends
an op at a newline only at bracket depth 0, skips '#' comment lines
between ops and '//' trailing comments, and ignores all of that inside
quoted strings. The arg and brace matchers are quote-aware too, so a
stray paren inside a content string no longer breaks an op.
@vicmaster
vicmaster merged commit 0f3b5c3 into master Oct 23, 2026
3 checks passed
@vicmaster
vicmaster deleted the fix-batch-design-multiline-ops branch October 23, 2026 19:06
@vicmaster vicmaster mentioned this pull request Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

batch_design parser rejects multi-line ops and # comment lines — the README's own examples fail as pasted

1 participant