GLM 0.5.0.0 → 0.7.0.0
raw patch · 3 files changed
+49/−3 lines, 3 files
Files
- GLM.cabal +3/−3
- README.md +3/−0
- src/GLM/JSON.hs +43/−0
GLM.cabal view
@@ -1,5 +1,5 @@ name: GLM-version: 0.5.0.0+version: 0.7.0.0 synopsis: Simple Gridlab-D GLM parser and utilities. description: Simple Gridlab-D GLM parser and utilities. category: Language@@ -19,9 +19,9 @@ Library default-language: Haskell2010 Hs-source-dirs: src- Exposed-modules: GLM.Dot, GLM.Nesting, GLM.Parser, GLM.Tokenizer+ Exposed-modules: GLM.Dot, GLM.Nesting, GLM.Parser, GLM.Tokenizer, GLM.JSON build-depends: base <= 5, parsec, interpolate, bytestring, pureMD5, transformers, lens, mtl,- test-framework, test-framework-quickcheck2, QuickCheck, test-framework-th+ test-framework, test-framework-quickcheck2, QuickCheck, test-framework-th, aeson executable glm2props default-language: Haskell2010
README.md view
@@ -39,6 +39,9 @@ ## glmprops +# Links++Hackage: <https://hackage.haskell.org/package/GLM> Downloads:
+ src/GLM/JSON.hs view
@@ -0,0 +1,43 @@++{-# LANGUAGE OverloadedStrings #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}++module GLM.JSON where++import Data.Aeson+import Data.String+import Control.Lens+import Control.Arrow+import GLM.Parser+import System.Environment+import System.Exit+import System.IO+import qualified Data.ByteString.Lazy.Char8 as B++instance ToJSON Entry where+ toJSON (Entry a b) = object [ ("path" , fromString (unwords a))+ , ("selector" , toJSON a )+ , ("nested" , toJSON nests)+ , ("properties", object $ over each (fromString *** fromString) props)]+ where+ props :: [(String, String)]+ props = b ^.. each . _Prop+ nests = b ^.. each . _Nested++main :: IO ()+main = do+ a <- getArgs+ case a of [] -> getContents >>= go "STDIN"+ xs -> mapM_ doF xs++doF :: FilePath -> IO ()+doF f = readFile f >>= go f++go :: String -> String -> IO ()+go f c =+ case glmParser f c of+ Left err -> oops err+ Right res -> B.putStrLn $ encode $ res++oops :: Show a => a -> IO b+oops err = hPutStrLn stderr (show err) >> exitFailure