#compiler #codegen #zpl #zebra

bin+lib zpl_toolchain_spec_compiler

Spec-file compiler that generates parser tables and documentation for ZPL commands

12 unstable releases (3 breaking)

Uses new Rust 2024

0.4.0 Feb 21, 2026
0.3.1 Feb 16, 2026
0.2.1 Feb 14, 2026
0.1.6 Feb 10, 2026

#923 in Parser implementations

MIT/Apache

175KB
3.5K SLoC

zpl_toolchain_spec_compiler

Part of the zpl-toolchain project.

Purpose

  • Validate per-command JSONC files under spec/commands/ against spec/schema/zpl-spec.schema.jsonc.
  • Merge into a single registry and emit generated artifacts:
    • generated/parser_tables.json
    • generated/constraints_bundle.json
    • generated/docs_bundle.json
    • generated/coverage.json

CLI

zpl-spec-compiler build --spec-dir spec --out-dir generated
zpl-spec-compiler check --spec-dir spec

Inputs

  • spec/commands/*.jsonc: one file per command family (codes[] + arity + signature + args/constraints).
  • Schema reference: ../../spec/schema/zpl-spec.schema.jsonc.

Outputs

  • parser_tables.json: canonical table set consumed by parser/validator (includes the opcode trie inline), per-command structuralRules, and top-level structuralRuleIndex (by kind/trigger/effect).
  • constraints_bundle.json: constraints extracted per command code (not consumed at runtime; available for external tooling such as IDE plugins and documentation generators).
  • docs_bundle.json: per-code docs view with signature, args, docs, enumValues, composites.exposesArgs, missingFields (not consumed at runtime; available for external tooling).
  • coverage.json: present/missing counts; per_code stats (arg_count, union_positions, missing fields, validation_errors).

Notes

  • Comments are allowed in source JSONC; the compiler strips them before validation.
  • The compiler passes through fields to spec-tables structures and performs cross-field validation (signature/args/composites/overrides; arg hygiene), including structural rule binding validation.
  • A constraint_kinds_match_schema test validates that ConstraintKind::ALL (the Rust enum) and the JSONC schema's kind enum stay in sync.
  • A structural trigger invariant test validates CommandEntry trigger flags align with structuralRuleIndex.byTrigger.
  • Schema version policy is strict: all loaded spec files must use a single schema version, and it must match the compiler SCHEMA_VERSION constant. Mixed or unexpected versions fail check/build.

Dependencies

~1.4–4.5MB
~80K SLoC