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-builtins.pyj
CHANGED
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
# globals: exports, console, ρσ_iterator_symbol, ρσ_kwargs_symbol, ρσ_arraylike, ρσ_list_contains
|
|
6
6
|
|
|
7
|
+
|
|
7
8
|
def ρσ_bool(val):
|
|
8
9
|
return v'!!val'
|
|
9
10
|
|
|
11
|
+
|
|
10
12
|
def ρσ_print():
|
|
11
13
|
if v'typeof console' is 'object':
|
|
12
14
|
parts = v'[]'
|
|
@@ -14,8 +16,9 @@ def ρσ_print():
|
|
|
14
16
|
parts.push(ρσ_str(v'arguments[i]')) # noqa: undef
|
|
15
17
|
console.log(parts.join(' '))
|
|
16
18
|
|
|
19
|
+
|
|
17
20
|
def ρσ_int(val, base):
|
|
18
|
-
if jstype(val) is
|
|
21
|
+
if jstype(val) is 'number':
|
|
19
22
|
ans = val | 0
|
|
20
23
|
else:
|
|
21
24
|
ans = parseInt(val, base or 10)
|
|
@@ -23,8 +26,9 @@ def ρσ_int(val, base):
|
|
|
23
26
|
raise ValueError('Invalid literal for int with base ' + (base or 10) + ': ' + val)
|
|
24
27
|
return ans
|
|
25
28
|
|
|
29
|
+
|
|
26
30
|
def ρσ_float(val):
|
|
27
|
-
if jstype(val) is
|
|
31
|
+
if jstype(val) is 'number':
|
|
28
32
|
ans = val
|
|
29
33
|
else:
|
|
30
34
|
ans = parseFloat(val)
|
|
@@ -32,24 +36,28 @@ def ρσ_float(val):
|
|
|
32
36
|
raise ValueError('Could not convert string to float: ' + arguments[0])
|
|
33
37
|
return ans
|
|
34
38
|
|
|
39
|
+
|
|
35
40
|
def ρσ_arraylike_creator():
|
|
36
41
|
names = 'Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array'.split(' ')
|
|
37
42
|
if jstype(HTMLCollection) is 'function':
|
|
38
43
|
names = names.concat('HTMLCollection NodeList NamedNodeMap TouchList'.split(' '))
|
|
39
|
-
return def(x):
|
|
44
|
+
return def (x):
|
|
40
45
|
if Array.isArray(x) or v'typeof x' is 'string' or names.indexOf(Object.prototype.toString.call(x).slice(8, -1)) > -1:
|
|
41
46
|
return True
|
|
42
47
|
return False
|
|
43
48
|
|
|
49
|
+
|
|
44
50
|
def options_object(f):
|
|
45
|
-
return def():
|
|
51
|
+
return def ():
|
|
46
52
|
if v'typeof arguments[arguments.length - 1] === "object"':
|
|
47
53
|
arguments[arguments.length - 1][ρσ_kwargs_symbol] = True
|
|
48
54
|
return f.apply(this, arguments)
|
|
49
55
|
|
|
56
|
+
|
|
50
57
|
def ρσ_id(x):
|
|
51
58
|
return x.ρσ_object_id
|
|
52
59
|
|
|
60
|
+
|
|
53
61
|
def ρσ_dir(item):
|
|
54
62
|
# TODO: this isn't really representative of real Python's dir(), nor is it
|
|
55
63
|
# an intuitive replacement for "for ... in" loop, need to update this logic
|
|
@@ -58,6 +66,7 @@ def ρσ_dir(item):
|
|
|
58
66
|
for v'var i in item': arr.push(i) # noqa:undef
|
|
59
67
|
return arr
|
|
60
68
|
|
|
69
|
+
|
|
61
70
|
def ρσ_ord(x):
|
|
62
71
|
ans = x.charCodeAt(0)
|
|
63
72
|
if 0xD800 <= ans <= 0xDBFF:
|
|
@@ -67,15 +76,18 @@ def ρσ_ord(x):
|
|
|
67
76
|
raise TypeError('string is missing the low surrogate char')
|
|
68
77
|
return ans
|
|
69
78
|
|
|
79
|
+
|
|
70
80
|
def ρσ_chr(code):
|
|
71
81
|
if code <= 0xFFFF:
|
|
72
82
|
return String.fromCharCode(code)
|
|
73
83
|
code -= 0x10000
|
|
74
|
-
return String.fromCharCode(0xD800+(code>>10), 0xDC00+(code&0x3FF))
|
|
84
|
+
return String.fromCharCode(0xD800 + (code >> 10), 0xDC00 + (code & 0x3FF))
|
|
85
|
+
|
|
75
86
|
|
|
76
87
|
def ρσ_callable(x):
|
|
77
88
|
return v'typeof x === "function"'
|
|
78
89
|
|
|
90
|
+
|
|
79
91
|
def ρσ_bin(x):
|
|
80
92
|
if jstype(x) is not 'number' or x % 1 is not 0:
|
|
81
93
|
raise TypeError('integer required')
|
|
@@ -86,6 +98,7 @@ def ρσ_bin(x):
|
|
|
86
98
|
ans = '0b' + ans
|
|
87
99
|
return ans
|
|
88
100
|
|
|
101
|
+
|
|
89
102
|
def ρσ_hex(x):
|
|
90
103
|
if jstype(x) is not 'number' or x % 1 is not 0:
|
|
91
104
|
raise TypeError('integer required')
|
|
@@ -96,21 +109,22 @@ def ρσ_hex(x):
|
|
|
96
109
|
ans = '0x' + ans
|
|
97
110
|
return ans
|
|
98
111
|
|
|
112
|
+
|
|
99
113
|
def ρσ_enumerate(iterable):
|
|
100
114
|
ans = v'{"_i":-1}'
|
|
101
|
-
ans[ρσ_iterator_symbol] = def():
|
|
115
|
+
ans[ρσ_iterator_symbol] = def ():
|
|
102
116
|
return this
|
|
103
117
|
if ρσ_arraylike(iterable):
|
|
104
|
-
ans['next'] = def():
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
118
|
+
ans['next'] = def ():
|
|
119
|
+
this._i += 1
|
|
120
|
+
if this._i < iterable.length:
|
|
121
|
+
return v"{'done':false, 'value':[this._i, iterable[this._i]]}"
|
|
122
|
+
return v"{'done':true}"
|
|
109
123
|
return ans
|
|
110
124
|
if jstype(iterable[ρσ_iterator_symbol]) is 'function':
|
|
111
125
|
iterator = iterable.keys() if jstype(Map) is 'function' and v'iterable instanceof Map' else iterable[ρσ_iterator_symbol]()
|
|
112
126
|
ans['_iterator'] = iterator
|
|
113
|
-
ans['next'] = def():
|
|
127
|
+
ans['next'] = def ():
|
|
114
128
|
r = this._iterator.next()
|
|
115
129
|
if r.done:
|
|
116
130
|
return v"{'done':true}"
|
|
@@ -119,28 +133,30 @@ def ρσ_enumerate(iterable):
|
|
|
119
133
|
return ans
|
|
120
134
|
return ρσ_enumerate(Object.keys(iterable))
|
|
121
135
|
|
|
136
|
+
|
|
122
137
|
def ρσ_reversed(iterable):
|
|
123
138
|
if ρσ_arraylike(iterable):
|
|
124
139
|
ans = v'{"_i": iterable.length}'
|
|
125
|
-
ans['next'] = def():
|
|
140
|
+
ans['next'] = def ():
|
|
126
141
|
this._i -= 1
|
|
127
142
|
if this._i > -1:
|
|
128
143
|
return v"{'done':false, 'value':iterable[this._i]}"
|
|
129
144
|
return v"{'done':true}"
|
|
130
|
-
ans[ρσ_iterator_symbol] = def():
|
|
145
|
+
ans[ρσ_iterator_symbol] = def ():
|
|
131
146
|
return this
|
|
132
147
|
return ans
|
|
133
148
|
raise TypeError('reversed() can only be called on arrays or strings')
|
|
134
149
|
|
|
150
|
+
|
|
135
151
|
def ρσ_iter(iterable):
|
|
136
152
|
# Generate a JavaScript iterator object from iterable
|
|
137
153
|
if jstype(iterable[ρσ_iterator_symbol]) is 'function':
|
|
138
154
|
return iterable.keys() if jstype(Map) is 'function' and v'iterable instanceof Map' else iterable[ρσ_iterator_symbol]()
|
|
139
155
|
if ρσ_arraylike(iterable):
|
|
140
156
|
ans = v'{"_i":-1}'
|
|
141
|
-
ans[ρσ_iterator_symbol] = def():
|
|
157
|
+
ans[ρσ_iterator_symbol] = def ():
|
|
142
158
|
return this
|
|
143
|
-
ans['next'] = def():
|
|
159
|
+
ans['next'] = def ():
|
|
144
160
|
this._i += 1
|
|
145
161
|
if this._i < iterable.length:
|
|
146
162
|
return v"{'done':false, 'value':iterable[this._i]}"
|
|
@@ -148,6 +164,7 @@ def ρσ_iter(iterable):
|
|
|
148
164
|
return ans
|
|
149
165
|
return ρσ_iter(Object.keys(iterable))
|
|
150
166
|
|
|
167
|
+
|
|
151
168
|
def ρσ_range_next(step, length):
|
|
152
169
|
this._i += step
|
|
153
170
|
this._idx += 1
|
|
@@ -156,6 +173,7 @@ def ρσ_range_next(step, length):
|
|
|
156
173
|
return v"{'done':true}"
|
|
157
174
|
return v"{'done':false, 'value':this._i}"
|
|
158
175
|
|
|
176
|
+
|
|
159
177
|
def ρσ_range(start, stop, step):
|
|
160
178
|
if arguments.length <= 1:
|
|
161
179
|
stop = start or 0
|
|
@@ -163,28 +181,28 @@ def ρσ_range(start, stop, step):
|
|
|
163
181
|
step = arguments[2] or 1
|
|
164
182
|
length = Math.max(Math.ceil((stop - start) / step), 0)
|
|
165
183
|
ans = v'{start:start, step:step, stop:stop}'
|
|
166
|
-
ans[ρσ_iterator_symbol] = def():
|
|
184
|
+
ans[ρσ_iterator_symbol] = def ():
|
|
167
185
|
it = v'{"_i": start - step, "_idx": -1}'
|
|
168
186
|
it.next = ρσ_range_next.bind(it, step, length)
|
|
169
|
-
it[ρσ_iterator_symbol] = def():
|
|
187
|
+
it[ρσ_iterator_symbol] = def ():
|
|
170
188
|
return this
|
|
171
189
|
return it
|
|
172
|
-
ans.count = def(val):
|
|
190
|
+
ans.count = def (val):
|
|
173
191
|
if not this._cached:
|
|
174
192
|
this._cached = list(this)
|
|
175
193
|
return this._cached.count(val)
|
|
176
|
-
ans.index = def(val):
|
|
194
|
+
ans.index = def (val):
|
|
177
195
|
if not this._cached:
|
|
178
196
|
this._cached = list(this)
|
|
179
197
|
return this._cached.index(val)
|
|
180
|
-
ans.__len__ = def():
|
|
198
|
+
ans.__len__ = def ():
|
|
181
199
|
return length
|
|
182
|
-
ans.__repr__ = def():
|
|
200
|
+
ans.__repr__ = def ():
|
|
183
201
|
return f'range({start}, {stop}, {step})'
|
|
184
202
|
ans.__str__ = ans.toString = ans.__repr__
|
|
185
203
|
if jstype(Proxy) is 'function':
|
|
186
204
|
ans = new Proxy(ans, {
|
|
187
|
-
'get': def(obj, prop):
|
|
205
|
+
'get': def (obj, prop):
|
|
188
206
|
if jstype(prop) is 'string':
|
|
189
207
|
iprop = parseInt(prop)
|
|
190
208
|
if not isNaN(iprop):
|
|
@@ -197,6 +215,7 @@ def ρσ_range(start, stop, step):
|
|
|
197
215
|
})
|
|
198
216
|
return ans
|
|
199
217
|
|
|
218
|
+
|
|
200
219
|
def ρσ_getattr(obj, name, defval):
|
|
201
220
|
try:
|
|
202
221
|
ret = obj[name]
|
|
@@ -210,37 +229,39 @@ def ρσ_getattr(obj, name, defval):
|
|
|
210
229
|
ret = defval
|
|
211
230
|
return ret
|
|
212
231
|
|
|
232
|
+
|
|
213
233
|
def ρσ_setattr(obj, name, value):
|
|
214
234
|
obj[name] = value
|
|
215
235
|
|
|
236
|
+
|
|
216
237
|
def ρσ_hasattr(obj, name):
|
|
217
238
|
return v'name in obj'
|
|
218
239
|
|
|
219
240
|
ρσ_len = (def ():
|
|
220
|
-
|
|
221
241
|
def len(obj):
|
|
222
242
|
if ρσ_arraylike(obj): return obj.length
|
|
223
243
|
if jstype(obj.__len__) is 'function': return obj.__len__()
|
|
224
244
|
if v'obj instanceof Set' or v'obj instanceof Map': return obj.size
|
|
225
245
|
return Object.keys(obj).length
|
|
226
|
-
|
|
227
246
|
def len5(obj):
|
|
228
247
|
if ρσ_arraylike(obj): return obj.length
|
|
229
248
|
if jstype(obj.__len__) is 'function': return obj.__len__()
|
|
230
249
|
return Object.keys(obj).length
|
|
231
|
-
|
|
232
250
|
return len if v'typeof Set' is 'function' and v'typeof Map' is 'function' else len5
|
|
233
251
|
)()
|
|
234
252
|
|
|
253
|
+
|
|
235
254
|
def ρσ_get_module(name):
|
|
236
255
|
return ρσ_modules[name]
|
|
237
256
|
|
|
257
|
+
|
|
238
258
|
def ρσ_pow(x, y, z):
|
|
239
259
|
ans = Math.pow(x, y)
|
|
240
260
|
if z is not undefined:
|
|
241
261
|
ans %= z
|
|
242
262
|
return ans
|
|
243
263
|
|
|
264
|
+
|
|
244
265
|
def ρσ_type(x):
|
|
245
266
|
return x.constructor
|
|
246
267
|
|