packages feed

HXQ 0.1 → 0.2

raw patch · 7 files changed

+63/−28 lines, 7 files

Files

HXQ.cabal view
@@ -1,5 +1,5 @@ Name:                HXQ-Version:             0.1+Version:             0.2 Description:         A Compiler from XQuery to Haskell Synopsis:            A Compiler from XQuery to Haskell Category:            XML@@ -16,6 +16,7 @@   XQuery.hs   XQueryParser.hs   XQueryParser.y+  Main2.hs   hxml-0.2/Arrow.hs   hxml-0.2/LLParsing.hs   hxml-0.2/XML.hs
+ Main2.hs view
@@ -0,0 +1,28 @@+{--------------------------------------------------------------+-+- The main program of the XQuery processor+- Programmer: Leonidas Fegaras (fegaras@cse.uta.edu)+- Date: 03/19/2008+-+---------------------------------------------------------------}++{-# OPTIONS_GHC -fth #-}++module Main where++import XQuery++f(x,y) = $(xe "<a>{$x,', ',$y}</a>")++main = do a <- $(xq ("<result>{                                                               "+                 ++"     for $x in doc('/home/fegaras/data/dblp.xml')//inproceedings at $i    "+                 ++"     where $x/author = 'Leonidas Fegaras'                                 "+                 ++"     orderby $x/year descending                                           "+                 ++"     return <paper>{ $i, ') ', $x/booktitle/text(),                       "+                 ++"                     ': ', $x/title/text()                                "+                 ++"            }</paper>                                                     "+                 ++"  }</result>                                                              "))+          putStrLn (show a)+          b <- $(xq "f($a/paper[10],$a/paper[8])")+          putStrLn (show b)+
Makefile view
@@ -3,7 +3,7 @@ runopt = +RTS -S -RTS  xquery: XQueryParser.hs XQuery.hs Main.hs-	ghc $(options) -i${hxml} --make Main.hs -o xquery+	ghc $(options) -i$(hxml) --make Main.hs -o xquery  XQueryParser.hs: XQueryParser.y 	happy -g -c XQueryParser.y@@ -12,8 +12,8 @@ 	./xquery $(runopt)  test:   XQueryParser.hs-	ghci -fth -i${hxml} XQuery.hs XQueryParser.hs+	ghci -fth -i$(hxml) XQuery.hs XQueryParser.hs  clean:-	/bin/rm -f *~ *.o *.hi XQueryParser.hs *.stat *.prof *.ps *.aux *.hp xquery+	/bin/rm -f *~ *.o *.hi $(hxml)/*.o $(hxml)/*.hi XQueryParser.hs *.stat *.prof *.ps *.aux *.hp xquery 
XQuery.hs view
@@ -336,15 +336,16 @@                     bc = compile body context index seqSize                 in [| [ XElem $ct $alc $bc ] |]       Ast "predicate" [condition,body]-             |  containsLast condition+             |  containsLast condition      -- blocking: use only when last() is used in condition              -> let c = compile condition                     b = compile body context index seqSize                 in [| let bl = $b-                      in foldir (\x i r -> case $(c [| [ x ] |] [| [ XInt i ] |] [| [ XInt (length bl) ] |]) of+                          len = length bl+                      in foldir (\x i r -> case $(c [| [ x ] |] [| [ XInt i ] |] [| [ XInt len ] |]) of                                              [] -> r                                              [XInt n] -> if i==n then x:r else r    -- indexing                                              _ -> x:r) [] bl 1 |]-      Ast "predicate" [condition,body]+      Ast "predicate" [condition,body]      -- non-blocking              -> let c = compile condition                     b = compile body context index seqSize                 in [| foldir (\x i r -> case $(c [| [ x ] |] [| [ XInt i ] |] seqSize) of@@ -355,14 +356,14 @@              -> do s <- compile source context index seqSize                    b <- compile body context index seqSize                    return (AppE (LamE [VarP (mkName var)] b) s)-      Ast "for" [Avar var,Avar "$",source,body]-             -> let b = compile body [| $(varE (mkName var)) |] [| [] |] [| [ XInt 0 ] |]+      Ast "for" [Avar var,Avar "$",source,body]      -- a for-loop without an index+             -> let b = compile body [| $(varE (mkName var)) |] [| [] |] [| [] |]                     f = lamE [varP (mkName var)] [| \x -> $b ++ x |]                     s = compile source context index seqSize                 in [| foldr (\x -> $f [x]) [] $s |]-      Ast "for" [Avar var,Avar ivar,source,body]+      Ast "for" [Avar var,Avar ivar,source,body]     -- a for-loop with an index              -> let b = compile body [| $(varE (mkName var)) |]-                                     [| $(varE (mkName ivar)) |] [| [ XInt 0 ] |]+                                     [| $(varE (mkName ivar)) |] [| [] |]                     f = lamE [varP (mkName var)] (lamE [varP (mkName ivar)] [| \x -> $b ++ x |])                     s = compile source context index seqSize                 in [| foldir (\x i -> $f [x] [XInt i]) [] $s 1 |]@@ -403,7 +404,7 @@ compileQuery :: Ast -> Q Exp -> Q Exp compileQuery query context    = let (ast,_,ns) = getDocs query 0-         code = compile (optimize ast) context [| [] |] [| [ XInt 0 ] |]+         code = compile (optimize ast) context [| [] |] [| [] |]      in foldr (\(n,file) r -> let d = lamE [varP (mkName ("_doc"++(show n)))] r                               in [| do doc <- readFile $(litE (StringL file))                                        let x = materialize (parseDocument doc)@@ -428,7 +429,7 @@ -- Run an XQuery expression that does not read XML documents -- When evaluated, it returns XSeq xe :: String -> Q Exp-xe query = compile (optimize (parse (scan query))) [| [] |] [| [] |] [| [ XInt 0 ] |]+xe query = compile (optimize (parse (scan query))) [| [] |] [| [] |] [| [] |]   -- Run an XQuery that reads XML documents
XQueryParser.hs view
@@ -1437,7 +1437,6 @@ action_85 (55#) = happyShift action_76 action_85 x = happyTcHack x happyReduce_23 -action_86 (40#) = happyShift action_61 action_86 (41#) = happyShift action_62 action_86 (42#) = happyShift action_63 action_86 (43#) = happyShift action_64@@ -1446,7 +1445,6 @@ action_86 (46#) = happyShift action_67 action_86 x = happyTcHack x happyReduce_22 -action_87 (40#) = happyShift action_61 action_87 (41#) = happyShift action_62 action_87 (42#) = happyShift action_63 action_87 (43#) = happyShift action_64@@ -1455,7 +1453,6 @@ action_87 (46#) = happyShift action_67 action_87 x = happyTcHack x happyReduce_21 -action_88 (40#) = happyShift action_61 action_88 (41#) = happyShift action_62 action_88 (42#) = happyShift action_63 action_88 (43#) = happyShift action_64@@ -1464,7 +1461,6 @@ action_88 (46#) = happyShift action_67 action_88 x = happyTcHack x happyReduce_20 -action_89 (40#) = happyShift action_61 action_89 (41#) = happyShift action_62 action_89 (42#) = happyShift action_63 action_89 (43#) = happyShift action_64@@ -1473,7 +1469,6 @@ action_89 (46#) = happyShift action_67 action_89 x = happyTcHack x happyReduce_19 -action_90 (40#) = happyShift action_61 action_90 (41#) = happyShift action_62 action_90 (42#) = happyShift action_63 action_90 (43#) = happyShift action_64@@ -1482,7 +1477,6 @@ action_90 (46#) = happyShift action_67 action_90 x = happyTcHack x happyReduce_18 -action_91 (40#) = happyShift action_61 action_91 (41#) = happyShift action_62 action_91 (42#) = happyShift action_63 action_91 (43#) = happyShift action_64@@ -1491,32 +1485,38 @@ action_91 (46#) = happyShift action_67 action_91 x = happyTcHack x happyReduce_17 -action_92 (40#) = happyShift action_61 action_92 x = happyTcHack x happyReduce_16 -action_93 (40#) = happyShift action_61 action_93 x = happyTcHack x happyReduce_15 -action_94 (40#) = happyShift action_61 action_94 x = happyTcHack x happyReduce_14 -action_95 (40#) = happyShift action_61 action_95 x = happyTcHack x happyReduce_13 -action_96 (40#) = happyShift action_61 action_96 (43#) = happyShift action_64 action_96 (44#) = happyShift action_65 action_96 (45#) = happyShift action_66 action_96 (46#) = happyShift action_67 action_96 x = happyTcHack x happyReduce_12 -action_97 (40#) = happyShift action_61 action_97 (43#) = happyShift action_64 action_97 (44#) = happyShift action_65 action_97 (45#) = happyShift action_66 action_97 (46#) = happyShift action_67 action_97 x = happyTcHack x happyReduce_11 +action_98 (41#) = happyShift action_62+action_98 (42#) = happyShift action_63+action_98 (43#) = happyShift action_64+action_98 (44#) = happyShift action_65+action_98 (45#) = happyShift action_66+action_98 (46#) = happyShift action_67+action_98 (47#) = happyShift action_68+action_98 (48#) = happyShift action_69+action_98 (49#) = happyShift action_70+action_98 (50#) = happyShift action_71+action_98 (51#) = happyShift action_72+action_98 (52#) = happyShift action_73 action_98 x = happyTcHack x happyReduce_10  action_99 (40#) = happyShift action_61
XQueryParser.y view
@@ -89,10 +89,10 @@ %right		'or' %right		'and' %nonassoc	'not'+%left		'to' %left		'=' '<' '>' '<=' '>=' '!=' %left		'+' '-' %left		'*' 'div' 'idiv' 'mod'-%left		'to' %nonassoc	UMINUS  
index.html view
@@ -22,6 +22,11 @@ My high-performance Java implementation of XQuery, called <a href="/XQPull/">XQPull</a>, which is stream-based (based on a StAX events), took about the same time. <p>+HXQ uses the <a href="http://www.flightlab.com/~joe/hxml/">HXML parser for XML</a> (developed by Joe English),+which is included in the source.+I have also tried hexpat, but I found it too slow for large documents (too many space leaks).+I haven't tried HaXML.+<p> <h2>Installation Instructions</h2> <p> If you haven't done so, install the Glasgow Haskell Compiler,@@ -32,7 +37,7 @@ <pre> yum install ghc happy </pre>-Then download <a href="/HXQ-0.1.tar.gz">HXQ</a> and untar it.+Then download <a href="/HXQ-0.2.tar.gz">HXQ</a> and untar it. You can either use cabal or make to build it. Then run xquery to test drive it. <p> <h2>Current Status</h2>@@ -102,4 +107,4 @@ <p> <hr> <p>-<address>Last modified: 03/18/08 by <a href="http://lambda.uta.edu/">Leonidas Fegaras</a></address>+<address>Last modified: 03/21/08 by <a href="http://lambda.uta.edu/">Leonidas Fegaras</a></address>