Portability | non-portable (GHC QuasiQuotes) |
---|---|
Stability | unstable |
Maintainer | mjm2002@gmail.com |
Text.Regex.PCRE.QQ
Description
A quasiquoter for Text.Regex.PCRE regexes. This makes use of a new GHC extension known as QuasiQuotes. See the README for the temporary location of the docs for Language.Haskell.TH.Quote. See the EXAMPLES file for examples.
ghci> [$rx|([aeiou]).*(er|ing|tion)([\.,\?]*)$|] "helloing.!?!?!" Just ["elloing.!?!?!","e","ing",".!?!?!"]
- rx :: QuasiQuoter
- regexToExpQ :: String -> ExpQ
- regexToPatQ :: String -> PatQ
- module Language.Haskell.TH.Quote
- module Language.Haskell.TH.Syntax
- module Language.Haskell.TH.Lib
- module Language.Haskell.TH.Ppr
Documentation
ghci> maybe [] tail $ [$rx|^([+-])?([0-9]+)\.([0-9]+)|] (show $ negate pi) ["-","3","141592653589793"]
regexToExpQ :: String -> ExpQSource
Transform a string rep
of a regex to an ExpQ. The
resulting ExpQ, when spliced,
results in a function of type
String -> Maybe [String]
,
where the input is the String
to match on. The result is
Nothing on error, and Just
a list of results on success.
Note: I'm packing/unpacking/...
the ByteString unnecessarily
for convenience in testing
out the first go at this.
This will be dealt with in
the future.
regexToPatQ :: String -> PatQSource
Transform a string (presumably) containing a regex to a PatQ. NOTE: Given a regex, a pattern is constructed which matches a literal string containing the verbatim regex. It does this because I couldn't think of anything better for it to do off the cuff. This needs thought.
module Language.Haskell.TH.Quote
module Language.Haskell.TH.Syntax
module Language.Haskell.TH.Lib
module Language.Haskell.TH.Ppr