{- |
  Module        : Text.Tokenizer.Types
  Copyright     : (c) Lev Dvorkin, 2022
  License       : MIT
  Maintainer    : lev_135@mail.ru
  Stability     : Experimental

  This module contains common types used by uniqueness checking and
  tokenizing algorithms
-}
module Text.Tokenizer.Types (
    Alt (..), Count (..), Repeatable (..),
    TokId, Token (..), RToken (..), makeRToken
  ) where

import Data.Function (on)

import Text.Tokenizer.BlackWhiteSet (BlackWhiteSet)
import Control.Applicative (Alternative)

-- | Type synonym for list monad used as a collection of alternatives

newtype Alt a = Alt [a]
  deriving (
      Alt a -> Alt a -> Bool
(Alt a -> Alt a -> Bool) -> (Alt a -> Alt a -> Bool) -> Eq (Alt a)
forall a. Eq a => Alt a -> Alt a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Alt a -> Alt a -> Bool
$c/= :: forall a. Eq a => Alt a -> Alt a -> Bool
== :: Alt a -> Alt a -> Bool
$c== :: forall a. Eq a => Alt a -> Alt a -> Bool
Eq, Eq (Alt a)
Eq (Alt a)
-> (Alt a -> Alt a -> Ordering)
-> (Alt a -> Alt a -> Bool)
-> (Alt a -> Alt a -> Bool)
-> (Alt a -> Alt a -> Bool)
-> (Alt a -> Alt a -> Bool)
-> (Alt a -> Alt a -> Alt a)
-> (Alt a -> Alt a -> Alt a)
-> Ord (Alt a)
Alt a -> Alt a -> Bool
Alt a -> Alt a -> Ordering
Alt a -> Alt a -> Alt a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (Alt a)
forall a. Ord a => Alt a -> Alt a -> Bool
forall a. Ord a => Alt a -> Alt a -> Ordering
forall a. Ord a => Alt a -> Alt a -> Alt a
min :: Alt a -> Alt a -> Alt a
$cmin :: forall a. Ord a => Alt a -> Alt a -> Alt a
max :: Alt a -> Alt a -> Alt a
$cmax :: forall a. Ord a => Alt a -> Alt a -> Alt a
>= :: Alt a -> Alt a -> Bool
$c>= :: forall a. Ord a => Alt a -> Alt a -> Bool
> :: Alt a -> Alt a -> Bool
$c> :: forall a. Ord a => Alt a -> Alt a -> Bool
<= :: Alt a -> Alt a -> Bool
$c<= :: forall a. Ord a => Alt a -> Alt a -> Bool
< :: Alt a -> Alt a -> Bool
$c< :: forall a. Ord a => Alt a -> Alt a -> Bool
compare :: Alt a -> Alt a -> Ordering
$ccompare :: forall a. Ord a => Alt a -> Alt a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (Alt a)
Ord, Int -> Alt a -> ShowS
[Alt a] -> ShowS
Alt a -> String
(Int -> Alt a -> ShowS)
-> (Alt a -> String) -> ([Alt a] -> ShowS) -> Show (Alt a)
forall a. Show a => Int -> Alt a -> ShowS
forall a. Show a => [Alt a] -> ShowS
forall a. Show a => Alt a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Alt a] -> ShowS
$cshowList :: forall a. Show a => [Alt a] -> ShowS
show :: Alt a -> String
$cshow :: forall a. Show a => Alt a -> String
showsPrec :: Int -> Alt a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Alt a -> ShowS
Show,
      a -> Alt b -> Alt a
