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.
(atom-scanlet token-type consume-fn)Build a scanlet that consumes chars via consume-fn, makes a token, returns atom node. consume-fn: (fn [^String source ^long len ^long pos] → end-pos)
Build a scanlet that consumes chars via consume-fn, makes a token, returns atom node. consume-fn: (fn [^String source ^long len ^long pos] → end-pos)
(block-comment-consumer engine)Consume a block comment (* ... *). Supports nesting.
Consume a block comment (* ... *). Supports nesting.
(char-code ch)Character code point. Normalizes the JVM/CLJS asymmetry: on JVM ch is a
Character and int returns the code point; on CLJS ch is a one-char
String. The CLJS (str ch) coercion is defensive against callers passing
a char-typed value in the JS world.
Character code point. Normalizes the JVM/CLJS asymmetry: on JVM `ch` is a Character and `int` returns the code point; on CLJS `ch` is a one-char String. The CLJS `(str ch)` coercion is defensive against callers passing a char-typed value in the JS world.
(consume-identifier source len pos)Consume [a-zA-Z_][a-zA-Z0-9_]*
Consume [a-zA-Z_][a-zA-Z0-9_]*
(consume-number source len pos)Consume integer or float: digits [. digits] [e/E [+/-] digits]
Consume integer or float: digits [. digits] [e/E [+/-] digits]
(consume-string source len pos)Consume double-quoted string with backslash escapes.
Consume double-quoted string with backslash escapes.
(delimited-scanlet node-type token-type close-char close-type)Build a scanlet for an opening delimiter that parses children until close-char.
Build a scanlet for an opening delimiter that parses children until close-char.
(digit? ch)True if ch is an ASCII digit (0–9). Cross-platform (normalizes JVM
Character vs CLJS single-char String via char-code).
True if `ch` is an ASCII digit (0–9). Cross-platform (normalizes JVM Character vs CLJS single-char String via `char-code`).
(ident-char? ch)Default identifier-continuation predicate: ident-start? or digit?.
Override for language-specific rules.
Default identifier-continuation predicate: `ident-start?` or `digit?`. Override for language-specific rules.
(ident-start? ch)Default identifier start: [a-zA-Z_]. Override for language-specific rules.
Default identifier start: [a-zA-Z_]. Override for language-specific rules.
(line-comment-consumer engine prefix-len)Consume a line comment from current position to end of line. prefix-len: number of chars to skip (e.g. 2 for //, 1 for ;).
Consume a line comment from current position to end of line. prefix-len: number of chars to skip (e.g. 2 for //, 1 for ;).
(newline-consumer engine)Trivia consumer for a single newline. Advances past \r\n or \n and
emits a :newline trivia token. Plug into a grammar's trivia table.
Trivia consumer for a single newline. Advances past `\r\n` or `\n` and emits a `:newline` trivia token. Plug into a grammar's trivia table.
(single-char-scanlet token-type factory-parselet)Build a scanlet for a single-character token that delegates to a factory parselet. factory-parselet: (fn [engine tok] → CST node)
Build a scanlet for a single-character token that delegates to a factory parselet. factory-parselet: (fn [engine tok] → CST node)
(ws-consumer engine)(ws-consumer engine whitespace-pred)Consume whitespace (space, tab). Override whitespace-pred for language-specific rules.
Consume whitespace (space, tab). Override whitespace-pred for language-specific rules.
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 |