Skip to content

Lanexio Parser

Lanexio Parser is a modular parser framework for HTML, Markdown, JSON, YAML, and CSS. It produces a zero-copy flat AST backed by a single ArrayBuffer, parses any byte sequence without panicking or throwing, and passes 100% of the html5lib and CommonMark 0.31.2 test suites. Every grammar ships as a separate npm package so you pay only for what you use.

  • HTML: 100% html5lib conformance (5,199 tree-construction tests), all 23 insertion modes, adoption agency, foster parenting, foreign content.
  • Markdown: 100% CommonMark 0.31.2 (652 specs) and 100% GFM (648 specs). Roundtrip serializer included.
  • JSON: RFC 8259, complete JSONTestSuite corpus (311/311), strict accept/reject semantics with error-position reporting.
  • YAML: YAML 1.2.2, 267/268 yaml-test-suite, structured flow collections, anchors/aliases/tags.
  • CSS: CSS Syntax Level 3, full CourtBouillon corpus never-throw + error-detection agreement.
  • Zero-copy flat AST: 16-byte nodes in preorder DFS, O(1) subtree skip, no per-node object allocation.
  • Never-throw parse path: parse() never throws. Malformed input produces error nodes in the tree.
  • Panic-free: any byte sequence of any length is accepted. Backed by fuzz harnesses and structural forward-progress guards.
  • LexQuery: kind-name pattern queries with field and error modifiers.
  • CLI: lanexio-parser parse/query/serialize with stdin support and strict invocation validation.

Parse an HTML document:

import { parseHtml } from '@lanexio/parser-grammar-html';
const encoder = new TextEncoder();
const tree = parseHtml(encoder.encode('<h1>Hello</h1>'));
const cursor = tree.cursor();
visit: while (true) {
console.log(cursor.current.kind, cursor.current.range);
if (cursor.gotoFirstChild()) continue;
while (!cursor.gotoNextSibling()) {
if (!cursor.gotoParent()) break visit;
}
}

Parse a Markdown document:

import { parseMarkdown } from '@lanexio/parser-grammar-markdown';
const encoder = new TextEncoder();
const tree = parseMarkdown(encoder.encode('# Hello\n\nA paragraph.'));
console.log(tree.nodeCount); // number of nodes in the flat AST
console.log(tree.root.kind); // numeric kind id for the document root