rapydscript-ng 0.8.0 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +8 -0
- package/bin/build.ts +117 -0
- package/build_wheels.py +133 -0
- package/editor-plugins/README.md +80 -0
- package/editor-plugins/nvim.lua +321 -0
- package/package.json +1 -1
- package/publish.py +27 -17
- package/release/compiler.js +8125 -8093
- package/release/signatures.json +27 -27
- package/release/stdlib_modules.json +1 -0
- package/src/ast.pyj +379 -279
- package/src/baselib-builtins.pyj +47 -26
- package/src/baselib-containers.pyj +105 -92
- package/src/baselib-errors.pyj +8 -1
- package/src/baselib-internal.pyj +35 -20
- package/src/baselib-itertools.pyj +13 -7
- package/src/baselib-str.pyj +55 -80
- package/src/compiler.pyj +4 -4
- package/src/errors.pyj +3 -4
- package/src/lib/aes.pyj +46 -32
- package/src/lib/elementmaker.pyj +11 -9
- package/src/lib/encodings.pyj +15 -5
- package/src/lib/gettext.pyj +9 -4
- package/src/lib/math.pyj +106 -45
- package/src/lib/operator.pyj +10 -10
- package/src/lib/pythonize.pyj +2 -1
- package/src/lib/random.pyj +28 -21
- package/src/lib/re.pyj +490 -17
- package/src/lib/traceback.pyj +7 -2
- package/src/lib/uuid.pyj +2 -2
- package/src/output/classes.pyj +28 -27
- package/src/output/codegen.pyj +80 -83
- package/src/output/comments.pyj +8 -8
- package/src/output/exceptions.pyj +20 -21
- package/src/output/functions.pyj +37 -26
- package/src/output/literals.pyj +14 -10
- package/src/output/loops.pyj +63 -59
- package/src/output/modules.pyj +52 -23
- package/src/output/operators.pyj +40 -29
- package/src/output/statements.pyj +20 -14
- package/src/output/stream.pyj +33 -34
- package/src/output/utils.pyj +12 -8
- package/src/parse.pyj +234 -233
- package/src/string_interpolation.pyj +5 -3
- package/src/tokenizer.pyj +176 -148
- package/src/utils.pyj +31 -14
- package/test/fmt.pyj +94 -4
- package/test/generic.pyj +9 -0
- package/test/lsp.pyj +35 -0
- package/test/str.pyj +8 -0
- package/tools/cli.mjs +25 -4
- package/tools/compile.mjs +7 -3
- package/tools/compiler.mjs +34 -2
- package/tools/fmt.mjs +269 -22
- package/tools/ini.mjs +112 -1
- package/tools/lsp.mjs +56 -6
- package/tools/repl.mjs +5 -2
- package/tools/self.mjs +15 -0
- package/tools/test.mjs +100 -0
- package/tools/web_repl_export.mjs +4 -0
- package/tree-sitter/package.json +1 -1
- package/tree-sitter/tree-sitter.json +1 -1
- package/editor-plugins/nvim/rapydscript/README.md +0 -184
- package/editor-plugins/nvim/rapydscript/bin/rapydscript.so +0 -0
- package/editor-plugins/nvim/rapydscript/ftdetect/rapydscript.lua +0 -10
- package/editor-plugins/nvim/rapydscript/lua/rapydscript/health.lua +0 -88
- package/editor-plugins/nvim/rapydscript/lua/rapydscript/init.lua +0 -279
- /package/tree-sitter/queries/{rapydscript/highlights.scm → highlights.scm} +0 -0
- /package/tree-sitter/queries/{rapydscript/indents.scm → indents.scm} +0 -0
- /package/tree-sitter/queries/{rapydscript/injections.scm → injections.scm} +0 -0
- /package/tree-sitter/queries/{rapydscript/locals.scm → locals.scm} +0 -0
package/src/baselib-internal.pyj
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
# globals: exports, console, ρσ_iterator_symbol, ρσ_kwargs_symbol, ρσ_arraylike, ρσ_list_constructor, ρσ_str, ρσ_int, ρσ_float
|
|
5
5
|
|
|
6
|
+
|
|
6
7
|
def ρσ_eslice(arr, step, start, end):
|
|
7
8
|
if jstype(arr) is 'string' or v'arr instanceof String':
|
|
8
9
|
is_string = True
|
|
@@ -11,26 +12,27 @@ def ρσ_eslice(arr, step, start, end):
|
|
|
11
12
|
if step < 0:
|
|
12
13
|
step = -step
|
|
13
14
|
arr = arr.slice().reverse()
|
|
14
|
-
if jstype(start) is not
|
|
15
|
-
if jstype(end) is not
|
|
16
|
-
if jstype(start) is
|
|
17
|
-
if jstype(end) is
|
|
15
|
+
if jstype(start) is not 'undefined': start = arr.length - start - 1
|
|
16
|
+
if jstype(end) is not 'undefined': end = arr.length - end - 1
|
|
17
|
+
if jstype(start) is 'undefined': start = 0
|
|
18
|
+
if jstype(end) is 'undefined': end = arr.length
|
|
18
19
|
|
|
19
|
-
arr = arr.slice(start, end).filter(def(e, i): return i % step is 0;)
|
|
20
|
+
arr = arr.slice(start, end).filter(def (e, i): return i % step is 0;)
|
|
20
21
|
if is_string:
|
|
21
22
|
arr = arr.join('')
|
|
22
23
|
return arr
|
|
23
24
|
|
|
25
|
+
|
|
24
26
|
def ρσ_delslice(arr, step, start, end):
|
|
25
27
|
if jstype(arr) is 'string' or v'arr instanceof String':
|
|
26
28
|
is_string = True
|
|
27
29
|
arr = arr.split('')
|
|
28
30
|
if step < 0:
|
|
29
|
-
if jstype(start) is
|
|
30
|
-
if jstype(end) is
|
|
31
|
+
if jstype(start) is 'undefined': start = arr.length
|
|
32
|
+
if jstype(end) is 'undefined': end = 0
|
|
31
33
|
start, end, step = end, start, -step
|
|
32
|
-
if jstype(start) is
|
|
33
|
-
if jstype(end) is
|
|
34
|
+
if jstype(start) is 'undefined': start = 0
|
|
35
|
+
if jstype(end) is 'undefined': end = arr.length
|
|
34
36
|
|
|
35
37
|
if step is 1:
|
|
36
38
|
arr.splice(start, end - start)
|
|
@@ -46,6 +48,7 @@ def ρσ_delslice(arr, step, start, end):
|
|
|
46
48
|
arr = arr.join('')
|
|
47
49
|
return arr
|
|
48
50
|
|
|
51
|
+
|
|
49
52
|
def ρσ_flatten(arr):
|
|
50
53
|
ans = []
|
|
51
54
|
for v'var i=0; i < arr.length; i++':
|
|
@@ -56,6 +59,7 @@ def ρσ_flatten(arr):
|
|
|
56
59
|
ans.push(value)
|
|
57
60
|
return ans
|
|
58
61
|
|
|
62
|
+
|
|
59
63
|
def ρσ_unpack_asarray(num, iterable):
|
|
60
64
|
if ρσ_arraylike(iterable):
|
|
61
65
|
return iterable
|
|
@@ -68,13 +72,14 @@ def ρσ_unpack_asarray(num, iterable):
|
|
|
68
72
|
result = iterator.next()
|
|
69
73
|
return ans
|
|
70
74
|
|
|
75
|
+
|
|
71
76
|
def ρσ_extends(child, parent):
|
|
72
77
|
child.prototype = Object.create(parent.prototype)
|
|
73
78
|
child.prototype.constructor = child
|
|
74
79
|
|
|
75
80
|
ρσ_in = (def ():
|
|
76
81
|
if jstype(Map) is 'function' and jstype(Set) is 'function':
|
|
77
|
-
return def(val, arr):
|
|
82
|
+
return def (val, arr):
|
|
78
83
|
if jstype(arr) is 'string':
|
|
79
84
|
return arr.indexOf(val) is not -1
|
|
80
85
|
if jstype(arr.__contains__) is 'function':
|
|
@@ -84,7 +89,7 @@ def ρσ_extends(child, parent):
|
|
|
84
89
|
if ρσ_arraylike(arr):
|
|
85
90
|
return Array.prototype.__contains__.call(arr, val)
|
|
86
91
|
return Object.prototype.hasOwnProperty.call(arr, val)
|
|
87
|
-
return def(val, arr):
|
|
92
|
+
return def (val, arr):
|
|
88
93
|
if jstype(arr) is 'string':
|
|
89
94
|
return arr.indexOf(val) is not -1
|
|
90
95
|
if jstype(arr.__contains__) is 'function':
|
|
@@ -94,6 +99,7 @@ def ρσ_extends(child, parent):
|
|
|
94
99
|
return Object.prototype.hasOwnProperty.call(arr, val)
|
|
95
100
|
)()
|
|
96
101
|
|
|
102
|
+
|
|
97
103
|
def ρσ_Iterable(iterable):
|
|
98
104
|
# Once ES6 is mature, change AST_ForIn to use the iterator protocol and get
|
|
99
105
|
# rid of this function entirely
|
|
@@ -112,13 +118,13 @@ def ρσ_Iterable(iterable):
|
|
|
112
118
|
|
|
113
119
|
ρσ_desugar_kwargs = (def ():
|
|
114
120
|
if jstype(Object.assign) is 'function':
|
|
115
|
-
return def():
|
|
121
|
+
return def ():
|
|
116
122
|
ans = Object.create(None)
|
|
117
123
|
ans[ρσ_kwargs_symbol] = True
|
|
118
124
|
for v'var i = 0; i < arguments.length; i++':
|
|
119
125
|
Object.assign(ans, arguments[i])
|
|
120
126
|
return ans
|
|
121
|
-
return def():
|
|
127
|
+
return def ():
|
|
122
128
|
ans = Object.create(None)
|
|
123
129
|
ans[ρσ_kwargs_symbol] = True
|
|
124
130
|
for v'var i = 0; i < arguments.length; i++':
|
|
@@ -128,6 +134,7 @@ def ρσ_Iterable(iterable):
|
|
|
128
134
|
return ans
|
|
129
135
|
)()
|
|
130
136
|
|
|
137
|
+
|
|
131
138
|
def ρσ_interpolate_kwargs(f, supplied_args):
|
|
132
139
|
if not f.__argnames__:
|
|
133
140
|
return f.apply(this, supplied_args)
|
|
@@ -154,6 +161,7 @@ def ρσ_interpolate_kwargs(f, supplied_args):
|
|
|
154
161
|
supplied_args[i] = kwobj[prop]
|
|
155
162
|
return f.apply(this, supplied_args)
|
|
156
163
|
|
|
164
|
+
|
|
157
165
|
def ρσ_interpolate_kwargs_constructor(apply, f, supplied_args):
|
|
158
166
|
if apply:
|
|
159
167
|
f.apply(this, supplied_args)
|
|
@@ -161,6 +169,7 @@ def ρσ_interpolate_kwargs_constructor(apply, f, supplied_args):
|
|
|
161
169
|
ρσ_interpolate_kwargs.call(this, f, supplied_args)
|
|
162
170
|
return this
|
|
163
171
|
|
|
172
|
+
|
|
164
173
|
def ρσ_getitem(obj, key):
|
|
165
174
|
if obj.__getitem__:
|
|
166
175
|
return obj.__getitem__(key)
|
|
@@ -168,6 +177,7 @@ def ρσ_getitem(obj, key):
|
|
|
168
177
|
key += obj.length
|
|
169
178
|
return obj[key]
|
|
170
179
|
|
|
180
|
+
|
|
171
181
|
def ρσ_setitem(obj, key, val):
|
|
172
182
|
if obj.__setitem__:
|
|
173
183
|
obj.__setitem__(key, val)
|
|
@@ -177,6 +187,7 @@ def ρσ_setitem(obj, key, val):
|
|
|
177
187
|
obj[key] = val
|
|
178
188
|
return val
|
|
179
189
|
|
|
190
|
+
|
|
180
191
|
def ρσ_delitem(obj, key):
|
|
181
192
|
if obj.__delitem__:
|
|
182
193
|
obj.__delitem__(key)
|
|
@@ -187,11 +198,13 @@ def ρσ_delitem(obj, key):
|
|
|
187
198
|
key += obj.length
|
|
188
199
|
v'delete obj[key]'
|
|
189
200
|
|
|
201
|
+
|
|
190
202
|
def ρσ_bound_index(idx, arr):
|
|
191
203
|
if jstype(idx) is 'number' and idx < 0:
|
|
192
204
|
idx += arr.length
|
|
193
205
|
return idx
|
|
194
206
|
|
|
207
|
+
|
|
195
208
|
def ρσ_splice(arr, val, start, end):
|
|
196
209
|
start = start or 0
|
|
197
210
|
if start < 0:
|
|
@@ -203,24 +216,25 @@ def ρσ_splice(arr, val, start, end):
|
|
|
203
216
|
Array.prototype.splice.apply(arr, v'[start, end - start].concat(val)')
|
|
204
217
|
|
|
205
218
|
ρσ_exists = {
|
|
206
|
-
'n': def(expr):
|
|
219
|
+
'n': def (expr):
|
|
207
220
|
return expr is not undefined and expr is not None
|
|
208
|
-
,'d': def(expr):
|
|
221
|
+
, 'd': def (expr):
|
|
209
222
|
if expr is undefined or expr is None:
|
|
210
223
|
return Object.create(None)
|
|
211
224
|
return expr
|
|
212
|
-
,'c': def(expr):
|
|
225
|
+
, 'c': def (expr):
|
|
213
226
|
if jstype(expr) is 'function':
|
|
214
227
|
return expr
|
|
215
|
-
return def():
|
|
228
|
+
return def ():
|
|
216
229
|
return undefined
|
|
217
|
-
,'g': def(expr):
|
|
230
|
+
, 'g': def (expr):
|
|
218
231
|
if expr is undefined or expr is None or jstype(expr.__getitem__) is not 'function':
|
|
219
|
-
return {'__getitem__': def(): return undefined;}
|
|
220
|
-
,'e': def(expr, alt):
|
|
232
|
+
return {'__getitem__': def (): return undefined;}
|
|
233
|
+
, 'e': def (expr, alt):
|
|
221
234
|
return alt if expr is undefined or expr is None else expr
|
|
222
235
|
}
|
|
223
236
|
|
|
237
|
+
|
|
224
238
|
def ρσ_mixin():
|
|
225
239
|
# Implement a depth-first left-to-right method resolution order This is not
|
|
226
240
|
# the same as python's MRO, but I really dont feel like implementing the C3
|
|
@@ -249,6 +263,7 @@ def ρσ_mixin():
|
|
|
249
263
|
p = Object.getPrototypeOf(p)
|
|
250
264
|
Object.defineProperties(target, resolved_props)
|
|
251
265
|
|
|
266
|
+
|
|
252
267
|
def ρσ_instanceof():
|
|
253
268
|
obj = arguments[0]
|
|
254
269
|
bases = ''
|
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
# globals: ρσ_iterator_symbol, ρσ_bool
|
|
6
6
|
|
|
7
|
+
|
|
7
8
|
def sum(iterable, start):
|
|
8
9
|
if Array.isArray(iterable):
|
|
9
10
|
return iterable.reduce(
|
|
10
|
-
def(prev, cur): return prev+cur
|
|
11
|
+
def (prev, cur): return prev + cur
|
|
11
12
|
,
|
|
12
13
|
start or 0
|
|
13
14
|
)
|
|
@@ -19,6 +20,7 @@ def sum(iterable, start):
|
|
|
19
20
|
r = iterator.next()
|
|
20
21
|
return ans
|
|
21
22
|
|
|
23
|
+
|
|
22
24
|
def map():
|
|
23
25
|
iterators = new Array(arguments.length - 1)
|
|
24
26
|
func = arguments[0] # noqa: unused-local
|
|
@@ -26,9 +28,9 @@ def map():
|
|
|
26
28
|
for v'var i = 1; i < arguments.length; i++':
|
|
27
29
|
iterators[i - 1] = iter(arguments[i]) # noqa:undef
|
|
28
30
|
ans = v"{'_func':func, '_iterators':iterators, '_args':args}"
|
|
29
|
-
ans[ρσ_iterator_symbol] = def():
|
|
31
|
+
ans[ρσ_iterator_symbol] = def ():
|
|
30
32
|
return this
|
|
31
|
-
ans['next'] = def():
|
|
33
|
+
ans['next'] = def ():
|
|
32
34
|
for v'var i = 0; i < this._iterators.length; i++':
|
|
33
35
|
r = this._iterators[i].next()
|
|
34
36
|
if r.done:
|
|
@@ -37,12 +39,13 @@ def map():
|
|
|
37
39
|
return v"{'done':false, 'value':this._func.apply(undefined, this._args)}"
|
|
38
40
|
return ans
|
|
39
41
|
|
|
42
|
+
|
|
40
43
|
def filter(func_or_none, iterable):
|
|
41
44
|
func = ρσ_bool if func_or_none is None else func_or_none # noqa: unused-local
|
|
42
45
|
ans = v"{'_func':func, '_iterator':ρσ_iter(iterable)}"
|
|
43
|
-
ans[ρσ_iterator_symbol] = def():
|
|
46
|
+
ans[ρσ_iterator_symbol] = def ():
|
|
44
47
|
return this
|
|
45
|
-
ans['next'] = def():
|
|
48
|
+
ans['next'] = def ():
|
|
46
49
|
r = this._iterator.next()
|
|
47
50
|
while not r.done:
|
|
48
51
|
if this._func(r.value):
|
|
@@ -51,14 +54,15 @@ def filter(func_or_none, iterable):
|
|
|
51
54
|
return v"{'done':true}"
|
|
52
55
|
return ans
|
|
53
56
|
|
|
57
|
+
|
|
54
58
|
def zip():
|
|
55
59
|
iterators = new Array(arguments.length)
|
|
56
60
|
for v'var i = 0; i < arguments.length; i++':
|
|
57
61
|
iterators[i] = iter(arguments[i]) # noqa:undef
|
|
58
62
|
ans = v"{'_iterators':iterators}"
|
|
59
|
-
ans[ρσ_iterator_symbol] = def():
|
|
63
|
+
ans[ρσ_iterator_symbol] = def ():
|
|
60
64
|
return this
|
|
61
|
-
ans['next'] = def():
|
|
65
|
+
ans['next'] = def ():
|
|
62
66
|
args = new Array(this._iterators.length)
|
|
63
67
|
for v'var i = 0; i < this._iterators.length; i++':
|
|
64
68
|
r = this._iterators[i].next()
|
|
@@ -68,12 +72,14 @@ def zip():
|
|
|
68
72
|
return v"{'done':false, 'value':args}"
|
|
69
73
|
return ans
|
|
70
74
|
|
|
75
|
+
|
|
71
76
|
def any(iterable):
|
|
72
77
|
for i in iterable:
|
|
73
78
|
if i:
|
|
74
79
|
return True
|
|
75
80
|
return False
|
|
76
81
|
|
|
82
|
+
|
|
77
83
|
def all(iterable):
|
|
78
84
|
for i in iterable:
|
|
79
85
|
if not i:
|