packages feed

ghc-lib-parser-ex 0.20211201 → 0.20220103

raw patch · 7 files changed

+84/−36 lines, 7 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Language.Haskell.GhclibParserEx.GHC.Hs.Types: fromTyParen :: LHsType GhcPs -> LHsType GhcPs
- Language.Haskell.GhclibParserEx.GHC.Hs.Types: isTyQuasiQuote :: LHsType GhcPs -> Bool
- Language.Haskell.GhclibParserEx.GHC.Hs.Types: isUnboxedTuple :: HsTupleSort -> Bool
+ Language.Haskell.GhclibParserEx.GHC.Hs.Expr: isOverLabel :: LHsExpr GhcPs -> Bool
+ Language.Haskell.GhclibParserEx.GHC.Hs.Expr: isQuasiQuoteExpr :: LHsExpr GhcPs -> Bool
+ Language.Haskell.GhclibParserEx.GHC.Hs.Expr: isQuasiQuoteSplice :: HsSplice GhcPs -> Bool
+ Language.Haskell.GhclibParserEx.GHC.Hs.Type: fromTyParen :: LHsType GhcPs -> LHsType GhcPs
+ Language.Haskell.GhclibParserEx.GHC.Hs.Type: isKindTyApp :: LHsType GhcPs -> Bool
+ Language.Haskell.GhclibParserEx.GHC.Hs.Type: isTyQuasiQuote :: LHsType GhcPs -> Bool
+ Language.Haskell.GhclibParserEx.GHC.Hs.Type: isUnboxedTuple :: HsTupleSort -> Bool

Files

