module ParserCo: BatParserCotype 'a state =
| |
Eof |
(* | The end of the source has been reached. | *) |
| |
State of |
The current state of the parser.
The actual set of states is defined by the user. States are typically used to convey information, 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
A source for parsing.
type ('a, 'b, 'c) t
A parser for elements of type 'a, producing
elements of type 'b, with user-defined states
of type 'c.
val eof : ('a, unit, 'b) tAccept the end of an enumeration.
val either : ('a, 'b, 'c) t list -> ('a, 'b, 'c) tAccept one of several parsers.
val (<|>) : ('a, 'b, 'c) t ->
('a, 'b, 'c) t -> ('a, 'b, 'c) tAccept one of two parsers
val maybe : ('a, 'b, 'c) t -> ('a, 'b option, 'c) tAccept an optional argument.
val (~?) : ('a, 'b, 'c) t -> ('a, 'b option, 'c) tAs maybe
val bind : ('a, 'b, 'c) t ->
('b -> ('a, 'd, 'c) t) -> ('a, 'd, 'c) tMonadic-style combination:
bind p f results in a new parser which behaves as p
then, in case of success, applies f to the result.
val (>>=) : ('a, 'b, 'c) t ->
('b -> ('a, 'd, 'c) t) -> ('a, 'd, 'c) tAs bind
val (>>>) : ('a, 'b, 'c) t ->
('a, 'd, 'c) t -> ('a, 'd, 'c) tAs bind, but ignoring the result
val cons : ('a, 'b, 'c) t ->
('a, 'b list, 'c) t -> ('a, 'b list, 'c) tcons 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) tAs cons
val label : string -> ('a, 'b, 'c) t -> ('a, 'b, 'c) tGive a name to a parser, for debugging purposes.
val state : ('a, 'b state, 'b) tSucceed and return the state of the parser
val any : ('a, 'a, 'b) tAccept any singleton value.
val return : 'b -> ('a, 'b, 'c) tA parser which always succeeds
val satisfy : ('a -> bool) -> ('a, 'a, 'b) tsatisfy p accepts one value p x such that p x = true
val filter : ('b -> bool) -> ('a, 'b, 'c) t -> ('a, 'b, 'c) tfilter 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) BatPervasives.result, 'c)
tsuspend s returns the state of the parser in a form that can be
resumed by calling the returned function. evaluation will resume
from parser s
val run : ('a, 'b, 'c) t ->
('a, 'c) Source.t ->
('b, 'c report) BatPervasives.resultrun 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) tAlways fail, without consuming anything.
val fatal : ('a, 'b, 'c) t
val lookahead : ('a, 'b, 'c) t -> ('a, 'b option, 'c) tlookahead p behaves as maybe p but without consuming anything
val exactly : 'a -> ('a, 'a, 'c) tAccept exactly one singleton.
val one_of : 'a list -> ('a, 'a, 'c) tAccept one of several values.
Faster and more convenient than combining satisfy and either.
val none_of : 'a list -> ('a, 'a, 'c) tAccept any value not in a list
Faster and more convenient than combining satisfy and either.
val range : 'a -> 'a -> ('a, 'a, 'c) tAccept any element from a given range.
val zero_plus : ?sep:('a, 'd, 'c) t ->
('a, 'b, 'c) t -> ('a, 'b list, 'c) tAccept a (possibly empty) list of expressions.
val ignore_zero_plus : ?sep:('a, 'b, 'c) t ->
('a, 'd, 'c) t -> ('a, unit, 'c) tIgnore a (possibly empty) list of expressions.
Optimized version of zero_plus, for use when the
list of expressions is unimportant.
val ( ~* ) : ('a, 'b, 'c) t -> ('a, 'b list, 'c) tAs zero_plus without arguments.
val one_plus : ?sep:('a, 'd, 'c) t ->
('a, 'b, 'c) t -> ('a, 'b list, 'c) tAccept a (non-empty) list of expressions
val ignore_one_plus : ?sep:('a, 'b, 'c) t ->
('a, 'd, 'c) t -> ('a, unit, 'c) tIgnore a (non-empty) list of expressions.
Optimized version of one_plus, for use when the
list of expressions is unimportant.
val (~+) : ('a, 'b, 'c) t -> ('a, 'b list, 'c) tAs one_plus
val times : int -> ('a, 'b, 'c) t -> ('a, 'b list, 'c) ttimes n p accepts a list of n expressions accepted by p
val (^^) : ('a, 'b, 'c) t -> int -> ('a, 'b list, 'c) tp ^^ n is the same thing as times n p
val must : ('a, 'b, 'c) t -> ('a, 'b, 'c) tPrevent backtracking.
val should : ('a, 'b, 'c) t -> ('a, 'b, 'c) tPrevent backtracking.
val post_map : ('b -> 'c) -> ('a, 'b, 'd) t -> ('a, 'c, 'd) tPass the (successful) result of some parser through a map.
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) tUse a parser to extract list of tokens, but return that list of tokens instead of whatever the original parser returned.
val sat : ('a -> bool) -> ('a, unit, 'b) tsatisfy p accepts one value p x such that p x = true
val debug_mode : bool Stdlib.refIf set to true, debugging information will be printed to the standard error.
module Infix:sig..end
Infix submodule regrouping all infix operators