1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE Rank2Types #-}
3 {-# LANGUAGE TypeFamilies #-}
4 module Language.TCT.Read.Cell where
6 import Data.Char (Char)
7 import Data.Either (Either(..))
8 import Data.Function (($), (.))
9 import Data.Functor ((<$>))
11 import Data.List.NonEmpty (NonEmpty(..))
12 import Data.Maybe (Maybe(..))
14 import Data.String (String, IsString)
15 import Prelude (Num(..), toInteger)
16 import Text.Show (Show)
17 import qualified Data.Set as Set
18 import qualified Text.Megaparsec as P
20 import Language.TCT.Cell
23 -- | Convenient alias.
28 , IsString (P.Tokens s)
31 p_satisfyMaybe :: P.MonadParsec e s m => (P.Token s -> Maybe a) -> m a
32 p_satisfyMaybe f = check `P.token` Nothing
37 Nothing -> Left (Just $ P.Tokens $ c:|[], Set.empty)
39 p_Position :: Parser e s Pos
40 p_Position = (<$> P.getPosition) $ \p ->
42 (intOfPos $ P.sourceLine p)
43 (intOfPos $ P.sourceColumn p)
44 intOfPos :: P.Pos -> Int
45 intOfPos = fromInteger . toInteger . P.unPos
47 p_LineNum :: Parser e s Line
48 p_LineNum = intOfPos . P.sourceLine <$> P.getPosition
50 p_ColNum :: Parser e s Column
51 p_ColNum = intOfPos . P.sourceColumn <$> P.getPosition
56 , P.ShowToken (P.Token s)
58 ) => String -> P.ParsecT e s m a -> P.ParsecT e s m a
59 -- pdbg m p = P.dbg m p