Skip to content

Commit

Permalink
deleted: drop GHC 7 test
Browse files Browse the repository at this point in the history
Yesod drop support GHC 7.
[yesod/.travis.yml at cdba6c1678d8002eac94ba175e00183a7e87c09d ·
yesodweb/yesod](https://github.com/yesodweb/yesod/blob/cdba6c1678d8002eac94ba175e00183a7e87c09d/.travis.yml)

GHC 7 is slow, and GHC 7 support add CPP switch.
To drop GHC 7 get correct travis test and simple code.

I delete unneed CPP pragma.

And I run stylish-haskell all source code.
Because I want to detect unneed import.
  • Loading branch information
ncaq committed Aug 25, 2018
1 parent 924aa28 commit 3290ac9
Show file tree
Hide file tree
Showing 21 changed files with 433 additions and 589 deletions.
47 changes: 0 additions & 47 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,6 @@ matrix:
include:
# We grab the appropriate GHC and cabal-install versions from hvr's PPA. See:
# https://github.com/hvr/multi-ghc-travis
#- env: BUILD=cabal GHCVER=7.0.4 CABALVER=1.16 HAPPYVER=1.19.5 ALEXVER=3.1.7
# compiler: ": #GHC 7.0.4"
# addons: {apt: {packages: [cabal-install-1.16,ghc-7.0.4,happy-1.19.5,alex-3.1.7], sources: [hvr-ghc]}}
#- env: BUILD=cabal GHCVER=7.2.2 CABALVER=1.16 HAPPYVER=1.19.5 ALEXVER=3.1.7
# compiler: ": #GHC 7.2.2"
# addons: {apt: {packages: [cabal-install-1.16,ghc-7.2.2,happy-1.19.5,alex-3.1.7], sources: [hvr-ghc]}}
#- env: BUILD=cabal GHCVER=7.4.2 CABALVER=1.16 HAPPYVER=1.19.5 ALEXVER=3.1.7
# compiler: ": #GHC 7.4.2"
# addons: {apt: {packages: [cabal-install-1.16,ghc-7.4.2,happy-1.19.5,alex-3.1.7], sources: [hvr-ghc]}}
- env: BUILD=cabal GHCVER=7.6.3 CABALVER=1.16 HAPPYVER=1.19.5 ALEXVER=3.1.7
compiler: ": #GHC 7.6.3"
addons: {apt: {packages: [cabal-install-1.16,ghc-7.6.3,happy-1.19.5,alex-3.1.7], sources: [hvr-ghc]}}
- env: BUILD=cabal GHCVER=7.8.4 CABALVER=1.18 HAPPYVER=1.19.5 ALEXVER=3.1.7
compiler: ": #GHC 7.8.4"
addons: {apt: {packages: [cabal-install-1.18,ghc-7.8.4,happy-1.19.5,alex-3.1.7], sources: [hvr-ghc]}}
- env: BUILD=cabal GHCVER=7.10.3 CABALVER=1.22 HAPPYVER=1.19.5 ALEXVER=3.1.7
compiler: ": #GHC 7.10.3"
addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.3,happy-1.19.5,alex-3.1.7], sources: [hvr-ghc]}}
- env: BUILD=cabal GHCVER=8.0.2 CABALVER=1.24 HAPPYVER=1.19.5 ALEXVER=3.1.7
compiler: ": #GHC 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]}}
Expand All @@ -65,22 +47,6 @@ matrix:

# The Stack builds. We can pass in arbitrary Stack arguments via the ARGS
# variable, such as using --stack-yaml to point to a different file.
- env: BUILD=stack ARGS=""
compiler: ": #stack default"
addons: {apt: {packages: [libgmp-dev]}}

- env: BUILD=stack ARGS="--resolver lts-2"
compiler: ": #stack 7.8.4"
addons: {apt: {packages: [libgmp-dev]}}

- env: BUILD=stack ARGS="--resolver lts-3"
compiler: ": #stack 7.10.2"
addons: {apt: {packages: [libgmp-dev]}}

- env: BUILD=stack ARGS="--resolver lts-6"
compiler: ": #stack 7.10.3"
addons: {apt: {packages: [libgmp-dev]}}

- env: BUILD=stack ARGS="--resolver lts-7"
compiler: ": #stack 8.0.1"
addons: {apt: {packages: [libgmp-dev]}}
Expand All @@ -99,19 +65,6 @@ matrix:
compiler: ": #stack default osx"
os: osx

# Travis includes an macOS which is incompatible with GHC 7.8.4
#- env: BUILD=stack ARGS="--resolver lts-2"
# compiler: ": #stack 7.8.4 osx"
# os: osx

