forked from wolfgangmm/xqlint
-
Notifications
You must be signed in to change notification settings - Fork 3
/
generate_builtin.xq
78 lines (73 loc) · 2.32 KB
/
generate_builtin.xq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import module namespace file = "http://expath.org/ns/file";
import module namespace xqdoc = "http://www.zorba-xquery.com/modules/xqdoc";
declare namespace xqd = "http://www.xqdoc.org/1.0";
declare function local:description-summary($description as element(xqd:description)*)
as element(p)
{
let $text := local:text($description)
let $text := normalize-space($text)
let $text := if(string-length($text) gt 300) then substring($text, 1, 300) || "..." else $text
return
<p>{$text}</p>
};
declare function local:text($nodes)
as xs:string?
{
string-join(
for $node in $nodes
return
if($node instance of text()) then
$node
else
local:text($node/node())
, " ")
};
variable $processed := ();
{|
for $file in file:list("modules", true(), "*.xq")
return {
trace($file, "file");
variable $source := file:read-text("modules/" || $file);
variable $xqdoc := xqdoc:xqdoc-content($source);
variable $ns := $xqdoc/xqd:module/xqd:uri/text();
variable $description := $xqdoc/xqd:module/xqd:comment/xqd:description;
variable $r :=
{
$ns : {
"doc": local:description-summary($description),
"docUrl": "http://www.28msec.com/modules/",
"functions": {|
for $function in $xqdoc/xqd:functions/xqd:function
let $name := $function/xqd:name/text()
let $name := substring-after($name, ":")
let $arity := $function/@arity/string()
group by $name
(:
let $fn := $function[1]
let $is-private := exists($fn/xqd:annotations/xqd:annotation[@namespace = "http://www.w3.org/2005/xpath-functions" and @localname = "private"])
where not($is-private)
:)
return {
$name : [
for $f in $function
group by $arity := $f/@arity/string()
return {
"doc": local:description-summary($f[1]/xqd:comment/xqd:description),
"docUrl": "http://www.28msec.com/modules/",
"params": [
for $param in $f[1]/xqd:parameters/xqd:parameter
return "$" || $param/xqd:name/text()
]
}
]
}
|}
}
};
$processed := ($processed, $ns);
if(count($processed[. eq $ns]) = 1) then
$r
else
()
}
|}