Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/mParser.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

(* MParser, a simple monadic parser combinator library
-----------------------------------------------------------------------------
Copyright (C) 2008, Holger Arnold
Expand Down Expand Up @@ -407,9 +406,13 @@ let (>>=) = bind
let (>>) p q =
p >>= fun _ -> q

let ( *> ) = (>>)

let (<<) p q =
p >>= fun x -> q >> return x

let ( <* ) = ( << )

let (>>>) = (>>)

let (<<<) = (<<)
Expand Down Expand Up @@ -492,6 +495,9 @@ let (<?>) p label s =
else
reply

let hidden p s =
( <?> ) p "" s

let (<??>) p label s =
let reply = p s in
if is_empty reply then
Expand Down
19 changes: 16 additions & 3 deletions src/mParser.mli
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

(* MParser, a simple monadic parser combinator library
-----------------------------------------------------------------------------
Copyright (C) 2008, Holger Arnold
Expand Down Expand Up @@ -335,10 +334,20 @@ val (>>=): ('a, 's) t -> ('a -> ('b, 's) t) -> ('b, 's) t
(** [p >>= f] is equivalent to [bind p f] *)

val (>>): ('a, 's) t -> ('b, 's) t -> ('b, 's) t
(** [p >> q] is equivalent to [p >>= (fun _ -> q)]. *)
(** [p >> q] runs [p], discards its result and then runs [q], and returns its
result. *)

val ( *> ): ('a, 's) t -> ('b, 's) t -> ('b, 's) t
(** [p *> q] runs [p], discards its result and then runs [q], and returns its
result. *)

val (<<): ('a, 's) t -> ('b, 's) t -> ('a, 's) t
(** [p << q] is equivalent to [p >>= (fun x -> q >> return x)]. *)
(** [p << q] runs [p], then runs [q], discards its result, and returns the
result of [p]. *)

val ( <* ): ('a, 's) t -> ('b, 's) t -> ('a, 's) t
(** [p <* q] runs [p], then runs [q], discards its result, and returns the
result of [p]. *)

val (>>>): ('a, 's) t -> ('b, 's) t -> ('b, 's) t
(** Camlp4-compatible alternative to [>>]. *)
Expand Down Expand Up @@ -386,6 +395,10 @@ val (<?>): ('a, 's) t -> string -> ('a, 's) t
consuming input, the error message of [p] is replaced by an
[Expected_error] with the label [label]. *)

val hidden : ('a, 's) t -> ('a, 's) t
(** [hidden p] behaves just like parser [p] but it doesn't show any
expected tokens in error message of [p]*)

val (<??>): ('a, 's) t -> string -> ('a, 's) t
(** [p <??> label] behaves like [p <?> label], but if [p] fails after
consuming input, the error message of [p] is wrapped inside a
Expand Down