package combinaml

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module CombinamlSource

Sourcemodule Input : sig ... end
Sourcetype err = int * string

err an input position and message.

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

function which may cons errs.

Sourcetype 'a res = Input.t * ('a, fail) result
Sourcetype 'a t = {
  1. run : Input.t -> fail -> 'a res;
}
Sourceval input : string -> Input.t

input s alias of Input.init

Sourceval return : 'a -> 'a t

return x a parser that always succeeds, returning x

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

errors_to_string errs a helper for converting errs to a string.

Sourceval fail : string -> 'a t

fail msg a parser that always fails with msg.

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

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

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

p >>| f map operator.

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

f <$> p reverse map.

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

a >>= ab bind operator.

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

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

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

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

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

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

Sourceval 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.

Sourceval lift3 : ('a -> 'b -> 'c -> 'd) -> 'a t -> 'b t -> 'c t -> 'd t
Sourceval lift4 : ('a -> 'b -> 'c -> 'd -> 'e) -> 'a t -> 'b t -> 'c t -> 'd t -> 'e t
Sourceval lift5 : ('a -> 'b -> 'c -> 'd -> 'e -> 'f) -> 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> 'f t
Sourceval lift6 : ('a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g) -> 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> 'f t -> 'g t
Sourceval satisfy : (char -> bool) -> char t

satisfy f a parser accepting when f returns true.

Sourceval char : char -> char t

char c a parser accepting c.

Sourceval not_char : char -> char t

not_char c a parser accepting not c.

Sourceval any_char : char t

any_char a parser accepting any char.

Sourceval any_char_in : string -> char t

any_char_in s a parser accepting any char in s.

Sourceval any_char_except : string -> char t

any_char_except s a parser accepting any char not in s.

Sourceval char_range : char -> char -> char t

char_range min max a parser accepting any char in the range min max) (inclusive).

Sourceval str : string -> string t

str s a parser accepting input which starts with s.

Sourceval forward : int -> unit t

forward n move the input position forward by n. fail if resulting input position would be out of bounds.

Sourceval backward : int -> unit t

backward n move the input position backward by n. fail if resulting input position would be less than 0.

Sourceval is_end_of_input : bool t

is_end_of_input always succeeds. true if at end of input.

Sourceval end_of_input : unit t

end_of_input a parser accepting when at end of input.

Sourceval peek_char : char option t

peek_char return optional next char without advancing input.

Sourceval peek_char_fail : char t

peek_char_fail return next char without advancing input. fail on end of input.

Sourceval peek : 'a t -> 'a t

peek run p without advancing input.

Sourceval peek_string : int -> string t

peek_string return next n characters without advancing input.

Sourceval pos : int t

pos return current input position.

Sourceval len : int t

len return current input remaining length.

Sourceval 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.

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

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

Sourceval take_while_fn1 : ?max:int -> (char -> bool) -> string t
Sourceval 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.

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

optional always succeeds returning result as an optional.

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

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

Sourceval 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.

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

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

Sourceval 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.

Sourceval 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.

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

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

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

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

Sourceval choice : ?failure_msg:string -> 'a t list -> 'a t
Sourceval list : 'a t list -> 'a list t
Sourcetype consume =
  1. | Prefix
  2. | All
Sourceval 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.

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

pair a b a helper useful with lift2.