package combinaml

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
module Input : sig ... end
type err = int * string

err an input position and message.

type errs = err list
type fail = Input.t -> errs -> errs

function which may cons errs.

type 'a res = Input.t * ('a, fail) Stdlib.result
type 'a t = {
  1. run : Input.t -> fail -> 'a res;
}
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

val errors_to_string : (int * string) list -> string

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.

val (<?>) : 'a t -> string -> 'a t

p <?> msg provide a failure msg for parser p.

val (>>|) : 'a t -> ('a -> 'b) -> 'b t

p >>| f map operator.

val (<$>) : ('a -> 'b) -> 'a t -> 'b t

f <$> p reverse map.

val (>>=) : 'a t -> ('a -> 'b t) -> 'b t

a >>= ab bind operator.

val (*>) : 'a t -> 'b t -> 'b t

a *> b run a and b in sequence ignoring result of a.

val (<*) : 'a t -> 'b t -> 'a t

a <* b run a and b in sequence ignoring result of b.

val (<*>) : ('a -> 'b) t -> 'a t -> 'b t

ab <*> a run ab and a in sequence, passing the result of a to ab.

val lift2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t

lift f p1 p2 run p1 and p2 in sequence, applying f to the results.

val lift3 : ('a -> 'b -> 'c -> 'd) -> 'a t -> 'b t -> 'c t -> 'd t
val lift4 : ('a -> 'b -> 'c -> 'd -> 'e) -> 'a t -> 'b t -> 'c t -> 'd t -> 'e t
val lift5 : ('a -> 'b -> 'c -> 'd -> 'e -> 'f) -> 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> 'f t
val lift6 : ('a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g) -> 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> 'f t -> 'g t
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 : 'a t -> 'a t

peek run p without advancing 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.

val take_while : ?min:int -> ?max:int -> 'a t -> string t

take_while ?min ?max p a parser that takes input while p succeeds up to max times. fail if less than min times.

val take_while1 : 'a t -> string t
val take_until : ?min:int -> ?max:int -> 'a t -> string t

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_until1 : 'a t -> string t
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.

val optional : 'a t -> 'a option t

optional always succeeds returning result as an optional.

val (<|>) : 'a t -> 'a t -> 'a t

p1 <|> p2 alternative operator. if p1 fails, run p2. both p1 and p2 receive the same input.

val many : ?min:int -> ?max:int -> 'a t -> 'a list t

many ?min ?max p return a list from evaluating p up to max times. fail if less than min.

val many1 : 'a t -> 'a list t
val fix : ('a t -> 'a t) -> 'a t

fix p create a lazy version of p. this allows for creating recursive parsers.

val until : 'b t -> 'a t -> 'a t

until sep p take input until the start of sep (without consuming sep) and feed the result to p.

val many_until : 'a t -> 'b t -> 'b list t

many_until sep p accumulate result of p in a list until sep succeeds. consumes and ignores sep.

val sep_by1 : 'a t -> 'b t -> 'b list t

sep_by sep p accumulate result of (p (sep p)?)+ in a list.

val sep_by : 'a t -> 'b t -> 'b list t

sep_by sep p accumulate result of (p (sep p)?)* in a list.

val choice : ?failure_msg:string -> 'a t list -> 'a t
val list : 'a t list -> 'a list t
type consume =
  1. | Prefix
  2. | All
val parse_string : ?consume:consume -> 'a t -> string -> 'a res

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.

val pair : 'a -> 'b -> 'a * 'b

pair a b a helper useful with lift2.

OCaml

Innovation. Community. Security.