Format: the composite repair rewrites section headers #291

Closed
opened 2026-11-26 21:42:33 +01:00 by abiwab · 0 comments
Owner

Found by the fuzz (format-idempotent … second pass reported changes on an unchanged output, seed 1627016615, index 10547 on dev/1.6), present on main and dev/1.6.

Rule 6 of the formatter (glue a spaced composite, @a{1} < @b{2} → @a{1}<@b{2}) runs on every line, section headers included. A ## header holds no element: its title is plain text the compiler keeps as written. Two consequences:

  • ## <@s: rule 6 takes the blank after ##, rule 8 puts it back. The text never changes, but every pass reports 2 changes (compositeSeparatorSpacing, headerSpacing), so gram format --check would fail forever on that file.
  • ## Zest <@lemon ~{-1 h} becomes ## Zest<@lemon ~{-1 h}, and ## Mix @a{1} < @b{2} becomes ## Mix @a{1}<@b{2}: the compiled section title changes.

Fix: rule 6 skips header lines (## not followed by #, as rule 8 reads them).

Found by the fuzz (`format-idempotent … second pass reported changes on an unchanged output`, seed 1627016615, index 10547 on `dev/1.6`), present on `main` and `dev/1.6`. Rule 6 of the formatter (glue a spaced composite, `@a{1} < @b{2}` → `@a{1}<@b{2}`) runs on every line, section headers included. A `## ` header holds no element: its title is plain text the compiler keeps as written. Two consequences: - `## <@s`: rule 6 takes the blank after `##`, rule 8 puts it back. The text never changes, but every pass reports 2 changes (`compositeSeparatorSpacing`, `headerSpacing`), so `gram format --check` would fail forever on that file. - `## Zest <@lemon ~{-1 h}` becomes `## Zest<@lemon ~{-1 h}`, and `## Mix @a{1} < @b{2}` becomes `## Mix @a{1}<@b{2}`: the compiled section title changes. Fix: rule 6 skips header lines (`##` not followed by `#`, as rule 8 reads them).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gram-lang/gram#291
No description provided.