xquery / xquerydoc

xquerydoc - generate XQuery API documentation from your source code comments
https://github.com/xquery/xquerydoc
Other
38 stars 11 forks source link

XQuery parser hard-coded? #28

Closed jfix closed 10 years ago

jfix commented 10 years ago

I'm trying to make the pure xquery approach work for me but am encountering problems.

Basic 1.0 xquery works (but not as shown in README, I'm calling xqdoc:parse rather than xqp:parse-XQuery):

xquery version "1.0" encoding "UTF-8";

import module namespace xqdoc="http://github.com/xquery/xquerydoc" at "/xquery/xquerydoc.xq";

xqdoc:parse(doc("/application/lib/scribd-ml-connector/lib-multipart-post.xqy")) 

I get the full xqdoc result XML for the input file.

I note that in xquerydoc.xq, line 30, the MarkLogic 1.0 parser is hard-coded:

import module namespace xqp="XQueryML10" at "parsers/XQueryML10.xq";

Now I add a couple of annotations (rxq-style) to a function in the input file and run it again, the result is 'incomplete':

<doc:xqdoc xmlns:doc="http://www.xqdoc.org/1.0">
  <doc:control>
    <!--Generated by xquerydoc: http://github.com/xquery/xquerydoc-->
    <doc:date>2014-01-04T19:33:47.242949+01:00</doc:date>
    <doc:version>N/A</doc:version>
  </doc:control>
  <doc:module type="library">
    <doc:uri/>
  </doc:module>
  <doc:variables/>
  <doc:functions/>
</doc:xqdoc>

So I try to use the xqp:parse-XQuery function directly (as indicated in the readme), and also include some other library modules:

xquery version "1.0-ml" encoding "UTF-8";

import module namespace xqdoc="http://github.com/xquery/xquerydoc" at "/xquery/xquerydoc.xq";
import module namespace xqp="XQueryML10" at "/xquery/parsers/XQueryML10.xq";
(:import module namespace xqdc="XQDocComments" at "/xquery/parsers/XQDocComments.xq";
import module namespace util="http://github.com/xquery/xquerydoc/utils" at "/xquery/utils.xq";:)

xqp:parse-XQuery(doc("/application/lib/scribd-ml-connector/lib-multipart-post.xqy")) 

which returns the following error:

<ERROR b="1753" e="1760" o="85" x="24">syntax error, found 'declare'
while expecting EOF
after scanning 7 characters at line 56, column 1
...declare&#13;
    %rxq:path('/v1/admi...</ERROR>

So, clearly, it doesn't like the annotations.

Now, let's use the 3.0 parser (I've also modified line 30 in the xquerydoc.xq file):

xquery version "1.0-ml" encoding "UTF-8";

import module namespace xqdoc="http://github.com/xquery/xquerydoc" at "/xquery/xquerydoc.xq";
import module namespace xqp="XQueryV30" at "/xquery/parsers/XQueryV30.xq";
(:import module namespace xqdc="XQDocComments" at "/xquery/parsers/XQDocComments.xq";
import module namespace util="http://github.com/xquery/xquerydoc/utils" at "/xquery/utils.xq";:)

xqp:parse-XQuery(doc("/application/lib/scribd-ml-connector/lib-multipart-post.xqy")) 

This throws the following error:

<ERROR b="2889" e="2889" s="192">lexical analysis failed
while expecting [EOF, S, '!=', '#', '(', '(:', ')', '*', '+', ',', '-', '/', '//', ';', '&lt;', '&lt;&lt;', '&lt;=', '=', '&gt;', '&gt;=', '&gt;&gt;', '[', ']', 'and', 'ascending', 'case', 'cast', 'castable', 'collation', 'count', 'default', 'descending', 'div', 'else', 'empty', 'end', 'eq', 'except', 'for', 'ge', 'group', 'gt', 'idiv', 'instance', 'intersect', 'is', 'le', 'let', 'lt', 'mod', 'ne', 'only', 'or', 'order', 'return', 'satisfies', 'stable', 'start', 'to', 'treat', 'union', 'where', '|', '}']
after scanning 0 characters at line 78, column 12
...{ xs:hexBinary(concat(string(dat...</ERROR>

Changing the xquery version to 3.0 doesn't make a difference.

Thanks for letting me know how to fix this.

By the way, this is using an old ML7 nightly (that expires today) on Mac, but I doubt this is a deal breaker (will update to latest version though).

jfix commented 10 years ago

partially related to #9 and to #24 I guess.

jpcs commented 10 years ago

The ML10 parser handles XQuery 3.0 syntax with all MarkLogic extension syntax, and so is the most general parser. There's no need to change the parser library.

jpcs commented 10 years ago

Yeah, we need to work on adding annotation support to the parser. I think this is covered completely by #9 and #24, so I'm going to close this bug report.