diff --git a/app/Lexer.hs b/app/Lexer.hs index f18b11d..e5d9794 100644 --- a/app/Lexer.hs +++ b/app/Lexer.hs @@ -26,7 +26,11 @@ lex' (x:xs) tokens orgLength = case x of lexNumbers :: String -> [Token] -> Int -> [Token] lexNumbers (x:xs) tokens orgLength - | isDigit x = lex' (dropWhile isDigit (x:xs)) ((Integer(read (takeWhile isDigit (x:xs))::Int)):tokens) orgLength - | otherwise = error $ "Syntax error: " ++ [x] ++ " (" ++ show (orgLength - (length (x:xs))) ++ ")" + | isDigit x = lex' rest ((Integer(read digits::Int)):tokens) orgLength + | 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 ++ ")"