This repository has been archived by the owner on Feb 20, 2020. It is now read-only.
forked from dlam26/xqueryvim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasex-fn2vim.xq
56 lines (50 loc) · 1.58 KB
/
basex-fn2vim.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
(:~
: Helping script
:
: generates list of module namespaces
: and list of functions for each module
:
: data is generated from BaseX documentation
: using https://github.com/arolle/basex-docu
:)
import module namespace C = "basex-docu-conversion-config" at "config.xqm";
(:~
: generate "vim-array let declaration" from sequence
:
: @return string as "let nm = ['a', 'b']"
:)
declare function local:let-vimarray-from(
$var-name as xs:string,
$seq as xs:string*
) {
string-join(
$seq ! ('"' || . || '"'),
", "
) ! ("let " || $var-name ||" = [" || . || "]")
};
(:
: output VimL strings
:)
let $modules := (
C:open-by-name($C:WIKI-DUMP-PATH || "Module%20Library")
//*:table/*:tr/*:td[position() = 3]/data() ! normalize-space(.)
)[string-length(.) > 0] (: remove empty :)
let $all-signatures := (: all function signatures :)
distinct-values(C:open-by-name($C:WIKI-DUMP-PATH)//table/tr/td[position() = 2]/code/b/text())
return string-join((
$modules ! ("elseif namespace =~ '" || . || "'" || out:nl()
|| out:tab() || "call map(" || . ||"_functions, '"" || . || ":" . v:val . "("')" || out:nl()
|| out:tab() || "let function_completions = copy(" || . ||"_functions)")
, "",
(: list of namespaces :)
local:let-vimarray-from("library_modules_namespaces", $modules),
(: list of functions :)
for $x in $all-signatures
let $parts := tokenize($x, ':'),
$ns := $parts[1]
group by $ns
return
local:let-vimarray-from($ns[1] || "_functions",
$parts[position() mod 2 = 0] (: removes $ns[1] from $parts :)
)
), out:nl())