From 2e2697f31d60c70d72108b0e12cc20d78377c1ce Mon Sep 17 00:00:00 2001 From: Nurlan Alkuatov Date: Thu, 16 Jun 2022 13:35:21 +0600 Subject: [PATCH] fixup! [#6] Add a switch for allowing comments --- .../Text/Interpolation/Nyan/Core/Internal/Parser.hs | 5 +++-- core/tests/Test/Interpolator.hs | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) 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" ] ]