Liking cljdoc? Tell your friends :D

meme.tools.parser

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.
raw docstring

advance!clj/s

(advance! engine n)

Move cursor forward by n characters.

Move cursor forward by n characters.
sourceraw docstring

cstclj/s

(cst type fields)

Create a CST node.

Create a CST node.
sourceraw docstring

cursorclj/s

(cursor engine)

Current cursor position in source.

Current cursor position in source.
sourceraw docstring

eof?clj/s

(eof? engine)

Is cursor at or past end of source?

Is cursor at or past end of source?
sourceraw docstring

expect-close!clj/s

(expect-close! engine close-char close-type)

If the current character matches close-char, consume it and return a close token of the given type. Otherwise return nil (unclosed delimiter).

If the current character matches close-char, consume it and return a close
token of the given type. Otherwise return nil (unclosed delimiter).
sourceraw docstring

led-callclj/s

(led-call node-type close-char close-type)

Factory: call parselet (head + delimited args).

Factory: call parselet (head + delimited args).
sourceraw docstring

led-infixclj/s

(led-infix node-type)
(led-infix node-type right-bp)

Factory: binary infix parselet.

Factory: binary infix parselet.
sourceraw docstring

make-engineclj/s

(make-engine source spec)
source

make-token!clj/s

(make-token! engine type start)

Produce a token map covering [start, cursor). Drains trivia-acc and attaches as :trivia/before. Token shape is identical to the legacy tokenizer output.

Produce a token map covering [start, cursor). Drains trivia-acc and attaches
as :trivia/before. Token shape is identical to the legacy tokenizer output.
sourceraw docstring

make-trivia-token!clj/s

(make-trivia-token! engine type start)

Produce a trivia token covering [start, cursor). Does NOT drain trivia-acc. Used by trivia consumers — the token is pushed onto trivia-acc by skip-trivia!.

Produce a trivia token covering [start, cursor). Does NOT drain trivia-acc.
Used by trivia consumers — the token is pushed onto trivia-acc by skip-trivia!.
sourceraw docstring

nud-atomclj/s

(nud-atom _node-type)

Factory: atom parselet (leaf node, no operands).

Factory: atom parselet (leaf node, no operands).
sourceraw docstring

nud-delimitedclj/s

(nud-delimited node-type close-char close-type)

Factory: delimited parselet (consume children until close char).

Factory: delimited parselet (consume children until close char).
sourceraw docstring

nud-empty-or-errorclj/s

(nud-empty-or-error empty-node-type close-char close-type error-message)

Factory: empty-or-error parselet (empty list or bare parens error).

Factory: empty-or-error parselet (empty list or bare parens error).
sourceraw docstring

nud-prefixclj/s

(nud-prefix node-type)
(nud-prefix node-type bp)

Factory: prefix parselet (consume 1 operand).

Factory: prefix parselet (consume 1 operand).
sourceraw docstring

nud-prefix-twoclj/s

(nud-prefix-two node-type first-key second-key)
(nud-prefix-two node-type first-key second-key bp)

Factory: prefix parselet consuming 2 operands (e.g., metadata).

Factory: prefix parselet consuming 2 operands (e.g., metadata).
sourceraw docstring

nud-prefixed-delimitedclj/s

(nud-prefixed-delimited node-type open-char open-type close-char close-type)
(nud-prefixed-delimited node-type
                        open-char
                        open-type
                        close-char
                        close-type
                        extra-fn)

Factory: prefixed-delimited parselet (prefix token + delimited body). extra-fn: optional (fn [prefix-tok] → extra-fields-map).

Factory: prefixed-delimited parselet (prefix token + delimited body).
extra-fn: optional (fn [prefix-tok] → extra-fields-map).
sourceraw docstring

parseclj/s

(parse source spec)

Parse a source string into a vector of CST nodes using the given grammar spec.

Parse a source string into a vector of CST nodes using the given grammar spec.
sourceraw docstring

parse-exprclj/s

(parse-expr engine min-bp)

Parse one expression at the given minimum binding power.

Parse one expression at the given minimum binding power.
sourceraw docstring

parse-untilclj/s

(parse-until engine close-char close-type)

Parse expressions until a closing character. Returns [nodes close-tok]. close-tok is nil if EOF is reached before the close character.

Parse expressions until a closing character. Returns [nodes close-tok].
close-tok is nil if EOF is reached before the close character.
sourceraw docstring

peek-charclj/s

(peek-char engine)
(peek-char engine offset)

Character at cursor, or nil if at EOF.

Character at cursor, or nil if at EOF.
sourceraw docstring

pos-atclj/s

(pos-at engine offset)

Compute {:line :col} for a character offset. Line/col are 1-indexed.

Compute {:line :col} for a character offset. Line/col are 1-indexed.
sourceraw docstring

set-pos!clj/s

(set-pos! engine pos)

Set cursor to an absolute position.

Set cursor to an absolute position.
sourceraw docstring

skip-trivia!clj/s

(skip-trivia! engine)

Consume trivia characters, accumulating trivia tokens in trivia-acc. A trivia consumer may return nil to signal no match (e.g., BOM not at position 0). In that case, stop the trivia loop.

Consume trivia characters, accumulating trivia tokens in trivia-acc.
A trivia consumer may return nil to signal no match (e.g., BOM not at
position 0). In that case, stop the trivia loop.
sourceraw docstring

source-lenclj/s

(source-len engine)

Length of source string.

Length of source string.
sourceraw docstring

source-strclj/s

(source-str engine)

The full source string.

The full source string.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close