-
-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error when carriage return used as linebreak in comment #175
Comments
Whatever kind of dark magic Nix does here, I'd say that not implementing that and giving an error is an acceptable thing to do here |
Likely the carriage return stops the one-line comment: https://github.com/NixOS/nix/blob/master/src/libexpr/lexer.l#L284
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 |
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: