diff --git a/core/src/Text/Interpolation/Nyan/Core/Internal/Parser.hs b/core/src/Text/Interpolation/Nyan/Core/Internal/Parser.hs index d4c51d5..cbab063 100644 --- a/core/src/Text/Interpolation/Nyan/Core/Internal/Parser.hs +++ b/core/src/Text/Interpolation/Nyan/Core/Internal/Parser.hs @@ -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 @@ -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]) diff --git a/core/tests/Test/Interpolator.hs b/core/tests/Test/Interpolator.hs index b3aa01c..4651777 100644 --- a/core/tests/Test/Interpolator.hs +++ b/core/tests/Test/Interpolator.hs @@ -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" ] ]