here (empty) → 1.0
raw patch · 4 files changed
+78/−0 lines, 4 filesdep +basedep +template-haskellsetup-changed
Dependencies added: base, template-haskell
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- here.cabal +19/−0
- src/Data/String/Here.hs +27/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2013, Taylor Hedberg++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 Taylor Hedberg 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
+ here.cabal view
@@ -0,0 +1,19 @@+name: here+version: 1.0+synopsis: Here docs via quasiquotation+description: Here docs via quasiquotation+license: BSD3+license-file: LICENSE+author: Taylor M. Hedberg+maintainer: t@tmh.cc+copyright: ©2013 Taylor M. Hedberg+homepage: https://github.com/tmhedberg/here+category: Data+build-type: Simple+cabal-version: >=1.8++library+ hs-source-dirs: src+ exposed-modules: Data.String.Here+ build-depends: base ==4.6.*, template-haskell+ ghc-options: -Wall
+ src/Data/String/Here.hs view
@@ -0,0 +1,27 @@+{-# OPTIONS_GHC -fno-warn-missing-fields #-}++-- | Here docs via quasiquotation+module Data.String.Here (here, hereLit) where++import Data.Char++import Language.Haskell.TH+import Language.Haskell.TH.Quote++-- | Quote a here doc, stripping leading and trailing whitespace+here :: QuasiQuoter+here = QuasiQuoter {quoteExp = stringE . trim}++-- | Quote a here doc literally, with no whitespace stripping+hereLit :: QuasiQuoter+hereLit = QuasiQuoter {quoteExp = stringE}++trim :: String -> String+trim = trimTail . dropWhile isSpace++trimTail :: String -> String+trimTail "" = ""+trimTail s = take (lastNonBlank s) s+ where lastNonBlank = (+1) . fst . foldl acc (0, 0)+ acc (l, n) c | isSpace c = (l, n + 1)+ | otherwise = (n, n + 1)