XQuery parser in XQuery

591 views
Skip to first unread message

John Snelson

unread,
Sep 14, 2011, 6:55:58 AM9/14/11
to carro...@googlegroups.com
The following webpage has a parser generator that can produce XQuery output:

http://www.bottlecaps.de/rex/

It also has the XQuery 1.0 and 3.0 grammars already made as examples.
That gives you an XQuery parser written in XQuery - seems to work pretty
well.

John

--
John Snelson, Senior Engineer http://twitter.com/jpcs
MarkLogic Corporation http://www.marklogic.com

Evan Lenz

unread,
Sep 22, 2011, 1:20:16 PM9/22/11
to carro...@googlegroups.com
Hi John,

I'm finally taking a look at this. Wow, what a good find! This looks like
a perfect launching point for creating a Carrot parser.

Do you know if this tool is open-source? (I guess I don't care as long as
the web page stays up.)

Evan

David Lee

unread,
Sep 22, 2011, 1:30:20 PM9/22/11
to carro...@googlegroups.com
Was thinking about this.
What is the expected language of first implementation for the "compiler"
assuming we have a parser.
If its Xquery or XSLT it makes sense. If its Java then a Java parser makes
more sense.
While the W3C parser has its advantages (being based on an XML grammar to
start with) it is highly complex in the steps required and the result is
really non-ideal, e.g. the JTree output still is Java Objects which are
tightly bound to the parse tree (not necessarily the ideal AST).
So if all we were going to do is dump those to xml say (xqueryx-carrot
schema) then load it into XSLT ...
then an Xquery parser makes good sense ... it could all run in an
Xquery/XSLT environment.
(or ideally pure Xquery !!! why pollute it with XSLT ? :) )


----------------------------------------
David A. Lee
dl...@calldei.com
http://www.xmlsh.org

Evan Lenz

unread,
Sep 22, 2011, 2:18:33 PM9/22/11
to carro...@googlegroups.com
The first one I tested out was a Java parser that it generated. It lets
you choose from C++, Java, JavaScript, XQuery, and "XML" as target parser
languages. I don't know if its Java output would be easier to work with.
You should take a look at it if you haven't already. There's nothing that
says we can't have multiple implementations, even from the start!

I personally would be inclined to compile to XSLT using XSLT, but that's
just me. I guess I like polluting things. ;-) (Mostly, I think XSLT will
be the quickest target language to implement because of its relatively
straightforward mappings to Carrot.)

I definitely like the idea of using an XQuery-based parser, because then,
as you point out, you could create a library for directly calling Carrot
modules in environments like MarkLogic.

Evan

Evan Lenz

unread,
Sep 22, 2011, 4:51:54 PM9/22/11
to carro...@googlegroups.com
I created Carrot.ebnf based on the modifications to the XQuery 1.0 grammar
I described in an earlier thread:

https://github.com/evanlenz/Carrot/commit/d840a834cd52e0be876fcc13cbf9aea13
4ca73ab


I also generated XQuery- and Java-based parsers, if anyone wants to play
around with them. Here's a script for invoking the parser in MarkLogic
Server (it works!):

https://github.com/evanlenz/Carrot/blob/master/parser/parse.xqy


Evan

David Lee

unread,
Sep 22, 2011, 6:17:19 PM9/22/11
to carro...@googlegroups.com, carro...@googlegroups.com
Definitely have to check this out
Apologize for being slow in this front ... No excuses but that day job thing is really getting In the way of me getting things done!
Someday I can retire so I can get some real work done ;)


Sent from my iPad (excuse the terseness)
David A Lee
dl...@calldei.com

Reply all
Reply to author
Forward
0 new messages