Library
Module
Module type
Parameter
Class
Class type
module Input : sig ... end
type errs = err list
val input : string -> Input.t
input s
alias of Input.init
val return : 'a -> 'a t
return x
a parser that always succeeds, returning x
errors_to_string errs
a helper for converting errs
to a string.
val fail : string -> 'a t
fail msg
a parser that always fails with msg
.
ab <*> a
run ab
and a
in sequence, passing the result of a
to ab
.
lift f p1 p2
run p1
and p2
in sequence, applying f
to the results.
val satisfy : (char -> bool) -> char t
satisfy f
a parser accepting when f
returns true.
val char : char -> char t
char c
a parser accepting c
.
val not_char : char -> char t
not_char c
a parser accepting not c
.
val any_char : char t
any_char
a parser accepting any char.
val any_char_in : string -> char t
any_char_in s
a parser accepting any char in s
.
val any_char_except : string -> char t
any_char_except s
a parser accepting any char not in s
.
val char_range : char -> char -> char t
char_range min max
a parser accepting any char in the range min max) (inclusive).
val str : string -> string t
str s
a parser accepting input which starts with s
.
val forward : int -> unit t
forward n
move the input position forward by n
. fail if resulting input position would be out of bounds.
val backward : int -> unit t
backward n
move the input position backward by n
. fail if resulting input position would be less than 0.
val is_end_of_input : bool t
is_end_of_input
always succeeds. true if at end of input.
val end_of_input : unit t
end_of_input
a parser accepting when at end of input.
val peek_char : char option t
peek_char
return optional next char without advancing input.
val peek_char_fail : char t
peek_char_fail
return next char without advancing input. fail on end of input.
val peek_string : int -> string t
peek_string
return next n characters without advancing input.
val pos : int t
pos
return current input position.
val len : int t
len
return current input remaining length.
take_while ?min ?max p
a parser that takes input while p
succeeds up to max
times. fail if less than min
times.
take_until ?min ?max p
a parser that takes input while p
fails up to max
times. fail if less than min
times.
val take_while_fn : ?min:int -> ?max:int -> (char -> bool) -> string t
take_while_fn ?min ?max f
take up to max
chars of input while f
is true. fail if less than min
.
val take_while_fn1 : ?max:int -> (char -> bool) -> string t
val scan : 'a -> ('a -> char -> 'a option) -> (string * 'a) t
scan state f
given initial state
, take input while f
returns Some. returns string * final state.
p1 <|> p2
alternative operator. if p1
fails, run p2
. both p1
and p2
receive the same input.
many ?min ?max p
return a list from evaluating p
up to max
times. fail if less than min
.
fix p
create a lazy version of p
. this allows for creating recursive parsers.
until sep p
take input until the start of sep
(without consuming sep
) and feed the result to p
.
many_until sep p
accumulate result of p
in a list until sep
succeeds. consumes and ignores sep
.
parse_string ?consume p s
return result of running p
on s
. consume:All
requires that all input is consumes by running p <* end_of_input
.