The main parsing functions.
The main parsing functions.
(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 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 |