# TOML grammar

`TomlLexer.g4` and `TomlParser.g4` are pinned from
[`antlr/grammars-v4`](https://github.com/antlr/grammars-v4/tree/42b1ea521705c126d84331186b221c9819db1058/toml)
at commit `42b1ea521705c126d84331186b221c9819db1058`. The grammar is
licensed under Apache-2.0; its upstream license and source notices are retained.

Local corrections:

- multiline basic strings permit raw single and paired quote characters while
  four- and five-quote terminal runs preserve their data quotes;
- multiline continuations accept spaces and tabs before the newline;
- comments reject TOML-forbidden C0 control characters and DEL while retaining
  horizontal tab;
- arrays accept comments and newlines between values and separators;
- UTC offsets accept TOML's case-insensitive `Z` spelling;
- TOML 1.1 optional seconds, multiline inline tables, and `\e` / `\xHH`
  escapes are accepted.

The smaller `benkonz/TOML-Grammar` candidate generated 309,019 bytes of Rust
with version 0.30.0, versus 436,379 bytes for this grammar. It was not selected
because the repository carries no license and its grammar omits the required
document EOF while rejecting valid lowercase hexadecimal digits,
variable-length octal and binary integers, and space-separated date-times. The
grammars-v4 version is the smallest compared candidate that is both
redistributable and suitable for a strict parser.

The checked-in recognizers under
`crates/antlr-rust-toml-parser/src/generated/` are generated by this project's
own `antlr4-rust-gen` binary. Verify them with:

```text
tools/toml-syntax/update-generated.sh --check
```

Regenerate them with `tools/toml-syntax/update-generated.sh --update`.

The generated parser and value facade accept all 268 valid fixtures from
`toml-lang/toml-test` commit
`9eef1b959e0449d41a31d4e4e0a839faee534b36`.

The baseline generator output is retained because the optional optimization
passes do not reduce this recognizer: reachability pruning leaves the output
unchanged, while fixed-lookahead specialization increases generated Rust source
size.
