rapydscript-ns 0.8.2 → 0.8.3
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 +31 -0
- package/PYTHON_DIFFERENCES_REPORT.md +291 -0
- package/PYTHON_FEATURE_COVERAGE.md +96 -5
- package/README.md +161 -46
- package/TODO.md +2 -283
- package/language-service/index.js +4474 -0
- package/language-service/language-service.d.ts +40 -0
- package/package.json +9 -7
- package/src/baselib-builtins.pyj +77 -1
- package/src/baselib-containers.pyj +8 -4
- package/src/baselib-internal.pyj +30 -1
- package/src/baselib-str.pyj +8 -1
- package/src/lib/collections.pyj +1 -1
- package/src/lib/numpy.pyj +10 -10
- package/src/monaco-language-service/analyzer.js +131 -9
- package/src/monaco-language-service/builtins.js +12 -2
- package/src/monaco-language-service/completions.js +170 -1
- package/src/monaco-language-service/diagnostics.js +1 -1
- package/src/monaco-language-service/index.js +17 -0
- package/src/monaco-language-service/scope.js +3 -0
- package/src/output/classes.pyj +20 -3
- package/src/output/codegen.pyj +1 -1
- package/src/output/functions.pyj +4 -16
- package/src/output/loops.pyj +0 -9
- package/src/output/modules.pyj +1 -4
- package/src/output/operators.pyj +14 -0
- package/src/output/stream.pyj +0 -13
- package/src/parse.pyj +17 -1
- package/test/baselib.pyj +4 -4
- package/test/classes.pyj +56 -17
- package/test/collections.pyj +5 -5
- package/test/python_compat.pyj +326 -0
- package/test/python_features.pyj +110 -23
- package/test/slice.pyj +105 -0
- package/test/str.pyj +25 -0
- package/test/unit/fixtures/fibonacci_expected.js +1 -1
- package/test/unit/index.js +119 -7
- package/test/unit/language-service-builtins.js +70 -0
- package/test/unit/language-service-bundle.js +5 -5
- package/test/unit/language-service-completions.js +180 -0
- package/test/unit/language-service-index.js +350 -0
- package/test/unit/language-service-scope.js +255 -0
- package/test/unit/language-service.js +35 -0
- package/test/unit/run-language-service.js +1 -0
- package/test/unit/web-repl.js +134 -0
- package/tools/build-language-service.js +2 -2
- package/tools/compiler.js +0 -24
- package/tools/export.js +3 -37
- package/web-repl/rapydscript.js +6 -40
- package/web-repl/language-service.js +0 -4187
package/test/unit/web-repl.js
CHANGED
|
@@ -445,6 +445,140 @@ var TESTS = [
|
|
|
445
445
|
},
|
|
446
446
|
},
|
|
447
447
|
|
|
448
|
+
{
|
|
449
|
+
name: "nested_class_web_repl",
|
|
450
|
+
description: "Nested class definitions compile and run correctly via the web-repl bundle",
|
|
451
|
+
run: function () {
|
|
452
|
+
var repl = RS.web_repl();
|
|
453
|
+
var js = bundle_compile(repl, [
|
|
454
|
+
"class Outer:",
|
|
455
|
+
" class Inner:",
|
|
456
|
+
" def __init__(self, val):",
|
|
457
|
+
" self.val = val",
|
|
458
|
+
" def __init__(self, v):",
|
|
459
|
+
" self.inner = Outer.Inner(v)",
|
|
460
|
+
"o = Outer(99)",
|
|
461
|
+
"assrt.equal(o.inner.val, 99)",
|
|
462
|
+
"assrt.ok(isinstance(o.inner, Outer.Inner))",
|
|
463
|
+
"assrt.ok(o.Inner is Outer.Inner)",
|
|
464
|
+
].join("\n"));
|
|
465
|
+
run_js(js);
|
|
466
|
+
},
|
|
467
|
+
},
|
|
468
|
+
|
|
469
|
+
// ── slice() builtin ───────────────────────────────────────────────────
|
|
470
|
+
|
|
471
|
+
{
|
|
472
|
+
name: "bundle_slice_constructor",
|
|
473
|
+
description: "slice() constructor stores start/stop/step attributes correctly",
|
|
474
|
+
run: function () {
|
|
475
|
+
var repl = RS.web_repl();
|
|
476
|
+
var js = bundle_compile(repl, [
|
|
477
|
+
"s1 = slice(5)",
|
|
478
|
+
"assrt.equal(s1.start, None)",
|
|
479
|
+
"assrt.equal(s1.stop, 5)",
|
|
480
|
+
"assrt.equal(s1.step, None)",
|
|
481
|
+
"s2 = slice(2, 8)",
|
|
482
|
+
"assrt.equal(s2.start, 2)",
|
|
483
|
+
"assrt.equal(s2.stop, 8)",
|
|
484
|
+
"assrt.equal(s2.step, None)",
|
|
485
|
+
"s3 = slice(1, 9, 2)",
|
|
486
|
+
"assrt.equal(s3.start, 1)",
|
|
487
|
+
"assrt.equal(s3.stop, 9)",
|
|
488
|
+
"assrt.equal(s3.step, 2)",
|
|
489
|
+
].join("\n"));
|
|
490
|
+
run_js(js);
|
|
491
|
+
},
|
|
492
|
+
},
|
|
493
|
+
|
|
494
|
+
{
|
|
495
|
+
name: "bundle_slice_subscript",
|
|
496
|
+
description: "slice object used as list subscript returns the correct sub-list",
|
|
497
|
+
run: function () {
|
|
498
|
+
var repl = RS.web_repl();
|
|
499
|
+
var js = bundle_compile(repl, [
|
|
500
|
+
"from __python__ import overload_getitem",
|
|
501
|
+
"lst = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]",
|
|
502
|
+
"s = slice(2, 5)",
|
|
503
|
+
"assrt.deepEqual(lst[s], [2, 3, 4])",
|
|
504
|
+
"assrt.deepEqual(lst[slice(0, 6, 2)], [0, 2, 4])",
|
|
505
|
+
"assrt.deepEqual(lst[slice(5, 1, -1)], [5, 4, 3, 2])",
|
|
506
|
+
].join("\n"));
|
|
507
|
+
run_js(js);
|
|
508
|
+
},
|
|
509
|
+
},
|
|
510
|
+
|
|
511
|
+
{
|
|
512
|
+
name: "bundle_slice_indices",
|
|
513
|
+
description: "slice.indices() returns normalised (start, stop, step) tuple",
|
|
514
|
+
run: function () {
|
|
515
|
+
var repl = RS.web_repl();
|
|
516
|
+
var js = bundle_compile(repl, [
|
|
517
|
+
"s = slice(2, 8)",
|
|
518
|
+
"idx = s.indices(10)",
|
|
519
|
+
"assrt.equal(idx[0], 2)",
|
|
520
|
+
"assrt.equal(idx[1], 8)",
|
|
521
|
+
"assrt.equal(idx[2], 1)",
|
|
522
|
+
"# negative indices normalised",
|
|
523
|
+
"s2 = slice(-3, -1)",
|
|
524
|
+
"idx2 = s2.indices(10)",
|
|
525
|
+
"assrt.equal(idx2[0], 7)",
|
|
526
|
+
"assrt.equal(idx2[1], 9)",
|
|
527
|
+
].join("\n"));
|
|
528
|
+
run_js(js);
|
|
529
|
+
},
|
|
530
|
+
},
|
|
531
|
+
|
|
532
|
+
{
|
|
533
|
+
name: "bundle_slice_repr",
|
|
534
|
+
description: "str(slice(...)) produces the Python-style repr",
|
|
535
|
+
run: function () {
|
|
536
|
+
var repl = RS.web_repl();
|
|
537
|
+
var js = bundle_compile(repl, [
|
|
538
|
+
"assrt.equal(str(slice(1, 5, None)), 'slice(1, 5, None)')",
|
|
539
|
+
"assrt.equal(str(slice(None, 5, 2)), 'slice(None, 5, 2)')",
|
|
540
|
+
].join("\n"));
|
|
541
|
+
run_js(js);
|
|
542
|
+
},
|
|
543
|
+
},
|
|
544
|
+
|
|
545
|
+
{
|
|
546
|
+
name: "bundle_slice_isinstance",
|
|
547
|
+
description: "isinstance(slice(...), slice) returns True in bundled baselib",
|
|
548
|
+
run: function () {
|
|
549
|
+
var repl = RS.web_repl();
|
|
550
|
+
var js = bundle_compile(repl, [
|
|
551
|
+
"s = slice(1, 5)",
|
|
552
|
+
"assrt.ok(isinstance(s, slice))",
|
|
553
|
+
].join("\n"));
|
|
554
|
+
run_js(js);
|
|
555
|
+
},
|
|
556
|
+
},
|
|
557
|
+
|
|
558
|
+
{
|
|
559
|
+
name: "bundle_list_concatenation",
|
|
560
|
+
description: "list + list returns a concatenated list in the bundled baselib",
|
|
561
|
+
run: function () {
|
|
562
|
+
var repl = RS.web_repl();
|
|
563
|
+
var js = bundle_compile(repl, [
|
|
564
|
+
"a = [1, 2]",
|
|
565
|
+
"b = [3, 4]",
|
|
566
|
+
"c = a + b",
|
|
567
|
+
"assrt.deepEqual(c, [1, 2, 3, 4])",
|
|
568
|
+
"assrt.deepEqual(a, [1, 2])",
|
|
569
|
+
"assrt.deepEqual(b, [3, 4])",
|
|
570
|
+
"# iadd extends in-place",
|
|
571
|
+
"a += [5]",
|
|
572
|
+
"assrt.deepEqual(a, [1, 2, 5])",
|
|
573
|
+
"# numbers still work",
|
|
574
|
+
"assrt.equal(1 + 2, 3)",
|
|
575
|
+
"# strings still work",
|
|
576
|
+
"assrt.equal('foo' + 'bar', 'foobar')",
|
|
577
|
+
].join("\n"));
|
|
578
|
+
run_js(js);
|
|
579
|
+
},
|
|
580
|
+
},
|
|
581
|
+
|
|
448
582
|
];
|
|
449
583
|
|
|
450
584
|
// ---------------------------------------------------------------------------
|
|
@@ -14,7 +14,7 @@ var path = require("path");
|
|
|
14
14
|
|
|
15
15
|
var SRC_DIR = path.join(__dirname, "..", "src", "monaco-language-service");
|
|
16
16
|
var COMPILER_JS = path.join(__dirname, "..", "web-repl", "rapydscript.js");
|
|
17
|
-
var DEFAULT_OUT = path.join(__dirname, "..", "
|
|
17
|
+
var DEFAULT_OUT = path.join(__dirname, "..", "language-service", "index.js");
|
|
18
18
|
|
|
19
19
|
// Parse --out flag
|
|
20
20
|
var out_path = DEFAULT_OUT;
|
|
@@ -124,7 +124,7 @@ var chunks = [
|
|
|
124
124
|
"// language-service.js — RapydScript Monaco Language Service",
|
|
125
125
|
"// Auto-generated by tools/build-language-service.js — do not edit directly.",
|
|
126
126
|
"// Source: src/monaco-language-service/ + web-repl/rapydscript.js (embedded)",
|
|
127
|
-
"// Usage: import { registerRapydScript } from '
|
|
127
|
+
"// Usage: import { registerRapydScript } from 'rapydscript-ns/language-service';",
|
|
128
128
|
"// No external compiler bundle needed — the compiler is bundled inside.",
|
|
129
129
|
"",
|
|
130
130
|
compiler_chunk,
|
package/tools/compiler.js
CHANGED
|
@@ -13,7 +13,6 @@ var path = require("path");
|
|
|
13
13
|
var fs = require("fs");
|
|
14
14
|
var crypto = require('crypto');
|
|
15
15
|
var vm = require("vm");
|
|
16
|
-
var regenerator = require('regenerator');
|
|
17
16
|
var UglifyJS = require("uglify-js");
|
|
18
17
|
|
|
19
18
|
function sha1sum(data) {
|
|
@@ -38,28 +37,6 @@ function uglify(code) {
|
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
|
|
41
|
-
function regenerate(code, beautify) {
|
|
42
|
-
var ans, start, end;
|
|
43
|
-
if (code) {
|
|
44
|
-
ans = regenerator.compile(code).code;
|
|
45
|
-
if (!beautify) {
|
|
46
|
-
ans = uglify(ans);
|
|
47
|
-
}
|
|
48
|
-
} else {
|
|
49
|
-
// Return the runtime
|
|
50
|
-
ans = regenerator.compile('', {includeRuntime:true}).code;
|
|
51
|
-
start = ans.indexOf('=') + 1;
|
|
52
|
-
end = ans.lastIndexOf('typeof');
|
|
53
|
-
end = ans.lastIndexOf('}(', end);
|
|
54
|
-
ans = ans.slice(start + 1, end);
|
|
55
|
-
if (!beautify) {
|
|
56
|
-
var extra = '})()';
|
|
57
|
-
ans = uglify(ans + extra).slice(0, extra.length);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return ans;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
40
|
var _current_virtual_files = null;
|
|
64
41
|
|
|
65
42
|
function virtual_readfile(name, encoding) {
|
|
@@ -90,7 +67,6 @@ function create_compiler() {
|
|
|
90
67
|
writefile : virtual_writefile,
|
|
91
68
|
sha1sum : sha1sum,
|
|
92
69
|
require : require,
|
|
93
|
-
regenerate : regenerate,
|
|
94
70
|
exports : compiler_exports,
|
|
95
71
|
});
|
|
96
72
|
|
package/tools/export.js
CHANGED
|
@@ -145,7 +145,7 @@ function vrequire(name, base) {
|
|
|
145
145
|
return load(modpath);
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
var UglifyJS = null
|
|
148
|
+
var UglifyJS = null;
|
|
149
149
|
var crypto = null, fs = require('fs');
|
|
150
150
|
|
|
151
151
|
var current_virtual_files = null;
|
|
@@ -176,40 +176,6 @@ function uglify(x) {
|
|
|
176
176
|
return ans.code;
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
function regenerate(code, beautify) {
|
|
180
|
-
var orig = fs.readFileSync;
|
|
181
|
-
fs.readFileSync = function(name) {
|
|
182
|
-
if (!has(data, name)) {
|
|
183
|
-
throw {message: "Failed to readfile from data: " + name};
|
|
184
|
-
}
|
|
185
|
-
return data[name];
|
|
186
|
-
};
|
|
187
|
-
if (!regenerator) regenerator = vrequire('regenerator');
|
|
188
|
-
var ans;
|
|
189
|
-
if (code) {
|
|
190
|
-
try {
|
|
191
|
-
ans = regenerator.compile(code).code;
|
|
192
|
-
} catch (e) {
|
|
193
|
-
console.error('regenerator failed for code: ' + code + 'with error stack:\n' + e.stack);
|
|
194
|
-
throw e;
|
|
195
|
-
}
|
|
196
|
-
if (!beautify) ans = uglify(ans);
|
|
197
|
-
} else {
|
|
198
|
-
// Return the runtime
|
|
199
|
-
ans = regenerator.compile('', {includeRuntime:true}).code;
|
|
200
|
-
start = ans.indexOf('=') + 1;
|
|
201
|
-
end = ans.lastIndexOf('typeof');
|
|
202
|
-
end = ans.lastIndexOf('}(', end);
|
|
203
|
-
ans = ans.slice(start + 1, end);
|
|
204
|
-
if (!beautify) {
|
|
205
|
-
var extra = '})()';
|
|
206
|
-
ans = uglify(ans + extra).slice(0, extra.length);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
fs.readFileSync = orig;
|
|
210
|
-
return ans;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
179
|
if (typeof this != 'object' || typeof this.sha1sum !== 'function') {
|
|
214
180
|
var sha1sum = function (data) {
|
|
215
181
|
if (!crypto) crypto = require('crypto');
|
|
@@ -222,8 +188,8 @@ if (typeof this != 'object' || typeof this.sha1sum !== 'function') {
|
|
|
222
188
|
function create_compiler() {
|
|
223
189
|
var compilerjs = data['compiler.js'];
|
|
224
190
|
var module = {'id':'compiler', 'exports':{}};
|
|
225
|
-
var wrapped = '(function(module, exports, readfile, writefile, sha1sum
|
|
226
|
-
vm.runInThisContext(wrapped, {'filename': 'compiler.js'})(module, module.exports, readfile_wrapper, writefile_wrapper, sha1sum
|
|
191
|
+
var wrapped = '(function(module, exports, readfile, writefile, sha1sum) {' + data['compiler.js'] + ';\n})';
|
|
192
|
+
vm.runInThisContext(wrapped, {'filename': 'compiler.js'})(module, module.exports, readfile_wrapper, writefile_wrapper, sha1sum);
|
|
227
193
|
return module.exports;
|
|
228
194
|
}
|
|
229
195
|
|