fix(format): glue a composite separator surrounded by Unicode blanks #270

Merged
abiwab merged 1 commit from fix/format-composite-unicode-spaces into main 2026-11-26 13:22:37 +01:00
Owner

Closes #269.

Kitchen flags SPACED_COMPOSITE whatever blank surrounds the <, but the formatter's repair (rule 6) only glued a space or a tab: with a no-break space or another Unicode blank, gram format left in place a composite that Gram warns is broken. The fuzz harness reported it as format-preserves-meaning | compilation differs after formatting at $.warnings[].data (rule 6 did not fire, and rule 1 lowercased the parent quoted by data.suggestion).

  • packages/format/src/index.ts: rule 6 takes every Unicode horizontal blank ([^\S\r\n]), never \s, since it runs before the parser finds the steps and a line break taken there would merge two steps or a comment. The comment explains why this repair, unlike trimBlanks (#200), covers those blanks.
  • fuzz/src/normalize.ts: a SPACED_COMPOSITE's data.suggestion is lowercased like parent (rule 1). Unreachable today (rule 6 now glues every < kitchen flags, so I6 skips the input): a guard should a flagged blank ever escape rule 6 again.
  • Tests: U+00A0 on one or both sides, U+3000, one pass and idempotent; no line break is ever taken. Minimized input in fuzz/regressions/269-nbsp-around-composite-separator.gram.
  • Changeset: patch on @gram-lang/format.

A composite cut by a line break (@a{1} <\n@b{2}) is not affected: the parser splits the text at the line break, so kitchen never flags it.

Checks: build, typecheck, bun test (3890 pass), conformance, bun run fuzz --iterations 50000 (0 signature).

Once merged: merge main into dev/1.6.

Closes #269. Kitchen flags `SPACED_COMPOSITE` whatever blank surrounds the `<`, but the formatter's repair (rule 6) only glued a space or a tab: with a no-break space or another Unicode blank, `gram format` left in place a composite that Gram warns is broken. The fuzz harness reported it as `format-preserves-meaning | compilation differs after formatting at $.warnings[].data` (rule 6 did not fire, and rule 1 lowercased the parent quoted by `data.suggestion`). - `packages/format/src/index.ts`: rule 6 takes every Unicode horizontal blank (`[^\S\r\n]`), never `\s`, since it runs before the parser finds the steps and a line break taken there would merge two steps or a comment. The comment explains why this repair, unlike `trimBlanks` (#200), covers those blanks. - `fuzz/src/normalize.ts`: a `SPACED_COMPOSITE`'s `data.suggestion` is lowercased like `parent` (rule 1). Unreachable today (rule 6 now glues every `<` kitchen flags, so I6 skips the input): a guard should a flagged blank ever escape rule 6 again. - Tests: U+00A0 on one or both sides, U+3000, one pass and idempotent; no line break is ever taken. Minimized input in `fuzz/regressions/269-nbsp-around-composite-separator.gram`. - Changeset: `patch` on `@gram-lang/format`. A composite cut by a line break (`@a{1} <\n@b{2}`) is not affected: the parser splits the text at the line break, so kitchen never flags it. Checks: build, typecheck, `bun test` (3890 pass), conformance, `bun run fuzz --iterations 50000` (0 signature). Once merged: merge `main` into `dev/1.6`.
fix(format): glue a composite separator surrounded by Unicode blanks
All checks were successful
CI / Build & Test (pull_request) Successful in 5m12s
457f1c8ca3
abiwab scheduled this pull request to auto merge when all checks succeed 2026-11-26 13:19:41 +01:00
abiwab merged commit d8f1a67f98 into main 2026-11-26 13:22:37 +01:00
abiwab deleted branch fix/format-composite-unicode-spaces 2026-11-26 13:22:38 +01:00
Sign in to join this conversation.
No description provided.