module BatParserCo:sig..end
This module permits the simple definition of highly modular, dynamic parsers with unlimited backtracking. It may be used to parse any form of enumeration, including regular text, latin-1 text, bits, etc.
This library is vastly more powerful than Lexing, Str, Parsing
or Scanf. It is also considerably slower.
Module CharParser contains pre-defined parsers to deal
specifically with latin-1 text. Module Genlex contains a number
of pre-defined parsers to deal specifically with programming
languages.
Note This library is still very rough and needs much testing.
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) tval either : ('a, 'b, 'c) t list -> ('a, 'b, 'c) tval (<|>) : ('a, 'b, 'c) t ->
('a, 'b, 'c) t -> ('a, 'b, 'c) tval maybe : ('a, 'b, 'c) t -> ('a, 'b option, 'c) tval (~?) : ('a, 'b, 'c) t -> ('a, 'b option, 'c) tmaybeval 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.
val (>>=) : ('a, 'b, 'c) t ->
('b -> ('a, 'd, 'c) t) -> ('a, 'd, 'c) tbindval (>>>) : ('a, 'b, 'c) t ->
('a, 'd, 'c) t -> ('a, 'd, 'c) tbind, but ignoring the resultval 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) tconsval label : string -> ('a, 'b, 'c) t -> ('a, 'b, 'c) tval state : ('a, 'b state, 'b) tval any : ('a, 'a, 'b) tval return : 'b -> ('a, 'b, 'c) tval satisfy : ('a -> bool) -> ('a, 'a, 'b) tsatisfy p accepts one value p x such that p x = trueval 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 trueval 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 sval 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 Bad f, with f containing
details on the parsing error.val fail : ('a, 'b, 'c) tval fatal : ('a, 'b, 'c) t
val lookahead : ('a, 'b, 'c) t -> ('a, 'b option, 'c) tlookahead p behaves as maybe p but without consuming anythingval exactly : 'a -> ('a, 'a, 'c) tval one_of : 'a list -> ('a, 'a, 'c) tsatisfy and either.val none_of : 'a list -> ('a, 'a, 'c) tsatisfy and either.val range : 'a -> 'a -> ('a, 'a, 'c) tval zero_plus : ?sep:('a, 'd, 'c) t ->
('a, 'b, 'c) t -> ('a, 'b list, 'c) tval ignore_zero_plus : ?sep:('a, 'b, 'c) t ->
('a, 'd, 'c) t -> ('a, unit, 'c) tzero_plus, for use when the
list of expressions is unimportant.val ( ~* ) : ('a, 'b, 'c) t -> ('a, 'b list, 'c) tzero_plus without arguments.val one_plus : ?sep:('a, 'd, 'c) t ->
('a, 'b, 'c) t -> ('a, 'b list, 'c) tval ignore_one_plus : ?sep:('a, 'b, 'c) t ->
('a, 'd, 'c) t -> ('a, unit, 'c) tone_plus, for use when the
list of expressions is unimportant.val (~+) : ('a, 'b, 'c) t -> ('a, 'b list, 'c) tone_plusval times : int -> ('a, 'b, 'c) t -> ('a, 'b list, 'c) ttimes n p accepts a list of n expressions accepted by pval (^^) : ('a, 'b, 'c) t -> int -> ('a, 'b list, 'c) tp ^^ n is the same thing as times n pval must : ('a, 'b, 'c) t -> ('a, 'b, 'c) tval should : ('a, 'b, 'c) t -> ('a, 'b, 'c) tval post_map : ('b -> 'c) -> ('a, 'b, 'd) t -> ('a, 'c, 'd) tval source_map : ('a, 'b, 'c) t ->
('a, 'c) Source.t -> ('b, 'c) Source.t
val scan : ('a, 'b, 'c) t -> ('a, 'a list, 'c) tval sat : ('a -> bool) -> ('a, unit, 'b) tsatisfy p accepts one value p x such that p x = trueval debug_mode : bool Pervasives.reftrue, debugging information will be printed to the standard error.module Infix:sig..end