nyan-interpolation-core 0.9.0.1 → 0.9.1
raw patch · 7 files changed
+117/−35 lines, 7 filesdep ~basePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: base
API changes (from Hackage documentation)
- Text.Interpolation.Nyan.Core.Internal.Splice: type ExtendableRes = (ExpQ -> ExpQ) -> ExpQ
+ Text.Interpolation.Nyan.RModes.CommonExtra: rmode'exc :: Exception e => RMode e
Files
- CHANGES.md +10/−1
- nyan-interpolation-core.cabal +69/−7
- src/Text/Interpolation/Nyan/Core.hs +6/−1
- src/Text/Interpolation/Nyan/Core/Internal/Parser.hs +4/−6
- src/Text/Interpolation/Nyan/Core/Internal/Splice.hs +0/−7
- src/Text/Interpolation/Nyan/RModes/CommonExtra.hs +8/−1
- tests/Test/Interpolator.hs +20/−12
CHANGES.md view
@@ -4,6 +4,15 @@ -- SPDX-License-Identifier: MPL-2.0 --> -# 0.1+# Unreleased+++# 0.9.1++* Bump upper bound on `base` to <4.17.+* Fix the issue with interpolator failing with non-exhaustive pattern match on fresh LTS / GHC versions.+* Avoid creating extra `\r`s at end of line on Windows.++# 0.9 Initial version.
nyan-interpolation-core.cabal view
@@ -1,13 +1,13 @@ cabal-version: 2.0 --- This file has been generated from package.yaml by hpack version 0.33.0.+-- This file has been generated from package.yaml by hpack version 0.35.0. -- -- see: https://github.com/sol/hpack ----- hash: 4810cd4539501b3d69ccbc22d8a6c24b1545a973c329ab1e27f62cdcb2296dde+-- hash: 454835beb066a76fcd19ff1540bc89d3e2f2732ac9d7164ec5903d0eb782bebd name: nyan-interpolation-core-version: 0.9.0.1+version: 0.9.1 synopsis: Customize your nyan interpolator! description: This package to tune up your own variation of interpolator. Declare new rendering modes, set desired switches defaults and more. category: Interpolation, Text@@ -43,10 +43,40 @@ Paths_nyan_interpolation_core hs-source-dirs: src- default-extensions: AllowAmbiguousTypes BangPatterns BlockArguments ConstraintKinds DataKinds DefaultSignatures DeriveDataTypeable DeriveGeneric DerivingStrategies FlexibleContexts FlexibleInstances FunctionalDependencies GeneralizedNewtypeDeriving LambdaCase MultiParamTypeClasses MultiWayIf NamedFieldPuns OverloadedStrings RankNTypes RecordWildCards ScopedTypeVariables StandaloneDeriving TemplateHaskell TupleSections TypeFamilies UndecidableInstances ViewPatterns TypeApplications TypeOperators QuasiQuotes+ default-extensions:+ AllowAmbiguousTypes+ BangPatterns+ BlockArguments+ ConstraintKinds+ DataKinds+ DefaultSignatures+ DeriveDataTypeable+ DeriveGeneric+ DerivingStrategies+ FlexibleContexts+ FlexibleInstances+ FunctionalDependencies+ GeneralizedNewtypeDeriving+ LambdaCase+ MultiParamTypeClasses+ MultiWayIf+ NamedFieldPuns+ OverloadedStrings+ RankNTypes+ RecordWildCards+ ScopedTypeVariables+ StandaloneDeriving+ TemplateHaskell+ TupleSections+ TypeFamilies+ UndecidableInstances+ ViewPatterns+ TypeApplications+ TypeOperators+ QuasiQuotes ghc-options: -Weverything -Wno-missing-export-lists -Wno-missing-exported-signatures -Wno-missing-import-lists -Wno-missed-specialisations -Wno-all-missed-specialisations -Wno-unsafe -Wno-safe -Wno-missing-local-signatures -Wno-monomorphism-restriction -Wno-implicit-prelude -Wno-prepositive-qualified-module -Wno-missing-safe-haskell-mode -Wno-unused-packages build-depends:- base <4.15+ base <4.17 , fmt , megaparsec , mtl@@ -67,15 +97,47 @@ Test.ValueInterpolators Tree Paths_nyan_interpolation_core+ autogen-modules:+ Paths_nyan_interpolation_core hs-source-dirs: tests- default-extensions: AllowAmbiguousTypes BangPatterns BlockArguments ConstraintKinds DataKinds DefaultSignatures DeriveDataTypeable DeriveGeneric DerivingStrategies FlexibleContexts FlexibleInstances FunctionalDependencies GeneralizedNewtypeDeriving LambdaCase MultiParamTypeClasses MultiWayIf NamedFieldPuns OverloadedStrings RankNTypes RecordWildCards ScopedTypeVariables StandaloneDeriving TemplateHaskell TupleSections TypeFamilies UndecidableInstances ViewPatterns TypeApplications TypeOperators QuasiQuotes+ default-extensions:+ AllowAmbiguousTypes+ BangPatterns+ BlockArguments+ ConstraintKinds+ DataKinds+ DefaultSignatures+ DeriveDataTypeable+ DeriveGeneric+ DerivingStrategies+ FlexibleContexts+ FlexibleInstances+ FunctionalDependencies+ GeneralizedNewtypeDeriving+ LambdaCase+ MultiParamTypeClasses+ MultiWayIf+ NamedFieldPuns+ OverloadedStrings+ RankNTypes+ RecordWildCards+ ScopedTypeVariables+ StandaloneDeriving+ TemplateHaskell+ TupleSections+ TypeFamilies+ UndecidableInstances+ ViewPatterns+ TypeApplications+ TypeOperators+ QuasiQuotes ghc-options: -Weverything -Wno-missing-export-lists -Wno-missing-exported-signatures -Wno-missing-import-lists -Wno-missed-specialisations -Wno-all-missed-specialisations -Wno-unsafe -Wno-safe -Wno-missing-local-signatures -Wno-monomorphism-restriction -Wno-implicit-prelude -Wno-prepositive-qualified-module -Wno-missing-safe-haskell-mode -Wno-unused-packages build-tool-depends: tasty-discover:tasty-discover build-depends: HUnit- , base <4.15+ , base <4.17 , fmt , megaparsec , mtl
src/Text/Interpolation/Nyan/Core.hs view
@@ -74,7 +74,7 @@ { TH.quoteExp = \s -> do (sopts, sint) <- either fail pure $- parseIntString (defaultSwitchesOptions iopts) (T.pack s)+ parseIntString (defaultSwitchesOptions iopts) (useUnixLineEndings $ T.pack s) let sint' = processIntString sopts sint intSplice iopts (sopts, sint') , TH.quotePat = \_ ->@@ -84,6 +84,11 @@ , TH.quoteDec = \_ -> fail "Cannot interpolate at declaration position" }+ where+ -- as in https://github.com/serokell/nyan-interpolation/issues/21,+ -- we should use LF line endings even when source file has CRLF+ useUnixLineEndings :: T.Text -> T.Text+ useUnixLineEndings = T.replace "\r\n" "\n" -- | The most interpolator options. --
src/Text/Interpolation/Nyan/Core/Internal/Parser.hs view
@@ -4,7 +4,7 @@ module Text.Interpolation.Nyan.Core.Internal.Parser where -import Control.Applicative (many, optional)+import Control.Applicative (many) import Control.Monad (guard, when, (<=<)) import Control.Monad.State (MonadState, execStateT, get, put) import Data.Bifunctor (first)@@ -304,11 +304,9 @@ ] where- newline = PipNewline . mconcat <$> sequence- [ maybe "" T.singleton <$> optional (single '\r')- , T.singleton <$> single '\n'- ]- isNonNewlineSpace c = isSpace c && c /= '\n' && c /= '\r'+ newline = PipNewline . T.singleton <$> single '\n'++ isNonNewlineSpace c = isSpace c && c /= '\n' -- Parse indentation lineStart = asum
src/Text/Interpolation/Nyan/Core/Internal/Splice.hs view
@@ -17,9 +17,6 @@ import Text.Interpolation.Nyan.Core.Internal.Base import Text.Interpolation.Nyan.Core.Internal.RMode --- | Expression result of which can yet be somehow extended.-type ExtendableRes = (ExpQ -> ExpQ) -> ExpQ- -- | Build interpolated string into TH splice. -- Note: one of things we aim at is concise produced code, as the user may@@ -162,10 +159,6 @@ go = \case ' ' : s -> '·' : go s- '\r' : '\n' : s ->- '⤶' : '\r' : '\n' : go s- '\r' : s ->- '⤶' : '\r' : go s '\n' : s -> '⤶' : '\n' : go s
src/Text/Interpolation/Nyan/RModes/CommonExtra.hs view
@@ -5,8 +5,9 @@ -- | Common additional rendering modes like the ones for numbers. module Text.Interpolation.Nyan.RModes.CommonExtra where -import Fmt (Builder)+import Fmt (Builder, build) +import Control.Exception (Exception (..)) import Text.Interpolation.Nyan.Core import Text.Interpolation.Nyan.RModes.Buildable (rmode') @@ -30,3 +31,9 @@ -- Alias for 'rmode'd'. rmode'n :: RMode Integer rmode'n = rmode'd++-- * Exceptions++-- | Render exception via 'displayException'.+rmode'exc :: Exception e => RMode e+rmode'exc = RMode (build . displayException)
tests/Test/Interpolator.hs view
@@ -5,6 +5,7 @@ -- | Tests on the interpolator in overall. module Test.Interpolator where +import Control.Exception (AsyncException (ThreadKilled)) import Control.Monad.Reader (ask, runReader) import Data.Functor.Identity (Identity (..)) import Data.Text (Text)@@ -59,18 +60,6 @@ [int|t|Values: {#{a}, #{b}} and #{c}|] @?= "Values: {X, Y} and Z" - , testCase "Rendering modes" do- let a = PrintedValue 1- let n = 5- let s = "string"- [int|t|#{a}, #s{a}, #d{n}, #l{s}|]- @?= "v = 1, PrintedValue 1, 5, string"-- , testCase "Locally defined rendering mode" do- let s = "nyan"- [int|t|#mega{s}|]- @?= "mega nyan"- , testCase "Spaces in {}" do let a = 5 let s = "string"@@ -78,6 +67,25 @@ @?= "5, string" ]++ , testGroup "Rendering modes"+ [ testCase "Basic" do+ let a = PrintedValue 1+ let n = 5+ let s = "string"+ [int|t|#{a}, #s{a}, #d{n}, #l{s}|]+ @?= "v = 1, PrintedValue 1, 5, string"++ , testCase "Locally defined rendering mode" do+ let s = "nyan"+ [int|t|#mega{s}|]+ @?= "mega nyan"++ , testCase "Exception" do+ let err = ThreadKilled+ [int|t|Failed with: #exc{err}|]+ @?= "Failed with: thread killed"+ ] , testGroup "Escaping" [ testCase "Newline" do