Skip to content

Commit

Permalink
Haisheng/tweak parser comment line (#1505)
Browse files Browse the repository at this point in the history
* Tweak the comment line parsing rule

- In order to support `-- |` being an empty line

* run through stylish-haskell

* Update changelog

* Update changelog - update PR number
  • Loading branch information
hw202207 authored Jun 28, 2023
1 parent 2a26141 commit 892a9d5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions persistent/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

* [#1496](https://github.com/yesodweb/persistent/pull/1496)
* Fixes name shadowing error at the generated `keyFromRecordM` function.
* [#1505](https://github.com/yesodweb/persistent/pull/1505)
* Fixes the comment line parsing rule so that accommodates paragraph breaks.

## 2.14.5.0

Expand Down
4 changes: 2 additions & 2 deletions persistent/Database/Persist/Quasi/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ module Database.Persist.Quasi.Internal
import Prelude hiding (lines)

import Control.Applicative (Alternative((<|>)))
import Data.Char (isDigit, isLower, isSpace, isUpper, toLower)
import Control.Monad
import Data.Char (isDigit, isLower, isSpace, isUpper, toLower)
import Data.List (find, foldl')
import Data.List.NonEmpty (NonEmpty(..))
import qualified Data.List.NonEmpty as NEL
Expand Down Expand Up @@ -238,7 +238,7 @@ parseIndentationAmount txt =
tokenize :: Text -> [Token]
tokenize t
| T.null t = []
| Just txt <- T.stripPrefix "-- | " t = [DocComment txt]
| Just txt <- T.stripPrefix "-- |" t = [DocComment (T.stripStart txt)]
| "--" `T.isPrefixOf` t = [] -- Comment until the end of the line.
| "#" `T.isPrefixOf` t = [] -- Also comment to the end of the line, needed for a CPP bug (#110)
| T.head t == '"' = quotes (T.tail t) id
Expand Down
7 changes: 7 additions & 0 deletions persistent/test/Database/Persist/QuasiSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,13 @@ spec = describe "Quasi" $ do
[ DocComment "this is a comment"
]
)
it "recognizes empty line" $ do
parseLine "-- |" `shouldBe`
Just
( Line 0
[ DocComment ""
]
)

it "works if comment is indented" $ do
parseLine " -- | comment" `shouldBe`
Expand Down

0 comments on commit 892a9d5

Please sign in to comment.