Skip to content

@lanexio/parser-wasm

This page documents @lanexio/parser-wasm, the WASM bridge package that delegates to WASM-parsed grammar implementations. At v1.0, the WASM bridge is backed by pure TypeScript — WASM acceleration is a future optimization target.

  • Version: Stable
  • Module name: parser-wasm
  • Package: @lanexio/parser-wasm
  • Import path: @lanexio/parser-wasm
  • Layer: 4 (Bridge)
  • Runtime: Universal (requires WASM runtime support)
  • Module format: ESM
  • Stability: Stable
  • Primary use case: WASM-backed parser bridge for HTML and Markdown.
  • You want to use the WASM bridge interface for grammar parsing.
  • You need to load bundled WASM bytes for HTML or toy grammar.
  • You are building a custom integration that uses the WASM bridge pattern.
BoundaryDescription
InputsUint8Array (source bytes)
OutputsLexTree
Side effectsWASM module instantiation on first use
DeterminismYes
External dependencies@lanexio/parser-core, @lanexio/parser-grammar-html, @lanexio/parser-grammar-markdown
Never-throw guaranteeYes for parse functions. WASM instantiation may throw WasmLoaderError.
Security surfaceNone (delegates to grammar parsers)
  1. Install the package.

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

    import { createHtmlWasmBridgeParser } from '@lanexio/parser-wasm';
RequirementRequiredLayerNotes
@lanexio/parser-coreYes1^1.0.0
@lanexio/parser-grammar-htmlYes2^1.0.0
@lanexio/parser-grammar-markdownYes2^1.0.0
import { createHtmlWasmBridgeParser, parseHtml } from '@lanexio/parser-wasm';
const encoder = new TextEncoder();
const tree = parseHtml(encoder.encode('<p>Hello</p>'));
console.log(tree.nodeCount);
import { createHtmlWasmBridgeParser } from '@lanexio/parser-wasm';
const parser = createHtmlWasmBridgeParser();
const tree = parser.parse(encoder.encode('<p>Hello</p>'));
ExportTypeDescription
createHtmlWasmBridgeParser() => WasmBridgeParserCreate a WASM-backed HTML parser bridge.
createMarkdownWasmBridgeParser() => WasmBridgeParserCreate a WASM-backed Markdown parser bridge (GFM enabled).
parseHtml(bytes: Uint8Array) => LexTreeParse HTML via WASM bridge.
parseMarkdown(bytes: Uint8Array) => LexTreeParse Markdown via WASM bridge.
createToyWasmBridgeParser() => WasmBridgeParserCreate a WASM-backed toy grammar parser bridge.
loadBundledHtmlWasmBytes() => Promise<Uint8Array>Load bundled HTML WASM bytes.
loadBundledToyWasmBytes() => Promise<Uint8Array>Load bundled toy WASM bytes.
instantiateToyWasm(bytes: Uint8Array) => ToyWasmParserExportsInstantiate toy WASM module from bytes.
createReferenceWasmBridgeParser() => WasmBridgeParserCreate a reference WASM bridge parser.
WasmLoaderErrorclassError thrown when WASM instantiation fails.
WasmLoaderErrorCodeconst objectError code constants for WASM loader failures.
WasmFallbackErrorclassError thrown when WASM fallback is unavailable.
isWasmParserExports(exports: unknown) => exports is WasmParserExportsType guard for WASM parser exports.
isToyWasmParserExports(exports: unknown) => exports is ToyWasmParserExportsType guard for toy WASM parser exports.
TOY_GRAMMAR_NAMEstringName of the toy grammar.
defineLanexioParserGrammar(name: string, source: LanexioParserGrammarSource) => LanexioParserGrammarDefine a WASM grammar descriptor.
resolveGrammarSource(source: LanexioParserGrammarSource) => Uint8Array | nullResolve a grammar source to bytes.
toyGrammarLanexioParserGrammarToy grammar descriptor.

No options. All WASM bridge functions accept only Uint8Array.

TypePurposeNotes
WasmBridgeParserWASM bridge parser shape{ runtime: string; parse: (bytes: Uint8Array) => LexTree }
WasmParserExportsWASM parser exports interfaceInternal
ToyWasmParserExportsToy WASM parser exports interfaceInternal
LanexioParserGrammarWASM grammar descriptorUsed for defining WASM grammars
LanexioParserGrammarSourceGrammar source (bytes, path, or URL)Used for WASM grammar loading
LanexioParserGrammarSourceLikeGrammar source-likeRelaxed input type
WasmLoaderErrorCodeError code type for WASM loaderUnion of error codes

At v1.0, the WASM bridge is backed by pure TypeScript. WASM acceleration is a future optimization target. If WASM instantiation fails (WasmLoaderError), callers should fall back to the grammar-specific parse functions from @lanexio/parser-grammar-html or @lanexio/parser-grammar-markdown.

  • No direct accessibility surface. The WASM bridge delegates to grammar parsers.
ConcernStatus
Generated output semanticsDelegated to grammar parsers
ARIA attributes in serialized outputNot applicable
Semantic element round-tripNot applicable
  • All parse functions never throw.
  • WASM instantiation may throw WasmLoaderError if the WASM runtime is unavailable.
ThreatMitigationStatus
Malformed input byte sequenceDelegates to grammar parsers (panic-free)Implemented
WASM instantiation failureThrows WasmLoaderError with clear messageImplemented
PackageRelationshipLayerNotes
@lanexio/parser-coreRequires1Core tree and protocol
@lanexio/parser-grammar-htmlRequires2HTML grammar delegation
@lanexio/parser-grammar-markdownRequires2Markdown grammar delegation
@lanexio/parserConsumes6Entry point uses WASM as optional backend
@lanexio/parser-pureFallback4Pure TS fallback when WASM unavailable
VersionDateStatusNotable changes
1.0.02026-05-29CurrentInitial stable release. Apache-2.0.
  • None.