@lanexio/parser-grammar-toml
This page documents @lanexio/parser-grammar-toml, the TOML grammar package supporting both TOML v1.0.0 and v1.1.0 with version selection.
- Version: Stable
- Module name:
parser-grammar-toml - Package:
@lanexio/parser-grammar-toml - Import path:
@lanexio/parser-grammar-toml - Layer: 2 (Grammar)
- Runtime: Universal
- Module format: ESM
- Stability: Stable
- Primary use case: Parse TOML configuration files into a flat AST.
Layer contract
Section titled “Layer contract”When to use this module
Section titled “When to use this module”- You need to parse TOML configuration files (v1.0.0 or v1.1.0) into a traversable AST.
- You need strict adherence to a specific TOML version.
- You need incremental reuse for repeated parsing.
Module boundary
Section titled “Module boundary”| Boundary | Description |
|---|---|
| Inputs | Uint8Array (source bytes) + optional ParseTomlOptions |
| Outputs | LexTree (flat AST) |
| Side effects | None |
| Determinism | Yes |
| External dependencies | @lanexio/parser-core |
| Never-throw guarantee | Yes |
| Security surface | None (parse only, no output generation) |
Installation
Section titled “Installation”-
Install the package.
Terminal window pnpm add @lanexio/parser-grammar-tomlTerminal window npm install @lanexio/parser-grammar-tomlTerminal window yarn add @lanexio/parser-grammar-toml -
Import the named export.
import { parseToml } from '@lanexio/parser-grammar-toml';
Peer dependencies
Section titled “Peer dependencies”| Requirement | Required | Layer | Notes |
|---|---|---|---|
@lanexio/parser-core | Yes | 1 | ^1.0.0 |
Basic Usage
Section titled “Basic Usage”import { parseToml } from '@lanexio/parser-grammar-toml';
const encoder = new TextEncoder();const bytes = encoder.encode('[server]\nhost = "localhost"\nport = 8080');
const tree = parseToml(bytes);
console.log(tree.nodeCount);Strict TOML 1.0.0
Section titled “Strict TOML 1.0.0”import { parseToml10 } from '@lanexio/parser-grammar-toml';
const encoder = new TextEncoder();const tree = parseToml10(encoder.encode('key = "value"'));Explicit TOML 1.1.0
Section titled “Explicit TOML 1.1.0”import { parseToml } from '@lanexio/parser-grammar-toml';
const encoder = new TextEncoder();const tree = parseToml(encoder.encode('key = "value"'), { version: '1.1' });Exports
Section titled “Exports”| Export | Type | Description |
|---|---|---|
parseToml | (bytes: Uint8Array, options?: ParseTomlOptions) => LexTree | Parse TOML (defaults to v1.1.0). Never throws. |
parseToml10 | (bytes: Uint8Array) => LexTree | Parse TOML v1.0.0 (strict). |
parseToml11 | (bytes: Uint8Array) => LexTree | Parse TOML v1.1.0. |
TomlKind | const object | Numeric kind IDs for all TOML node types. |
TomlField | const object | Numeric field IDs for TOML value slots. |
TOML_FIELD_NAMES_BY_ID | readonly string[] | Field name lookup by numeric field ID. |
TOML_KIND_NAMES_BY_ID | readonly Record<number, string> | Kind-name lookup by numeric ID. |
tomlGrammar | LanexioParserPureGrammar | Grammar descriptor for use with parser-pure. |
tomlRegistration | GrammarRegistration | Registration for the unified grammar registry. |
tomlReuseOracle | ReuseOracle | Incremental reuse oracle. |
Options
Section titled “Options”ParseTomlOptions
Section titled “ParseTomlOptions”| Field | Type | Required | Default | Description |
|---|---|---|---|---|
version | TomlVersion | No | '1.1' | TOML version dialect: '1.0' or '1.1'. |
Return shape
Section titled “Return shape”| Property | Type | Description |
|---|---|---|
root | LexNode | Root node of the document. |
nodeCount | number | Total nodes in the tree. |
source | Uint8Array | Original parsed bytes. |
Exported types
Section titled “Exported types”| Type | Purpose | Notes |
|---|---|---|
ParseTomlOptions | Options for parseToml | { version?: TomlVersion } |
TomlVersion | TOML version string | '1.0' | '1.1' |
TomlKindType | Union of all TomlKind values | Type-safe kind reference |
TomlFieldType | Union of all TomlField values | Type-safe field reference |
Configuration and Extension
Section titled “Configuration and Extension”Version selection
Section titled “Version selection”parseToml defaults to TOML 1.1.0. Use parseToml10(bytes) for strict TOML 1.0.0. Use parseToml(bytes, { version: '1.0' }) for explicit version selection.
Accessibility
Section titled “Accessibility”Accessibility requirements
Section titled “Accessibility requirements”- No direct accessibility surface. The TOML parser produces flat AST data structures.
Accessibility checklist
Section titled “Accessibility checklist”| Concern | Status |
|---|---|
| Generated output semantics | Not applicable (data format) |
| ARIA attributes in serialized output | Not applicable |
| Semantic element round-trip | Not applicable |
Security
Section titled “Security”Security considerations
Section titled “Security considerations”parseTomlnever throws on any byte sequence.
| Threat | Mitigation | Status |
|---|---|---|
| Malformed input byte sequence | Panic-free guarantee: all inputs accepted, errors produce LexError AST nodes | Implemented |
Companion packages
Section titled “Companion packages”| Package | Relationship | Layer | Notes |
|---|---|---|---|
@lanexio/parser-core | Requires | 1 | Provides LexTree, LexNode, LexCursor |
@lanexio/parser | Consumes | 6 | Unified entry point |
Changelog
Section titled “Changelog”| Version | Date | Status | Notable changes |
|---|---|---|---|
1.0.0 | 2026-05-29 | Current | Initial stable release. Apache-2.0. |
Migration notes
Section titled “Migration notes”- None.
Related Content
Section titled “Related Content” Flat AST How the 16-byte node layout works.
Stability Guarantees Never-throw, panic-free, and 3-token recovery.