diff --git a/core/tests/Test/Interpolator.hs b/core/tests/Test/Interpolator.hs index 27c9f0a..fc23e22 100644 --- a/core/tests/Test/Interpolator.hs +++ b/core/tests/Test/Interpolator.hs @@ -321,13 +321,20 @@ test_DefaultInterpolator = testGroup "Default interpolator" -} |] @?= " My text \n" - , testCase "Other switches keep the comments" do - [int|t| + , testCase "Line comments do not affect the indentation" do + [int|tc| The beginning - -- some comments in the middle + -- some comments in the middle The end - |] @?= "The beginning\n-- some comments in the middle\nThe end\n" - ] + |] @?= " The beginning\n\n The end\n" + + , testCase "Block comments do not affect the indentation" do + [int|tc| + The beginning {- some clarifying + comments in the middle -} + The end + |] @?= "The beginning \nThe end\n" + ] ] diff --git a/full/src/Text/Interpolation/Nyan/Tutorial.hs b/full/src/Text/Interpolation/Nyan/Tutorial.hs index 47817ae..5540f63 100644 --- a/full/src/Text/Interpolation/Nyan/Tutorial.hs +++ b/full/src/Text/Interpolation/Nyan/Tutorial.hs @@ -207,6 +207,20 @@ In case monadic actions have side effects, they will be applied in the same orde in which placeholders appear in the quoter. /But you are not going to use this behaviour, don't you?/ +==== c ([c]omments handling) + +Handle line comments starting with @--@ and/or block comments enclosed in @{- ... -}@. + +>>> :{ + [int|c|My text -- this is a line comment|] +:} +"My text " + +>>> :{ + [int|c|My {- this is a block comment -} text|] +:} +"My text" + ==== t (return [t]ext) The quoter will return concrete t'Text'. @@ -223,10 +237,6 @@ The quoter will return concrete t'Builder'. The quoter will return any type with t'FromBuilder' instance. -==== c ([c]omments handling) - -Ignore line comments starting with @--@ and/or block comments enclosed in @{- ... -}@. - ==== ! (preview) Quoter will show as an error (non-blocking for the module's build) how the @@ -276,16 +286,16 @@ affects indentation stripping to also ignore the line with @|]@: :} "\nValue 1 is 5, value 2 is 10\n" -* Comments __are not ignored__ by other switches unless comments handling is explicitly turned on: +* Comments remain invisible for other switches and thus do not affect them. +Consider the following indentation stripping example: >>> :{ - [int|t| + [int|c| The beginning - -- some comments in the middle - The end - |] +-- some comments in the middle + The end|] :} -"The beginning\n-- some comments in the middle\nThe end\n" +"The beginning\n\nThe end" === Customizing the interpolator