Module Parser_utils.Parser

The Parser module collects an API of parser-combinators for parsing FIX messages into OCaml types. Each combinator takes a continuation function that returns a ( 'a Parser.t * msg ) type

type msg = (Imandra_prelude.string * Imandra_prelude.string) list

Type alias for a FIX message -- we assyme it is a list of string parirs

type 'a t =
| ParseSuccess of 'a
| UnknownMessageTag of Imandra_prelude.string
| RequiredTagMissing of Imandra_prelude.string
| DuplicateTag of Imandra_prelude.string
| WrongValueFormat of Imandra_prelude.string
| UndefinedTag of Imandra_prelude.string
| EmptyValue of Imandra_prelude.string
| IncorrectNumInGroupCount of Imandra_prelude.string
| RepeatingGroupOutOfOrder of Imandra_prelude.string
| GarbledMessage
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t

A standard monadic bind operator for the Parser.t type

val (>|>=) : 'a t -> ('a -> 'b t * 'c list) -> 'b t * 'c list

The modified bind operator that applies a function that returns ( 'a Parser.t * msg ) pair

val rev_collect : 'a t list -> 'a list t

A "collect" function that convers 'a t list -> 'a list t Note: Tail-recursive, but reverses the list.

val opt : (Imandra_prelude.string * Imandra_prelude.string) list -> Imandra_prelude.string -> (Imandra_prelude.string -> 'a option) -> ((Imandra_prelude.string * Imandra_prelude.string) list -> 'a option -> 'b t * 'c list) -> 'b t * 'c list

Optional field combinator, passes None into continuation if the tag is not present

val req : (Imandra_prelude.string * Imandra_prelude.string) list -> Imandra_prelude.string -> (Imandra_prelude.string -> 'a option) -> ((Imandra_prelude.string * Imandra_prelude.string) list -> 'a -> 'b t * 'c list) -> 'b t * 'c list

Required field combinator, returns RequiredTagMissing if the tag is not present

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

Block parser combinator parsers a record and passes it into the continuation

val repeating : msg -> Imandra_prelude.string -> (msg -> 'a t * msg) -> (msg -> 'a list -> 'b t * msg) -> 'b t * msg

Repeating group parser combinator, starting from the tag that encodes the length of the list, identifies the subgroups and passes each of them into the block parser. Performs a number of consistency checks on the parsed results.

val check_duplicate_tags : msg -> (Imandra_prelude.unit -> 'a t * msg) -> 'a t * msg

Checks for duplicate tags in messages -- should be called after all the repeating groups are porcessed

val check_unknown_tags : ('a t * (Imandra_prelude.string * 'b) list) -> 'a t

This finalizes the message -- if there are any unplrocessed tag=value pairs left -- we return an error

val get_top_and_last : 'a list -> 'a list * 'a option
val list_to_split : Imandra_prelude.string list -> char -> Imandra_prelude.string
val split_to_list : Imandra_prelude.string -> char -> Imandra_prelude.string list