ghc-lib-parser-ex 9.8.0.2 → 9.10.0.0
raw patch · 8 files changed
+330/−329 lines, 8 filesdep ~ghcdep ~ghc-lib-parserPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: ghc, ghc-lib-parser
API changes (from Hackage documentation)
- Language.Haskell.GhclibParserEx.Dump: BlankEpAnnotations :: BlankEpAnnotations
- Language.Haskell.GhclibParserEx.Dump: BlankSrcSpan :: BlankSrcSpan
- Language.Haskell.GhclibParserEx.Dump: BlankSrcSpanFile :: BlankSrcSpan
- Language.Haskell.GhclibParserEx.Dump: NoBlankEpAnnotations :: BlankEpAnnotations
- Language.Haskell.GhclibParserEx.Dump: NoBlankSrcSpan :: BlankSrcSpan
- Language.Haskell.GhclibParserEx.Dump: data () => BlankEpAnnotations
- Language.Haskell.GhclibParserEx.Dump: data () => BlankSrcSpan
- Language.Haskell.GhclibParserEx.Dump: showAstData :: Data a => BlankSrcSpan -> BlankEpAnnotations -> a -> SDoc
+ Language.Haskell.GhclibParserEx.GHC.Hs.Dump: BlankEpAnnotations :: BlankEpAnnotations
+ Language.Haskell.GhclibParserEx.GHC.Hs.Dump: BlankSrcSpan :: BlankSrcSpan
+ Language.Haskell.GhclibParserEx.GHC.Hs.Dump: BlankSrcSpanFile :: BlankSrcSpan
+ Language.Haskell.GhclibParserEx.GHC.Hs.Dump: NoBlankEpAnnotations :: BlankEpAnnotations
+ Language.Haskell.GhclibParserEx.GHC.Hs.Dump: NoBlankSrcSpan :: BlankSrcSpan
+ Language.Haskell.GhclibParserEx.GHC.Hs.Dump: data () => BlankEpAnnotations
+ Language.Haskell.GhclibParserEx.GHC.Hs.Dump: data () => BlankSrcSpan
+ Language.Haskell.GhclibParserEx.GHC.Hs.Dump: showAstData :: Data a => BlankSrcSpan -> BlankEpAnnotations -> a -> SDoc
- Language.Haskell.GhclibParserEx.GHC.Hs.Expr: isStrictMatch :: HsMatchContext GhcPs -> Bool
+ Language.Haskell.GhclibParserEx.GHC.Hs.Expr: isStrictMatch :: HsMatchContext (LocatedN RdrName) -> Bool
Files
- ChangeLog.md +5/−0
- README.md +2/−2
- cbits/ghclib_api.h +8/−3
- ghc-lib-parser-ex.cabal +67/−85
- src/Language/Haskell/GhclibParserEx/Dump.hs +6/−237
- src/Language/Haskell/GhclibParserEx/GHC/Hs/Dump.hs +240/−0
- src/Language/Haskell/GhclibParserEx/GHC/Hs/ExtendInstances.hs +1/−1
- test/Test.hs +1/−1
ChangeLog.md view
@@ -1,5 +1,10 @@ # Changelog for ghc-lib-parser-ex +## unreleased+- Deprecate `Dump`+- New module `GHC.Hs.Dump`+- Add support for ghc-9.10 series: `GHCLIB_API_910`+ ## 9.8.0.2 released - Fix broken cpp in `isStrictMatch`
README.md view
@@ -1,5 +1,5 @@-# ghc-lib-parser-ex [](http://opensource.org/licenses/BSD-3-Clause) [](https://hackage.haskell.org/package/ghc-lib-parser-ex) [](https://www.stackage.org/package/ghc-lib-parser-ex) [](https://shayne-fletcher.visualstudio.com/ghc-lib-parser-ex/_build/latest?definitionId=1&branchName=master)-Copyright © 2020-2022 Shayne Fletcher. All rights reserved.+# ghc-lib-parser-ex [](http://opensource.org/licenses/BSD-3-Clause) [](https://hackage.haskell.org/package/ghc-lib-parser-ex) [](https://www.stackage.org/package/ghc-lib-parser-ex) [](https://shayne-fletcher.visualstudio.com/ghc-lib-parser-ex/_build/latest?definitionId=1&branchName=master)[](https://github.com/shayne-fletcher/ghc-lib-parser-ex/actions/workflows/main.yml)+Copyright © 2020-2024 Shayne Fletcher. All rights reserved. SPDX-License-Identifier: BSD-3-Clause The `ghc-lib-parser-ex` package contains GHC API parse tree utilities. It works with or without [`ghc-lib-parser`](https://github.com/digital-asset/ghc-lib).
cbits/ghclib_api.h view
@@ -1,12 +1,13 @@ /*-Copyright (c) 2020 - 2023 Shayne Fletcher. All rights reserved.+Copyright (c) 2020 - 2024 Shayne Fletcher. All rights reserved. SPDX-License-Identifier: BSD-3-Clause. */ #if !defined(GHCLIB_API_H) # define GHCLIB_API_H -# if !(defined (GHC_9_10) \+# if !(defined (GHC_9_12) \+ || defined (GHC_9_10) \ || defined (GHC_9_8) \ || defined (GHC_9_6) \ || defined (GHC_9_4) \@@ -16,6 +17,8 @@ || defined (GHC_8_8)) # if defined (MIN_VERSION_ghc_lib_parser) # if !MIN_VERSION_ghc_lib_parser ( 1, 0, 0)+# define GHC_9_12+# elif MIN_VERSION_ghc_lib_parser (9, 10, 0) # define GHC_9_10 # elif MIN_VERSION_ghc_lib_parser (9, 8, 0) # define GHC_9_8@@ -35,7 +38,9 @@ # error Unsupported GHC API version # endif # else-# if __GLASGOW_HASKELL__ == 909+# if __GLASGOW_HASKELL__ == 911+# define GHC_9_12+# elif __GLASGOW_HASKELL__ == 910 # define GHC_9_10 # elif __GLASGOW_HASKELL__ == 908 # define GHC_9_8
ghc-lib-parser-ex.cabal view
@@ -1,21 +1,19 @@-cabal-version: 1.18-name: ghc-lib-parser-ex-version: 9.8.0.2-description: Please see the README on GitHub at <https://github.com/shayne-fletcher/ghc-lib-parser-ex#readme>-homepage: https://github.com/shayne-fletcher/ghc-lib-parser-ex#readme-bug-reports: https://github.com/shayne-fletcher/ghc-lib-parser-ex/issues-author: Shayne Fletcher-maintainer: shayne@shaynefletcher.org-copyright: Copyright © 2020-2022 Shayne Fletcher. All rights reserved.-license: BSD3+cabal-version: 3.4+name: ghc-lib-parser-ex+version: 9.10.0.0+description: Please see the README on GitHub at <https://github.com/shayne-fletcher/ghc-lib-parser-ex#readme>+homepage: https://github.com/shayne-fletcher/ghc-lib-parser-ex#readme+bug-reports: https://github.com/shayne-fletcher/ghc-lib-parser-ex/issues+author: Shayne Fletcher+maintainer: shayne@shaynefletcher.org+copyright: Copyright © 2020-2024 Shayne Fletcher. All rights reserved.+license: BSD-3-Clause license-file: LICENSE-category: Development-synopsis: Algorithms on GHC parse trees-build-type: Simple+category: Development+synopsis: Programming with GHC parse trees+build-type: Simple extra-source-files:- README.md- ChangeLog.md- cbits/ghclib_api.h+ README.md ChangeLog.md cbits/ghclib_api.h source-repository head type: git@@ -29,9 +27,48 @@ flag no-ghc-lib default: False manual: True- description: Force dependency on native ghc-libs+ description: Do not link ghc-lib. Use the native GHC libs +common base+ default-language: Haskell2010+ ghc-options:+ -Wall -Wincomplete-record-updates+ -Wredundant-constraints -Widentities+ -Wno-simplifiable-class-constraints+ build-depends:+ base >=4.7 && <5++common ghc_libs+ include-dirs: cbits+ default-extensions: CPP+ if flag(auto) && impl(ghc >= 9.10.0) && impl(ghc < 9.11.0)+ build-depends:+ ghc == 9.10.*,+ ghc-boot-th,+ ghc-boot+ else+ if flag(auto)+ build-depends:+ ghc-lib-parser == 9.10.*+ else+ if flag(no-ghc-lib)+ build-depends:+ ghc == 9.10.*,+ ghc-boot-th,+ ghc-boot+ else+ build-depends:+ ghc-lib-parser == 9.10.*++common lib+ import: base, ghc_libs+ build-depends:+ uniplate >= 1.5,+ bytestring >= 0.10.8.2,+ containers >= 0.5.8.1+ library+ import: lib exposed-modules: Language.Haskell.GhclibParserEx.Dump Language.Haskell.GhclibParserEx.Fixity@@ -39,6 +76,7 @@ Language.Haskell.GhclibParserEx.GHC.Driver.Flags Language.Haskell.GhclibParserEx.GHC.Driver.Session Language.Haskell.GhclibParserEx.GHC.Hs+ Language.Haskell.GhclibParserEx.GHC.Hs.Dump Language.Haskell.GhclibParserEx.GHC.Hs.Expr Language.Haskell.GhclibParserEx.GHC.Hs.Pat Language.Haskell.GhclibParserEx.GHC.Hs.Type@@ -50,76 +88,20 @@ Language.Haskell.GhclibParserEx.GHC.Parser Language.Haskell.GhclibParserEx.GHC.Types.Name.Reader Language.Haskell.GhclibParserEx.GHC.Utils.Outputable- other-modules:- Paths_ghc_lib_parser_ex- hs-source-dirs:- src+ autogen-modules: Paths_ghc_lib_parser_ex+ other-modules: Paths_ghc_lib_parser_ex+ hs-source-dirs: src++common test+ import: lib build-depends:- base >=4.7 && <5,- uniplate >= 1.5,- bytestring >= 0.10.8.2,- containers >= 0.5.8.1- if flag(auto) && impl(ghc >= 9.8.0) && impl(ghc < 9.9.0)- build-depends:- ghc == 9.8.*,- ghc-boot-th,- ghc-boot- else- if flag(auto)- build-depends:- ghc-lib-parser == 9.8.*- else- if flag(no-ghc-lib)- build-depends:- ghc == 9.8.*,- ghc-boot-th,- ghc-boot- else- build-depends:- ghc-lib-parser == 9.8.*- include-dirs:- cbits- install-includes:- cbits/ghclib_api.h- default-language: Haskell2010- default-extensions: CPP+ tasty >= 1.2, tasty-hunit >= 0.10.0, directory >= 1.3.3,+ filepath >= 1.4.2, extra >=1.6, uniplate >= 1.6.12,+ ghc-lib-parser-ex test-suite ghc-lib-parser-ex-test+ import: test type: exitcode-stdio-1.0- main-is:- Test.hs- other-modules:- Paths_ghc_lib_parser_ex- hs-source-dirs:- test- include-dirs:- cbits ghc-options: -threaded -rtsopts -with-rtsopts=-N- build-depends:- base >=4.7 && <5- , tasty >= 1.2- , tasty-hunit >= 0.10.0- , directory >= 1.3.3- , filepath >= 1.4.2- , extra >=1.6- , uniplate >= 1.6.12- , ghc-lib-parser-ex- if flag(auto) && impl(ghc >= 9.8.0) && impl(ghc < 9.9.0)- build-depends:- ghc == 9.8.*,- ghc-boot-th,- ghc-boot- else- if flag(auto)- build-depends:- ghc-lib-parser == 9.8.*- else- if flag(no-ghc-lib)- build-depends:- ghc == 9.8.*,- ghc-boot-th,- ghc-boot- else- build-depends:- ghc-lib-parser == 9.8.*- default-language: Haskell2010+ main-is: Test.hs+ hs-source-dirs: test
src/Language/Haskell/GhclibParserEx/Dump.hs view
@@ -1,240 +1,9 @@--- Copyright (c) 2020-2023, Shayne Fletcher. All rights reserved.+-- Copyright (c) 2024, Shayne Fletcher. All rights reserved. -- SPDX-License-Identifier: BSD-3-Clause.-{--(c) The University of Glasgow 2006-(c) The GRASP/AQUA Project, Glasgow University, 1992-1998--}-{- HLINT ignore -} -- Not our code.-{-# LANGUAGE NoImplicitPrelude #-}-{-# LANGUAGE RankNTypes #-}-{-# LANGUAGE ScopedTypeVariables #-}-#include "ghclib_api.h"-module Language.Haskell.GhclibParserEx.Dump(- showAstData- , BlankSrcSpan(..)-#if ! (defined (GHC_9_0) || defined (GHC_8_10) || defined (GHC_8_8) )- , BlankEpAnnotations(..)-#endif-) where -#if !defined(MIN_VERSION_ghc_lib_parser)--- Pay attenion: This is the native GHC case.--# if defined (GHC_8_8)-import HsDumpAst-# else-import GHC.Hs.Dump-# endif--#else--- Once again, attenion please. This is the ghc-lib-parser case.--# if !defined (GHC_8_8)-import GHC.Hs.Dump-# else--- In the 8.8 case reproduce the implementation (the original ended up--- in ghc-lib).--import Prelude as X hiding ((<>))--import Data.Data hiding (Fixity)-import Bag-import BasicTypes-import FastString-import NameSet-import Name-import DataCon-import SrcLoc-import HsSyn-import OccName hiding (occName)-import Var-import Module-import Outputable--import qualified Data.ByteString as B--data BlankSrcSpan = BlankSrcSpan | NoBlankSrcSpan- deriving (Eq,Show)---- | Show a GHC syntax tree. This parameterised because it is also used for--- comparing ASTs in ppr roundtripping tests, where the SrcSpan's are blanked--- out, to avoid comparing locations, only structure-showAstData :: Data a => BlankSrcSpan -> a -> SDoc-showAstData b a0 = blankLine $$ showAstData' a0- where- showAstData' :: Data a => a -> SDoc- showAstData' =- generic- `ext1Q` list- `extQ` string `extQ` fastString `extQ` srcSpan- `extQ` lit `extQ` litr `extQ` litt- `extQ` bytestring- `extQ` name `extQ` occName `extQ` moduleName `extQ` var- `extQ` dataCon- `extQ` bagName `extQ` bagRdrName `extQ` bagVar `extQ` nameSet- `extQ` fixity- `ext2Q` located-- where generic :: Data a => a -> SDoc- generic t = parens $ text (showConstr (toConstr t))- $$ vcat (gmapQ showAstData' t)-- string :: String -> SDoc- string = text . normalize_newlines . show-- fastString :: FastString -> SDoc- fastString s = braces $- text "FastString: "- <> text (normalize_newlines . show $ s)-- bytestring :: B.ByteString -> SDoc- bytestring = text . normalize_newlines . show-- list [] = brackets empty- list [x] = brackets (showAstData' x)- list (x1 : x2 : xs) = (text "[" <> showAstData' x1)- $$ go x2 xs- where- go y [] = text "," <> showAstData' y <> text "]"- go y1 (y2 : ys) = (text "," <> showAstData' y1) $$ go y2 ys-- -- Eliminate word-size dependence- lit :: HsLit GhcPs -> SDoc- lit (HsWordPrim s x) = numericLit "HsWord{64}Prim" x s- lit (HsWord64Prim s x) = numericLit "HsWord{64}Prim" x s- lit (HsIntPrim s x) = numericLit "HsInt{64}Prim" x s- lit (HsInt64Prim s x) = numericLit "HsInt{64}Prim" x s- lit l = generic l-- litr :: HsLit GhcRn -> SDoc- litr (HsWordPrim s x) = numericLit "HsWord{64}Prim" x s- litr (HsWord64Prim s x) = numericLit "HsWord{64}Prim" x s- litr (HsIntPrim s x) = numericLit "HsInt{64}Prim" x s- litr (HsInt64Prim s x) = numericLit "HsInt{64}Prim" x s- litr l = generic l-- litt :: HsLit GhcTc -> SDoc- litt (HsWordPrim s x) = numericLit "HsWord{64}Prim" x s- litt (HsWord64Prim s x) = numericLit "HsWord{64}Prim" x s- litt (HsIntPrim s x) = numericLit "HsInt{64}Prim" x s- litt (HsInt64Prim s x) = numericLit "HsInt{64}Prim" x s- litt l = generic l-- numericLit :: String -> Integer -> SourceText -> SDoc- numericLit tag x s = braces $ hsep [ text tag- , generic x- , generic s ]-- name :: Name -> SDoc- name nm = braces $ text "Name: " <> ppr nm-- occName n = braces $- text "OccName: "- <> text (OccName.occNameString n)-- moduleName :: ModuleName -> SDoc- moduleName m = braces $ text "ModuleName: " <> ppr m-- srcSpan :: SrcSpan -> SDoc- srcSpan ss = case b of- BlankSrcSpan -> text "{ ss }"- NoBlankSrcSpan -> braces $ char ' ' <>- (hang (ppr ss) 1- -- TODO: show annotations here- (text ""))-- var :: Var -> SDoc- var v = braces $ text "Var: " <> ppr v-- dataCon :: DataCon -> SDoc- dataCon c = braces $ text "DataCon: " <> ppr c-- bagRdrName:: Bag (Located (HsBind GhcPs)) -> SDoc- bagRdrName bg = braces $- text "Bag(Located (HsBind GhcPs)):"- $$ (list . bagToList $ bg)-- bagName :: Bag (Located (HsBind GhcRn)) -> SDoc- bagName bg = braces $- text "Bag(Located (HsBind Name)):"- $$ (list . bagToList $ bg)-- bagVar :: Bag (Located (HsBind GhcTc)) -> SDoc- bagVar bg = braces $- text "Bag(Located (HsBind Var)):"- $$ (list . bagToList $ bg)-- nameSet ns = braces $- text "NameSet:"- $$ (list . nameSetElemsStable $ ns)-- fixity :: Fixity -> SDoc- fixity fx = braces $- text "Fixity: "- <> ppr fx-- located :: (Data b,Data loc) => GenLocated loc b -> SDoc- located (L ss a) = parens $- case cast ss of- Just (s :: SrcSpan) ->- srcSpan s- Nothing -> text "nnnnnnnn"- $$ showAstData' a--normalize_newlines :: String -> String-normalize_newlines ('\\':'r':'\\':'n':xs) = '\\':'n':normalize_newlines xs-normalize_newlines (x:xs) = x:normalize_newlines xs-normalize_newlines [] = []--{--************************************************************************-* *-* Copied from syb-* *-************************************************************************--}----- | The type constructor for queries-newtype Q q x = Q { unQ :: x -> q }---- | Extend a generic query by a type-specific case-extQ :: ( Typeable a- , Typeable b- )- => (a -> q)- -> (b -> q)- -> a- -> q-extQ f g a = maybe (f a) g (cast a)---- | Type extension of queries for type constructors-ext1Q :: (Data d, Typeable t)- => (d -> q)- -> (forall e. Data e => t e -> q)- -> d -> q-ext1Q def ext = unQ ((Q def) `ext1` (Q ext))----- | Type extension of queries for type constructors-ext2Q :: (Data d, Typeable t)- => (d -> q)- -> (forall d1 d2. (Data d1, Data d2) => t d1 d2 -> q)- -> d -> q-ext2Q def ext = unQ ((Q def) `ext2` (Q ext))---- | Flexible type extension-ext1 :: (Data a, Typeable t)- => c a- -> (forall d. Data d => c (t d))- -> c a-ext1 def ext = maybe def id (dataCast1 ext)+module Language.Haskell.GhclibParserEx.Dump+ {-# DEPRECATED "Use Language.Haskell.GhclibParserEx.GHC.Hs.Dump instead" #-} (+ module Language.Haskell.GhclibParserEx.GHC.Hs.Dump+ ) where --- | Flexible type extension-ext2 :: (Data a, Typeable t)- => c a- -> (forall d1 d2. (Data d1, Data d2) => c (t d1 d2))- -> c a-ext2 def ext = maybe def id (dataCast2 ext)-# endif-#endif+import Language.Haskell.GhclibParserEx.GHC.Hs.Dump
+ src/Language/Haskell/GhclibParserEx/GHC/Hs/Dump.hs view
@@ -0,0 +1,240 @@+-- Copyright (c) 2020-2023, Shayne Fletcher. All rights reserved.+-- SPDX-License-Identifier: BSD-3-Clause.+{-+(c) The University of Glasgow 2006+(c) The GRASP/AQUA Project, Glasgow University, 1992-1998+-}+{- HLINT ignore -} -- Not our code.+{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE ScopedTypeVariables #-}+#include "ghclib_api.h"+module Language.Haskell.GhclibParserEx.GHC.Hs.Dump(+ showAstData+ , BlankSrcSpan(..)+#if ! (defined (GHC_9_0) || defined (GHC_8_10) || defined (GHC_8_8) )+ , BlankEpAnnotations(..)+#endif+) where++#if !defined(MIN_VERSION_ghc_lib_parser)+-- Pay attenion: This is the native GHC case.++# if defined (GHC_8_8)+import HsDumpAst+# else+import GHC.Hs.Dump+# endif++#else+-- Once again, attenion please. This is the ghc-lib-parser case.++# if !defined (GHC_8_8)+import GHC.Hs.Dump+# else+-- In the 8.8 case reproduce the implementation (the original ended up+-- in ghc-lib).++import Prelude as X hiding ((<>))++import Data.Data hiding (Fixity)+import Bag+import BasicTypes+import FastString+import NameSet+import Name+import DataCon+import SrcLoc+import HsSyn+import OccName hiding (occName)+import Var+import Module+import Outputable++import qualified Data.ByteString as B++data BlankSrcSpan = BlankSrcSpan | NoBlankSrcSpan+ deriving (Eq,Show)++-- | Show a GHC syntax tree. This parameterised because it is also used for+-- comparing ASTs in ppr roundtripping tests, where the SrcSpan's are blanked+-- out, to avoid comparing locations, only structure+showAstData :: Data a => BlankSrcSpan -> a -> SDoc+showAstData b a0 = blankLine $$ showAstData' a0+ where+ showAstData' :: Data a => a -> SDoc+ showAstData' =+ generic+ `ext1Q` list+ `extQ` string `extQ` fastString `extQ` srcSpan+ `extQ` lit `extQ` litr `extQ` litt+ `extQ` bytestring+ `extQ` name `extQ` occName `extQ` moduleName `extQ` var+ `extQ` dataCon+ `extQ` bagName `extQ` bagRdrName `extQ` bagVar `extQ` nameSet+ `extQ` fixity+ `ext2Q` located++ where generic :: Data a => a -> SDoc+ generic t = parens $ text (showConstr (toConstr t))+ $$ vcat (gmapQ showAstData' t)++ string :: String -> SDoc+ string = text . normalize_newlines . show++ fastString :: FastString -> SDoc+ fastString s = braces $+ text "FastString: "+ <> text (normalize_newlines . show $ s)++ bytestring :: B.ByteString -> SDoc+ bytestring = text . normalize_newlines . show++ list [] = brackets empty+ list [x] = brackets (showAstData' x)+ list (x1 : x2 : xs) = (text "[" <> showAstData' x1)+ $$ go x2 xs+ where+ go y [] = text "," <> showAstData' y <> text "]"+ go y1 (y2 : ys) = (text "," <> showAstData' y1) $$ go y2 ys++ -- Eliminate word-size dependence+ lit :: HsLit GhcPs -> SDoc+ lit (HsWordPrim s x) = numericLit "HsWord{64}Prim" x s+ lit (HsWord64Prim s x) = numericLit "HsWord{64}Prim" x s+ lit (HsIntPrim s x) = numericLit "HsInt{64}Prim" x s+ lit (HsInt64Prim s x) = numericLit "HsInt{64}Prim" x s+ lit l = generic l++ litr :: HsLit GhcRn -> SDoc+ litr (HsWordPrim s x) = numericLit "HsWord{64}Prim" x s+ litr (HsWord64Prim s x) = numericLit "HsWord{64}Prim" x s+ litr (HsIntPrim s x) = numericLit "HsInt{64}Prim" x s+ litr (HsInt64Prim s x) = numericLit "HsInt{64}Prim" x s+ litr l = generic l++ litt :: HsLit GhcTc -> SDoc+ litt (HsWordPrim s x) = numericLit "HsWord{64}Prim" x s+ litt (HsWord64Prim s x) = numericLit "HsWord{64}Prim" x s+ litt (HsIntPrim s x) = numericLit "HsInt{64}Prim" x s+ litt (HsInt64Prim s x) = numericLit "HsInt{64}Prim" x s+ litt l = generic l++ numericLit :: String -> Integer -> SourceText -> SDoc+ numericLit tag x s = braces $ hsep [ text tag+ , generic x+ , generic s ]++ name :: Name -> SDoc+ name nm = braces $ text "Name: " <> ppr nm++ occName n = braces $+ text "OccName: "+ <> text (OccName.occNameString n)++ moduleName :: ModuleName -> SDoc+ moduleName m = braces $ text "ModuleName: " <> ppr m++ srcSpan :: SrcSpan -> SDoc+ srcSpan ss = case b of+ BlankSrcSpan -> text "{ ss }"+ NoBlankSrcSpan -> braces $ char ' ' <>+ (hang (ppr ss) 1+ -- TODO: show annotations here+ (text ""))++ var :: Var -> SDoc+ var v = braces $ text "Var: " <> ppr v++ dataCon :: DataCon -> SDoc+ dataCon c = braces $ text "DataCon: " <> ppr c++ bagRdrName:: Bag (Located (HsBind GhcPs)) -> SDoc+ bagRdrName bg = braces $+ text "Bag(Located (HsBind GhcPs)):"+ $$ (list . bagToList $ bg)++ bagName :: Bag (Located (HsBind GhcRn)) -> SDoc+ bagName bg = braces $+ text "Bag(Located (HsBind Name)):"+ $$ (list . bagToList $ bg)++ bagVar :: Bag (Located (HsBind GhcTc)) -> SDoc+ bagVar bg = braces $+ text "Bag(Located (HsBind Var)):"+ $$ (list . bagToList $ bg)++ nameSet ns = braces $+ text "NameSet:"+ $$ (list . nameSetElemsStable $ ns)++ fixity :: Fixity -> SDoc+ fixity fx = braces $+ text "Fixity: "+ <> ppr fx++ located :: (Data b,Data loc) => GenLocated loc b -> SDoc+ located (L ss a) = parens $+ case cast ss of+ Just (s :: SrcSpan) ->+ srcSpan s+ Nothing -> text "nnnnnnnn"+ $$ showAstData' a++normalize_newlines :: String -> String+normalize_newlines ('\\':'r':'\\':'n':xs) = '\\':'n':normalize_newlines xs+normalize_newlines (x:xs) = x:normalize_newlines xs+normalize_newlines [] = []++{-+************************************************************************+* *+* Copied from syb+* *+************************************************************************+-}+++-- | The type constructor for queries+newtype Q q x = Q { unQ :: x -> q }++-- | Extend a generic query by a type-specific case+extQ :: ( Typeable a+ , Typeable b+ )+ => (a -> q)+ -> (b -> q)+ -> a+ -> q+extQ f g a = maybe (f a) g (cast a)++-- | Type extension of queries for type constructors+ext1Q :: (Data d, Typeable t)+ => (d -> q)+ -> (forall e. Data e => t e -> q)+ -> d -> q+ext1Q def ext = unQ ((Q def) `ext1` (Q ext))+++-- | Type extension of queries for type constructors+ext2Q :: (Data d, Typeable t)+ => (d -> q)+ -> (forall d1 d2. (Data d1, Data d2) => t d1 d2 -> q)+ -> d -> q+ext2Q def ext = unQ ((Q def) `ext2` (Q ext))++-- | Flexible type extension+ext1 :: (Data a, Typeable t)+ => c a+ -> (forall d. Data d => c (t d))+ -> c a+ext1 def ext = maybe def id (dataCast1 ext)++-- | Flexible type extension+ext2 :: (Data a, Typeable t)+ => c a+ -> (forall d1 d2. (Data d1, Data d2) => c (t d1 d2))+ -> c a+ext2 def ext = maybe def id (dataCast2 ext)+# endif+#endif
src/Language/Haskell/GhclibParserEx/GHC/Hs/ExtendInstances.hs view
@@ -24,7 +24,7 @@ #endif import Data.Data import Data.Function-import Language.Haskell.GhclibParserEx.Dump+import Language.Haskell.GhclibParserEx.GHC.Hs.Dump newtype HsExtendInstances a = HsExtendInstances { unextendInstances :: a }
test/Test.hs view
@@ -26,7 +26,7 @@ import GHC.Types.Error #endif -import Language.Haskell.GhclibParserEx.Dump+import Language.Haskell.GhclibParserEx.GHC.Hs.Dump import Language.Haskell.GhclibParserEx.Fixity import Language.Haskell.GhclibParserEx.GHC.Settings.Config import Language.Haskell.GhclibParserEx.GHC.Parser