on master help sign in
Add support for hexadecimal integer literals
91953b6Mauris Van Hauwe
src/Parse/Literal.hs+11−1
@@ -12,15 +12,25 @@ num :: IParser L.Literal
12num = toLit <$> (number <?> "number")
12num = toLit <$> (number <?> "number")
13 where
13 where
14 toLit n
14 toLit n
15+ | 'x' `elem` n = L.IntNum (read n)
15 | any (`elem` ".eE") n = L.FloatNum (read n)
16 | any (`elem` ".eE") n = L.FloatNum (read n)
16 | otherwise = L.IntNum (read n)
17 | otherwise = L.IntNum (read n)
17
18
18 number = concat <$> sequence
19 number = concat <$> sequence
19 [ option "" minus
20 [ option "" minus
21+ , hexNum <|> decNum ]
22+
23+ decNum = concat <$> sequence
20− , many1 digit
24+ [ many1 digit
21 , option "" decimals
25 , option "" decimals
22 , option "" exponent ]
26 , option "" exponent ]
23
27
28+ hexNum = do
29+ try $ lookAhead (string "0x" >> hexDigit)
30+ string "0x"
31+ n <- many1 hexDigit
32+ return $ "0x" ++ n
33+
24 minus = try $ do
34 minus = try $ do
25 string "-"
35 string "-"
26 lookAhead digit
36 lookAhead digit