haskell-src-exts-qq 0.5.0 → 0.6.0
raw patch · 2 files changed
+31/−16 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- Language/Haskell/Exts/QQ.hs +15/−11
- haskell-src-exts-qq.cabal +16/−5
Language/Haskell/Exts/QQ.hs view
@@ -9,8 +9,15 @@ -- Names in patterns can also be antiquoted, using double parentheses. For -- instance: ----- > let f = Hs.name "foo" in [$dec| ((f)) x = x + x |]+-- > let x = Hs.name "n" in [hs| \ ((x)) -> $(Hs.Var (Hs.UnQual x)) + 1 |] --+-- Alternatively, one can use the double underscore syntax, useful when+-- antiquoting a function name as in the following:+--+-- > let f = "incr"+-- > fE = Hs.Var $ Hs.UnQual $ Hs.name f+-- > in [hs| let __f__ x = x + 1 in $fE 10 |]+-- -- In a pattern context, antiquotations use the same syntax. module Language.Haskell.Exts.QQ (hs, dec, ty, hsWithMode, decWithMode, tyWithMode) where@@ -21,7 +28,7 @@ import Language.Haskell.TH.Quote import Language.Haskell.TH.Lib import Data.Generics-import Data.List (intercalate)+import Data.List (intercalate, isPrefixOf, isSuffixOf) allExtensions :: Hs.ParseMode allExtensions = Hs.defaultParseMode{Hs.extensions = Hs.knownExtensions}@@ -86,23 +93,20 @@ antiquoteExp :: Data a => a -> Q Exp antiquoteExp t = dataToQa (conE . qualify) litE (foldl appE)- (const Nothing `extQ` antiE `extQ` antiP) t+ (const Nothing `extQ` antiE `extQ` antiP `extQ` antiN) t where antiE (Hs.SpliceExp (Hs.IdSplice v)) = Just $ varE $ mkName v antiE (Hs.SpliceExp (Hs.ParenSplice e)) = Just $ return $ Hs.toExp e antiE _ = Nothing antiP (Hs.PParen (Hs.PParen (Hs.PVar (Hs.Ident n)))) = Just $ appE [| Hs.PVar |] (varE (mkName n)) antiP _ = Nothing+ antiN (Hs.Ident n) | "__" `isPrefixOf` n, "__" `isSuffixOf` n =+ let nn = take (length n - 4) (drop 2 n)+ in Just $ appE [| Hs.Ident |] (varE (mkName nn))+ antiN _ = Nothing antiquotePat :: Data a => a -> Q Pat antiquotePat = dataToQa qualify litP conP (const Nothing `extQ` antiP)- where antiE (Hs.SpliceExp (Hs.IdSplice v)) = Just $ varP $ mkName v- antiE (Hs.SpliceExp (Hs.ParenSplice e)) =- case Hs.parsePat $ Hs.prettyPrint e of- Hs.ParseOk p -> Just $ return $ Hs.toPat p- Hs.ParseFailed _ err -> Just $ fail err- antiE _ = Nothing- antiP (Hs.PParen (Hs.PParen (Hs.PVar (Hs.Ident n)))) =+ where antiP (Hs.PParen (Hs.PParen (Hs.PVar (Hs.Ident n)))) = Just $ conP 'Hs.PVar [varP (mkName n)] antiP _ = Nothing-
haskell-src-exts-qq.cabal view
@@ -1,5 +1,5 @@ Name: haskell-src-exts-qq-Version: 0.5.0+Version: 0.6.0 Author: Mathieu Boespflug Maintainer: Mathieu Boespflug <mboes@tweag.net> Synopsis: A quasiquoter for haskell-src-exts.@@ -8,13 +8,24 @@ more concisely and legibly. This package supports: . * Antiquotations, denoted by stealing the splice syntax of- Template Haskell, for example @[$hs| $x ++ $(Hs.strE "bar") |]@.+ Template Haskell, for example @[hs| $x ++ $(Hs.strE "bar") |]@. Splices may not nested. .- * Antiquoting names in patterns. Names that are antiquoted appear- surrounded by double parentheses. For instance:+ * Antiquoting pattern variables in patterns, using double+ parentheses. For instance: .- > let f = Hs.name "foo" in [$hs| ((f)) x = x + x |]+ > let x = Hs.name "n" in [hs| \ ((x)) -> $(Hs.Var (Hs.UnQual x)) + 1 |]+ .+ * Antiquoting bound names. Names that are antiquoted appear+ surrounded by double underscores. For instance:+ .+ > let f = "incr"+ > fE = Hs.Var $ Hs.UnQual $ Hs.name f+ > in [hs| let __f__ x = x + 1 in $fE 10 |]+ .+ We need three different syntaxes for antiquotations, because we do+ not extend the haskell-src-exts parser in any way and the Template+ Haskell splicing syntax is only available in expression contexts. Category: Language License: BSD3 License-File: LICENSE