-
Notifications
You must be signed in to change notification settings - Fork 249
/
Copy pathgen-js-ext.nu
106 lines (90 loc) · 3.1 KB
/
gen-js-ext.nu
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
def gen_keywords [] {
let cmds = (scope commands
| where is_extern == false
and is_custom == false
and category !~ deprecated
and not ($it.name | str contains ' ')
| get name
| str join '|')
let var_with_dash_or_under_regex = '(([a-zA-Z]+[\\-_]){1,}[a-zA-Z]+\\s)'
let preamble = '\\b('
let postamble = ')\\b'
$'"match": "($var_with_dash_or_under_regex)|($preamble)($cmds)($postamble)",'
}
def gen_sub_keywords [] {
let sub_cmds = (scope commands
| where is_extern == false
and is_custom == false
and category !~ deprecated
and ($it.name | str contains ' ')
| get name)
let preamble = '\\b('
let postamble = ')\\b'
let cmds = ($sub_cmds | each {|x|
let parts = ($x | split row ' ')
$'($parts.0)\\s($parts.1)'
} | str join '|')
$'"match": "($preamble)($cmds)($postamble)",'
}
def gen_keywords_alphabetically [] {
let alphabet = [a b c d e f g h i j k l m n o p q r s t u v w x y z]
let cmds = (scope commands
| where is_extern == false
and is_custom == false
and category !~ deprecated
and not ($it.name | str contains ' ')
| get name)
let preamble = '\\b('
let postamble = ')\\b'
$alphabet | each {|alpha|
let letter_cmds = ($cmds | each {|cmd|
if ($cmd | str starts-with $alpha) {
$cmd
} else {
null
}
} | str join '|')
if ($letter_cmds | str trim | str length) > 0 {
$'"match": "($preamble)($letter_cmds)($postamble)",'
}
} | str join "\n"
}
def gen_sub_keywords_alphabetically [] {
let alphabet = [a b c d e f g h i j k l m n o p q r s t u v w x y z]
let sub_cmds = (scope commands |
| where is_extern == false
and is_custom == false
and category !~ deprecated
and ($it.name | str contains ' ')
| get name)
let preamble = '\\b('
let postamble = ')\\b'
$alphabet | each {|alpha|
let letter_cmds = ($sub_cmds | each {|cmd|
if ($cmd | str starts-with $alpha) {
let parts = ($cmd | split row ' ')
$'($parts.0)\\s($parts.1)'
} else {
null
}
} | str join '|')
if ($letter_cmds | str trim | str length) > 0 {
$'"match": "($preamble)($letter_cmds)($postamble)",'
}
} | str join "\n"
}
export def main [] {
print $"Generating keywords(char nl)"
print (gen_keywords)
print (char nl)
print (char nl)
print $"Generating sub keywords(char nl)"
print (gen_sub_keywords)
print (char nl)
print "Generating keywords alphabetically\n"
print (gen_keywords_alphabetically)
print (char nl)
print "Generating sub keywords alphabetically\n"
print (gen_sub_keywords_alphabetically)
print (char nl)
}