ghc-lib-parser-ex 8.10.0.11 → 8.10.0.12
raw patch · 5 files changed
+73/−11 lines, 5 filesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ Language.Haskell.GhclibParserEx.GHC.Hs: modName :: Located (HsModule GhcPs) -> String
Files
- ChangeLog.md +3/−0
- README.md +3/−1
- ghc-lib-parser-ex.cabal +3/−2
- src/Language/Haskell/GhclibParserEx/GHC/Hs.hs +32/−0
- test/Test.hs +32/−8
ChangeLog.md view
@@ -1,5 +1,8 @@ # Changelog for ghc-lib-parser-ex +## 8.10.0.12 released 2020-05-31+- New module `GHC.Hs`+ ## 8.10.0.11 released 2020-05-18 - Upgrade to `ghc-lib-parser-8.10.1.20200523`
README.md view
@@ -8,7 +8,9 @@ Package `ghc-lib-parser-ex` is on [Hackage](https://hackage.haskell.org/package/ghc-lib-parser-ex) e.g. `cabal install ghc-lib-parser-ex`. Like `ghc-lib-parser`, there are two release streams within the `ghc-lib-parser-ex` name. -Version numbers are of the form α.β.γ.δ where α.β corresponds to a GHC series and γ.δ are the major and minor parts of the `ghc-lib-ex-parser` package release. Examples:+### Versioning policy++Package `ghc-lib-parser-ex` does **not** conform to the [Haskell Package Versioning Policy](https://pvp.haskell.org/). Version numbers are of the form α.β.γ.δ where α.β corresponds to a GHC series and γ.δ are the major and minor parts of the `ghc-lib-ex-parser` package release. Examples: * Version 8.10.1.3 is compatible with any `ghc-lib-parser-8.10.*` (or `ghc-8.10.*`) package; * Version 0.20190204.2.0 is compatible with [`ghc-lib-parser-0.20190204`](http://hackage.haskell.org/package/ghc-lib-0.20190204).
ghc-lib-parser-ex.cabal view
@@ -1,6 +1,6 @@ cabal-version: >= 1.18 name: ghc-lib-parser-ex-version: 8.10.0.11+version: 8.10.0.12 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@@ -25,7 +25,7 @@ flag auto default: True manual: True- description: Used default configuration+ description: Use default configuration flag no-ghc-lib default: False@@ -39,6 +39,7 @@ Language.Haskell.GhclibParserEx.Fixity Language.Haskell.GhclibParserEx.GHC.Driver.Flags Language.Haskell.GhclibParserEx.GHC.Driver.Session+ Language.Haskell.GhclibParserEx.GHC.Hs Language.Haskell.GhclibParserEx.GHC.Hs.Expr Language.Haskell.GhclibParserEx.GHC.Hs.Pat Language.Haskell.GhclibParserEx.GHC.Hs.Types
+ src/Language/Haskell/GhclibParserEx/GHC/Hs.hs view
@@ -0,0 +1,32 @@+-- Copyright (c) 2020, Shayne Fletcher. All rights reserved.+-- SPDX-License-Identifier: BSD-3-Clause.++{-# LANGUAGE CPP #-}+#include "ghclib_api.h"++module Language.Haskell.GhclibParserEx.GHC.Hs(+ modName+ )+where++#if defined(GHCLIB_API_811)+import GHC.Hs+import GHC.Unit.Module+import GHC.Types.SrcLoc+#elif defined(GHCLIB_API_810)+import GHC.Hs+import Module+import SrcLoc+#else+import HsSyn+import Module+import SrcLoc+#endif++#if defined(GHCLIB_API_811)+modName :: Located HsModule -> String+#else+modName :: Located (HsModule GhcPs) -> String+#endif+modName (L _ HsModule {hsmodName=Nothing}) = "Main"+modName (L _ HsModule {hsmodName=Just (L _ n)}) = moduleNameString n
test/Test.hs view
@@ -21,6 +21,7 @@ import Language.Haskell.GhclibParserEx.Dump import Language.Haskell.GhclibParserEx.Fixity import Language.Haskell.GhclibParserEx.GHC.Parser+import Language.Haskell.GhclibParserEx.GHC.Hs import Language.Haskell.GhclibParserEx.GHC.Hs.ExtendInstances import Language.Haskell.GhclibParserEx.GHC.Hs.Expr import Language.Haskell.GhclibParserEx.GHC.Hs.Pat@@ -64,6 +65,7 @@ , expressionPredicateTests , patternPredicateTests , dynFlagsTests+ , nameTests ] makeFile :: FilePath -> String -> IO FilePath@@ -141,6 +143,16 @@ flags = unsafeGlobalDynFlags report flags msgs = concat [ showSDoc flags msg | msg <- pprErrMsgBagWithLoc msgs ] +#if defined(GHCLIB_API_811)+moduleTest :: String -> DynFlags -> (Located HsModule -> IO ()) -> IO ()+#else+moduleTest :: String -> DynFlags -> (Located (HsModule GhcPs) -> IO ()) -> IO ()+#endif+moduleTest s flags test =+ case parseModule s flags of+ POk _ e -> test e+ _ -> assertFailure "parse error"+ exprTest :: String -> DynFlags -> (LHsExpr GhcPs -> IO ()) -> IO () exprTest s flags test = case parseExpression s flags of@@ -155,34 +167,32 @@ fixityTests :: TestTree fixityTests = testGroup "Fixity tests"- [ testCase "Expression" $ do- let flags = defaultDynFlags fakeSettings fakeLlvmConfig+ [ testCase "Expression" $ exprTest "1 + 2 * 3" flags (\e -> assertBool "parse tree not affected" $ showSDocUnsafe (showAstData BlankSrcSpan e) /= showSDocUnsafe (showAstData BlankSrcSpan (applyFixities [] e)) )- , testCase "Pattern" $ do- let flags = defaultDynFlags fakeSettings fakeLlvmConfig+ , testCase "Pattern" $ case parseDeclaration "f (1 : 2 :[]) = 1" flags of POk _ d -> assertBool "parse tree not affected" $ showSDocUnsafe (showAstData BlankSrcSpan d) /= showSDocUnsafe (showAstData BlankSrcSpan (applyFixities [] d)) PFailed{} -> assertFailure "parse error"- , testCase "fixitiesFromModule" $ do- let flags = defaultDynFlags fakeSettings fakeLlvmConfig+ , testCase "fixitiesFromModule" $ case parseModule "infixl 4 <*!" flags of POk _ m -> assertBool "one fixity expected" $ not (null (fixitiesFromModule m)) PFailed{} -> assertFailure "parse error" ]+ where+ flags = defaultDynFlags fakeSettings fakeLlvmConfig extendInstancesTests :: TestTree extendInstancesTests = testGroup "Extend instances tests"- [ testCase "Eq, Ord" $ do- let flags = defaultDynFlags fakeSettings fakeLlvmConfig+ [ testCase "Eq, Ord" $ exprTest "1 + 2 * 3" flags (\e -> do e' <- return $ applyFixities [] e@@ -196,6 +206,8 @@ assertBool ">=" $ e >= e' ) ]+ where+ flags = defaultDynFlags fakeSettings fakeLlvmConfig expressionPredicateTests :: TestTree expressionPredicateTests = testGroup "Expression predicate tests"@@ -315,3 +327,15 @@ where flags = unsafeGlobalDynFlags report flags msgs = concat [ showSDoc flags msg | msg <- pprErrMsgBagWithLoc msgs ]++nameTests :: TestTree+nameTests = testGroup "Name tests"+ [ testCase "Module (1)" $+ moduleTest "module Foo.Bar.Baz where" flags+ (\n -> assertBool "Unexpected name string" $ modName n == "Foo.Bar.Baz")+ , testCase "Module (2)" $+ moduleTest "f x = x * 2" flags+ (\n -> assertBool "Unexpected name string" $ modName n == "Main")+ ]+ where+ flags = defaultDynFlags fakeSettings fakeLlvmConfig