(a -> b) -> Alt a -> Alt b
(forall a b. (a -> b) -> Alt a -> Alt b)
-> (forall a b. a -> Alt b -> Alt a) -> Functor Alt
forall a b. a -> Alt b -> Alt a
forall a b. (a -> b) -> Alt a -> Alt b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Alt b -> Alt a
$c<$ :: forall a b. a -> Alt b -> Alt a
fmap :: (a -> b) -> Alt a -> Alt b
$cfmap :: forall a b. (a -> b) -> Alt a -> Alt b
Functor, Functor Alt
a -> Alt a
Functor Alt
-> (forall a. a -> Alt a)
-> (forall a b. Alt (a -> b) -> Alt a -> Alt b)
-> (forall a b c. (a -> b -> c) -> Alt a -> Alt b -> Alt c)
-> (forall a b. Alt a -> Alt b -> Alt b)
-> (forall a b. Alt a -> Alt b -> Alt a)
-> Applicative Alt
Alt a -> Alt b -> Alt b
Alt a -> Alt b -> Alt a
Alt (a -> b) -> Alt a -> Alt b
(a -> b -> c) -> Alt a -> Alt b -> Alt c
forall a. a -> Alt a
forall a b. Alt a -> Alt b -> Alt a
forall a b. Alt a -> Alt b -> Alt b
forall a b. Alt (a -> b) -> Alt a -> Alt b
forall a b c. (a -> b -> c) -> Alt a -> Alt b -> Alt c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: Alt a -> Alt b -> Alt a
$c<* :: forall a b. Alt a -> Alt b -> Alt a
*> :: Alt a -> Alt b -> Alt b
$c*> :: forall a b. Alt a -> Alt b -> Alt b
liftA2 :: (a -> b -> c) -> Alt a -> Alt b -> Alt c
$cliftA2 :: forall a b c. (a -> b -> c) -> Alt a -> Alt b -> Alt c
<*> :: Alt (a -> b) -> Alt a -> Alt b
$c<*> :: forall a b. Alt (a -> b) -> Alt a -> Alt b
pure :: a -> Alt a
$cpure :: forall a. a -> Alt a
$cp1Applicative :: Functor Alt
Applicative, Applicative Alt
a -> Alt a
Applicative Alt
-> (forall a b. Alt a -> (a -> Alt b) -> Alt b)
-> (forall a b. Alt a -> Alt b -> Alt b)
-> (forall a. a -> Alt a)
-> Monad Alt
Alt a -> (a -> Alt b) -> Alt b
Alt a -> Alt b -> Alt b
forall a. a -> Alt a
forall a b. Alt a -> Alt b -> Alt b
forall a b. Alt a -> (a -> Alt b) -> Alt b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: a -> Alt a
$creturn :: forall a. a -> Alt a
>> :: Alt a -> Alt b -> Alt b
$c>> :: forall a b. Alt a -> Alt b -> Alt b
>>= :: Alt a -> (a -> Alt b) -> Alt b
$c>>= :: forall a b. Alt a -> (a -> Alt b) -> Alt b
$cp1Monad :: Applicative Alt
Monad, Applicative Alt
Alt a
Applicative Alt
-> (forall a. Alt a)
-> (forall a. Alt a -> Alt a -> Alt a)
-> (forall a. Alt a -> Alt [a])
-> (forall a. Alt a -> Alt [a])
-> Alternative Alt
Alt a -> Alt a -> Alt a
Alt a -> Alt [a]
Alt a -> Alt [a]
forall a. Alt a
forall a. Alt a -> Alt [a]
forall a. Alt a -> Alt a -> Alt a
forall (f :: * -> *).
Applicative f
-> (forall a. f a)
-> (forall a. f a -> f a -> f a)
-> (forall a. f a -> f [a])
-> (forall a. f a -> f [a])
-> Alternative f
many :: Alt a -> Alt [a]
$cmany :: forall a. Alt a -> Alt [a]
some :: Alt a -> Alt [a]
$csome :: forall a. Alt a -> Alt [a]
<|> :: Alt a -> Alt a -> Alt a
$c<|> :: forall a. Alt a -> Alt a -> Alt a
empty :: Alt a
$cempty :: forall a. Alt a
$cp1Alternative :: Applicative Alt
Alternative,
      a -> Alt a -> Bool
Alt m -> m
Alt a -> [a]
Alt a -> Bool
Alt a -> Int
Alt a -> a
Alt a -> a
Alt a -> a
Alt a -> a
(a -> m) -> Alt a -> m
(a -> m) -> Alt a -> m
(a -> b -> b) -> b -> Alt a -> b
(a -> b -> b) -> b -> Alt a -> b
(b -> a -> b) -> b -> Alt a -> b
(b -> a -> b) -> b -> Alt a -> b
(a -> a -> a) -> Alt a -> a
(a -> a -> a) -> Alt a -> a
(forall m. Monoid m => Alt m -> m)
-> (forall m a. Monoid m => (a -> m) -> Alt a -> m)
-> (forall m a. Monoid m => (a -> m) -> Alt a -> m)
-> (forall a b. (a -> b -> b) -> b -> Alt a -> b)
-> (forall a b. (a -> b -> b) -> b -> Alt a -> b)
-> (forall b a. (b -> a -> b) -> b -> Alt a -> b)
-> (forall b a. (b -> a -> b) -> b -> Alt a -> b)
-> (forall a. (a -> a -> a) -> Alt a -> a)
-> (forall a. (a -> a -> a) -> Alt a -> a)
-> (forall a. Alt a -> [a])
-> (forall a. Alt a -> Bool)
-> (forall a. Alt a -> Int)
-> (forall a. Eq a => a -> Alt a -> Bool)
-> (forall a. Ord a => Alt a -> a)
-> (forall a. Ord a => Alt a -> a)
-> (forall a. Num a => Alt a -> a)
-> (forall a. Num a => Alt a -> a)
-> Foldable Alt
forall a. Eq a => a -> Alt a -> Bool
forall a. Num a => Alt a -> a
forall a. Ord a => Alt a -> a
forall m. Monoid m => Alt m -> m
forall a. Alt a -> Bool
forall a. Alt a -> Int
forall a. Alt a -> [a]
forall a. (a -> a -> a) -> Alt a -> a
forall m a. Monoid m => (a -> m) -> Alt a -> m
forall b a. (b -> a -> b) -> b -> Alt a -> b
forall a b. (a -> b -> b) -> b -> Alt a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: Alt a -> a
$cproduct :: forall a. Num a => Alt a -> a
sum :: Alt a -> a
$csum :: forall a. Num a => Alt a -> a
minimum :: Alt a -> a
$cminimum :: forall a. Ord a => Alt a -> a
maximum :: Alt a -> a
$cmaximum :: forall a. Ord a => Alt a -> a
elem :: a -> Alt a -> Bool
$celem :: forall a. Eq a => a -> Alt a -> Bool
length :: Alt a -> Int
$clength :: forall a. Alt a -> Int
null :: Alt a -> Bool
$cnull :: forall a. Alt a -> Bool
toList :: Alt a -> [a]
$ctoList :: forall a. Alt a -> [a]
foldl1 :: (a -> a -> a) -> Alt a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Alt a -> a
foldr1 :: (a -> a -> a) -> Alt a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Alt a -> a
foldl' :: (b -> a -> b) -> b -> Alt a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Alt a -> b
foldl :: (b -> a -> b) -> b -> Alt a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Alt a -> b
foldr' :: (a -> b -> b) -> b -> Alt a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Alt a -> b
foldr :: (a -> b -> b) -> b -> Alt a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Alt a -> b
foldMap' :: (a -> m) -> Alt a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Alt a -> m
foldMap :: (a -> m) -> Alt a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Alt a -> m
fold :: Alt m -> m
$cfold :: forall m. Monoid m => Alt m -> m
Foldable, Functor Alt
Foldable Alt
Functor Alt
-> Foldable Alt
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> Alt a -> f (Alt b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Alt (f a) -> f (Alt a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Alt a -> m (Alt b))
-> (forall (m :: * -> *) a. Monad m => Alt (m a) -> m (Alt a))
-> Traversable Alt
(a -> f b) -> Alt a -> f (Alt b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Alt (m a) -> m (Alt a)
forall (f :: * -> *) a. Applicative f => Alt (f a) -> f (Alt a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Alt a -> m (Alt b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Alt a -> f (Alt b)
sequence :: Alt (m a) -> m (Alt a)
$csequence :: forall (m :: * -> *) a. Monad m => Alt (m a) -> m (Alt a)
mapM :: (a -> m b) -> Alt a -> m (Alt b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Alt a -> m (Alt b)
sequenceA :: Alt (f a) -> f (Alt a)
$csequenceA :: forall (f :: * -> *) a. Applicative f => Alt (f a) -> f (Alt a)
traverse :: (a -> f b) -> Alt a -> f (Alt b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Alt a -> f (Alt b)
$cp2Traversable :: Foldable Alt
$cp1Traversable :: Functor Alt
Traversable
    )

-- | Number of symbols acceptable by 'Repeatable'

data Count = One | Some
  deriving (Count -> Count -> Bool
(Count -> Count -> Bool) -> (Count -> Count -> Bool) -> Eq Count
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Count -> Count -> Bool
$c/= :: Count -> Count -> Bool
== :: Count -> Count -> Bool
$c== :: Count -> Count -> Bool
Eq, Eq Count
Eq Count
-> (Count -> Count -> Ordering)
-> (Count -> Count -> Bool)
-> (Count -> Count -> Bool)
-> (Count -> Count -> Bool)
-> (Count -> Count -> Bool)
-> (Count -> Count -> Count)
-> (Count -> Count -> Count)
-> Ord Count
Count -> Count -> Bool
Count -> Count -> Ordering
Count -> Count -> Count
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Count -> Count -> Count
$cmin :: Count -> Count -> Count
max :: Count -> Count -> Count
$cmax :: Count -> Count -> Count
>= :: Count -> Count -> Bool
$c>= :: Count -> Count -> Bool
> :: Count -> Count -> Bool
$c> :: Count -> Count -> Bool
<= :: Count -> Count -> Bool
$c<= :: Count -> Count -> Bool
< :: Count -> Count -> Bool
$c< :: Count -> Count -> Bool
compare :: Count -> Count -> Ordering
$ccompare :: Count -> Count -> Ordering
$cp1Ord :: Eq Count
Ord, Int -> Count -> ShowS
[Count] -> ShowS
Count -> String
(Int -> Count -> ShowS)
-> (Count -> String) -> ([Count] -> ShowS) -> Show Count
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Count] -> ShowS
$cshowList :: [Count] -> ShowS
show :: Count -> String
$cshow :: Count -> String
showsPrec :: Int -> Count -> ShowS
$cshowsPrec :: Int -> Count -> ShowS
Show)

-- | 'BlackWhiteSet' that can be repeated.

data Repeatable c = Repeatable {
    Repeatable c -> Count
getCnt :: Count,
    Repeatable c -> BlackWhiteSet c
getBWS :: BlackWhiteSet c
  } deriving (Repeatable c -> Repeatable c -> Bool
(Repeatable c -> Repeatable c -> Bool)
-> (Repeatable c -> Repeatable c -> Bool) -> Eq (Repeatable c)
forall c. Eq c => Repeatable c -> Repeatable c -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Repeatable c -> Repeatable c -> Bool
$c/= :: forall c. Eq c => Repeatable c -> Repeatable c -> Bool
== :: Repeatable c -> Repeatable c -> Bool
$c== :: forall c. Eq c => Repeatable c -> Repeatable c -> Bool
Eq, Eq (Repeatable c)
Eq (Repeatable c)
-> (Repeatable c -> Repeatable c -> Ordering)
-> (Repeatable c -> Repeatable c -> Bool)
-> (Repeatable c -> Repeatable c -> Bool)
-> (Repeatable c -> Repeatable c -> Bool)
-> (Repeatable c -> Repeatable c -> Bool)
-> (Repeatable c -> Repeatable c -> Repeatable c)
-> (Repeatable c -> Repeatable c -> Repeatable c)
-> Ord (Repeatable c)
Repeatable c -> Repeatable c -> Bool
Repeatable c -> Repeatable c -> Ordering
Repeatable c -> Repeatable c -> Repeatable c
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall c. Ord c => Eq (Repeatable c)
forall c. Ord c => Repeatable c -> Repeatable c -> Bool
forall c. Ord c => Repeatable c -> Repeatable c -> Ordering
forall c. Ord c => Repeatable c -> Repeatable c -> Repeatable c
min :: Repeatable c -> Repeatable c -> Repeatable c
$cmin :: forall c. Ord c => Repeatable c -> Repeatable c -> Repeatable c
max :: Repeatable c -> Repeatable c -> Repeatable c
$cmax :: forall c. Ord c => Repeatable c -> Repeatable c -> Repeatable c
>= :: Repeatable c -> Repeatable c -> Bool
$c>= :: forall c. Ord c => Repeatable c -> Repeatable c -> Bool
> :: Repeatable c -> Repeatable c -> Bool
$c> :: forall c. Ord c => Repeatable c -> Repeatable c -> Bool
<= :: Repeatable c -> Repeatable c -> Bool
$c<= :: forall c. Ord c => Repeatable c -> Repeatable c -> Bool
< :: Repeatable c -> Repeatable c -> Bool
$c< :: forall c. Ord c => Repeatable c -> Repeatable c -> Bool
compare :: Repeatable c -> Repeatable c -> Ordering
$ccompare :: forall c. Ord c => Repeatable c -> Repeatable c -> Ordering
$cp1Ord :: forall c. Ord c => Eq (Repeatable c)
Ord, Int -> Repeatable c -> ShowS
[Repeatable c] -> ShowS
Repeatable c -> String
(Int -> Repeatable c -> ShowS)
-> (Repeatable c -> String)
-> ([Repeatable c] -> ShowS)
-> Show (Repeatable c)
forall c. Show c => Int -> Repeatable c -> ShowS
forall c. Show c => [Repeatable c] -> ShowS
forall c. Show c => Repeatable c -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Repeatable c] -> ShowS
$cshowList :: forall c. Show c => [Repeatable c] -> ShowS
show :: Repeatable c -> String
$cshow :: forall c. Show c => Repeatable c -> String
showsPrec :: Int -> Repeatable c -> ShowS
$cshowsPrec :: forall c. Show c => Int -> Repeatable c -> ShowS
Show)

-- | Token with name of type @k@ (used for uniqueness error messages and

-- tokenizing output) over char type @c@.

data Token k c = Token
  { -- | the name of token

    Token k c -> k
name:: k,
    -- | restrictions on symbols before/after matchable part

    --

    -- NB! they are assumed to be satisfied if there are no symbols before/after

    -- matched part respectively

    Token k c -> [BlackWhiteSet c]
behind, Token k c -> [BlackWhiteSet c]
ahead :: [BlackWhiteSet c],
    -- | matchable sequences of char sets with possible repetitions

    Token k c -> [Repeatable c]
body :: [Repeatable c]
  }
  deriving (Int -> Token k c -> ShowS
[Token k c] -> ShowS
Token k c -> String
(Int -> Token k c -> ShowS)
-> (Token k c -> String)
-> ([Token k c] -> ShowS)
-> Show (Token k c)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k c. (Show k, Show c) => Int -> Token k c -> ShowS
forall k c. (Show k, Show c) => [Token k c] -> ShowS
forall k c. (Show k, Show c) => Token k c -> String
showList :: [Token k c] -> ShowS
$cshowList :: forall k c. (Show k, Show c) => [Token k c] -> ShowS
show :: Token k c -> String
$cshow :: forall k c. (Show k, Show c) => Token k c -> String
showsPrec :: Int -> Token k c -> ShowS
$cshowsPrec :: forall k c. (Show k, Show c) => Int -> Token k c -> ShowS
Show)

-- | Token id type synonym.

type TokId = Int

-- | Type for internal needs. Contains autogenerated 'tokId' and restrictions

-- behind token are reversed

data RToken c = RToken
  { -- | unique token's id (generated automatically)

    RToken c -> Int
tokId :: TokId,
    -- | constraints on symbols behind/ahead of matchable part

    RToken c -> [Repeatable c]
rbehind, RToken c -> [Repeatable c]
ahead :: [Repeatable c],
    -- | matchable part of string

    RToken c -> [Repeatable c]
body :: [Repeatable c]
  }
  deriving (Int -> RToken c -> ShowS
[RToken c] -> ShowS
RToken c -> String
(Int -> RToken c -> ShowS)
-> (RToken c -> String) -> ([RToken c] -> ShowS) -> Show (RToken c)
forall c. Show c => Int -> RToken c -> ShowS
forall c. Show c => [RToken c] -> ShowS
forall c. Show c => RToken c -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RToken c] -> ShowS
$cshowList :: forall c. Show c => [RToken c] -> ShowS
show :: RToken c -> String
$cshow :: forall c. Show c => RToken c -> String
showsPrec :: Int -> RToken c -> ShowS
$cshowsPrec :: forall c. Show c => Int -> RToken c -> ShowS
Show)

-- | Compares by token's id

instance Eq (RToken c) where
  == :: RToken c -> RToken c -> Bool
(==) = Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
(==) (Int -> Int -> Bool)
-> (RToken c -> Int) -> RToken c -> RToken c -> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` RToken c -> Int
forall c. RToken c -> Int
tokId
-- | Compares by token's id

instance Ord (RToken c) where
  compare :: RToken c -> RToken c -> Ordering
compare = Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (Int -> Int -> Ordering)
-> (RToken c -> Int) -> RToken c -> RToken c -> Ordering
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` RToken c -> Int
forall c. RToken c -> Int
tokId

-- | Construct an 'RToken' from 'Token' and its id

makeRToken :: TokId -> Token k c -> RToken c
makeRToken :: Int -> Token k c -> RToken c
makeRToken Int
tokId Token{[Repeatable c]
body :: [Repeatable c]
$sel:body:Token :: forall k c. Token k c -> [Repeatable c]
body, [BlackWhiteSet c]
behind :: [BlackWhiteSet c]
$sel:behind:Token :: forall k c. Token k c -> [BlackWhiteSet c]
behind, [BlackWhiteSet c]
ahead :: [BlackWhiteSet c]
$sel:ahead:Token :: forall k c. Token k c -> [BlackWhiteSet c]
ahead} =
  RToken :: forall c.
Int
-> [Repeatable c] -> [Repeatable c] -> [Repeatable c] -> RToken c
RToken {
    Int
tokId :: Int
$sel:tokId:RToken :: Int
tokId,
    [Repeatable c]
body :: [Repeatable c]
$sel:body:RToken :: [Repeatable c]
body,
    $sel:rbehind:RToken :: [Repeatable c]
rbehind = Count -> BlackWhiteSet c -> Repeatable c
forall c. Count -> BlackWhiteSet c -> Repeatable c
Repeatable Count
One (BlackWhiteSet c -> Repeatable c)
-> [BlackWhiteSet c] -> [Repeatable c]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [BlackWhiteSet c] -> [BlackWhiteSet c]
forall a. [a] -> [a]
reverse [BlackWhiteSet c]
behind,
    $sel:ahead:RToken :: [Repeatable c]
ahead = Count -> BlackWhiteSet c -> Repeatable c
forall c. Count -> BlackWhiteSet c -> Repeatable c
Repeatable Count
One (BlackWhiteSet c -> Repeatable c)
-> [BlackWhiteSet c] -> [Repeatable c]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [BlackWhiteSet c]
ahead
  }