Skip to content

@lanexio/parser-grammar-kit

This page documents @lanexio/parser-grammar-kit, the grammar authoring toolkit for building and validating Lanexio Parser grammar packages. This is a build-time utility, not a runtime dependency.

  • Version: Internal
  • Module name: parser-grammar-kit
  • Package: @lanexio/parser-grammar-kit
  • Import path: @lanexio/parser-grammar-kit
  • Layer: Build
  • Runtime: Node.js (build-time only)
  • Module format: ESM
  • Stability: Internal (build-time utility)
  • Primary use case: Validate grammar metadata and generate kind module source.
  • You are authoring a new grammar package for Lanexio Parser.
  • You need to validate grammar metadata before code generation.
  • You need to emit a deterministic TypeScript kind module from grammar metadata.
BoundaryDescription
InputsGrammarMetadata, EmitKindModuleOptions
OutputsGrammarMetadataValidationResult, KindModuleEmitResult (with source string)
Side effectsNone
DeterminismYes (same metadata + options produce same output)
External dependencies@lanexio/parser-core
Never-throw guaranteeNo: validation returns { ok: false, diagnostics } on error.
Security surfaceNone (build-time tool, no input processing)
  1. Install the package.

    Terminal window
    pnpm add -D @lanexio/parser-grammar-kit
  2. Import the named export.

    import { validateGrammarMetadata, emitKindModule } from '@lanexio/parser-grammar-kit';
RequirementRequiredLayerNotes
@lanexio/parser-coreYes1^1.0.0
import { validateGrammarMetadata, emitKindModule } from '@lanexio/parser-grammar-kit';
const metadata = {
name: '@lanexio/parser-grammar-example',
version: '1.0.0',
protocolVersion: 3,
kinds: [
{ name: 'Document', id: 0x100, named: true },
],
fields: [
{ name: 'value', id: 1 },
],
};
const validation = validateGrammarMetadata(metadata);
if (validation.ok) {
const result = emitKindModule(metadata, { exportName: 'ExampleKind' });
if (result.ok) {
console.log(result.source);
}
}
ExportTypeDescription
validateGrammarMetadata(metadata: GrammarMetadata) => GrammarMetadataValidationResultValidate grammar metadata shape. Returns { ok, diagnostics }.
emitKindModule(metadata: GrammarMetadata, options: EmitKindModuleOptions) => KindModuleEmitResultEmit a deterministic TypeScript kind module.
FieldTypeRequiredDefaultDescription
exportNamestringYes-PascalCase name for the exported kind constant object.
fieldExportNamestringNo{exportName}FieldPascalCase name for the exported field constant object.
PropertyTypeDescription
okbooleanWhether validation passed.
metadataGrammarMetadataThe validated metadata (when ok: true).
diagnosticsGrammarMetadataDiagnostic[]List of validation errors (when ok: false).
PropertyTypeDescription
okbooleanWhether emission succeeded.
sourcestringThe generated TypeScript source (when ok: true).
diagnosticsGrammarMetadataDiagnostic[]List of errors (when ok: false).
TypePurposeNotes
GrammarMetadataGrammar metadata descriptor{ name, version, protocolVersion, kinds, fields? }
GrammarKindDefinitionOne grammar node kind{ name, id, named }
GrammarFieldDefinitionOne grammar field{ name, id }
GrammarMetadataDiagnosticValidation diagnostic{ code, path, message }
GrammarMetadataDiagnosticCodeDiagnostic code constantsInvalidName, InvalidVersion, etc.
GrammarMetadataValidationResultValidation resultDiscriminated union
KindModuleEmitResultKind module emission resultDiscriminated union
EmitKindModuleOptionsOptions for emitKindModuleSee options table above.
  • No direct accessibility surface. This is a build-time code generation tool.
  • Input validation returns diagnostics rather than throwing.
  • Generated source code includes a standard ADT Studios LLC copyright header.
ThreatMitigationStatus
Invalid metadata inputReturns { ok: false, diagnostics } instead of throwingImplemented
PackageRelationshipLayerNotes
@lanexio/parser-coreRequires1Protocol version constant for validation
VersionDateStatusNotable changes
1.0.02026-05-29CurrentInitial stable release. Internal build utility.
  • This package is a build-time utility. It is never a production dependency.