packages feed

ini-qq (empty) → 0.1.0.0

raw patch · 6 files changed

+199/−0 lines, 6 filesdep +HUnitdep +basedep +inisetup-changed

Dependencies added: HUnit, base, ini, ini-qq, raw-strings-qq, template-haskell, text

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Kwang Yul Seo (c) 2016++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Kwang Yul Seo nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,34 @@+ini-qq [![Build Status](https://travis-ci.org/kseo/ini-qq.svg?branch=master)](https://travis-ci.org/kseo/ini-qq)+======++Quasiquote for INI.++## Usage++```haskell+{-# LANGUAGE QuasiQuotes #-}++import Data.Ini+import Data.Ini.QQ++testIni :: Ini+testIni = [ini|+# Some comment.+[SERVER]+port=6667+hostname=localhost+; another comment here+[AUTH]+user: hello+pass: world+salt:|]+# Some comment.+[SERVER]+port=6667+hostname=localhost+[AUTH]+user=hello+pass=world+# Salt can be an empty string.+salt=|]+```
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ ini-qq.cabal view
@@ -0,0 +1,41 @@+name:                ini-qq+version:             0.1.0.0+synopsis:            Quasiquoter for INI+description:         This library provides quasiquoters for the ini package.+homepage:            https://github.com/kseo/ini-qq#readme+license:             BSD3+license-file:        LICENSE+author:              Kwang Yul Seo+maintainer:          kwangyul.seo@gmail.com+copyright:           BSD3+category:            Data, Configuration+build-type:          Simple+extra-source-files:  README.md+cabal-version:       >=1.10+tested-with:         GHC >= 8.0.1++library+  hs-source-dirs:      src+  exposed-modules:     Data.Ini.QQ+  build-depends:       base >= 4.7 && < 5+                     , ini >= 0.3 && < 0.4+                     , template-haskell >= 2.10+                     , text+  default-language:    Haskell2010++test-suite ini-qq-test+  type:                exitcode-stdio-1.0+  hs-source-dirs:      test+  main-is:             Spec.hs+  build-depends:       base+                     , HUnit+                     , ini+                     , ini-qq+                     , raw-strings-qq+                     , text+  ghc-options:         -threaded -rtsopts -with-rtsopts=-N+  default-language:    Haskell2010++source-repository head+  type:     git+  location: https://github.com/kseo/ini-qq
+ src/Data/Ini/QQ.hs view
@@ -0,0 +1,41 @@+{-# LANGUAGE TemplateHaskell #-}++-- | Quasiquoter for ini configuration+module Data.Ini.QQ+  ( ini+  ) where++import Data.Data+import Data.Ini+import qualified Data.Text as T+import Language.Haskell.TH+import Language.Haskell.TH.Quote+import Language.Haskell.TH.Syntax++-- See http://stackoverflow.com/questions/38143464/cant-find-inerface-file-declaration-for-variable+liftText :: T.Text -> Q Exp+liftText txt = AppE (VarE 'T.pack) <$> lift (T.unpack txt)++liftDataWithText :: Data a => a -> ExpQ+liftDataWithText = dataToExpQ (\a -> liftText <$> cast a)++ini :: QuasiQuoter+ini = QuasiQuoter {+  quoteExp = iniExp,+  quotePat = \s -> error "No quotePat defined for ini",+  quoteType = \s -> error "No quoteType defined for ini",+  quoteDec = \s -> error "No quoteDec defined for ini"+}++iniExp :: String -> ExpQ+iniExp txt =+  case parseIni (T.pack txt) of+    Left err -> error ("Error in iniExp: " ++ show err)+    Right val -> toExpQ val++-- Requires GHC 8 due to https://phabricator.haskell.org/D1313+toExpQ :: Ini -> ExpQ+toExpQ (Ini m) = do+  e <- liftDataWithText m+  return $ AppE (ConE $ mkName "Data.Ini.Ini") e+
+ test/Spec.hs view
@@ -0,0 +1,51 @@+{-# LANGUAGE QuasiQuotes, StandaloneDeriving #-}++import Data.Data+import Data.Ini+import Data.Ini.QQ+import qualified Data.Text as T+import System.Exit+import Text.RawString.QQ+import Test.HUnit++deriving instance Eq Ini++testIni :: Ini+testIni = [ini|+# Some comment.+[SERVER]+port=6667+hostname=localhost+; another comment here+[AUTH]+user: hello+pass: world+salt:|]++expectedIni :: Ini+expectedIni =+  case parsed of+    Left err -> error $ "Error in parsing ini: " ++ show err+    Right val -> val+  where parsed = parseIni (T.pack [r|+# Some comment.+[SERVER]+port=6667+hostname=localhost+; another comment here+[AUTH]+user: hello+pass: world+salt:|])++main :: IO ()+main = defaultMain $ test [+  "Quasiquote for ini" ~: (expectedIni ~=? testIni)+  ]++defaultMain :: Test -> IO ()+defaultMain t = do+  cnts <- runTestTT t+  case failures cnts + errors cnts of+    0 -> exitWith $ ExitSuccess+    n -> exitWith $ ExitFailure n