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.
- package/.agignore +1 -0
- package/.gitattributes +4 -0
- package/.github/workflows/ci.yml +38 -0
- package/.github/workflows/web-repl-page-deploy.yml +42 -0
- package/=template.pyj +5 -0
- package/CHANGELOG.md +456 -0
- package/CONTRIBUTORS +13 -0
- package/HACKING.md +103 -0
- package/LICENSE +24 -0
- package/README.md +2512 -0
- package/TODO.md +327 -0
- package/add-toc-to-readme +2 -0
- package/bin/export +75 -0
- package/bin/rapydscript +70 -0
- package/bin/web-repl-export +102 -0
- package/build +3 -0
- package/package.json +46 -0
- package/publish.py +37 -0
- package/release/baselib-plain-pretty.js +4370 -0
- package/release/baselib-plain-ugly.js +3 -0
- package/release/compiler.js +18394 -0
- package/release/signatures.json +31 -0
- package/session.vim +4 -0
- package/setup.cfg +2 -0
- package/src/ast.pyj +1356 -0
- package/src/baselib-builtins.pyj +279 -0
- package/src/baselib-containers.pyj +723 -0
- package/src/baselib-errors.pyj +37 -0
- package/src/baselib-internal.pyj +421 -0
- package/src/baselib-itertools.pyj +97 -0
- package/src/baselib-str.pyj +798 -0
- package/src/compiler.pyj +36 -0
- package/src/errors.pyj +30 -0
- package/src/lib/aes.pyj +646 -0
- package/src/lib/collections.pyj +695 -0
- package/src/lib/elementmaker.pyj +83 -0
- package/src/lib/encodings.pyj +126 -0
- package/src/lib/functools.pyj +148 -0
- package/src/lib/gettext.pyj +569 -0
- package/src/lib/itertools.pyj +580 -0
- package/src/lib/math.pyj +193 -0
- package/src/lib/numpy.pyj +2101 -0
- package/src/lib/operator.pyj +11 -0
- package/src/lib/pythonize.pyj +20 -0
- package/src/lib/random.pyj +118 -0
- package/src/lib/re.pyj +470 -0
- package/src/lib/traceback.pyj +63 -0
- package/src/lib/uuid.pyj +77 -0
- package/src/monaco-language-service/analyzer.js +526 -0
- package/src/monaco-language-service/builtins.js +543 -0
- package/src/monaco-language-service/completions.js +498 -0
- package/src/monaco-language-service/diagnostics.js +643 -0
- package/src/monaco-language-service/dts.js +550 -0
- package/src/monaco-language-service/hover.js +121 -0
- package/src/monaco-language-service/index.js +386 -0
- package/src/monaco-language-service/scope.js +162 -0
- package/src/monaco-language-service/signature.js +144 -0
- package/src/output/__init__.pyj +0 -0
- package/src/output/classes.pyj +296 -0
- package/src/output/codegen.pyj +492 -0
- package/src/output/comments.pyj +45 -0
- package/src/output/exceptions.pyj +105 -0
- package/src/output/functions.pyj +491 -0
- package/src/output/literals.pyj +109 -0
- package/src/output/loops.pyj +444 -0
- package/src/output/modules.pyj +329 -0
- package/src/output/operators.pyj +429 -0
- package/src/output/statements.pyj +463 -0
- package/src/output/stream.pyj +309 -0
- package/src/output/treeshake.pyj +182 -0
- package/src/output/utils.pyj +72 -0
- package/src/parse.pyj +3106 -0
- package/src/string_interpolation.pyj +72 -0
- package/src/tokenizer.pyj +702 -0
- package/src/unicode_aliases.pyj +576 -0
- package/src/utils.pyj +192 -0
- package/test/_import_one.pyj +37 -0
- package/test/_import_two/__init__.pyj +11 -0
- package/test/_import_two/level2/__init__.pyj +0 -0
- package/test/_import_two/level2/deep.pyj +4 -0
- package/test/_import_two/other.pyj +6 -0
- package/test/_import_two/sub.pyj +13 -0
- package/test/aes_vectors.pyj +421 -0
- package/test/annotations.pyj +80 -0
- package/test/baselib.pyj +319 -0
- package/test/classes.pyj +452 -0
- package/test/collections.pyj +152 -0
- package/test/decorators.pyj +77 -0
- package/test/dict_spread.pyj +76 -0
- package/test/docstrings.pyj +39 -0
- package/test/elementmaker_test.pyj +45 -0
- package/test/ellipsis.pyj +49 -0
- package/test/functions.pyj +151 -0
- package/test/generators.pyj +41 -0
- package/test/generic.pyj +370 -0
- package/test/imports.pyj +72 -0
- package/test/internationalization.pyj +73 -0
- package/test/lint.pyj +164 -0
- package/test/loops.pyj +85 -0
- package/test/numpy.pyj +734 -0
- package/test/omit_function_metadata.pyj +20 -0
- package/test/regexp.pyj +55 -0
- package/test/repl.pyj +121 -0
- package/test/scoped_flags.pyj +76 -0
- package/test/starargs.pyj +506 -0
- package/test/starred_assign.pyj +104 -0
- package/test/str.pyj +198 -0
- package/test/subscript_tuple.pyj +53 -0
- package/test/unit/fixtures/fibonacci_expected.js +46 -0
- package/test/unit/index.js +2989 -0
- package/test/unit/language-service-builtins.js +815 -0
- package/test/unit/language-service-completions.js +1067 -0
- package/test/unit/language-service-dts.js +543 -0
- package/test/unit/language-service-hover.js +455 -0
- package/test/unit/language-service-scope.js +833 -0
- package/test/unit/language-service-signature.js +458 -0
- package/test/unit/language-service.js +705 -0
- package/test/unit/run-language-service.js +41 -0
- package/test/unit/web-repl.js +484 -0
- package/tools/build-language-service.js +190 -0
- package/tools/cli.js +547 -0
- package/tools/compile.js +219 -0
- package/tools/compiler.js +108 -0
- package/tools/completer.js +131 -0
- package/tools/embedded_compiler.js +251 -0
- package/tools/export.js +316 -0
- package/tools/gettext.js +185 -0
- package/tools/ini.js +65 -0
- package/tools/lint.js +705 -0
- package/tools/msgfmt.js +187 -0
- package/tools/repl.js +223 -0
- package/tools/self.js +162 -0
- package/tools/test.js +118 -0
- package/tools/utils.js +128 -0
- package/tools/web_repl.js +95 -0
- package/try +41 -0
- package/web-repl/env.js +74 -0
- package/web-repl/index.html +163 -0
- package/web-repl/language-service.js +4084 -0
- package/web-repl/main.js +254 -0
- package/web-repl/prism.css +139 -0
- package/web-repl/prism.js +113 -0
- package/web-repl/rapydscript.js +435 -0
- 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)");
|