@libgeorge/rules-antlr-pipeline
v0.1.0
Published
This skeleton demonstrates the recommended architecture:
Readme
ANTLR + Async Sink Pipeline Skeleton
This skeleton demonstrates the recommended architecture:
- ANTLR4 listener/visitor remains synchronous
- Listener emits events into an AsyncEventQueue
- An async consumer (
for await) performs:- rule assembly
- lowering
- rewrite / stratify / typecheck
- IR emission
- I/O (writing JSON artifacts)
This pattern gives you:
- deterministic parsing order
- async-friendly compilation steps
- queue-based buffering (you control max size)
Files
grammar/TwoWorldsRules.g4: starter grammar (subset)src/queue/AsyncEventQueue.ts: async iterator queuesrc/parser/ListenerSink.ts: listener → queue sinksrc/pipeline/compilePipeline.ts: async consumer skeletonsrc/pipeline/types.ts: event & rule builder typessrc/pipeline/exampleHooks.ts: stub hooks that write anout/rules.ir.json
Notes
- This repo does not include ANTLR runtime or generated parser code.
In a real project:
- generate TS parser/lexer from
.g4 - wire
ListenerSinkinto the parse call - run
compilePipelineon the queue
- generate TS parser/lexer from
Next steps
- Generate parser/lexer via antlr4ts
- Implement RuleBuilderVisitor to produce your SurfaceRule AST
- Replace ListenerSinkAntlr placeholders with generated listener methods
- Plug RulescriptCompilerHooks into your real passes
Lowering rules (infix → call)
a + b→call("add", [a,b])a - b→call("sub", [a,b])a * b→call("mul", [a,b])a / b→call("div", [a,b])x = exprin conditions →==condition on variablex
See src/parser/RuleBuilderVisitor.ts.
not lowering
This repo includes a minimal pass src/compile/rewriteNot.ts that lowers not atom into not_exists(atom).
Full rewrite pass
src/compile/rewriteFull.tslowers: not/exists/xor/forall/cardinality and performs DNF expansion.src/compile/stratify.tschecks stratified negation on derived predicates.
