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,190 @@
1
+ #!/usr/bin/env node
2
+ // tools/build-language-service.js
3
+ // Bundles src/monaco-language-service/*.js into a single ES module.
4
+ // No external dependencies — pure Node.js string processing.
5
+ //
6
+ // Usage:
7
+ // node tools/build-language-service.js [--out <path>]
8
+ // npm run build:ls
9
+
10
+ "use strict";
11
+
12
+ var fs = require("fs");
13
+ var path = require("path");
14
+
15
+ var SRC_DIR = path.join(__dirname, "..", "src", "monaco-language-service");
16
+ var COMPILER_JS = path.join(__dirname, "..", "web-repl", "rapydscript.js");
17
+ var DEFAULT_OUT = path.join(__dirname, "..", "web-repl", "language-service.js");
18
+
19
+ // Parse --out flag
20
+ var out_path = DEFAULT_OUT;
21
+ var argv = process.argv.slice(2);
22
+ var out_idx = argv.indexOf("--out");
23
+ if (out_idx !== -1 && argv[out_idx + 1]) {
24
+ out_path = path.resolve(argv[out_idx + 1]);
25
+ }
26
+
27
+ // ── Dependency order ──────────────────────────────────────────────────────────
28
+ // Files are listed in topological order so that when imports are stripped,
29
+ // all referenced identifiers are already defined above.
30
+
31
+ var FILES = [
32
+ "scope.js", // no internal deps
33
+ "diagnostics.js", // no internal deps
34
+ "analyzer.js", // imports from scope.js
35
+ "completions.js", // imports from analyzer.js
36
+ "signature.js", // no internal deps
37
+ "dts.js", // no internal deps
38
+ "builtins.js", // no internal deps
39
+ "hover.js", // imports from dts.js, builtins.js (type refs only)
40
+ "index.js", // imports from all above
41
+ ];
42
+
43
+ // ── Public exports ────────────────────────────────────────────────────────────
44
+ // Only registerRapydScript is part of the public API.
45
+ // Internal classes (ScopeMap, SourceAnalyzer, Diagnostics, …) remain accessible
46
+ // via the returned service object but are not re-exported.
47
+
48
+ var PUBLIC_EXPORTS = ["registerRapydScript", "web_repl"];
49
+
50
+ // ── Embed the RapydScript compiler ────────────────────────────────────────────
51
+ // rapydscript.js uses (function(external_namespace){...})(this) to attach to
52
+ // the global. In strict ES modules `this` is undefined, so we wrap it in an
53
+ // IIFE that passes a plain object and captures the result as _RS_COMPILER.
54
+
55
+ var compiler_src = fs.readFileSync(COMPILER_JS, "utf8").replace(/\r\n/g, "\n");
56
+
57
+ // Strip leading vim modeline comment (first line).
58
+ compiler_src = compiler_src.replace(/^\/\/[^\n]*\n/, "");
59
+
60
+ // Replace the trailing })(this); with })(_container); so the namespace is
61
+ // captured into our container object instead of being attached to the global.
62
+ compiler_src = compiler_src.replace(/\}\)\(this\)\s*;?\s*$/, "})(_container);");
63
+
64
+ // Augmentation code injected inside the IIFE (has access to `namespace` and
65
+ // `create_compiler` which are private locals inside rapydscript.js).
66
+ // The language service needs parse(), OutputStream, SyntaxError, ImportError,
67
+ // NATIVE_CLASSES, tree_shake, and ALL AST_* classes — all of which live on the
68
+ // inner compiler object returned by create_compiler(), not on the outer namespace.
69
+ // We expose them lazily: on first access the inner compiler is eval'd once and
70
+ // ALL of its keys (including every AST_ class) are copied onto namespace.
71
+ var augment_src = [
72
+ "",
73
+ "// Expose inner compiler API (parse, OutputStream, AST_*, etc.) on namespace",
74
+ "// for the language service. Lazily initialises the inner compiler on first",
75
+ "// property access so the large eval() only runs when actually needed.",
76
+ "(function() {",
77
+ " var _inner = null;",
78
+ " function _initInner() {",
79
+ " if (_inner) return;",
80
+ " _inner = create_compiler();",
81
+ " // Copy every key from the inner compiler (including all AST_* classes)",
82
+ " // directly onto namespace, skipping keys that already have lazy getters.",
83
+ " var keys = Object.keys(_inner);",
84
+ " for (var i = 0; i < keys.length; i++) {",
85
+ " var k = keys[i];",
86
+ " if (!(k in namespace)) namespace[k] = _inner[k];",
87
+ " }",
88
+ " }",
89
+ " // Install lazy getters for a small set of sentinel keys so that the",
90
+ " // inner compiler is initialised on first use. The getter returns",
91
+ " // _inner[k] directly to avoid re-entering the getter (namespace[k]",
92
+ " // would recurse because the getter is still installed).",
93
+ " var LAZY_KEYS = ['parse','OutputStream','SyntaxError','ImportError','NATIVE_CLASSES','tree_shake'];",
94
+ " LAZY_KEYS.forEach(function(k) {",
95
+ " if (!(k in namespace)) {",
96
+ " Object.defineProperty(namespace, k, {",
97
+ " get: function() { _initInner(); return _inner[k]; },",
98
+ " configurable: true,",
99
+ " enumerable: false,",
100
+ " });",
101
+ " }",
102
+ " });",
103
+ "})();",
104
+ "",
105
+ ].join("\n");
106
+
107
+ // Inject augmentation just before the closing })(_container);
108
+ compiler_src = compiler_src.replace(/\}\)\(_container\)\s*;?\s*$/, augment_src + "})(_container);");
109
+
110
+ var compiler_chunk = [
111
+ "// ── rapydscript.js (embedded compiler) " + "─".repeat(29),
112
+ "",
113
+ "const _RS_COMPILER = (() => {",
114
+ " const _container = {};",
115
+ compiler_src,
116
+ " return _container.RapydScript;",
117
+ "})();",
118
+ "",
119
+ ].join("\n");
120
+
121
+ // ── Process each file ─────────────────────────────────────────────────────────
122
+
123
+ var chunks = [
124
+ "// language-service.js — RapydScript Monaco Language Service",
125
+ "// Auto-generated by tools/build-language-service.js — do not edit directly.",
126
+ "// Source: src/monaco-language-service/ + web-repl/rapydscript.js (embedded)",
127
+ "// Usage: import { registerRapydScript } from './language-service.js';",
128
+ "// No external compiler bundle needed — the compiler is bundled inside.",
129
+ "",
130
+ compiler_chunk,
131
+ ];
132
+
133
+ FILES.forEach(function (file) {
134
+ var src = fs.readFileSync(path.join(SRC_DIR, file), "utf8").replace(/\r\n/g, "\n");
135
+
136
+ var processed = src
137
+ // 1. Remove import lines (all resolved by concatenation order).
138
+ // Handles both single-line imports, including those with extra whitespace.
139
+ .replace(/^import\s+\{[^}]*\}\s+from\s+['"][^'"]+['"]\s*;?\r?\n/gm, "")
140
+ // 2. Strip the `export` keyword from inline class/function declarations.
141
+ .replace(/^export\s+((?:class|function)\s)/gm, "$1")
142
+ // 3. Remove any bare `export { ... };` blocks left over.
143
+ .replace(/^export\s+\{[^}]*\}\s*;?\r?\n/gm, "")
144
+ // 4. In index.js: make options.compiler optional — fall back to the
145
+ // embedded _RS_COMPILER captured above.
146
+ .replace(
147
+ "const compiler = options.compiler;\n if (!compiler) throw new Error('registerRapydScript: options.compiler is required');",
148
+ "const compiler = options.compiler || _RS_COMPILER;\n if (!compiler) throw new Error('registerRapydScript: compiler bundle not found');"
149
+ )
150
+ // 5. Update the usage comment in index.js to reflect that compiler is optional.
151
+ .replace(
152
+ "// compiler: window.RapydScript, // compiled rapydscript bundle",
153
+ "// compiler: window.RapydScript, // optional — embedded compiler is used by default"
154
+ )
155
+ .trimEnd();
156
+
157
+ chunks.push(
158
+ "",
159
+ "// ── " + file + " " + "─".repeat(Math.max(1, 68 - file.length)),
160
+ "",
161
+ processed,
162
+ ""
163
+ );
164
+ });
165
+
166
+ // ── Compiler utility exports ──────────────────────────────────────────────────
167
+ chunks.push(
168
+ "// ── Compiler utility exports " + "─".repeat(41),
169
+ "",
170
+ "/** Returns a web_repl compiler instance (same as RapydScript.web_repl()). */",
171
+ "function web_repl() { return _RS_COMPILER.web_repl(); }",
172
+ ""
173
+ );
174
+
175
+ // ── Final named export ────────────────────────────────────────────────────────
176
+ chunks.push("export { " + PUBLIC_EXPORTS.join(", ") + " };", "");
177
+
178
+ var output = chunks.join("\n");
179
+
180
+ // Ensure output directory exists
181
+ var out_dir = path.dirname(out_path);
182
+ if (!fs.existsSync(out_dir)) {
183
+ fs.mkdirSync(out_dir, { recursive: true });
184
+ }
185
+
186
+ fs.writeFileSync(out_path, output, "utf8");
187
+
188
+ var rel = path.relative(process.cwd(), out_path);
189
+ var kb = (output.length / 1024).toFixed(1);
190
+ console.log("Built: " + rel + " (" + kb + " KB)");