Skip to content
This repository
Browse code

Switched to using the xqueryparser.xq parser.

  • Loading branch information...
commit 8179b89a738ac880e418f575cfe80872a89fd98a 1 parent 670c118
John Snelson jpcs authored
3  README.md
Source Rendered
@@ -186,6 +186,9 @@ Thanks to [Darin McBeath](http://xqdoc.org/history.html) for creating
186 186 the original xqDoc, which xquerydoc borrows heavily. xqDoc is released under the
187 187 Apache License, Version 2.0
188 188
  189 +The [XQuery parser](https://github.com/jpcs/xqueryparser.xq) itself is now a
  190 +separate library under Apache License, Version 2.
  191 +
189 192 XQuery parsers were generated from EBNF using Gunther Rademacher's
190 193 excellent http://www.bottlecaps.de/rex/
191 194
4 src/lib/html-module.xsl
@@ -131,8 +131,8 @@ version="2.0">
131 131 <xsl:template match="doc:variable[@private]"/>
132 132
133 133 <xsl:template match="doc:variable">
134   - <div id="{ concat('var_', replace(doc:uri, ':', '_')) }">
135   - <h4><pre class="prettyprint lang-xq"><u>Variable</u>:&#160;$<xsl:value-of select="doc:uri"/> as <xsl:value-of select="doc:type"/><xsl:value-of select="doc:type/@occurrence"/></pre></h4>
  134 + <div id="{ concat('var_', replace(doc:name, ':', '_')) }">
  135 + <h4><pre class="prettyprint lang-xq"><u>Variable</u>:&#160;$<xsl:value-of select="doc:name"/> as <xsl:value-of select="doc:type"/><xsl:value-of select="doc:type/@occurrence"/></pre></h4>
136 136 <xsl:apply-templates select="doc:comment"/>
137 137 </div>
138 138 </xsl:template>
6 src/lib/markdown-module.xsl
@@ -63,10 +63,10 @@ version="2.0">
63 63
64 64 <xsl:template match="doc:variable">
65 65 <xsl:text>
66   -### &lt;a name="</xsl:text><xsl:sequence select="concat('var_', replace(doc:uri, ':', '_'))"/><xsl:text>"/&gt; $</xsl:text><xsl:value-of select="doc:uri"/><xsl:text>
  66 +### &lt;a name="</xsl:text><xsl:sequence select="concat('var_', replace(doc:name, ':', '_'))"/><xsl:text>"/&gt; $</xsl:text><xsl:value-of select="doc:name"/><xsl:text>
67 67 </xsl:text>
68 68 <xsl:text>```xquery
69   -$</xsl:text><xsl:value-of select="doc:uri"/><xsl:text> as </xsl:text><xsl:value-of select="doc:escape(doc:type)"/><xsl:value-of select="doc:escape(doc:type/@occurrence)"/><xsl:text>
  69 +$</xsl:text><xsl:value-of select="doc:name"/><xsl:text> as </xsl:text><xsl:value-of select="doc:escape(doc:type)"/><xsl:value-of select="doc:escape(doc:type/@occurrence)"/><xsl:text>
70 70 ```
71 71 </xsl:text>
72 72 <xsl:apply-templates select="doc:comment"/>
@@ -262,7 +262,7 @@ Version: </xsl:text><xsl:value-of select="doc:escape(.)"/>
262 262 * Variables: </xsl:text>
263 263 <xsl:for-each select="doc:variable[not(@private)]">
264 264 <xsl:if test="position() ne 1"><xsl:text>, </xsl:text></xsl:if>
265   - <xsl:text>[$</xsl:text><xsl:value-of select="doc:uri"/><xsl:text>](#</xsl:text><xsl:sequence select="concat('var_', replace(doc:uri, ':', '_'))"/><xsl:text>)</xsl:text>
  265 + <xsl:text>[$</xsl:text><xsl:value-of select="doc:name"/><xsl:text>](#</xsl:text><xsl:sequence select="concat('var_', replace(doc:name, ':', '_'))"/><xsl:text>)</xsl:text>
266 266 </xsl:for-each>
267 267 </xsl:template>
268 268
2  src/xquery/parsers/XQueryML30.xq
@@ -1882,7 +1882,7 @@ declare function p:transition($input as xs:string,
1882 1882 $end as xs:integer,
1883 1883 $result as xs:integer,
1884 1884 $current-state as xs:integer,
1885   - $previous-state as xs:integer) as xs:integer+
  1885 + $previous-state as xs:integer)
1886 1886 {
1887 1887 if ($current-state = 0) then
1888 1888 let $result := $result idiv 2048
381 src/xquery/parsers/xqueryparser.xq
... ... @@ -0,0 +1,381 @@
  1 +xquery version "1.0";
  2 +
  3 +(:
  4 + : Licensed under the Apache License, Version 2.0 (the "License");
  5 + : you may not use this file except in compliance with the License.
  6 + : You may obtain a copy of the License at
  7 + :
  8 + : http://www.apache.org/licenses/LICENSE-2.0
  9 + :
  10 + : Unless required by applicable law or agreed to in writing, software
  11 + : distributed under the License is distributed on an "AS IS" BASIS,
  12 + : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + : See the License for the specific language governing permissions and
  14 + : limitations under the License.
  15 + :)
  16 +
  17 +(:~
  18 + : <h1>xqueryparser.xq</h1>
  19 + : <p>An parser for XQuery 3.0 and MarkLogic extensions.</p>
  20 + :
  21 + : @author John Snelson
  22 + : @since Feb 17, 2012
  23 + : @version 0.1
  24 + :)
  25 +module namespace xqp="http://github.com/jpcs/xqueryparser.xq";
  26 +declare default function namespace "http://github.com/jpcs/xqueryparser.xq";
  27 +
  28 +import module namespace p="XQueryML30" at "XQueryML30.xq";
  29 +
  30 +(:~
  31 + : Parses the XQuery module in the string argument. The module string
  32 + : is returned marked up in elements, with attributes adding statically
  33 + : analysed values like unescaped string values, and lexical QNames
  34 + : resolved to expanded QNames.
  35 + :
  36 + : @param $module: XQuery module passed as a string
  37 + :
  38 + : @return A marked up copy of the XQuery module, or an error element
  39 + : detailing the parse error encountered.
  40 + :)
  41 +declare function parse($module as xs:string) as element()
  42 +{
  43 + let $markup := p:parse-XQuery($module)
  44 + let $markup := _simplify($markup)
  45 + (: let $markup := _combine($markup,()) :) (: Causes stack overflow - jpcs :)
  46 + let $ns := _build_namespaces($markup)
  47 + let $markup := _analyze($markup,$ns)
  48 + return $markup
  49 +};
  50 +
  51 +(:~ Simplify the markup to remove unneeded elements :)
  52 +declare (: private :) function _simplify($nodes)
  53 +{
  54 + for $n in $nodes
  55 + return typeswitch($n)
  56 + case element() return
  57 + typeswitch($n)
  58 + case element(EOF) return ()
  59 + case element(MainModuleSequence) return _process_skip($n)
  60 + case element(Setter) return _process_skip($n)
  61 + case element(Import) return _process_skip($n)
  62 + case element(QueryBody) return _process_skip($n)
  63 + case element(Expr) return _process_skip($n)
  64 + case element(ExprSingle) return _process_skip($n)
  65 + case element(EnclosedExprExtended) return _process_skip($n)
  66 + case element(InitialClause) return _process_skip($n)
  67 + case element(IntermediateClause) return _process_skip($n)
  68 + case element(OrExpr) return _process_skip($n)
  69 + case element(AndExpr) return _process_skip($n)
  70 + case element(ComparisonExpr) return _process_skip($n)
  71 + case element(StringConcatExpr) return _process_skip($n)
  72 + case element(RangeExpr) return _process_skip($n)
  73 + case element(AdditiveExpr) return _process_skip($n)
  74 + case element(MultiplicativeExpr) return _process_skip($n)
  75 + case element(UnionExpr) return _process_skip($n)
  76 + case element(IntersectExceptExpr) return _process_skip($n)
  77 + case element(InstanceofExpr) return _process_skip($n)
  78 + case element(TreatExpr) return _process_skip($n)
  79 + case element(CastableExpr) return _process_skip($n)
  80 + case element(CastExpr) return _process_skip($n)
  81 + case element(UnaryExpr) return _process_skip($n)
  82 + case element(ValueExpr) return _process_skip($n)
  83 + case element(PathExpr) return _process_skip($n)
  84 + case element(RelativePathExpr) return _process_skip($n)
  85 + case element(StepExpr) return _process_skip($n)
  86 + case element(NodeTest) return _process_skip($n)
  87 + case element(PostfixExpr) return _process_skip($n)
  88 + case element(PredicateList) return _process_skip($n)
  89 + case element(PrimaryExpr) return _process_skip($n)
  90 + case element(Literal) return _process_skip($n)
  91 + case element(NumericLiteral) return _process_skip($n)
  92 + case element(Argument) return _process_skip($n)
  93 + case element(Constructor) return _process_skip($n)
  94 + case element(DirectConstructor) return _process_skip($n)
  95 + case element(QuotAttrValueContent) return _process_skip($n)
  96 + case element(AposAttrValueContent) return _process_skip($n)
  97 + case element(DirElemContent) return _process_skip($n)
  98 + case element(CommonContent) return _process_skip($n)
  99 + case element(ComputedConstructor) return _process_skip($n)
  100 + case element(ItemType) return _process_skip($n)
  101 + case element(KindTest) return _process_skip($n)
  102 +
  103 + case element(EQName) return _process_skip($n)
  104 + case element(FunctionName) return _process_skip($n)
  105 +
  106 + case element(PredefinedEntityRef) return
  107 + element { fn:node-name($n) } {
  108 + attribute value { _unescape_helper($n,"") },
  109 + $n/node()
  110 + }
  111 + case element(CharRef) return
  112 + element { fn:node-name($n) } {
  113 + attribute value { _unescape_helper($n,"") },
  114 + $n/node()
  115 + }
  116 + case element(StringLiteral) return
  117 + element { fn:node-name($n) } {
  118 + attribute value { _unescape_string($n) },
  119 + $n/node()
  120 + }
  121 + case element(URILiteral) return
  122 + element { fn:node-name($n) } {
  123 + attribute value { fn:normalize-space(_unescape_string($n)) },
  124 + $n/node()
  125 + }
  126 +
  127 + default return _process_copy($n)
  128 + default return $n
  129 +};
  130 +
  131 +declare (: private :) function _process_skip($n)
  132 +{
  133 + if(fn:empty($n/*[2])) then _simplify($n/*)
  134 + else _process_copy($n)
  135 +};
  136 +
  137 +declare (: private :) function _process_copy($n)
  138 +{
  139 + element { fn:node-name($n) } {
  140 + $n/@*,
  141 + _simplify($n/node())
  142 + }
  143 +};
  144 +
  145 +(:~ Combine QuotAttrContentChar, AposAttrContentChar, and ElementContentChar into usable values :)
  146 +declare (: private :) function _combine($node, $group)
  147 +{
  148 + typeswitch($node)
  149 + case element() return typeswitch($node)
  150 + case element(QuotAttrContentChar) return
  151 + _combine($node/following-sibling::node()[1],($group,$node))
  152 + case element(AposAttrContentChar) return
  153 + _combine($node/following-sibling::node()[1],($group,$node))
  154 + case element(ElementContentChar) return
  155 + _combine($node/following-sibling::node()[1],($group,$node))
  156 + default return (
  157 + _combine_group($group),
  158 + element { fn:node-name($node) } {
  159 + $node/@*,
  160 + _combine($node/node()[1],())
  161 + },
  162 + _combine($node/following-sibling::node()[1],())
  163 + )
  164 + case node() return (
  165 + _combine_group($group),
  166 + $node,
  167 + _combine($node/following-sibling::node()[1],())
  168 + )
  169 + default return
  170 + _combine_group($group)
  171 +};
  172 +
  173 +declare (: private :) function _combine_group($group)
  174 +{
  175 + typeswitch($group)
  176 + case element()+ return element Content { for $g in $group return $g/text() }
  177 + default return $group
  178 +};
  179 +
  180 +(:~ Build the namespace map :)
  181 +declare (: private :) function _build_namespaces($n)
  182 +{
  183 + let $marklogic := fn:contains($n/Module/VersionDecl/StringLiteral[1],"-ml")
  184 + let $ns := (
  185 + (: Pre-declared bindings :)
  186 + <ns prefix="xml" uri="http://www.w3.org/XML/1998/namespace"/>,
  187 + <ns prefix="xs" uri="http://www.w3.org/2001/XMLSchema"/>,
  188 + <ns prefix="xsi" uri="http://www.w3.org/2001/XMLSchema-instance"/>,
  189 + <ns prefix="fn" uri="http://www.w3.org/2005/xpath-functions"/>,
  190 + <ns prefix="local" uri="http://www.w3.org/2005/xquery-local-functions"/>,
  191 + if($marklogic) then (
  192 + <ns prefix="err" uri="http://www.w3.org/2005/xqt-errors"/>,
  193 + <ns prefix="xdmp" uri="http://marklogic.com/xdmp"/>,
  194 + <ns prefix="cts" uri="http://marklogic.com/cts"/>,
  195 + <ns prefix="sec" uri="http://marklogic.com/xdmp/security"/>,
  196 + <ns prefix="error" uri="http://marklogic.com/xdmp/error"/>,
  197 + <ns prefix="dir" uri="http://marklogic.com/xdmp/directory"/>,
  198 + <ns prefix="dav" uri="DAV:"/>,
  199 + <ns prefix="lock" uri="http://marklogic.com/xdmp/lock"/>,
  200 + <ns prefix="prop" uri="http://marklogic.com/xdmp/property"/>,
  201 + <ns prefix="spell" uri="http://marklogic.com/xdmp/spell"/>,
  202 + <ns prefix="math" uri="http://marklogic.com/xdmp/math"/>,
  203 + <ns prefix="dbg" uri="http://marklogic.com/xdmp/debug"/>,
  204 + <ns prefix="prof" uri="http://marklogic.com/xdmp/profile"/>,
  205 + <ns prefix="map" uri="http://marklogic.com/xdmp/map"/>
  206 + ) else ()
  207 + )
  208 + let $ns := (
  209 + for $d in $n/Module/LibraryModule/ModuleDecl
  210 + return (<ns prefix="{ $d/NCName/NCName }"
  211 + uri="{ $d/URILiteral/@value }"/>,
  212 + if($marklogic) then <function uri="{ $d/URILiteral/@value }"/> else ()),
  213 + $ns
  214 + )
  215 + let $ns := (
  216 + for $d in $n/Module/LibraryModule/Prolog/NamespaceDecl
  217 + return <ns prefix="{ $d/NCName/NCName }"
  218 + uri="{ $d/URILiteral/@value }"/>,
  219 + $ns
  220 + )
  221 + let $ns := (
  222 + for $d in $n/Module/LibraryModule/Prolog/SchemaImport[SchemaPrefix]
  223 + return
  224 + if($d/SchemaPrefix/NCName) then
  225 + <ns prefix="{ $d/SchemaPrefix/NCName/NCName }"
  226 + uri="{ $d/URILiteral[1]/@value }"/>
  227 + else <element uri="{ $d/URILiteral[1]/@value }"/>,
  228 + $ns
  229 + )
  230 + let $ns := (
  231 + for $d in $n/Module/LibraryModule/Prolog/ModuleImport[NCName]
  232 + return <ns prefix="{ $d/NCName/NCName }"
  233 + uri="{ $d/URILiteral[1]/@value }"/>,
  234 + $ns
  235 + )
  236 + let $ns := (
  237 + for $d in $n/Module/LibraryModule/Prolog/DefaultNamespaceDecl
  238 + return
  239 + if($d/TOKEN[3] eq "function") then
  240 + <function uri="{ $d/URILiteral/@value }"/>
  241 + else <element uri="{ $d/URILiteral/@value }"/>,
  242 + $ns
  243 + )
  244 + return $ns
  245 +};
  246 +
  247 +declare (: private :) function _unescape_string($s as xs:string)
  248 +{
  249 + let $quot := fn:substring($s,1,1)
  250 + let $s := fn:substring($s,2,fn:string-length($s) - 2)
  251 + return fn:string-join(_unescape_helper($s,$quot),"")
  252 +};
  253 +
  254 +declare (: private :) function _unescape_helper(
  255 + $s as xs:string,
  256 + $quot as xs:string
  257 +)
  258 +{
  259 + if(fn:string-length($s) = 0) then (
  260 + (: Do nothing :)
  261 + ) else if($quot != "" and fn:starts-with($s,$quot)) then (
  262 + fn:substring($s,2,1),
  263 + _unescape_helper(fn:substring($s,3),$quot)
  264 + ) else if(fn:starts-with($s,"&amp;lt;")) then (
  265 + "&lt;",
  266 + _unescape_helper(fn:substring($s,5),$quot)
  267 + ) else if(fn:starts-with($s,"&amp;gt;")) then (
  268 + "&gt;",
  269 + _unescape_helper(fn:substring($s,5),$quot)
  270 + ) else if(fn:starts-with($s,"&amp;amp;")) then (
  271 + "&amp;",
  272 + _unescape_helper(fn:substring($s,6),$quot)
  273 + ) else if(fn:starts-with($s,"&amp;apos;")) then (
  274 + "&apos;",
  275 + _unescape_helper(fn:substring($s,7),$quot)
  276 + ) else if(fn:starts-with($s,"&amp;quot;")) then (
  277 + "&quot;",
  278 + _unescape_helper(fn:substring($s,7),$quot)
  279 + ) else if(fn:starts-with($s,"&amp;#x")) then (
  280 + fn:codepoints-to-string(_decodeHexString(fn:substring-before(fn:substring($s,4), ";"))),
  281 + _unescape_helper(fn:substring-after($s,";"),$quot)
  282 + ) else if(fn:starts-with($s,"&amp;#")) then (
  283 + fn:codepoints-to-string(xs:integer(fn:substring-before(fn:substring($s,3), ";"))),
  284 + _unescape_helper(fn:substring-after($s,";"),$quot)
  285 + ) else (
  286 + fn:substring($s,1,1),
  287 + _unescape_helper(fn:substring($s,2),$quot)
  288 + )
  289 +};
  290 +
  291 +declare (:private:) function _decodeHexChar($val as xs:integer)
  292 + as xs:integer
  293 +{
  294 + let $tmp := $val - 48 (: '0' :)
  295 + let $tmp := if($tmp <= 9) then $tmp else $tmp - (65-48-10) (: 'A'-'0'-10 :)
  296 + let $tmp := if($tmp <= 15) then $tmp else $tmp - (97-65) (: 'a'-'A' :)
  297 + return $tmp
  298 +};
  299 +
  300 +declare (:private:) function _decodeHexStringHelper($chars as xs:integer*, $acc as xs:integer)
  301 + as xs:integer
  302 +{
  303 + if(fn:empty($chars)) then $acc
  304 + else _decodeHexStringHelper(fn:remove($chars,1), ($acc * 16) + _decodeHexChar($chars[1]))
  305 +};
  306 +
  307 +declare (:private:) function _decodeHexString($val as xs:string)
  308 + as xs:integer
  309 +{
  310 + _decodeHexStringHelper(fn:string-to-codepoints($val), 0)
  311 +};
  312 +
  313 +(:~ Perform namespace analysis and QName resolution :)
  314 +declare (: private :) function _analyze($nodes, $ns)
  315 +{
  316 + for $n in $nodes
  317 + return typeswitch($n)
  318 + case element() return typeswitch($n)
  319 + case element(QName) return
  320 + element { fn:node-name($n) } {
  321 + $n/@*, _resolve_qname($n,$ns), $n//text()
  322 + }
  323 + case element(FunctionQName) return
  324 + element { fn:node-name($n) } {
  325 + $n/@*, _resolve_qname($n,$ns), $n//text()
  326 + }
  327 + case element(URIQualifiedName) return
  328 + element { fn:node-name($n) } {
  329 + $n/@*,
  330 + let $parts := fn:tokenize($n,":")
  331 + let $localname := $parts[fn:last()]
  332 + let $uri := _unescape_string(fn:string-join($parts[fn:position() < fn:last()],":"))
  333 + return (
  334 + attribute prefix { "" },
  335 + attribute uri { $uri },
  336 + attribute localname { $localname }
  337 + ),
  338 + $n//text()
  339 + }
  340 + (: TBD DirAttributeList namespace attrs - jpcs :)
  341 + default return
  342 + element { fn:node-name($n) } {
  343 + $n/@*,
  344 + _analyze($n/node(),$ns)
  345 + }
  346 + default return $n
  347 +};
  348 +
  349 +declare (: private :) function _resolve_qname($n, $ns)
  350 +{
  351 + let $qname := fn:string($n//(QName|TOKEN))
  352 + let $prefix := fn:substring-before($qname,":")
  353 + let $localname := fn:substring-after($qname,":")
  354 + let $localname := if($localname="") then $qname else $localname
  355 + let $uri :=
  356 + if($prefix != "") then fn:string($ns[@prefix=$prefix][1]/@uri)
  357 + else if($n/(parent::FunctionCall|
  358 + parent::Annotation|
  359 + parent::FunctionDecl|
  360 + parent::LiteralFunctionItem))
  361 + then fn:string(($ns/self::function)[1]/@uri)
  362 + else if($n/(parent::DirElemConstructor|
  363 + parent::CompElemConstructor|
  364 + parent::AtomicOrUnionType|
  365 + parent::ElementName|
  366 + parent::TypeName))
  367 + then fn:string(($ns/self::element)[1]/@uri)
  368 + else if($n/(parent::OptionDecl))
  369 + then "http://www.w3.org/2011/xquery-options"
  370 + else if($n/(parent::NameTest) and fn:not(
  371 + $n/../preceding-sibling::TOKEN = "@" or
  372 + $n/../preceding-sibling::ForwardAxis/TOKEN = "attribute"
  373 + ))
  374 + then fn:string(($ns/self::element)[1]/@uri)
  375 + else ""
  376 + return (
  377 + attribute prefix { $prefix },
  378 + attribute uri { $uri },
  379 + attribute localname { $localname }
  380 + )
  381 +};
44 src/xquery/xquerydoc.xq
@@ -23,7 +23,7 @@ xquery version "1.0" encoding "UTF-8";
23 23 :
24 24 : xquery version "1.0" encoding "UTF-8";
25 25 :
26   - : import module namespace xqdoc="http://github.com/xquery/xquerydoc" at "/xquery/xque rydoc.xq";
  26 + : import module namespace xqdoc="http://github.com/xquery/xquerydoc" at "/xquery/xquerydoc.xq";
27 27 :
28 28 : xqp:parse-XQuery(fn:collection('/some/xquery/?select=file.xqy;unparsed=yes'))
29 29 :
@@ -39,22 +39,15 @@ module namespace xqd="http://github.com/xquery/xquerydoc";
39 39 declare default function namespace "http://github.com/xquery/xquerydoc";
40 40 declare namespace doc="http://www.xqdoc.org/1.0";
41 41
42   -import module namespace xqp="XQueryML30" at "parsers/XQueryML30.xq";
  42 +import module namespace xqp="http://github.com/jpcs/xqueryparser.xq" at "parsers/xqueryparser.xq";
43 43 import module namespace xqdc="XQDocComments" at "parsers/XQDocComments.xq";
44 44 import module namespace util="http://github.com/xquery/xquerydoc/utils" at "utils.xq";
45 45
46   -(:~
47   - : private function trimming string literals
48   - :)
49   -declare (: private :) function _trimStringLiteral($literal as xs:string) as xs:string
50   -{
51   - fn:substring($literal, 2, fn:string-length($literal) - 2)
52   -};
53   -
54   -declare (: private :) function _localname($qname as xs:string) as xs:string
  46 +declare (: private :) function _name($qname as element())
55 47 {
56   - let $localname := fn:substring-after($qname, ":")
57   - return if($localname = "") then $qname else $localname
  48 + element doc:name {
  49 + $qname/@*, fn:normalize-space($qname)
  50 + }
58 51 };
59 52
60 53 declare (: private :) function _type($t as element(SequenceType)?)
@@ -63,10 +56,17 @@ declare (: private :) function _type($t as element(SequenceType)?)
63 56 element doc:type {
64 57 if($t/OccurrenceIndicator) then
65 58 attribute occurrence { $t/OccurrenceIndicator/TOKEN/fn:string() } else (),
66   - if($t/ItemType) then $t/ItemType/fn:string() else $t/fn:string()
  59 + $t/(node() except OccurrenceIndicator)/descendant-or-self::text()
67 60 }
68 61 };
69 62
  63 +declare (: private :) function _private($annotations as element()*)
  64 +{
  65 + let $names := $annotations/(URIQualifiedName|QName)
  66 + where $names[@uri = "http://www.w3.org/2005/xpath-functions"][@localname = "private"]
  67 + return attribute private { "true" }
  68 +};
  69 +
70 70 declare (: private :) function _commentContents($e)
71 71 {
72 72 typeswitch($e)
@@ -128,7 +128,7 @@ declare function parse($module as xs:string) as element(doc:xqdoc)
128 128 :)
129 129 declare function parse($module as xs:string, $mode as xs:string) as element(doc:xqdoc)
130 130 {
131   - let $markup := xqp:parse-XQuery($module)
  131 + let $markup := xqp:parse($module)
132 132 let $module := $markup/Module/(MainModuleSequence/MainModule | LibraryModule)
133 133 return element doc:xqdoc {
134 134
@@ -140,7 +140,7 @@ declare function parse($module as xs:string, $mode as xs:string) as element(doc:
140 140
141 141 element doc:module {
142 142 attribute type { if($module/self::MainModule) then "main" else "library" },
143   - element doc:uri { if($module/ModuleDecl/URILiteral) then _trimStringLiteral($module/ModuleDecl/URILiteral) else () },
  143 + element doc:uri { $module/ModuleDecl/URILiteral/@value/fn:string() },
144 144 if($module/(ModuleDecl | self::MainModule/Prolog/Import/ModuleImport)) then _comment($module/(ModuleDecl | self::MainModule/Prolog/Import/ModuleImport)) else ()
145 145 (: TBD name and body - jpcs :)
146 146 },
@@ -150,9 +150,8 @@ declare function parse($module as xs:string, $mode as xs:string) as element(doc:
150 150 element doc:variables {
151 151 for $v in $module/Prolog/AnnotatedDecl/VarDecl
152 152 return element doc:variable {
153   - if($v/../Annotation/(TOKEN|EQName) = ("private","fn:private"))
154   - then attribute private { "true" } else (),
155   - element doc:uri { if($v/VarName) then _localname($v/VarName) else () },
  153 + _private($v/../Annotation),
  154 + _name($v/VarName/(URIQualifiedName|QName)),
156 155 _type($v/TypeDeclaration/SequenceType),
157 156 _comment($v/..)
158 157 }
@@ -161,11 +160,10 @@ declare function parse($module as xs:string, $mode as xs:string) as element(doc:
161 160 element doc:functions {
162 161 for $f in $module/Prolog/AnnotatedDecl/FunctionDecl
163 162 return element doc:function {
164   - if($f/../Annotation/(TOKEN|EQName) = ("private","fn:private"))
165   - then attribute private { "true" } else (),
166 163 attribute arity { fn:count($f/ParamList/Param) },
  164 + _private($f/../Annotation),
167 165 _comment($f/..),
168   - element doc:name { if ($f/EQName) then _localname($f/EQName) else () },
  166 + _name($f/(URIQualifiedName|QName)),
169 167 element doc:signature {
170 168 fn:string-join(("(", $f/ParamList/fn:string(), "&#10;)",
171 169 if($f/SequenceType) then (" as ", $f/SequenceType/fn:string()) else ()
@@ -174,7 +172,7 @@ declare function parse($module as xs:string, $mode as xs:string) as element(doc:
174 172 if($f/ParamList) then element doc:parameters {
175 173 for $p in $f/ParamList/Param
176 174 return element doc:parameter {
177   - element doc:name { if($p/EQName) then _localname($p/EQName) else () },
  175 + _name($p/(URIQualifiedName|QName)),
178 176 _type($p/TypeDeclaration/SequenceType)
179 177 }
180 178 } else (),

0 comments on commit 8179b89

Please sign in to comment.
Something went wrong with that request. Please try again.