sv-svfactor (empty) → 0.1
raw patch · 5 files changed
+177/−0 lines, 5 filesdep +basedep +bytestringdep +lenssetup-changed
Dependencies added: base, bytestring, lens, profunctors, sv-core, svfactor, validation
Files
- LICENCE +31/−0
- Setup.hs +2/−0
- changelog.md +5/−0
- src/Data/Sv/Svfactor.hs +93/−0
- sv-svfactor.cabal +46/−0
+ LICENCE view
@@ -0,0 +1,31 @@+Copyright (c) 2017-2018, Commonwealth Scientific and Industrial Research Organisation+(CSIRO) ABN 41 687 119 230.++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 QFPL 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.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ changelog.md view
@@ -0,0 +1,5 @@+# Revision history for sv-svfactor++## 0.1 -- 2018-07-19++* First version. Released on an unsuspecting world.
+ src/Data/Sv/Svfactor.hs view
@@ -0,0 +1,93 @@+{-|+Module : Data.Sv.Svfactor+Copyright : (C) CSIRO 2017-2018+License : BSD3+Maintainer : George Wilson <george.wilson@data61.csiro.au>+Stability : experimental+Portability : non-portable+-}++module Data.Sv.Svfactor (+ parseDecode+, parseDecode'+, decodeSvfactor+, ignoreSpaces+, ignoreField+, ignoreSpacedField+, treatAsQuoted+, treatAsQuotedUnspaced+, spacedField+, field+, contents+) where++import Control.Lens (view)+import Data.ByteString (ByteString)+import Data.Profunctor (Profunctor (lmap))+import Data.Svfactor.Parse+import Data.Svfactor.Syntax+import Data.Svfactor.Vector.NonEmpty (toVector)+import Data.Svfactor.Text.Space (spacedValue)+import Data.Svfactor.Text.Quote (Quote (DoubleQuote))+import qualified Data.Sv.Decode.Core as D+import Data.Validation++-- | Parse a 'ByteString' as an 'Sv' and then decode it using the given+-- decoder.+--+-- This version uses trifecta for parsing.+parseDecode :: D.Decode ByteString (SpacedField ByteString) a -> ParseOptions ByteString -> ByteString -> D.DecodeValidation ByteString [a]+parseDecode =+ parseDecode' trifecta++-- | Parse a 'ByteString' as an 'Sv' and then decode it using the given+-- decoder.+--+-- This version lets you control which parser is used.+parseDecode' :: SvParser s -> D.Decode s (SpacedField s) a -> ParseOptions s -> s -> D.DecodeValidation s [a]+parseDecode' svp dec opts = + flip bindValidation (decodeSvfactor dec) . D.validateEitherWith D.BadParse . parseSv' svp opts++-- | Decode from an 'Sv' using the given decoder+decodeSvfactor :: D.Decode s (SpacedField s) a -> Sv s -> D.DecodeValidation s [a]+decodeSvfactor dec =+ let dec' = D.promote' (view (spacedValue.fieldContents)) dec+ in traverse dec' . fmap (toVector . view spacedFields) . recordList++-- | Promote a decoder that works on fields to one that works on fields with+-- optional surrounding spaces, by ignoring the spaces.+ignoreSpaces :: D.Decode e (Field s) a -> D.Decode e (SpacedField s) a+ignoreSpaces = lmap (view spacedValue)++-- | Promote a decoder to work on a field by ignoring the structure of the+-- field.+ignoreField :: D.Decode e s a -> D.Decode e (Field s) a+ignoreField = lmap (view fieldContents)++-- | Promote a decoder to work on a spaced field by ignoring the spacing and+-- the field.+ignoreSpacedField :: D.Decode e s a -> D.Decode e (SpacedField s) a+ignoreSpacedField = ignoreSpaces . ignoreField++-- | Demote a decoder that works on fields to one that ignores the field+-- structure by always passing in a dummy set of double quotes.+treatAsQuoted :: D.Decode e (Field s) a -> D.Decode e s a+treatAsQuoted = lmap (unescapedField DoubleQuote)++-- | Demote a decoder that works on spaced fields to one that ignores the+-- spacing and field structure by always passing in a dummy set of double+-- quotes and empty spacing.+treatAsQuotedUnspaced :: D.Decode e (SpacedField s) a -> D.Decode e s a+treatAsQuotedUnspaced = treatAsQuoted . lmap pure++-- | Alias for 'D.contents'+spacedField :: D.Decode e (SpacedField s) (SpacedField s)+spacedField = D.contents++-- | Get the 'Field' from a 'SpacedField'+field :: D.Decode e (SpacedField s) (Field s)+field = fmap (view spacedValue) D.contents++-- | Get the contents from a 'SpacedField'+contents :: D.Decode e (SpacedField s) s+contents = fmap (view (spacedValue.fieldContents)) D.contents
+ sv-svfactor.cabal view
@@ -0,0 +1,46 @@+name: sv-svfactor+version: 0.1+license: BSD3+license-file: LICENCE+author: George Wilson+maintainer: george@qfpl.io+copyright: Copyright (c) 2018, Commonwealth Scientific and Industrial Research Organisation (CSIRO) ABN 41 687 119 230.+category: CSV, Text, Web+synopsis:+ sv-core + svfactor++description:+ <<http://i.imgur.com/uZnp9ke.png>>+ .+ Use sv-core's decoding atop svfactor's parser++homepage: https://github.com/qfpl/sv+bug-reports: https://github.com/qfpl/sv/issues+build-type: Simple+extra-source-files: changelog.md+cabal-version: >=1.10+tested-with: GHC == 7.10.3+ , GHC == 8.0.2+ , GHC == 8.2.2+ , GHC == 8.4.3+ , GHC == 8.6.1++source-repository head+ type: git+ location: git@github.com/qfpl/sv.git++library+ exposed-modules: Data.Sv.Svfactor+ -- other-modules:+ -- other-extensions: + build-depends: base >=4.7 && <5+ , bytestring >= 0.9.1.10 && < 0.11+ , lens >= 4 && < 4.18+ , profunctors >= 5.2.1 && < 6+ , sv-core >= 0.1 && < 0.2+ , svfactor >= 0.1 && < 0.2+ , validation >= 1 && < 1.1+ hs-source-dirs: src+ default-language: Haskell2010+ ghc-options:+ -Wall -O2