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.
Files changed (144) hide show
  1. package/.agignore +1 -0
  2. package/.gitattributes +4 -0
  3. package/.github/workflows/ci.yml +38 -0
  4. package/.github/workflows/web-repl-page-deploy.yml +42 -0
  5. package/=template.pyj +5 -0
  6. package/CHANGELOG.md +456 -0
  7. package/CONTRIBUTORS +13 -0
  8. package/HACKING.md +103 -0
  9. package/LICENSE +24 -0
  10. package/README.md +2512 -0
  11. package/TODO.md +327 -0
  12. package/add-toc-to-readme +2 -0
  13. package/bin/export +75 -0
  14. package/bin/rapydscript +70 -0
  15. package/bin/web-repl-export +102 -0
  16. package/build +3 -0
  17. package/package.json +46 -0
  18. package/publish.py +37 -0
  19. package/release/baselib-plain-pretty.js +4370 -0
  20. package/release/baselib-plain-ugly.js +3 -0
  21. package/release/compiler.js +18394 -0
  22. package/release/signatures.json +31 -0
  23. package/session.vim +4 -0
  24. package/setup.cfg +2 -0
  25. package/src/ast.pyj +1356 -0
  26. package/src/baselib-builtins.pyj +279 -0
  27. package/src/baselib-containers.pyj +723 -0
  28. package/src/baselib-errors.pyj +37 -0
  29. package/src/baselib-internal.pyj +421 -0
  30. package/src/baselib-itertools.pyj +97 -0
  31. package/src/baselib-str.pyj +798 -0
  32. package/src/compiler.pyj +36 -0
  33. package/src/errors.pyj +30 -0
  34. package/src/lib/aes.pyj +646 -0
  35. package/src/lib/collections.pyj +695 -0
  36. package/src/lib/elementmaker.pyj +83 -0
  37. package/src/lib/encodings.pyj +126 -0
  38. package/src/lib/functools.pyj +148 -0
  39. package/src/lib/gettext.pyj +569 -0
  40. package/src/lib/itertools.pyj +580 -0
  41. package/src/lib/math.pyj +193 -0
  42. package/src/lib/numpy.pyj +2101 -0
  43. package/src/lib/operator.pyj +11 -0
  44. package/src/lib/pythonize.pyj +20 -0
  45. package/src/lib/random.pyj +118 -0
  46. package/src/lib/re.pyj +470 -0
  47. package/src/lib/traceback.pyj +63 -0
  48. package/src/lib/uuid.pyj +77 -0
  49. package/src/monaco-language-service/analyzer.js +526 -0
  50. package/src/monaco-language-service/builtins.js +543 -0
  51. package/src/monaco-language-service/completions.js +498 -0
  52. package/src/monaco-language-service/diagnostics.js +643 -0
  53. package/src/monaco-language-service/dts.js +550 -0
  54. package/src/monaco-language-service/hover.js +121 -0
  55. package/src/monaco-language-service/index.js +386 -0
  56. package/src/monaco-language-service/scope.js +162 -0
  57. package/src/monaco-language-service/signature.js +144 -0
  58. package/src/output/__init__.pyj +0 -0
  59. package/src/output/classes.pyj +296 -0
  60. package/src/output/codegen.pyj +492 -0
  61. package/src/output/comments.pyj +45 -0
  62. package/src/output/exceptions.pyj +105 -0
  63. package/src/output/functions.pyj +491 -0
  64. package/src/output/literals.pyj +109 -0
  65. package/src/output/loops.pyj +444 -0
  66. package/src/output/modules.pyj +329 -0
  67. package/src/output/operators.pyj +429 -0
  68. package/src/output/statements.pyj +463 -0
  69. package/src/output/stream.pyj +309 -0
  70. package/src/output/treeshake.pyj +182 -0
  71. package/src/output/utils.pyj +72 -0
  72. package/src/parse.pyj +3106 -0
  73. package/src/string_interpolation.pyj +72 -0
  74. package/src/tokenizer.pyj +702 -0
  75. package/src/unicode_aliases.pyj +576 -0
  76. package/src/utils.pyj +192 -0
  77. package/test/_import_one.pyj +37 -0
  78. package/test/_import_two/__init__.pyj +11 -0
  79. package/test/_import_two/level2/__init__.pyj +0 -0
  80. package/test/_import_two/level2/deep.pyj +4 -0
  81. package/test/_import_two/other.pyj +6 -0
  82. package/test/_import_two/sub.pyj +13 -0
  83. package/test/aes_vectors.pyj +421 -0
  84. package/test/annotations.pyj +80 -0
  85. package/test/baselib.pyj +319 -0
  86. package/test/classes.pyj +452 -0
  87. package/test/collections.pyj +152 -0
  88. package/test/decorators.pyj +77 -0
  89. package/test/dict_spread.pyj +76 -0
  90. package/test/docstrings.pyj +39 -0
  91. package/test/elementmaker_test.pyj +45 -0
  92. package/test/ellipsis.pyj +49 -0
  93. package/test/functions.pyj +151 -0
  94. package/test/generators.pyj +41 -0
  95. package/test/generic.pyj +370 -0
  96. package/test/imports.pyj +72 -0
  97. package/test/internationalization.pyj +73 -0
  98. package/test/lint.pyj +164 -0
  99. package/test/loops.pyj +85 -0
  100. package/test/numpy.pyj +734 -0
  101. package/test/omit_function_metadata.pyj +20 -0
  102. package/test/regexp.pyj +55 -0
  103. package/test/repl.pyj +121 -0
  104. package/test/scoped_flags.pyj +76 -0
  105. package/test/starargs.pyj +506 -0
  106. package/test/starred_assign.pyj +104 -0
  107. package/test/str.pyj +198 -0
  108. package/test/subscript_tuple.pyj +53 -0
  109. package/test/unit/fixtures/fibonacci_expected.js +46 -0
  110. package/test/unit/index.js +2989 -0
  111. package/test/unit/language-service-builtins.js +815 -0
  112. package/test/unit/language-service-completions.js +1067 -0
  113. package/test/unit/language-service-dts.js +543 -0
  114. package/test/unit/language-service-hover.js +455 -0
  115. package/test/unit/language-service-scope.js +833 -0
  116. package/test/unit/language-service-signature.js +458 -0
  117. package/test/unit/language-service.js +705 -0
  118. package/test/unit/run-language-service.js +41 -0
  119. package/test/unit/web-repl.js +484 -0
  120. package/tools/build-language-service.js +190 -0
  121. package/tools/cli.js +547 -0
  122. package/tools/compile.js +219 -0
  123. package/tools/compiler.js +108 -0
  124. package/tools/completer.js +131 -0
  125. package/tools/embedded_compiler.js +251 -0
  126. package/tools/export.js +316 -0
  127. package/tools/gettext.js +185 -0
  128. package/tools/ini.js +65 -0
  129. package/tools/lint.js +705 -0
  130. package/tools/msgfmt.js +187 -0
  131. package/tools/repl.js +223 -0
  132. package/tools/self.js +162 -0
  133. package/tools/test.js +118 -0
  134. package/tools/utils.js +128 -0
  135. package/tools/web_repl.js +95 -0
  136. package/try +41 -0
  137. package/web-repl/env.js +74 -0
  138. package/web-repl/index.html +163 -0
  139. package/web-repl/language-service.js +4084 -0
  140. package/web-repl/main.js +254 -0
  141. package/web-repl/prism.css +139 -0
  142. package/web-repl/prism.js +113 -0
  143. package/web-repl/rapydscript.js +435 -0
  144. package/web-repl/sha1.js +25 -0
