rapydscript-ng 0.8.3 → 0.8.4

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 (49) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/bin/build.ts +29 -0
  3. package/package.json +1 -1
  4. package/release/baselib-plain-pretty.js +85 -61
  5. package/release/baselib-plain-ugly.js +3 -3
  6. package/release/compiler.js +2543 -2432
  7. package/release/signatures.json +26 -26
  8. package/src/ast.pyj +170 -58
  9. package/src/baselib-builtins.pyj +35 -14
  10. package/src/baselib-containers.pyj +70 -40
  11. package/src/baselib-internal.pyj +20 -8
  12. package/src/baselib-itertools.pyj +6 -2
  13. package/src/baselib-str.pyj +74 -28
  14. package/src/errors.pyj +4 -1
  15. package/src/lib/aes.pyj +664 -35
  16. package/src/lib/elementmaker.pyj +105 -13
  17. package/src/lib/encodings.pyj +31 -7
  18. package/src/lib/gettext.pyj +6 -3
  19. package/src/lib/math.pyj +38 -22
  20. package/src/lib/pythonize.pyj +5 -3
  21. package/src/lib/random.pyj +13 -5
  22. package/src/lib/re.pyj +81 -18
  23. package/src/lib/traceback.pyj +42 -10
  24. package/src/lib/uuid.pyj +2 -1
  25. package/src/output/classes.pyj +70 -26
  26. package/src/output/codegen.pyj +92 -20
  27. package/src/output/comments.pyj +11 -4
  28. package/src/output/exceptions.pyj +17 -4
  29. package/src/output/functions.pyj +34 -13
  30. package/src/output/literals.pyj +7 -2
  31. package/src/output/loops.pyj +50 -16
  32. package/src/output/modules.pyj +41 -12
  33. package/src/output/operators.pyj +154 -31
  34. package/src/output/statements.pyj +38 -10
  35. package/src/output/stream.pyj +43 -12
  36. package/src/output/utils.pyj +10 -3
  37. package/src/parse.pyj +740 -259
  38. package/src/string_interpolation.pyj +4 -1
  39. package/src/tokenizer.pyj +300 -55
  40. package/src/unicode_aliases.pyj +4 -2
  41. package/src/utils.pyj +19 -5
  42. package/test/functions.pyj +8 -0
  43. package/test/generic.pyj +9 -0
  44. package/test/lsp.pyj +16 -0
  45. package/tools/compiler.mjs +0 -6
  46. package/tools/fmt.mjs +41 -2
  47. package/tools/lint-worker.mjs +7 -1
  48. package/tools/lint.mjs +12 -5
  49. package/tools/lsp.mjs +11 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ version 0.8.4
2
+ ================
3
+ * Fix LSP ignoring globals: comments
4
+ * Fix function call separated by new lines in tuples not being parsed
5
+ * Fix lint not working in standalone binary when linting more than 4 files at once
6
+
1
7
  version 0.8.3
2
8
  =======================
3
9
 
package/bin/build.ts CHANGED
@@ -42,6 +42,29 @@ const stdlib_files: string[] = (await fs.promises.readdir(src_lib_dir))
42
42
  .filter(f => f.endsWith('.pyj'))
43
43
  .sort();
44
44
 
45
+ // --- Pre-bundle the lint worker ---
46
+ // lint-worker.mjs is loaded via Worker() at runtime. In a compiled standalone
47
+ // binary Bun can't JIT-bundle it from the /$bunfs/ virtual FS unless all its
48
+ // transitive imports are already inlined. We pre-bundle it here into a single
49
+ // self-contained file and embed it via `with { type: 'file' }` so the compiled
50
+ // binary has a ready-to-use worker chunk at a known virtual-FS path.
51
+
52
+ const lint_worker_src = path.join(repo_root, 'tools', 'lint-worker.mjs');
53
+ const lint_worker_bundle_path = path.join(bin_dir, 'lint-worker-bundle.mjs');
54
+ const worker_build = await Bun.build({
55
+ entrypoints: [lint_worker_src],
56
+ target: 'bun',
57
+ format: 'esm',
58
+ minify: false,
59
+ });
60
+ if (!worker_build.success) {
61
+ console.error('lint-worker bundle failed:');
62
+ worker_build.logs.forEach(l => console.error(l));
63
+ process.exit(1);
64
+ }
65
+ await Bun.write(lint_worker_bundle_path, worker_build.outputs[0]);
66
+ console.log(`Written ${path.relative(repo_root, lint_worker_bundle_path)}`);
67
+
45
68
  // --- Build the generated asset section ---
