t-regex-0.1.0.0: Matchers and grammars using tree regular expressions

Safe HaskellNone
LanguageHaskell2010

Data.Regex.TH

Description

Quasi-quoters for doing pattern matching using tree regular expressions.

Synopsis

Documentation

rx :: QuasiQuoter Source

Builds a pattern for a matching a tree regular expression over a regular data type. Those variables not bound are taken to be capture identifiers. Note that the value of capture identifiers is always a list, even if it matches only one subterm in the given tree regular expression.

One example of use is:

f [rx| iter $ \k -> x <<- inj One <||> y <<- inj (Two (k#)) |] =
  ... x and y available here with type [Fix f] ...

In many cases, it is useful to define pattern synonyms for injecting constructors, as shown below:

pattern One_   = Inject One
pattern Two_ x = Inject (Two_ x)

f [rx| (\k -> x <<- One_ <||> y <<- Two_ (k#))^* |] = ...

mrx :: QuasiQuoter Source

Builds a pattern for a matching a tree regular expression over a family of regular data type. Those variables not bound are taken to be capture identifiers, and their index should be explicitly given in the expression. Note that the value of capture identifiers is always a list, even if it matches only one subterm in the given tree regular expression.

One example of use is:

f [mrx| iter $ \k -> (x :: A) <<- inj One <||> (y :: B) <<- inj (Two (k#)) |] =
  ... x is available with type [Fix f A]
  ... and y with type [Fix f B]