Skip to content
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

Fix 197 #208

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Nixfmt/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ indentedStringPart =
( chunk "''\\n"
<|> chunk "''\\r"
<|> chunk "''\\t"
<|> chunk "''\\'"
<|> chunk "''\\"
-- ''\ followed by any char throws away the ''\ part, leaving just the char
*> (Text.singleton <$> anySingle)
<|> chunk "''$"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh, I'm now seeing the problem: The formatting here is very misleading, because it makes me believe that <|> binds stronger than *>, but in reality it's the other way around: <|> is infixl 3, while *> is infixl 4.

It makes more sense when we format it this way, also added a comment:

chunk "''\\n"
<|> chunk "''\\r"
<|> chunk "''\\t"
<|> chunk "''\\'"
-- ''\ followed by any char throws away the ''\ part, leaving just the char
<|> chunk "''\\" *> (Text.singleton <$> anySingle)
<|> chunk "''$"
<|> chunk "'''"
<|> chunk "$$"
<|> try (chunk "$" <* notFollowedBy (char '{'))
<|> try (chunk "'" <* notFollowedBy (char '\''))
<|> someP (\t -> t /= '\'' && t /= '$' && t /= '\n')

<|> chunk "'''"
Expand Down
3 changes: 3 additions & 0 deletions test/correct/regression-197.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
''
''\'''${A}
''