never executed always true always false
    1 module HelVM.HelMA.Automata.WhiteSpace.Token where
    2 
    3 import           HelVM.HelIO.Collections.SList
    4 import           HelVM.HelIO.Control.Safe
    5 import           HelVM.HelIO.Digit.ToDigit
    6 
    7 import           Text.Read
    8 
    9 import qualified Text.Show
   10 
   11 data Token =  S | T | N
   12   deriving stock (Bounded , Enum , Eq , Read , Show)
   13 
   14 type TokenList = [Token]
   15 type TokenSList = SList Token
   16 
   17 instance ToDigit Token where
   18   toDigit S = pure 0
   19   toDigit T = pure 1
   20   toDigit t = liftErrorWithPrefix "Wrong token" $ show t
   21 
   22 ----
   23 
   24 newtype WhiteToken = WhiteToken { unWhiteToken :: Token}
   25   deriving stock (Eq)
   26 
   27 instance Show WhiteToken where
   28   show (WhiteToken S) = " "
   29   show (WhiteToken T) = "\t"
   30   show (WhiteToken N) = "\n"
   31 
   32 -- | Scanner
   33 instance Read WhiteToken where
   34   readsPrec _ " "  = [( WhiteToken S , "")]
   35   readsPrec _ "\t" = [( WhiteToken T , "")]
   36   readsPrec _ "\n" = [( WhiteToken N , "")]
   37   readsPrec _ _    = []
   38 
   39 type WhiteTokenList = [WhiteToken]
   40 
   41 whiteTokenListToTokenList :: WhiteTokenList -> TokenList
   42 whiteTokenListToTokenList = fmap unWhiteToken
   43