here 1.2.3 → 1.2.4
raw patch · 5 files changed
+35/−21 lines, 5 filesdep ~basedep ~mtl
Dependency ranges changed: base, mtl
Files
- LICENSE +1/−0
- here.cabal +4/−4
- src/Data/String/Here/Internal.hs +14/−1
- src/Data/String/Here/Interpolated.hs +15/−15
- src/Data/String/Here/Uninterpolated.hs +1/−1
LICENSE view
@@ -1,4 +1,5 @@ Copyright (c) 2013, Taylor Hedberg+Copyright (c) 2014, Google, Inc. All rights reserved.
here.cabal view
@@ -1,12 +1,12 @@ name: here-version: 1.2.3+version: 1.2.4 synopsis: Here docs & interpolated strings via quasiquotation description: Here docs & interpolated strings via quasiquotation license: BSD3 license-file: LICENSE author: Taylor M. Hedberg maintainer: t@tmh.cc-copyright: ©2013 Taylor M. Hedberg+copyright: ©2013 Taylor M. Hedberg, ©2014 Google Inc. homepage: https://github.com/tmhedberg/here category: Data build-type: Simple@@ -25,9 +25,9 @@ other-modules: Data.String.Here.Internal build-depends:- base >= 4.5 && < 4.7,+ base >= 4.5 && < 4.8, haskell-src-meta ==0.6.*,- mtl ==2.1.*,+ mtl >=2.1 && < 2.3, parsec ==3.1.*, template-haskell ghc-options: -Wall
src/Data/String/Here/Internal.hs view
@@ -1,7 +1,13 @@-module Data.String.Here.Internal (trim) where+{-# LANGUAGE NamedFieldPuns #-}+{-# OPTIONS_GHC -fno-warn-missing-fields #-} +module Data.String.Here.Internal (trim, quoteDependentFile) where+ import Data.Char +import Language.Haskell.TH.Quote+import Language.Haskell.TH.Syntax+ trim :: String -> String trim = trimTail . dropWhile isSpace @@ -11,3 +17,10 @@ where lastNonBlank = (+1) . fst . foldl acc (0, 0) acc (l, n) c | isSpace c = (l, n + 1) | otherwise = (n, n + 1)++quoteDependentFile :: QuasiQuoter -> QuasiQuoter+quoteDependentFile QuasiQuoter {quoteExp} =+ QuasiQuoter+ { quoteExp = \filename -> do addDependentFile filename+ runIO (readFile filename) >>= quoteExp+ }
src/Data/String/Here/Interpolated.hs view
@@ -30,9 +30,9 @@ , prevCharWasIdentChar :: Bool } -data QuoteState = None | Single Escaped | Double Escaped+data QuoteState = None | Single EscapeState | Double EscapeState -type Escaped = Bool+data EscapeState = Escaped | Unescaped -- | Quote a here doc with embedded antiquoted expressions --@@ -54,7 +54,7 @@ -- -- This enables usage as a simple template engine template :: QuasiQuoter-template = quoteFile i+template = quoteDependentFile i quoteInterp :: String -> Q Exp quoteInterp s = either (handleError s) combineParts (parseInterp s)@@ -113,20 +113,20 @@ '{' -> incBraceCt 1 >> next '}' | braceCt > 0 -> incBraceCt (-1) >> next | otherwise -> stepBack >> return (reverse $ tail consumed)- '\'' -> when (not prevCharWasIdentChar) (setQuoteState $ Single False)+ '\'' -> unless prevCharWasIdentChar (setQuoteState $ Single Unescaped) >> next- '"' -> setQuoteState (Double False) >> next+ '"' -> setQuoteState (Double Unescaped) >> next _ -> next- Single False -> do case c of '\\' -> setQuoteState (Single True)- '\'' -> setQuoteState None- _ -> return ()- next- Single True -> setQuoteState (Single False) >> next- Double False -> do case c of '\\' -> setQuoteState (Double True)- '"' -> setQuoteState None- _ -> return ()- next- Double True -> setQuoteState (Double False) >> next+ Single Unescaped -> do case c of '\\' -> setQuoteState (Single Escaped)+ '\'' -> setQuoteState None+ _ -> return ()+ next+ Single Escaped -> setQuoteState (Single Unescaped) >> next+ Double Unescaped -> do case c of '\\' -> setQuoteState (Double Escaped)+ '"' -> setQuoteState None+ _ -> return ()+ next+ Double Escaped -> setQuoteState (Double Unescaped) >> next stepBack = lift $ updateParserState (\s@State {..} -> s {statePos = incSourceColumn statePos (-1)})
src/Data/String/Here/Uninterpolated.hs view
@@ -18,4 +18,4 @@ -- | Splice a file's contents as a here doc hereFile :: QuasiQuoter-hereFile = quoteFile hereLit+hereFile = quoteDependentFile hereLit