{-# Language TypeFamilies #-}
module Data.Source.String.Offset where
import Data.Source.Class

data Src 
 = Src 
 { loc :: Int
 , str :: [Char]
 } deriving (Eq,Ord,Read,Show)

instance Source Src where
 type Location  Src = Int
 type Element   Src = Char
 type Token     Src = [Char]
 type Error     Src = () -- errors are impossible here, so this is dummy
 uncons (Src i (x:xs))          = Right $ Just (x,Src (i+1) xs)
 uncons _                       = Right $ Nothing
 view src _ emh nxh           = case src of
        Src i (x:xs)    -> nxh x $ Src (i+1) xs
        _               -> emh 
 location                       = loc
 token (Src il h) (Src ir _)    = take (ir - il) h
 offset                         = loc

mkSrc :: String -> Src
mkSrc = Src 0

