module Language.Haskell.Lexer
( PosToken
, Token(..)
, lexerPass0
, lexerPass0'
, lexerPass1
, rmSpace
, layoutPre
, module Language.Haskell.Lexer.Position
) where
import Language.Haskell.Lexer.Lex(haskellLex)
import Language.Haskell.Lexer.Utils
import Language.Haskell.Lexer.Layout(layoutPre,PosToken)
import Language.Haskell.Lexer.Position
import Data.List(mapAccumL)
default(Int)
lexerPass1 :: String -> [PosToken]
lexerPass1 :: String -> [PosToken]
lexerPass1 = [PosToken] -> [PosToken]
lexerPass1Only ([PosToken] -> [PosToken])
-> (String -> [PosToken]) -> String -> [PosToken]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> [PosToken]
lexerPass0
lexerPass1Only :: [PosToken] -> [PosToken]
lexerPass1Only :: [PosToken] -> [PosToken]
lexerPass1Only = [PosToken] -> [PosToken]
layoutPre ([PosToken] -> [PosToken])
-> ([PosToken] -> [PosToken]) -> [PosToken] -> [PosToken]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [PosToken] -> [PosToken]
rmSpace
rmSpace :: [PosToken] -> [PosToken]
rmSpace :: [PosToken] -> [PosToken]
rmSpace = (PosToken -> Bool) -> [PosToken] -> [PosToken]
forall a. (a -> Bool) -> [a] -> [a]
filter (Token -> Bool
notWhite(Token -> Bool) -> (PosToken -> Token) -> PosToken -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
.PosToken -> Token
forall a b. (a, b) -> a
fst)
notWhite :: Token -> Bool
notWhite :: Token -> Bool
notWhite Token
t = Token
tToken -> Token -> Bool
forall a. Eq a => a -> a -> Bool
/=Token
Whitespace Bool -> Bool -> Bool
&&
Token
tToken -> Token -> Bool
forall a. Eq a => a -> a -> Bool
/=Token
Commentstart Bool -> Bool -> Bool
&& Token
tToken -> Token -> Bool
forall a. Eq a => a -> a -> Bool
/=Token
Comment Bool -> Bool -> Bool
&&
Token
tToken -> Token -> Bool
forall a. Eq a => a -> a -> Bool
/=Token
NestedComment
lexerPass0 :: String -> [PosToken]
lexerPass0 :: String -> [PosToken]
lexerPass0 = Pos -> String -> [PosToken]
lexerPass0' Pos
startPos
lexerPass0' :: Pos -> String -> [PosToken]
lexerPass0' :: Pos -> String -> [PosToken]
lexerPass0' Pos
pos0 = [(Token, String)] -> [PosToken]
forall {a}. [(a, String)] -> [(a, (Pos, String))]
addPos ([(Token, String)] -> [PosToken])
-> (String -> [(Token, String)]) -> String -> [PosToken]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> [(Token, String)]
haskellLex (String -> [(Token, String)])
-> (String -> String) -> String -> [(Token, String)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
rmcr
where
addPos :: [(a, String)] -> [(a, (Pos, String))]
addPos = (Pos, [(a, (Pos, String))]) -> [(a, (Pos, String))]
forall a b. (a, b) -> b
snd ((Pos, [(a, (Pos, String))]) -> [(a, (Pos, String))])
-> ([(a, String)] -> (Pos, [(a, (Pos, String))]))
-> [(a, String)]
-> [(a, (Pos, String))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Pos -> (a, String) -> (Pos, (a, (Pos, String))))
-> Pos -> [(a, String)] -> (Pos, [(a, (Pos, String))])
forall (t :: * -> *) s a b.
Traversable t =>
(s -> a -> (s, b)) -> s -> t a -> (s, t b)
mapAccumL Pos -> (a, String) -> (Pos, (a, (Pos, String)))
forall {a}. Pos -> (a, String) -> (Pos, (a, (Pos, String)))
pos Pos
pos0
pos :: Pos -> (a, String) -> (Pos, (a, (Pos, String)))
pos Pos
p (a
t,String
s) = (Pos
p',(a
t,(Pos
p,String
s)))
where p' :: Pos
p' = Pos -> String -> Pos
nextPos Pos
p String
s
rmcr :: String -> String
rmcr :: String -> String
rmcr (Char
'\CR':Char
'\LF':String
s) = Char
'\LF'Char -> String -> String
forall a. a -> [a] -> [a]
:String -> String
rmcr String
s
rmcr (Char
c:String
s) = Char
cChar -> String -> String
forall a. a -> [a] -> [a]
:String -> String
rmcr String
s
rmcr String
"" = String
""