1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00
Files
stedolan-jq/Main.hs

23 lines
579 B
Haskell
Raw Permalink Normal View History

2012-07-18 20:57:59 +01:00
import Parser
import Lexer
import JQ
import Text.JSON
import Text.JSON.String
import PrettyJSON
2012-07-18 20:57:59 +01:00
import System.Environment
import Control.Monad
import System.IO
parseJS :: String -> JSValue
parseJS s = case runGetJSON readJSValue s of
Left err -> error err
Right val -> val
main = do
[program] <- getArgs
stdlib <- openFile "stdlib.jq" ReadMode >>= hGetContents
2012-07-18 20:57:59 +01:00
json <- liftM parseJS $ hGetContents stdin
case runLexer (stdlib ++ program) >>= runParser of
2012-07-18 20:57:59 +01:00
Left err -> putStrLn err
Right program -> mapM_ (putStrLn . show . renderJSON) (runJQ program json)