Formal contract for the meme pipeline context map.
Defines clojure.spec.alpha specs for the context at each stage boundary, a toggleable runtime validator, and explain functions for debugging.
The pipeline is composable ctx → ctx stages:
scan → parse → expand
Context map contract:
| Key | Type | Written by | Read by |
|---|---|---|---|
| :source | String | caller | scan, parse |
| :opts | Map or nil | caller | parse, expand |
| :raw-tokens | Vector | scan | (tooling) |
| :tokens | Vector | scan | parse |
| :forms | Vector | parse, expand | expand, caller |
Guest languages that replace stages (e.g. a custom parser that reads :tokens and writes :forms) must produce context maps conforming to the relevant stage-output spec. Enable runtime validation during development:
(binding [contract/validate true] (pipeline/run source))
Formal contract for the meme pipeline context map.
Defines clojure.spec.alpha specs for the context at each stage boundary,
a toggleable runtime validator, and explain functions for debugging.
The pipeline is composable ctx → ctx stages:
scan → parse → expand
Context map contract:
| Key | Type | Written by | Read by |
|--------------|----------------|---------------|----------------------|
| :source | String | caller | scan, parse |
| :opts | Map or nil | caller | parse, expand |
| :raw-tokens | Vector | scan | (tooling) |
| :tokens | Vector | scan | parse |
| :forms | Vector | parse, expand | expand, caller |
Guest languages that replace stages (e.g. a custom parser that reads
:tokens and writes :forms) must produce context maps conforming to
the relevant stage-output spec. Enable runtime validation during
development:
(binding [contract/*validate* true]
(pipeline/run source))When true, pipeline stages validate their input and output context maps against the formal contract. Default: false (zero overhead). Bind to true for development, testing, or debugging guest parsers.
Example: (binding [contract/validate true] (pipeline/run source))
When true, pipeline stages validate their input and output context maps
against the formal contract. Default: false (zero overhead).
Bind to true for development, testing, or debugging guest parsers.
Example:
(binding [contract/*validate* true]
(pipeline/run source))(explain-context stage phase ctx)Return a human-readable explanation of why ctx fails the contract for the given stage and phase (:input or :output). Returns nil if ctx is valid. Not gated by validate.
Useful for tooling, REPL debugging, and guest language development.
Return a human-readable explanation of why ctx fails the contract for the given stage and phase (:input or :output). Returns nil if ctx is valid. Not gated by *validate*. Useful for tooling, REPL debugging, and guest language development.
Map from stage keyword to the spec its input context must satisfy.
Map from stage keyword to the spec its input context must satisfy.
Map from stage keyword to the spec its output context must satisfy.
Map from stage keyword to the spec its output context must satisfy.
All token types emitted by the meme tokenizer.
All token types emitted by the meme tokenizer.
(valid? stage phase ctx)Check if ctx satisfies the contract for the given stage and phase. Does not throw. Not gated by validate.
Check if ctx satisfies the contract for the given stage and phase. Does not throw. Not gated by *validate*.
(validate! stage phase ctx)Validate ctx against the contract for the given stage and phase.
Throws ex-info with :stage, :phase, and :problems when
validate is true and ctx fails spec. No-op when validate is false.
Called automatically by pipeline stages when validate is true. Can also be called directly by guest language parsers.
Validate ctx against the contract for the given stage and phase. Throws ex-info with `:stage`, `:phase`, and `:problems` when *validate* is true and ctx fails spec. No-op when *validate* is false. Called automatically by pipeline stages when *validate* is true. Can also be called directly by guest language parsers.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |