You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
eol from Megaparsec only understands \n. Something like this might work, but change things elsewhere? position values might get messed up? Have to make sure the "\r\n" sequence is replaced first.
diff --git a/src/Nixfmt/Lexer.hs b/src/Nixfmt/Lexer.hs
index b331359..996e847 100644
--- a/src/Nixfmt/Lexer.hs+++ b/src/Nixfmt/Lexer.hs@@ -17,7 +17,7 @@ import Data.Text as Text
import Text.Megaparsec
(SourcePos(..), anySingle, chunk, getSourcePos, hidden, many, manyTill, some,
try, unPos, (<|>))
-import Text.Megaparsec.Char (eol)+import Text.Megaparsec.Char (string, eol)
import Nixfmt.Types (Ann(..), Parser, TrailingComment(..), Trivia, Trivium(..))
import Nixfmt.Util (manyP)
@@ -32,7 +32,7 @@ preLexeme :: Parser a -> Parser a
preLexeme p = p <* manyP (\x -> isSpace x && x /= '\n' && x /= '\r')
newlines :: Parser ParseTrivium
-newlines = PTNewlines <$> Prelude.length <$> some (preLexeme eol)+newlines = PTNewlines <$> Prelude.length <$> some (preLexeme (eol <|> string "\r"))
splitLines :: Text -> [Text]
splitLines = dropWhile Text.null . dropWhileEnd Text.null
Single \r carriage returns which are not followed by a line feed are effectively unsupported by Nix (= buggy arbitrary behavior) and thus won't be supported by Nixfmt. Any bugs in Nixfmt on files with CLRF line endings however should be handled.
Description
nixfmt
errors when a carriage return is used as a linebreak in a comment.Small example input
(Where
^M
is a literal carriage return character.)We can see that
nix-instantiate
parses the file OK:Actual output
The text was updated successfully, but these errors were encountered: