package re_parser

  1. Overview
  2. Docs

Module Re_parserSource

Sourcetype 'a t
Sourcemodule Open_on_rhs_intf : sig ... end
include Base.Applicative.Let_syntax with type 'a t := 'a t with module Open_on_rhs_intf := Open_on_rhs_intf
Sourcemodule Let_syntax : sig ... end
include Open_on_rhs_intf.S with type 'a t := 'a t
include Regex_parser_intf.S with type 'a t := 'a t
Sourceval compile : ?case_sensitive:Base.bool -> 'a t -> (Base.string -> 'a Base.option) Base.Staged.t

case_sensitive defaults to true.

Sourceval run : ?case_sensitive:Base.bool -> 'a t -> Base.string -> 'a Base.option
Sourceval matches : ?case_sensitive:Base.bool -> 'a t -> Base.string -> Base.bool

The applicative interface provides sequencing, e.g. both a b is a regex that parses an a followed by a b and returns both results in a pair.

include Base.Applicative.S with type 'a t := 'a t
Sourceval return : 'a -> 'a t
Sourceval map : 'a t -> f:('a -> 'b) -> 'b t
Sourceval both : 'a t -> 'b t -> ('a * 'b) t
Sourceval (<*>) : ('a -> 'b) t -> 'a t -> 'b t

same as apply

Sourceval (<*) : 'a t -> unit t -> 'a t
Sourceval (*>) : unit t -> 'a t -> 'a t
Sourceval (>>|) : 'a t -> ('a -> 'b) -> 'b t
Sourceval apply : ('a -> 'b) t -> 'a t -> 'b t
Sourceval map2 : 'a t -> 'b t -> f:('a -> 'b -> 'c) -> 'c t
Sourceval map3 : 'a t -> 'b t -> 'c t -> f:('a -> 'b -> 'c -> 'd) -> 'd t
Sourceval all : 'a t list -> 'a list t
Sourceval all_unit : unit t list -> unit t
Sourcemodule Applicative_infix : sig ... end
Sourceval ignore_m : _ t -> Base.unit t

ignore_m t is a regex which matches the same strings that t matches, but doesn't call functions on the captured submatches. Particularly, something like ignore (map (string "x") ~f:Int.of_string) won't raise an exception, because the int conversion is never attempted.

Sourceval capture : Base.unit t -> Base.string t

capture t returns the string matched by t

Sourceval and_capture : 'a t -> ('a * Base.string) t

and_capture t returns the string matched by t in addition to whatever it was already going to return.

Sourceval fail : 'a t

Regex that matches nothing

Sourceval or_ : 'a t Base.list -> 'a t
Sourceval optional : ?greedy:Base.bool -> 'a t -> 'a Base.option t

greedy defaults to true. If false, the regexp will prefer not matching.

Sourceval repeat : ?greedy:Base.bool -> ?min:Base.int -> ?max:Base.int Base.option -> Base.unit t -> Base.unit t

repeat ~min ~max t constructs the regex t{min,max}. min defaults to 0 and max defaults to None (unbounded), so that just plain repeat t is equivalent to t*.

It would be better for repeat to be 'a t -> 'a list t, but the Re2 library, for example, doesn't give you access to repeated submatches like that. Hence, repeat ignores all submatches of its argument and does not call any callbacks that may have been attached to them, as if it had ignore called on its result.

times r n essentially constructs the regex r{n}. It is equivalent to repeat ~min:n ~max:(Some n) r.

Compare with, say, all (List.init n ~f:(fun _ -> r)), which constructs the regex rrr...r (with n copies of r) and has the type 'a t -> 'a list t.

Sourceval string : Base.string -> Base.unit t
Sourceval any_string : Base.string t
Sourceval start_of_input : Base.unit t

Matches empty string at the beginning of the text

Sourceval end_of_input : Base.unit t

Matches empty string at the end of the text

Sourcemodule Char : sig ... end
Sourcemodule Decimal : sig ... end
Sourceval to_re : ?case_sensitive:Base.bool -> _ t -> Re.t
Sourceval of_re : Re.t -> Base.unit t
OCaml

Innovation. Community. Security.