Skip to content

Commit 5d4391c

Browse files
authored
Allow Natural and Integer literals in binary notation (#2540)
1 parent 2b3a6bc commit 5d4391c

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

dhall/src/Dhall/Parser/Token.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,14 @@ integerLiteral = (do
299299
-}
300300
naturalLiteral :: Parser Natural
301301
naturalLiteral = (do
302-
a <- try (char '0' >> char 'x' >> Text.Megaparsec.Char.Lexer.hexadecimal)
302+
a <- binary
303+
<|> hexadecimal
303304
<|> decimal
304305
<|> (char '0' $> 0)
305306
return a ) <?> "literal"
306307
where
308+
binary = try (char '0' >> char 'b' >> Text.Megaparsec.Char.Lexer.binary)
309+
hexadecimal = try (char '0' >> char 'x' >> Text.Megaparsec.Char.Lexer.hexadecimal)
307310
decimal = do
308311
n <- headDigit
309312
ns <- many tailDigit
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ example0 = 0x42, example1 = +0x42, example2 = 1.2e20 }
1+
{ example0 = 0x42, example1 = +0x42, example2 = 1.2e20, example3 = -0b0111 }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ example0 = 0x42, example1 = +0x42, example2 = 1.2e20 }
1+
{ example0 = 0x42, example1 = +0x42, example2 = 1.2e20, example3 = -0b0111 }

0 commit comments

Comments
 (0)