Experimental combinators. These may get promoted, or changed, or dismissed.
These combinators are not available in the string- or data-driven
grammar (yet). To use them with those, you can use the
other-parsers
parameter of their respective create-parser
functions, like:
(require '[crustimoney.combinators.experimental :as e])
(create-parser
"root= <- stream
expr= <- '{' [0-9]+ '}'"
{:stream [::e/stream handle-expr
[::e/recover [:ref :expr] [:regex ".*?}"]]})
Note that the other-parsers here is written in vector-grammar
format. This is a little power-user trick, and allows you to declare
ref
s that do not have to resolve immediatly on their creation.
Experimental combinators. These may get promoted, or changed, or dismissed. These combinators are not available in the string- or data-driven grammar (yet). To use them with those, you can use the `other-parsers` parameter of their respective `create-parser` functions, like: (require '[crustimoney.combinators.experimental :as e]) (create-parser "root= <- stream expr= <- '{' [0-9]+ '}'" {:stream [::e/stream handle-expr [::e/recover [:ref :expr] [:regex ".*?}"]]}) Note that the other-parsers here is written in vector-grammar format. This is a little power-user trick, and allows you to declare `ref`s that do not have to resolve immediatly on their creation.
(range parser min max)
Like a repeat, but the times the wrapped parser
is matched must lie
within the given range. It will not try to parse more than max
times.
Like a repeat, but the times the wrapped `parser` is matched must lie within the given range. It will not try to parse more than `max` times.
(recover parser recovery)
Like a choice
, capturing errors of the first choice, including
soft-cuts in its scope.
If the first parser
fails, the recovery
parser is tried. If it
succeeds, it results in a success node like this:
[:crusti/recovered {:start .., :end .., :errors #{..}}]
The errors are those of the first parser, and can be extracted using
success->recovered-errors
. If recovery parser fails, the result
will also be the errors of first parser.
Example usage:
(repeat* (recover (with-name :content
(chain (literal "{")
(regex #"\d+")
(literal "}")))
(regex ".*?}")))
Parsing something like {42}{nan}{100}
would result in:
[nil {:start 0, :end 14}
[:content {:start 0, :end 4}]
[:crusti/recovered {:start 4, :end 9, :errors #{{:key :expected-match, :at 5, ...}}}]
[:content {:start 9, :end 14}]]
Like a `choice`, capturing errors of the first choice, including soft-cuts in its scope. If the first `parser` fails, the `recovery` parser is tried. If it succeeds, it results in a success node like this: [:crusti/recovered {:start .., :end .., :errors #{..}}] The errors are those of the first parser, and can be extracted using `success->recovered-errors`. If recovery parser fails, the result will also be the errors of first parser. Example usage: (repeat* (recover (with-name :content (chain (literal "{") (regex #"\d+") (literal "}"))) (regex ".*?}"))) Parsing something like `{42}{nan}{100}` would result in: [nil {:start 0, :end 14} [:content {:start 0, :end 4}] [:crusti/recovered {:start 4, :end 9, :errors #{{:key :expected-match, :at 5, ...}}}] [:content {:start 9, :end 14}]]
(stream callback parser)
Like repeat*
, but pushes results to the callback
function,
instead of returning them as children.
If callback
is a symbol, it is resolved using requiring-resolve
.
Like `repeat*`, but pushes results to the `callback` function, instead of returning them as children. If `callback` is a symbol, it is resolved using `requiring-resolve`.
(success->recovered-errors success)
Returns the recovered errors from a result, as set by the
recover
combinator parser.
Returns the recovered errors from a result, as set by the `recover` combinator parser.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close