Skip to content

@lanexio/parser-grammar-yaml

This page documents @lanexio/parser-grammar-yaml, the YAML grammar package implementing an iterative YAML 1.2.2 parser with explicit indentation and container stack.

  • Version: Stable
  • Module name: parser-grammar-yaml
  • Package: @lanexio/parser-grammar-yaml
  • Import path: @lanexio/parser-grammar-yaml
  • Layer: 2 (Grammar)
  • Runtime: Universal
  • Module format: ESM
  • Stability: Stable
  • Primary use case: Parse YAML 1.2.2 documents into a flat AST.
  • You need to parse YAML 1.2.2 documents (block and flow) into a traversable AST.
  • You need structured flow collections (flow mappings and sequences produce structured subtrees).
  • You need multi-document stream support.
BoundaryDescription
InputsUint8Array (source bytes) + optional ParseYamlOptions
OutputsLexTree (flat AST rooted at YamlKind.Stream)
Side effectsNone
DeterminismYes (same bytes + same options produce identical tree)
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-yaml
  2. Import the named export.

    import { parseYaml } from '@lanexio/parser-grammar-yaml';
RequirementRequiredLayerNotes
@lanexio/parser-coreYes1^1.0.0
import { parseYaml } from '@lanexio/parser-grammar-yaml';
const encoder = new TextEncoder();
const bytes = encoder.encode('key: value\nlist:\n - one\n - two');
const tree = parseYaml(bytes);
console.log(tree.nodeCount);
console.log(tree.root.kind); // YamlKind.Stream
import { parseYaml, YamlKind } from '@lanexio/parser-grammar-yaml';
const encoder = new TextEncoder();
const tree = parseYaml(encoder.encode('{ x: 1, y: [2, 3] }'));
// Walk: Stream -> Document -> FlowMapping -> MappingPair -> (Key, Value)
ExportTypeDescription
parseYaml(bytes: Uint8Array, options?: ParseYamlOptions) => LexTreeParse YAML 1.2.2. Never throws.
YamlKindconst objectNumeric kind IDs for all YAML node types.
YAML_KIND_NAMES_BY_IDReadonlyMap<number, string>Kind-name lookup by numeric ID.
yamlGrammarLanexioParserPureGrammarGrammar descriptor for use with parser-pure.
yamlRegistrationGrammarRegistrationRegistration for the unified grammar registry.
FieldTypeRequiredDefaultDescription
strictModebooleanNoundefinedReserved for future use. Currently has no effect.
PropertyTypeDescription
rootLexNodeRoot node (YamlKind.Stream).
nodeCountnumberTotal nodes in the tree.
sourceUint8ArrayOriginal parsed bytes.
TypePurposeNotes
ParseYamlOptionsOptions for parseYaml{ readonly strictMode?: boolean }
YamlKindValueUnion of all YamlKind valuesType-safe kind reference

No configuration extension points. The parser is fully self-contained. ParseYamlOptions is reserved for future extension.

  • No direct accessibility surface. The YAML parser produces flat AST data structures. Consuming code is responsible for rendering output with appropriate semantics.
ConcernStatus
Generated output semanticsNot applicable (data format)
ARIA attributes in serialized outputNot applicable
Semantic element round-tripNot applicable
  • parseYaml never throws on any byte sequence.
  • YAML has unique security risks (anchors, aliases, tags). Lanexio Parser produces a LexTree and does not resolve YAML tags into application-level types.
ThreatMitigationStatus
Malformed input byte sequencePanic-free guarantee: all inputs accepted, errors produce YamlKind.Error AST nodesImplemented
YAML anchor/alias injectionParser produces AST but does not resolve anchors or execute tag handlersDocumented
PackageRelationshipLayerNotes
@lanexio/parser-coreRequires1Provides LexTree, LexNode, LexCursor
@lanexio/parserConsumes6Unified entry point
VersionDateStatusNotable changes
1.0.02026-05-29CurrentInitial stable release. Apache-2.0.
  • None.