From 5d4391ce498ecab73b9b98243fd698c38576266f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kukie=C5=82a?= <53443372+kukimik@users.noreply.github.com> Date: Mon, 20 Nov 2023 04:38:25 +0100 Subject: [PATCH] Allow Natural and Integer literals in binary notation (#2540) --- dhall/src/Dhall/Parser/Token.hs | 5 ++++- dhall/tests/format/numericLiteralsA.dhall | 2 +- dhall/tests/format/numericLiteralsB.dhall | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/dhall/src/Dhall/Parser/Token.hs b/dhall/src/Dhall/Parser/Token.hs index db7e1a629..e17dff164 100644 --- a/dhall/src/Dhall/Parser/Token.hs +++ b/dhall/src/Dhall/Parser/Token.hs @@ -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 diff --git a/dhall/tests/format/numericLiteralsA.dhall b/dhall/tests/format/numericLiteralsA.dhall index 578ad271e..7a585a3d7 100644 --- a/dhall/tests/format/numericLiteralsA.dhall +++ b/dhall/tests/format/numericLiteralsA.dhall @@ -1 +1 @@ -{ example0 = 0x42, example1 = +0x42, example2 = 1.2e20 } +{ example0 = 0x42, example1 = +0x42, example2 = 1.2e20, example3 = -0b0111 } diff --git a/dhall/tests/format/numericLiteralsB.dhall b/dhall/tests/format/numericLiteralsB.dhall index 578ad271e..7a585a3d7 100644 --- a/dhall/tests/format/numericLiteralsB.dhall +++ b/dhall/tests/format/numericLiteralsB.dhall @@ -1 +1 @@ -{ example0 = 0x42, example1 = +0x42, example2 = 1.2e20 } +{ example0 = 0x42, example1 = +0x42, example2 = 1.2e20, example3 = -0b0111 }