module CCApp_parse:sig
..end
status: deprecated
Example: basic S-expr parser
open Containers_string.App_parse;;
type sexp = Atom of string | List of sexp list;;
let mkatom a = Atom a;;
let mklist l = List l;;
let ident_char = alpha_num <+> any_of "|!;$#@%&-_/=*.:~+[]<>'" ;;
let ident = many1 ident_char >|= str_of_l ;;
let atom = (ident <+> quoted) >|= mkatom ;;
let sexp = fix (fun sexp ->
white >>
(atom <+>
((char '(' >> many sexp << char ')') >|= mklist)
)
);;
Str.parse_exn "(a (b c d) e)" sexp;;
type('a, 'b)
result =[ `Error of 'b | `Ok of 'a ]
type 'a
t
val return : 'a -> 'a t
val pure : 'a -> 'a t
CCApp_parse.return
val junk : unit t
val fail : string -> 'a t
fail msg
fails with the given error messageval failf : ('a, unit, string, 'b t) Pervasives.format4 -> 'a
val app : ('a -> 'b) t -> 'a t -> 'b t
val map : ('a -> 'b) -> 'a t -> 'b t
val int : int t
val float : float t
val bool : bool t
val char : char -> char t
char c
parses c
and c
onlyval any_of : string -> char t
val alpha_lower : char t
val alpha_upper : char t
val alpha : char t
val symbols : char t
val num : char t
val alpha_num : char t
val word : string t
word
parses any identifier not starting with an integer and
not containing any whitespace nor delimiter
TODO: specifyval quoted : string t
val str_of_l : char list -> string
val spaces : unit t
'\t'
and ' '
val spaces1 : unit t
CCApp_parse.spaces
but requires at least one spaceval white : unit t
'\t'
, '\n'
and ' '
val white1 : unit t
val eof : unit t
val many : ?sep:unit t -> 'a t -> 'a list t
sep
: separator between elements of the list (for instance, space
)val many1 : ?sep:unit t -> 'a t -> 'a list t
CCApp_parse.many
, but needs at least one elementval skip : 'a t -> unit t
val skip1 : 'a t -> unit t
val opt : 'a t -> 'a option t
opt x
tries to parse x
, and returns None
otherwiseval filter : ('a -> bool) -> 'a t -> 'a t
filter f p
parses the same as p
, but fails if the returned value
does not satisfy f
val switch_c : ?default:'a t ->
(char * 'a t) list -> 'a t
switch_c l
matches the next char and uses the corresponding parser.
Fails if the next char is not in the list, unless default is defined.Invalid_argument
if some char occurs several times in l
default
: parser to use if no char matchesval switch_s : (string * 'a t) list -> 'a t
switch_s l
attempts to match matches any of the strings in l
.
If one of those strings matches, the corresponding parser
is used from now on.Invalid_argument
if some string is a prefix of another string,
or is empty, or if the list is emptyval choice : 'a t list -> 'a t
choice l
chooses between the parsers, unambiguouslyInvalid_argument
if the list is empty, or if some parsers
overlap, making the choice ambiguousval fix : ('a t -> 'a t) -> 'a t
fix f
makes a fixpointmodule Infix:sig
..end
include CCApp_parse.Infix
type
error = {
|
line : |
|
col : |
|
msg : |
val string_of_error : error -> string
exception Error of error
module type S =sig
..end
module type INPUT =sig
..end
module Make(
I
:
INPUT
)
:S
with type source = I.t
val print : Format.formatter -> 'a t -> unit
type
token =
| |
Yield of |
| |
EOF |
module type READER =sig
..end
module MakeFromReader(
R
:
READER
)
:S
with type source = R.source
module Str:S
with type source = string
module Chan:S
with type source = in_channel