:: TokenValue
//Value tokens
= IdentToken [Char] // Identifier
- | NumberToken [Char]// Integer
+ | NumberToken Int // Integer
| CharToken Char // Character literal
//Keyword tokens
| VarToken // var keyword
Just t = ret (CharToken t) xs
_ = err ("Unknown escape: \\" +++ toString x)
lex ['-':t=:[x:xs]]
-| isDigit x = let (n, r) = span isDigit t in ret (NumberToken ['-':n]) r
+| isDigit x = let (n, r) = span isDigit t in
+ ret (NumberToken (toInt $ toString ['-':n])) r
| otherwise = ret DashToken xs
lex t=:[x:xs] = case get x SingleCharTokens of
(Just tok) = ret tok xs
Nothing
| x == '\n' = \i.lex xs (i+1)
| isSpace x = lex xs
- | isDigit x = let (v, r) = span isDigit t in ret (NumberToken v) r
+ | isDigit x = let (v, r) = span isDigit t in
+ ret (NumberToken (toInt $ toString v)) r
| isAlpha x = let (v, r) = span isIdent t in ret (IdentToken v) r
with isIdent c = isAlphanum c || c == '_'
| otherwise = err ("Unexpected character: " +++ toString x)