From 847916426e357978640e514f7a3507ac9915bf4d Mon Sep 17 00:00:00 2001 From: Nurlan Alkuatov Date: Mon, 27 Jun 2022 21:34:26 +0600 Subject: [PATCH] fixup! [#6] Add a switch for allowing comments --- .../Interpolation/Nyan/Core/Internal/Parser.hs | 4 ++-- core/tests/Test/Interpolator.hs | 7 +++++++ full/src/Text/Interpolation/Nyan/Tutorial.hs | 14 ++++++++++++++ 3 files changed, 23 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 cbab063..bb3e198 100644 --- a/core/src/Text/Interpolation/Nyan/Core/Internal/Parser.hs +++ b/core/src/Text/Interpolation/Nyan/Core/Internal/Parser.hs @@ -53,7 +53,7 @@ toSwitchesOptionsBuilder DefaultSwitchesOptions{..} = finalizeSwitchesOptions :: MonadFail m => SwitchesOptionsBuilder -> m SwitchesOptions finalizeSwitchesOptions SwitchesOptionsBuilder{..} = do spacesTrimming <- fromOptional "spaces trimming" spacesTrimmingB - commenting <- fromOptional "allow commenting" commentingB + commenting <- fromOptional "comments handling" commentingB indentationStripping <- fromOptional "indentation stripping" indentationStrippingB leadingNewlineStripping <- fromOptional "leading newline stripping" leadingNewlineStrippingB trailingSpacesStripping <- fromOptional "trailing spaces stripping" trailingSpacesStrippingB @@ -80,7 +80,7 @@ setIfNew desc new (OptionChanged ch, old) setCommenting :: SwitchesOptionsSetter m => Bool -> m () setCommenting enable = do opts <- get - res <- setIfNew "allow comments" enable (commentingB opts) + res <- setIfNew "comments handling" enable (commentingB opts) put opts{ commentingB = res } setSpacesTrimming :: SwitchesOptionsSetter m => Bool -> m () diff --git a/core/tests/Test/Interpolator.hs b/core/tests/Test/Interpolator.hs index 4651777..27c9f0a 100644 --- a/core/tests/Test/Interpolator.hs +++ b/core/tests/Test/Interpolator.hs @@ -320,6 +320,13 @@ test_DefaultInterpolator = testGroup "Default interpolator" aren't they? -} |] @?= " My text \n" + + , testCase "Other switches keep the comments" do + [int|t| + The beginning + -- some comments in the middle + The end + |] @?= "The beginning\n-- some comments in the middle\nThe end\n" ] ] diff --git a/full/src/Text/Interpolation/Nyan/Tutorial.hs b/full/src/Text/Interpolation/Nyan/Tutorial.hs index 98be387..47817ae 100644 --- a/full/src/Text/Interpolation/Nyan/Tutorial.hs +++ b/full/src/Text/Interpolation/Nyan/Tutorial.hs @@ -223,6 +223,10 @@ 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 @@ -272,6 +276,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: + +>>> :{ + [int|t| + The beginning + -- some comments in the middle + The end + |] +:} +"The beginning\n-- some comments in the middle\nThe end\n" === Customizing the interpolator