Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GHC 7.10 compatibility update #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions invertible-syntax-poly.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: invertible-syntax-poly
version: 0.1.0.0
version: 0.1.0.1
synopsis: Extends invertible-syntax library
capable to use parameterized token type.
description: Extends invertible-syntax library
Expand All @@ -12,7 +12,7 @@ maintainer: Kei Hibino <[email protected]>
category: Text
stability: experimental
build-type: Simple
cabal-version: >=1.2
cabal-version: >=1.6

library
hs-source-dirs: src
Expand Down Expand Up @@ -40,7 +40,8 @@ library

build-depends: base < 5
, partial-isomorphisms


ghc-options: -Wall

source-repository head
type: git
Expand Down
3 changes: 0 additions & 3 deletions src/Control/Isomorphism/Partial/Ext/Prim.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ module Control.Isomorphism.Partial.Ext.Prim (
mayPrepend', (?||), mayPrepend
) where



import Prelude hiding (id)
import qualified Prelude as P
import Control.Category (id)
import Control.Isomorphism.Partial.Prim (inverse, apply, unapply)
import Control.Isomorphism.Partial.Unsafe (Iso (Iso))
Expand Down
3 changes: 1 addition & 2 deletions src/Text/Syntax/Check/Prim.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ module Text.Syntax.Check.Prim (
) where

import Text.Syntax.Poly.Type (SyntaxT, RunAsParser, RunAsPrinter)

import Text.Syntax.Printer.List (runAsPrinter)
import Text.Syntax.Parser.List.LazyMaybe (runAsParser)
import Text.Syntax.Parser.List.LazyMaybe (runAsParser)

-- | Run print and parse series, then check the equality between input and output.
printParseIso0 :: (Eq a, Show e0, Show e1) =>
Expand Down
6 changes: 6 additions & 0 deletions src/Text/Syntax/Parser/Instances.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

-- |
-- Module : Text.Syntax.Parser.Instances
Expand All @@ -19,6 +21,10 @@ import Control.Monad (MonadPlus (mzero))
import Control.Isomorphism.Partial.Ext.Prim (apply')
import Text.Syntax.Poly.Instances ()

#if __GLASGOW_HASKELL__ >= 710
import Prelude hiding ((<$>))
#endif

-- | 'IsoFunctor' instance for parsers on 'MonadPlus' context
instance MonadPlus m => IsoFunctor m where
iso <$> mp = do a <- mp
Expand Down
19 changes: 18 additions & 1 deletion src/Text/Syntax/Parser/List/Compose.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE CPP #-}

-- |
-- Module : Text.Syntax.Parser.List.Compose
Expand All @@ -20,7 +21,12 @@ module Text.Syntax.Parser.List.Compose (
runAsParser
) where

import Control.Monad (MonadPlus(mzero, mplus))
import Control.Applicative (Alternative(empty, (<|>)))
import Control.Monad (MonadPlus(mzero, mplus), ap, liftM)

#if __GLASGOW_HASKELL__ < 710
import Control.Applicative (Applicative(pure, (<*>)))
#endif

import Text.Syntax.Parser.Instances ()
import Text.Syntax.Poly.Class
Expand Down Expand Up @@ -55,11 +61,22 @@ runParser p0 s0 = let z = d p0 s0 in z `seq` z where
Bad -> runParser p2 s
r1@(Good _ _) -> r1

instance Functor (Parser tok) where
fmap = liftM

instance Applicative (Parser tok) where
pure = return
(<*>) = ap

instance Monad (Parser tok) where
return = Prim . Good
(>>=) = (:>>=)
fail = const mzero

instance Alternative (Parser tok) where
empty = mzero
(<|>) = mplus

instance MonadPlus (Parser tok) where
mzero = Prim $ const Bad
mplus = (:<|>)
Expand Down
19 changes: 18 additions & 1 deletion src/Text/Syntax/Parser/List/Lazy.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE CPP #-}

-- |
-- Module : Text.Syntax.Parser.List.Lazy
Expand All @@ -18,7 +19,12 @@ module Text.Syntax.Parser.List.Lazy (
runAsParser
) where

import Control.Monad (MonadPlus(mzero, mplus))
import Control.Applicative (Alternative(empty, (<|>)))
import Control.Monad (MonadPlus(mzero, mplus), ap, liftM)

#if __GLASGOW_HASKELL__ < 710
import Control.Applicative (Applicative(pure, (<*>)))
#endif

import Text.Syntax.Parser.Instances ()
import Text.Syntax.Poly.Instances ()
Expand All @@ -33,12 +39,23 @@ newtype Parser tok alpha =
runParser :: [tok] -> ErrorStack -> Either ErrorStack (alpha, [tok])
}

instance Functor (Parser tok) where
fmap = liftM

instance Applicative (Parser tok) where
pure = return
(<*>) = ap

instance Monad (Parser tok) where
return a = Parser $ \s _ -> Right (a, s)
Parser p >>= fb = Parser (\s e -> do (a, s') <- p s e
runParser (fb a) s' e)
fail msg = Parser (\_ e -> Left $ errorString msg : e)

instance Alternative (Parser tok) where
empty = mzero
(<|>) = mplus

instance MonadPlus (Parser tok) where
mzero = Parser $ const Left
Parser p1 `mplus` p2' =
Expand Down
21 changes: 19 additions & 2 deletions src/Text/Syntax/Parser/List/LazyMaybe.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}

{-# LANGUAGE CPP #-}

-- |
-- Module : Text.Syntax.Parser.List.LazyMaybe
Expand All @@ -19,7 +19,13 @@ module Text.Syntax.Parser.List.LazyMaybe (
runAsParser
) where

import Control.Monad (MonadPlus(mzero, mplus))

import Control.Applicative (Alternative(empty, (<|>)))
import Control.Monad (MonadPlus(mzero, mplus), ap, liftM)

#if __GLASGOW_HASKELL__ < 710
import Control.Applicative (Applicative(pure, (<*>)))
#endif

import Text.Syntax.Parser.Instances ()
import Text.Syntax.Poly.Class
Expand All @@ -33,12 +39,23 @@ newtype Parser tok alpha =
runParser :: [tok] -> Maybe (alpha, [tok])
}

instance Functor (Parser tok) where
fmap = liftM

instance Applicative (Parser tok) where
pure = return
(<*>) = ap

instance Monad (Parser tok) where
return a = Parser $ \s -> Just (a, s)
Parser p >>= fb = Parser (\s -> do (a, s') <- p s
runParser (fb a) s')
fail = const mzero

instance Alternative (Parser tok) where
empty = mzero
(<|>) = mplus

instance MonadPlus (Parser tok) where
mzero = Parser $ const Nothing
Parser p1 `mplus` p2' =
Expand Down
19 changes: 18 additions & 1 deletion src/Text/Syntax/Parser/List/Strict.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}

-- |
-- Module : Text.Syntax.Parser.List.Strict
Expand All @@ -19,7 +20,12 @@ module Text.Syntax.Parser.List.Strict (
runAsParser
) where

import Control.Monad (MonadPlus(mzero, mplus))
import Control.Applicative (Alternative(empty, (<|>)))
import Control.Monad (MonadPlus(mzero, mplus), ap, liftM)

#if __GLASGOW_HASKELL__ < 710
import Control.Applicative (Applicative(pure, (<*>)))
#endif

import Text.Syntax.Parser.Instances ()
import Text.Syntax.Poly.Class
Expand All @@ -36,6 +42,13 @@ newtype Parser tok alpha =
runParser :: [tok] -> ErrorStack -> Result alpha tok
}

instance Functor (Parser tok) where
fmap = liftM

instance Applicative (Parser tok) where
pure = return
(<*>) = ap

instance Monad (Parser tok) where
return !a = Parser $ \s _ -> Good a s
Parser !p >>= fb = Parser (\s e -> case p s e of
Expand All @@ -44,6 +57,10 @@ instance Monad (Parser tok) where
Bad e' -> Bad $ e' ++ e)
fail msg = Parser (\_ e -> Bad $ errorString msg : e)

instance Alternative (Parser tok) where
empty = mzero
(<|>) = mplus

instance MonadPlus (Parser tok) where
mzero = Parser $ const Bad
Parser p1 `mplus` p2' =
Expand Down
19 changes: 18 additions & 1 deletion src/Text/Syntax/Parser/List/StrictMaybe.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}

-- |
-- Module : Text.Syntax.Parser.List.StrictMaybe
Expand All @@ -19,7 +20,12 @@ module Text.Syntax.Parser.List.StrictMaybe (
runAsParser
) where

import Control.Monad (MonadPlus(mzero, mplus))
import Control.Applicative (Alternative(empty, (<|>)))
import Control.Monad (MonadPlus(mzero, mplus), ap, liftM)