package/test/str.pyj ADDED
@@ -0,0 +1,198 @@
1
+ # vim:fileencoding=utf-8
2
+ # License: BSD
3
+ # Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
4
+ # globals: assrt
5
+
6
+ import encodings
7
+ ae = assrt.equal
8
+
9
+ # Test literals
10
+
11
+ ae(r'\n', '\\n')
12
+ ae('\n'.charCodeAt(0), 10)
13
+ ae('\'', "'")
14
+ ae('\76'.charCodeAt(0), 62) # octal escapes
15
+ ae('\x2a'.charCodeAt(0), 0x2a) # hex escapes
16
+ ae('\u2028'.charCodeAt(0), 0x2028)
17
+ ae("\U0001F431", '🐱')
18
+ ae("\U0001F431", '🐱')
19
+ ae("\N{nbsp}", '\u00a0')
20
+ ae("\N{NBSp}", '\u00a0')
21
+ for qs, aval in [['a', True], ['A', False]]:
22
+ ae(str.islower(qs), aval)
23
+ ae(str.islower(new String(qs)), aval)
24
+ ae(str.isupper(qs), aval ^ True)
25
+ ae(str.isupper(new String(qs)), aval ^ True)
26
+
27
+ # Test format()
28
+
29
+ def test():
30
+ args = Array.prototype.slice.call(arguments, 1)
31
+ ae(arguments[0], str.format.apply(None, args))
32
+
33
+ def test_throws():
34
+ args = Array.prototype.slice.call(arguments)
35
+ def f():
36
+ return str.format.apply(None, args[1:])
37
+ assrt.throws(f, args[0])
38
+
39
+ def test_interpolation():
40
+ a, b, c = 1, ['x'], 30000
41
+ ae(f'{a}', '1')
42
+ ae(f'0{a}', '01')
43
+ ae(f'0{a}2', '012')
44
+ ae(f'{a}{b[-1]}', '1x')
45
+ ae(f'{c:,d}', (30000).toLocaleString())
46
+ ae(f'\n', '\n')
47
+ ae(f'{a}\\{b[0]}', '1\\x')
48
+ ae(f'x\n\ny', 'x\n\ny')
49
+ ae(f'{a=}', 'a=1')
50
+ somevar = {'x': 1}
51
+ ae(f'{somevar.x=}', 'somevar.x=1')
52
+
53
+ somevar = 33
54
+ test('somevar=33', '{somevar=}', somevar=somevar)
55
+ somevar = {'v': 'x'}
56
+ test('somevar.v=x', '{somevar.v=}', somevar=somevar)
57
+ test(' 1 2', ' {} {}', 1, 2)
58
+ test('{ a ', '{{ {0} ', 'a')
59
+ test('11', '{0}{0}', 1)
60
+ test('12', '{a}{b}', a=1, b=2)
61
+ test('12', '{a}{0}', 2, a=1)
62
+ test('1', '{0[0]}', [1])
63
+ test('1', '{0.a.b}', {'a':{'b':1}})
64
+ test('1', '{0[a][b]}', {'a':{'b':1}})
65
+ test('x', '{}', def (): return 'x';)
66
+ test('11', '{:b}', 3)
67
+ test('0b11', '{:#b}', 3)
68
+ test((30000).toLocaleString(), '{:,d}', 30000)
69
+ # in e.g. the indian number system, this is 3,00,000
70
+ test((300000).toLocaleString(), '{:,d}', 300000)
71
+ test('1.234568e+8', '{:e}', 123456789)
72
+ test('1.23E+8', '{:.2E}', 123456789)
73
+ test('12.35%', '{:.2%}', .123456789)
74
+ test((1234).toLocaleString(), '{:,}', 1234)
75
+ test('1_234', '{:_d}', 1234)
76
+ # 6 is the default: 1234.000000% or 1234,000000%
77
+ test((1234).toLocaleString(undefined, {'minimumFractionDigits': 6}), '{:,f}', 1234)
78
+ # 1234.0% or 1234,0%
79
+ test((1234).toLocaleString(undefined, {'minimumFractionDigits': 1}) + '%', '{:,.1%}', 12.34)
80
+ test((1234.57).toLocaleString(), '{:,g}', 1234.567)
81
+ test((1234).toLocaleString(), '{:,g}', 1234)
82
+ fnum = 1234
83
+ ae(f'{fnum:,}', (1234).toLocaleString())
84
+ test('left aligned ', '{:<30}', 'left aligned')
85
+ test(' right aligned', '{:>30}', 'right aligned')
86
+ test(' centered ', '{:^30}', 'centered')
87
+ test('***********centered***********', '{:*^30}', 'centered')
88
+ test('+3.140000; -3.140000', '{:+f}; {:+f}', 3.14, -3.14)
89
+ test('3.140000; -3.140000', '{:-f}; {:-f}', 3.14, -3.14)
90
+ test(' 3.140000; -3.140000', '{: f}; {: f}', 3.14, -3.14)
91
+ test('int: 42; hex: 2a; oct: 52; bin: 101010', "int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42)
92
+ test('int: 42; hex: 0x2a; oct: 0o52; bin: 0b101010', "int: {0:d}; hex: {0:#x}; oct: {0:#o}; bin: {0:#b}", 42)
93
+ test('100', '{:{fill}{align}3}', 1, fill=0, align='<')
94
+ test_throws(AttributeError, '{0.a}', {})
95
+ test_throws(KeyError, '{a}', b=1)
96
+ test_throws(IndexError, '{} {}', 1)
97
+ test_throws(IndexError, '{1} {2}', 1)
98
+ test_throws(ValueError, '{1')
99
+ test_interpolation()
100
+
101
+ # Test miscellaneous services
102
+ ae('Abc', str.capitalize('aBC'))
103
+ ae(' 1 ', str.center('1', 3))
104
+ ae(2, str.count('xyx', 'x'))
105
+ ae(1, str.count('xyx', 'x', 2))
106
+ ae(True, str.endswith('a', ''))
107
+ ae(True, str.endswith('', ''))
108
+ ae(False, str.endswith('a', 'ab'))
109
+ ae(True, str.endswith('e', ['f', 'e']))
110
+ ae(True, str.startswith('a', ''))
111
+ ae(True, str.startswith('', ''))
112
+ ae(False, str.startswith('a', 'ab'))
113
+ ae(True, str.startswith('e', ['f', 'e']))
114
+ ae(1, str.find('ab', 'b'))
115
+ ae(2, str.rfind('abbc', 'b'))
116
+ ae(1, str.index('ab', 'b'))
117
+ ae(-1, str.find('abcd', 'b', 2))
118
+ ae(-1, str.find('abcd', 'b', 0, 1))
119
+ ae(-1, str.find('abcd', 'bcd', 0, 2))
120
+ ae(-1, str.rfind('abcd', 'b', 2))
121
+ ae(-1, str.rfind('abcd', 'b', 0, 1))
122
+ ae(3, str.rfind('abcd', 'd'))
123
+ ae('1,2', str.join(',', [1, 2]))
124
+ ae('1,2', str.join(',', iter([1, 2])))
125
+ ae('a ', str.ljust('a', 3))
126
+ ae(' a', str.rjust('a', 3))
127
+ ae('A', str.upper('a'))
128
+ ae('a', str.lower('A'))
129
+ ae('a', str.lstrip(' a'))
130
+ ae('a', str.lstrip('a'))
131
+ ae('a', str.rstrip('a '))
132
+ ae('a', str.rstrip('a'))
133
+ ae('a', str.strip(' a '))
134
+ ae('', str.strip(' '))
135
+ ae('', str.lstrip(' '))
136
+ ae('', str.rstrip(' '))
137
+ assrt.deepEqual(['1', ',', '2,3'], str.partition('1,2,3', ','))
138
+ assrt.deepEqual(['1,2,3', '', ''], str.partition('1,2,3', ' '))
139
+ assrt.deepEqual(['1,2', ',', '3'], str.rpartition('1,2,3', ','))
140
+ assrt.deepEqual(['', '', '1,2,3'], str.rpartition('1,2,3', ' '))
141
+ assrt.deepEqual(['1', ',2'], str.split('1,,2', ',', 1))
142
+ assrt.deepEqual(['1', '2', '3'], str.split('1 2 3'))
143
+ assrt.deepEqual(['1', '2 3'], str.split('1 2 3', None, 1))
144
+ assrt.deepEqual(['1', '2 \t3'], str.split('1 2 \t3', None, 1))
145
+ assrt.deepEqual(['-a--b-c', ''], str.rsplit('-a--b-c-', '-', 1))
146
+ assrt.deepEqual(['', 'a', 'b'], str.rsplit(',a,b', ','))
147
+ assrt.deepEqual([',a', 'b'], str.rsplit(',a,b', ',', 1))
148
+ assrt.deepEqual(['x,a', 'b'], str.rsplit('x,a,b', ',', 1))
149
+ assrt.deepEqual([' a b', 'c'], str.rsplit(' a b c ', None, 1))
150
+ assrt.deepEqual([' a bx', 'c'], str.rsplit(' a bx c ', None, 1))
151
+ for x in ['a\nb', 'a\r\nb', 'a\rb']:
152
+ assrt.deepEqual(['a', 'b'], str.splitlines(x))
153
+ assrt.deepEqual(['a', '', 'b'], str.splitlines('a\n\rb'))
154
+ assrt.deepEqual(['a\n', 'b'], str.splitlines('a\nb', True))
155
+ assrt.deepEqual(['a\r\n', 'b'], str.splitlines('a\r\nb', True))
156
+ assrt.deepEqual(['s', "🐱", 'a', '\u2028'], list(str.uchrs('s🐱a\u2028')))
157
+ assrt.deepEqual([[0, 's'], [1, "🐱"], [3, 'a'], [4, '\u2028']], list(str.uchrs('s🐱a\u2028', True)))
158
+ ae('bbb', str.replace('aaa', 'a', 'b'))
159
+ ae('baa', str.replace('aaa', 'a', 'b', 1))
160
+ ae('bba', str.replace('aaa', 'a', 'b', 2))
161
+ ae('aaa', str.replace('aaa', 'a', 'a'))
162
+ ae('', str.replace('aaa', 'a', ''))
163
+ ae('a1B', str.swapcase('A1b'))
164
+ ae('001', str.zfill('1', 3))
165
+ ae('111', str.zfill('111', 2))
166
+ ae('a\u2028', str.uslice('s🐱a\u2028', 2))
167
+ ae(4, str.ulen('s🐱a\u2028', 2))
168
+
169
+ for f in (str, repr):
170
+ ae(f(True), 'True')
171
+ ae(f(False), 'False')
172
+ ae(f(None), 'None')
173
+ ae(f(1), '1')
174
+ ae(f([1,'2']), '[1, "2"]')
175
+ ae(f({1:[1, '2']}), '{"1":[1, "2"]}')
176
+ ae(f({1:'a', 2:'b'}), '{"1":"a", "2":"b"}')
177
+ ae(str('a'), 'a')
178
+ ae(repr('a'), '"a"')
179
+
180
+ bytes = list(range(256))
181
+ assrt.deepEqual(bytes, list(encodings.base64decode(encodings.base64encode(bytes))))
182
+ assrt.deepEqual(bytes, list(encodings.unhexlify(encodings.hexlify(bytes))))
183
+ for k in ['abc', "mūs", '', 's🐱a\u2028']:
184
+ bytes = encodings.utf8_encode(k)
185
+ ae(encodings.utf8_decode(bytes), k)
186
+ ae(encodings.utf8_decode(encodings.utf8_encode_js(k)), k)
187
+ assrt.deepEqual(list(bytes), list(encodings.base64decode(encodings.base64encode(bytes))))
188
+
189
+ from pythonize import strings
190
+ strings()
191
+ ae('{0} {a}'.format(1, a=2), str.format('{0} {a}', 1, a=2))
192
+ ae(' x '.strip(), str.strip(' x '))
193
+ ae(','.join([1,2,3]), str.join(',', [1,2,3]))
194
+ ae('11111'.count('1', start=1, end=1), str.count('11111', '1', start=1, end=1))
195
+ ae('{{}}'.format(), '{}')
196
+ ae('{x}}}'.format(x=1), '1}')
197
+ a = 1
198
+ ae(f'{{ {a} }}', '{ 1 }')
@@ -0,0 +1,53 @@
1
+ # globals: assrt
2
+ # Tests for Python's extended subscript syntax: commas inside [] form tuples (JS arrays)
3
+
4
+ # --- Basic tuple key access ---
5
+ d = {}
6
+ d[[1, 2]] = 'two-d'
7
+ assrt.equal(d[[1, 2]], 'two-d', 'dict with [1,2] key')
8
+
9
+ # --- Tuple subscript syntax: a[1, 2] is equivalent to a[[1, 2]] ---
10
+ d2 = {}
11
+ d2[1, 2] = 'hello'
12
+ assrt.equal(d2[1, 2], 'hello', 'a[1, 2] read/write')
13
+
14
+ # --- Three-element tuple subscript ---
15
+ d3 = {}
16
+ d3[1, 2, 3] = 'three'
17
+ assrt.equal(d3[1, 2, 3], 'three', 'a[1, 2, 3]')
18
+
19
+ # --- Mixed types ---
20
+ d4 = {}
21
+ d4['x', 0] = 99
22
+ assrt.equal(d4['x', 0], 99, "a['x', 0]")
23
+
24
+ # --- Consistency: a[1, 2] and a[[1, 2]] access the same key ---
25
+ arr = {}
26
+ arr[1, 2] = 'via tuple syntax'
27
+ key = [1, 2]
28
+ # Since JS uses reference equality for array keys, both forms produce the same
29
+ # string key when used directly in the subscript
30
+ arr2 = {}
31
+ arr2[1, 2] = 'A'
32
+ arr2[1, 2] = 'B'
33
+ assrt.equal(arr2[1, 2], 'B', 'overwrite via tuple subscript')
34
+
35
+ # --- Works with variables in subscript ---
36
+ x = 3
37
+ y = 7
38
+ d5 = {}
39
+ d5[x, y] = 'xy'
40
+ assrt.equal(d5[x, y], 'xy', 'variable tuple subscript')
41
+
42
+ # --- Works as expression in larger expressions ---
43
+ m = {}
44
+ m[0, 0] = 1
45
+ m[0, 1] = 2
46
+ m[1, 0] = 3
47
+ m[1, 1] = 4
48
+ assrt.equal(m[0, 0] + m[1, 1], 5, 'sum of diagonal')
49
+
50
+ # --- Two-element tuple subscript round-trip ---
51
+ t = {}
52
+ t[10, 20] = 'found'
53
+ assrt.equal(t[10, 20], 'found', 'round-trip [10,20]')
@@ -0,0 +1,46 @@
1
+ var __name__ = "__main__";
2
+
3
+ function memoize(f) {
4
+ var memo;
5
+ memo = {};
6
+ return (function() {
7
+ var ρσ_anonfunc = function (x) {
8
+ if (!ρσ_in(x, memo)) {
9
+ memo[(typeof x === "number" && x < 0) ? memo.length + x : x] = f(x);
10
+ }
11
+ return memo[(typeof x === "number" && x < 0) ? memo.length + x : x];
12
+ };
13
+ if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
14
+ __argnames__ : {value: ["x"]},
15
+ __module__ : {value: "__main__"}
16
+ });
17
+ return ρσ_anonfunc;
18
+ })();
19
+ };
20
+ if (!memoize.__argnames__) Object.defineProperties(memoize, {
21
+ __argnames__ : {value: ["f"]},
22
+ __module__ : {value: "__main__"}
23
+ });
24
+
25
+
26
+ var fib = memoize((function() {
27
+ var ρσ_anonfunc = function fib(n) {
28
+ if ((n === 0 || typeof n === "object" && ρσ_equals(n, 0))) {
29
+ return 0;
30
+ } else if ((n === 1 || typeof n === "object" && ρσ_equals(n, 1))) {
31
+ return 1;
32
+ } else {
33
+ return fib(n - 1) + fib(n - 2);
34
+ }
35
+ };
36
+ if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
37
+ __argnames__ : {value: ["n"]},
38
+ __module__ : {value: "__main__"}
39
+ });
40
+ return ρσ_anonfunc;
41
+ })());
42
+
43
+ assrt.equal(fib(0), 0);
44
+ assrt.equal(fib(1), 1);
45
+ assrt.equal(fib(10), 55);
46
+ assrt.equal(fib(15), 610);