fix(parser): parse a document that ends with blank lines only #212

Merged
abiwab merged 2 commits from fix/parser-blank-source into main 2026-11-21 21:23:55 +01:00
Owner

Closes #199.

Recipe = Frontmatter? UseBlock? Content? accepted no blank line with nothing after it, so getAST("\n") threw. Since formatGram("") returns "\n", a new empty .gram file showed a syntax error after its first save. A frontmatter or @use lines followed by a blank line and nothing else failed the same way.

  • Grammar: Recipe = Frontmatter? UseBlock? Content? nl* (the semantic action takes and ignores the extra argument).
  • Parser tests for the three cases and for steps kept before trailing blank lines.
  • Conformance: new case 055-blank-lines-only (frontmatter + blank lines → empty recipe), so the Rust port inherits it.
  • Fuzz: the #199 entry leaves the ratchet; fuzz/regressions/199-*.gram holds the empty file and a frontmatter followed by a blank line.

All package tests, conformance (135 + 24) and lint pass. bun run fuzz --iterations 50000 --seed 2111373929 reports one new signature ($.registry.ingredients, @e{%1.0}), which is present on main too and is unrelated: the formatter trims a zero inside what the parser reads as a unit text. It was masked by a #197 entry; to be filed as its own issue.

Closes #199. `Recipe = Frontmatter? UseBlock? Content?` accepted no blank line with nothing after it, so `getAST("\n")` threw. Since `formatGram("")` returns `"\n"`, a new empty `.gram` file showed a syntax error after its first save. A frontmatter or `@use` lines followed by a blank line and nothing else failed the same way. - Grammar: `Recipe = Frontmatter? UseBlock? Content? nl*` (the semantic action takes and ignores the extra argument). - Parser tests for the three cases and for steps kept before trailing blank lines. - Conformance: new case `055-blank-lines-only` (frontmatter + blank lines → empty recipe), so the Rust port inherits it. - Fuzz: the #199 entry leaves the ratchet; `fuzz/regressions/199-*.gram` holds the empty file and a frontmatter followed by a blank line. All package tests, conformance (135 + 24) and lint pass. `bun run fuzz --iterations 50000 --seed 2111373929` reports one new signature (`$.registry.ingredients`, `@e{%1.0}`), which is present on main too and is unrelated: the formatter trims a zero inside what the parser reads as a unit text. It was masked by a #197 entry; to be filed as its own issue.
fix(parser): parse a document that ends with blank lines only
Some checks failed
CI / Build & Test (pull_request) Failing after 5m9s
04df74e964
Merge branch 'main' into fix/parser-blank-source
All checks were successful
CI / Build & Test (pull_request) Successful in 4m47s
0f9eaa3c84
abiwab scheduled this pull request to auto merge when all checks succeed 2026-11-21 21:22:49 +01:00
abiwab merged commit 0ea14dfa24 into main 2026-11-21 21:23:55 +01:00
abiwab deleted branch fix/parser-blank-source 2026-11-21 21:23:55 +01:00
Sign in to join this conversation.
No description provided.