Xmlc.Parser
Parser Combinators for XML signals
val return : 'a -> 'a t
return v
creates a parser that will always succeed and return v
.
val fail : exn -> 'a t
fail exn
creates a parser that will always fail with the exception exn
.
val fail_with : ?signal:Xmlm.signal -> string -> 'a t
fail_with msg
creates a parser that will always fail with the message msg
. If an optional signal
is provided the error message is annotated with signal
.
p >>= f
creates a parser that will run p
, pass its result to f
and run the parser that f
produces, and returns its result.
p >>| f
creates a parser that will run p
, and if it succeeds with result v
, will return f v
p <* q
runs p
, then runs q
, discards its result, and returns the result of p
.
p <* q
runs p
, then runs q
, discards its result, and returns the result of p
.
p <?> msg
returns a parser that runs p
and returns the result of p
if p
succeeds. If p
fails the parser fails with message msg
.
p <|> q
returns a parser that runs p
and returns the result of p
if p
succeeds. If p
fails q
is run.
choice ?failure_msg ts
runs each parser in ts
in order until one succeeds and returns that result. In the case that none of the parser succeeds, then the parser will fail with the message failure_msg
, if provided, or a much less informative message otherwise.
option p
returns a parser that runs p
and returns the result of p
as Some _
or None
if p
fails.
fix f
computes the fixpoint of f
and runs the resultant parser. The argument that f
receives is the result of fix f
, which f
must use, paradoxically, to define fix f
.
many p
runs p
zero or more times and returns a list of results from the runs of p
.
val stream_end : unit t
stream_end
succeeds if the end of input is reached and fails otherwise.
val dtd : string option t
dtd
returns a parser that returns a XML DTD definition.
val data : string t
data
reads an XML data signal.
val any_el_start : Xmlm.tag t
any_el_start
reads an XML element start and returns the tag.
val el_start : Xmlm.name -> Xmlm.attribute list t
el_start name
returns a parser that reads an XML element start with name
and returns the attributes.
val el_end : unit t
el_end
reads an XML element end signal.
These are useful combinations of the XML signal parsers.
element name f
returns a parser that reads an XML element with name
and runs the parer resulting by apply f
on the attributes of the XML element followed by an el_end
parser.
any_element name f
returns a parser that reads any XML element and runs the parer resulting by apply f
on the tag of the XML element followed by an el_end
parser.
val ignore_any : unit t
ignore_any
reads one XML element or data item and ignores it.
val ignore_element : unit t
ignore_element
reads one XML and ignores it.
val complex : ?required:Xmlm.name list -> ?ignore_other:bool ->
Xmlm.name -> (Xmlm.attribute list -> 'a t) -> (Xmlm.name * ('a -> 'a)) t list -> 'a t
complex ~required name root children
returns a parser for a complex object name
that is represented with multiple XML child elements that appear in an unspecified order. The root
parser is applied to the root element and provides a base object.
If the root element does not have any children complex
will return the same parser as root
(if no required fields are specified).
Child elements are parsed with the first succeeding parser in children
whose elements returns a transformation of the base object.
If a required
argument is provided the returned parser will fail if there is no child with given name for every member of required
.
If ignore_others
(defaults: false) is set then child elements that can not be parsed with parsers in children
are ignored.
complex
is useful for parsing complex data types such as Atom entries, where there are many optional child elements that may appear in unspecified order.
module Attributes : sig ... end
Helpers for getting attribute values
val parse_stream : 'a t -> Xmlm.signal Lwt_stream.t -> 'a Lwt.t