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
@@ -0,0 +1,20 @@
1
+ # globals: RapydScript
2
+
3
+ # Test that omit_function_metadata flag suppresses __module__ and __argnames__
4
+ code = 'def foo(a, b):\n return a + b'
5
+ ast = RapydScript.parse(code, {'filename': '<test>'})
6
+
7
+ # Without flag: output should contain __module__ and __argnames__
8
+ output_with = v'new RapydScript.OutputStream({"beautify": true, "omit_baselib": true})'
9
+ ast.print(output_with)
10
+ result_with = output_with.get()
11
+ assrt.ok(result_with.indexOf('__module__') >= 0, '__module__ should appear in default output')
12
+ assrt.ok(result_with.indexOf('__argnames__') >= 0, '__argnames__ should appear in default output')
13
+
14
+ # With flag: output should not contain __module__, __argnames__, or Object.defineProperties
15
+ output_without = v'new RapydScript.OutputStream({"beautify": true, "omit_baselib": true, "omit_function_metadata": true})'
16
+ ast.print(output_without)
17
+ result_without = output_without.get()
18
+ assrt.ok(result_without.indexOf('__module__') is -1, '__module__ should not appear when omit_function_metadata is set')
19
+ assrt.ok(result_without.indexOf('__argnames__') is -1, '__argnames__ should not appear when omit_function_metadata is set')
20
+ assrt.ok(result_without.indexOf('Object.defineProperties') is -1, 'Object.defineProperties should not appear when omit_function_metadata is set')
@@ -0,0 +1,55 @@
1
+ # vim:fileencoding=utf-8
2
+ # License: BSD
3
+ # Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
4
+
5
+ # Test the re module
6
+ import re
7
+ s = "Isaac Newton, physicist"
8
+ c = re.search("(\\w+) (\\w+)", s)
9
+ assrt.equal(c.group(1), 'Isaac')
10
+ assrt.equal(c.group(2), 'Newton')
11
+ c = re.match("(\\w+) (\\w+)", s)
12
+ assrt.equal(c.group(1), 'Isaac')
13
+ assrt.equal(c.start(1), 0)
14
+ assrt.equal(c.end(1), c.group(1).length)
15
+ assrt.equal(c.start(2), c.group(1).length + 1)
16
+ assrt.equal(c.group(2), 'Newton')
17
+ m = re.search('a(b)cd', 'abc abcd')
18
+ assrt.equal(m.group(1), 'b')
19
+ assrt.equal(m.start(1), m.string.lastIndexOf('b'))
20
+ assrt.deepEqual(re.split('\\s', s), ['Isaac', 'Newton,', 'physicist'])
21
+ assrt.deepEqual(re.findall('s[a-z]', s), ['sa', 'si', 'st'])
22
+ assrt.deepEqual([m.group() for m in re.finditer('s[a-z]', s)], ['sa', 'si', 'st'])
23
+ assrt.deepEqual(re.findall(/s[a-z]/, s), ['sa', 'si', 'st'])
24
+ assrt.equal(re.sub('[A-Z]', '_', s), '_saac _ewton, physicist')
25
+ assrt.equal(re.sub('[A-Z]', '_', s, count=1), '_saac Newton, physicist')
26
+ assrt.equal(re.search('a[.]b', 'axb'), None)
27
+ assrt.equal(re.search(r'a\.b', 'axb'), None)
28
+ assrt.equal(re.search('a[.]b', 'axb', flags=re.D), None)
29
+ assrt.equal(re.search('.+', 'a\nb').group(), 'a')
30
+ assrt.equal(re.search('.+', 'a\nb', flags=re.D).group(), 'a\nb')
31
+ assrt.equal(re.search('(?s).+', 'a\nb').group(), 'a\nb')
32
+ assrt.equal(re.sub('a(b)', r'xx', 'ab'), r'xx')
33
+ assrt.equal(re.sub('a(b)', r'\\1', 'ab'), r'\1')
34
+ assrt.equal(re.sub('a(b)', r'\\\1', 'ab'), r'\b')
35
+ assrt.equal(re.sub('a(b)', r'\g<1>', 'ab'), r'b')
36
+ assrt.equal(re.sub('a(b)', def(m):return m.group(1);, 'ab'), r'b')
37
+ assrt.equal(']', re.match('[]]', ']').group())
38
+
39
+ assrt.throws(def():re.search(r'(?(1)a|b)b', 'ab');, re.error)
40
+
41
+ # Test lookbehind assertions
42
+ assrt.equal('acdb', re.sub(r'(?<=a)b', 'c', 'abdb'))
43
+
44
+ # Test named groups
45
+ assrt.equal('aa', re.sub(r'(?P<a>a)b', r'\g<a>\1', 'ab'))
46
+ assrt.equal('bb', re.sub(r'(?P<a>a)(?P=a)', r'bb', 'aa'))
47
+ assrt.equal('ab', re.sub(r'(.)(?P<a>a)', r'\g<a>\1', 'ba'))
48
+ assrt.deepEqual({'a':'a', 'b':'b'}, re.search(r'(?P<a>a)(?P<b>b)', 'ab').groupdict())
49
+
50
+ # Test verbose mode literals
51
+ assrt.equal(re.search(///
52
+ a
53
+ . # anything
54
+ b
55
+ ///, ' axb').group(), 'axb')
package/test/repl.pyj ADDED
@@ -0,0 +1,121 @@
1
+ # globals: compiler_dir
2
+ stdout = []
3
+ def clear():
4
+ stdout.length = 0
5
+
6
+ class FakeConsole:
7
+
8
+ def log(self):
9
+ Array.prototype.slice.call(arguments).forEach(def (arg):
10
+ stdout.push((arg or '').toString())
11
+ )
12
+ stdout.push('\n')
13
+
14
+ def error(self):
15
+ Array.prototype.slice.call(arguments).forEach(def (arg):
16
+ stdout.push((arg or '').toString())
17
+ )
18
+ stdout.push('\n')
19
+
20
+ class FakeReadline:
21
+
22
+ def __init__(self):
23
+ self.listeners = {}
24
+ self._prompt = ''
25
+
26
+ def setPrompt(self, prompt):
27
+ self._prompt = prompt
28
+
29
+ def write(self, data):
30
+ stdout.push(data)
31
+
32
+ def clearLine(self):
33
+ pass
34
+
35
+ def on(self, event, callback):
36
+ self.listeners[event] = callback
37
+ return self
38
+
39
+ def prompt(self):
40
+ stdout.push(self._prompt)
41
+
42
+ def send_line(self, text):
43
+ self.listeners['line'](text)
44
+
45
+ repl = require('./repl')
46
+ rl = FakeReadline()
47
+
48
+ send_line = rl.send_line.bind(rl)
49
+
50
+ def send_text(text):
51
+ for line in text.split('\n'):
52
+ send_line(line)
53
+
54
+ def check(text, output):
55
+ send_text(text)
56
+ eq(output, stdout[0])
57
+ clear()
58
+
59
+ def check_in(text, output):
60
+ send_text(text)
61
+ assrt.ok(output in stdout, output + ' not in ' + stdout)
62
+ clear()
63
+
64
+ def check_not_in(text, output):
65
+ send_text(text)
66
+ assrt.ok(output not in stdout)
67
+ clear()
68
+
69
+ readline = {
70
+ 'createInterface': def(options):
71
+ rl.completer = options.completer
72
+ return rl
73
+ }
74
+ repl({'lib_path':compiler_dir, 'console':FakeConsole(), 'readline':readline, 'terminal':False, 'show_js':False, 'histfile':False})
75
+ eq = assrt.equal
76
+ eq('>>> ', stdout[-1])
77
+ clear()
78
+ check('1', '1')
79
+ check_in('if 1:\n 2\n \n ', '2')
80
+ check_not_in('if 1:\n 2\n ', '2')
81
+ check_in('1 +\n1\n\n', '2')
82
+ check('max(1, 2)', '2')
83
+ send_text(
84
+ '''
85
+ class A:
86
+
87
+ def __init__(self, a):
88
+ self. a = a
89
+
90
+
91
+ ''')
92
+ clear()
93
+ check_in('b = A(1)\nb.a', '1')
94
+ check_in('c = A(2)\nc.a', '2')
95
+ send_text('from __python__ import dict_literals\nd={1:1}')
96
+ check_in('isinstance(d, dict)', 'true')
97
+ send_text('from __python__ import no_dict_literals\nd={1:1}')
98
+ check_in('isinstance(d, dict)', 'false')
99
+ # Test completions
100
+ def completions(line):
101
+ return rl.completer(line)[0]
102
+
103
+ def check_completions():
104
+ items = completions(arguments[0])
105
+ for x in Array.prototype.slice.call(arguments, 1):
106
+ assrt.ok(items and x in items, x + ' not in completions for: ' + arguments[0])
107
+
108
+ check_completions('', 'return', 'A')
109
+ check_completions('Array.', 'isArray', 'apply')
110
+ send_text('x = ""\ny = []'), clear()
111
+ check_completions('x.', 'substr', 'trim')
112
+ check_completions('y.', 'concat', 'push')
113
+ check_completions('x.sl', 'slice')
114
+ send_text('y = {"x":1}'), clear()
115
+ check_completions('y.', 'x')
116
+
117
+ # Test docstrings
118
+ clear()
119
+ send_text('def ds():\n "xxx"\n\n')
120
+ clear()
121
+ check('ds.__doc__', "'xxx'")
@@ -0,0 +1,76 @@
1
+ # vim:fileencoding=utf-8
2
+ # License: BSD Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
3
+
4
+ a = {1:1}
5
+ assrt.ok(not isinstance(a, dict))
6
+
7
+ from __python__ import dict_literals, overload_getitem
8
+ a = {1:1}
9
+ assrt.ok(isinstance(a, dict))
10
+ assrt.equal(a[1], 1)
11
+ a[2] = 2
12
+ assrt.equal(a[2], 2)
13
+ a[2] += 4
14
+ assrt.equal(a[2], 6)
15
+ assrt.deepEqual(list(a.keys()), [1, 2])
16
+ from __python__ import no_dict_literals, no_overload_getitem
17
+
18
+
19
+ a = {1:1}
20
+ assrt.ok(not isinstance(a, dict))
21
+
22
+ def f():
23
+ from __python__ import dict_literals
24
+ a = {1:1}
25
+ assrt.ok(isinstance(a, dict))
26
+
27
+ a = {1:1}
28
+ assrt.ok(not isinstance(a, dict))
29
+
30
+ class S:
31
+ from __python__ import bound_methods
32
+
33
+ def __init__(self):
34
+ self.a = 3
35
+
36
+ def val(self):
37
+ return self.a if self else None
38
+
39
+ f = S().val
40
+ assrt.equal(f(), S().val())
41
+
42
+ class U:
43
+
44
+ def __init__(self):
45
+ self.a = 3
46
+
47
+ def val(self):
48
+ return self.a if self else None
49
+
50
+ f = U().val
51
+ assrt.equal(f(), None)
52
+
53
+ class C:
54
+
55
+ def __init__(self):
56
+ self.a = 3
57
+
58
+ def uval1(self):
59
+ return self.a if self else None
60
+
61
+ from __python__ import bound_methods
62
+
63
+ def bval(self):
64
+ return self.a
65
+
66
+ from __python__ import no_bound_methods
67
+
68
+ def uval2(self):
69
+ return self.a if self else None
70
+
71
+ c = C()
72
+ u1, u2 = c.uval1, c.uval2
73
+ f = c.bval
74
+ assrt.equal(u1(), None)
75
+ assrt.equal(u2(), None)
76
+ assrt.equal(f(), 3)