raw-strings-qq (empty) → 1.0
raw patch · 5 files changed
+185/−0 lines, 5 filesdep +basedep +template-haskellsetup-changed
Dependencies added: base, template-haskell
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- Text/RawString/QQ.hs +94/−0
- examples/RawRegex.hs +27/−0
- raw-strings-qq.cabal +32/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2013, Mikhail Glushenkov++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Mikhail Glushenkov nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ Text/RawString/QQ.hs view
@@ -0,0 +1,94 @@+-- | Raw string literals, implemented using Template Haskell's quasiquotation+-- feature.+module Text.RawString.QQ+ where++import Language.Haskell.TH+import Language.Haskell.TH.Quote++{-|++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.++Usage:++@+ ghci> :set -XQuasiQuotes+ ghci> import Text.RawString.QQ+ ghci> let s = [r|\\w+\@[a-zA-Z_]+?\\.[a-zA-Z]{2,3}|]+ ghci> s+ \"\\\\w+\@[a-zA-Z_]+?\\\\.[a-zA-Z]{2,3}\"+ ghci> [r|C:\\Windows\\SYSTEM|] ++ [r|\\user32.dll|]+ \"C:\\\\Windows\\\\SYSTEM\\\\user32.dll\"+@++Multiline raw string literals are also supported:++@+ multiline :: String+ multiline = [r|\<HTML\>+ \<HEAD\>+ \<TITLE\>Auto-generated html formated source\</TITLE\>+ \<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=windows-1252\"\>+ \</HEAD\>+ \<BODY LINK=\"#0000ff\" VLINK=\"#800080\" BGCOLOR=\"#ffffff\"\>+ \<P\> \</P\>+ \<PRE\>|]+@++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>++-}+r :: QuasiQuoter+r = QuasiQuoter {+ -- Extracted from dead-simple-json.+ quoteExp = return . LitE . StringL,++ quotePat = \_ -> fail "illegal raw string QuasiQuote \+ \(allowed as expression only, used as a pattern)",+ quoteType = \_ -> fail "illegal raw string QuasiQuote \+ \(allowed as expression only, used as a type)",+ quoteDec = \_ -> fail "illegal raw string QuasiQuote \+ \(allowed as expression only, used as a declaration)"+}++{-| A variant of 'r' that interprets the @\"|~]\"@ sequence as @\"|]\"@.++Usage:++@+ ghci> [rQ||~]|~]|]+ \"|]|]\"+@+-}+rQ :: QuasiQuoter+rQ = QuasiQuoter {+ quoteExp = return . LitE . StringL . escape,++ quotePat = \_ -> fail "illegal raw string QuasiQuote \+ \(allowed as expression only, used as a pattern)",+ quoteType = \_ -> fail "illegal raw string QuasiQuote \+ \(allowed as expression only, used as a type)",+ quoteDec = \_ -> fail "illegal raw string QuasiQuote \+ \(allowed as expression only, used as a declaration)"+}+ where+ escape :: String -> String+ escape [] = []+ escape ('|':'~':']':xs) = '|':']':escape xs+ escape (x:xs) = x : escape xs
+ examples/RawRegex.hs view
@@ -0,0 +1,27 @@+module Main+ where++import Text.Regex.Posix+import Text.RawString.QQ++haystack :: String+haystack = "My e-mail address is user@example.com"++needle :: String+needle = [r|\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}|]++multiline :: String+multiline = [r|<HTML>+<HEAD>+<TITLE>Auto-generated html formated source</TITLE>+<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">+</HEAD>+<BODY LINK="#0000ff" VLINK="#800080" BGCOLOR="#ffffff">+<P> </P>+<PRE>|]++main :: IO ()+main = do+ print multiline+ print ""+ print $ ((haystack =~ needle) :: String)
+ raw-strings-qq.cabal view
@@ -0,0 +1,32 @@+name: raw-strings-qq+version: 1.0+synopsis: Raw string literals for Haskell.+description:++ 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).+ .+ See @examples/RawRegex.hs@ for a usage example.++homepage: https://github.com/23Skidoo/raw-strings-qq+bug-reports: https://github.com/23Skidoo/raw-strings-qq/issues+license: BSD3+license-file: LICENSE+author: Mikhail Glushenkov+maintainer: mikhail.glushenkov@gmail.com+copyright: (c) Mikhail Glushenkov 2013+category: Text+build-type: Simple+cabal-version: >=1.8+extra-source-files: examples/RawRegex.hs++source-repository head+ type: git+ location: https://github.com/23Skidoo/raw-strings-qq.git++library+ exposed-modules: Text.RawString.QQ+ build-depends: base <= 10, template-haskell >= 2.5