HXQ-0.7.2: Main.hs
{--------------------------------------------------------------
-
- The main program of the XQuery interpreter
- Programmer: Leonidas Fegaras (fegaras@cse.uta.edu)
- Date: 04/22/2008
-
---------------------------------------------------------------}
{-# OPTIONS_GHC -fth #-}
module Main where
import System.Environment
import XQueryCompiler(functions)
import XQuery
main = do env <- getArgs
putStrLn "HXQ: XQuery Compiler/Interpreter version 0.7.2"
if (length env) > 0 && (head env) == "-help"
then putStrLn ("Functions: "++(foldr (\(f,_,_) r -> f++" "++r) "" functions))
else if (length env) > 1 && (head env) == "-c"
then do query <- readFile (head (tail env))
let qf = map (\c -> if c=='\"' then '\'' else c)
(foldr1 (\a r -> a++" "++r) (lines query))
let pr = "{-# OPTIONS_GHC -fth #-}\nmodule Main where\nimport XQuery\n\nmain = do res <- $(xq \""
++ qf ++ "\")\n putXSeq res\n"
writeFile "Temp.hs" pr
else if (length env) == 3 && (head env) == "-p"
then do result <- xquery ("doc('"++(head (tail (tail env)))++"')"++(head (tail env)))
putXSeq result
else do result <- if (length env) == 1
then xfile (head env)
else do let readl x = do t <- getLine
if null t then return x else readl (x++" "++t)
putStrLn "Write an XQuery (finish the query with an empty line)"
query <- readl ""
xquery query
putXSeq result