@text on a grammar: its Bytes input is checked once and cut at text positions; yaml, json and toml are marked (ADR-grammar-input-v1 D14)Open and answer this issue on GitHub.
ready, yaml · opened 2026-11-28 · updated 2026-11-28 · 0 comments
Part of #1548 Found while #1934
ADR-grammar-input-v1 D14 (owner, 2026-11-28, #1934): a grammar marked @text describes a format that is text throughout. Over a Bytes input its entry checks the whole input as UTF-8 once before the parse, with D3’s error at the first bad byte. From there it parses the input as text: here and span(p) are text::Pos and text::Match (ADR-374 D7), and an element that yields text cuts at those positions with no check of its own (ADR-374 D8). Every other grammar keeps D2.
Today the yaml facade reads Bytes, so every scalar, key and tag is checked again where it becomes text. That is core::str::from_utf8 under grammar::covered_bytes and the parse_*_inner actions emit_grammar.nika writes over input bytes: 2.94 % of the yaml benchmark’s instructions on large (callgrind, checks off). Part 1 of the yaml goal (“text without a second UTF-8 check”).
@text on a grammar declaration, parsed and checked. @text on anything but a grammar is refused where it stands, with a code from the supervisor’s block. Part III’s code table names it.Bytes of a @text grammar checks the input once, vectorised (the checked-text crate’s check, as String construction uses), and then emits the grammar’s text copy over that input. No covered_bytes check runs per cut. An invalid byte still fails with invalid UTF-8 at byte N: 0xXX at its own offset.@stream entry over a String uses winnow-grammar’s parse_<rule>_str_each rather than copying to Vec<u8> and _slice_each. This closes the _str_each issue (#2716).@text on the grammars of packages/yaml, packages/json and the toml grammar.tests/compiler/tests/:
@text grammar over Bytes with valid input, whose output equals the same grammar over String;@text on a function, refused with its code.The stream part (one check per stream buffer, a cut sequence checked whole in the next buffer) is built with the stream buffers of ADR-stream-buffers-v1 (#2852, #2853), not here.
The yaml benchmark on large (callgrind) shows no from_utf8 under covered_bytes or the emitted actions, and its instruction count before and after is in the commit message. The tests of item 5 are green, and packages/yaml, json and toml pass their tests.