Result constructors, accessors and predicates. Includes transformation utilities.
Result constructors, accessors and predicates. Includes transformation utilities.
(->error key index)
(->error key index detail)
Create an error result, given an error key and an index. An extra detail object can be added.
Create an error result, given an error key and an index. An extra detail object can be added.
(->push parser index)
(->push parser index state)
Create a push value, given a parser function and an index. Optionally a state object can be added.
Create a push value, given a parser function and an index. Optionally a state object can be added.
(->success start end)
(->success start end children)
Create a success result, given a start index (inclusive) and end index (exclusive). Optionally a collection of success children can be given. The name of the success is nil.
Create a success result, given a start index (inclusive) and end index (exclusive). Optionally a collection of success children can be given. The name of the success is nil.
(coerce f)
(coerce binding & body)
Transformer for use with transform
. It applies function f
to the
matched text of the success node, or it binds the matched text to
the binding
vector and executes body
. For example:
(coerce parse-long)
(coerce [s] (-> s upper-case reverse str))
Transformer for use with `transform`. It applies function `f` to the matched text of the success node, or it binds the matched text to the `binding` vector and executes `body`. For example: (coerce parse-long) (coerce [s] (-> s upper-case reverse str))
(collect f)
(collect binding & body)
Transformer for use with transform
. It applies function f
to the
children of the success node, or it binds the children to the
binding
vector and executes body
. For example:
(collect first)
(collect [[val1 op val2]] (op val1 val2))
Transformer for use with `transform`. It applies function `f` to the children of the success node, or it binds the children to the `binding` vector and executes `body`. For example: (collect first) (collect [[val1 op val2]] (op val1 val2))
(error->detail error)
Return the detail object of an error.
Return the detail object of an error.
(error->index error)
Return the index of an error
Return the index of an error
(error->key error)
Return the key of an error.
Return the key of an error.
(errors->line-column result text)
If result
is a set of errors, each error gets a :line
and
:column
entry added. Otherwise, the result
is returned as is.
If `result` is a set of errors, each error gets a `:line` and `:column` entry added. Otherwise, the `result` is returned as is.
(push->index push)
Returns the index of a push value.
Returns the index of a push value.
(push->parser push)
Returns the parser of a push value.
Returns the parser of a push value.
(push->state push)
Returns the state of a push value.
Returns the state of a push value.
(push? obj)
Returns obj if obj is a push value.
Returns obj if obj is a push value.
(success->children success)
Returns the children of a success.
Returns the children of a success.
(success->end success)
Return the end index of a success.
Return the end index of a success.
(success->name success)
Return the name of a success.
Return the name of a success.
(success->start success)
Return the start index of a success.
Return the start index of a success.
(success->text success text)
Returns the matched text of a success, given the full text.
Returns the matched text of a success, given the full text.
(success? obj)
Returns obj if obj is a success value, nil otherwise.
Returns obj if obj is a success value, nil otherwise.
(transform result text transformations)
If result
is a success, it applies the map of transformations
functions in postwalk order based on the node's name. A
transformation function receives the node and the full text
. See
also coerce
and collect
for helpers, for example:
(-> (parse ... text)
(transform text
{:number (coerce parse-long)
:operand (coerce {"+" + "-" - "*" * "/" /})
:operation (collect [[v1 op v2]] (op v1 v2))
nil (collect first)}))
If result
is not a success, it is returned as is.
If `result` is a success, it applies the map of `transformations` functions in postwalk order based on the node's name. A transformation function receives the node and the full `text`. See also `coerce` and `collect` for helpers, for example: (-> (parse ... text) (transform text {:number (coerce parse-long) :operand (coerce {"+" + "-" - "*" * "/" /}) :operation (collect [[v1 op v2]] (op v1 v2)) nil (collect first)})) If `result` is not a success, it is returned as is.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close