Page
Library
Module
Module type
Parameter
Class
Class type
Source
Qinap
SourceA (very small) parsing library.
Module containing functions for working with strings.
'a parser
parses values of type 'a
. A parser consumes a string and either returns a tuple with the result of the parsing and the remaining unparsed input or fails.
result x
returns a parser that consumes no input and always succeeds with the value x
. It is an implementation of return
for the parser monad.
item
parses exactly one character from its input. Fails if applied to an empty string.
p => f
returns a parser that applies the function f
to the result of p
and fails if p
fails. This combinator is an implementation of map
for the parser functor.
let* p f
returns a parser that chains the parser p
and the parser that results from applying f
to the result of p
. This combinator is an implementation of bind
for the parser monad. let*
can be used similarly to Haskell's do-notation to chain parsers without using many anonymous functions.
p <|> q
parses its input using p
; if that fails, it parses the original input using q
. Can be read as a logical "or". <|>
is the choice combinator.
p >> q
parses its input using p
, throws away the result of p
, and parses the remaining input using q
.
p << q
parses its input using p
, passes the remaining input using q
, and throws away the result of q
, leaving only the result of p
.
p <~> ps
parses its input using p
, parses the remaining input using ps
, and preppends the result of p
to the list obtained by applying ps
. You can think of p <~> ps
as the parser version of x :: xs
.
many p
parses its input using p
zero or more times and returns the results in a list.
many1 p
parses its input using p
one or more times and returns the results in a list.
satisfy ~f
parsers a character x
from its input if f x
is true and fails otherwise.
char c
parses a character from its input if it is equal to c
and fails otherwise.
clist cs
takes a list of characters cs
as its argument and succeeds if it can parse all of them from its input in order.
string s
takes a string s
as its argument and succeeds if it can parse that string from its input.
one_of cs
tries to parse a character from the list cs
, in order, and succeeds returning the parsed character if a match is found, failing otherwise.
between ~l ~r p
parses p
between l
and r
, whose results are discarded.
sep_by1 p ~sep
returns a list of the results of the parser p
, ignoring the results given by the separator parser sep
, which is applied one or more times between each use of p
.
sep_by p ~sep
returns a list of the results of the parser p
, ignoring the results given by the separator parser sep
, which is applied zero or more times between each use of p
.
space
is a parser that succeeds if it finds a whitespace character, returning it, and fails otherwise.
spaces
is a parser that suceeds if it finds one or more whitespace characters, returning a list of the parsed characters, and fails otherwise.
digit
parses exactly one digit from its input and fails if that is not possible.
digits
parses zero or more digits from its input and returns them a string, and fails if that is not possible.
digits1
parses one or more digits from its input and returns them a string, and fails if that is not possible.
natural
parses a natural number from its input as an int and fails if that is not possible.
integer
parses an integer from its input as an int and fails if that is not possible.