ChangeLog.md view
@@ -1,7 +1,18 @@ # Changelog for ghc-lib-parser-ex -## 0.20211201 released 2021-12-01+## Unreleased+- New function `isOverLabel`++## 9.0.0.6 released 2021-12-26+- Add back `isQuasiQuote` for backwards compatibility++## 9.0.0.5 released 2021-12-25 - Bugfix to `isFieldPunUpdate`+- New module `Language.Haskell.GHC.Hs.Type.hs` to replace `Language.Haskell.GHC.Hs.Types.hs` (which remains for now but deprecated and will be removed in a future release)+  - New function `isKindTyApp`+- Rename `isQuasiQuote` to `isQuasiQuoteExpr`+- Add new function `isQuasiQuoteSplice`+- Update to `ghc-lib-parser-9.0.2.20211226`  ## 9.2.0.1 released 2021-11-01 - Update to `ghc-lib-parser-9.2.1.20211101`
README.md view
@@ -27,7 +27,7 @@ ``` Run `stack runhaskell --package extra --package optparse-applicative CI.hs -- --help` for more options. -To run [`hlint`](https://github.com/ndmitchell/hlint) on this repository, `hlint --cpp-include cbits --cpp-define GHCLIB_API_XXX .` (where `XXX` at this time is one of `808`, `810` or `900`).+To run [`hlint`](https://github.com/ndmitchell/hlint) on this repository, `hlint --cpp-include cbits --cpp-define GHCLIB_API_XXX .` (where `XXX` at this time is one of `808`, `810`, `900`, `902` or `HEAD`).  ## Releasing `ghc-lib-parser-ex` (notes for maintainers) 
ghc-lib-parser-ex.cabal view
@@ -1,6 +1,6 @@ cabal-version:  1.18 name:           ghc-lib-parser-ex-version:        0.20211201+version:        0.20220103 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@@ -41,6 +41,7 @@       Language.Haskell.GhclibParserEx.GHC.Hs       Language.Haskell.GhclibParserEx.GHC.Hs.Expr       Language.Haskell.GhclibParserEx.GHC.Hs.Pat+      Language.Haskell.GhclibParserEx.GHC.Hs.Type       Language.Haskell.GhclibParserEx.GHC.Hs.Types       Language.Haskell.GhclibParserEx.GHC.Hs.Decls       Language.Haskell.GhclibParserEx.GHC.Hs.Binds
src/Language/Haskell/GhclibParserEx/GHC/Hs/Expr.hs view
@@ -7,7 +7,7 @@ #include "ghclib_api.h" module Language.Haskell.GhclibParserEx.GHC.Hs.Expr(   isTag, isDol, isDot, isReturn, isSection, isRecConstr, isRecUpdate,-  isVar, isPar, isApp, isOpApp, isAnyApp, isLexeme, isLambda, isQuasiQuote,+  isVar, isPar, isApp, isOpApp, isAnyApp, isLexeme, isLambda, isQuasiQuote, isQuasiQuoteExpr, isQuasiQuoteSplice,  isOverLabel,   isDotApp, isTypeApp, isWHNF, isLCase,   isFieldPun, isFieldPunUpdate, isRecStmt, isParComp, isMDo, isListComp, isMonadComp, isTupleSection, isString, isPrimLiteral,   isSpliceDecl, isFieldWildcard, isUnboxed, isWholeFrac, isStrictMatch, isMultiIf, isProc, isTransStmt,@@ -45,8 +45,8 @@ isTag tag = \case (L _ (HsVar _ (L _ s))) -> occNameString (rdrNameOcc s) == tag; _ -> False  isDot, isDol, isReturn, isSection, isRecConstr, isRecUpdate,-  isVar, isPar, isApp, isOpApp, isAnyApp, isLexeme, isQuasiQuote,-  isLambda, isDotApp, isTypeApp, isWHNF, isLCase :: LHsExpr GhcPs -> Bool+  isVar, isPar, isApp, isOpApp, isAnyApp, isLexeme, isQuasiQuote, isQuasiQuoteExpr,+  isLambda, isDotApp, isTypeApp, isWHNF, isLCase, isOverLabel :: LHsExpr GhcPs -> Bool isDol = isTag "$" isDot = isTag "." isReturn x = isTag "return" x || isTag "pure" x -- Allow both 'pure' and 'return' as they have the same semantics.@@ -60,7 +60,8 @@ isAnyApp x = isApp x || isOpApp x isLexeme = \case (L _ HsVar{}) -> True; (L _ HsOverLit{}) -> True; (L _ HsLit{}) -> True; _ -> False isLambda = \case (L _ HsLam{}) -> True; _ -> False-isQuasiQuote = \case (L _ (HsSpliceE _ HsQuasiQuote{})) -> True; _ -> False+isQuasiQuoteExpr = \case (L _ (HsSpliceE _ HsQuasiQuote{})) -> True; _ -> False+isQuasiQuote = isQuasiQuoteExpr -- Backwards compat. isDotApp = \case (L _ (OpApp _ _ op _)) -> isDot op; _ -> False isTypeApp = \case (L _ HsAppType{}) -> True; _ -> False isWHNF = \case@@ -81,6 +82,10 @@     | occNameString (rdrNameOcc x) `elem` ["Just", "Left", "Right"] -> True   _ -> False isLCase = \case (L _ HsLamCase{}) -> True; _ -> False+isOverLabel = \case (L _ HsOverLabel{}) -> True; _ -> False++isQuasiQuoteSplice :: HsSplice GhcPs -> Bool+isQuasiQuoteSplice = \case HsQuasiQuote{} -> True; _ -> False  #if defined (GHCLIB_API_HEAD) || defined(GHCLIB_API_902) || defined (GHCLIB_API_901) isStrictMatch :: HsMatchContext GhcPs -> Bool
+ src/Language/Haskell/GhclibParserEx/GHC/Hs/Type.hs view
@@ -0,0 +1,36 @@+-- Copyright (c) 2021, Shayne Fletcher. All rights reserved.+-- SPDX-License-Identifier: BSD-3-Clause.++{-# LANGUAGE CPP #-}+{-# LANGUAGE LambdaCase #-}+#include "ghclib_api.h"+module Language.Haskell.GhclibParserEx.GHC.Hs.Type (+    fromTyParen+  , isTyQuasiQuote, isUnboxedTuple, isKindTyApp+) where++#if defined (GHCLIB_API_HEAD) || defined (GHCLIB_API_902) || defined (GHCLIB_API_900) || defined (GHCLIB_API_810)+import GHC.Hs+#else+import HsSyn+#endif+#if defined (GHCLIB_API_HEAD) || defined (GHCLIB_API_902) || defined (GHCLIB_API_900)+import GHC.Types.SrcLoc+#else+import SrcLoc+#endif++isKindTyApp :: LHsType GhcPs -> Bool+isKindTyApp = \case (L _ HsAppKindTy{}) -> True; _ -> False++fromTyParen :: LHsType GhcPs -> LHsType GhcPs+fromTyParen (L _ (HsParTy _ x)) = x+fromTyParen x = x++isTyQuasiQuote :: LHsType GhcPs -> Bool+isTyQuasiQuote (L _ (HsSpliceTy _ HsQuasiQuote{})) = True+isTyQuasiQuote _ = False++isUnboxedTuple :: HsTupleSort -> Bool+isUnboxedTuple HsUnboxedTuple = True+isUnboxedTuple _ = False
src/Language/Haskell/GhclibParserEx/GHC/Hs/Types.hs view
@@ -1,32 +1,9 @@ -- 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.Types(-    fromTyParen-  , isTyQuasiQuote, isUnboxedTuple+module Language.Haskell.GhclibParserEx.GHC.Hs.Types+  {-# DEPRECATED "Use Language.Haskell.GhclibParserEx.GHC.Hs.Type instead" #-} (+  module Language.Haskell.GhclibParserEx.GHC.Hs.Type   ) where -#if defined (GHCLIB_API_HEAD) || defined (GHCLIB_API_902) || defined (GHCLIB_API_900) || defined (GHCLIB_API_810)-import GHC.Hs-#else-import HsSyn-#endif-#if defined (GHCLIB_API_HEAD) || defined (GHCLIB_API_902) || defined (GHCLIB_API_900)-import GHC.Types.SrcLoc-#else-import SrcLoc-#endif--fromTyParen :: LHsType GhcPs -> LHsType GhcPs-fromTyParen (L _ (HsParTy _ x)) = x-fromTyParen x = x--isTyQuasiQuote :: LHsType GhcPs -> Bool-isTyQuasiQuote (L _ (HsSpliceTy _ HsQuasiQuote{})) = True-isTyQuasiQuote _ = False--isUnboxedTuple :: HsTupleSort -> Bool-isUnboxedTuple HsUnboxedTuple = True-isUnboxedTuple _ = False+import Language.Haskell.GhclibParserEx.GHC.Hs.Type
test/Test.hs view
@@ -31,6 +31,7 @@ import Language.Haskell.GhclibParserEx.GHC.Hs.ExtendInstances import Language.Haskell.GhclibParserEx.GHC.Hs.Expr import Language.Haskell.GhclibParserEx.GHC.Hs.Pat+import Language.Haskell.GhclibParserEx.GHC.Hs.Type -- We only test 'isImportQualifiedPost' at this time which requires >= -- 8.10; avoid unused import warning. #if defined (MIN_VERSION_ghc_lib_parser)@@ -91,6 +92,7 @@   , fixityTests   , extendInstancesTests   , expressionPredicateTests+  , typePredicateTests   , patternPredicateTests   , dynFlagsTests   , nameTests@@ -224,6 +226,12 @@         POk _ e -> test e         _ -> assertFailure "parse error" +typeTest :: String -> DynFlags -> (LHsType GhcPs -> IO ()) -> IO ()+typeTest s flags test =+      case parseType s flags of+        POk _ e -> test e+        _ -> assertFailure "parse error"+ patTest :: String -> DynFlags -> (LPat GhcPs -> IO ()) -> IO () patTest s flags test =       case parsePattern s flags of@@ -284,6 +292,16 @@   where     flags = defaultDynFlags fakeSettings fakeLlvmConfig +typePredicateTests :: TestTree+typePredicateTests = testGroup "Type predicate tests"+  [ testCase "isKindTyApp" $ test_with_exts [TypeApplications] "K @T" $ assert' . isKindTyApp+  , testCase "isKindTyApp" $ test_with_exts [TypeApplications] "K T" $ assert' . not . isKindTyApp+  ]+  where+    assert' = assertBool ""+    test_with_exts exts s = typeTest s (flags exts)+    flags = foldl' xopt_set (defaultDynFlags fakeSettings fakeLlvmConfig)+ expressionPredicateTests :: TestTree expressionPredicateTests = testGroup "Expression predicate tests"   [ testCase "isTag" $ test "foo" $ assert' . isTag "foo"@@ -350,8 +368,8 @@   , testCase "isSpliceDecl" $ test "$x" $ assert' . isSpliceDecl . unLoc   , testCase "isSpliceDecl" $ test "f$x" $ assert' . not . isSpliceDecl . unLoc   , testCase "isSpliceDecl" $ test "$(a + b)" $ assert' . isSpliceDecl . unLoc-  , testCase "isQuasiQuote" $ test "[expr|1 + 2|]" $ assert' . isQuasiQuote-  , testCase "isQuasiQuote" $ test "[expr(1 + 2)]" $ assert' . not . isQuasiQuote+  , testCase "isQuasiQuoteExpr" $ test "[expr|1 + 2|]" $ assert' . isQuasiQuoteExpr+  , testCase "isQuasiQuoteExpr" $ test "[expr(1 + 2)]" $ assert' . not . isQuasiQuoteExpr   , testCase "isWholeFrac" $ test "3.2e1" $ assert' . isWholeFrac . unLoc   , testCase "isWholeFrac" $ test "3.22e1" $ assert' . not . isWholeFrac . unLoc   , testCase "isMDo" $ test_with_exts [ RecursiveDo ] "mdo { pure () }" $ assert' . any isMDo . universeBi