Parser: a colon then blanks at the end of a line is read as an empty alias #281

Closed
opened 2026-11-26 18:07:44 +01:00 by abiwab · 0 comments
Owner

Found by the fuzz (format-preserves-meaning, seed 1515514652, index 5209 on dev/1.6), present on main and dev/1.6.

alias = ":" refName in packages/parser/grammar.ohm accepts an alias made of blanks only. After a bare ingredient or cookware at the end of a line, the blanks become an empty alias and the colon vanishes from the step:

  • Add @salt: + line break → ["Add ", salt, " ", "ok."] (colon lost)
  • Add @salt: + line break → ["Add ", salt, ":", " ", "ok."] (colon kept)

gram format strips the trailing blank, so formatting changes the compiled recipe. Minimal input from the fuzz:

---
lan@guage: \r
fr
---

Reposer ~_{2 jours}.

Fix: blanks alone up to the end of the line (LF, CRLF, lone CR) or of the file are no alias; the colon stays text.

Follow-ups:

  • tree-sitter-gram has the same behavior (src/scanner.c, ALIAS_COLON emitted as soon as ref_name_end > 0, blanks included): only the highlighting of the : is affected, to sync later.
  • Not in scope: Add @salt: a pinch. still reads "a pinch." as the alias of a bare ingredient (the alias swallows the rest of the line); changing that is a syntax change (RFC).
Found by the fuzz (`format-preserves-meaning`, seed 1515514652, index 5209 on `dev/1.6`), present on `main` and `dev/1.6`. `alias = ":" refName` in `packages/parser/grammar.ohm` accepts an alias made of blanks only. After a bare ingredient or cookware at the end of a line, the blanks become an empty alias and the colon vanishes from the step: - `Add @salt: ` + line break → `["Add ", salt, " ", "ok."]` (colon lost) - `Add @salt:` + line break → `["Add ", salt, ":", " ", "ok."]` (colon kept) `gram format` strips the trailing blank, so formatting changes the compiled recipe. Minimal input from the fuzz: ``` --- lan@guage: \r fr --- Reposer ~_{2 jours}. ``` Fix: blanks alone up to the end of the line (LF, CRLF, lone CR) or of the file are no alias; the colon stays text. Follow-ups: - `tree-sitter-gram` has the same behavior (`src/scanner.c`, `ALIAS_COLON` emitted as soon as `ref_name_end > 0`, blanks included): only the highlighting of the `:` is affected, to sync later. - Not in scope: `Add @salt: a pinch.` still reads "a pinch." as the alias of a bare ingredient (the alias swallows the rest of the line); changing that is a syntax change (RFC).
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#281
No description provided.