This page documents @lanexio/parser, the main entry point package that provides a unified API across all Lanexio Parser grammars: parse, createParser, register, and detectLanguage.
Version: Stable
Module name: parser
Package: @lanexio/parser
Import path: @lanexio/parser
Layer: 6 (Entry)
Runtime: Universal
Module format: ESM
Stability: Stable
Primary use case: Unified parsing API across all grammar packs.
You want a single parse() function that auto-detects the grammar.
You want to register multiple grammars and switch between them by language, file extension, or MIME type.
You want a single import instead of importing each grammar pack individually.
Boundary Description Inputs Uint8Array (source bytes) + ParseOptions (language, grammar)Outputs LexTreeSide effects register() mutates grammarRegistry. grammarRegistry is a shared global.Determinism Yes (same input + same registrations produce same tree) External dependencies @lanexio/parser-core, @lanexio/parser-wasm (optional)Never-throw guarantee No: parse() throws LanexioParseError when auto-detection fails and no grammar is specified. Grammar-specific parse functions within a created parser are never-throw. Security surface None
Install the package.
npm install @lanexio/parser
Import the named export.
import { parse, createParser, register } from ' @lanexio/parser ' ;
Requirement Required Layer Notes @lanexio/parser-coreYes 1 ^1.0.0@lanexio/parser-wasmNo 4 Optional WASM bridge Grammar packages No 2 Must be registered before use
import { parse, register } from ' @lanexio/parser ' ;
import { htmlRegistration } from ' @lanexio/parser-grammar-html ' ;
register (htmlRegistration);
const encoder = new TextEncoder ();
const tree = parse (encoder . encode ( ' <p>Hello</p> ' ) , { language: ' html ' } );
console . log (tree . nodeCount );
// Detects grammar from file extension hints in ParseOptions
const tree = parse (encoder . encode ( ' <p>Hello</p> ' ) , { grammar: htmlGrammar } );
import { createParser } from ' @lanexio/parser ' ;
import { htmlGrammar } from ' @lanexio/parser-grammar-html ' ;
const parser = createParser (htmlGrammar);
const tree = parser . parse (encoder . encode ( ' <p>Hello</p> ' ));
Export Type Description parse(source: Uint8Array, options?: ParseOptions) => LexTreeUnified parse entry point. Throws LanexioParseError on detection failure. createParser(grammar: LanexioParserPureGrammar) => LanexioParserCreate a parser handle bound to a specific grammar. register(registration: GrammarRegistration) => voidRegister a grammar in the unified registry. detectLanguage(source: Uint8Array, hints?: DetectionHints) => DetectionResultAuto-detect the grammar language from source bytes. actionableError(error: LanexioParseError) => stringGenerate a human-readable error message. KNOWN_GRAMMARSreadonly KnownGrammarEntry[]List of pre-registered known grammars. LanexioParserErrorclassParser error base class. LanexioParserErrorCodeconst objectError code constants. LanexioParseErrorclassError thrown when parsing fails (e.g., unknown grammar). grammarRegistryobjectGlobal grammar registry (re-exported from parser-core). LexCursorclassRe-export from parser-core. LexNodeclassRe-export from parser-core. LexToyKindconst objectRe-export from parser-core. LexTreeclassRe-export from parser-core. PROTOCOL_VERSIONnumberRe-export from parser-core. LexEditErrorclassRe-export from parser-core. LexEditErrorCodeconst objectRe-export from parser-core. applyEditfunctionRe-export from parser-core. toyParsefunctionRe-export from parser-core (toy grammar parse). createParseStreamfunctionRe-export from parser-core.
Field Type Required Default Description languagestringNo undefinedLanguage name for grammar lookup (e.g., "html", "markdown"). grammarLanexioParserPureGrammarNo undefinedExplicit grammar descriptor (skips registry lookup).
Property Type Description rootLexNodeRoot node of the parsed tree. nodeCountnumberTotal nodes in the tree. sourceUint8ArrayOriginal parsed bytes.
Type Purpose Notes ParseOptionsOptions for parse() { language?: string; grammar?: LanexioParserPureGrammar }LanexioParserParser handle returned by createParser { parse: (bytes: Uint8Array) => LexTree }DetectionResultResult of language detection Language and confidence DetectionHintsHints for language detection Extension, MIME type KnownGrammarEntryEntry in KNOWN_GRAMMARS Grammar metadata LexRangeByte range Re-export from parser-core LanexioParserPureGrammarGrammar descriptor Re-export from parser-core LexParseStreamStreaming parse interface Re-export from parser-core GrammarRegistrationGrammar registration Re-export from parser-core LexEditEdit descriptor Re-export from parser-core
Register grammars before calling parse(). The registry supports lookup by language name, file extension, and MIME type.
KNOWN_GRAMMARS lists the pre-registered grammar metadata. This is a read-only list for reference.
No direct accessibility surface. The main entry point dispatches to grammar-specific parsers. Consuming code is responsible for semantic rendering.
Concern Status Generated output semantics Not applicable (dispatch layer) ARIA attributes in serialized output Not applicable Semantic element round-trip Not applicable
The unified parse() function relies on auto-detection. Grammar-specific parse functions within created parsers are never-throw.
When auto-detection fails and no grammar is specified, parse() throws LanexioParseError.
Threat Mitigation Status Malformed input byte sequence Delegated to grammar-specific parsers (all grammar parsers are never-throw) Implemented Grammar detection failure Throws LanexioParseError with clear message Implemented
Package Relationship Layer Notes @lanexio/parser-coreRequires 1 Core tree and protocol. Re-exported. @lanexio/parser-grammar-htmlDev dependency 2 Optional grammar. @lanexio/parser-grammar-markdownDev dependency 2 Optional grammar. @lanexio/parser-wasmRequires 4 WASM bridge support.
Version Date Status Notable changes 1.0.02026-05-29Current Initial stable release. Apache-2.0.
Quick Start Parse HTML and Markdown in five lines each. Flat AST How the 16-byte node layout works.