packages feed

record-dot-preprocessor 0.2.10 → 0.2.11

raw patch · 4 files changed

+19/−10 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

CHANGES.txt view
@@ -1,5 +1,7 @@ Changelog for record-dot-preprocessor +0.2.11, released 2021-05-28+    #41, use qualified names in the plugin 0.2.10, released 2021-03-01     #40, compatibility with qualified QuasiQuotes     Emit LINE pragmas slightly earlier in some cases
README.md view
@@ -56,3 +56,7 @@ ## Any advice for using this magic?  The most important consideration is that all records used by `a.b` or `a{b=c}` syntax _must_ have `HasField` instances, which requires either running the preprocessor/plugin over the module defining them, or writing orphan instances by hand. To use records which don't have such instances use normal selector functions (e.g. `b a`) and insert a space before the `{` (e.g. `a {b=c}`).++## Limitations++* The preprocessor doesn't deal with anti-quoted expressions inside `QuasiQuotes`, e.g. `[D.pgSQL|$ SELECT ${dummy.x} :: text|]`.
plugin/RecordDotPreprocessor.hs view
@@ -55,7 +55,7 @@  onModule :: Module -> Module onModule x = x { hsmodImports = onImports $ hsmodImports x-               , hsmodDecls = concatMap onDecl $ hsmodDecls x+               , hsmodDecls = concatMap (onDecl (unLoc <$> hsmodName x)) $ hsmodDecls x                }  @@ -108,19 +108,19 @@         vX = GHC.mkRdrUnqual $ GHC.mkVarOcc "x"  -onDecl :: LHsDecl GhcPs -> [LHsDecl GhcPs]-onDecl o@(L _ (GHC.TyClD _ x)) = o :+onDecl :: Maybe GHC.ModuleName -> LHsDecl GhcPs -> [LHsDecl GhcPs]+onDecl modName o@(L _ (GHC.TyClD _ x)) = o :     [ noL $ InstD noE $ instanceTemplate field (unLoc record) (unbang typ)-    | let fields = nubOrdOn (\(_,_,x,_) -> GHC.occNameFS $ GHC.rdrNameOcc $ unLoc $ rdrNameFieldOcc x) $ getFields x+    | let fields = nubOrdOn (\(_,_,x,_) -> GHC.occNameFS $ GHC.rdrNameOcc $ unLoc $ rdrNameFieldOcc x) $ getFields modName x     , (record, _, field, typ) <- fields]-onDecl x = [descendBi onExp x]+onDecl _ x = [descendBi onExp x]  unbang :: HsType GhcPs -> HsType GhcPs unbang (HsBangTy _ _ x) = unLoc x unbang x = x -getFields :: TyClDecl GhcPs -> [(LHsType GhcPs, IdP GhcPs, FieldOcc GhcPs, HsType GhcPs)]-getFields DataDecl{tcdDataDefn=HsDataDefn{..}, ..} = concatMap ctor dd_cons+getFields :: Maybe GHC.ModuleName -> TyClDecl GhcPs -> [(LHsType GhcPs, IdP GhcPs, FieldOcc GhcPs, HsType GhcPs)]+getFields modName DataDecl{tcdDataDefn=HsDataDefn{..}, ..} = concatMap ctor dd_cons     where         ctor (L _ ConDeclH98{con_args=RecCon (L _ fields),con_name=L _ name}) = concatMap (field name) fields         ctor (L _ ConDeclGADT{con_args=RecCon (L _ fields),con_names=names}) = concat [field name fld | L _ name <- names, fld <- fields]@@ -130,8 +130,11 @@         field _ _ = error "unknown field declaration in getFields"          -- A value of this data declaration will have this type.-        result = foldl (\x y -> noL $ HsAppTy noE x $ hsLTyVarBndrToType y) (noL $ HsTyVar noE GHC.NotPromoted tcdLName) $ hsq_explicit tcdTyVars-getFields _ = []+        result = foldl (\x y -> noL $ HsAppTy noE x $ hsLTyVarBndrToType y) (noL $ HsTyVar noE GHC.NotPromoted tyName) $ hsq_explicit tcdTyVars+        tyName = case (tcdLName, modName) of+            (L l (GHC.Unqual name), Just modName') -> L l (GHC.Qual modName' name)+            _ -> tcdLName+getFields _ _ = []   -- At this point infix expressions have not had associativity/fixity applied, so they are bracketed
record-dot-preprocessor.cabal view
@@ -1,7 +1,7 @@ cabal-version:      >= 1.18 build-type:         Simple name:               record-dot-preprocessor-version:            0.2.10+version:            0.2.11 license:            BSD3 x-license:          BSD-3-Clause OR Apache-2.0 license-file:       LICENSE