parseq.combinators
Combinators for `parseq.parsers` and similar.
For simplicity the docstrings describe the parser that is returned by each combinator.
alt
(alt & parsers)
Tries `parsers` one after another. Returns the result from the first parser
that succeeds. If all parsers fail, it fails.
altn
(altn & bindings)
Given `bindings` mappings of `name->parser`, associates the `name`s to the `parser`s with `pc/named`, then works as per `alt`.
bind
(bind p f)
This is a monadic bind. A.k.a. `>>=`.
Its type is:
bind :: [Parser a, (a -> Parser b)] -> Parser b
cat
(cat & parsers)
Applies `parsers` one after another. If any parser fails, it fails.
cat<<
(cat<< & parsers)
Applies `parsers` one after another as per `cat`. Returns the result from the first parser in `parsers` and discards the rest.
cat>>
(cat>> & parsers)
Applies `parsers` one after another as per `cat`. Returns the result from the last parser in `parsers` and discards the rest.
catn
(catn & bindings)
Given `bindings` mappings of `name->parser`, associates the `name`s to the `parser`s with `pc/named`, then works as per `cat`.
enum
(enum bindings)
Given a map `bindings` of `name->literal-form`, it returns a parser that returns the `name` of the first `(pp/one= literal-form)` that succeeds.
fmap
(fmap f p)
Applies function `f` to the result of `p`.
Its type is:
fmap :: [Parser a, (a -> b)] -> Parser b
into-map
(into-map & parsers)
Applies `parsers` in order and then `into`s their results into one map. Useful for use with `named`.
many*
(many* p)
Parse `p` 0 or more times. Similar to `*` in regular expressions.
many+
(many+ p)
Parse `p` 1 or more times. Similar to `+` in regular expressions.
map-merge
(map-merge & parsers)
Applies `parsers` in order and then merges their results into one map.
named
(named n p)
Applies `p`, if it succeeds it returns the tuple `[n result]`
one?
(one? p)
Optionally parses one `p`, returning its result, if
found. If `p` doesn't match, returns an nil.
peek
(peek p)
Peeks with `p` (and fails if `p` fails). Does not consume any input.
return
(return v)
A parser that does nothing and always succeeds. It returns the input
unchanged and the supplied `v` as a result.
sep-by
(sep-by separator-p p)
Returns a parser that repeatedly parses with `p` interposed with `separator-p` and discards the parses from `separator-p`
surrounded-by
(surrounded-by surrounding-p p)
Returns a parser that parses with `(cat surrounding-p p surrounding-p)`. Returns the result of `p`.
unordered-pair
(unordered-pair p1 p2)
Tries `p1` followed by `p2` or `p2` followed by `p1`. If either combination
succeeds, always returns `[result1 result2]`.