The main parsing functions.
The main parsing functions.
(compile model)
Compile a parser model to its combinator function. This way the
parse
function can skip this step (speeding it up) and the
model can be checked at compile time.
For more information on the model, see the vector-grammar
namespace. Note that the string-grammar
, data-grammar
and
combinator-grammar
all return vector models.
Compile a parser model to its combinator function. This way the `parse` function can skip this step (speeding it up) and the model can be checked at compile time. For more information on the model, see the `vector-grammar` namespace. Note that the `string-grammar`, `data-grammar` and `combinator-grammar` all return vector models.
(parse parser text)
(parse parser text opts)
Use the given parser
to parse the supplied text
string. The
result will either be a success (a hiccup-style vector) or a set of
errors. By default only named nodes are kept in a success
result (the root node is allowed to be nameless).
A success result looks like this:
[:name {:start 0, :end 3}
[:child-1 {:start 0, :end 2}]
[:child-2 {:start 2, :end 3}]]
An error result looks like this:
({:key :expected-literal, :at 0, :detail {:literal "foo"}}
{:key :unexpected-match, :at 8, :detail {:text "eve"}})
The parse function can take an opts
map, with the following
options:
:index
, the index at which to start parsing in the text, default 0.
:cache
, the packrat cache to use, see the caches namespace.
Default is treemap-cache. To disable caching, use nil.
:infinite-check?
, check for infinite loops during parsing.
Default is true. Setting it to false yields a small performance
boost.
:keep-nameless?
, set this to true if nameless success nodes
should be kept in the parse result. This can be useful for
debugging. Defaults to false.
Use the given `parser` to parse the supplied `text` string. The result will either be a success (a hiccup-style vector) or a set of errors. By default only named nodes are kept in a success result (the root node is allowed to be nameless). A success result looks like this: [:name {:start 0, :end 3} [:child-1 {:start 0, :end 2}] [:child-2 {:start 2, :end 3}]] An error result looks like this: ({:key :expected-literal, :at 0, :detail {:literal "foo"}} {:key :unexpected-match, :at 8, :detail {:text "eve"}}) The parse function can take an `opts` map, with the following options: - `:index`, the index at which to start parsing in the text, default 0. - `:cache`, the packrat cache to use, see the caches namespace. Default is treemap-cache. To disable caching, use nil. - `:infinite-check?`, check for infinite loops during parsing. Default is true. Setting it to false yields a small performance boost. - `:keep-nameless?`, set this to true if nameless success nodes should be kept in the parse result. This can be useful for debugging. Defaults to false.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close