Skip to content

Commit

Permalink
fixup! [#6] Add a switch for allowing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nalkuatov committed Jun 27, 2022
1 parent 7832b9d commit 8479164
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/src/Text/Interpolation/Nyan/Core/Internal/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ()
Expand Down
7 changes: 7 additions & 0 deletions core/tests/Test/Interpolator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]

]
Expand Down
14 changes: 14 additions & 0 deletions full/src/Text/Interpolation/Nyan/Tutorial.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8479164

Please sign in to comment.