Skip to content

@lanexio/parser-cli

This page documents @lanexio/parser-cli, the command-line interface for parsing files, running LexQuery patterns, and serializing parse trees.

  • Version: Stable
  • Module name: parser-cli
  • Package: @lanexio/parser-cli
  • Import path: @lanexio/parser-cli
  • Layer: 6 (CLI)
  • Runtime: Node.js only
  • Module format: ESM
  • Stability: Stable
  • Primary use case: Parse, query, and serialize files from the command line.
  • You want to parse files from the command line without writing code.
  • You want to run LexQuery patterns on files from the terminal.
  • You want to serialize parsed files back to their source format.
BoundaryDescription
InputsCommand-line arguments, stdin
Outputsstdout (tree, JSON, serialized output)
Side effectsFile I/O, stdout writes
DeterminismYes (same input produces same output)
External dependencies@lanexio/parser-core, @lanexio/parser-grammar-html, @lanexio/parser-grammar-markdown, @lanexio/parser-query
Never-throw guaranteeNo: exits with code 1 on fatal errors. Parse operations within a grammar are never-throw.
Security surfaceNone (processes local files)
Terminal window
pnpm add -g @lanexio/parser-cli

The CLI is available as both lanexio-parser and parser:

Terminal window
lanexio-parser parse index.html
parser parse index.html
Terminal window
parser parse index.html
parser parse README.md --output json
Terminal window
parser query Element index.html
parser query "Element, Text" --grammar html --output json < input.html
Terminal window
parser serialize index.html
parser serialize --grammar markdown README.md
ExportTypeDescription
LANEXIO_PARSER_CLI_PACKAGE_NAMEstringStable npm package name constant.
CLI_VERSIONstringThe current package version (read from package.json).
validateEncoding(label: string) => string | nullValidates a WHATWG encoding label.
decode(bytes: Uint8Array, encoding: string) => stringDecodes bytes using the given encoding.

The CLI binary (dist/bin.js) is the primary interface.

These flags work with any subcommand:

FlagDescription
--versionPrint the CLI version and exit. Overrides the subcommand.
--quietSuppress stderr diagnostic output. Useful in scripting.
--helpShow help for the subcommand.
FlagValuesDefaultDescription
--grammarhtml, markdown, autoautoGrammar to use. auto infers from file extension.
--outputtree, jsontreeOutput format. tree prints indented text; json prints serialized tree.
--encodingWHATWG labelutf-8Input file encoding.
FlagValuesDefaultDescription
--grammarhtml, markdown, autoautoGrammar to use.
--outputtext, jsontextOutput format.
--encodingWHATWG labelutf-8Input file encoding.
FlagValuesDefaultDescription
--grammarhtml, markdown, autoautoGrammar to use.
CodeMeaning
0Success. A tree was produced, even if it contains LexError nodes.
1System error (file not found, I/O failure).
2Argument misuse (missing argument, unknown flag, invalid grammar, invalid encoding).

When --grammar auto (default), the grammar is inferred from file extension using the shared grammar registry. All registered grammar packages are available:

ExtensionGrammar
.html, .htmhtml
.md, .markdownmarkdown

The registry is extensible: when new grammar packages are added to the workspace, the CLI automatically detects them without code changes. Use --grammar to force a specific grammar for files with ambiguous or unsupported extensions.

When reading from stdin, --grammar is required (no file extension to infer from).

Per POSIX convention, the -- token separates flags from positional arguments. Everything after -- is treated as a file path or argument, even if it looks like a flag:

Terminal window
parser parse -- some-file.html --output json
# --output and json are treated as part of the filename (warning: file likely not found)
Terminal window
echo '<p>Hello</p>' | parser parse --grammar html
cat index.html | parser parse --grammar html --output json
  • No direct accessibility surface. The CLI produces text output for terminal use.
ConcernStatus
Generated output semanticsNot applicable (terminal output)
ARIA attributes in serialized outputNot applicable
Semantic element round-tripNot applicable
  • The CLI reads files from the local filesystem. It does not execute remote code.
  • Parse operations within recognized grammars are never-throw.
ThreatMitigationStatus
Malformed input fileGrammar parse functions never throw. CLI exits 0 with error nodes in tree.Implemented
Grammar not recognizedExits with code 2 and clear error message.Implemented
PackageRelationshipLayerNotes
@lanexio/parser-coreRequires1Core tree and protocol
@lanexio/parser-grammar-htmlRequires2HTML grammar for CLI
@lanexio/parser-grammar-markdownRequires2Markdown grammar for CLI
@lanexio/parser-queryRequires3LexQuery for query subcommand
VersionDateStatusNotable changes
1.0.02026-05-29CurrentInitial stable release. Apache-2.0.
  • None.
  • Query selectors are kind names, not CSS selectors.
  • No --include-errors flag. The parse --output json format includes hasError per node.
  • Markdown serialization is available and functional (MD-S4).
  • Multi-file glob patterns and streaming parse for large inputs are not yet supported.