Skip to content

Commit

Permalink
Allow Natural and Integer literals in binary notation (#2540)
Browse files Browse the repository at this point in the history
  • Loading branch information
kukimik authored Nov 20, 2023
1 parent 2b3a6bc commit 5d4391c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion dhall/src/Dhall/Parser/Token.hs
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,14 @@ integerLiteral = (do
-}
naturalLiteral :: Parser Natural
naturalLiteral = (do
a <- try (char '0' >> char 'x' >> Text.Megaparsec.Char.Lexer.hexadecimal)
a <- binary
<|> hexadecimal
<|> decimal
<|> (char '0' $> 0)
return a ) <?> "literal"
where
binary = try (char '0' >> char 'b' >> Text.Megaparsec.Char.Lexer.binary)
hexadecimal = try (char '0' >> char 'x' >> Text.Megaparsec.Char.Lexer.hexadecimal)
decimal = do
n <- headDigit
ns <- many tailDigit
Expand Down
2 changes: 1 addition & 1 deletion dhall/tests/format/numericLiteralsA.dhall
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ example0 = 0x42, example1 = +0x42, example2 = 1.2e20 }
{ example0 = 0x42, example1 = +0x42, example2 = 1.2e20, example3 = -0b0111 }
2 changes: 1 addition & 1 deletion dhall/tests/format/numericLiteralsB.dhall
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ example0 = 0x42, example1 = +0x42, example2 = 1.2e20 }
{ example0 = 0x42, example1 = +0x42, example2 = 1.2e20, example3 = -0b0111 }

0 comments on commit 5d4391c

Please sign in to comment.