Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add attach function #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions src/tyre.ml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ let pcre s = regex @@ Re.Pcre.re s
let conv to_ from_ x : _ t =
Conv (x, {to_; from_})

let const v x =
conv (fun () -> v) (fun _ -> ()) x

let seq a b : _ t = Seq (a, b)
let alt a b : _ t = Alt (a, b)

Expand Down
7 changes: 5 additions & 2 deletions src/tyre.mli
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(** {1 Typed regular expressions} *)

(**
(**
Tyre is a set of combinators to build type-safe regular expressions, allowing automatic extraction and modification of matched groups.

Tyre is bi-directional: a typed regular expressions can be used both for {{!matching}matching} and {{!eval}evaluation}. Multiple tyregexs can be combined in order to do {{!routing}routing} in similar manner as switches/pattern matching.
Expand Down Expand Up @@ -40,7 +40,7 @@ type 'a t
(** {1 Combinators} *)

val pcre : string -> string t
(** [pcre s] is a tyregex that matches the PCRE [s] and return the
(** [pcre s] is a tyregex that matches the PCRE [s] and return the
corresponding string.
Groups in [s] are ignored.
*)
Expand All @@ -66,6 +66,9 @@ let pos_int =
]}
*)

val const : 'a -> unit t -> 'a t
(** [const v tyre] matches [tyre] but has value [v]. Is a simplification of [conv] for [unit] regular expressions.*)

val opt : 'a t -> 'a option t
(** [opt tyre] matches either [tyre] or the empty string. Similar to {!Re.opt}. *)

Expand Down