rapydscript-ns 0.8.0
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/.agignore +1 -0
- package/.gitattributes +4 -0
- package/.github/workflows/ci.yml +38 -0
- package/.github/workflows/web-repl-page-deploy.yml +42 -0
- package/=template.pyj +5 -0
- package/CHANGELOG.md +456 -0
- package/CONTRIBUTORS +13 -0
- package/HACKING.md +103 -0
- package/LICENSE +24 -0
- package/README.md +2512 -0
- package/TODO.md +327 -0
- package/add-toc-to-readme +2 -0
- package/bin/export +75 -0
- package/bin/rapydscript +70 -0
- package/bin/web-repl-export +102 -0
- package/build +3 -0
- package/package.json +46 -0
- package/publish.py +37 -0
- package/release/baselib-plain-pretty.js +4370 -0
- package/release/baselib-plain-ugly.js +3 -0
- package/release/compiler.js +18394 -0
- package/release/signatures.json +31 -0
- package/session.vim +4 -0
- package/setup.cfg +2 -0
- package/src/ast.pyj +1356 -0
- package/src/baselib-builtins.pyj +279 -0
- package/src/baselib-containers.pyj +723 -0
- package/src/baselib-errors.pyj +37 -0
- package/src/baselib-internal.pyj +421 -0
- package/src/baselib-itertools.pyj +97 -0
- package/src/baselib-str.pyj +798 -0
- package/src/compiler.pyj +36 -0
- package/src/errors.pyj +30 -0
- package/src/lib/aes.pyj +646 -0
- package/src/lib/collections.pyj +695 -0
- package/src/lib/elementmaker.pyj +83 -0
- package/src/lib/encodings.pyj +126 -0
- package/src/lib/functools.pyj +148 -0
- package/src/lib/gettext.pyj +569 -0
- package/src/lib/itertools.pyj +580 -0
- package/src/lib/math.pyj +193 -0
- package/src/lib/numpy.pyj +2101 -0
- package/src/lib/operator.pyj +11 -0
- package/src/lib/pythonize.pyj +20 -0
- package/src/lib/random.pyj +118 -0
- package/src/lib/re.pyj +470 -0
- package/src/lib/traceback.pyj +63 -0
- package/src/lib/uuid.pyj +77 -0
- package/src/monaco-language-service/analyzer.js +526 -0
- package/src/monaco-language-service/builtins.js +543 -0
- package/src/monaco-language-service/completions.js +498 -0
- package/src/monaco-language-service/diagnostics.js +643 -0
- package/src/monaco-language-service/dts.js +550 -0
- package/src/monaco-language-service/hover.js +121 -0
- package/src/monaco-language-service/index.js +386 -0
- package/src/monaco-language-service/scope.js +162 -0
- package/src/monaco-language-service/signature.js +144 -0
- package/src/output/__init__.pyj +0 -0
- package/src/output/classes.pyj +296 -0
- package/src/output/codegen.pyj +492 -0
- package/src/output/comments.pyj +45 -0
- package/src/output/exceptions.pyj +105 -0
- package/src/output/functions.pyj +491 -0
- package/src/output/literals.pyj +109 -0
- package/src/output/loops.pyj +444 -0
- package/src/output/modules.pyj +329 -0
- package/src/output/operators.pyj +429 -0
- package/src/output/statements.pyj +463 -0
- package/src/output/stream.pyj +309 -0
- package/src/output/treeshake.pyj +182 -0
- package/src/output/utils.pyj +72 -0
- package/src/parse.pyj +3106 -0
- package/src/string_interpolation.pyj +72 -0
- package/src/tokenizer.pyj +702 -0
- package/src/unicode_aliases.pyj +576 -0
- package/src/utils.pyj +192 -0
- package/test/_import_one.pyj +37 -0
- package/test/_import_two/__init__.pyj +11 -0
- package/test/_import_two/level2/__init__.pyj +0 -0
- package/test/_import_two/level2/deep.pyj +4 -0
- package/test/_import_two/other.pyj +6 -0
- package/test/_import_two/sub.pyj +13 -0
- package/test/aes_vectors.pyj +421 -0
- package/test/annotations.pyj +80 -0
- package/test/baselib.pyj +319 -0
- package/test/classes.pyj +452 -0
- package/test/collections.pyj +152 -0
- package/test/decorators.pyj +77 -0
- package/test/dict_spread.pyj +76 -0
- package/test/docstrings.pyj +39 -0
- package/test/elementmaker_test.pyj +45 -0
- package/test/ellipsis.pyj +49 -0
- package/test/functions.pyj +151 -0
- package/test/generators.pyj +41 -0
- package/test/generic.pyj +370 -0
- package/test/imports.pyj +72 -0
- package/test/internationalization.pyj +73 -0
- package/test/lint.pyj +164 -0
- package/test/loops.pyj +85 -0
- package/test/numpy.pyj +734 -0
- package/test/omit_function_metadata.pyj +20 -0
- package/test/regexp.pyj +55 -0
- package/test/repl.pyj +121 -0
- package/test/scoped_flags.pyj +76 -0
- package/test/starargs.pyj +506 -0
- package/test/starred_assign.pyj +104 -0
- package/test/str.pyj +198 -0
- package/test/subscript_tuple.pyj +53 -0
- package/test/unit/fixtures/fibonacci_expected.js +46 -0
- package/test/unit/index.js +2989 -0
- package/test/unit/language-service-builtins.js +815 -0
- package/test/unit/language-service-completions.js +1067 -0
- package/test/unit/language-service-dts.js +543 -0
- package/test/unit/language-service-hover.js +455 -0
- package/test/unit/language-service-scope.js +833 -0
- package/test/unit/language-service-signature.js +458 -0
- package/test/unit/language-service.js +705 -0
- package/test/unit/run-language-service.js +41 -0
- package/test/unit/web-repl.js +484 -0
- package/tools/build-language-service.js +190 -0
- package/tools/cli.js +547 -0
- package/tools/compile.js +219 -0
- package/tools/compiler.js +108 -0
- package/tools/completer.js +131 -0
- package/tools/embedded_compiler.js +251 -0
- package/tools/export.js +316 -0
- package/tools/gettext.js +185 -0
- package/tools/ini.js +65 -0
- package/tools/lint.js +705 -0
- package/tools/msgfmt.js +187 -0
- package/tools/repl.js +223 -0
- package/tools/self.js +162 -0
- package/tools/test.js +118 -0
- package/tools/utils.js +128 -0
- package/tools/web_repl.js +95 -0
- package/try +41 -0
- package/web-repl/env.js +74 -0
- package/web-repl/index.html +163 -0
- package/web-repl/language-service.js +4084 -0
- package/web-repl/main.js +254 -0
- package/web-repl/prism.css +139 -0
- package/web-repl/prism.js +113 -0
- package/web-repl/rapydscript.js +435 -0
- package/web-repl/sha1.js +25 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
# vim:fileencoding=utf-8
|
|
2
|
+
# License: BSD
|
|
3
|
+
# Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
|
4
|
+
|
|
5
|
+
# globals: exports, console, ρσ_iterator_symbol, ρσ_kwargs_symbol, ρσ_arraylike, ρσ_list_contains
|
|
6
|
+
|
|
7
|
+
def ρσ_bool(val):
|
|
8
|
+
return v'!!val'
|
|
9
|
+
|
|
10
|
+
def ρσ_print(*args, **kwargs):
|
|
11
|
+
if v'typeof console' is 'object':
|
|
12
|
+
sep = kwargs.sep if kwargs.sep is not undefined else ' '
|
|
13
|
+
parts = [ρσ_str(a) for a in args]
|
|
14
|
+
console.log(parts.join(sep))
|
|
15
|
+
|
|
16
|
+
def ρσ_int(val, base):
|
|
17
|
+
if jstype(val) is "number":
|
|
18
|
+
ans = val | 0
|
|
19
|
+
else:
|
|
20
|
+
ans = parseInt(val, base or 10)
|
|
21
|
+
if isNaN(ans):
|
|
22
|
+
raise ValueError('Invalid literal for int with base ' + (base or 10) + ': ' + val)
|
|
23
|
+
return ans
|
|
24
|
+
|
|
25
|
+
def ρσ_float(val):
|
|
26
|
+
if jstype(val) is "number":
|
|
27
|
+
ans = val
|
|
28
|
+
else:
|
|
29
|
+
ans = parseFloat(val)
|
|
30
|
+
if isNaN(ans):
|
|
31
|
+
raise ValueError('Could not convert string to float: ' + arguments[0])
|
|
32
|
+
return ans
|
|
33
|
+
|
|
34
|
+
def ρσ_arraylike_creator():
|
|
35
|
+
names = 'Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array'.split(' ')
|
|
36
|
+
if jstype(HTMLCollection) is 'function':
|
|
37
|
+
names = names.concat('HTMLCollection NodeList NamedNodeMap TouchList'.split(' '))
|
|
38
|
+
return def(x):
|
|
39
|
+
if Array.isArray(x) or v'typeof x' is 'string' or names.indexOf(Object.prototype.toString.call(x).slice(8, -1)) > -1:
|
|
40
|
+
return True
|
|
41
|
+
return False
|
|
42
|
+
|
|
43
|
+
def options_object(f):
|
|
44
|
+
return def():
|
|
45
|
+
if v'typeof arguments[arguments.length - 1] === "object"':
|
|
46
|
+
arguments[arguments.length - 1][ρσ_kwargs_symbol] = True
|
|
47
|
+
return f.apply(this, arguments)
|
|
48
|
+
|
|
49
|
+
def ρσ_id(x):
|
|
50
|
+
return x.ρσ_object_id
|
|
51
|
+
|
|
52
|
+
def ρσ_dir(item):
|
|
53
|
+
# TODO: this isn't really representative of real Python's dir(), nor is it
|
|
54
|
+
# an intuitive replacement for "for ... in" loop, need to update this logic
|
|
55
|
+
# and introduce a different way of achieving "for ... in"
|
|
56
|
+
arr = []
|
|
57
|
+
for v'var i in item': arr.push(i) # noqa:undef
|
|
58
|
+
return arr
|
|
59
|
+
|
|
60
|
+
def ρσ_ord(x):
|
|
61
|
+
ans = x.charCodeAt(0)
|
|
62
|
+
if 0xD800 <= ans <= 0xDBFF:
|
|
63
|
+
second = x.charCodeAt(1)
|
|
64
|
+
if 0xDC00 <= second <= 0xDFFF:
|
|
65
|
+
return (ans - 0xD800) * 0x400 + second - 0xDC00 + 0x10000
|
|
66
|
+
raise TypeError('string is missing the low surrogate char')
|
|
67
|
+
return ans
|
|
68
|
+
|
|
69
|
+
def ρσ_chr(code):
|
|
70
|
+
if code <= 0xFFFF:
|
|
71
|
+
return String.fromCharCode(code)
|
|
72
|
+
code -= 0x10000
|
|
73
|
+
return String.fromCharCode(0xD800+(code>>10), 0xDC00+(code&0x3FF))
|
|
74
|
+
|
|
75
|
+
def ρσ_callable(x):
|
|
76
|
+
return v'typeof x === "function"'
|
|
77
|
+
|
|
78
|
+
def ρσ_bin(x):
|
|
79
|
+
if jstype(x) is not 'number' or x % 1 is not 0:
|
|
80
|
+
raise TypeError('integer required')
|
|
81
|
+
ans = x.toString(2)
|
|
82
|
+
if ans[0] is '-':
|
|
83
|
+
ans = '-' + '0b' + ans[1:]
|
|
84
|
+
else:
|
|
85
|
+
ans = '0b' + ans
|
|
86
|
+
return ans
|
|
87
|
+
|
|
88
|
+
def ρσ_hex(x):
|
|
89
|
+
if jstype(x) is not 'number' or x % 1 is not 0:
|
|
90
|
+
raise TypeError('integer required')
|
|
91
|
+
ans = x.toString(16)
|
|
92
|
+
if ans[0] is '-':
|
|
93
|
+
ans = '-' + '0x' + ans[1:]
|
|
94
|
+
else:
|
|
95
|
+
ans = '0x' + ans
|
|
96
|
+
return ans
|
|
97
|
+
|
|
98
|
+
def ρσ_enumerate(iterable):
|
|
99
|
+
ans = v'{"_i":-1}'
|
|
100
|
+
ans[ρσ_iterator_symbol] = def():
|
|
101
|
+
return this
|
|
102
|
+
if ρσ_arraylike(iterable):
|
|
103
|
+
ans['next'] = def():
|
|
104
|
+
this._i += 1
|
|
105
|
+
if this._i < iterable.length:
|
|
106
|
+
return v"{'done':false, 'value':[this._i, iterable[this._i]]}"
|
|
107
|
+
return v"{'done':true}"
|
|
108
|
+
return ans
|
|
109
|
+
if jstype(iterable[ρσ_iterator_symbol]) is 'function':
|
|
110
|
+
iterator = iterable.keys() if jstype(Map) is 'function' and v'iterable instanceof Map' else iterable[ρσ_iterator_symbol]()
|
|
111
|
+
ans['_iterator'] = iterator
|
|
112
|
+
ans['next'] = def():
|
|
113
|
+
r = this._iterator.next()
|
|
114
|
+
if r.done:
|
|
115
|
+
return v"{'done':true}"
|
|
116
|
+
this._i += 1
|
|
117
|
+
return v"{'done':false, 'value':[this._i, r.value]}"
|
|
118
|
+
return ans
|
|
119
|
+
return ρσ_enumerate(Object.keys(iterable))
|
|
120
|
+
|
|
121
|
+
def ρσ_reversed(iterable):
|
|
122
|
+
if ρσ_arraylike(iterable):
|
|
123
|
+
ans = v'{"_i": iterable.length}'
|
|
124
|
+
ans['next'] = def():
|
|
125
|
+
this._i -= 1
|
|
126
|
+
if this._i > -1:
|
|
127
|
+
return v"{'done':false, 'value':iterable[this._i]}"
|
|
128
|
+
return v"{'done':true}"
|
|
129
|
+
ans[ρσ_iterator_symbol] = def():
|
|
130
|
+
return this
|
|
131
|
+
return ans
|
|
132
|
+
raise TypeError('reversed() can only be called on arrays or strings')
|
|
133
|
+
|
|
134
|
+
def ρσ_iter(iterable):
|
|
135
|
+
# Generate a JavaScript iterator object from iterable
|
|
136
|
+
if jstype(iterable[ρσ_iterator_symbol]) is 'function':
|
|
137
|
+
return iterable.keys() if jstype(Map) is 'function' and v'iterable instanceof Map' else iterable[ρσ_iterator_symbol]()
|
|
138
|
+
if ρσ_arraylike(iterable):
|
|
139
|
+
ans = v'{"_i":-1}'
|
|
140
|
+
ans[ρσ_iterator_symbol] = def():
|
|
141
|
+
return this
|
|
142
|
+
ans['next'] = def():
|
|
143
|
+
this._i += 1
|
|
144
|
+
if this._i < iterable.length:
|
|
145
|
+
return v"{'done':false, 'value':iterable[this._i]}"
|
|
146
|
+
return v"{'done':true}"
|
|
147
|
+
return ans
|
|
148
|
+
return ρσ_iter(Object.keys(iterable))
|
|
149
|
+
|
|
150
|
+
def ρσ_range_next(step, length):
|
|
151
|
+
this._i += step
|
|
152
|
+
this._idx += 1
|
|
153
|
+
if this._idx >= length:
|
|
154
|
+
this._i, this._idx = this.__i, -1
|
|
155
|
+
return v"{'done':true}"
|
|
156
|
+
return v"{'done':false, 'value':this._i}"
|
|
157
|
+
|
|
158
|
+
def ρσ_range(start, stop, step):
|
|
159
|
+
if arguments.length <= 1:
|
|
160
|
+
stop = start or 0
|
|
161
|
+
start = 0
|
|
162
|
+
step = arguments[2] or 1
|
|
163
|
+
length = Math.max(Math.ceil((stop - start) / step), 0)
|
|
164
|
+
ans = v'{start:start, step:step, stop:stop}'
|
|
165
|
+
ans[ρσ_iterator_symbol] = def():
|
|
166
|
+
it = v'{"_i": start - step, "_idx": -1}'
|
|
167
|
+
it.next = ρσ_range_next.bind(it, step, length)
|
|
168
|
+
it[ρσ_iterator_symbol] = def():
|
|
169
|
+
return this
|
|
170
|
+
return it
|
|
171
|
+
ans.count = def(val):
|
|
172
|
+
if not this._cached:
|
|
173
|
+
this._cached = list(this)
|
|
174
|
+
return this._cached.count(val)
|
|
175
|
+
ans.index = def(val):
|
|
176
|
+
if not this._cached:
|
|
177
|
+
this._cached = list(this)
|
|
178
|
+
return this._cached.index(val)
|
|
179
|
+
ans.__len__ = def():
|
|
180
|
+
return length
|
|
181
|
+
ans.__repr__ = def():
|
|
182
|
+
return f'range({start}, {stop}, {step})'
|
|
183
|
+
ans.__str__ = ans.toString = ans.__repr__
|
|
184
|
+
if jstype(Proxy) is 'function':
|
|
185
|
+
ans = new Proxy(ans, {
|
|
186
|
+
'get': def(obj, prop):
|
|
187
|
+
if jstype(prop) is 'string':
|
|
188
|
+
iprop = parseInt(prop)
|
|
189
|
+
if not isNaN(iprop):
|
|
190
|
+
prop = iprop
|
|
191
|
+
if jstype(prop) is 'number':
|
|
192
|
+
if not obj._cached:
|
|
193
|
+
obj._cached = list(obj)
|
|
194
|
+
return obj._cached[prop]
|
|
195
|
+
return obj[prop]
|
|
196
|
+
})
|
|
197
|
+
return ans
|
|
198
|
+
|
|
199
|
+
def ρσ_getattr(obj, name, defval):
|
|
200
|
+
try:
|
|
201
|
+
ret = obj[name]
|
|
202
|
+
except TypeError:
|
|
203
|
+
if defval is undefined:
|
|
204
|
+
raise AttributeError('The attribute ' + name + ' is not present')
|
|
205
|
+
return defval
|
|
206
|
+
if ret is undefined and not v'(name in obj)':
|
|
207
|
+
if defval is undefined:
|
|
208
|
+
raise AttributeError('The attribute ' + name + ' is not present')
|
|
209
|
+
ret = defval
|
|
210
|
+
return ret
|
|
211
|
+
|
|
212
|
+
def ρσ_setattr(obj, name, value):
|
|
213
|
+
obj[name] = value
|
|
214
|
+
|
|
215
|
+
def ρσ_hasattr(obj, name):
|
|
216
|
+
return v'name in obj'
|
|
217
|
+
|
|
218
|
+
ρσ_len = (def ():
|
|
219
|
+
|
|
220
|
+
def len(obj):
|
|
221
|
+
if ρσ_arraylike(obj): return obj.length
|
|
222
|
+
if jstype(obj.__len__) is 'function': return obj.__len__()
|
|
223
|
+
if v'obj instanceof Set' or v'obj instanceof Map': return obj.size
|
|
224
|
+
return Object.keys(obj).length
|
|
225
|
+
|
|
226
|
+
def len5(obj):
|
|
227
|
+
if ρσ_arraylike(obj): return obj.length
|
|
228
|
+
if jstype(obj.__len__) is 'function': return obj.__len__()
|
|
229
|
+
return Object.keys(obj).length
|
|
230
|
+
|
|
231
|
+
return len if v'typeof Set' is 'function' and v'typeof Map' is 'function' else len5
|
|
232
|
+
)()
|
|
233
|
+
|
|
234
|
+
def ρσ_get_module(name):
|
|
235
|
+
return ρσ_modules[name]
|
|
236
|
+
|
|
237
|
+
def ρσ_pow(x, y, z):
|
|
238
|
+
ans = Math.pow(x, y)
|
|
239
|
+
if z is not undefined:
|
|
240
|
+
ans %= z
|
|
241
|
+
return ans
|
|
242
|
+
|
|
243
|
+
def ρσ_type(x):
|
|
244
|
+
return x.constructor
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def ρσ_divmod(x, y):
|
|
248
|
+
if y is 0:
|
|
249
|
+
raise ZeroDivisionError('integer division or modulo by zero')
|
|
250
|
+
d = Math.floor(x / y)
|
|
251
|
+
return d, x - d * y
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def ρσ_max(*args, **kwargs):
|
|
255
|
+
if args.length is 0:
|
|
256
|
+
if kwargs.defval is not undefined:
|
|
257
|
+
return kwargs.defval
|
|
258
|
+
raise TypeError('expected at least one argument')
|
|
259
|
+
if args.length is 1:
|
|
260
|
+
args = args[0]
|
|
261
|
+
if kwargs.key:
|
|
262
|
+
args = [kwargs.key(x) for x in args]
|
|
263
|
+
if not Array.isArray(args):
|
|
264
|
+
args = list(args)
|
|
265
|
+
if args.length:
|
|
266
|
+
return this.apply(None, args)
|
|
267
|
+
if kwargs.defval is not undefined:
|
|
268
|
+
return kwargs.defval
|
|
269
|
+
raise TypeError('expected at least one argument')
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
v'var abs = Math.abs, max = ρσ_max.bind(Math.max), min = ρσ_max.bind(Math.min), bool = ρσ_bool, type = ρσ_type'
|
|
273
|
+
v'var float = ρσ_float, int = ρσ_int, arraylike = ρσ_arraylike_creator(), ρσ_arraylike = arraylike'
|
|
274
|
+
v'var id = ρσ_id, get_module = ρσ_get_module, pow = ρσ_pow, divmod = ρσ_divmod'
|
|
275
|
+
v'var dir = ρσ_dir, ord = ρσ_ord, chr = ρσ_chr, bin = ρσ_bin, hex = ρσ_hex, callable = ρσ_callable'
|
|
276
|
+
v'var enumerate = ρσ_enumerate, iter = ρσ_iter, reversed = ρσ_reversed, len = ρσ_len'
|
|
277
|
+
v'var range = ρσ_range, getattr = ρσ_getattr, setattr = ρσ_setattr, hasattr = ρσ_hasattr'
|
|
278
|
+
v'var ρσ_Ellipsis = Object.freeze({toString: function(){return "Ellipsis";}, __repr__: function(){return "Ellipsis";}})'
|
|
279
|
+
v'var Ellipsis = ρσ_Ellipsis'
|