fix(parser): report leftover text in section headers instead of dropping the section #135

Merged
abiwab merged 1 commit from fix/section-anchor-multiword-intermediate into main 2026-11-13 14:32:47 +01:00
Owner

Problem

Any text left after a section header's ~{...} anchor or ->&name intermediate made the header rule fail, so the whole ## line fell back to a plain step:

  • ## Garniture rhubarbe ~{-10h} ->&rhubarbe laquée (multi-word intermediate without {}) reported Invalid quantity '{-10h}' for timer, blaming the anchor instead of the missing braces.
  • Without an anchor, the same header silently became a step and the section vanished.
  • A header on the last line of a file, with no final newline, also became a step.

Fix

  • New header_trailing branch in grammar.ohm, matched only to raise a readable GramParseError:
    • leftover word after a bare ->&name -> asks for braces (->&rhubarbe laquée{}), offset on the ->&;
    • any other leftover text -> Unexpected text '...' in a section header.
  • header_ok accepts (nl+ | end), so a header at end of file is still a header.
  • No syntax change: multi-word names still require {} everywhere.

Tests

  • 9 parser tests in grammar-edge-cases.test.ts.
  • Conformance case err-014-multiword-intermediate-in-header.
  • Full suite (2425), conformance, lint and typecheck pass.
  • Patch changeset for @gram-lang/parser.
## Problem Any text left after a section header's `~{...}` anchor or `->&name` intermediate made the `header` rule fail, so the whole `##` line fell back to a plain step: - `## Garniture rhubarbe ~{-10h} ->&rhubarbe laquée` (multi-word intermediate without `{}`) reported `Invalid quantity '{-10h}' for timer`, blaming the anchor instead of the missing braces. - Without an anchor, the same header silently became a step and the section vanished. - A header on the last line of a file, with no final newline, also became a step. ## Fix - New `header_trailing` branch in `grammar.ohm`, matched only to raise a readable `GramParseError`: - leftover word after a bare `->&name` -> asks for braces (`->&rhubarbe laquée{}`), offset on the `->&`; - any other leftover text -> `Unexpected text '...' in a section header`. - `header_ok` accepts `(nl+ | end)`, so a header at end of file is still a header. - No syntax change: multi-word names still require `{}` everywhere. ## Tests - 9 parser tests in `grammar-edge-cases.test.ts`. - Conformance case `err-014-multiword-intermediate-in-header`. - Full suite (2425), conformance, lint and typecheck pass. - Patch changeset for `@gram-lang/parser`.
fix(parser): report leftover text in section headers instead of dropping the section
All checks were successful
CI / Build & Test (pull_request) Successful in 3m48s
4608f96823
abiwab scheduled this pull request to auto merge when all checks succeed 2026-11-13 14:30:14 +01:00
abiwab merged commit f4d8f9a353 into main 2026-11-13 14:32:47 +01:00
abiwab deleted branch fix/section-anchor-multiword-intermediate 2026-11-13 14:32:47 +01:00
Sign in to join this conversation.
No description provided.