#if __GLASGOW_HASKELL__ < 710
import Control.Applicative (Applicative(pure, (<*>)))
#endif

import Text.Syntax.Parser.Instances ()
import Text.Syntax.Poly.Class
Expand All @@ -36,6 +42,13 @@ newtype Parser tok alpha =
runParser :: [tok] -> Result alpha tok
}

instance Functor (Parser tok) where
fmap = liftM

instance Applicative (Parser tok) where
pure = return
(<*>) = ap

instance Monad (Parser tok) where
return !a = Parser $ \s -> Good a s
Parser p >>= fb = Parser (\s -> case p s of
Expand All @@ -45,6 +58,10 @@ instance Monad (Parser tok) where
Bad -> Bad)
fail = const mzero

instance Alternative (Parser tok) where
empty = mzero
(<|>) = mplus

instance MonadPlus (Parser tok) where
mzero = Parser $ const Bad
Parser p1 `mplus` Parser p2 =
Expand Down
1 change: 1 addition & 0 deletions src/Text/Syntax/Parser/ReadP.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances, UndecidableInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

-- |
-- Module : Text.Syntax.Poly.Parser.ReadP
Expand Down
8 changes: 7 additions & 1 deletion src/Text/Syntax/Poly/Class.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE CPP #-}

#if __GLASGOW_HASKELL__ == 708
{-# OPTIONS_GHC -fno-warn-amp #-}
#endif

-- |
-- Module : Text.Syntax.Poly.Class
Expand Down Expand Up @@ -57,6 +63,6 @@ class (IsoFunctor delta, ProductFunctor delta,
syntaxError = const empty

-- | Syntax abstraction with token type @tok@.
class AbstractSyntax delta => Syntax tok delta where
class AbstractSyntax delta => Syntax tok delta | delta -> tok where
-- | Get a token from stream.
token :: delta tok
5 changes: 5 additions & 0 deletions src/Text/Syntax/Poly/Combinators.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE CPP #-}

-- |
-- Module : Text.Syntax.Poly.Combinators
Expand Down Expand Up @@ -37,7 +38,11 @@ module Text.Syntax.Poly.Combinators (
format
) where

#if __GLASGOW_HASKELL__ < 710
import Prelude hiding (foldl, succ, replicate, (.))
#else
import Prelude hiding (foldl, succ, replicate, (.), (<$>), (<*>), (<*), (*>))
#endif

import Control.Isomorphism.Partial.Ext
(nothing, just, nil, cons, left, right, foldl,
Expand Down
4 changes: 4 additions & 0 deletions src/Text/Syntax/Poly/Combinators/Char.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE CPP #-}

-- |
-- Module : Text.Syntax.Poly.Combinators.Char
Expand All @@ -22,6 +23,9 @@ module Text.Syntax.Poly.Combinators.Char (
optSpace
) where

#if __GLASGOW_HASKELL__ >= 710
import Prelude hiding ((<$>), (<*))
#endif
import Data.Char (isSpace)
import Control.Isomorphism.Partial.Prim ((<$>), ignore, subset)
import Text.Syntax.Poly.Class (Syntax, syntax, token)
Expand Down
6 changes: 6 additions & 0 deletions src/Text/Syntax/Poly/Instances.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

-- |
-- Module : Text.Syntax.Poly.Instances
Expand All @@ -21,6 +23,10 @@ import Text.Syntax.Poly.Class
IsoAlternative((<||>), empty), TryAlternative,
AbstractSyntax(syntax, syntaxError))

#if __GLASGOW_HASKELL__ >= 710
import Prelude hiding ((<*>))
#endif

-- | 'ProductFunctor' instance on 'Monad' context
-- which is a prerequisite for 'Syntax' definitions.
instance Monad m => ProductFunctor m where
Expand Down
5 changes: 5 additions & 0 deletions src/Text/Syntax/Printer/List.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE CPP #-}

-- |
-- Module : Text.Syntax.Printer.List
Expand Down Expand Up @@ -30,6 +31,10 @@ import Text.Syntax.Poly.Class
import Text.Syntax.Poly.Type (ErrorString, errorString)
import qualified Text.Syntax.Poly.Type as T

#if __GLASGOW_HASKELL__ >= 710
import Prelude hiding ((<$>), (<*>))
#endif

-- | Naive 'Printer' type. Print @alpha@ into @[tok]@.
newtype Printer tok alpha =
Printer {
Expand Down