string-interpolate 0.2.0.1 → 0.2.0.2
raw patch · 4 files changed
+102/−93 lines, 4 filesdep +haskell-src-extsdep ~QuickCheckdep ~bytestringdep ~criterion
Dependencies added: haskell-src-exts
Dependency ranges changed: QuickCheck, bytestring, criterion, formatting, haskell-src-meta, hspec, interpolate, interpolatedstring-perl6, neat-interpolation, quickcheck-instances, quickcheck-text, quickcheck-unicode, random-shuffle, template-haskell, text, text-conversions, unordered-containers, utf8-string
Files
- CHANGELOG.md +5/−0
- src/lib/Data/String/Interpolate.hs +16/−9
- string-interpolate.cabal +76/−83
- test/Spec.hs +5/−1
CHANGELOG.md view
@@ -2,6 +2,11 @@ ## Unreleased +## v0.2.0.2 (2020-04-25)+++ Updated interpolation parser to use enabled language extensions+ (Thanks Cary Robbins!)+ ## v0.2.0.1 (2020-04-09) + Fixed bug caused when escaping a backslash right before an interpolation
src/lib/Data/String/Interpolate.hs view
@@ -1,7 +1,7 @@ -- | -- Module : Data.String.Interpolate -- Description : Unicode-aware string interpolation that handles all textual types.--- Copyright : (c) William Yao, 2019+-- Copyright : (c) William Yao, 2019-2020 -- License : BSD-3 -- Maintainer : williamyaoh@gmail.com -- Stability : experimental@@ -49,12 +49,14 @@ import Data.Proxy -import Language.Haskell.Meta.Parse ( parseExp )-import Language.Haskell.TH-import Language.Haskell.TH.Quote ( QuasiQuoter(..) )+import qualified Language.Haskell.Exts.Extension as Ext+import Language.Haskell.Exts.Parser+ ( ParseMode(..), ParseResult(..), defaultParseMode, parseExpWithMode )+import Language.Haskell.Meta ( ToExp(..) )+import Language.Haskell.TH+import Language.Haskell.TH.Quote ( QuasiQuoter(..) ) -import Data.String.Interpolate.Conversion- ( build, finalize, interpolate, ofString, chompSpaces )+import Data.String.Interpolate.Conversion ( build, chompSpaces, finalize, interpolate, ofString ) import Data.String.Interpolate.Parse ( InterpSegment(..), dosToUnix, parseInterpSegments ) i :: QuasiQuoter@@ -102,6 +104,11 @@ [|build Proxy (interpolate Proxy $(reifyExpression expr)) $(go rest)|] reifyExpression :: String -> Q Exp-reifyExpression s = case parseExp s of- Left _ -> fail $ "Data.String.Interpolate.i: parse error in expression: " ++ s- Right e -> pure e+reifyExpression s = do+ -- We want to explicitly use whatever extensions are enabled in current module+ exts <- (fmap . fmap) (Ext.parseExtension . show) extsEnabled+ parseMode <- pure (defaultParseMode { extensions = exts })+ case parseExpWithMode parseMode s of+ ParseFailed _ err -> fail $+ "Data.String.Interpolate.i: got error: '" ++ err ++ "' while parsing expression: " ++ s+ ParseOk e -> pure (toExp e)
string-interpolate.cabal view
@@ -1,92 +1,85 @@ cabal-version: 1.18---- This file has been generated from package.yaml by hpack version 0.31.2.------ see: https://github.com/sol/hpack------ hash: b3c4b493a41aadee8fb1cd235201f3fc305dfecc895817cd699b8785b1b1bed9--name: string-interpolate-version: 0.2.0.1-synopsis: Haskell string/text/bytestring interpolation that just works-description: Unicode-aware string interpolation that handles all textual types.- .- See the README at <https://gitlab.com/williamyaoh/string-interpolate/blob/master/README.md> for more info.-category: Data, Text-homepage: https://gitlab.com/williamyaoh/string-interpolate/blob/master/README.md-bug-reports: https://gitlab.com/williamyaoh/string-interpolate/issues-author: William Yao-maintainer: williamyaoh@gmail.com-copyright: 2019-2020 William Yao-license: BSD3-license-file: LICENSE-build-type: Simple-extra-doc-files:- README.md- CHANGELOG.md+name: string-interpolate+version: 0.2.0.2+license: BSD3+license-file: LICENSE+copyright: 2019-2020 William Yao+maintainer: williamyaoh@gmail.com+author: William Yao+homepage: https://gitlab.com/williamyaoh/string-interpolate/blob/master/README.md+bug-reports: https://gitlab.com/williamyaoh/string-interpolate/issues+synopsis: Haskell string/text/bytestring interpolation that just works+description:+ Unicode-aware string interpolation that handles all textual types.+ .+ See the README at <https://gitlab.com/williamyaoh/string-interpolate/blob/master/README.md> for more info.+category: Data, Text+build-type: Simple+extra-doc-files: README.md+ CHANGELOG.md source-repository head- type: git- location: https://www.gitlab.com/williamyaoh/string-interpolate.git+ type: git+ location: https://www.gitlab.com/williamyaoh/string-interpolate.git library- exposed-modules:- Data.String.Interpolate- Data.String.Interpolate.Conversion- other-modules:- Data.String.Interpolate.Parse- Paths_string_interpolate- hs-source-dirs:- src/lib- ghc-options: -Wall -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints -Wnoncanonical-monad-instances -fno-warn-name-shadowing- build-depends:- base ==4.*- , bytestring- , haskell-src-meta- , template-haskell- , text- , text-conversions- , utf8-string- default-language: Haskell2010+ exposed-modules:+ Data.String.Interpolate+ Data.String.Interpolate.Conversion+ hs-source-dirs: src/lib+ other-modules:+ Data.String.Interpolate.Parse+ Paths_string_interpolate+ default-language: Haskell2010+ ghc-options: -Wall -Wcompat -Wincomplete-record-updates+ -Wincomplete-uni-patterns -Wredundant-constraints+ -Wnoncanonical-monad-instances -fno-warn-name-shadowing+ build-depends:+ base ==4.*,+ bytestring >=0.10.8.2 && <0.11,+ haskell-src-exts >=1.21.1 && <1.22,+ haskell-src-meta >=0.8.3 && <0.9,+ template-haskell >=2.14.0.0 && <2.15,+ text >=1.2.3.1 && <1.3,+ text-conversions >=0.3.0 && <0.4,+ utf8-string >=1.0.1.1 && <1.1 test-suite string-interpolate-test- type: exitcode-stdio-1.0- main-is: Spec.hs- other-modules:- Paths_string_interpolate- hs-source-dirs:- test- ghc-options: -threaded -rtsopts -with-rtsopts=-N- build-depends:- QuickCheck- , base ==4.*- , bytestring- , hspec- , quickcheck-instances- , quickcheck-text- , quickcheck-unicode- , random-shuffle- , string-interpolate- , text- , unordered-containers- default-language: Haskell2010+ type: exitcode-stdio-1.0+ main-is: Spec.hs+ hs-source-dirs: test+ other-modules:+ Paths_string_interpolate+ default-language: Haskell2010+ ghc-options: -threaded -rtsopts -with-rtsopts=-N+ build-depends:+ QuickCheck >=2.13.2 && <2.14,+ base ==4.*,+ bytestring >=0.10.8.2 && <0.11,+ hspec >=2.7.1 && <2.8,+ quickcheck-instances >=0.3.22 && <0.4,+ quickcheck-text >=0.1.2.1 && <0.2,+ quickcheck-unicode >=1.0.1.0 && <1.1,+ random-shuffle >=0.0.4 && <0.1,+ string-interpolate -any,+ text >=1.2.3.1 && <1.3,+ unordered-containers >=0.2.10.0 && <0.3 benchmark string-interpolate-bench- type: exitcode-stdio-1.0- main-is: Bench.hs- other-modules:- Paths_string_interpolate- hs-source-dirs:- bench- build-depends:- QuickCheck- , base ==4.*- , bytestring- , criterion- , formatting- , interpolate- , interpolatedstring-perl6- , neat-interpolation- , string-interpolate- , text- default-language: Haskell2010+ type: exitcode-stdio-1.0+ main-is: Bench.hs+ hs-source-dirs: bench+ other-modules:+ Paths_string_interpolate+ default-language: Haskell2010+ build-depends:+ QuickCheck >=2.13.2 && <2.14,+ base ==4.*,+ bytestring >=0.10.8.2 && <0.11,+ criterion >=1.5.6.1 && <1.6,+ formatting >=6.3.7 && <6.4,+ interpolate >=0.2.0 && <0.3,+ interpolatedstring-perl6 >=1.0.2 && <1.1,+ neat-interpolation >=0.3.2.6 && <0.4,+ string-interpolate -any,+ text >=1.2.3.1 && <1.3
test/Spec.hs view
@@ -45,9 +45,13 @@ expected :: String = "foo\\bar" [i|foo\\#{var}|] `shouldBe` expected - it "should only esacpe verbatim segments a single time" $ do+ it "should only escape verbatim segments a single time" $ do let expected :: String = "\\\\\\\\" [i|\\\\\\\\|] `shouldBe` expected++ it "should parse TypeApplications" $ do+ let expected :: String = "2"+ [i|#{show @Int 2}|] `shouldBe` expected context "when using String as a parameter" $ do prop "just interpolating should be id" $