46
69
 
47
70
  function var_name(prefix: string, filename: string): string {
@@ -55,6 +78,10 @@ lines.push('// vim:ft=javascript:ts=4:et');
55
78
  lines.push('');
56
79
  lines.push('// === Embedded assets (generated by bin/build.ts) ===');
57
80
 
81
+ // Pre-bundled lint worker: type:'file' embeds the bundle in the binary and
82
+ // returns a virtual-FS path that can be passed directly to new Worker().
83
+ lines.push(`import _lint_worker_url from './lint-worker-bundle.mjs' with { type: 'file' };`);
84
+
58
85
  for (const a of found_dev_text) {
59
86
  lines.push(`import ${var_name('_dev_', a)} from '../dev/${a}' with { type: 'text' };`);
60
87
  }
@@ -81,6 +108,8 @@ for (const f of stdlib_files) {
81
108
  lines.push(` '${f}': ${var_name('_stdlib_', f)},`);
82
109
  }
83
110
  lines.push(' },');
111
+ lines.push(' // Virtual-FS path to the pre-bundled lint worker (set via type:\'file\' import above).');
112
+ lines.push(' \'lint-worker-url\': _lint_worker_url,');
84
113
  lines.push('};');
85
114
  lines.push('');
86
115
  lines.push('// === Entry point (from bin/rapydscript) ===');
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "start": "node bin/rapydscript",
15
15
  "build-self": "node bin/rapydscript self --complete"
16
16
  },
17
- "version": "0.8.3",
17
+ "version": "0.8.4",
18
18
  "license": "BSD-2-Clause",
