module ParserCo: BatParserCo
type 'a
state =
| |
Eof |
(* | The end of the source has been reached. | *) |
| |
State of |
The actual set of states is defined by the user. States are
typically used to convey informations, such as position in the file
(i.e. line number and character).
type 'a
report =
| |
Report of |
(* | The final result of parsing | *) |
module Source:sig
..end
type ('a, 'b, 'c)
t
'a
, producing
elements of type 'b
, with user-defined states
of type 'c
.val eof : ('a, unit, 'b) t
val either : ('a, 'b, 'c) t list -> ('a, 'b, 'c) t
val (<|>) : ('a, 'b, 'c) t ->
('a, 'b, 'c) t -> ('a, 'b, 'c) t
val maybe : ('a, 'b, 'c) t -> ('a, 'b option, 'c) t
val (~?) : ('a, 'b, 'c) t -> ('a, 'b option, 'c) t
maybe
val bind : ('a, 'b, 'c) t ->
('b -> ('a, 'd, 'c) t) -> ('a, 'd, 'c) t
bind p f
results in a new parser which behaves as p
then, in case of success, applies f
to the result.
compose p q
results in a new parser which feeds the
consecutive results of p
into q
. In case of error,
positions are taken from p
.
val (>>=) : ('a, 'b, 'c) t ->
('b -> ('a, 'd, 'c) t) -> ('a, 'd, 'c) t
bind
val (>>>) : ('a, 'b, 'c) t ->
('a, 'd, 'c) t -> ('a, 'd, 'c) t
bind
, but ignoring the resultval cons : ('a, 'b, 'c) t ->
('a, 'b list, 'c) t -> ('a, 'b list, 'c) t
cons p q
applies parser p
then parser q
and
conses the results into a list.val (>::) : ('a, 'b, 'c) t ->
('a, 'b list, 'c) t -> ('a, 'b list, 'c) t
cons
val label : string -> ('a, 'b, 'c) t -> ('a, 'b, 'c) t
val state : ('a, 'b state, 'b) t
val any : ('a, 'a, 'b) t
val return : 'a -> ('b, 'a, 'c) t
val satisfy : ('a -> bool) -> ('a, 'a, 'b) t
satisfy p
accepts one value p x
such that p x = true
val filter : ('a -> bool) -> ('b, 'a, 'c) t -> ('b, 'a, 'c) t
filter f p
is only accepts values x
such that p
accepts x
and f (p x)
is true
val suspend : ('a, 'b, 'c) t ->
('a, unit -> ('b, 'c report) BatStd.result, 'c) t
suspend s
returns the state of the parser in a form that can be
resumed by calling the returned function. evaluation will resume
from parser sval run : ('a, 'b, 'c) t ->
('a, 'c) Source.t -> ('b, 'c report) BatStd.result
run p s
executes parser p
on source s
. In case of
success, returns Ok v
, where v
is the return value of p
.
In case of failure, returns Error f
, with f
containing
details on the parsing error.val fail : ('a, 'b, 'c) t
val fatal : ('a, 'b, 'c) t
val lookahead : ('a, 'b, 'c) t -> ('a, 'b option, 'c) t
lookahead p
behaves as maybe p
but without consuming anythingval exactly : 'a -> ('a, 'a, 'b) t
val one_of : 'a list -> ('a, 'a, 'b) t
satisfy
and either
.val none_of : 'a list -> ('a, 'a, 'b) t
satisfy
and either
.val range : 'a -> 'a -> ('a, 'a, 'b) t
val zero_plus : ?sep:('a, 'b, 'c) t ->
('a, 'd, 'c) t -> ('a, 'd list, 'c) t
val ignore_zero_plus : ?sep:('a, 'b, 'c) t ->
('a, 'd, 'c) t -> ('a, unit, 'c) t
zero_plus
, for use when the
list of expressions is unimportant.val ( ~* ) : ('a, 'b, 'c) t -> ('a, 'b list, 'c) t
zero_plus
without arguments.val one_plus : ?sep:('a, 'b, 'c) t ->
('a, 'd, 'c) t -> ('a, 'd list, 'c) t
val ignore_one_plus : ?sep:('a, 'b, 'c) t ->
('a, 'd, 'c) t -> ('a, unit, 'c) t
one_plus
, for use when the
list of expressions is unimportant.val (~+) : ('a, 'b, 'c) t -> ('a, 'b list, 'c) t
one_plus
val times : int -> ('a, 'b, 'c) t -> ('a, 'b list, 'c) t
times n p
accepts a list of n
expressions accepted by p
val (^^) : ('a, 'b, 'c) t -> int -> ('a, 'b list, 'c) t
p ^^ n
is the same thing as times n p
val must : ('a, 'b, 'c) t -> ('a, 'b, 'c) t
val should : ('a, 'b, 'c) t -> ('a, 'b, 'c) t
val post_map : ('a -> 'b) -> ('c, 'a, 'd) t -> ('c, 'b, 'd) t
val source_map : ('a, 'b, 'c) t ->
('a, 'c) Source.t -> ('b, 'c) Source.t
val scan : ('a, 'b, 'c) t -> ('a, 'a list, 'c) t
val sat : ('a -> bool) -> ('a, unit, 'b) t
val debug_mode : bool Pervasives.ref
true
, debugging information will be printed to the standard error.