packages feed

ghc-source-gen 0.2.0.1 → 0.3.0.0

raw patch · 6 files changed

+44/−6 lines, 6 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ GHC.SourceGen.Name: nameToStr :: Name -> OccNameStr
+ GHC.SourceGen.Name: occNameToStr :: OccName -> OccNameStr

Files

ChangeLog.md view
@@ -1,5 +1,10 @@ # Changelog for haskell-syntax +## 0.3.0.0+- Add `occNameToStr` and `nameToStr` to convert from the GHC types.+- Make `listPromotedTy` emit the promoted form `'[..]`,+  to distinguish from regular list types of zero or one elements.+ ## 0.2.0.1 - Bump upper-bound to allow `QuickCheck-2.13`. 
ghc-source-gen.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: fd532959021d2e779b8bb178f99ac15ef05fbcafafe9f46369ebe284a72d65e1+-- hash: df3442cc801aef91cf974539ddc9628924856c16db7eaddc3ca0811136afa6e2  name:           ghc-source-gen-version:        0.2.0.1+version:        0.3.0.0 synopsis:       Constructs Haskell syntax trees for the GHC API. description:    @ghc-source-gen@ is a library for generating Haskell source code.                 It uses the <https://hackage.haskell.org/package/ghc ghc> library
src/GHC/SourceGen/Name.hs view
@@ -20,6 +20,8 @@     , OccNameStr     , occNameStrToString     , occNameStrNamespace+    , occNameToStr+    , nameToStr       -- ModuleNameStr     , ModuleNameStr(..)     , moduleNameStrToString@@ -28,6 +30,8 @@ import FastString (unpackFS) import Module (moduleNameString) import GHC.SourceGen.Name.Internal+import OccName (OccName, occNameFS, occNameSpace, isVarNameSpace)+import Name (Name, nameOccName)  unqual :: OccNameStr -> RdrNameStr unqual = UnqualStr@@ -48,3 +52,18 @@ rdrNameStrToString (UnqualStr o) = occNameStrToString o rdrNameStrToString (QualStr m o) =     moduleNameStrToString m ++ '.' : occNameStrToString o++-- | Converts a GHC 'OccName' to an 'OccNameStr'.  Ignores whether the input+-- came from the namespace of types or of values.+occNameToStr :: OccName -> OccNameStr+occNameToStr o = OccNameStr n (occNameFS o)+  where+    n = if isVarNameSpace $ occNameSpace o+            then Value+            else Constructor++-- | Converts from a GHC 'Name' to an 'OccNameStr'.  Ignores whether+-- the input came from the namespace of types or of values, as well+-- as any other information about where the name came from.+nameToStr :: Name -> OccNameStr+nameToStr = occNameToStr  . nameOccName
src/GHC/SourceGen/Type.hs view
@@ -40,7 +40,9 @@ listTy = noExt HsListTy . builtLoc  listPromotedTy :: [HsType'] -> HsType'-listPromotedTy = withPlaceHolder (noExt HsExplicitListTy notPromoted) . map builtLoc+-- Lists of two or more elements don't need the explicit tick (`'`).+-- But for consistency, just always add it.+listPromotedTy = withPlaceHolder (noExt HsExplicitListTy promoted) . map builtLoc  -- | A function type. --
tests/name_test.hs view
@@ -3,6 +3,8 @@  import GHC.SourceGen.Name +import OccName+ import Data.List (intercalate) import Data.String (fromString) import Test.Tasty@@ -41,6 +43,16 @@         occNameStrNamespace (fromString n) === Value     , testProperty "punctuation" $ forAll genOp $ \n ->         occNameStrNamespace (fromString n) === Value+    , testGroup "occNameToStr"+        [ testProperty "var" $ forAll genLowerName $ \n ->+            occNameToStr (mkVarOcc n) === fromString n+        , testProperty "data" $ forAll genUpperName $ \n ->+            occNameToStr (mkDataOcc n) === fromString n+        , testProperty "tyVar" $ forAll genLowerName $ \n ->+            occNameToStr (mkTyVarOcc n) === fromString n+        , testProperty "cls" $ forAll genUpperName $ \n ->+            occNameToStr (mkClsOcc n) === fromString n+        ]     ]  genUpperName, genLowerName, genOp :: Gen String
tests/pprint_test.hs view
@@ -95,9 +95,9 @@         [ "()" :~ unit ]    , test "list"         [ "[x]" :~ listTy (var "x")-        , "[]" :~ listPromotedTy []-        , "[x]" :~ listPromotedTy [var "x"]-        , "[y, z]" :~ listPromotedTy [var "y", var "z"]+        , "'[]" :~ listPromotedTy []+        , "'[x]" :~ listPromotedTy [var "x"]+        , "'[y, z]" :~ listPromotedTy [var "y", var "z"]         ]     , test "tyPromotedVar"         -- For some reason, older GHC pretty-printed an extra space.