refactor: lexNumbers
This commit is contained in:
parent
5c2dc50872
commit
9123e0b882
1 changed files with 7 additions and 3 deletions
10
app/Lexer.hs
10
app/Lexer.hs
|
|
@ -26,7 +26,11 @@ lex' (x:xs) tokens orgLength = case x of
|
||||||
|
|
||||||
lexNumbers :: String -> [Token] -> Int -> [Token]
|
lexNumbers :: String -> [Token] -> Int -> [Token]
|
||||||
lexNumbers (x:xs) tokens orgLength
|
lexNumbers (x:xs) tokens orgLength
|
||||||
| isDigit x = lex' (dropWhile isDigit (x:xs)) ((Integer(read (takeWhile isDigit (x:xs))::Int)):tokens) orgLength
|
| isDigit x = lex' rest ((Integer(read digits::Int)):tokens) orgLength
|
||||||
| otherwise = error $ "Syntax error: " ++ [x] ++ " (" ++ show (orgLength - (length (x:xs))) ++ ")"
|
| otherwise = syntaxError x (orgLength - (length (x:xs)) + 1)
|
||||||
|
where
|
||||||
|
digits = takeWhile isDigit (x:xs)
|
||||||
|
rest = dropWhile isDigit (x:xs)
|
||||||
|
isDigit c = c `elem` "0123456789"
|
||||||
|
|
||||||
isDigit x = x `elem` "0123456789"
|
syntaxError char pos = error $ "Syntax error: " ++ [char] ++ " (" ++ show pos ++ ")"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue