Skip to content

actionGrammar: replace GrammarWriter with 2-pass compact-first formatter#1974

Merged
curtisman merged 2 commits intomicrosoft:mainfrom
curtisman:grammarRuleWriter-compact-formatter
Mar 3, 2026
Merged

actionGrammar: replace GrammarWriter with 2-pass compact-first formatter#1974
curtisman merged 2 commits intomicrosoft:mainfrom
curtisman:grammarRuleWriter-compact-formatter

Conversation

@curtisman
Copy link
Member

@curtisman curtisman commented Mar 3, 2026

Summary

  • Refactors GrammarWriter to use an IR-based two-pass layout algorithm (build pass + render pass) that produces compact single-line output when it fits within maxLineLength and gracefully expands to multi-line when it doesn't
  • Introduces IR node types (NewlinePart, ListPart, BlockPart, GroupPart) and rendering helpers (measureParts, renderParts, capture, emitParts, emitList, emitBlock, emitGroup)
  • All five grammar constructs (rule alternatives, -> arrows, objects {}, arrays [], inline expression groups, and expression-sequence wrapping) independently choose flat vs broken form based on actual column position at render time

🤖 Generated with Claude Code

Refactor GrammarWriter to use an IR-based two-pass layout algorithm
(build pass + render pass) that produces compact, single-line output
when it fits within maxLineLength and gracefully expands to multi-line
when it doesn't.

Key changes:
- Add IR node types: NewlinePart, ListPart, BlockPart, GroupPart
- Add measureParts() for flat-length measurement and renderParts() for
  column-tracking render
- Add GrammarWriter helpers: capture(), emitParts(), emitList(),
  emitBlock(), emitGroup()
- Rules, arrows (->), objects, arrays, inline groups, and expression
  sequences all independently choose flat vs broken based on available
  column space
- Add comprehensive layout test suite in grammarRuleWriter.spec.ts
  covering all five formatting rules with exact-limit and round-trip cases

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@curtisman curtisman added this pull request to the merge queue Mar 3, 2026
Merged via the queue into microsoft:main with commit ddc7433 Mar 3, 2026
13 of 15 checks passed
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.

1 participant