json-ast-json-encoder (empty) → 0.1
raw patch · 4 files changed
+143/−0 lines, 4 filesdep +base-preludedep +contravariantdep +contravariant-extrassetup-changed
Dependencies added: base-prelude, contravariant, contravariant-extras, json-ast, json-encoder, scientific, text, unordered-containers, vector
Files
- LICENSE +22/−0
- Setup.hs +2/−0
- json-ast-json-encoder.cabal +56/−0
- library/JSONAST/JSONEncoder.hs +63/−0
+ LICENSE view
@@ -0,0 +1,22 @@+Copyright (c) 2016, Sannsyn AS++Permission is hereby granted, free of charge, to any person+obtaining a copy of this software and associated documentation+files (the "Software"), to deal in the Software without+restriction, including without limitation the rights to use,+copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the+Software is furnished to do so, subject to the following+conditions:++The above copyright notice and this permission notice shall be+included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR+OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ json-ast-json-encoder.cabal view
@@ -0,0 +1,56 @@+name:+ json-ast-json-encoder+version:+ 0.1+synopsis:+ Encoders of JSON AST+homepage:+ https://github.com/sannsyn/json-ast-json-encoder +bug-reports:+ https://github.com/sannsyn/json-ast-json-encoder/issues +author:+ Nikita Volkov <nikita.y.volkov@mail.ru>+maintainer:+ Nikita Volkov <nikita.y.volkov@mail.ru>+copyright:+ (c) 2016, Sannsyn AS+license:+ MIT+license-file:+ LICENSE+build-type:+ Simple+cabal-version:+ >=1.10+++source-repository head+ type:+ git+ location:+ git://github.com/sannsyn/json-ast-json-encoder.git+++library+ hs-source-dirs:+ library+ default-extensions:+ Arrows, BangPatterns, ConstraintKinds, DataKinds, DefaultSignatures, DeriveDataTypeable, DeriveFoldable, DeriveFunctor, DeriveGeneric, DeriveTraversable, EmptyDataDecls, FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs, GeneralizedNewtypeDeriving, ImpredicativeTypes, LambdaCase, LiberalTypeSynonyms, MagicHash, MultiParamTypeClasses, MultiWayIf, NoImplicitPrelude, NoMonomorphismRestriction, OverloadedStrings, PatternGuards, ParallelListComp, QuasiQuotes, RankNTypes, RecordWildCards, ScopedTypeVariables, StandaloneDeriving, TemplateHaskell, TupleSections, TypeFamilies, TypeOperators, UnboxedTuples+ default-language:+ Haskell2010+ other-modules:+ exposed-modules:+ JSONAST.JSONEncoder+ build-depends:+ -- + json-encoder >= 0.1.7 && < 0.2,+ json-ast >= 0.3 && < 0.4,+ -- data:+ vector >= 0.10 && < 0.12,+ unordered-containers >= 0.2 && < 0.3,+ text >= 1 && < 2,+ scientific >= 0.3 && < 0.4,+ -- general:+ contravariant >= 1.3 && < 2,+ contravariant-extras >= 0.3.2 && < 0.4,+ base-prelude < 2
+ library/JSONAST/JSONEncoder.hs view
@@ -0,0 +1,63 @@+module JSONAST.JSONEncoder+where++import BasePrelude hiding (null)+import JSONEncoder+import JSONAST+import Data.Vector (Vector)+import Data.Text (Text)+import Data.Scientific (Scientific)+import Data.HashMap.Strict (HashMap)+import Data.Functor.Contravariant+import Data.Functor.Contravariant.Divisible+import Contravariant.Extras+import qualified Data.HashMap.Strict as HashMap+++json :: Value JSON+json =+ contramap match $+ chosen jsonObject $+ chosen jsonArray $+ chosen jsonString $+ chosen jsonNumber $+ chosen jsonBoolean $+ jsonNull+ where+ match =+ \case+ JSON_Object x -> Left x+ JSON_Array x -> Right (Left x)+ JSON_String x -> Right (Right (Left x))+ JSON_Number x -> Right (Right (Right (Left x)))+ JSON_Bool x -> Right (Right (Right (Right (Left x))))+ _ -> Right (Right (Right (Right (Right ()))))++jsonObject :: Value (HashMap Text JSON)+jsonObject =+ object $+ contramap HashMap.toList $+ contramany $+ row json++jsonArray :: Value (Vector JSON)+jsonArray =+ array $+ homo foldl' json++jsonString :: Value Text+jsonString =+ string++jsonNumber :: Value Scientific+jsonNumber =+ number_scientific++jsonBoolean :: Value Bool+jsonBoolean =+ boolean++jsonNull :: Value ()+jsonNull =+ null+