kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

gram — parser / lexer generator

gram is a libkit subsystem that turns an EBNF grammar into C: a table-driven LL(1) (+ Pratt) parser, a DFA lexer, regular %machine token automata, and optional standalone (re2c-style) scanners. It is not a lang/ frontend — it registers no KitFrontendVTable and emits no KitCg. Its surface is consumed by embedders, by the kit gram driver command, and by the C it generates.

It was imported as a one-time fork of the standalone gramgen project. The public kit_gram_* names and the interfaces described here are the maintained Kit surface.

Public API

All allocation flows through KitContext.heap; all diagnostics through KitContext.diag. The runtimes are allocation-free and caller-owned.

Opaque, stack-allocatable runtime objects (KitGramParser, KitGramLexer, KitGramMatcher, …) are sized by _Static_assert-guarded KIT_GRAM_*_SIZE constants, so the caller owns every byte and the driver allocates nothing.

Command

kit gram [options] grammar.ebnf (or - for stdin) generates <grammar>.c / .h (override with -o / --header / --prefix). Other modes: --dump-sexpr, --sample-tokens, --sample-traces NAME. Lexer/parser knobs: --multiline, --lexer-standalone, --fold-keywords, --position-lazy, --parser-codegen, --parser-recover. See kit gram --help.

Implementation layout (src/gram/)

Build gating

KIT_GRAM_ENABLED (library: runtime + generator, gated together) and KIT_TOOL_GRAM_ENABLED (the gram driver command) in include/kit/config.h. When gated out, src/api/config_stubs.c provides KIT_UNSUPPORTED stubs so the public ABI surface stays complete.

Tests & regeneration