import Control.Applicative
import Control.Monad
import Control.Monad.State
+import Data.Functor
from Data.Func import $
// Misschien moeten we hier continuation style van maken
toString l = "dit is een lexer output, danwel error\n"
lexer :: [Char] -> LexerOutput [Token]
-lexer _ = Left "Not Implemented"
+lexer i = let (out, rest) = runParser (many anyT) i in case rest of
+ [] = out
+ _ = Left "Unexpected input after last token"
//lexer functions
identT = alpha >>= \a -> many (char '_' <|> alphaNum) >>= \as -> return $ IdentToken [a:as]
numberT = optional (char '-') >>= \sign -> (some digit) >>= \n -> case sign of
Nothing -> return $ NumberToken $ 5 //fromString n
_ -> return $ NumberToken $ -5 //(fromString n) * -1
-charLT = liftM CharToken item
+charLT = CharToken <$> (char '\'' *> item <* char '\'')
char2T = item >>= \c1 -> case c1 of
':' = char ':' >>| return DoubleColonToken
'<' = char '=' >>| return LesserEqToken
'&' = char '&' >>| return AmpersandsToken
'|' = char '|' >>| return PipesToken
'-' = char '>' >>| return ArrowToken
+ _ = zero
char1T = item >>= \c1 -> findT c1 charTokenMap
varT = string (fromString "var") >>| return VarToken
voidT = string (fromString "Void") >>| return VoidToken
whileT = string (fromString "while") >>| return WhileToken
trueT = string (fromString "True") >>| return TrueToken
falseT = string (fromString "False") >>| return FalseToken
+//note, for the anyToken parser the order matters!
+anyT = char2T <|> char1T <|> varT <|> voidT <|> returnT <|> ifT <|> elseT <|> whileT <|>
+ trueT <|> falseT <|> numberT <|> identT <|> charLT
Start :: *World -> *World
Start w