package encore

  1. Overview
  2. Docs

Module Encore.SyntaxSource

Sourceval fail : string -> 'a t

fail msg creates a combinator that will always fail with the message msg.

Sourceval map : ('a, 'b) Bij.t -> 'a t -> 'b t
Sourceval product : 'a t -> 'b t -> ('a * 'b) t
Sourceval commit : unit t

commit prevents backtracking beyong the current position of the input, allowing the manager of the input buffer to reuse the preceding bytes for other purposes when the combinator is used as a parser.

As a serializer, commit forces to flush the internal buffer to the manager of the output buffer (if the current state is not into an alteration - see choice).

Sourceval fix : ('a t -> 'a t) -> 'a t
Sourceval pure : compare:('a -> 'a -> bool) -> 'a -> 'a t
Sourceval peek : 'a t -> 'b t -> ('a, 'b) Either.t t

peek p q accepts/computes p and returns it. Otherwise, it accepts/computes q and returns it. It does not advance the input as a parser or produce something into the output as a serializer.

Sourceval const : string -> string t
Sourceval any : char t

any accepts/produces any character. As a parser, it returns it. As a serializer, it writes it.

Sourceval nil : 'a list t
Sourceval rep1 : 'a t -> 'a list t

rep1 t runs t one or more times and accepts/produces a list of results from the runs of t.

Sourceval rep0 : 'a t -> 'a list t

rep0 t runs t zero of more times and accepts/produces a list of results from the runs of t.

Sourceval sep_by0 : sep:unit t -> 'a t -> 'a list t
Sourceval sep_by1 : sep:unit t -> 'a t -> 'a list t
Sourceval while0 : (char -> bool) -> string t

while0 p accepts/produces a string which respects the predicate p. For example, this description:

NUMBER = *DIGIT

can be translated to:

 let number = while0 is_digit 
Sourceval while1 : (char -> bool) -> string t

while1 p accepts/produces a string which respects the predicate p. The string must be not empty. This description:

NUMBER = 1*DIGIT

can be translated to:

 let number = while1 is_digit 
Sourceval fixed : int -> string t

fixed n accepts/produces any string with n bytes.

Sourceval choice : 'a t list -> 'a t
Sourceval sequence : 'a t list -> 'a list t
Sourceval count : int -> 'a t -> 'a list t
Sourceval option : 'a t -> 'a option t
Sourceval lower : char t

lower accepts/produces any US-ASCII lowercase letter 'a' .. 'z', that is a byte in the range [0x61;0x7A].

Sourceval upper : char t

upper accepts/produces any US-ASCII uppercase letter 'A' .. 'Z', that is a byte in the range [0x41;0x5A].

Sourceval alpha : char t

alpha is lower <|> upper.

Sourceval digit : char t

digit accepts/produces any US-ASCII digit '0' .. '9', that is a byte in the range [0x30;0x39].

Sourceval (<$>) : ('a, 'b) Bij.t -> 'a t -> 'b t
Sourceval (<|>) : 'a t -> 'a t -> 'a t
Sourceval (*>) : unit t -> 'a t -> 'a t
Sourceval (<*) : 'a t -> unit t -> 'a t
Sourceval (<*>) : 'a t -> 'b t -> ('a * 'b) t
OCaml

Innovation. Community. Security.