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.combinators :as c]
         '[crustimoney.string-grammar :as sg]
         '[crustimoney.experimental.combinators :as ec])

(merge
 (sg/create-parser
   "root= <- stream
    expr= <- 'BEGIN' [0-9]+ 'END'")
 {:stream (ec/stream* {}
            (c/chain {}
              (ec/with-callback {:callback handle-expr}
                (c/ref {:to :expr}))
              :hard-cut))})

Above example also shows how to setup a streaming parser. The stream* ensures that the result tree does not grow, the with-callback passes chunks of results to a function, before it is hard-cut. The hard-cut ensures both the packrat cache and the streaming reader buffer (if used, see reader namespace) are kept small.

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.combinators :as c]
             '[crustimoney.string-grammar :as sg]
             '[crustimoney.experimental.combinators :as ec])

    (merge
     (sg/create-parser
       "root= <- stream
        expr= <- 'BEGIN' [0-9]+ 'END'")
     {:stream (ec/stream* {}
                (c/chain {}
                  (ec/with-callback {:callback handle-expr}
                    (c/ref {:to :expr}))
                  :hard-cut))})

Above example also shows how to setup a streaming parser. The
`stream*` ensures that the result tree does not grow, the
`with-callback` passes chunks of results to a function, before it is
hard-cut. The hard-cut ensures both the packrat cache and the
streaming reader buffer (if used, see `reader` namespace) are kept
small.
raw docstring

rangeclj

(range {:keys [min max] :or {max Long/MAX_VALUE}} parser)

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. If max is not supplied, there is no maximum.

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. If `max` is not supplied, there is no maximum.
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 {:keys [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