19
19
  "engines": {
20
20
  "node": ">=0.14.0"
@@ -57,7 +57,7 @@ if (!ρσ_float.__argnames__) Object.defineProperties(ρσ_float, {
57
57
 
58
58
  function ρσ_arraylike_creator() {
59
59
  var names;
60
- names = "Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" ");
60
+ names = ("Int8Array Uint8Array Uint8ClampedArray Int16Array" + " Uint16Array Int32Array Uint32Array Float32Array" + " Float64Array").split(" ");
61
61
  if (typeof HTMLCollection === "function") {
62
62
  names = names.concat("HTMLCollection NodeList NamedNodeMap TouchList".split(" "));
63
63
  }
@@ -617,12 +617,18 @@ if (!ρσ_max.__handles_kwarg_interpolation__) Object.defineProperties(ρσ_max,
617
617
  __module__ : {value: "__main__"}
618
618
  });
619
619
 
620
- var abs = Math.abs, max = ρσ_max.bind(Math.max), min = ρσ_max.bind(Math.min), bool = ρσ_bool, type = ρσ_type;
621
- var float = ρσ_float, int = ρσ_int, arraylike = ρσ_arraylike_creator(), ρσ_arraylike = arraylike;
622
- var print = ρσ_print, id = ρσ_id, get_module = ρσ_get_module, pow = ρσ_pow, divmod = ρσ_divmod;
623
- var dir = ρσ_dir, ord = ρσ_ord, chr = ρσ_chr, bin = ρσ_bin, hex = ρσ_hex, callable = ρσ_callable;
624
- var enumerate = ρσ_enumerate, iter = ρσ_iter, reversed = ρσ_reversed, len = ρσ_len;
625
- var range = ρσ_range, getattr = ρσ_getattr, setattr = ρσ_setattr, hasattr = ρσ_hasattr;function ρσ_equals(a, b) {
620
+ var abs = Math.abs, max = ρσ_max.bind(Math.max);
621
+ var min = ρσ_max.bind(Math.min), bool = ρσ_bool, type = ρσ_type;
622
+ var float = ρσ_float, int = ρσ_int, arraylike = ρσ_arraylike_creator();
623
+ var ρσ_arraylike = arraylike;
624
+ var print = ρσ_print, id = ρσ_id, get_module = ρσ_get_module;
625
+ var pow = ρσ_pow, divmod = ρσ_divmod;
626
+ var dir = ρσ_dir, ord = ρσ_ord, chr = ρσ_chr, bin = ρσ_bin;
627
+ var hex = ρσ_hex, callable = ρσ_callable;
628
+ var enumerate = ρσ_enumerate, iter = ρσ_iter, reversed = ρσ_reversed;
629
+ var len = ρσ_len;
630
+ var range = ρσ_range, getattr = ρσ_getattr, setattr = ρσ_setattr;
631
+ var hasattr = ρσ_hasattr;function ρσ_equals(a, b) {
626
632
  var ρσ_unpack, akeys, bkeys, key;
627
633
  if (a === b) {
628
634
  return true;
@@ -1012,34 +1018,38 @@ if (typeof Array.prototype.append !== "function") {
1012
1018
  if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "reverse")){
1013
1019
  reverse = ρσ_kwargs_obj.reverse;
1014
1020
  }
1015
- var mult, keymap, posmap, k;
1016
- function _sort_key(value) {
1017
- var t;
1018
- t = typeof value;
1019
- if (t === "string" || t === "number") {
1020
- return value;
1021
- }
1022
- return value.toString();
1023
- };
1024
- if (!_sort_key.__argnames__) Object.defineProperties(_sort_key, {
1025
- __argnames__ : {value: ["value"]},
1026
- __module__ : {value: "__main__"}
1027
- });
1028
-
1029
- function _sort_cmp(a, b, ap, bp) {
1030
- if (a < b) {
1031
- return -1;
1032
- }
1033
- if (a > b) {
1034
- return 1;
1035
- }
1036
- return ap - bp;
1037
- };
1038
- if (!_sort_cmp.__argnames__) Object.defineProperties(_sort_cmp, {
1039
- __argnames__ : {value: ["a", "b", "ap", "bp"]},
1040
- __module__ : {value: "__main__"}
1041
- });
1042
-
1021
+ var _sort_key, _sort_cmp, mult, keymap, posmap, k;
1022
+ _sort_key = (function() {
1023
+ var ρσ_anonfunc = function (value) {
1024
+ var t;
1025
+ t = typeof value;
1026
+ if (t === "string" || t === "number") {
1027
+ return value;
1028
+ }
1029
+ return value.toString();
1030
+ };
1031
+ if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
1032
+ __argnames__ : {value: ["value"]},
1033
+ __module__ : {value: "__main__"}
1034
+ });
1035
+ return ρσ_anonfunc;
1036
+ })();
1037
+ _sort_cmp = (function() {
1038
+ var ρσ_anonfunc = function (a, b, ap, bp) {
1039
+ if (a < b) {
1040
+ return -1;
1041
+ }
1042
+ if (a > b) {
1043
+ return 1;
1044
+ }
1045
+ return ap - bp;
1046
+ };
1047
+ if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
1048
+ __argnames__ : {value: ["a", "b", "ap", "bp"]},
1049
+ __module__ : {value: "__main__"}
1050
+ });
1051
+ return ρσ_anonfunc;
1052
+ })();
1043
1053
  key = key || _sort_key;
1044
1054
  mult = (reverse) ? -1 : 1;
1045
1055
  keymap = dict();
@@ -3212,7 +3222,7 @@ if (!all.__argnames__) Object.defineProperties(all, {
3212
3222
  __argnames__ : {value: ["iterable"]},
3213
3223
  __module__ : {value: "__main__"}
3214
3224
  });
3215
- var decimal_sep, define_str_func, ρσ_unpack, ρσ_orig_split, ρσ_orig_replace;
3225
+ var decimal_sep, define_str_func, ρσ_orig_split, ρσ_orig_replace;
3216
3226
  decimal_sep = 1.1.toLocaleString()[1];
3217
3227
  function ρσ_repr_js_builtin(x, as_array) {
3218
3228
  var ans, b, keys, key;
@@ -3263,7 +3273,7 @@ if (!ρσ_html_element_to_string.__argnames__) Object.defineProperties(ρσ_html
3263
3273
  });
3264
3274
 
3265
3275
  function ρσ_repr(x) {
3266
- var ans, name;
3276
+ var ans, name, mapped;
3267
3277
  if (x === null) {
3268
3278
  return "None";
3269
3279
  }
@@ -3283,8 +3293,8 @@ function ρσ_repr(x) {
3283
3293
  ans = ρσ_repr_js_builtin(x);
3284
3294
  } else {
3285
3295
  name = Object.prototype.toString.call(x).slice(8, -1);
3286
- if (ρσ_not_equals("Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".indexOf(name), -1)) {
3287
- return name + "([" + x.map((function() {
3296
+ if (ρσ_not_equals(("Int8Array Uint8Array Uint8ClampedArray Int16Array" + " Uint16Array Int32Array Uint32Array" + " Float32Array Float64Array").indexOf(name), -1)) {
3297
+ mapped = x.map((function() {
3288
3298
  var ρσ_anonfunc = function (i) {
3289
3299
  return str.format("0x{:02x}", i);
3290
3300
  };
@@ -3293,7 +3303,8 @@ function ρσ_repr(x) {
3293
3303
  __module__ : {value: "__main__"}
3294
3304
  });
3295
3305
  return ρσ_anonfunc;
3296
- })()).join(", ") + "])";
3306
+ })());
3307
+ return name + "([" + mapped.join(", ") + "])";
3297
3308
  }
3298
3309
  if (typeof HTMLElement !== "undefined" && x instanceof HTMLElement) {
3299
3310
  ans = ρσ_html_element_to_string(x);
@@ -3319,7 +3330,7 @@ if (!ρσ_repr.__argnames__) Object.defineProperties(ρσ_repr, {
3319
3330
  });
3320
3331
 
3321
3332
  function ρσ_str(x) {
3322
- var ans, name;
3333
+ var ans, name, mapped;
3323
3334
  if (x === null) {
3324
3335
  return "None";
3325
3336
  }
@@ -3337,8 +3348,8 @@ function ρσ_str(x) {
3337
3348
  ans = ρσ_repr_js_builtin(x, true);
3338
3349
  } else if (typeof x.toString === "function") {
3339
3350
  name = Object.prototype.toString.call(x).slice(8, -1);
3340
- if (ρσ_not_equals("Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".indexOf(name), -1)) {
3341
- return name + "([" + x.map((function() {
3351
+ if (ρσ_not_equals(("Int8Array Uint8Array Uint8ClampedArray Int16Array" + " Uint16Array Int32Array Uint32Array" + " Float32Array Float64Array").indexOf(name), -1)) {
3352
+ mapped = x.map((function() {
3342
3353
  var ρσ_anonfunc = function (i) {
3343
3354
  return str.format("0x{:02x}", i);
3344
3355
  };
@@ -3347,7 +3358,8 @@ function ρσ_str(x) {
3347
3358
  __module__ : {value: "__main__"}
3348
3359
  });
3349
3360
  return ρσ_anonfunc;
3350
- })()).join(", ") + "])";
3361
+ })());
3362
+ return name + "([" + mapped.join(", ") + "])";
3351
3363
  }
3352
3364
  if (typeof HTMLElement !== "undefined" && x instanceof HTMLElement) {
3353
3365
  ans = ρσ_html_element_to_string(x);
@@ -3386,9 +3398,8 @@ define_str_func = (function() {
3386
3398
  });
3387
3399
  return ρσ_anonfunc;
3388
3400
  })();
3389
- ρσ_unpack = [String.prototype.split.call.bind(String.prototype.split), String.prototype.replace.call.bind(String.prototype.replace)];
3390
- ρσ_orig_split = ρσ_unpack[0];
3391
- ρσ_orig_replace = ρσ_unpack[1];
3401
+ ρσ_orig_split = String.prototype.split.call.bind(String.prototype.split);
3402
+ ρσ_orig_replace = String.prototype.replace.call.bind(String.prototype.replace);
3392
3403
  define_str_func("format", (function() {
3393
3404
  var ρσ_anonfunc = function () {
3394
3405
  var template, args, kwargs, explicit, implicit, idx, split, ans, pos, in_brace, markup, ch;
@@ -3430,10 +3441,12 @@ define_str_func("format", (function() {
3430
3441
  });
3431
3442
 
3432
3443
  function resolve_format_spec(format_spec) {
3444
+ var pat;
3433
3445
  if (ρσ_str.format._template_resolve_fs_pat === undefined) {
3434
3446
  ρσ_str.format._template_resolve_fs_pat = /[{]([a-zA-Z0-9_]+)[}]/g;
3435
3447
  }
3436
- return format_spec.replace(ρσ_str.format._template_resolve_fs_pat, (function() {
3448
+ pat = ρσ_str.format._template_resolve_fs_pat;
3449
+ return format_spec.replace(pat, (function() {
3437
3450
  var ρσ_anonfunc = function (match, key) {
3438
3451
  if (!Object.prototype.hasOwnProperty.call(kwargs, key)) {
3439
3452
  return "";
@@ -3482,11 +3495,19 @@ define_str_func("format", (function() {
3482
3495
  });
3483
3496
 
3484
3497
  function safe_fixed(value, precision, comma) {
3498
+ var ufmt;
3485
3499
  if (!comma) {
3486
3500
  return value.toFixed(precision);
3487
3501
  }
3488
3502
  try {
3489
- return set_comma(value.toLocaleString(undefined, {useGrouping: true, minimumFractionDigits: precision, maximumFractionDigits: precision}), comma);
3503
+ ufmt = (function(){
3504
+ var ρσ_d = {};
3505
+ ρσ_d["useGrouping"] = true;
3506
+ ρσ_d["minimumFractionDigits"] = precision;
3507
+ ρσ_d["maximumFractionDigits"] = precision;
3508
+ return ρσ_d;
3509
+ }).call(this);
3510
+ return set_comma(value.toLocaleString(undefined, ufmt), comma);
3490
3511
  } catch (ρσ_Exception) {
3491
3512
  ρσ_last_exception = ρσ_Exception;
3492
3513
  {
@@ -3500,7 +3521,7 @@ define_str_func("format", (function() {
3500
3521
  });
3501
3522
 
3502
3523
  function apply_formatting(value, format_spec) {
3503
- var ρσ_unpack, fill, align, sign, fhash, zeropad, width, comma, precision, ftype, is_numeric, is_int, lftype, code, prec, exp, nval, is_positive, left, right;
3524
+ var m, ρσ_unpack, fill, align, sign, fhash, zeropad, width, comma, precision, ftype, is_numeric, is_int, lftype, code, prec, exp, nval, is_positive, left, right;
3504
3525
  if (format_spec.indexOf("{") !== -1) {
3505
3526
  format_spec = resolve_format_spec(format_spec);
3506
3527
  }
@@ -3508,17 +3529,18 @@ define_str_func("format", (function() {
3508
3529
  ρσ_str.format._template_format_pat = /([^{}](?=[<>=^]))?([<>=^])?([-+\x20])?(\#)?(0)?(\d+)?([,_])?(?:\.(\d+))?([bcdeEfFgGnosxX%])?/;
3509
3530
  }
3510
3531
  try {
3511
- ρσ_unpack = format_spec.match(ρσ_str.format._template_format_pat).slice(1);
3512
- ρσ_unpack = ρσ_unpack_asarray(9, ρσ_unpack);
3532
+ m = format_spec.match(ρσ_str.format._template_format_pat);
3533
+ ρσ_unpack = [m[1], m[2], m[3], m[4], m[5]];
3513
3534
  fill = ρσ_unpack[0];
3514
3535
  align = ρσ_unpack[1];
3515
3536
  sign = ρσ_unpack[2];
3516
3537
  fhash = ρσ_unpack[3];
3517
3538
  zeropad = ρσ_unpack[4];
3518
- width = ρσ_unpack[5];
3519
- comma = ρσ_unpack[6];
3520
- precision = ρσ_unpack[7];
3521
- ftype = ρσ_unpack[8];
3539
+ ρσ_unpack = [m[6], m[7], m[8], m[9]];
3540
+ width = ρσ_unpack[0];
3541
+ comma = ρσ_unpack[1];
3542
+ precision = ρσ_unpack[2];
3543
+ ftype = ρσ_unpack[3];
3522
3544
  } catch (ρσ_Exception) {
3523
3545
  ρσ_last_exception = ρσ_Exception;
3524
3546
  if (ρσ_Exception instanceof TypeError) {
@@ -3728,7 +3750,7 @@ define_str_func("format", (function() {
3728
3750
  if (lkey) {
3729
3751
  explicit = true;
3730
3752
  if (implicit) {
3731
- throw new ValueError("cannot switch from automatic field numbering to manual field specification");
3753
+ throw new ValueError("cannot switch from automatic field numbering" + " to manual field specification");
3732
3754
  }
3733
3755
  nvalue = parseInt(lkey);
3734
3756
  object = (isNaN(nvalue)) ? kwargs[(typeof lkey === "number" && lkey < 0) ? kwargs.length + lkey : lkey] : args[(typeof nvalue === "number" && nvalue < 0) ? args.length + nvalue : nvalue];
@@ -3742,7 +3764,7 @@ define_str_func("format", (function() {
3742
3764
  } else {
3743
3765
  implicit = true;
3744
3766
  if (explicit) {
3745
- throw new ValueError("cannot switch from manual field specification to automatic field numbering");
3767
+ throw new ValueError("cannot switch from manual field specification" + " to automatic field numbering");
3746
3768
  }
3747
3769
  if (idx >= args.length) {
3748
3770
  throw new IndexError("Not enough arguments to match template: " + template);
@@ -3831,11 +3853,13 @@ define_str_func("capitalize", (function() {
3831
3853
  })());
3832
3854
  define_str_func("center", (function() {
3833
3855
  var ρσ_anonfunc = function (width, fill) {
3834
- var left, right;
3856
+ var left, right, left_pad, right_pad;
3835
3857
  left = Math.floor((width - this.length) / 2);
3836
3858
  right = width - left - this.length;
3837
3859
  fill = fill || " ";
3838
- return new Array(left+1).join(fill) + this + new Array(right+1).join(fill);
3860
+ left_pad = new Array(left+1).join(fill);
3861
+ right_pad = new Array(right+1).join(fill);
3862
+ return left_pad + this + right_pad;
3839
3863
  };
3840
3864
  if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
3841
3865
  __argnames__ : {value: ["width", "fill"]},
@@ -4483,7 +4507,7 @@ define_str_func("zfill", (function() {
4483
4507
  ρσ_str.ascii_letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
4484
4508
  ρσ_str.digits = "0123456789";
4485
4509
  ρσ_str.punctuation = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
4486
- ρσ_str.printable = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\u000b\f";
4510
+ ρσ_str.printable = "0123456789abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\u000b\f";
4487
4511
  ρσ_str.whitespace = " \t\n\r\u000b\f";
4488
4512
  define_str_func = undefined;
4489
4513
  var str = ρσ_str, repr = ρσ_repr;