- env: BUILD=stack ARGS="--resolver lts-3"
compiler: ": #stack 7.10.2 osx"
os: osx

- env: BUILD=stack ARGS="--resolver lts-6"
compiler: ": #stack 7.10.3 osx"
os: osx

- env: BUILD=stack ARGS="--resolver lts-7"
compiler: ": #stack 8.0.1 osx"
os: osx
Expand Down
32 changes: 14 additions & 18 deletions Text/Cassius.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-missing-fields #-}
module Text.Cassius
( -- * Datatypes
Expand Down Expand Up @@ -40,25 +39,22 @@ module Text.Cassius
, cassiusUsedIdentifiers
) where

import Text.Internal.Css
import Text.Shakespeare.Base
import Text.Shakespeare (VarType)
import Language.Haskell.TH.Quote (QuasiQuoter (..))
import Language.Haskell.TH.Syntax
import qualified Data.Text.Lazy as TL
import Text.Internal.CssCommon
import Text.Lucius (lucius)
import qualified Data.Text.Lazy as TL
import Language.Haskell.TH.Quote (QuasiQuoter (..))
import Language.Haskell.TH.Syntax
import Text.IndentToBrace (i2b)
import Text.Internal.Css
import Text.Internal.CssCommon
import Text.Lucius (lucius)
import qualified Text.Lucius
import Text.IndentToBrace (i2b)
import Text.Shakespeare (VarType)
import Text.Shakespeare.Base

cassius :: QuasiQuoter
cassius = QuasiQuoter { quoteExp = quoteExp lucius . i2b }

cassiusFile :: FilePath -> Q Exp
cassiusFile fp = do
#ifdef GHC_7_4
qAddDependentFile fp
#endif
contents <- fmap TL.unpack $ qRunIO $ readUtf8File fp
quoteExp cassius contents

Expand Down Expand Up @@ -93,8 +89,8 @@ i2bMixin s' =
stripFront x y =
case TL.stripPrefix x y of
Nothing -> y
Just z -> z
Just z -> z
stripEnd x y =
case TL.stripSuffix x y of
Nothing -> y
Just z -> z
Just z -> z
15 changes: 7 additions & 8 deletions Text/Coffee.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -fno-warn-missing-fields #-}
-- | A Shakespearean module for CoffeeScript, introducing type-safe,
-- compile-time variable and url interpolation. It is exactly the same as
Expand All @@ -19,7 +18,7 @@
-- and then the value of the variables are applied to the function.
-- This means that in production the template can be compiled
-- once at compile time and there will be no dependency in your production
-- system on @coffee@.
-- system on @coffee@.
--
-- Your code:
--
Expand Down Expand Up @@ -61,10 +60,10 @@ module Text.Coffee
#endif
) where

import Language.Haskell.TH.Quote (QuasiQuoter (..))
import Language.Haskell.TH.Syntax
import Text.Shakespeare
import Text.Julius
import Language.Haskell.TH.Quote (QuasiQuoter (..))
import Language.Haskell.TH.Syntax
import Text.Julius
import Text.Shakespeare

