diff --git a/core/src/Text/Interpolation/Nyan/Core/Internal/Parser.hs b/core/src/Text/Interpolation/Nyan/Core/Internal/Parser.hs index bb3e198..c60c4af 100644 --- a/core/src/Text/Interpolation/Nyan/Core/Internal/Parser.hs +++ b/core/src/Text/Interpolation/Nyan/Core/Internal/Parser.hs @@ -16,7 +16,8 @@ import qualified Data.Text as T 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) + single, takeWhile1P, takeWhileP, try) +import Text.Megaparsec.Char (spaceChar) import Text.Megaparsec.Char.Lexer (skipBlockComment, skipLineComment) import Text.Megaparsec.Error (ShowErrorComponent (..)) @@ -280,7 +281,7 @@ intPieceP SwitchesOptions{..} = asum [ -- ignore comments if 'commenting' switch is on guard commenting *> - asum [ skipLineComment "--" , skipBlockComment "{-" "-}" ] $> [] + asum [ skipLineComment "--", skipBlockComment' ] $> [] -- consume normal text , one . PipString <$> takeWhile1P Nothing (notAnyOf [(== '\\'), (== '#'), isSpace]) @@ -329,6 +330,11 @@ intPieceP SwitchesOptions{..} = asum [ ] where + skipBlockComment' = asum + [ skipBlockComment "{-" "-}" + , try $ spaceChar *> skipBlockComment "{-" "-}" + ] + newline = PipNewline . mconcat <$> sequence [ maybe "" T.singleton <$> optional (single '\r') , T.singleton <$> single '\n' diff --git a/core/tests/Test/Interpolator.hs b/core/tests/Test/Interpolator.hs index fc23e22..1f89ea8 100644 --- a/core/tests/Test/Interpolator.hs +++ b/core/tests/Test/Interpolator.hs @@ -311,15 +311,15 @@ test_DefaultInterpolator = testGroup "Default interpolator" |] @?= " \nMy text \n\n" , testCase "Inline block comments" do - [int|tc| My text {- inline comment -} - |] @?= " My text \n" + [int|tc| My {- inline comment -} text + |] @?= " My text\n" , testCase "Multiline block comments" do [int|tc| My text {- multiline block comments are fun, aren't they? -} - |] @?= " My text \n" + |] @?= " My text\n" , testCase "Line comments do not affect the indentation" do [int|tc| @@ -331,9 +331,9 @@ test_DefaultInterpolator = testGroup "Default interpolator" , testCase "Block comments do not affect the indentation" do [int|tc| The beginning {- some clarifying - comments in the middle -} + comments in the middle -} The end - |] @?= "The beginning \nThe end\n" + |] @?= "The beginning\nThe end\n" ] ] diff --git a/full/src/Text/Interpolation/Nyan/Tutorial.hs b/full/src/Text/Interpolation/Nyan/Tutorial.hs index 5540f63..c775ce6 100644 --- a/full/src/Text/Interpolation/Nyan/Tutorial.hs +++ b/full/src/Text/Interpolation/Nyan/Tutorial.hs @@ -219,7 +219,7 @@ Handle line comments starting with @--@ and/or block comments enclosed in @{- .. >>> :{ [int|c|My {- this is a block comment -} text|] :} -"My text" +"My text" ==== t (return [t]ext)