Changes

Jump to navigation Jump to search
11,122 bytes added ,  14:18, 20 July 2022
no edit summary
This [[Module Library|XQuery Module]] contains functions for extracting internal information about modules and functions and generating xqDoc files from XQuery modulesdocumentation.
=IntroductionConventions= All functions and errors in this module are assigned to the <code><nowiki>http://basex.org/modules/inspect</nowiki></code> namespace, which is statically bound to the {{Code|inspect}} prefix.<br/>xqDoc document instances are assigned to the <code><nowiki>http://www.xqdoc.org/1.0</nowiki></code> namespace, which is statically bound to the {{Code|xqdoc}} prefix. =Reflection= ==inspect:functions== {| width='100%'|- valign="top"| width='120' | '''Signatures'''|{{Func|inspect:functions||function(*)*}}<br/>{{Func|inspect:functions|$uri as xs:string|function(*)*}}|- valign="top"| '''Summary'''|Returns function items for all user-defined functions (both public and private) that are known in the current query context. If a {{Code|$uri}} is specified, the specified resource will be retrieved as string and compiled, and its functions will be added to the query context and returned to the user. A relative URI will be resolved against the static base URI of the query.|- valign="top"|'''Examples'''|Invokes the declared functions and returns their values:<br/><syntaxhighlight lang="xquery">declare %private function local:one() { 12 };declare %private function local:two() { 34 };for $f in inspect:functions() return $f()</syntaxhighlight>Compiles all functions in {{Code|code.xqm}} and invokes the function named {{Code|run}}:<syntaxhighlight lang="xquery">let $uri := 'code.xqm'let $name := 'run'for $f in inspect:functions($uri)where local-name-from-QName(function-name($f)) = $namereturn $f()</syntaxhighlight>|- valign="top"| '''Errors'''|{{Error|parse|#Errors}} Error while parsing a module.|} ==inspect:function-annotations== {| width='100%'|- valign="top"| width='120' | '''Signatures'''|{{Func|inspect:function-annotations|$function as function(*)?|map(xs:QName, xs:anyAtomicType*)}}<br/>|- valign="top"| '''Summary'''|Returns the annotations of the specified {{Code|$function}} in a map.|- valign="top"| '''Examples'''|* Returns an empty map:<syntaxhighlight lang="xquery">inspect:function-annotations(true#0)</syntaxhighlight>* Returns a map with a single key <code><nowiki>Q{http://www.w3.org/2012/xquery}private</nowiki></code> and an empty sequence as value:<syntaxhighlight lang="xquery">declare %private function local:f() { 'well hidden' };inspect:function-annotations(local:f#0)</syntaxhighlight>|} ==inspect:static-context==
{| width='100%'|- valign="top"| width='120' | '''Signatures'''|{{Func|inspect:static-context|$function as function(*)?, $name as xs:string|item()*}}<br/>|- valign="top"| '''Summary'''|Returns a component of the [httphttps://xqdocwww.w3.org xqDoc/TR/xquery-31/#dt-static-context static context] provides of a simple vendor neutral solution for generating a documentation from XQuery modules{{Code|$function}} with the specified {{Code|$name}}. If no function is supplied, the current static context is considered. <br/>The documentation conventions have been inspired by following components can be requested:* {{Code|base-uri}}: Static base URI.* {{Code|namespaces}}: Prefix/URI map with all statically known namespaces.* {{Code|element-namespace}}: Default element/type namespace URI, or an empty sequence if it is absent.* {{Code|function-namespace}}: Default function namespace URI, or an empty sequence if it is absent.* {{Code|collation}}: URI of the JavaDoc standarddefault collation. Documentation comments begin with * {{Code|ordering}}: Ordering mode ({{Code|ordered}}/{{Code|unordered}})* {{Code|construction}}: Construction mode ({{Code|preserve}}/{{Code|strip}})* {{Code|default-order-empty}}:~Default order for empty sequences ({{Code|greatest}}/{{Code|least}} and end with )* {{Code|boundary-space}}:Boundary-space policy ({{Code|preserve}}/{{Code|strip}})* {{Code|copy-namespaces}}: Copy-namespaces mode ({{Code|inherit}}/{{Code|no-inherit}}, and tags start {{Code|preserve}}/{{Code|no-preserve}})* {{Code|decimal-formats}}: Nested map with all statically known decimal formats|- valign="top"| '''Examples'''|* Returns the static base URI (same as {{Code|@static-base-uri()}}):<syntaxhighlight lang="xquery">inspect:static-context((), 'base-uri')</syntaxhighlight>* Returns a map with all namespaces that are statically known in the module of the specified function:<syntaxhighlight lang="xquery">import module namespace data = 'data. xqDoc comments can be xqm';inspect:static-context(data:get#1, 'namespaces')</syntaxhighlight>|- valign="top"| '''Errors'''|{{Error|unknown|#Errors}} The specified for main component does not exist.|} =Documentation= ==inspect:type== {| width='100%'|- valign="top"| width='120' | '''Signatures'''|{{Func|inspect:type|$value as item()*|xs:string}}<br/>{{Func|inspect:type|$value as item()*, $options as map(*)|xs:string}}|- valign="top"| '''Summary'''|Returns a string representation of the type of a {{Code|$value}}:* The string includes the occurrence indicator.* The type of functions and library modules nodes may be stricter than the returned type.* For type checking, the standard expressions {{Code|typeswitch}} and variable {{Code|instance of}} should be used instead.The following {{Code|$options}} are available:* {{Code|item}}: If enabled, only the item type is returned and function declarationsthe occurrence indicator is omitted. The default is {{Code|false()}}.* {{Code|mode}}: If {{Code|value}} is specified, the assigned type of the result value is returned. We With {{Code|expression}} the type of the input expression is returned (please note that the original expression may already have slightly extended been rewritten at compile-time). With {{Code|computed}}, the exact value is computed at runtime, based on the conventions expression and updated the result value. The default is {{Code|computed}}.|- valign="top"| '''Examples'''|* <code>inspect:type((<a/>, <a/>))</code> yields <code>element(a)+</code>* <code>inspect:type(map { 'a': (1, 2)[. = 1] })</code> yields <code>map(xs:string, xs:integer)</code>* <code>inspect:type(1 to 100, map { 'item': true() })</code> yields <code>xs:integer</code>|} ==inspect:function== {| width='100%'|- valign="top"| width='120' | '''Signatures'''|{{Func|inspect:function|$function as function(*)|element(function)}}|- valign="top"| '''Summary'''|Inspects the specified {{Code|$function}} and returns an element that describes its structure. The output of this function is similar to eXist-db’s [https://exist-db.org/exist/apps/fundocs/view.html?uri=http://filesexist-db.org/xquery/inspection&location=java:org.exist.basexxquery.functions.inspect.InspectionModule inspect:inspect-function] function.|- valign="top"|'''Examples'''|The query {{Code|inspect:function(count#1)}} yields:<syntaxhighlight lang="xml"><function name="count" uri="http://www.w3.org/etc2005/xqdocxpath-functions" external="false"> <argument type="item()" occurrence="*"/> <return type="xs:integer"/></function></syntaxhighlight>The function…<syntaxhighlight lang="xquery">(:~ : This function simply returns the specified integer. : @param $number number to return : @return specified number :)declare %private function local:same($number as xs:integer) as xs:integer { $number};</syntaxhighlight>…is represented by {{Code|inspect:function(local:same#1)}} as…<syntaxhighlight lang="xml"><function name="local:same" uri="http://www.w3.org/2005/xquery-local-functions" external="false"> <argument type="xs:integer" name="number">number to return</argument> <annotation name="private" uri="http://www.1w3.30052013org/2012/xquery"/> <description>This function simply returns the specified integer.xsd xqDoc schema]</description> <return type="xs:integer">specified number</return></function></syntaxhighlight>|}
* an {{Code|<xqdoc==inspect:namespaces/>}} node lists all namespaces of a module* if annotations are attached to variables or functions, an {{Code|<xqdoc:annotations/>}} node is added* variables now have a name and a type.context==
An [[#Example{|example]] is shown belowwidth='100%'|- valign="top"| width='120' | '''Signatures'''|{{Func|inspect:context||element(context)}}|- valign="top"| '''Summary'''|Generates an element that describes all variables and functions in the current query context.|- valign="top"| '''Examples'''|Evaluate all user-defined functions with zero arguments in the query context:<br/><syntaxhighlight lang="xquery">inspect:context()/function ! function-lookup(QName(@uri, @name), 0) ! .()</syntaxhighlight>Return the names of all private functions in the current context:<syntaxhighlight lang="xquery">for $f in inspect:context()/functionwhere $f/annotation/@name = 'private'return $f/@name/string()</syntaxhighlight>|}
=Conventions=inspect:module==
All functions in this module are assigned to the {| width='100%'|- valign="top"| width='120' | '''Signatures'''|{{CodeFunc|inspect:module|http$uri as xs://basex.org/modules/xqdocstring|element(module)}} namespace, which is statically bound to |- valign="top"| '''Summary'''|Retrieves the resource located at the specified {{Code|xqdoc$uri}} prefix, parses it as XQuery module, and generates an element that describes the module's structure.<br/>A relative URI will be resolved against the static base URI of the query.|- valign="top"|'''Examples'''All errors are assigned to the {{Code|http://basexAn example is [[#Examples|shown below]].org/errors}} namespace, which is statically bound to the |- valign="top"| '''Errors'''|{{CodeError|parse|bxerr#Errors}} prefixError while parsing a module.|}
=Functions=inspect:xqdoc==
==xqdoc:parse==
{| width='100%'
|-valign="top"| width='90120' | '''Signatures'''|{{Func|inspect:xqdoc:parse|$input uri as xs:string|element(xqdoc:xqdoc)}}|-valign="top"
| '''Summary'''
|Parses Retrieves the resource located at the specified {{Code|$inputuri}} , parses it as XQuery module, and generates an xqDoc element. A relative URI will be resolved against the static base URI of the query.<br/>[http://xqdoc.org/ xqDoc] provides a simple vendor-neutral solution for generating documentation from XQuery modules. The documentation conventions have been inspired by the JavaDoc standard. Documentation comments begin with {{Code|(:~}} and end with {{Code|:)}}, and tags start with {{Code|@}}. xqDoc comments can be specified for main and library modules and variable and function declarations.<br/>We have slightly extended the xqDoc conventions to do justice to more recent versions of XQuery (Schema: [https://files.basex.org/etc/xqdoc-1.1.30052013.xsd xqdoc-1.1.30052013.xsd]):<br/>* an {{Code|<xqdoc:annotations/>}} node is added to each variable or function that uses annotations. The xqdoc:annotation child nodes may have additional {{Code|xqdoc:literal}} elements with {{Code|type}} attributes (xs:string, xs:integer, xs:decimal, xs:double) and values.* a single {{Code|<xqdoc:namespaces/>}} node is added to the root element, which summarizes all prefixes and namespace URIs used or declared in the module.* name and type elements are added to variables.|- valign="top"|'''Examples'''|An example is [[#Examples|shown below]].|- valign="top"| '''Errors'''|{{Error|parse|#Errors}} Error while parsing a module.
|}
=ExampleExamples=
The query This is the {{Code|xqdoc:parse('sample.xq')xqm}} will convert the following example library module...:
<pre classsyntaxhighlight lang="brush:xquery">
(:~
: This module provides some sample functions to demonstrate
: the features of the XQDoc Inspection Module. : : @author BaseX Team : @see http://docs.basex.org/wiki/XQDoc_Module : @version 1.0
:)
module namespace samples = 'http://basex.org/modules/samples';
(:~ This is a sample string. :)
declare variable $samples:test-string as xs:string := 'this is a string';
(:~
: This function simply returns the specified integer.
: @param $number number to return : @return specified number
:)
declare %private function samples:same( $number as xs:integer) as xs:integer {
$number
};
</presyntaxhighlight> If {{Code|inspect:module('sample.xqm')}} is run, the following output will be generated: <syntaxhighlight lang="xml"><module prefix="samples" uri="http://basex.org/modules/samples"> <description>This module provides some sample functions to demonstratethe features of the Inspection Module.</description> <author>BaseX Team</author> <see>http://docs.basex.org/wiki/XQDoc_Module</see> <version>1.0</version> <variable name="samples:test-string" uri="http://basex.org/modules/samples" type="xs:string" external="false"> <description>This is a sample string.</description> </variable> <function name="samples:same" uri="http://basex.org/modules/samples" external="false"> <argument name="number" type="xs:integer">number to return</argument> <annotation name="private" uri="http://www.w3.org/2012/xquery"/> <description>This function simply returns the specified integer.</description> <return type="xs:integer">specified number</return> </function></module></syntaxhighlight>
The output looks as follows if {{Code|inspect:xqdoc('sample...to the following outputxqm')}} is called:
<pre classsyntaxhighlight lang="brush:xml">
<xqdoc:xqdoc xmlns:xqdoc="http://www.xqdoc.org/1.0">
<xqdoc:control>
<xqdoc:date>2013-0506-31T0801T16:4359:0533.123654+02:00</xqdoc:date>
<xqdoc:version>1.1</xqdoc:version>
</xqdoc:control>
<xqdoc:uri>http://basex.org/modules/samples</xqdoc:uri>
<xqdoc:name>sample.xqm</xqdoc:name>
<xqdoc:comment>
<xqdoc:description>This module provides some sample functions to demonstrate
the features of the Inspection Module.</xqdoc:description>
<xqdoc:author>BaseX Team</xqdoc:author>
<xqdoc:see>http://docs.basex.org/wiki/XQDoc_Module</xqdoc:see>
<xqdoc:version>1.0</xqdoc:version>
</xqdoc:comment>
</xqdoc:module>
<xqdoc:imports/>
<xqdoc:namespaces>
<xqdoc:namespace prefix="samples" uri="http://basex.org/modules/samples"/>
</xqdoc:namespaces>
<xqdoc:imports/>
<xqdoc:variables>
<xqdoc:variable>
</xqdoc:functions>
</xqdoc:xqdoc>
</presyntaxhighlight=Errors= {| class="wikitable" width="100%"! width="110"|Code|Description|- valign="top"|{{Code|parse}}|Error while parsing a module.|- valign="top"|{{Code|unknown}}|The specified component does not exist.|}
=Changelog=
 
;Version 9.6
* Updated: {{Function||inspect:type}}: options added
 
;Version 9.3
* Added: {{Function||inspect:type}}
 
;Version 8.5
* Added: {{Function||inspect:function-annotations}}, {{Function||inspect:static-context}}
* Updated: {{Code|external}} attribute added to variables and functions
* Updated: Relative URIs will always be resolved against the static base URI of the query
 
;Version 7.9
* Updated: a query URI can now be specified with {{Function||inspect:functions}}.
This module was introduced with Version 7.7.
 
[[Category:XQuery]]
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu