{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, FunctionalDependencies #-}
module Text.Flow.Token where

import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B

class (Show t, Eq t) => Token t where
    isNewline :: t -> Bool

class (Token t, Show s, Eq s) => TokenStream t s where
    isEmpty :: s -> Bool
    uncons :: s -> (t, s)

instance Token Char where
    isNewline = (=='\n')

instance (Token t) => TokenStream t [t] where
    isEmpty = null
    uncons (x:xs) = (x, xs)

instance TokenStream Char T.Text where
    isEmpty = T.null
    uncons t = (T.head t, T.tail t)

instance TokenStream Char B.ByteString where
    isEmpty = B.null
    uncons b = (B.head b, B.tail b)
