I’m happy to announce the release of Tyre, a library for Typed Regular Expressions.
Tyre is a set of combinators to build type-safe regular expressions, allowing automatic extraction and modification of matched groups.
# let dim = Tyre.( "dim:" *> int <*> "x" *> int ) ;; (* A new tyregex *) val dim : (int * int) Tyre.t # let dim_re = Tyre.compile dim ;; (* We compile it *) val dim_re : (int * int) Tyre.re # Tyre.exec dim_re "dim:3x4" ;; (* Using it for matching *) - : (int * int, (int * int) Tyre.error) result = Result.Ok (3, 4) # Tyre.eval dim (2, 5) ;; (* We can also use it for unparsing *) - : string = "dim:2x5"
For the most curious among you, the implementation of Tyre is a good example of “real world” GADT usage, while still being short (500 lines) and understandable (I hope). The details might be the subject of another blog post! :)
Good OCaml hacking!