Skip to content

Commit

Permalink
fixup! [#6] Add a switch for allowing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nalkuatov committed Jun 16, 2022
1 parent ecf1fdf commit 7832b9d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions core/src/Text/Interpolation/Nyan/Core/Internal/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Fmt (Builder, build, fmt)
import Text.Interpolation.Nyan.Core.Internal.Base
import Text.Megaparsec (Parsec, customFailure, eof, errorBundlePretty, label, lookAhead, parse,
single, takeWhile1P, takeWhileP)
import Text.Megaparsec.Char.Lexer (skipLineComment)
import Text.Megaparsec.Char.Lexer (skipBlockComment, skipLineComment)
import Text.Megaparsec.Error (ShowErrorComponent (..))

newtype OptionChanged = OptionChanged Bool
Expand Down Expand Up @@ -279,7 +279,8 @@ intPieceP :: Ord e => SwitchesOptions -> Parsec e Text [ParsedIntPiece]
intPieceP SwitchesOptions{..} = asum [

-- ignore comments if 'commenting' switch is on
guard commenting *> skipLineComment "--" $> []
guard commenting *>
asum [ skipLineComment "--" , skipBlockComment "{-" "-}" ] $> []

-- consume normal text
, one . PipString <$> takeWhile1P Nothing (notAnyOf [(== '\\'), (== '#'), isSpace])
Expand Down
11 changes: 11 additions & 0 deletions core/tests/Test/Interpolator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,17 @@ test_DefaultInterpolator = testGroup "Default interpolator"
My text -- comments in the middle
-- comments at the end
|] @?= " \nMy text \n\n"

, testCase "Inline block comments" do
[int|tc| My text {- inline comment -}
|] @?= " My text \n"

, testCase "Multiline block comments" do
[int|tc| My text {- multiline block
comments are fun,
aren't they?
-}
|] @?= " My text \n"
]

]
Expand Down

0 comments on commit 7832b9d

Please sign in to comment.