on master help sign in
Add support for hexadecimal integer literals
commit91953b62b865bbb1ccdfad0e6f5597e66e620ccb authorMauris Van Hauwe <mauris.van.hauwe@gmail.com> dateWed 26 Nov 2014, 00:09 (12 years ago) parent58090de
1 file changed+11−1
src/Parse/Literal.hs+11−1
src/Parse/Literal.hs+11−1
@@ -12,15 +12,25 @@ num :: IParser L.Literal
1212num = toLit <$> (number <?> "number")
1313 where
1414 toLit n
15+ | 'x' `elem` n = L.IntNum (read n)
1516 | any (`elem` ".eE") n = L.FloatNum (read n)
1617 | otherwise = L.IntNum (read n)
1718
1819 number = concat <$> sequence
1920 [ option "" minus
20− , many1 digit
21+ , hexNum <|> decNum ]
22+
23+ decNum = concat <$> sequence
24+ [ many1 digit
2125 , option "" decimals
2226 , option "" exponent ]
2327
28+ hexNum = do
29+ try $ lookAhead (string "0x" >> hexDigit)
30+ string "0x"
31+ n <- many1 hexDigit
32+ return $ "0x" ++ n
33+
2434 minus = try $ do
2535 string "-"
2636 lookAhead digit