packages feed

haskell-src-exts-qq 0.1 → 0.2

raw patch · 2 files changed

+40/−17 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

Language/Haskell/Exts/QQ.hs view
@@ -1,8 +1,21 @@+-- | This module defines quasiquoters for haskell-src-exts expressions and+-- declarations.+--+-- Antiquotations steal the splice syntax of Template Haskell, so for+-- example example 'x' appears antiquoted in @[hs| $x ++ $(Hs.strE \"bar\") |]@.+-- Expressions appearing inside parenthesized splices are limited to concrete+-- syntax expressible by Template Haskell's 'Exp' data type.+--+-- Names in patterns can also be antiquoted, using double parentheses. For+-- instance:+--+-- > let f = Hs.name "foo" in [hs| ((f)) x = x + x |]+--+-- In a pattern context, antiquotations use the same syntax.+ module Language.Haskell.Exts.QQ (hs, dec) where -import qualified Language.Haskell.Exts.Syntax as Hs-import qualified Language.Haskell.Exts.Parser as Hs-import qualified Language.Haskell.Exts.Extension as Hs+import qualified Language.Haskell.Exts as Hs import qualified Language.Haskell.Exts.Translate as Hs import Language.Haskell.TH.Syntax import Language.Haskell.TH.Quote@@ -14,10 +27,10 @@ hs = QuasiQuoter { quoteExp = Hs.parseExpWithMode                               Hs.defaultParseMode{Hs.extensions = Hs.knownExtensions}                                     `project` antiquoteExp-                  , quotePat = Hs.parsePat `project` antiquotePat+                 , quotePat = Hs.parsePat `project` antiquotePat #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 613-                  , quoteType = error "Unimplemented."-                  , quoteDec = error "Unimplemented."+                 , quoteType = error "Unimplemented."+                 , quoteDec = error "Unimplemented." #endif                  } @@ -29,7 +42,7 @@                   , quoteType = error "Unimplemented."                   , quoteDec = error "Unimplemented." #endif-                 }+                  }  project f k s = case f s of                   Hs.ParseOk x -> k x@@ -42,15 +55,15 @@ qualify :: Name -> Name -- Need special cases for constructors used in string literals. Assume nearly -- all else is a datatype defined in Syntax module of haskell-src-exts.-qualify n | ":" <- nameBase n = n-          | "[]" <- nameBase n = n-          | "Nothing" <- nameBase n = n-          | "Just" <- nameBase n = n-          | "SrcLoc" <- nameBase n = Name (mkOccName (nameBase n)) (flav "SrcLoc")-          | otherwise = Name (mkOccName (nameBase n)) (flav "Syntax")+qualify n | ":" <- nameBase n = '(:)+          | "[]" <- nameBase n = '[]+          | "Nothing" <- nameBase n = '[]+          | "Just" <- nameBase n = 'Just+          | "SrcLoc" <- nameBase n = 'Hs.SrcLoc+          | otherwise = Name (mkOccName (nameBase n)) flavour     where pkg = "haskell-src-exts-" ++ VERSION_haskell_src_exts-          flav mod = NameG VarName (mkPkgName pkg)-                     (mkModName ("Language.Haskell.Exts." ++ mod))+          flavour = NameG VarName (mkPkgName pkg)+                    (mkModName "Language.Haskell.Exts.Syntax")  antiquoteExp :: Data a => a -> Q Exp antiquoteExp t = dataToQa (conE . qualify) litE (foldl appE)@@ -63,4 +76,14 @@           antiP _ = Nothing  antiquotePat :: Data a => a -> Q Pat-antiquotePat = dataToQa qualify litP conP (const Nothing)+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)))) =+              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.1+Version:        0.2 Author:         Mathieu Boespflug Maintainer:     Mathieu Boespflug <mboes@tweag.net> Synopsis:       A quasiquoter for haskell-src-exts.