raw-strings-qq-1.0.2: Raw string literals for Haskell.

Safe HaskellNone



Raw string literals, implemented using Template Haskell's quasiquotation feature.



r :: QuasiQuoterSource

A quasiquoter for raw string literals - that is, string literals that don't recognise the standard escape sequences (such as '\n'). Basically, they make your code more readable by freeing you from the responsibility to escape backslashes. They are useful when working with regular expressions, DOS/Windows paths and markup languages (such as XML).

Don't forget the LANGUAGE QuasiQuotes pragma if you're using this module in your code.


    ghci> :set -XQuasiQuotes
    ghci> import Text.RawString.QQ
    ghci> let s = [r|\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}|]
    ghci> s
    ghci> [r|C:\Windows\SYSTEM|] ++ [r|\user32.dll|]

Multiline raw string literals are also supported:

    multiline :: String
    multiline = [r|<HTML>
    <TITLE>Auto-generated html formated source</TITLE>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
    <BODY LINK="800080" BGCOLOR="#ffffff">
    <P> </P>

Caveat: since the "|]" character sequence is used to terminate the quasiquotation, you can't use it inside the raw string literal. Use rQ if you want to embed that character sequence inside the raw string.

For more on raw strings, see e.g. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2053.html

For more on quasiquotation, see http://www.haskell.org/haskellwiki/Quasiquotation

rQ :: QuasiQuoterSource

A variant of r that interprets the "|~]" sequence as "|]", "|~~]" as "|~]" and, in general, "|~^n]" as "|~^(n-1)]".


    ghci> [rQ||~]|~]|]
    ghci> [rQ||~~]|]
    ghci> [rQ||~~~~]|]