coffeeSettings :: Q ShakespeareSettings
coffeeSettings = do
Expand All @@ -74,7 +73,7 @@ coffeeSettings = do
preConvert = ReadProcess "coffee" ["-spb"]
, preEscapeIgnoreBalanced = "'\"`" -- don't insert backtacks for variable already inside strings or backticks.
, preEscapeIgnoreLine = "#" -- ignore commented lines
, wrapInsertion = Just WrapInsertion {
, wrapInsertion = Just WrapInsertion {
wrapInsertionIndent = Just " "
, wrapInsertionStartBegin = "("
, wrapInsertionSeparator = ", "
Expand Down
125 changes: 55 additions & 70 deletions Text/Hamlet.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-missing-fields #-}
module Text.Hamlet
( -- * Plain HTML
Expand Down Expand Up @@ -48,32 +47,26 @@ module Text.Hamlet
, hamletFromString
) where

import Text.Shakespeare.Base
import Text.Hamlet.Parse
#if MIN_VERSION_template_haskell(2,9,0)
import Language.Haskell.TH.Syntax hiding (Module)
#else
import Language.Haskell.TH.Syntax
#endif
import Language.Haskell.TH.Quote
import Data.Char (isUpper, isDigit)
import Data.Maybe (fromMaybe)
import Data.Text (Text, pack)
import qualified Data.Text.Lazy as TL
import Text.Blaze.Html (Html, toHtml)
import Text.Blaze.Internal (preEscapedText)
import qualified Data.Foldable as F
import Control.Monad (mplus)
import Data.Monoid (mempty, mappend, mconcat)
import Control.Arrow ((***))
import Data.List (intercalate)

import Data.IORef
import qualified Data.Map as M
import System.IO.Unsafe (unsafePerformIO)
import System.Directory (getModificationTime)
import Data.Time (UTCTime)
import Text.Blaze.Html (preEscapedToHtml)
import Control.Arrow ((***))
import Control.Monad (mplus)
import Data.Char (isDigit, isUpper)
import qualified Data.Foldable as F
import Data.IORef
import Data.List (intercalate)
import qualified Data.Map as M
import Data.Maybe (fromMaybe)
import Data.Monoid (mappend, mconcat, mempty)
import Data.Text (Text, pack)
import qualified Data.Text.Lazy as TL
import Data.Time (UTCTime)
import Language.Haskell.TH.Quote
import Language.Haskell.TH.Syntax hiding (Module)
import System.Directory (getModificationTime)
import System.IO.Unsafe (unsafePerformIO)
import Text.Blaze.Html (Html, preEscapedToHtml, toHtml)
import Text.Blaze.Internal (preEscapedText)
import Text.Hamlet.Parse
import Text.Shakespeare.Base

-- | Convert some value to a list of attribute pairs.
class ToAttributes a where
Expand Down Expand Up @@ -112,18 +105,18 @@ docsToExp :: Env -> HamletRules -> Scope -> [Doc] -> Q Exp
docsToExp env hr scope docs = do
exps <- mapM (docToExp env hr scope) docs
case exps of
[] -> [|return ()|]
[] -> [|return ()|]
[x] -> return x
_ -> return $ DoE $ map NoBindS exps
_ -> return $ DoE $ map NoBindS exps

unIdent :: Ident -> String
unIdent (Ident s) = s

bindingPattern :: Binding -> Q (Pat, [(Ident, Exp)])
bindingPattern (BindAs i@(Ident s) b) = do
name <- newName s
(pattern, scope) <- bindingPattern b
return (AsP name pattern, (i, VarE name):scope)
(newPattern, scope) <- bindingPattern b
return (AsP name newPattern, (i, VarE name):scope)
bindingPattern (BindVar i@(Ident s))
| s == "_" = return (WildP, [])
| all isDigit s = do
Expand Down Expand Up @@ -154,7 +147,7 @@ mkConName :: DataConstr -> Name
mkConName = mkName . conToStr

conToStr :: DataConstr -> String
conToStr (DCUnqualified (Ident x)) = x
conToStr (DCUnqualified (Ident x)) = x
conToStr (DCQualified (Module xs) (Ident x)) = intercalate "." $ xs ++ [x]

-- Wildcards bind all of the unbound fields to variables whose name
Expand Down Expand Up @@ -183,13 +176,8 @@ recordToFieldNames conStr = do
-- use 'lookupValueName' instead of just using 'mkName' so we reify the
-- data constructor and not the type constructor if their names match.
Just conName <- lookupValueName $ conToStr conStr
#if MIN_VERSION_template_haskell(2,11,0)
DataConI _ _ typeName <- reify conName
TyConI (DataD _ _ _ _ cons _) <- reify typeName
#else
DataConI _ _ typeName _ <- reify conName
TyConI (DataD _ _ _ cons _) <- reify typeName
#endif
[fields] <- return [fields | RecC name fields <- cons, name == conName]
return [fieldName | (fieldName, _, _) <- fields]

Expand Down Expand Up @@ -401,8 +389,8 @@ hamletWithSettings hr set =

data HamletRules = HamletRules
{ hrFromHtml :: Exp
, hrWithEnv :: (Env -> Q Exp) -> Q Exp
, hrEmbed :: Env -> Exp -> Q Exp
, hrWithEnv :: (Env -> Q Exp) -> Q Exp
, hrEmbed :: Env -> Exp -> Q Exp
}

data Env = Env
Expand All @@ -418,14 +406,11 @@ hamletFromString qhr set s = do
docFromString :: HamletSettings -> String -> [Doc]
docFromString set s =
case parseDoc set s of
Error s' -> error s'
Error s' -> error s'
Ok (_, d) -> d

hamletFileWithSettings :: Q HamletRules -> HamletSettings -> FilePath -> Q Exp
hamletFileWithSettings qhr set fp = do
#ifdef GHC_7_4
qAddDependentFile fp
#endif
contents <- fmap TL.unpack $ qRunIO $ readUtf8File fp
hamletFromString qhr set contents

Expand Down Expand Up @@ -474,7 +459,7 @@ ihamletFile :: FilePath -> Q Exp
ihamletFile = hamletFileWithSettings ihamletRules defaultHamletSettings

varName :: Scope -> String -> Exp
varName _ "" = error "Illegal empty varName"
varName _ "" = error "Illegal empty varName"
varName scope v@(_:_) = fromMaybe (strToExp v) $ lookup (Ident v) scope

strToExp :: String -> Exp
Expand Down Expand Up @@ -511,21 +496,21 @@ data VarExp msg url = EPlain Html
| EMsg msg

instance Show (VarExp msg url) where
show (EPlain html) = "EPlain"
show (EUrl url) = "EUrl"
show (EUrlParam url) = "EUrlParam"
show (EMixin url) = "EMixin"
show (EPlain html) = "EPlain"
show (EUrl url) = "EUrl"
show (EUrlParam url) = "EUrlParam"
show (EMixin url) = "EMixin"
show (EMixinI18n msg_url) = "EMixinI18n"
show (EMsg msg) = "EMsg"
show (EMsg msg) = "EMsg"

getVars :: Content -> [(Deref, VarType)]
getVars ContentRaw{} = []
getVars (ContentVar d) = [(d, VTPlain)]
getVars ContentRaw{} = []
getVars (ContentVar d) = [(d, VTPlain)]
getVars (ContentUrl False d) = [(d, VTUrl)]
getVars (ContentUrl True d) = [(d, VTUrlParam)]
getVars (ContentEmbed d) = [(d, VTMixin)]
getVars (ContentMsg d) = [(d, VTMsg)]
getVars (ContentAttrs d) = [(d, VTAttrs)]
getVars (ContentUrl True d) = [(d, VTUrlParam)]
getVars (ContentEmbed d) = [(d, VTMixin)]
getVars (ContentMsg d) = [(d, VTMsg)]
getVars (ContentAttrs d) = [(d, VTAttrs)]

hamletUsedIdentifiers :: HamletSettings -> String -> [(Deref, VarType)]
hamletUsedIdentifiers settings =
Expand Down Expand Up @@ -556,12 +541,12 @@ hamletFileReloadWithSettings hrr settings fp = do
toExp = c
where
c :: VarType -> Q Exp
c VTAttrs = [|EPlain . attrsToHtml . toAttributes|]
c VTPlain = [|EPlain . toHtml|]
c VTUrl = [|EUrl|]
c VTAttrs = [|EPlain . attrsToHtml . toAttributes|]
c VTPlain = [|EPlain . toHtml|]
c VTUrl = [|EUrl|]
c VTUrlParam = [|EUrlParam|]
c VTMixin = [|\r -> EMixin $ \c -> r c|]
c VTMsg = [|EMsg|]
c VTMixin = [|\r -> EMixin $ \c -> r c|]
c VTMsg = [|EMsg|]

-- move to Shakespeare.Base?
readFileUtf8 :: FilePath -> IO String
Expand Down Expand Up @@ -591,11 +576,11 @@ contentFromString set = map justContent . docFromString set

justContent :: Doc -> Content
justContent (DocContent c) = c
justContent DocForall{} = unsupported "$forall"
justContent DocWith{} = unsupported "$with"
justContent DocMaybe{} = unsupported "$maybe"
justContent DocCase{} = unsupported "$case"
justContent DocCond{} = unsupported "attribute conditionals"
justContent DocForall{} = unsupported "$forall"
justContent DocWith{} = unsupported "$with"
justContent DocMaybe{} = unsupported "$maybe"
justContent DocCase{} = unsupported "$case"
justContent DocCond{} = unsupported "attribute conditionals"


hamletRuntime :: HamletSettings
Expand Down Expand Up @@ -639,7 +624,7 @@ hamletRuntimeMsg settings fp cd i18nRender render = unsafePerformIO $ do
go' = mconcat . map (runtimeContentToHtml cd render i18nRender handleMsg)
handleMsg d = case lookup d cd of
Just (EMsg s) -> i18nRender s
_ -> nothingError "EMsg for ContentMsg" d
_ -> nothingError "EMsg for ContentMsg" d

nothingError :: Show a => String -> a -> b
nothingError expected d = error $ "expected " ++ expected ++ " but got Nothing for: " ++ show d
Expand Down Expand Up @@ -669,6 +654,6 @@ runtimeContentToHtml cd render i18nRender handleMsg = go
toHtml $ render u p
_ -> error $ show d ++ ": expected EUrlParam"
go (ContentEmbed d) = case lookup d cd of
Just (EMixin m) -> m render
Just (EMixin m) -> m render
Just (EMixinI18n m) -> m i18nRender render
_ -> error $ show d ++ ": expected EMixin"
_ -> error $ show d ++ ": expected EMixin"
Loading

0 comments on commit 3290ac9

Please sign in to comment.