blob: 9e399d4cc9af0e05432de8229cee55dcb11e39cc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
import Parser
import Lexer
import JQ
import Text.JSON
import Text.JSON.String
import PrettyJSON
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
json <- liftM parseJS $ hGetContents stdin
case runLexer (stdlib ++ program) >>= runParser of
Left err -> putStrLn err
Right program -> mapM_ (putStrLn . show . renderJSON) (runJQ program json)
|