module Language.Haskell.Lexer.Utils
( module Language.Haskell.Lexer.Utils
, Token(..)
) where
import Language.Haskell.Lexer.Tokens
gotEOF :: [a] -> [(Token,[a])]
gotEOF [] = []
gotEOF as = [(GotEOF, reverse as)]
gotError :: [a] -> [a] -> [(Token, [a])]
gotError as is =
(ErrorToken, reverse as):
if null is then [(GotEOF,[])] else [(TheRest,is)]
output :: t -> [a] -> [(t, [a])] -> [(t, [a])]
output token as cont = (token,reverse as):cont
nestedComment :: [Char] -> [Char] -> (([a] -> [a] -> [(Token, [a])])
-> [Char] -> [Char] -> [(Token, [Char])]) -> [(Token, [Char])]
nestedComment as' is' next = nest (0::Int) as' is'
where
nest n as is =
case is of
'-' : '}' : is1 -> if n == 0
then next gotError ('}':'-':as) is1
else nest (n-1) ('}':'-':as) is1
'{' : '-' : is1 -> nest (n+1) ('-':'{':as) is1
c : is1 -> nest n (c:as) is1
[] -> gotError as is