rapydscript-ng 0.8.0 → 0.8.1
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 +9 -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 +262 -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
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
# globals:ρσ_iterator_symbol, ρσ_kwargs_symbol, ρσ_arraylike, ρσ_repr
|
|
6
6
|
|
|
7
|
+
|
|
7
8
|
def ρσ_equals(a, b):
|
|
8
9
|
if a is b:
|
|
9
10
|
return True
|
|
@@ -21,18 +22,19 @@ def ρσ_equals(a, b):
|
|
|
21
22
|
if jstype(a) is 'object' and jstype(b) is 'object' and a is not None and b is not None and (
|
|
22
23
|
(a.constructor is Object and b.constructor is Object) or (Object.getPrototypeOf(a) is None and Object.getPrototypeOf(b) is None)
|
|
23
24
|
):
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
# Do a dict like comparison as this is most likely either a JS has
|
|
26
|
+
# (Object.create(null) or a JS object used as a hash (v"{}"))
|
|
27
|
+
akeys, bkeys = Object.keys(a), Object.keys(b)
|
|
28
|
+
if akeys.length is not bkeys.length:
|
|
29
|
+
return False
|
|
30
|
+
for v'var j=0; j < akeys.length; j++':
|
|
31
|
+
key = akeys[j]
|
|
32
|
+
if not (a[key] == b[key]):
|
|
28
33
|
return False
|
|
29
|
-
|
|
30
|
-
key = akeys[j]
|
|
31
|
-
if not (a[key] == b[key]):
|
|
32
|
-
return False
|
|
33
|
-
return True
|
|
34
|
+
return True
|
|
34
35
|
return False
|
|
35
36
|
|
|
37
|
+
|
|
36
38
|
def ρσ_not_equals(a, b):
|
|
37
39
|
if a is b:
|
|
38
40
|
return False
|
|
@@ -46,19 +48,21 @@ v'var equals = ρσ_equals'
|
|
|
46
48
|
|
|
47
49
|
# list {{{
|
|
48
50
|
|
|
51
|
+
|
|
49
52
|
def ρσ_list_iterator(value):
|
|
50
53
|
self = this
|
|
51
54
|
return {
|
|
52
|
-
'_i'
|
|
53
|
-
'_list':self,
|
|
54
|
-
'next':def():
|
|
55
|
+
'_i': -1,
|
|
56
|
+
'_list': self,
|
|
57
|
+
'next': def ():
|
|
55
58
|
this._i += 1
|
|
56
59
|
if this._i >= this._list.length:
|
|
57
|
-
return {'done':True}
|
|
58
|
-
return {'done':False, 'value':this._list[this._i]}
|
|
60
|
+
return {'done': True}
|
|
61
|
+
return {'done': False, 'value': this._list[this._i]}
|
|
59
62
|
,
|
|
60
63
|
}
|
|
61
64
|
|
|
65
|
+
|
|
62
66
|
def ρσ_list_constructor(iterable):
|
|
63
67
|
if iterable is undefined:
|
|
64
68
|
ans = v'[]'
|
|
@@ -88,7 +92,7 @@ if v'typeof Array.prototype.append' is not 'function':
|
|
|
88
92
|
});
|
|
89
93
|
Object.defineProperty(Array.prototype, 'extend', {
|
|
90
94
|
'writable': False, 'configurable': False, 'enumerable': False,
|
|
91
|
-
'value': def(iterable):
|
|
95
|
+
'value': def (iterable):
|
|
92
96
|
if Array.isArray(iterable) or jstype(iterable) is 'string':
|
|
93
97
|
# Allocate all new memory in one operation
|
|
94
98
|
start = this.length
|
|
@@ -104,7 +108,7 @@ if v'typeof Array.prototype.append' is not 'function':
|
|
|
104
108
|
});
|
|
105
109
|
Object.defineProperty(Array.prototype, 'index', {
|
|
106
110
|
'writable': False, 'configurable': False, 'enumerable': False,
|
|
107
|
-
'value': def(val, start, stop):
|
|
111
|
+
'value': def (val, start, stop):
|
|
108
112
|
start = start or 0
|
|
109
113
|
if start < 0:
|
|
110
114
|
start = this.length + start
|
|
@@ -121,7 +125,7 @@ if v'typeof Array.prototype.append' is not 'function':
|
|
|
121
125
|
});
|
|
122
126
|
Object.defineProperty(Array.prototype, 'pypop', {
|
|
123
127
|
'writable': False, 'configurable': False, 'enumerable': False,
|
|
124
|
-
'value': def(index):
|
|
128
|
+
'value': def (index):
|
|
125
129
|
if this.length is 0:
|
|
126
130
|
raise IndexError('list is empty')
|
|
127
131
|
if index is undefined:
|
|
@@ -133,7 +137,7 @@ if v'typeof Array.prototype.append' is not 'function':
|
|
|
133
137
|
});
|
|
134
138
|
Object.defineProperty(Array.prototype, 'remove', {
|
|
135
139
|
'writable': False, 'configurable': False, 'enumerable': False,
|
|
136
|
-
'value': def(value):
|
|
140
|
+
'value': def (value):
|
|
137
141
|
for v'var i = 0; i < this.length; i++':
|
|
138
142
|
if this[i] == value:
|
|
139
143
|
this.splice(i, 1)
|
|
@@ -142,15 +146,15 @@ if v'typeof Array.prototype.append' is not 'function':
|
|
|
142
146
|
});
|
|
143
147
|
Object.defineProperty(Array.prototype, 'toString', {
|
|
144
148
|
'writable': False, 'configurable': False, 'enumerable': False,
|
|
145
|
-
'value': def(): return '[' + this.join(', ') + ']'
|
|
149
|
+
'value': def (): return '[' + this.join(', ') + ']'
|
|
146
150
|
});
|
|
147
151
|
Object.defineProperty(Array.prototype, 'inspect', {
|
|
148
152
|
'writable': False, 'configurable': False, 'enumerable': False,
|
|
149
|
-
'value': def(): return '[' + this.join(', ') + ']'
|
|
153
|
+
'value': def (): return '[' + this.join(', ') + ']'
|
|
150
154
|
});
|
|
151
155
|
Object.defineProperty(Array.prototype, 'insert', {
|
|
152
156
|
'writable': False, 'configurable': False, 'enumerable': False,
|
|
153
|
-
'value': def(index, val):
|
|
157
|
+
'value': def (index, val):
|
|
154
158
|
if index < 0:
|
|
155
159
|
index += this.length
|
|
156
160
|
index = min(this.length, max(index, 0))
|
|
@@ -163,19 +167,19 @@ if v'typeof Array.prototype.append' is not 'function':
|
|
|
163
167
|
});
|
|
164
168
|
Object.defineProperty(Array.prototype, 'copy', {
|
|
165
169
|
'writable': False, 'configurable': False, 'enumerable': False,
|
|
166
|
-
'value': def(): return ρσ_list_constructor(this)
|
|
170
|
+
'value': def (): return ρσ_list_constructor(this)
|
|
167
171
|
});
|
|
168
172
|
Object.defineProperty(Array.prototype, 'clear', {
|
|
169
173
|
'writable': False, 'configurable': False, 'enumerable': False,
|
|
170
|
-
'value': def(): this.length = 0
|
|
174
|
+
'value': def (): this.length = 0
|
|
171
175
|
});
|
|
172
176
|
Object.defineProperty(Array.prototype, 'count', {
|
|
173
177
|
'writable': False, 'configurable': False, 'enumerable': False,
|
|
174
|
-
'value': def(value): return this.reduce(def(n, val): return n + (val is value);, 0)
|
|
178
|
+
'value': def (value): return this.reduce(def (n, val): return n + (val is value);, 0)
|
|
175
179
|
});
|
|
176
180
|
Object.defineProperty(Array.prototype, 'pysort', {
|
|
177
181
|
'writable': False, 'configurable': False, 'enumerable': False,
|
|
178
|
-
'value': def(key=None, reverse=False):
|
|
182
|
+
'value': def (key = None, reverse = False):
|
|
179
183
|
def _sort_key(value):
|
|
180
184
|
t = jstype(value)
|
|
181
185
|
if t is 'string' or t is 'number':
|
|
@@ -199,15 +203,15 @@ if v'typeof Array.prototype.append' is not 'function':
|
|
|
199
203
|
});
|
|
200
204
|
Object.defineProperty(Array.prototype, 'as_array', {
|
|
201
205
|
'writable': False, 'configurable': False, 'enumerable': False,
|
|
202
|
-
'value': def(): return Array.from(this)
|
|
206
|
+
'value': def (): return Array.from (this)
|
|
203
207
|
});
|
|
204
208
|
Object.defineProperty(Array.prototype, '__len__', {
|
|
205
209
|
'writable': False, 'configurable': False, 'enumerable': False,
|
|
206
|
-
'value': def(): return this.length
|
|
210
|
+
'value': def (): return this.length
|
|
207
211
|
});
|
|
208
212
|
Object.defineProperty(Array.prototype, '__contains__', {
|
|
209
213
|
'writable': False, 'configurable': False, 'enumerable': False,
|
|
210
|
-
'value': def(val):
|
|
214
|
+
'value': def (val):
|
|
211
215
|
for v'var i = 0; i < this.length; i++':
|
|
212
216
|
if this[i] == val:
|
|
213
217
|
return True
|
|
@@ -215,7 +219,7 @@ if v'typeof Array.prototype.append' is not 'function':
|
|
|
215
219
|
});
|
|
216
220
|
Object.defineProperty(Array.prototype, '__eq__', {
|
|
217
221
|
'writable': False, 'configurable': False, 'enumerable': False,
|
|
218
|
-
'value': def(other):
|
|
222
|
+
'value': def (other):
|
|
219
223
|
if not ρσ_arraylike(other):
|
|
220
224
|
return False
|
|
221
225
|
if this.length != other.length:
|
|
@@ -230,11 +234,13 @@ if v'typeof Array.prototype.append' is not 'function':
|
|
|
230
234
|
'value': ρσ_list_constructor,
|
|
231
235
|
});
|
|
232
236
|
|
|
237
|
+
|
|
233
238
|
def ρσ_list_decorate(ans):
|
|
234
239
|
return ans
|
|
235
240
|
|
|
236
241
|
v'var list = ρσ_list_constructor, list_wrap = ρσ_list_decorate'
|
|
237
242
|
|
|
243
|
+
|
|
238
244
|
def sorted(iterable, key=None, reverse=False):
|
|
239
245
|
ans = ρσ_list_constructor(iterable)
|
|
240
246
|
ans.pysort(key, reverse)
|
|
@@ -244,34 +250,36 @@ def sorted(iterable, key=None, reverse=False):
|
|
|
244
250
|
# set {{{
|
|
245
251
|
v'var ρσ_global_object_id = 0, ρσ_set_implementation'
|
|
246
252
|
|
|
253
|
+
|
|
247
254
|
def ρσ_set_keyfor(x):
|
|
248
255
|
t = jstype(x)
|
|
249
256
|
if t is 'string' or t is 'number' or t is 'boolean':
|
|
250
257
|
return '_' + t[0] + x
|
|
251
|
-
if v'x === null':
|
|
252
|
-
return
|
|
258
|
+
if v'x === null': # also matches undefined
|
|
259
|
+
return '__!@#$0'
|
|
253
260
|
ans = x.ρσ_hash_key_prop
|
|
254
261
|
if ans is undefined:
|
|
255
262
|
v'ans = "_!@#$" + (++ρσ_global_object_id)'
|
|
256
|
-
Object.defineProperty(x, 'ρσ_hash_key_prop', {
|
|
263
|
+
Object.defineProperty(x, 'ρσ_hash_key_prop', {'value': ans})
|
|
257
264
|
return ans
|
|
258
265
|
|
|
266
|
+
|
|
259
267
|
def ρσ_set_polyfill():
|
|
260
268
|
this._store = {}
|
|
261
269
|
this.size = 0
|
|
262
270
|
|
|
263
|
-
ρσ_set_polyfill.prototype.add = def(x):
|
|
271
|
+
ρσ_set_polyfill.prototype.add = def (x):
|
|
264
272
|
key = ρσ_set_keyfor(x)
|
|
265
273
|
if not Object.prototype.hasOwnProperty.call(this._store, key):
|
|
266
274
|
this.size += 1
|
|
267
275
|
this._store[key] = x
|
|
268
276
|
return this
|
|
269
277
|
|
|
270
|
-
ρσ_set_polyfill.prototype.clear = def(x):
|
|
278
|
+
ρσ_set_polyfill.prototype.clear = def (x):
|
|
271
279
|
this._store = {}
|
|
272
280
|
this.size = 0
|
|
273
281
|
|
|
274
|
-
ρσ_set_polyfill.prototype.delete = def(x):
|
|
282
|
+
ρσ_set_polyfill.prototype.delete = def (x):
|
|
275
283
|
key = ρσ_set_keyfor(x)
|
|
276
284
|
if Object.prototype.hasOwnProperty.call(this._store, key):
|
|
277
285
|
this.size -= 1
|
|
@@ -279,14 +287,14 @@ def ρσ_set_polyfill():
|
|
|
279
287
|
return True
|
|
280
288
|
return False
|
|
281
289
|
|
|
282
|
-
ρσ_set_polyfill.prototype.has = def(x):
|
|
290
|
+
ρσ_set_polyfill.prototype.has = def (x):
|
|
283
291
|
return Object.prototype.hasOwnProperty.call(this._store, ρσ_set_keyfor(x))
|
|
284
292
|
|
|
285
|
-
ρσ_set_polyfill.prototype.values = def(x):
|
|
293
|
+
ρσ_set_polyfill.prototype.values = def (x):
|
|
286
294
|
ans = v"{'_keys': Object.keys(this._store), '_i':-1, '_s':this._store}"
|
|
287
|
-
ans[ρσ_iterator_symbol] = def():
|
|
295
|
+
ans[ρσ_iterator_symbol] = def ():
|
|
288
296
|
return this
|
|
289
|
-
ans['next'] = def():
|
|
297
|
+
ans['next'] = def ():
|
|
290
298
|
this._i += 1
|
|
291
299
|
if this._i >= this._keys.length:
|
|
292
300
|
return v"{'done': true}"
|
|
@@ -298,6 +306,7 @@ if jstype(Set) is not 'function' or jstype(Set.prototype.delete) is not 'functio
|
|
|
298
306
|
else:
|
|
299
307
|
v'ρσ_set_implementation = Set'
|
|
300
308
|
|
|
309
|
+
|
|
301
310
|
def ρσ_set(iterable):
|
|
302
311
|
if v'this instanceof ρσ_set':
|
|
303
312
|
this.jsset = new ρσ_set_implementation() # noqa:undef
|
|
@@ -325,19 +334,19 @@ def ρσ_set(iterable):
|
|
|
325
334
|
|
|
326
335
|
# These are for JavaScript users' convenience
|
|
327
336
|
Object.defineProperties(ρσ_set.prototype, {
|
|
328
|
-
'length': {
|
|
329
|
-
'size': {
|
|
337
|
+
'length': {'get': def (): return this.jsset.size;},
|
|
338
|
+
'size': {'get': def (): return this.jsset.size;},
|
|
330
339
|
})
|
|
331
340
|
|
|
332
|
-
ρσ_set.prototype.__len__ = def(): return this.jsset.size
|
|
333
|
-
ρσ_set.prototype.has = ρσ_set.prototype.__contains__ = def(x): return this.jsset.has(x)
|
|
334
|
-
ρσ_set.prototype.add = def(x): this.jsset.add(x)
|
|
335
|
-
ρσ_set.prototype.clear = def(): this.jsset.clear()
|
|
336
|
-
ρσ_set.prototype.copy = def(): return ρσ_set(this)
|
|
337
|
-
ρσ_set.prototype.discard = def(x): this.jsset.delete(x)
|
|
338
|
-
ρσ_set.prototype[ρσ_iterator_symbol] = def(): return this.jsset.values()
|
|
341
|
+
ρσ_set.prototype.__len__ = def (): return this.jsset.size
|
|
342
|
+
ρσ_set.prototype.has = ρσ_set.prototype.__contains__ = def (x): return this.jsset.has(x)
|
|
343
|
+
ρσ_set.prototype.add = def (x): this.jsset.add(x)
|
|
344
|
+
ρσ_set.prototype.clear = def (): this.jsset.clear()
|
|
345
|
+
ρσ_set.prototype.copy = def (): return ρσ_set(this)
|
|
346
|
+
ρσ_set.prototype.discard = def (x): this.jsset.delete(x)
|
|
347
|
+
ρσ_set.prototype[ρσ_iterator_symbol] = def (): return this.jsset.values()
|
|
339
348
|
|
|
340
|
-
ρσ_set.prototype.difference = def():
|
|
349
|
+
ρσ_set.prototype.difference = def ():
|
|
341
350
|
ans = new ρσ_set()
|
|
342
351
|
s = ans.jsset
|
|
343
352
|
iterator = this.jsset.values()
|
|
@@ -354,7 +363,7 @@ Object.defineProperties(ρσ_set.prototype, {
|
|
|
354
363
|
r = iterator.next()
|
|
355
364
|
return ans
|
|
356
365
|
|
|
357
|
-
ρσ_set.prototype.difference_update = def():
|
|
366
|
+
ρσ_set.prototype.difference_update = def ():
|
|
358
367
|
s = this.jsset
|
|
359
368
|
remove = v'[]'
|
|
360
369
|
iterator = s.values()
|
|
@@ -369,7 +378,7 @@ Object.defineProperties(ρσ_set.prototype, {
|
|
|
369
378
|
for v'var j = 0; j < remove.length; j++':
|
|
370
379
|
s.delete(remove[j]) # noqa:undef
|
|
371
380
|
|
|
372
|
-
ρσ_set.prototype.intersection = def():
|
|
381
|
+
ρσ_set.prototype.intersection = def ():
|
|
373
382
|
ans = new ρσ_set()
|
|
374
383
|
s = ans.jsset
|
|
375
384
|
iterator = this.jsset.values()
|
|
@@ -386,7 +395,7 @@ Object.defineProperties(ρσ_set.prototype, {
|
|
|
386
395
|
r = iterator.next()
|
|
387
396
|
return ans
|
|
388
397
|
|
|
389
|
-
ρσ_set.prototype.intersection_update = def():
|
|
398
|
+
ρσ_set.prototype.intersection_update = def ():
|
|
390
399
|
s = this.jsset
|
|
391
400
|
remove = v'[]'
|
|
392
401
|
iterator = s.values()
|
|
@@ -401,7 +410,7 @@ Object.defineProperties(ρσ_set.prototype, {
|
|
|
401
410
|
for v'var j = 0; j < remove.length; j++':
|
|
402
411
|
s.delete(remove[j]) # noqa:undef
|
|
403
412
|
|
|
404
|
-
ρσ_set.prototype.isdisjoint = def(other):
|
|
413
|
+
ρσ_set.prototype.isdisjoint = def (other):
|
|
405
414
|
iterator = this.jsset.values()
|
|
406
415
|
r = iterator.next()
|
|
407
416
|
while not r.done:
|
|
@@ -411,7 +420,7 @@ Object.defineProperties(ρσ_set.prototype, {
|
|
|
411
420
|
r = iterator.next()
|
|
412
421
|
return True
|
|
413
422
|
|
|
414
|
-
ρσ_set.prototype.issubset = def(other):
|
|
423
|
+
ρσ_set.prototype.issubset = def (other):
|
|
415
424
|
iterator = this.jsset.values()
|
|
416
425
|
r = iterator.next()
|
|
417
426
|
while not r.done:
|
|
@@ -421,7 +430,7 @@ Object.defineProperties(ρσ_set.prototype, {
|
|
|
421
430
|
r = iterator.next()
|
|
422
431
|
return True
|
|
423
432
|
|
|
424
|
-
ρσ_set.prototype.issuperset = def(other):
|
|
433
|
+
ρσ_set.prototype.issuperset = def (other):
|
|
425
434
|
s = this.jsset
|
|
426
435
|
iterator = other.jsset.values()
|
|
427
436
|
r = iterator.next()
|
|
@@ -432,7 +441,7 @@ Object.defineProperties(ρσ_set.prototype, {
|
|
|
432
441
|
r = iterator.next()
|
|
433
442
|
return True
|
|
434
443
|
|
|
435
|
-
ρσ_set.prototype.pop = def():
|
|
444
|
+
ρσ_set.prototype.pop = def ():
|
|
436
445
|
iterator = this.jsset.values()
|
|
437
446
|
r = iterator.next()
|
|
438
447
|
if r.done:
|
|
@@ -440,24 +449,24 @@ Object.defineProperties(ρσ_set.prototype, {
|
|
|
440
449
|
this.jsset.delete(r.value)
|
|
441
450
|
return r.value
|
|
442
451
|
|
|
443
|
-
ρσ_set.prototype.remove = def(x):
|
|
452
|
+
ρσ_set.prototype.remove = def (x):
|
|
444
453
|
if not this.jsset.delete(x):
|
|
445
454
|
raise KeyError(x.toString())
|
|
446
455
|
|
|
447
|
-
ρσ_set.prototype.symmetric_difference = def(other):
|
|
456
|
+
ρσ_set.prototype.symmetric_difference = def (other):
|
|
448
457
|
return this.union(other).difference(this.intersection(other))
|
|
449
458
|
|
|
450
|
-
ρσ_set.prototype.symmetric_difference_update = def(other):
|
|
459
|
+
ρσ_set.prototype.symmetric_difference_update = def (other):
|
|
451
460
|
common = this.intersection(other)
|
|
452
461
|
this.update(other)
|
|
453
462
|
this.difference_update(common)
|
|
454
463
|
|
|
455
|
-
ρσ_set.prototype.union = def():
|
|
464
|
+
ρσ_set.prototype.union = def ():
|
|
456
465
|
ans = ρσ_set(this)
|
|
457
466
|
ans.update.apply(ans, arguments)
|
|
458
467
|
return ans
|
|
459
468
|
|
|
460
|
-
ρσ_set.prototype.update = def():
|
|
469
|
+
ρσ_set.prototype.update = def ():
|
|
461
470
|
s = this.jsset
|
|
462
471
|
for v'var i=0; i < arguments.length; i++':
|
|
463
472
|
iterator = arguments[i][ρσ_iterator_symbol]() # noqa:undef
|
|
@@ -466,10 +475,10 @@ Object.defineProperties(ρσ_set.prototype, {
|
|
|
466
475
|
s.add(r.value)
|
|
467
476
|
r = iterator.next()
|
|
468
477
|
|
|
469
|
-
ρσ_set.prototype.toString = ρσ_set.prototype.__repr__ = ρσ_set.prototype.__str__ = ρσ_set.prototype.inspect = def():
|
|
478
|
+
ρσ_set.prototype.toString = ρσ_set.prototype.__repr__ = ρσ_set.prototype.__str__ = ρσ_set.prototype.inspect = def ():
|
|
470
479
|
return '{' + list(this).join(', ') + '}'
|
|
471
480
|
|
|
472
|
-
ρσ_set.prototype.__eq__ = def(other):
|
|
481
|
+
ρσ_set.prototype.__eq__ = def (other):
|
|
473
482
|
if not v'other instanceof this.constructor':
|
|
474
483
|
return False
|
|
475
484
|
if other.size is not this.size:
|
|
@@ -484,6 +493,7 @@ Object.defineProperties(ρσ_set.prototype, {
|
|
|
484
493
|
r = iterator.next()
|
|
485
494
|
return True
|
|
486
495
|
|
|
496
|
+
|
|
487
497
|
def ρσ_set_wrap(x):
|
|
488
498
|
ans = new ρσ_set()
|
|
489
499
|
ans.jsset = x
|
|
@@ -495,22 +505,23 @@ v'var set = ρσ_set, set_wrap = ρσ_set_wrap'
|
|
|
495
505
|
# dict {{{
|
|
496
506
|
v'var ρσ_dict_implementation'
|
|
497
507
|
|
|
508
|
+
|
|
498
509
|
def ρσ_dict_polyfill():
|
|
499
510
|
this._store = {}
|
|
500
511
|
this.size = 0
|
|
501
512
|
|
|
502
|
-
ρσ_dict_polyfill.prototype.set = def(x, value):
|
|
513
|
+
ρσ_dict_polyfill.prototype.set = def (x, value):
|
|
503
514
|
key = ρσ_set_keyfor(x)
|
|
504
515
|
if not Object.prototype.hasOwnProperty.call(this._store, key):
|
|
505
516
|
this.size += 1
|
|
506
517
|
this._store[key] = v'[x, value]'
|
|
507
518
|
return this
|
|
508
519
|
|
|
509
|
-
ρσ_dict_polyfill.prototype.clear = def(x):
|
|
520
|
+
ρσ_dict_polyfill.prototype.clear = def (x):
|
|
510
521
|
this._store = {}
|
|
511
522
|
this.size = 0
|
|
512
523
|
|
|
513
|
-
ρσ_dict_polyfill.prototype.delete = def(x):
|
|
524
|
+
ρσ_dict_polyfill.prototype.delete = def (x):
|
|
514
525
|
key = ρσ_set_keyfor(x)
|
|
515
526
|
if Object.prototype.hasOwnProperty.call(this._store, key):
|
|
516
527
|
this.size -= 1
|
|
@@ -518,42 +529,42 @@ def ρσ_dict_polyfill():
|
|
|
518
529
|
return True
|
|
519
530
|
return False
|
|
520
531
|
|
|
521
|
-
ρσ_dict_polyfill.prototype.has = def(x):
|
|
532
|
+
ρσ_dict_polyfill.prototype.has = def (x):
|
|
522
533
|
return Object.prototype.hasOwnProperty.call(this._store, ρσ_set_keyfor(x))
|
|
523
534
|
|
|
524
|
-
ρσ_dict_polyfill.prototype.get = def(x):
|
|
535
|
+
ρσ_dict_polyfill.prototype.get = def (x):
|
|
525
536
|
try:
|
|
526
537
|
return this._store[ρσ_set_keyfor(x)][1]
|
|
527
538
|
except TypeError: # Key is not present
|
|
528
539
|
return undefined
|
|
529
540
|
|
|
530
|
-
ρσ_dict_polyfill.prototype.values = def(x):
|
|
541
|
+
ρσ_dict_polyfill.prototype.values = def (x):
|
|
531
542
|
ans = v"{'_keys': Object.keys(this._store), '_i':-1, '_s':this._store}"
|
|
532
|
-
ans[ρσ_iterator_symbol] = def():
|
|
543
|
+
ans[ρσ_iterator_symbol] = def ():
|
|
533
544
|
return this
|
|
534
|
-
ans['next'] = def():
|
|
545
|
+
ans['next'] = def ():
|
|
535
546
|
this._i += 1
|
|
536
547
|
if this._i >= this._keys.length:
|
|
537
548
|
return v"{'done': true}"
|
|
538
549
|
return v"{'done':false, 'value':this._s[this._keys[this._i]][1]}"
|
|
539
550
|
return ans
|
|
540
551
|
|
|
541
|
-
ρσ_dict_polyfill.prototype.keys = def(x):
|
|
552
|
+
ρσ_dict_polyfill.prototype.keys = def (x):
|
|
542
553
|
ans = v"{'_keys': Object.keys(this._store), '_i':-1, '_s':this._store}"
|
|
543
|
-
ans[ρσ_iterator_symbol] = def():
|
|
554
|
+
ans[ρσ_iterator_symbol] = def ():
|
|
544
555
|
return this
|
|
545
|
-
ans['next'] = def():
|
|
556
|
+
ans['next'] = def ():
|
|
546
557
|
this._i += 1
|
|
547
558
|
if this._i >= this._keys.length:
|
|
548
559
|
return v"{'done': true}"
|
|
549
560
|
return v"{'done':false, 'value':this._s[this._keys[this._i]][0]}"
|
|
550
561
|
return ans
|
|
551
562
|
|
|
552
|
-
ρσ_dict_polyfill.prototype.entries = def(x):
|
|
563
|
+
ρσ_dict_polyfill.prototype.entries = def (x):
|
|
553
564
|
ans = v"{'_keys': Object.keys(this._store), '_i':-1, '_s':this._store}"
|
|
554
|
-
ans[ρσ_iterator_symbol] = def():
|
|
565
|
+
ans[ρσ_iterator_symbol] = def ():
|
|
555
566
|
return this
|
|
556
|
-
ans['next'] = def():
|
|
567
|
+
ans['next'] = def ():
|
|
557
568
|
this._i += 1
|
|
558
569
|
if this._i >= this._keys.length:
|
|
559
570
|
return v"{'done': true}"
|
|
@@ -565,6 +576,7 @@ if jstype(Map) is not 'function' or jstype(Map.prototype.delete) is not 'functio
|
|
|
565
576
|
else:
|
|
566
577
|
v'ρσ_dict_implementation = Map'
|
|
567
578
|
|
|
579
|
+
|
|
568
580
|
def ρσ_dict(iterable, **kw):
|
|
569
581
|
if v'this instanceof ρσ_dict':
|
|
570
582
|
this.jsmap = new ρσ_dict_implementation() # noqa:undef
|
|
@@ -579,20 +591,20 @@ def ρσ_dict(iterable, **kw):
|
|
|
579
591
|
|
|
580
592
|
# These are for JavaScript users' convenience
|
|
581
593
|
Object.defineProperties(ρσ_dict.prototype, {
|
|
582
|
-
'length': {
|
|
583
|
-
'size': {
|
|
594
|
+
'length': {'get': def (): return this.jsmap.size;},
|
|
595
|
+
'size': {'get': def (): return this.jsmap.size;},
|
|
584
596
|
})
|
|
585
597
|
|
|
586
|
-
ρσ_dict.prototype.__len__ = def(): return this.jsmap.size
|
|
587
|
-
ρσ_dict.prototype.has = ρσ_dict.prototype.__contains__ = def(x): return this.jsmap.has(x)
|
|
588
|
-
ρσ_dict.prototype.set = ρσ_dict.prototype.__setitem__ = def(key, value): this.jsmap.set(key, value)
|
|
598
|
+
ρσ_dict.prototype.__len__ = def (): return this.jsmap.size
|
|
599
|
+
ρσ_dict.prototype.has = ρσ_dict.prototype.__contains__ = def (x): return this.jsmap.has(x)
|
|
600
|
+
ρσ_dict.prototype.set = ρσ_dict.prototype.__setitem__ = def (key, value): this.jsmap.set(key, value)
|
|
589
601
|
ρσ_dict.prototype.__delitem__ = def (key): this.jsmap.delete(key)
|
|
590
|
-
ρσ_dict.prototype.clear = def(): this.jsmap.clear()
|
|
591
|
-
ρσ_dict.prototype.copy = def(): return ρσ_dict(this)
|
|
592
|
-
ρσ_dict.prototype.keys = def(): return this.jsmap.keys()
|
|
593
|
-
ρσ_dict.prototype.values = def(): return this.jsmap.values()
|
|
594
|
-
ρσ_dict.prototype.items = ρσ_dict.prototype.entries = def(): return this.jsmap.entries()
|
|
595
|
-
ρσ_dict.prototype[ρσ_iterator_symbol] = def(): return this.jsmap.keys()
|
|
602
|
+
ρσ_dict.prototype.clear = def (): this.jsmap.clear()
|
|
603
|
+
ρσ_dict.prototype.copy = def (): return ρσ_dict(this)
|
|
604
|
+
ρσ_dict.prototype.keys = def (): return this.jsmap.keys()
|
|
605
|
+
ρσ_dict.prototype.values = def (): return this.jsmap.values()
|
|
606
|
+
ρσ_dict.prototype.items = ρσ_dict.prototype.entries = def (): return this.jsmap.entries()
|
|
607
|
+
ρσ_dict.prototype[ρσ_iterator_symbol] = def (): return this.jsmap.keys()
|
|
596
608
|
|
|
597
609
|
ρσ_dict.prototype.__getitem__ = def (key):
|
|
598
610
|
ans = this.jsmap.get(key)
|
|
@@ -613,7 +625,7 @@ Object.defineProperties(ρσ_dict.prototype, {
|
|
|
613
625
|
return defval
|
|
614
626
|
return j.get(key)
|
|
615
627
|
|
|
616
|
-
ρσ_dict.fromkeys = ρσ_dict.prototype.fromkeys = def (iterable, value=None):
|
|
628
|
+
ρσ_dict.fromkeys = ρσ_dict.prototype.fromkeys = def (iterable, value = None):
|
|
617
629
|
ans = ρσ_dict()
|
|
618
630
|
iterator = iter(iterable)
|
|
619
631
|
r = iterator.next()
|
|
@@ -677,7 +689,7 @@ Object.defineProperties(ρσ_dict.prototype, {
|
|
|
677
689
|
if arguments.length > 1:
|
|
678
690
|
ρσ_dict.prototype.update.call(this, arguments[1])
|
|
679
691
|
|
|
680
|
-
ρσ_dict.prototype.toString = ρσ_dict.prototype.inspect = ρσ_dict.prototype.__str__ = ρσ_dict.prototype.__repr__ = def():
|
|
692
|
+
ρσ_dict.prototype.toString = ρσ_dict.prototype.inspect = ρσ_dict.prototype.__str__ = ρσ_dict.prototype.__repr__ = def ():
|
|
681
693
|
entries = v'[]'
|
|
682
694
|
iterator = this.jsmap.entries()
|
|
683
695
|
r = iterator.next()
|
|
@@ -686,7 +698,7 @@ Object.defineProperties(ρσ_dict.prototype, {
|
|
|
686
698
|
r = iterator.next()
|
|
687
699
|
return '{' + entries.join(', ') + '}'
|
|
688
700
|
|
|
689
|
-
ρσ_dict.prototype.__eq__ = def(other):
|
|
701
|
+
ρσ_dict.prototype.__eq__ = def (other):
|
|
690
702
|
if not v'(other instanceof this.constructor)':
|
|
691
703
|
return False
|
|
692
704
|
if other.size is not this.size:
|
|
@@ -702,7 +714,7 @@ Object.defineProperties(ρσ_dict.prototype, {
|
|
|
702
714
|
r = iterator.next()
|
|
703
715
|
return True
|
|
704
716
|
|
|
705
|
-
ρσ_dict.prototype.as_object = def(other):
|
|
717
|
+
ρσ_dict.prototype.as_object = def (other):
|
|
706
718
|
ans = {}
|
|
707
719
|
iterator = this.jsmap.entries()
|
|
708
720
|
r = iterator.next()
|
|
@@ -711,6 +723,7 @@ Object.defineProperties(ρσ_dict.prototype, {
|
|
|
711
723
|
r = iterator.next()
|
|
712
724
|
return ans
|
|
713
725
|
|
|
726
|
+
|
|
714
727
|
def ρσ_dict_wrap(x):
|
|
715
728
|
ans = new ρσ_dict()
|
|
716
729
|
ans.jsmap = x
|
package/src/baselib-errors.pyj
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
NameError = ReferenceError
|
|
7
7
|
|
|
8
|
-
class Exception(Error):
|
|
9
8
|
|
|
9
|
+
class Exception(Error):
|
|
10
10
|
def __init__(self, message):
|
|
11
11
|
self.message = message
|
|
12
12
|
self.stack = Error().stack
|
|
@@ -15,23 +15,30 @@ class Exception(Error):
|
|
|
15
15
|
def __repr__(self):
|
|
16
16
|
return self.name + ': ' + self.message
|
|
17
17
|
|
|
18
|
+
|
|
18
19
|
class AttributeError(Exception):
|
|
19
20
|
pass
|
|
20
21
|
|
|
22
|
+
|
|
21
23
|
class IndexError(Exception):
|
|
22
24
|
pass
|
|
23
25
|
|
|
26
|
+
|
|
24
27
|
class KeyError(Exception):
|
|
25
28
|
pass
|
|
26
29
|
|
|
30
|
+
|
|
27
31
|
class ValueError(Exception):
|
|
28
32
|
pass
|
|
29
33
|
|
|
34
|
+
|
|
30
35
|
class UnicodeDecodeError(Exception):
|
|
31
36
|
pass
|
|
32
37
|
|
|
38
|
+
|
|
33
39
|
class AssertionError(Exception):
|
|
34
40
|
pass
|
|
35
41
|
|
|
42
|
+
|
|
36
43
|
class ZeroDivisionError(Exception):
|
|
37
44
|
pass
|