Library
Module
Module type
Parameter
Class
Class type
reparse
is an easy to learn and use parser combinator library. It is designed to aid authoring recursive descent style parsers. It removes the tedium of having to maintain parser/lexer input buffer. It emphasises and enables monadic style of writing parsers. As such the parser uses error
type to denote errors in parsing rather than the ocaml exception.
Represents parser input.
The main parser type.'a
denotes the successful parse value while 'error
denotes error raised by the parser.
advance n
advances parser by the given n
number of characters. Always succeeds.
end_of_input
returns true
if parser has reached end of input. Always succeeds.
parse input p
executes parser p
with input input
.
char c
accepts character c
from input exactly and returns it. Fails Otherwise.
char_if f
accepts and returns a Some c
if f c
is true. Otherwise it returns None
. Always succeeds.
satisfy f
accepts a char c
from input if f c
is true and returns it. Otherwise it fails.
peek_char t
returns a character at the current position in the parser. Always suceeds and returns None
if EOF is reached.
Same as peek_char
except the call fails if end of input
is encountered.
peek_string n
attempts to match string of length n
from input exactly and return it. If it isn't matched None
is returned.
skip_while f
keeps accepting c
if f c
is true
. c
is discarded. Always succeeds.
count_skip_while f
accepts characters from input while f c
is true and records the count of times the input char was accepted. The accepted chars are discarded and the count is returned.
count_skip_while_string n f
accepts string s
of length n
if f s
is true. The accepted string s
is discarded and the count of times the string was accepted is noted. The count is then returned.
take_while f
keeps accepting character c
from input while f c
is true. It then concatenates the accepted characters and converts it into a string and returns it.
take_while_n n f
similar in functionality to take_while
. The parser however has a maximum upper bound n
on the number of characters it accepts.
p <|> q
creates a parser that executes p
and returns the result if it is successful. If false then it executes q
and returns it.
p >>= q
executes p
and if it succeeds executes q
and returns it's result else it returns the result of executing p
.
p >>| f
executes p
and then if it is successful returns a
. It then executes f a
and returns the result.
p >>|? f
executes p
and maps error
via f error
if p
results in error
.
p >>*? e
executes p
and returns error e
discarding error
if p
fails.
p <* q
discards result from q
and returns p
many p
runs p zero or more times and returns a list of results from the runs of p.
count_skip_many p
runs p
zeor or more times