diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e79c8d1..7ad0476 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -29,9 +29,6 @@ jobs: - os: ubuntu-18.04 ghc: 8.2.2 cabal: 3.2.0.0 - - os: ubuntu-18.04 - ghc: 8.0.2 - cabal: 3.2.0.0 runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 diff --git a/.travis.yml b/.travis.yml index ae64c83..cd70c46 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,7 +40,7 @@ before_cache: # addons: {apt: {packages: [libfcgi-dev,libgmp-dev]}} matrix: include: - + ##### OSX test via stack ##### # Build on macOS in addition to Linux @@ -49,10 +49,7 @@ matrix: os: osx ##### CABAL ##### - - - env: BUILD=cabal GHCVER=8.0.2 CABALVER=1.24 HAPPYVER=1.19.5 ALEXVER=3.1.7 - compiler: ": #cabal 8.0.2" - addons: {apt: {packages: [cabal-install-1.24,ghc-8.0.2,happy-1.19.5,alex-3.1.7], sources: [hvr-ghc]}} + - env: BUILD=cabal GHCVER=8.2.2 CABALVER=1.24 HAPPYVER=1.19.5 ALEXVER=3.1.7 compiler: ": #cabal 8.2.2" addons: {apt: {packages: [cabal-install-1.24,ghc-8.2.2,happy-1.19.5,alex-3.1.7], sources: [hvr-ghc]}} @@ -92,9 +89,6 @@ matrix: compiler: ": #stack default" addons: {apt: {packages: [libgmp-dev]}} - - env: BUILD=stack ARGS="--stack-yaml stack-8.0.2.yaml" - compiler: ": #stack 8.0.2" - addons: {apt: {packages: [libgmp-dev]}} - env: BUILD=stack ARGS="--stack-yaml stack-8.2.2.yaml" compiler: ": #stack 8.2.2" addons: {apt: {packages: [libgmp-dev]}} @@ -202,7 +196,7 @@ install: mkdir -p $HOME/.ghc $HOME/.cabal/lib $HOME/.cabal/share $HOME/.cabal/bin; cabal install -j$JOBS --only-dependencies --enable-tests --enable-benchmarks --ghc-options="-j1 +RTS -M700M -RTS"; fi - + # snapshot package-db on cache miss if [ ! -d $HOME/.cabsnap ]; then diff --git a/Makefile b/Makefile index e0213ab..c7524be 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ test: .PHONY: test-all test-all: - $(MAKE) test test-8.6.5 test-8.4.3 test-8.2.2 test-8.0.2 + $(MAKE) test test-8.6.5 test-8.4.3 test-8.2.2 .PHONY: test-8.6.5 test-8.6.5: @@ -21,8 +21,3 @@ test-8.4.3: test-8.2.2: echo "test 8.2.2" stack test --stack-yaml stack-8.2.2.yaml --work-dir .stack-work-8.2.2 - -.PHONY: test-8.0.2 -test-8.0.2: - echo "test 8.0.2" - stack test --stack-yaml stack-8.0.2.yaml --work-dir .stack-work-8.0.2 diff --git a/README.md b/README.md index 6fe5976..b009a37 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# brittany [![Hackage version](https://img.shields.io/hackage/v/brittany.svg?label=Hackage)](https://hackage.haskell.org/package/brittany) [![Stackage version](https://www.stackage.org/package/brittany/badge/lts?label=Stackage)](https://www.stackage.org/package/brittany) [![Build Status](https://secure.travis-ci.org/lspitzner/brittany.svg?branch=master)](http://travis-ci.org/lspitzner/brittany) +# brittany [![Hackage version](https://img.shields.io/hackage/v/brittany.svg?label=Hackage)](https://hackage.haskell.org/package/brittany) [![Stackage version](https://www.stackage.org/package/brittany/badge/lts?label=Stackage)](https://www.stackage.org/package/brittany) [![Build Status](https://secure.travis-ci.org/lspitzner/brittany.svg?branch=master)](http://travis-ci.org/lspitzner/brittany) haskell source code formatter ![Output sample](https://github.com/lspitzner/brittany/raw/master/brittany-sample.gif) @@ -31,7 +31,7 @@ require fixing: other module elements (data-decls, classes, instances, etc.) are not transformed in any way; this extends to e.g. **bindings inside class instance definitions** - they **won't be touched** (yet). -- By using `ghc-exactprint` as the parser, brittany supports full GHC +- By using `ghc-exactprint` as the parser, brittany supports full GHC including extensions, but **some of the less common syntactic elements (even of 2010 haskell) are not handled**. - **There are some known issues regarding handling of in-source comments.** @@ -48,7 +48,7 @@ log the size of the input, but _not_ the full input/output of requests.) # Other usage notes -- Supports GHC versions `8.0`, `8.2`, `8.4`, `8.6`, `8.8`. +- Supports GHC versions `8.2`, `8.4`, `8.6`, `8.8`. - included in stackage with lts>=10.0 (or nightlies dating to >=2017-11-15) - config (file) documentation is lacking. - some config values can not be configured via commandline yet. @@ -127,13 +127,13 @@ log the size of the input, but _not_ the full input/output of requests.) - Default mode of operation: Transform a single module, from `stdin` to `stdout`. Can pass one or multiple files as input, and there is a flag to override them in place instead of using `stdout` (since 0.9.0.0). So: - + ~~~~ .sh brittany # stdin -> stdout brittany mysource.hs # ./mysource.hs -> stdout brittany --write-mode=inplace *.hs # apply formatting to all ./*.hs inplace ~~~~ - + - For stdin/stdout usage it makes sense to enable certain syntactic extensions by default, i.e. to add something like this to your `~/.config/brittany/config.yaml` (execute `brittany` once to create default): diff --git a/brittany.cabal b/brittany.cabal index 704d505..0c3ed7c 100644 --- a/brittany.cabal +++ b/brittany.cabal @@ -91,8 +91,8 @@ library { -fno-warn-redundant-constraints } build-depends: - { base >=4.9 && <4.15 - , ghc >=8.0.1 && <8.11 + { base >=4.10 && <4.15 + , ghc >=8.2.1 && <8.11 , ghc-paths >=0.1.0.9 && <0.2 , ghc-exactprint >=0.5.8 && <0.6.4 , transformers >=0.5.2.0 && <0.6 @@ -118,7 +118,7 @@ library { , semigroups >=0.18.2 && <0.20 , cmdargs >=0.10.14 && <0.11 , czipwith >=1.0.1.0 && <1.1 - , ghc-boot-th >=8.0.1 && <8.11 + , ghc-boot-th >=8.2.1 && <8.11 , filepath >=1.4.1.0 && <1.5 , random >= 1.1 && <1.2 } diff --git a/src/Language/Haskell/Brittany/Internal/Config/Types.hs b/src/Language/Haskell/Brittany/Internal/Config/Types.hs index 32da0ac..c5d8eb0 100644 --- a/src/Language/Haskell/Brittany/Internal/Config/Types.hs +++ b/src/Language/Haskell/Brittany/Internal/Config/Types.hs @@ -229,15 +229,12 @@ deriving instance Data (CForwardOptions Identity) deriving instance Data (CPreProcessorConfig Identity) deriving instance Data (CConfig Identity) -#if MIN_VERSION_ghc(8,2,0) --- these instances break on earlier ghcs deriving instance Data (CDebugConfig Option) deriving instance Data (CLayoutConfig Option) deriving instance Data (CErrorHandlingConfig Option) deriving instance Data (CForwardOptions Option) deriving instance Data (CPreProcessorConfig Option) deriving instance Data (CConfig Option) -#endif instance Semigroup.Semigroup (CDebugConfig Option) where (<>) = gmappend @@ -356,4 +353,3 @@ deriveCZipWith ''CErrorHandlingConfig deriveCZipWith ''CForwardOptions deriveCZipWith ''CPreProcessorConfig deriveCZipWith ''CConfig - diff --git a/src/Language/Haskell/Brittany/Internal/ExactPrintUtils.hs b/src/Language/Haskell/Brittany/Internal/ExactPrintUtils.hs index 6115f52..7c06f69 100644 --- a/src/Language/Haskell/Brittany/Internal/ExactPrintUtils.hs +++ b/src/Language/Haskell/Brittany/Internal/ExactPrintUtils.hs @@ -323,7 +323,7 @@ withTransformedAnns ast m = MultiRWSS.mGetRawR >>= \case #if MIN_VERSION_ghc(8,4,0) /* ghc-8.4 */ warnExtractorCompat :: GHC.Warn -> String warnExtractorCompat (GHC.Warn _ (L _ s)) = s -#else /* ghc-8.0 && ghc-8.2 */ +#else /* ghc-8.2 */ warnExtractorCompat :: GenLocated l String -> String warnExtractorCompat (L _ s) = s #endif diff --git a/src/Language/Haskell/Brittany/Internal/Layouters/DataDecl.hs b/src/Language/Haskell/Brittany/Internal/Layouters/DataDecl.hs index 4d2b93a..74b6d53 100644 --- a/src/Language/Haskell/Brittany/Internal/Layouters/DataDecl.hs +++ b/src/Language/Haskell/Brittany/Internal/Layouters/DataDecl.hs @@ -297,7 +297,6 @@ createDerivingPar :: HsDeriving GhcPs -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered createDerivingPar derivs mainDoc = do case derivs of -#if MIN_VERSION_ghc(8,2,0) /* ghc-8.2 */ (L _ []) -> mainDoc (L _ types) -> docPar mainDoc @@ -306,26 +305,13 @@ createDerivingPar derivs mainDoc = do $ docWrapNode derivs $ derivingClauseDoc <$> types -#else - Nothing -> mainDoc - Just types -> - docPar mainDoc - $ docEnsureIndent BrIndentRegular - $ derivingClauseDoc types -#endif -#if MIN_VERSION_ghc(8,2,0) /* ghc-8.2 */ derivingClauseDoc :: LHsDerivingClause GhcPs -> ToBriDocM BriDocNumbered -#else -derivingClauseDoc :: Located [LHsSigType GhcPs] -> ToBriDocM BriDocNumbered -#endif #if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */ derivingClauseDoc (L _ (XHsDerivingClause ext)) = absurdExt ext derivingClauseDoc (L _ (HsDerivingClause _ext mStrategy types)) = case types of -#elif MIN_VERSION_ghc(8,2,0) /* ghc-8.2 */ -derivingClauseDoc (L _ (HsDerivingClause mStrategy types)) = case types of #else -derivingClauseDoc types = case types of +derivingClauseDoc (L _ (HsDerivingClause mStrategy types)) = case types of #endif (L _ []) -> docSeq [] (L _ ts) -> @@ -333,11 +319,7 @@ derivingClauseDoc types = case types of tsLength = length ts whenMoreThan1Type val = if tsLength > 1 then docLitS val else docLitS "" -#if MIN_VERSION_ghc(8,2,0) /* ghc-8.2 */ (lhsStrategy, rhsStrategy) = maybe (docEmpty, docEmpty) strategyLeftRight mStrategy -#else - (lhsStrategy, rhsStrategy) = (docEmpty, docEmpty) -#endif in docSeq [ docDeriving @@ -351,15 +333,12 @@ derivingClauseDoc types = case types of #if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */ HsIB _ t -> layoutType t XHsImplicitBndrs x -> absurdExt x -#elif MIN_VERSION_ghc(8,2,0) /* ghc-8.2 */ - HsIB _ t _ -> layoutType t #else - HsIB _ t -> layoutType t + HsIB _ t _ -> layoutType t #endif , whenMoreThan1Type ")" , rhsStrategy ] -#if MIN_VERSION_ghc(8,2,0) /* ghc-8.6 */ where strategyLeftRight = \case (L _ StockStrategy ) -> (docLitS " stock", docEmpty) @@ -377,7 +356,6 @@ derivingClauseDoc types = case types of XHsImplicitBndrs ext -> absurdExt ext ) #endif -#endif docDeriving :: ToBriDocM BriDocNumbered docDeriving = docLitS "deriving" diff --git a/src/Language/Haskell/Brittany/Internal/Layouters/Decl.hs b/src/Language/Haskell/Brittany/Internal/Layouters/Decl.hs index e512b9a..4a86954 100644 --- a/src/Language/Haskell/Brittany/Internal/Layouters/Decl.hs +++ b/src/Language/Haskell/Brittany/Internal/Layouters/Decl.hs @@ -49,9 +49,7 @@ import BasicTypes ( InlinePragma(..) , Activation(..) , InlineSpec(..) , RuleMatchInfo(..) -#if MIN_VERSION_ghc(8,2,0) , LexicalFixity(..) -#endif ) import Language.Haskell.GHC.ExactPrint.Types ( mkAnnKey ) @@ -100,10 +98,8 @@ layoutSig :: ToBriDoc Sig layoutSig lsig@(L _loc sig) = case sig of #if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */ TypeSig _ names (HsWC _ (HsIB _ typ)) -> layoutNamesAndType Nothing names typ -#elif MIN_VERSION_ghc(8,2,0) /* ghc-8.2 8.4 */ +#else /* ghc-8.2 */ TypeSig names (HsWC _ (HsIB _ typ _)) -> layoutNamesAndType Nothing names typ -#else /* ghc-8.0 */ - TypeSig names (HsIB _ (HsWC _ _ typ)) -> layoutNamesAndType Nothing names typ #endif #if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */ InlineSig _ name (InlinePragma _ spec _arity phaseAct conlike) -> @@ -128,17 +124,13 @@ layoutSig lsig@(L _loc sig) = case sig of <> Text.pack " #-}" #if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */ ClassOpSig _ False names (HsIB _ typ) -> layoutNamesAndType Nothing names typ -#elif MIN_VERSION_ghc(8,2,0) /* ghc-8.2 8.4 */ +#else /* ghc-8.2 */ ClassOpSig False names (HsIB _ typ _) -> layoutNamesAndType Nothing names typ -#else /* ghc-8.0 */ - ClassOpSig False names (HsIB _ typ) -> layoutNamesAndType Nothing names typ #endif #if MIN_VERSION_ghc(8,6,0) PatSynSig _ names (HsIB _ typ) -> layoutNamesAndType (Just "pattern") names typ -#elif MIN_VERSION_ghc(8,2,0) - PatSynSig names (HsIB _ typ _) -> layoutNamesAndType (Just "pattern") names typ #else - PatSynSig name (HsIB _ typ) -> layoutNamesAndType (Just "pattern") [name] typ + PatSynSig names (HsIB _ typ _) -> layoutNamesAndType (Just "pattern") names typ #endif _ -> briDocByExactNoComment lsig -- TODO where @@ -359,10 +351,8 @@ layoutPatternBind funId binderDoc lmatch@(L _ match) = do Match _ (FunRhs matchId _ _) _ _ -> Just <$> lrdrNameToTextAnn matchId #elif MIN_VERSION_ghc(8,4,0) /* ghc-8.4 */ Match (FunRhs matchId _ _) _ _ -> Just <$> lrdrNameToTextAnn matchId -#elif MIN_VERSION_ghc(8,2,0) /* ghc-8.4 */ - Match (FunRhs matchId _ _) _ _ _ -> Just <$> lrdrNameToTextAnn matchId #else - Match (FunBindMatch matchId _) _ _ _ -> Just <$> lrdrNameToTextAnn matchId + Match (FunRhs matchId _ _) _ _ _ -> Just <$> lrdrNameToTextAnn matchId #endif _ -> pure Nothing let mIdStr' = fixPatternBindIdentifier match <$> mIdStr @@ -406,7 +396,6 @@ layoutPatternBind funId binderDoc lmatch@(L _ match) = do mWhereArg hasComments -#if MIN_VERSION_ghc(8,2,0) /* ghc-8.2 && ghc-8.4 */ fixPatternBindIdentifier :: Match GhcPs (LHsExpr GhcPs) -> Text -> Text fixPatternBindIdentifier match idStr = go $ m_ctxt match @@ -424,10 +413,6 @@ fixPatternBindIdentifier match idStr = go $ m_ctxt match (ParStmtCtxt ctx1) -> goInner ctx1 (TransStmtCtxt ctx1) -> goInner ctx1 _ -> idStr -#else /* ghc-8.0 */ -fixPatternBindIdentifier :: Match GhcPs (LHsExpr GhcPs) -> Text -> Text -fixPatternBindIdentifier _ x = x -#endif layoutPatternBindFinal :: Maybe Text @@ -842,18 +827,11 @@ layoutTyCl ltycl@(L _loc tycl) = case tycl of let isInfix = case fixity of Prefix -> False Infix -> True -#elif MIN_VERSION_ghc(8,2,0) +#else SynDecl name vars fixity typ _ -> do let isInfix = case fixity of Prefix -> False Infix -> True -#else - SynDecl name vars typ _ -> do - nameStr <- lrdrNameToTextAnn name - let isInfixTypeOp = case Text.uncons nameStr of - Nothing -> False - Just (c, _) -> not (c == '(' || isUpper c) - isInfix <- (isInfixTypeOp ||) <$> hasAnnKeyword name AnnBackquote #endif -- hasTrailingParen <- hasAnnKeywordComment ltycl AnnCloseP -- let parenWrapper = if hasTrailingParen @@ -864,10 +842,8 @@ layoutTyCl ltycl@(L _loc tycl) = case tycl of $ layoutSynDecl isInfix wrapNodeRest name (hsq_explicit vars) typ #if MIN_VERSION_ghc(8,6,0) DataDecl _ext name tyVars _ dataDefn -> -#elif MIN_VERSION_ghc(8,2,0) - DataDecl name tyVars _ dataDefn _ _ -> #else - DataDecl name tyVars dataDefn _ _ -> + DataDecl name tyVars _ dataDefn _ _ -> #endif layoutDataDecl ltycl name tyVars dataDefn _ -> briDocByExactNoComment ltycl @@ -919,14 +895,14 @@ layoutTyVarBndr needsSep lbndr@(L _ bndr) = do #if MIN_VERSION_ghc(8,6,0) /* 8.6 */ XTyVarBndr{} -> error "brittany internal error: XTyVarBndr" UserTyVar _ name -> do -#else /* 8.0 8.2 8.4 */ +#else /* 8.2 8.4 */ UserTyVar name -> do #endif nameStr <- lrdrNameToTextAnn name docSeq $ [docSeparator | needsSep] ++ [docLit nameStr] #if MIN_VERSION_ghc(8,6,0) /* 8.6 */ KindedTyVar _ name kind -> do -#else /* 8.0 8.2 8.4 */ +#else /* 8.2 8.4 */ KindedTyVar name kind -> do #endif nameStr <- lrdrNameToTextAnn name @@ -967,12 +943,8 @@ layoutTyFamInstDecl inClass outerNode tfid = do FamEqn name pats _fixity typ = hsib_body $ tfid_eqn tfid bndrsMay = Nothing innerNode = outerNode -#elif MIN_VERSION_ghc(8,2,0) - innerNode@(L _ (TyFamEqn name boundPats _fixity typ)) = tfid_eqn tfid - bndrsMay = Nothing - pats = hsib_body boundPats #else - innerNode@(L _ (TyFamEqn name boundPats typ)) = tfid_eqn tfid + innerNode@(L _ (TyFamEqn name boundPats _fixity typ)) = tfid_eqn tfid bndrsMay = Nothing pats = hsib_body boundPats #endif diff --git a/src/Language/Haskell/Brittany/Internal/Layouters/Expr.hs b/src/Language/Haskell/Brittany/Internal/Layouters/Expr.hs index d7c9a2b..534496d 100644 --- a/src/Language/Haskell/Brittany/Internal/Layouters/Expr.hs +++ b/src/Language/Haskell/Brittany/Internal/Layouters/Expr.hs @@ -62,10 +62,8 @@ layoutExpr lexpr@(L _ expr) = do briDocByExactInlineOnly "HsRecFld" lexpr #if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */ HsOverLabel _ext _reboundFromLabel name -> -#elif MIN_VERSION_ghc(8,2,0) /* ghc-8.2 8.4 */ +#else /* ghc-8.2 */ HsOverLabel _reboundFromLabel name -> -#else /* ghc-8.0 */ - HsOverLabel name -> #endif let label = FastString.unpackFS name in docLit . Text.pack $ '#' : label @@ -176,19 +174,15 @@ layoutExpr lexpr@(L _ expr) = do #endif #if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */ HsLamCase _ (MG _ (L _ []) _) -> do -#elif MIN_VERSION_ghc(8,2,0) /* ghc-8.2 8.4*/ +#else /* ghc-8.2 */ HsLamCase (MG (L _ []) _ _ _) -> do -#else /* ghc-8.0 */ - HsLamCase _ (MG (L _ []) _ _ _) -> do #endif docSetParSpacing $ docAddBaseY BrIndentRegular $ (docLit $ Text.pack "\\case {}") #if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */ HsLamCase _ (MG _ lmatches@(L _ matches) _) -> do -#elif MIN_VERSION_ghc(8,2,0) /* ghc-8.2 8.4*/ +#else /* ghc-8.2 */ HsLamCase (MG lmatches@(L _ matches) _ _ _) -> do -#else /* ghc-8.0 */ - HsLamCase _ (MG lmatches@(L _ matches) _ _ _) -> do #endif binderDoc <- docLit $ Text.pack "->" funcPatDocs <- docWrapNode lmatches @@ -311,10 +305,8 @@ layoutExpr lexpr@(L _ expr) = do HsAppType XHsWildCardBndrs{} _ -> error "brittany internal error: HsAppType XHsWildCardBndrs" HsAppType (HsWC _ ty1) exp1 -> do -#elif MIN_VERSION_ghc(8,2,0) /* ghc-8.2 8.4 */ +#else /* ghc-8.2 */ HsAppType exp1 (HsWC _ ty1) -> do -#else /* ghc-8.0 */ - HsAppType exp1 (HsWC _ _ ty1) -> do #endif t <- docSharedWrapper layoutType ty1 e <- docSharedWrapper layoutExpr exp1 @@ -329,7 +321,7 @@ layoutExpr lexpr@(L _ expr) = do e (docSeq [docLit $ Text.pack "@", t ]) ] -#if !MIN_VERSION_ghc(8,6,0) /* ghc-8.0 8.2 8.4 */ +#if !MIN_VERSION_ghc(8,6,0) /* ghc-8.2 8.4 */ HsAppTypeOut{} -> do -- TODO briDocByExactInlineOnly "HsAppTypeOut{}" lexpr @@ -968,7 +960,7 @@ layoutExpr lexpr@(L _ expr) = do in docSetBaseY $ docLines $ [start] ++ linesM ++ [lineN] ++ [end] ExplicitList _ _ [] -> docLit $ Text.pack "[]" -#if !MIN_VERSION_ghc(8,6,0) /* ghc-8.0 8.2 8.4 */ +#if !MIN_VERSION_ghc(8,6,0) /* ghc-8.2 8.4 */ ExplicitPArr{} -> do -- TODO briDocByExactInlineOnly "ExplicitPArr{}" lexpr @@ -1052,10 +1044,8 @@ layoutExpr lexpr@(L _ expr) = do ExprWithTySig XHsWildCardBndrs{} _ -> error "brittany internal error: ExprWithTySig XHsWildCardBndrs" ExprWithTySig (HsWC _ (HsIB _ typ1)) exp1 -> do -#elif MIN_VERSION_ghc(8,2,0) /* ghc-8.2 8,4 */ +#else /* ghc-8.2 */ ExprWithTySig exp1 (HsWC _ (HsIB _ typ1 _)) -> do -#else /* ghc-8.0 */ - ExprWithTySig exp1 (HsIB _ (HsWC _ _ typ1)) -> do #endif expDoc <- docSharedWrapper layoutExpr exp1 typDoc <- docSharedWrapper layoutType typ1 @@ -1064,7 +1054,7 @@ layoutExpr lexpr@(L _ expr) = do , appSep $ docLit $ Text.pack "::" , typDoc ] -#if !MIN_VERSION_ghc(8,6,0) /* ghc-8.0 8.2 8.4 */ +#if !MIN_VERSION_ghc(8,6,0) /* ghc-8.2 8.4 */ ExprWithTySigOut{} -> do -- TODO briDocByExactInlineOnly "ExprWithTySigOut{}" lexpr @@ -1113,7 +1103,7 @@ layoutExpr lexpr@(L _ expr) = do ] ArithSeq{} -> briDocByExactInlineOnly "ArithSeq" lexpr -#if !MIN_VERSION_ghc(8,6,0) /* ghc-8.0 8.2 8.4 */ +#if !MIN_VERSION_ghc(8,6,0) /* ghc-8.2 8.4 */ PArrSeq{} -> do -- TODO briDocByExactInlineOnly "PArrSeq{}" lexpr @@ -1195,14 +1185,12 @@ layoutExpr lexpr@(L _ expr) = do HsWrap{} -> do -- TODO briDocByExactInlineOnly "HsWrap{}" lexpr -#if MIN_VERSION_ghc(8,2,0) /* ghc-8.2 */ HsConLikeOut{} -> do -- TODO briDocByExactInlineOnly "HsWrap{}" lexpr ExplicitSum{} -> do -- TODO briDocByExactInlineOnly "ExplicitSum{}" lexpr -#endif #if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */ XExpr{} -> error "brittany internal error: XExpr" #endif @@ -1367,7 +1355,7 @@ overLitValBriDoc = \case HsFractional (FL (SourceText t) _ _) -> BDFLit $ Text.pack t HsIsString (SourceText t) _ -> BDFLit $ Text.pack t _ -> error "overLitValBriDoc: literal with no SourceText" -#elif MIN_VERSION_ghc(8,2,0) /* ghc-8.2 */ +#else /* ghc-8.2 */ litBriDoc :: HsLit -> BriDocFInt litBriDoc = \case HsChar (SourceText t) _c -> BDFLit $ Text.pack t -- BDFLit $ Text.pack $ ['\'', c, '\''] @@ -1391,26 +1379,4 @@ overLitValBriDoc = \case HsFractional (FL t _) -> BDFLit $ Text.pack t HsIsString (SourceText t) _ -> BDFLit $ Text.pack t _ -> error "overLitValBriDoc: literal with no SourceText" -#else /* ghc-8.0 */ -litBriDoc :: HsLit -> BriDocFInt -litBriDoc = \case - HsChar t _c -> BDFLit $ Text.pack t -- BDFLit $ Text.pack $ ['\'', c, '\''] - HsCharPrim t _c -> BDFLit $ Text.pack t -- BDFLit $ Text.pack $ ['\'', c, '\''] - HsString t _fastString -> BDFLit $ Text.pack t -- BDFLit $ Text.pack $ FastString.unpackFS fastString - HsStringPrim t _byteString -> BDFLit $ Text.pack t -- BDFLit $ Text.pack $ Data.ByteString.Char8.unpack byteString - HsInt t _i -> BDFLit $ Text.pack t -- BDFLit $ Text.pack $ show i - HsIntPrim t _i -> BDFLit $ Text.pack t -- BDFLit $ Text.pack $ show i - HsWordPrim t _i -> BDFLit $ Text.pack t -- BDFLit $ Text.pack $ show i - HsInt64Prim t _i -> BDFLit $ Text.pack t -- BDFLit $ Text.pack $ show i - HsWord64Prim t _i -> BDFLit $ Text.pack t -- BDFLit $ Text.pack $ show i - HsInteger t _i _type -> BDFLit $ Text.pack t -- BDFLit $ Text.pack $ show i - HsRat (FL t _) _type -> BDFLit $ Text.pack t - HsFloatPrim (FL t _) -> BDFLit $ Text.pack t - HsDoublePrim (FL t _) -> BDFLit $ Text.pack t - -overLitValBriDoc :: OverLitVal -> BriDocFInt -overLitValBriDoc = \case - HsIntegral t _ -> BDFLit $ Text.pack t - HsFractional (FL t _) -> BDFLit $ Text.pack t - HsIsString t _ -> BDFLit $ Text.pack t #endif diff --git a/src/Language/Haskell/Brittany/Internal/Layouters/Expr.hs-boot b/src/Language/Haskell/Brittany/Internal/Layouters/Expr.hs-boot index 733ac90..606790b 100644 --- a/src/Language/Haskell/Brittany/Internal/Layouters/Expr.hs-boot +++ b/src/Language/Haskell/Brittany/Internal/Layouters/Expr.hs-boot @@ -30,7 +30,7 @@ layoutExpr :: ToBriDoc HsExpr #if MIN_VERSION_ghc(8,4,0) /* ghc-8.4 */ litBriDoc :: HsLit GhcPs -> BriDocFInt -#else /* ghc-8.0 && ghc-8.2 */ +#else /* ghc-8.2 */ litBriDoc :: HsLit -> BriDocFInt #endif diff --git a/src/Language/Haskell/Brittany/Internal/Layouters/IE.hs b/src/Language/Haskell/Brittany/Internal/Layouters/IE.hs index bfe2679..739d138 100644 --- a/src/Language/Haskell/Brittany/Internal/Layouters/IE.hs +++ b/src/Language/Haskell/Brittany/Internal/Layouters/IE.hs @@ -34,13 +34,8 @@ import Language.Haskell.Brittany.Internal.Utils -#if MIN_VERSION_ghc(8,2,0) prepareName :: LIEWrappedName name -> Located name prepareName = ieLWrappedName -#else -prepareName :: Located name -> Located name -prepareName = id -#endif layoutIE :: ToBriDoc IE layoutIE lie@(L _ ie) = docWrapNode lie $ case ie of @@ -111,7 +106,6 @@ layoutIE lie@(L _ ie) = docWrapNode lie $ case ie of ] _ -> docEmpty where -#if MIN_VERSION_ghc(8,2,0) /* ghc-8.2, 8.4, .. */ layoutWrapped _ = \case L _ (IEName n) -> docLit =<< lrdrNameToTextAnn n L _ (IEPattern n) -> do @@ -120,16 +114,6 @@ layoutIE lie@(L _ ie) = docWrapNode lie $ case ie of L _ (IEType n) -> do name <- lrdrNameToTextAnn n docLit $ Text.pack "type " <> name -#else /* ghc-8.0 */ - layoutWrapped outer n = do - name <- lrdrNameToTextAnn n - hasType <- hasAnnKeyword n AnnType - hasPattern <- hasAnnKeyword outer AnnPattern - docLit $ if - | hasType -> Text.pack "type (" <> name <> Text.pack ")" - | hasPattern -> Text.pack "pattern " <> name - | otherwise -> name -#endif -- Helper function to deal with Located lists of LIEs. -- In particular this will also associate documentation diff --git a/src/Language/Haskell/Brittany/Internal/Layouters/Import.hs b/src/Language/Haskell/Brittany/Internal/Layouters/Import.hs index d5bf0dd..ac29eda 100644 --- a/src/Language/Haskell/Brittany/Internal/Layouters/Import.hs +++ b/src/Language/Haskell/Brittany/Internal/Layouters/Import.hs @@ -26,24 +26,14 @@ import Language.Haskell.Brittany.Internal.Utils -#if MIN_VERSION_ghc(8,2,0) prepPkg :: SourceText -> String prepPkg rawN = case rawN of SourceText n -> n -- This would be odd to encounter and the -- result will most certainly be wrong NoSourceText -> "" -#else -prepPkg :: String -> String -prepPkg = id -#endif -#if MIN_VERSION_ghc(8,2,0) prepModName :: Located e -> e prepModName = unLoc -#else -prepModName :: e -> e -prepModName = id -#endif layoutImport :: ToBriDoc ImportDecl layoutImport limportD@(L _ importD) = docWrapNode limportD $ case importD of diff --git a/src/Language/Haskell/Brittany/Internal/Layouters/Pattern.hs b/src/Language/Haskell/Brittany/Internal/Layouters/Pattern.hs index de943b7..b0b13f2 100644 --- a/src/Language/Haskell/Brittany/Internal/Layouters/Pattern.hs +++ b/src/Language/Haskell/Brittany/Internal/Layouters/Pattern.hs @@ -50,14 +50,14 @@ layoutPat (ghcDL -> lpat@(L _ pat)) = docWrapNode lpat $ case pat of -- _ -> expr #if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */ VarPat _ n -> -#else /* ghc-8.0 8.2 8.4 */ +#else /* ghc-8.2 8.4 */ VarPat n -> #endif fmap Seq.singleton $ docLit $ lrdrNameToText n -- abc -> expr #if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */ LitPat _ lit -> -#else /* ghc-8.0 8.2 8.4 */ +#else /* ghc-8.2 8.4 */ LitPat lit -> #endif fmap Seq.singleton $ allocateNode $ litBriDoc lit @@ -66,7 +66,7 @@ layoutPat (ghcDL -> lpat@(L _ pat)) = docWrapNode lpat $ case pat of ParPat _ inner -> do #elif MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */ ParPat _ inner -> do -#else /* ghc-8.0 8.2 8.4 */ +#else /* ghc-8.2 8.4 */ ParPat inner -> do #endif -- (nestedpat) -> expr @@ -202,10 +202,8 @@ layoutPat (ghcDL -> lpat@(L _ pat)) = docWrapNode lpat $ case pat of SigPat _ pat1 (HsWC _ (HsIB _ ty1)) -> do #elif MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */ SigPat (HsWC _ (HsIB _ ty1)) pat1 -> do -#elif MIN_VERSION_ghc(8,2,0) /* ghc-8.2 8.4 */ +#else /* ghc-8.2 */ SigPatIn pat1 (HsWC _ (HsIB _ ty1 _)) -> do -#else /* ghc-8.0 */ - SigPatIn pat1 (HsIB _ (HsWC _ _ ty1)) -> do #endif -- i :: Int -> expr patDocs <- layoutPat pat1 @@ -260,11 +258,6 @@ layoutPat (ghcDL -> lpat@(L _ pat)) = docWrapNode lpat $ case pat of Just{} -> Seq.fromList [negDoc, litDoc] Nothing -> Seq.singleton litDoc --- if MIN_VERSION_ghc(8,0,0) --- VarPat n -> return $ stringLayouter lpat $ lrdrNameToText n --- else --- VarPat n -> return $ stringLayouter lpat $ rdrNameToText n --- endif _ -> return <$> briDocByExactInlineOnly "some unknown pattern" (ghcDL lpat) colsWrapPat :: Seq BriDocNumbered -> ToBriDocM BriDocNumbered diff --git a/src/Language/Haskell/Brittany/Internal/Layouters/Type.hs b/src/Language/Haskell/Brittany/Internal/Layouters/Type.hs index 7a1fee4..2060904 100644 --- a/src/Language/Haskell/Brittany/Internal/Layouters/Type.hs +++ b/src/Language/Haskell/Brittany/Internal/Layouters/Type.hs @@ -42,7 +42,6 @@ import DataTreePrint layoutType :: ToBriDoc HsType layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of -- _ | traceShow (ExactPrint.Types.mkAnnKey ltype) False -> error "impossible" -#if MIN_VERSION_ghc(8,2,0) #if MIN_VERSION_ghc(8,6,0) HsTyVar _ promoted name -> do #else /* ghc-8.2 ghc-8.4 */ @@ -60,11 +59,6 @@ layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of , docWrapNode name $ docLit t ] NotPromoted -> docWrapNode name $ docLit t -#else /* ghc-8.0 */ - HsTyVar name -> do - t <- lrdrNameToTextAnnTypeEqualityIsSpecial name - docWrapNode name $ docLit t -#endif #if MIN_VERSION_ghc(8,10,1) HsForAllTy _ _ bndrs (L _ (HsQualTy _ (L _ cntxts) typ2)) -> do #elif MIN_VERSION_ghc(8,6,0) @@ -547,10 +541,8 @@ layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of -- } #if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */ HsIParamTy _ (L _ (HsIPName ipName)) typ1 -> do -#elif MIN_VERSION_ghc(8,2,0) /* ghc-8.2 8.4 */ +#else /* ghc-8.2 */ HsIParamTy (L _ (HsIPName ipName)) typ1 -> do -#else /* ghc-8.0 */ - HsIParamTy (HsIPName ipName) typ1 -> do #endif typeDoc1 <- docSharedWrapper layoutType typ1 docAlt @@ -699,11 +691,7 @@ layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of briDocByExactInlineOnly "HsDocTy{}" ltype HsRecTy{} -> -- TODO briDocByExactInlineOnly "HsRecTy{}" ltype -#if MIN_VERSION_ghc(8,2,0) /* ghc-8.2 */ HsExplicitListTy _ _ typs -> do -#else /* ghc-8.0 */ - HsExplicitListTy _ typs -> do -#endif typDocs <- docSharedWrapper layoutType `mapM` typs hasComments <- hasAnyCommentsBelow ltype let specialCommaSep = appSep $ docLit $ Text.pack " ," @@ -755,27 +743,20 @@ layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of #else HsTyLit lit -> case lit of #endif -#if MIN_VERSION_ghc(8,2,0) /* ghc-8.2 */ HsNumTy (SourceText srctext) _ -> docLit $ Text.pack srctext HsNumTy NoSourceText _ -> error "overLitValBriDoc: literal with no SourceText" HsStrTy (SourceText srctext) _ -> docLit $ Text.pack srctext HsStrTy NoSourceText _ -> error "overLitValBriDoc: literal with no SourceText" -#else /* ghc-8.0 */ - HsNumTy srctext _ -> docLit $ Text.pack srctext - HsStrTy srctext _ -> docLit $ Text.pack srctext -#endif #if !MIN_VERSION_ghc(8,6,0) HsCoreTy{} -> -- TODO briDocByExactInlineOnly "HsCoreTy{}" ltype #endif HsWildCardTy _ -> docLit $ Text.pack "_" -#if MIN_VERSION_ghc(8,2,0) /* ghc-8.2 */ HsSumTy{} -> -- TODO briDocByExactInlineOnly "HsSumTy{}" ltype -#endif #if MIN_VERSION_ghc(8,6,0) HsStarTy _ isUnicode -> do if isUnicode diff --git a/src/Language/Haskell/Brittany/Internal/Prelude.hs b/src/Language/Haskell/Brittany/Internal/Prelude.hs index a0757d8..79e2975 100644 --- a/src/Language/Haskell/Brittany/Internal/Prelude.hs +++ b/src/Language/Haskell/Brittany/Internal/Prelude.hs @@ -1,4 +1,4 @@ -#if !MIN_VERSION_ghc(8,4,0) /* ghc-8.0, ghc-8.2 */ +#if !MIN_VERSION_ghc(8,4,0) /* ghc-8.2 */ {-# LANGUAGE TypeFamilies #-} #endif @@ -411,7 +411,7 @@ todo :: a todo = error "todo" -#if !MIN_VERSION_ghc(8,4,0) /* ghc-8.0, ghc-8.2 */ +#if !MIN_VERSION_ghc(8,4,0) /* ghc-8.2 */ type family IdP p type instance IdP GhcPs = RdrName @@ -422,7 +422,7 @@ type GhcPs = RdrName #if MIN_VERSION_ghc(8,8,0) ghcDL :: GHC.HasSrcSpan a => a -> GHC.Located (GHC.SrcSpanLess a) ghcDL = GHC.dL -#else /* ghc-8.0 8.2 8.4 8.6 */ +#else /* ghc-8.2 8.4 8.6 */ ghcDL :: GHC.Located a -> GHC.Located a ghcDL x = x #endif diff --git a/src/Language/Haskell/Brittany/Internal/Types.hs b/src/Language/Haskell/Brittany/Internal/Types.hs index 620a39b..f402e56 100644 --- a/src/Language/Haskell/Brittany/Internal/Types.hs +++ b/src/Language/Haskell/Brittany/Internal/Types.hs @@ -32,9 +32,7 @@ data PerItemConfig = PerItemConfig { _icd_perBinding :: Map String (CConfig Option) , _icd_perKey :: Map ExactPrint.Types.AnnKey (CConfig Option) } -#if MIN_VERSION_ghc(8,2,0) deriving Data.Data.Data -#endif type PPM = MultiRWSS.MultiRWS '[Map ExactPrint.AnnKey ExactPrint.Anns, PerItemConfig, Config, ExactPrint.Anns] diff --git a/stack-8.0.2.yaml b/stack-8.0.2.yaml deleted file mode 100644 index 80928db..0000000 --- a/stack-8.0.2.yaml +++ /dev/null @@ -1,12 +0,0 @@ -resolver: lts-9.0 - -extra-deps: - - monad-memo-0.4.1 - - czipwith-1.0.1.0 - - butcher-1.3.1.1 - - data-tree-print-0.1.0.0 - - deque-0.2 - - ghc-exactprint-0.5.8.0 - -packages: - - . \ No newline at end of file diff --git a/stack-8.0.2.yaml.lock b/stack-8.0.2.yaml.lock deleted file mode 100644 index 08d3ffb..0000000 --- a/stack-8.0.2.yaml.lock +++ /dev/null @@ -1,54 +0,0 @@ -# This file was autogenerated by Stack. -# You should not edit this file by hand. -# For more information, please see the documentation at: -# https://docs.haskellstack.org/en/stable/lock_files - -packages: -- completed: - hackage: monad-memo-0.4.1@sha256:d7575b0c89ad21818ca5746170d10a3b92f01fdf9028fa37d3a370e42b24b38b,3672 - pantry-tree: - size: 1823 - sha256: 8d7bcc8a8bce43804613a160fd7f0fea7869a54e530a9f1b9f9e853ec4e00b57 - original: - hackage: monad-memo-0.4.1 -- completed: - hackage: czipwith-1.0.1.0@sha256:30751c5a92488304863f20403cd8e9d4fee2b5def0b656a3d979aa3331a09c00,1652 - pantry-tree: - size: 323 - sha256: acd60968c5a1945741204751243f88d1af1c152018c2d9575f62c0805825f44f - original: - hackage: czipwith-1.0.1.0 -- completed: - hackage: butcher-1.3.1.1@sha256:d5734df2e42c28c5a8419eb8251cc531e5f5e6a13794b2ae1dac04abd1c359ad,3242 - pantry-tree: - size: 1197 - sha256: 057b5c8aa0211951337d87cda1f3d4c6f049945314f6fc7883394eebac79be5b - original: - hackage: butcher-1.3.1.1 -- completed: - hackage: data-tree-print-0.1.0.0@sha256:6610723626501d3ab65dc2290c0de59de8d042caf72a1db1e0cd01e84d229346,1547 - pantry-tree: - size: 272 - sha256: caa741fd498f754b42d45a16aae455056d5e71df51e960fce1579b8e8b6496ad - original: - hackage: data-tree-print-0.1.0.0 -- completed: - hackage: deque-0.2@sha256:a9736298cd04472924b3b681b3791c99e8b6009a6e5df1ff13dd57457109ad43,877 - pantry-tree: - size: 205 - sha256: c48e1f58dfac107ba9dd8d159d4c033fd72521de678204788e3f01f7a2e17546 - original: - hackage: deque-0.2 -- completed: - hackage: ghc-exactprint-0.5.8.0@sha256:71915a08a7d442d39a63cb3b0fbd90b7dacd19bc4b05bac5c53b6e8a0d931b7b,7728 - pantry-tree: - size: 83871 - sha256: 3998143d33f7de29b31e8cf8d1b207c1fb4962f819fc820e209e1eecbf7e5a35 - original: - hackage: ghc-exactprint-0.5.8.0 -snapshots: -- completed: - size: 533451 - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/9/0.yaml - sha256: 27f29b231b39ea68e967a7a4346b2693a49d77c50f41fc0c276e11189a538da7 - original: lts-9.0