module Language.Lexer.Tlex.Data.InputString ( InputStringContext (..), InputString (..), runInputString, ) where import Language.Lexer.Tlex.Prelude import qualified Language.Lexer.Tlex.Runner as Tlex data InputStringContext e = InputStringContext { forall e. InputStringContext e -> [e] inputStringCtxRest :: [e] , forall e. InputStringContext e -> Int inputStringCtxPos :: Int } deriving (InputStringContext e -> InputStringContext e -> Bool forall e. Eq e => InputStringContext e -> InputStringContext e -> Bool forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a /= :: InputStringContext e -> InputStringContext e -> Bool $c/= :: forall e. Eq e => InputStringContext e -> InputStringContext e -> Bool == :: InputStringContext e -> InputStringContext e -> Bool $c== :: forall e. Eq e => InputStringContext e -> InputStringContext e -> Bool Eq, Int -> InputStringContext e -> ShowS forall e. Show e => Int -> InputStringContext e -> ShowS forall e. Show e => [InputStringContext e] -> ShowS forall e. Show e => InputStringContext e -> String forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [InputStringContext e] -> ShowS $cshowList :: forall e. Show e => [InputStringContext e] -> ShowS show :: InputStringContext e -> String $cshow :: forall e. Show e => InputStringContext e -> String showsPrec :: Int -> InputStringContext e -> ShowS $cshowsPrec :: forall e. Show e => Int -> InputStringContext e -> ShowS Show) initialInputStringContext :: [e] -> InputStringContext e initialInputStringContext :: forall e. [e] -> InputStringContext e initialInputStringContext [e] s = InputStringContext { $sel:inputStringCtxRest:InputStringContext :: [e] inputStringCtxRest = [e] s , $sel:inputStringCtxPos:InputStringContext :: Int inputStringCtxPos = Int 0 } newtype InputString e a = InputString { forall e a. InputString e a -> State (InputStringContext e) a unInputString :: State (InputStringContext e) a } deriving ( forall a b. a -> InputString e b -> InputString e a forall a b. (a -> b) -> InputString e a -> InputString e b forall e a b. a -> InputString e b -> InputString e a forall e a b. (a -> b) -> InputString e a -> InputString e b forall (f :: * -> *). (forall a b. (a -> b) -> f a -> f b) -> (forall a b. a -> f b -> f a) -> Functor f <$ :: forall a b. a -> InputString e b -> InputString e a $c<$ :: forall e a b. a -> InputString e b -> InputString e a fmap :: forall a b. (a -> b) -> InputString e a -> InputString e b $cfmap :: forall e a b. (a -> b) -> InputString e a -> InputString e b Functor, forall e. Functor (InputString e) forall a. a -> InputString e a forall e a. a -> InputString e a forall a b. InputString e a -> InputString e b -> InputString e a forall a b. InputString e a -> InputString e b -> InputString e b forall a b. InputString e (a -> b) -> InputString e a -> InputString e b forall e a b. InputString e a -> InputString e b -> InputString e a forall e a b. InputString e a -> InputString e b -> InputString e b forall e a b. InputString e (a -> b) -> InputString e a -> InputString e b forall a b c. (a -> b -> c) -> InputString e a -> InputString e b -> InputString e c forall e a b c. (a -> b -> c) -> InputString e a -> InputString e b -> InputString e 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 <* :: forall a b. InputString e a -> InputString e b -> InputString e a $c<* :: forall e a b. InputString e a -> InputString e b -> InputString e a *> :: forall a b. InputString e a -> InputString e b -> InputString e b $c*> :: forall e a b. InputString e a -> InputString e b -> InputString e b liftA2 :: forall a b c. (a -> b -> c) -> InputString e a -> InputString e b -> InputString e c $cliftA2 :: forall e a b c. (a -> b -> c) -> InputString e a -> InputString e b -> InputString e c <*> :: forall a b. InputString e (a -> b) -> InputString e a -> InputString e b $c<*> :: forall e a b. InputString e (a -> b) -> InputString e a -> InputString e b pure :: forall a. a -> InputString e a $cpure :: forall e a. a -> InputString e a Applicative, forall e. Applicative (InputString e) forall a. a -> InputString e a forall e a. a -> InputString e a forall a b. InputString e a -> InputString e b -> InputString e b forall a b. InputString e a -> (a -> InputString e b) -> InputString e b forall e a b. InputString e a -> InputString e b -> InputString e b forall e a b. InputString e a -> (a -> InputString e b) -> InputString e 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 :: forall a. a -> InputString e a $creturn :: forall e a. a -> InputString e a >> :: forall a b. InputString e a -> InputString e b -> InputString e b $c>> :: forall e a b. InputString e a -> InputString e b -> InputString e b >>= :: forall a b. InputString e a -> (a -> InputString e b) -> InputString e b $c>>= :: forall e a b. InputString e a -> (a -> InputString e b) -> InputString e b Monad ) via State (InputStringContext e) runInputString :: InputString e a -> [e] -> (a, InputStringContext e) runInputString :: forall e a. InputString e a -> [e] -> (a, InputStringContext e) runInputString (InputString State (InputStringContext e) a runner) [e] input = forall s a. State s a -> s -> (a, s) runState State (InputStringContext e) a runner do forall e. [e] -> InputStringContext e initialInputStringContext [e] input instance Enum e => Tlex.TlexContext (InputStringContext e) e (InputString e) where tlexGetInputPart :: InputString e (Maybe e) tlexGetInputPart = forall e a. State (InputStringContext e) a -> InputString e a InputString do InputStringContext e inputCtx <- forall (m :: * -> *) s. Monad m => StateT s m s get case forall e. InputStringContext e -> [e] inputStringCtxRest InputStringContext e inputCtx of [] -> forall (f :: * -> *) a. Applicative f => a -> f a pure forall a. Maybe a Nothing e c:[e] r -> do forall (m :: * -> *) s. Monad m => s -> StateT s m () put do InputStringContext { $sel:inputStringCtxRest:InputStringContext :: [e] inputStringCtxRest = [e] r , $sel:inputStringCtxPos:InputStringContext :: Int inputStringCtxPos = forall a. Enum a => a -> a succ do forall e. InputStringContext e -> Int inputStringCtxPos InputStringContext e inputCtx } forall (f :: * -> *) a. Applicative f => a -> f a pure do forall a. a -> Maybe a Just e c tlexGetMark :: InputString e (InputStringContext e) tlexGetMark = forall e a. State (InputStringContext e) a -> InputString e a InputString forall (m :: * -> *) s. Monad m => StateT s m s get