Liking cljdoc? Tell your friends :D

crustimoney.experimental.combinators

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, combine them in a larger grammar like so:

(require '[crustimoney.experimental.combinators :as e])

(grammar
 (create-parser
   "root= <- stream
    expr= <- '{' [0-9]+ '}'")
 {:stream (e/stream*
           (e/with-callback handle-expr
             (e/recover (ref :expr) (regex ".*?}")))})
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, combine them in a larger
grammar like so:

    (require '[crustimoney.experimental.combinators :as e])

    (grammar
     (create-parser
       "root= <- stream
        expr= <- '{' [0-9]+ '}'")
     {:stream (e/stream*
               (e/with-callback handle-expr
                 (e/recover (ref :expr) (regex ".*?}")))})
raw docstring

rangeclj

(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.
sourceraw docstring

recoverclj

(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}]]
sourceraw docstring

stream*clj

(stream* parser)

Like repeat*, but does does not keep its children. Can be used in combination with with-callback combinator, for example.

Like `repeat*`, but does does not keep its children. Can be used in
combination with `with-callback` combinator, for example.
sourceraw docstring

stream+clj

(stream+ parser)

Like repeat+, but does does not keep its children. Can be used in combination with with-callback combinator, for example.

Like `repeat+`, but does does not keep its children. Can be used in
combination with `with-callback` combinator, for example.
sourceraw docstring

with-callbackclj

(with-callback callback parser)

Pushes (success) result of parser to the 2-arity callback function. The callback receives the text and the success result.

If callback is a symbol, it is resolved using requiring-resolve.

Pushes (success) result of `parser` to the 2-arity `callback`
function. The callback receives the text and the success result.

If `callback` is a symbol, it is resolved using `requiring-resolve`.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close