Skip to content

Commit

Permalink
Fixity parser: don't require trailing newline
Browse files Browse the repository at this point in the history
  • Loading branch information
amesgen committed Jun 9, 2024
1 parent a9e996b commit 868415f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Unreleased

* Don't require a trailing newline in `.ormolu` files. [Issue
1122](https://github.com/tweag/ormolu/issues/1122).

## Ormolu 0.7.5.0

* Switched to `ghc-lib-parser-9.10`, with the following new syntactic features/behaviors:
Expand Down
8 changes: 2 additions & 6 deletions src/Ormolu/Fixity/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,10 @@ pDotOrmolu =
(FixityOverrides . Map.fromList . mconcat)
(ModuleReexports . Map.map NE.sort . Map.fromListWith (<>))
. partitionEithers
<$> many configLine
<$> (configLine `sepEndBy` (void eol *> hidden space))
<* eof
where
configLine = do
x <- eitherP pFixity pModuleReexport
void eol
hidden space
return x
configLine = eitherP pFixity pModuleReexport

-- | Parse a single fixity declaration, such as
--
Expand Down
7 changes: 7 additions & 0 deletions tests/Ormolu/Fixity/ParserSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ spec = do
[ "infixr 9 .",
"infixr 5 ++"
]
it "parses inputs without a trailing newline" $
parseDotOrmolu ""
`shouldSucceedOn` T.intercalate
"\n"
[ "infixr 9 .",
"infixr 5 ++"
]
it "fails with correct parse error (keyword wrong second line)" $
parseDotOrmolu "" "infixr 5 .\nfoobar 5 $"
`shouldFailWith` err
Expand Down

0 comments on commit 868415f

Please sign in to comment.