Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump resolver to lts-20.26 #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions src/Text/XML/JSON/XmlToJson.hs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
module Text.XML.JSON.XmlToJson(xmlToJson, Flag(..)) where

import Control.Applicative ((*>), (<*))
import Control.Arrow (first, (&&&), (***), (>>>))
import Control.Arrow ((&&&), (***), (>>>))
import Control.Arrow.ArrowTree (ArrowTree)
import Control.Category (id)
import Control.Monad (forM_)
import Data.Maybe (catMaybes)
import Data.Tree.NTree.TypeDefs
import Data.Tree.Class (Tree)
import Data.Tree.Class (Tree)
import Prelude hiding (id)
import Text.Regex.Posix ((=~))
import Text.XML.HXT.Core (ArrowXml, XNode (..), XmlTree,
Expand All @@ -21,14 +20,13 @@ import Text.XML.HXT.Curl -- use libcurl for HTTP access, only necessary when rea
#endif

import qualified Data.Aeson as Aeson
import qualified Data.Aeson.Key as AesonKey
import qualified Data.ByteString.Lazy.Char8 as BS
import qualified Data.HashMap.Strict as HashMap
import qualified Data.Map as M
import qualified Data.Text as T
import qualified Data.Vector as Vector
import Text.XML.HXT.Expat (withExpat)


data Flag = Input String | StartFrom String | Multiline | SkipRoots | NoIgnoreNulls | WrapArray | NoCollapseText String | ShowHelp
deriving (Show, Eq)

Expand Down Expand Up @@ -104,10 +102,11 @@ arrayValuesToJSONArrays = M.mapMaybe f
f [x] = Just x -- don't store as array, just a single value
f xss = Just $ Aeson.Array . Vector.fromList $ xss -- arrays with more than one element are kept

packJSValueName :: JSValueName -> T.Text
packJSValueName Text = T.pack "value"
packJSValueName (Attr x) = T.pack x
packJSValueName (Tag x) = T.pack x
packJSValueName :: JSValueName -> Aeson.Key
packJSValueName jsValueName = AesonKey.fromString $ case jsValueName of
Text -> "value"
Attr x -> x
Tag x -> x

wrapRoot :: Maybe (JSValueName, Aeson.Value) -> Aeson.Value
wrapRoot Nothing = Aeson.Null
Expand All @@ -119,7 +118,7 @@ tagMapToJSValue :: Bool -> M.Map JSValueName Aeson.Value -> Aeson.Value
tagMapToJSValue collapseTextRegex m = case (collapseTextRegex, M.toList m) of
(True, [(Text, val)]) -> val
_ ->
Aeson.Object . HashMap.fromList . (map . first) packJSValueName $ M.toList m
Aeson.object [(packJSValueName k, v) | (k, v) <- M.toList m]

xmlTreeToJSON :: Maybe String -> XmlTree -> Maybe (JSValueName, Aeson.Value)
xmlTreeToJSON collapseTextRegex node@(NTree (XTag qName _) children)
Expand Down
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# resolver:
# name: custom-snapshot
# location: "./custom-snapshot.yaml"
resolver: lts-6.7
resolver: lts-20.26

# User packages to be built.
# Various formats can be used as shown in the example below.
Expand Down