raw-strings-qq-1.1/0000755000000000000000000000000012633374460012450 5ustar0000000000000000raw-strings-qq-1.1/LICENSE0000644000000000000000000000277612633374460013471 0ustar0000000000000000Copyright (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. raw-strings-qq-1.1/Setup.hs0000644000000000000000000000005612633374460014105 0ustar0000000000000000import Distribution.Simple main = defaultMain raw-strings-qq-1.1/raw-strings-qq.cabal0000644000000000000000000000267312633374460016343 0ustar0000000000000000name: raw-strings-qq version: 1.1 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-2015 category: Text build-type: Simple cabal-version: >=1.8 extra-source-files: examples/RawRegex.hs ChangeLog 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 test-suite tests hs-source-dirs: test main-is: Test.hs type: exitcode-stdio-1.0 build-depends: base, raw-strings-qq, HUnit ghc-options: -Wall raw-strings-qq-1.1/ChangeLog0000644000000000000000000000030712633374460014222 0ustar0000000000000000-*-change-log-*- 1.1 Mikhail Glushenkov * CRLF line endings are now normalised to LF (#1). 1.0 Mikhail Glushenkov * Initial release. raw-strings-qq-1.1/Text/0000755000000000000000000000000012633374457013402 5ustar0000000000000000raw-strings-qq-1.1/Text/RawString/0000755000000000000000000000000012633374457015322 5ustar0000000000000000raw-strings-qq-1.1/Text/RawString/QQ.hs0000644000000000000000000000714612633374457016207 0ustar0000000000000000-- | Raw string literals, implemented using Template Haskell's quasiquotation -- feature. module Text.RawString.QQ (r, rQ) 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|\ \ \Auto-generated html formated source\ \ \ \ \ \ \|] @ 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. For more on quasiquotation, see -} r :: QuasiQuoter r = QuasiQuoter { -- Extracted from dead-simple-json. quoteExp = return . LitE . StringL . normaliseNewlines, 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 @\"|]\"@, @\"|~~]\"@ as @\"|~]\"@ and, in general, @\"|~^n]\"@ as @\"|~^(n-1)]\"@ for n >= 1. Usage: @ ghci> [rQ||~]|~]|] \"|]|]\" ghci> [rQ||~~]|] \"|~]\" ghci> [rQ||~~~~]|] \"|~~~]\" @ -} rQ :: QuasiQuoter rQ = QuasiQuoter { quoteExp = return . LitE . StringL . escape_rQ . normaliseNewlines, 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)" } escape_rQ :: String -> String escape_rQ [] = [] escape_rQ ('|':'~':xs) = let (tildas, rest) = span (== '~') xs in case rest of [] -> '|':'~':tildas (']':rs) -> '|':tildas ++ ']':escape_rQ rs rs -> '|':'~':tildas ++ escape_rQ rs escape_rQ (x:xs) = x : escape_rQ xs -- See https://github.com/23Skidoo/raw-strings-qq/issues/1 and -- https://ghc.haskell.org/trac/ghc/ticket/11215. normaliseNewlines :: String -> String normaliseNewlines [] = [] normaliseNewlines ('\r':'\n':cs) = '\n':normaliseNewlines cs normaliseNewlines (c:cs) = c:normaliseNewlines cs raw-strings-qq-1.1/test/0000755000000000000000000000000012633374457013435 5ustar0000000000000000raw-strings-qq-1.1/test/Test.hs0000644000000000000000000000106412633374457014711 0ustar0000000000000000{-# LANGUAGE QuasiQuotes #-} module Main where import Test.HUnit import Text.RawString.QQ import System.Exit multilineUnixNewlines :: String multilineUnixNewlines = [r|FOO BAR|] multilineWindowsNewlines :: String multilineWindowsNewlines = [r|FOO BAR|] main :: IO () main = defaultMain $ test [ "Windows newlines" ~: (multilineUnixNewlines ~=? multilineWindowsNewlines) ] defaultMain :: Test -> IO () defaultMain t = do cnts <- runTestTT t case failures cnts + errors cnts of 0 -> exitWith $ ExitSuccess n -> exitWith $ ExitFailure n raw-strings-qq-1.1/examples/0000755000000000000000000000000012633374460014266 5ustar0000000000000000raw-strings-qq-1.1/examples/RawRegex.hs0000644000000000000000000000112112633374460016341 0ustar0000000000000000{-# LANGUAGE QuasiQuotes #-} 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| Auto-generated html formated source

|]

main :: IO ()
main = do
  print multiline
  print ""
  print $ ((haystack =~ needle) :: String)