Generic scanlet builders for the Pratt parser engine.
Scanlet builders wrap language-specific consume functions into parselets that the grammar spec can reference. They bridge the gap between 'consume characters from source' and 'produce a CST node'.
Any language can use these builders with its own consume functions.
Generic scanlet builders for the Pratt parser engine. Scanlet builders wrap language-specific consume functions into parselets that the grammar spec can reference. They bridge the gap between 'consume characters from source' and 'produce a CST node'. Any language can use these builders with its own consume functions.
Unified scanlet-parselet Pratt parser.
The engine reads directly from a source string. The grammar spec defines everything language-specific: character dispatch (scanlets), trivia classification, prefix parselets (nud), and postfix rules (led).
A scanlet is (fn [engine] → CST node). It consumes characters from the source string using engine primitives and produces a CST node.
Grammar spec shape: {:nud {char → scanlet-fn} :nud-pred [[pred scanlet-fn] ...] :trivia {char → trivia-consumer-fn} :trivia-pred [[pred trivia-consumer-fn] ...] :led [{:char c :bp n :when pred :fn scanlet-fn} ...]}
Parselet factories (nud-atom, nud-prefix, nud-delimited, etc.) generate common patterns. Custom parselets are plain functions.
Unified scanlet-parselet Pratt parser.
The engine reads directly from a source string. The grammar spec defines
everything language-specific: character dispatch (scanlets), trivia
classification, prefix parselets (nud), and postfix rules (led).
A scanlet is (fn [engine] → CST node). It consumes characters from the
source string using engine primitives and produces a CST node.
Grammar spec shape:
{:nud {char → scanlet-fn}
:nud-pred [[pred scanlet-fn] ...]
:trivia {char → trivia-consumer-fn}
:trivia-pred [[pred trivia-consumer-fn] ...]
:led [{:char c :bp n :when pred :fn scanlet-fn} ...]}
Parselet factories (nud-atom, nud-prefix, nud-delimited, etc.) generate
common patterns. Custom parselets are plain functions.Wadler-Lindig document algebra and layout engine. Generic — no meme-specific knowledge. Reusable for any pretty-printing task.
Doc types form a small algebra: DocText — literal string DocLine — newline+indent (or flat-alt when flat) DocCat — concatenation DocNest — increase indent DocGroup — try flat, break if too wide DocIfBreak — conditional on flat/break mode
layout renders a Doc tree to a string at a given page width. Use ##Inf for single-line (flat) rendering.
Wadler-Lindig document algebra and layout engine. Generic — no meme-specific knowledge. Reusable for any pretty-printing task. Doc types form a small algebra: DocText — literal string DocLine — newline+indent (or flat-alt when flat) DocCat — concatenation DocNest — increase indent DocGroup — try flat, break if too wide DocIfBreak — conditional on flat/break mode layout renders a Doc tree to a string at a given page width. Use ##Inf for single-line (flat) rendering.
Generic interactive eval loop. Language-agnostic. All language-specific behavior is injected via opts: :run-fn — (fn [source opts] → ctx-with-:forms) :expand-forms — (fn [forms opts] → expanded-forms) :format-error — (fn [exception input] → error-string) :eval — eval function (default: clojure.core/eval) :read-line — line reader fn (default: read-line) :banner — REPL banner string :reader-opts — opts map passed to run-fn :prelude — vector of forms to eval before REPL loop JVM/Babashka only.
Generic interactive eval loop. Language-agnostic. All language-specific behavior is injected via opts: :run-fn — (fn [source opts] → ctx-with-:forms) :expand-forms — (fn [forms opts] → expanded-forms) :format-error — (fn [exception input] → error-string) :eval — eval function (default: clojure.core/eval) :read-line — line reader fn (default: read-line) :banner — REPL banner string :reader-opts — opts map passed to run-fn :prelude — vector of forms to eval before REPL loop JVM/Babashka only.
Generic eval pipeline: source → parse → expand → eval. Language-agnostic. All language-specific behavior is injected via opts: :run-fn — (fn [source opts] → ctx-with-:forms) :expand-forms — (fn [forms opts] → expanded-forms) :eval — eval function (default: clojure.core/eval) :prelude — vector of forms to eval before user code JVM/Babashka only.
Generic eval pipeline: source → parse → expand → eval. Language-agnostic. All language-specific behavior is injected via opts: :run-fn — (fn [source opts] → ctx-with-:forms) :expand-forms — (fn [forms opts] → expanded-forms) :eval — eval function (default: clojure.core/eval) :prelude — vector of forms to eval before user code JVM/Babashka only.
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 |