(* p)
Returns a parser that parses zero or more occurrances of p
, and returns
a collection of the return values.
This is a 'sequence expression' parser, see cat
.
Similar to:
many
Returns a parser that parses zero or more occurrances of `p`, and returns a collection of the return values. This is a 'sequence expression' parser, see `cat`. Similar to: - parsec, fparsec: `many`
(*sep-by p psep)
(*sep-by p psep sep-may-end?)
Returns a parser that parses p
zero or more times, separated by
the parser psep
. Returns a collection of the return values of p
.
The return value of psep
is discarded.
When sep-may-end?
is true, allows the sequence to end with psep
.
Otherwise, expects p
to succeed after every psep
.
This is a 'sequence expression' parser, see cat
.
Similar to:
sepBy
, sepEndBy
Returns a parser that parses `p` zero or more times, separated by the parser `psep`. Returns a collection of the return values of `p`. The return value of `psep` is discarded. When `sep-may-end?` is true, allows the sequence to end with `psep`. Otherwise, expects `p` to succeed after every `psep`. This is a 'sequence expression' parser, see `cat`. Similar to: - parsec, fparsec: `sepBy`, `sepEndBy`
(*skip p)
Like *
, but discards p
's results and returns nil
.
Simillar to:
skipMany
Like `*`, but discards `p`'s results and returns `nil`. Simillar to: - fparsec: `skipMany`
(*skip-sep-by p psep)
(*skip-sep-by p psep end?)
Like *sep-by
, but discards all results and returns nil
.
Similar to:
skipSepBy
, skipSepEndBy
Like `*sep-by`, but discards all results and returns `nil`. Similar to: - fparsec: `skipSepBy`, `skipSepEndBy`
(*skip-until p pend)
Like *until
, but discards all results and returns nil
.
Similar to:
skipManyTill
Like `*until`, but discards all results and returns `nil`. Similar to: - fparsec: `skipManyTill`
(*until p pend)
(*until p pend include-end?)
Returns a parser that repeatedly applies the parser p
for as long
as pend
fails (without changing the parser state). It returns a collection
of the results returned by p
.
When include-end?
is true, also includes the result of pend
in the
returned collection.
Similar to:
manyTill
Returns a parser that repeatedly applies the parser `p` for as long as `pend` fails (without changing the parser state). It returns a collection of the results returned by `p`. When `include-end?` is true, also includes the result of `pend` in the returned collection. Similar to: - parsec, fparsec: `manyTill`
(+ p)
Returns a parser that parses one or more occurrances of p
, and returns
a collection of the return values.
This is a 'sequence expression' parser, see cat
.
Similar to:
many1
Returns a parser that parses one or more occurrances of `p`, and returns a collection of the return values. This is a 'sequence expression' parser, see `cat`. Similar to: - parsec, fparsec: `many1`
(+sep-by p psep)
(+sep-by p psep sep-may-end?)
Like *sep-by
, but requires p
to suceed at least once.
Similar to:
sepBy1
, sepEndBy1
Like `*sep-by`, but requires `p` to suceed at least once. Similar to: - parsec, fparsec: `sepBy1`, `sepEndBy1`
(+skip p)
Like +
, but discards p
's results and returns nil
.
Simillar to:
skipMany1
Like `+`, but discards `p`'s results and returns `nil`. Simillar to: - fparsec: `skipMany1`
(+skip-sep-by p psep)
(+skip-sep-by p psep end?)
Like +sep-by
, but discards all results and returns nil
.
Similar to:
skipSepBy1
, skipSepEndBy1
Like `+sep-by`, but discards all results and returns `nil`. Similar to: - fparsec: `skipSepBy1`, `skipSepEndBy1`
(+skip-until p pend)
Like +until
, but discards all results and returns nil
.
Similar to:
skipMany1Till
Like `+until`, but discards all results and returns `nil`. Similar to: - fparsec: `skipMany1Till`
(+until p pend)
(+until p pend include-end?)
Like *until
, but requires p
to succeed at least once.
Similar to:
many1Till
Like `*until`, but requires `p` to succeed at least once. Similar to: - fparsec: `many1Till`
(? p)
(? p not-found)
Returns a parser that parses an optional occurrence of p
.
When p
fails without changing parser state, (? p)
succeeds with nil
.
When p
fails after changing parser state, so will (? p)
.
This is a 'sequence expression' parser, see cat
.
Similar to:
option
, optional
Returns a parser that parses an optional occurrence of `p`. When `p` fails without changing parser state, `(? p)` succeeds with `nil`. When `p` fails after changing parser state, so will `(? p)`. This is a 'sequence expression' parser, see `cat`. Similar to: - parsec, fparsec: `option`, `optional`
(?atomic p)
(?atomic p not-found)
Returns a parser that applies the optional parser p
. If p
fails,
backtracks to the original state and succeeds with value not-found
(default: nil
).
(?atomic p)
is an optimized implementation of (? (atomic p))
.
Returns a parser that applies the _optional_ parser `p`. If `p` fails, backtracks to the original state and _succeeds_ with value `not-found` (default: `nil`). `(?atomic p)` is an optimized implementation of `(? (atomic p))`.
(alt p1)
(alt p1 p2)
(alt p1 p2 p3)
(alt p1 p2 p3 & more)
Returns a parser that applies the parsers until the first one succeeds or fails after changing the parser state.
Similar to:
<|>
, choice
Returns a parser that applies the parsers until the first one succeeds or fails after changing the parser state. Similar to: - parsec, fparsec: `<|>`, `choice`
(alts ps)
(alts ps label')
Like alt
, but takes a sequence of parsers.
Providing a label
is slightly faster, because the parser doesn't
have to aggregate error messages.
choice
, choiceL
(parsec, fparsec)Like `alt`, but takes a sequence of parsers. Providing a `label` is slightly faster, because the parser doesn't have to aggregate error messages. - `choice`, `choiceL` (parsec, fparsec)
(any-token source reply)
This parser accepts and returns any token from the input stream.
This parser accepts and returns any token from the input stream.
(atomic p)
Returns a parser that behaves like p
, but is atomic: When p
fails
after changing the parser state, backtracks to undo the change.
Similar to:
try
attempt
Returns a parser that behaves like `p`, but is atomic: When `p` fails after changing the parser state, backtracks to undo the change. Similar to: - parsec: `try` - fparsec: `attempt`
(between p pdelim)
(between p popen pclose)
Returns a parser that applies the parsers popen
, p
and pclose
in sequence
and returns the result of p
.
When called with two args, uses pdelim
for both popen
and pclose
.
Returns a parser that applies the parsers `popen`, `p` and `pclose` in sequence and returns the result of `p`. When called with two args, uses `pdelim` for both `popen` and `pclose`.
(bind p f)
Returns a parser that first applies the parser p
to the input, then
calls the function f
with the result value of p
and finally applies
the parser returned by f
to the input.
Similar to:
>>=
(parsec, fparsec)Returns a parser that first applies the parser `p` to the input, then calls the function `f` with the result value of `p` and finally applies the parser returned by `f` to the input. Similar to: - `>>=` (parsec, fparsec)
(cat & ps)
Returns a parser that applies the given parsers in sequence, and returns a collection of their result values (concatenation).
This is a 'sequence expression' parser: the result of nested sequence
expressions are flattened in this parser's return value.
(cat p1 (cat p2 p3))
is logically equivalent to (cat p1 p2 p3)
.
Returns a parser that applies the given parsers in sequence, and returns a collection of their result values (concatenation). This is a 'sequence expression' parser: the result of nested sequence expressions are flattened in this parser's return value. `(cat p1 (cat p2 p3))` is logically equivalent to `(cat p1 p2 p3)`.
(cats ps)
Like cat
, but takes a sequence of parsers.
Like `cat`, but takes a sequence of parsers.
(cond p pthen)
(cond p pthen pelse)
Returns a parser that first applies p
. If p
succeeds,
applies pthen
. Otherwise, when p
fails without changing the parser
state, applies pelse
.
Returns a parser that first applies `p`. If `p` succeeds, applies `pthen`. Otherwise, when `p` fails without changing the parser state, applies `pelse`.
(cond-bind p then-fn)
(cond-bind p then-fn pelse)
Returns a parser that first applies p
. If p
succeeds,
applies the parser returned by calling f
with the result of p
.
Otherwise, when p
fails without changing the parser state, applies
pelse
.
Returns a parser that first applies `p`. If `p` succeeds, applies the parser returned by calling `f` with the result of `p`. Otherwise, when `p` fails without changing the parser state, applies `pelse`.
(deref ref)
Returns a parser that de-references ref
on demand, allowing for
recursive or mutable parsers.
Similar to:
createParserForwardedToRef
Returns a parser that de-references `ref` on demand, allowing for recursive or mutable parsers. Similar to: - fparsec: `createParserForwardedToRef`
(end source reply)
The end
parser only succeeds a the end of the input stream and
returns nil
.
Similar to:
eof
The `end` parser only succeeds a the end of the input stream and returns `nil`. Similar to: - parsec, fparsec: `eof`
The eps(ilon) parser accepts the empty word (i.e. it always succeeds) and
returns nil
.
Similar to:
pzero
(but succeeds)The eps(ilon) parser accepts the empty word (i.e. it always succeeds) and returns `nil`. Similar to: - fparsec: `pzero` (but succeeds)
(fail message)
Returns a parser that always fails with given error message.
Returns a parser that always fails with given error message.
(followed-by p)
(followed-by p label)
EXPERIMENTAL: The difference between followed-by
and peek
(lookAhead
)
is subtle: fparsec's followedBy
is an assertion and returns nothing, while
lookAhead
returns the wrapped parser's result. Do we need both?
Returns a parser that succeeds if p
succeeds, but does not change
the parser state. Returns nil
.
Similar to:
followedBy
, followedByL
EXPERIMENTAL: The difference between `followed-by` and `peek` (`lookAhead`) is subtle: fparsec's `followedBy` is an assertion and returns nothing, while `lookAhead` returns the wrapped parser's result. Do we need both? Returns a parser that succeeds if `p` succeeds, but does not change the parser state. Returns `nil`. Similar to: - fparsec: `followedBy`, `followedByL`
(force d)
Returns a parser that realizes and applies a delayed parser on demand.
Returns a parser that realizes and applies a delayed parser on demand.
(fwd expr)
Returns a parser that applies the parser obtained by evaluating expr
,
delaying evaluation until it is needed.
Useful for recursive parsers, to use a parser that has been declared but not yet defined, usually in a var:
(def expr (alt digit (between (fwd expr) (char \() (char \)))))
Warning: Left-recursive parsers are not supported and will lead to infinite loops / stack overflows.
Returns a parser that applies the parser obtained by evaluating `expr`, delaying evaluation until it is needed. Useful for recursive parsers, to use a parser that has been declared but not yet defined, usually in a var: ```clojure (def expr (alt digit (between (fwd expr) (char \() (char \))))) ``` **Warning**: Left-recursive parsers are not supported and will lead to infinite loops / stack overflows.
(group p)
(group p1 p2 & ps)
Like cat
, but returns a collection that will not be flattened into
surrounding sequence expressions.
Like `cat`, but returns a collection that will not be flattened into surrounding sequence expressions.
(index source reply)
This parser returns the index of the next token in the input stream.
This parser returns the index of the next token in the input stream.
(label p label)
Returns a parser that behaves like p
, but replaces errors with
(expected label)
when p
not change the parser state.
Similar to:
Returns a parser that behaves like `p`, but replaces errors with `(expected label)` when `p` not change the parser state. Similar to: - fparsec: `<?>
(label-compound p label)
Returns a parser that behaves like (label p)
, but generates
a "compund error" message with both the given string label and the
error messages generated by p.
Similar to:
Returns a parser that behaves like `(label p)`, but generates a "compund error" message with both the given string label and the error messages generated by p. Similar to: - fparsec: `<??>
(lazy & body)
Returns a parser that evaluates body
the first time it is needed,
and caches the resulting parser.
Returns a parser that evaluates `body` the first time it is needed, and caches the resulting parser.
(let-parser bindings & body)
Similar to let
, but for parsers. The expressions in bindings
must
evaluate to parsers. The returned parser sequentially applies these parsers
to the input, and binds their result values to their binding forms. Every
expression can use the preceding bindings.
Finally, it evaluates body
with all bindings, which must yield a parser that
is then applied to the input.
Expands to a chain of bind
calls.
Use this to create parsers dynamically depending on the return value of a
previously succeeded parser. If you don't need this functionality, consider
using let-return
instead.
Similar to `let`, but for parsers. The expressions in `bindings` must evaluate to parsers. The returned parser sequentially applies these parsers to the input, and binds their result values to their binding forms. Every expression can use the preceding bindings. Finally, it evaluates `body` with all bindings, which must yield a parser that is then applied to the input. Expands to a chain of `bind` calls. Use this to create parsers dynamically depending on the return value of a previously succeeded parser. If you don't need this functionality, consider using `let-return` instead.
(let-return bindings & body)
Like let-parser
, but evaluates body
as the resulting parser's result
value, instead of expecting a final parser to apply.
The parser (let-return [x p] (f x))
is an optimised version of
(let-parser [x p] (return (f x)))
.
Like `let-parser`, but evaluates `body` as the resulting parser's result value, instead of expecting a final parser to apply. The parser `(let-return [x p] (f x))` is an optimised version of `(let-parser [x p] (return (f x)))`.
(map p f)
(map p1 p2 f)
(map p1 p2 p3 f)
(map p1 p2 p3 p4 & more)
Returns a parser that applies the parser p
and returns the return value
of calling f
with the result value of p
.
When multiple parsers are given, applies them in sequence and calls f
with
all result values. The arity of f
must match the number of supplied
parsers.
Similar to:
fmap
|>>
, pipe2
, pipe3
, pipe4
, pipe5
Returns a parser that applies the parser `p` and returns the return value of calling `f` with the result value of `p`. When multiple parsers are given, applies them in sequence and calls `f` with all result values. The arity of `f` must match the number of supplied parsers. Similar to: - parsec : `fmap` - fparsec: `|>>`, `pipe2`, `pipe3`, `pipe4`, `pipe5`
(max p n)
Returns a parser that applies p
at most n
times, and returns a
collection of the result values.
This is a 'sequence expression' parser, see cat
.
Returns a parser that applies `p` at most `n` times, and returns a collection of the result values. This is a 'sequence expression' parser, see `cat`.
(min p n)
Returns a parser that applies p
n
or more times, and returns a
collection of the result values.
This is a 'sequence expression' parser, see cat
.
Returns a parser that applies `p` `n` or more times, and returns a collection of the result values. This is a 'sequence expression' parser, see `cat`.
(not p)
(not p label)
Returns a parser that succeeds if the parser p
fails, and fails otherwise.
In both cases, it does not change the parser state. Returns nil
.
Similar to:
notFollowedBy
notFollowedBy
, notFollowedByL
Returns a parser that succeeds if the parser `p` fails, and fails otherwise. In both cases, it does not change the parser state. Returns `nil`. Similar to: - parsec: `notFollowedBy` - fparsec: `notFollowedBy`, `notFollowedByL`
(not-empty p)
Returns a parser that behaves like p
, but fails when p
does not
change the parser state.
Returns a parser that behaves like `p`, but fails when `p` does not change the parser state.
(parse p input & {:as opts})
Applies the parser p
to input
and returns its result value. Throws
an exception when p
fails.
Applies the parser `p` to `input` and returns its result value. Throws an exception when `p` fails.
(peek p)
Returns a parser that behaves like p
, but always restores the parser
state.
lookAhead
(parsec, fparsec)Returns a parser that behaves like `p`, but always restores the parser state. - `lookAhead` (parsec, fparsec)
(rec f)
Creates a recursive parser. Calls f
with one arg, a parser to recur,
and returns the parser returned by f
.
It is assumed that f
uses alt
or similar to eventually stop the
recursion. For example:
(def parens (rec #(? (between % (char \() (char \))))))
Creates a recursive parser. Calls `f` with one arg, a parser to recur, and returns the parser returned by `f`. It is assumed that `f` uses `alt` or similar to eventually stop the recursion. For example: ```clojure (def parens (rec #(? (between % (char \() (char \)))))) ```
(repeat p n)
(repeat p min max)
When called with two args, returns a parser that applies p
n
times.
When called with three args, returns a parser that applies p
at least
min
times and at most max
times (until it fails).
This is a 'sequence expression' parser, see cat
.
Similar to:
parray
When called with two args, returns a parser that applies `p` `n` times. When called with three args, returns a parser that applies `p` at least `min` times and at most `max` times (until it fails). This is a 'sequence expression' parser, see `cat`. Similar to: - fparsec: `parray`
(return x)
(return p x)
With one arg, returns a parser that consumes nothing and returns x
.
With two args, returns a parser that behaves like p
, but returns x
when p
succeeds.
Similar to:
preturn
, >>%
With one arg, returns a parser that consumes nothing and returns `x`. With two args, returns a parser that behaves like `p`, but returns `x` when `p` succeeds. Similar to: - fparsec: `preturn`, `>>%`
(run p input & {:as opts})
Applies the parser p
to input
and returns a map representing the
parser result.
Applies the parser `p` to `input` and returns a map representing the parser result.
(set-user-state u)
Returns a parser that unconditionally sets the user state to x
and returns swapped-in user state.
Returns a parser that unconditionally sets the user state to `x` and returns swapped-in user state.
(skip-any-token source reply)
This parser skips the next token from the input stream and returns nil
.
This parser skips the next token from the input stream and returns `nil`.
(swap-user-state f & args)
Returns a parser that sets ths user state to (apply f user-state args)
,
and returns the swapped-in user state.
Returns a parser that sets ths user state to `(apply f user-state args)`, and returns the swapped-in user state.
(then p)
(then p1 p2)
(then p1 p2 p3)
(then p1 p2 p3 p4 & more)
Returns a parser that applies the parsers ps
in sequence and returns the
result of the last one.
Similar to:
>>
>>.
Returns a parser that applies the parsers `ps` in sequence and returns the result of the last one. Similar to: - parsec: `>>` - fparsec: `>>.`
(then-skip p)
(then-skip p1 p2)
(then-skip p1 p2 p3)
(then-skip p1 p2 p3 p4 & more)
Returns a parser that applies the parsers ps
in sequence and
returns the result of the first one.
Similar to:
.>>
Returns a parser that applies the parsers `ps` in sequence and returns the result of the first one. Similar to: - fparsec: `.>>`
(token token)
Returns a parser that accepts and returns token
.
Returns a parser that accepts and returns `token`.
(token-return token value)
Returns a parser that expects token
to come next in the input stream
and returns value
.
Returns a parser that expects `token` to come next in the input stream and returns `value`.
(tuple p)
(tuple p1 p2)
(tuple p1 p2 p3)
(tuple p1 p2 p3 p4 & more)
Returns a parser that applies the parsers in sequence and returns a vector of their return values.
Similar to:
<*>
.>>.
, tuple2
, tuple3
, tuple4
, tuple5
Returns a parser that applies the parsers in sequence and returns a vector of their return values. Similar to: - parsec: `<*>` - fparsec: `.>>.`, `tuple2`, `tuple3`, `tuple4`, `tuple5`
(tuples ps)
Returns a parser that applies the parsers ps
in sequence and returns a
vector of their return values.
Returns a parser that applies the parsers `ps` in sequence and returns a vector of their return values.
(user-state source reply)
This parser returns the current user state.
This parser returns the current user state.
(user-state-satisfy pred)
Returns a parser that succeeds if pred
returns logical
true when called with the current user state, otherwise it fails.
Returns the return value of pred
.
Returns a parser that succeeds if `pred` returns logical true when called with the current user state, otherwise it fails. Returns the return value of `pred`.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close