Added virgil2json utility
Getty Ritter
8 years ago
27 | 27 |
vector,
|
28 | 28 |
pretty
|
29 | 29 |
build-tools: alex
|
30 | |
default-language: Haskell2010⏎
|
| 30 |
default-language: Haskell2010
|
| 31 |
|
| 32 |
executable virgil2json
|
| 33 |
hs-source-dirs: virgil2json
|
| 34 |
main-is: Main.hs
|
| 35 |
build-depends: base >=4.7 && <4.9,
|
| 36 |
aeson,
|
| 37 |
virgil,
|
| 38 |
bytestring
|
| 1 |
module Main where
|
| 2 |
|
| 3 |
import Data.ByteString.Lazy as B
|
| 4 |
import Data.Aeson (Value(..), Result(..), encode)
|
| 5 |
import Language.Virgil (eitherDecode)
|
| 6 |
import System.Environment (getArgs)
|
| 7 |
import System.Exit (die)
|
| 8 |
|
| 9 |
usage :: String
|
| 10 |
usage = "USAGE: virgil2json [source file]"
|
| 11 |
|
| 12 |
main :: IO ()
|
| 13 |
main = do
|
| 14 |
args <- getArgs
|
| 15 |
inp <- case args of
|
| 16 |
[] -> B.getContents
|
| 17 |
["-"] -> B.getContents
|
| 18 |
["--help"] -> die usage
|
| 19 |
[f] -> B.readFile f
|
| 20 |
_ -> die usage
|
| 21 |
case eitherDecode inp of
|
| 22 |
Error err -> die err
|
| 23 |
Success val -> B.putStrLn (encode (val ::Value))
|