Skip to content

@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.
  • 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.
BoundaryDescription
InputsUint8Array (source bytes) + optional ParseTomlOptions
OutputsLexTree (flat AST)
Side effectsNone
DeterminismYes
External dependencies@lanexio/parser-core
Never-throw guaranteeYes
Security surfaceNone (parse only, no output generation)
  1. Install the package.

    Terminal window
    pnpm add @lanexio/parser-grammar-toml
  2. Import the named export.

    import { parseToml } from '@lanexio/parser-grammar-toml';
RequirementRequiredLayerNotes
@lanexio/parser-coreYes1^1.0.0
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);
import { parseToml10 } from '@lanexio/parser-grammar-toml';
const encoder = new TextEncoder();
const tree = parseToml10(encoder.encode('key = "value"'));
import { parseToml } from '@lanexio/parser-grammar-toml';
const encoder = new TextEncoder();
const tree = parseToml(encoder.encode('key = "value"'), { version: '1.1' });
ExportTypeDescription
parseToml(bytes: Uint8Array, options?: ParseTomlOptions) => LexTreeParse TOML (defaults to v1.1.0). Never throws.
parseToml10(bytes: Uint8Array) => LexTreeParse TOML v1.0.0 (strict).
parseToml11(bytes: Uint8Array) => LexTreeParse TOML v1.1.0.
TomlKindconst objectNumeric kind IDs for all TOML node types.
TomlFieldconst objectNumeric field IDs for TOML value slots.
TOML_FIELD_NAMES_BY_IDreadonly string[]Field name lookup by numeric field ID.
TOML_KIND_NAMES_BY_IDreadonly Record<number, string>Kind-name lookup by numeric ID.
tomlGrammarLanexioParserPureGrammarGrammar descriptor for use with parser-pure.
tomlRegistrationGrammarRegistrationRegistration for the unified grammar registry.
tomlReuseOracleReuseOracleIncremental reuse oracle.
FieldTypeRequiredDefaultDescription
versionTomlVersionNo'1.1'TOML version dialect: '1.0' or '1.1'.
PropertyTypeDescription
rootLexNodeRoot node of the document.
nodeCountnumberTotal nodes in the tree.
sourceUint8ArrayOriginal parsed bytes.
TypePurposeNotes
ParseTomlOptionsOptions for parseToml{ version?: TomlVersion }
TomlVersionTOML version string'1.0' | '1.1'
TomlKindTypeUnion of all TomlKind valuesType-safe kind reference
TomlFieldTypeUnion of all TomlField valuesType-safe field reference

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.

  • No direct accessibility surface. The TOML parser produces flat AST data structures.
ConcernStatus
Generated output semanticsNot applicable (data format)
ARIA attributes in serialized outputNot applicable
Semantic element round-tripNot applicable
  • parseToml never throws on any byte sequence.
ThreatMitigationStatus
Malformed input byte sequencePanic-free guarantee: all inputs accepted, errors produce LexError AST nodesImplemented
PackageRelationshipLayerNotes
@lanexio/parser-coreRequires1Provides LexTree, LexNode, LexCursor
@lanexio/parserConsumes6Unified entry point
VersionDateStatusNotable changes
1.0.02026-05-29CurrentInitial stable release. Apache-2.0.
  • None.