lexProgram :: Parser Char [Token]
lexProgram = some lexToken <* many (satisfy isSpace) <* eof
- >>= \ts->pure (map (\t->(0, 0, t)) ts)
+ >>= \ts->pure $ (map (\t->(0, 0, t)) ts) ++ [(0, 0, EndOfFileToken)]
lexToken :: Parser Char TokenValue
lexToken =
//Number tokens
(liftM (NumberToken o toInt o toString) $ some $ satisfy isDigit) <|>
//Ident tokens
- (liftM IdentToken $ some $ satisfy isIdentChar) <|>
+ (liftM (IdentToken o toString) $ some $ satisfy isIdentChar) <|>
(satisfy isSpace >>| lexToken)
where
- lexUntilNL = top until ((item '\n' >>| return Void) <|> eof)
+ lexUntilNL = top until (eof <|> (item '\n' >>| pure Void))
lexUntilCommentClose = top until list (fromString "*/")
isIdentChar c = isAlphanum c || c == '_'
lexOp s tv = list (fromString s) >>| pure tv