diff --git a/src/Nixfmt/Parser.hs b/src/Nixfmt/Parser.hs index a4c0c6f8..361efab6 100644 --- a/src/Nixfmt/Parser.hs +++ b/src/Nixfmt/Parser.hs @@ -14,7 +14,7 @@ import Data.Char (isAlpha) import Data.Foldable (toList) import Data.Functor (($>)) import Data.Maybe (fromMaybe, mapMaybe, maybeToList) -import Data.Text (Text) +import Data.Text (Text, pack) import qualified Data.Text as Text import Data.Void (Void) import Nixfmt.Lexer (lexeme, takeTrivia, whole) @@ -71,8 +71,7 @@ import Text.Megaparsec ( try, (<|>), ) -import Text.Megaparsec.Char (char) -import qualified Text.Megaparsec.Char.Lexer as L (decimal) +import Text.Megaparsec.Char (char, digitChar) import Prelude hiding (String) -- HELPER FUNCTIONS @@ -110,7 +109,7 @@ reserved t = -- VALUES integer :: Parser (Ann Token) -integer = ann Integer L.decimal +integer = ann Integer (pack <$> some digitChar) float :: Parser (Ann Token) float = ann Float floatParse diff --git a/src/Nixfmt/Types.hs b/src/Nixfmt/Types.hs index 43d9073e..244ef71d 100644 --- a/src/Nixfmt/Types.hs +++ b/src/Nixfmt/Types.hs @@ -48,10 +48,9 @@ import Control.Monad.State.Strict (StateT) import Data.Bifunctor (first) import Data.Foldable (toList) import Data.Function (on) -import Data.Int (Int64) import Data.List.NonEmpty as NonEmpty import Data.Maybe (maybeToList) -import Data.Text (Text, pack) +import Data.Text (Text) import Data.Void (Void) import Text.Megaparsec (Pos) import qualified Text.Megaparsec as MP (ParseErrorBundle, Parsec, pos1) @@ -488,7 +487,7 @@ instance (LanguageElement a) => LanguageElement (NonEmpty a) where mapAllTokens f = NonEmpty.map (mapAllTokens f) data Token - = Integer Int64 + = Integer Text | Float Text | Identifier Text | EnvPath Text @@ -588,7 +587,7 @@ operators = tokenText :: Token -> Text tokenText (Identifier i) = i -tokenText (Integer i) = pack (show i) +tokenText (Integer i) = i tokenText (Float f) = f tokenText (EnvPath p) = "<" <> p <> ">" tokenText KAssert = "assert" diff --git a/test/correct/numbers.nix b/test/correct/numbers.nix index 8df9eb55..dd6ad802 100644 --- a/test/correct/numbers.nix +++ b/test/correct/numbers.nix @@ -3,9 +3,13 @@ (-1) 0 1 - # 01 - # 0000000000000000000000000000000000000000000001 + # https://github.com/NixOS/nixfmt/issues/292 + 01 + 0000000000000000000000000000000000000000000001 9223372036854775807 + 55555555555555555555555555555 + (-9223372036854775808) + 9223372036854775808 .1 0.1