rapydscript-ng 0.7.24 → 0.8.1
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 +28 -0
- package/README.md +80 -26
- package/bin/build.ts +117 -0
- package/bin/package.json +1 -0
- package/bin/rapydscript +65 -62
- package/build_wheels.py +133 -0
- package/editor-plugins/README.md +80 -0
- package/editor-plugins/nvim.lua +321 -0
- package/local-agent.md +28 -0
- package/package.json +4 -5
- package/publish.py +27 -17
- package/release/baselib-plain-pretty.js +448 -326
- package/release/baselib-plain-ugly.js +3 -3
- package/release/compiler.js +9027 -8139
- package/release/signatures.json +27 -27
- package/release/stdlib_modules.json +1 -0
- package/src/ast.pyj +428 -280
- package/src/baselib-builtins.pyj +49 -28
- package/src/baselib-containers.pyj +241 -226
- package/src/baselib-errors.pyj +8 -1
- package/src/baselib-internal.pyj +38 -23
- package/src/baselib-itertools.pyj +13 -7
- package/src/baselib-str.pyj +59 -84
- package/src/compiler.pyj +4 -4
- package/src/errors.pyj +3 -4
- package/src/lib/aes.pyj +46 -32
- package/src/lib/elementmaker.pyj +11 -9
- package/src/lib/encodings.pyj +15 -5
- package/src/lib/gettext.pyj +9 -4
- package/src/lib/math.pyj +106 -45
- package/src/lib/operator.pyj +10 -10
- package/src/lib/pythonize.pyj +2 -1
- package/src/lib/random.pyj +28 -21
- package/src/lib/re.pyj +492 -19
- package/src/lib/traceback.pyj +171 -29
- package/src/lib/uuid.pyj +2 -2
- package/src/output/classes.pyj +28 -27
- package/src/output/codegen.pyj +87 -83
- package/src/output/comments.pyj +8 -8
- package/src/output/exceptions.pyj +20 -21
- package/src/output/functions.pyj +66 -64
- package/src/output/literals.pyj +24 -23
- package/src/output/loops.pyj +84 -142
- package/src/output/modules.pyj +55 -68
- package/src/output/operators.pyj +40 -29
- package/src/output/statements.pyj +21 -15
- package/src/output/stream.pyj +82 -56
- package/src/output/utils.pyj +12 -8
- package/src/parse.pyj +971 -620
- package/src/string_interpolation.pyj +5 -3
- package/src/tokenizer.pyj +188 -148
- package/src/utils.pyj +32 -15
- package/test/_treeshake_mod.pyj +30 -0
- package/test/_treeshake_side_effect.pyj +9 -0
- package/test/ast_serialization.pyj +392 -0
- package/test/async.pyj +95 -0
- package/test/baselib.pyj +1 -2
- package/test/embedded_compiler.pyj +57 -0
- package/test/fmt.pyj +291 -0
- package/test/generic.pyj +16 -3
- package/test/imports.pyj +8 -6
- package/test/internationalization.pyj +38 -37
- package/test/lint.pyj +120 -117
- package/test/lsp.pyj +257 -0
- package/test/repl.pyj +70 -65
- package/test/sourcemaps.pyj +315 -0
- package/test/starargs.pyj +46 -39
- package/test/str.pyj +8 -0
- package/test/traceback.pyj +263 -0
- package/test/treeshaking.pyj +181 -0
- package/test/web_repl_export.pyj +88 -0
- package/tools/ast_serialize.mjs +557 -0
- package/tools/cli.mjs +531 -0
- package/tools/compile.mjs +205 -0
- package/tools/compiler.mjs +159 -0
- package/tools/{completer.js → completer.mjs} +6 -6
- package/tools/{embedded_compiler.js → embedded_compiler.mjs} +17 -13
- package/tools/export.js +109 -56
- package/tools/fmt.mjs +975 -0
- package/tools/{gettext.js → gettext.mjs} +46 -53
- package/tools/ini.mjs +175 -0
- package/tools/{lint.js → lint.mjs} +78 -55
- package/tools/lsp.mjs +964 -0
- package/tools/lsp_protocol.mjs +259 -0
- package/tools/lsp_symbols.mjs +418 -0
- package/tools/{msgfmt.js → msgfmt.mjs} +18 -18
- package/tools/{repl.js → repl.mjs} +56 -42
- package/tools/{self.js → self.mjs} +71 -46
- package/tools/sourcemap.mjs +123 -0
- package/tools/test.mjs +252 -0
- package/tools/treeshake.mjs +400 -0
- package/tools/{utils.js → utils.mjs} +26 -23
- package/tools/{web_repl.js → web_repl.mjs} +15 -13
- package/tools/web_repl_export.mjs +97 -0
- package/tree-sitter/README.md +101 -0
- package/tree-sitter/grammar.js +992 -0
- package/tree-sitter/package.json +43 -0
- package/tree-sitter/queries/highlights.scm +232 -0
- package/tree-sitter/queries/indents.scm +64 -0
- package/tree-sitter/queries/injections.scm +14 -0
- package/tree-sitter/queries/locals.scm +108 -0
- package/tree-sitter/src/grammar.json +4976 -0
- package/tree-sitter/src/node-types.json +2901 -0
- package/tree-sitter/src/parser.c +196465 -0
- package/tree-sitter/src/scanner.c +294 -0
- package/tree-sitter/src/tree_sitter/alloc.h +54 -0
- package/tree-sitter/src/tree_sitter/array.h +330 -0
- package/tree-sitter/src/tree_sitter/parser.h +286 -0
- package/tree-sitter/test/corpus/chaining.txt +99 -0
- package/tree-sitter/test/corpus/classes.txt +147 -0
- package/tree-sitter/test/corpus/comprehensions.txt +155 -0
- package/tree-sitter/test/corpus/containers.txt +242 -0
- package/tree-sitter/test/corpus/control_flow.txt +361 -0
- package/tree-sitter/test/corpus/decorators.txt +64 -0
- package/tree-sitter/test/corpus/existential.txt +102 -0
- package/tree-sitter/test/corpus/functions.txt +293 -0
- package/tree-sitter/test/corpus/imports.txt +117 -0
- package/tree-sitter/test/corpus/literals.txt +135 -0
- package/tree-sitter/test/corpus/operators.txt +296 -0
- package/tree-sitter/test/corpus/statements.txt +189 -0
- package/tree-sitter/test/corpus/strings.txt +90 -0
- package/tree-sitter/test/corpus/subscripts.txt +227 -0
- package/tree-sitter/tree-sitter.json +36 -0
- package/web-repl/env.js +35 -23
- package/web-repl/main.js +8 -8
- package/bin/export +0 -75
- package/bin/web-repl-export +0 -102
- package/tools/cli.js +0 -523
- package/tools/compile.js +0 -184
- package/tools/compiler.js +0 -84
- package/tools/ini.js +0 -65
- package/tools/test.js +0 -110
package/tools/compiler.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/* vim:fileencoding=utf-8
|
|
2
|
-
*
|
|
3
|
-
* Copyright (C) 2015 Kovid Goyal <kovid at kovidgoyal.net>
|
|
4
|
-
*
|
|
5
|
-
* Distributed under terms of the BSD license
|
|
6
|
-
*/
|
|
7
|
-
"use strict"; /*jshint node:true */
|
|
8
|
-
|
|
9
|
-
// Thin wrapper around (release|dev)/compiler.js to setup some global facilities and
|
|
10
|
-
// export the compiler's symbols safely.
|
|
11
|
-
|
|
12
|
-
var path = require("path");
|
|
13
|
-
var fs = require("fs");
|
|
14
|
-
var crypto = require('crypto');
|
|
15
|
-
var vm = require("vm");
|
|
16
|
-
var regenerator = require('regenerator');
|
|
17
|
-
var UglifyJS = require("uglify-js");
|
|
18
|
-
|
|
19
|
-
function sha1sum(data) {
|
|
20
|
-
var h = crypto.createHash('sha1');
|
|
21
|
-
h.update(data);
|
|
22
|
-
return h.digest('hex');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function path_exists(path) {
|
|
26
|
-
try {
|
|
27
|
-
fs.statSync(path);
|
|
28
|
-
return true;
|
|
29
|
-
} catch(e) {
|
|
30
|
-
if (e.code != 'ENOENT') throw e;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function uglify(code) {
|
|
35
|
-
var ans = UglifyJS.minify(code);
|
|
36
|
-
if (ans.error) throw ans.error;
|
|
37
|
-
return ans.code;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
function create_compiler() {
|
|
64
|
-
var compiler_exports = {};
|
|
65
|
-
var compiler_context = vm.createContext({
|
|
66
|
-
console : console,
|
|
67
|
-
readfile : fs.readFileSync,
|
|
68
|
-
writefile : fs.writeFileSync,
|
|
69
|
-
sha1sum : sha1sum,
|
|
70
|
-
require : require,
|
|
71
|
-
regenerate : regenerate,
|
|
72
|
-
exports : compiler_exports,
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
var base = path.dirname(path.dirname(module.filename));
|
|
76
|
-
var compiler_dir = path.join(base, 'dev');
|
|
77
|
-
if (!path_exists(path.join(compiler_dir, 'compiler.js'))) compiler_dir = path.join(base, 'release');
|
|
78
|
-
var compiler_file = path.join(compiler_dir, 'compiler.js');
|
|
79
|
-
var compilerjs = fs.readFileSync(compiler_file, 'utf-8');
|
|
80
|
-
vm.runInContext(compilerjs, compiler_context, path.relative(base, compiler_file));
|
|
81
|
-
return compiler_exports;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
exports.create_compiler = create_compiler;
|
package/tools/ini.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/* vim:fileencoding=utf-8
|
|
2
|
-
*
|
|
3
|
-
* Copyright (C) 2015 Kovid Goyal <kovid at kovidgoyal.net>
|
|
4
|
-
*
|
|
5
|
-
* Distributed under terms of the BSD license
|
|
6
|
-
*/
|
|
7
|
-
"use strict"; /*jshint node:true */
|
|
8
|
-
|
|
9
|
-
var fs = require('fs');
|
|
10
|
-
var path = require('path');
|
|
11
|
-
|
|
12
|
-
function parse_ini_data(data) {
|
|
13
|
-
// Based on MIT licensed code from:
|
|
14
|
-
// https://github.com/shockie/node-iniparser/blob/master/lib/node-iniparser.js
|
|
15
|
-
var ans = {}, match;
|
|
16
|
-
var lines = data.split(/\r\n|\r|\n/);
|
|
17
|
-
var section = null;
|
|
18
|
-
var section_pat = /^\s*\[\s*([^\]]*)\s*\]\s*$/;
|
|
19
|
-
var param_pat = /^\s*([\w\.\-\_]+)\s*=\s*(.*?)\s*$/;
|
|
20
|
-
var comment_pat = /^\s*;.*$/;
|
|
21
|
-
|
|
22
|
-
lines.forEach(function(line) {
|
|
23
|
-
if(comment_pat.test(line)) {
|
|
24
|
-
return;
|
|
25
|
-
} else if(param_pat.test(line)) {
|
|
26
|
-
match = line.match(param_pat);
|
|
27
|
-
if(section) {
|
|
28
|
-
ans[section][match[1]] = match[2];
|
|
29
|
-
} else {
|
|
30
|
-
ans[match[1]] = match[2];
|
|
31
|
-
}
|
|
32
|
-
} else if(section_pat.test(line)) {
|
|
33
|
-
match = line.match(section_pat);
|
|
34
|
-
ans[match[1]] = {};
|
|
35
|
-
section = match[1];
|
|
36
|
-
} else if(line.length === 0 && section) {
|
|
37
|
-
section = null;
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
return ans;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function find_cfg_file(toplevel_dir) {
|
|
44
|
-
var current_dir = toplevel_dir, previous_dir = toplevel_dir;
|
|
45
|
-
do {
|
|
46
|
-
try {
|
|
47
|
-
return fs.readFileSync(path.join(current_dir, 'setup.cfg'), 'utf-8');
|
|
48
|
-
} catch (e) {
|
|
49
|
-
if (e.code !== 'ENOENT') throw e;
|
|
50
|
-
}
|
|
51
|
-
previous_dir = current_dir;
|
|
52
|
-
current_dir = path.dirname(current_dir);
|
|
53
|
-
} while(current_dir != previous_dir && current_dir);
|
|
54
|
-
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function read_config(toplevel_dir) {
|
|
59
|
-
var data = find_cfg_file(toplevel_dir);
|
|
60
|
-
if (!data) return {};
|
|
61
|
-
return parse_ini_data(data);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
exports.read_config = read_config;
|
package/tools/test.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* test.js
|
|
3
|
-
* Copyright (C) 2015 Kovid Goyal <kovid at kovidgoyal.net>
|
|
4
|
-
*
|
|
5
|
-
* Distributed under terms of the BSD license.
|
|
6
|
-
*/
|
|
7
|
-
"use strict"; /*jshint node:true */
|
|
8
|
-
var path = require('path');
|
|
9
|
-
var fs = require('fs');
|
|
10
|
-
var RapydScript = require('./compiler').create_compiler();
|
|
11
|
-
var utils = require('./utils');
|
|
12
|
-
var colored = utils.safe_colored;
|
|
13
|
-
|
|
14
|
-
module.exports = function(argv, base_path, src_path, lib_path) {
|
|
15
|
-
// run all tests and exit
|
|
16
|
-
var assert = require("assert");
|
|
17
|
-
var os = require('os');
|
|
18
|
-
var failures = [];
|
|
19
|
-
var vm = require('vm');
|
|
20
|
-
var compiler_dir = path.join(base_path, 'dev');
|
|
21
|
-
if (!utils.path_exists(path.join(compiler_dir, 'compiler.js'))) compiler_dir = path.join(base_path, 'release');
|
|
22
|
-
var test_dir = path.join(base_path, 'test');
|
|
23
|
-
var baselib = fs.readFileSync(path.join(lib_path, 'baselib-plain-pretty.js'), 'utf-8');
|
|
24
|
-
var files;
|
|
25
|
-
var deep_eq = assert.deepEqual;
|
|
26
|
-
assert.deepEqual = function(a, b, message) {
|
|
27
|
-
// Compare array objects that have extra properties as simple arrays
|
|
28
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
|
29
|
-
if (a === b) return;
|
|
30
|
-
if (a.length !== b.length) throw new assert.AssertionError({actual:a, expected:b, operator:'deepEqual', stackStartFunction:assert.deepEqual});
|
|
31
|
-
for(var i=0; i < a.length; i++) assert.deepEqual(a[i], b[i], message);
|
|
32
|
-
} else if (a !== undefined && a !== null && typeof a.__eq__ === 'function') {
|
|
33
|
-
if (!a.__eq__(b)) throw new assert.AssertionError({actual:a, expected:b, operator:'deepEqual', stackStartFunction:assert.deepEqual});
|
|
34
|
-
} else return deep_eq(a, b, message);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
if (argv.files.length) {
|
|
38
|
-
files = [];
|
|
39
|
-
argv.files.forEach(function(fname) { files.push(fname + '.pyj'); });
|
|
40
|
-
} else {
|
|
41
|
-
files = fs.readdirSync(test_dir).filter(function(name){
|
|
42
|
-
return /^[^_].*\.pyj$/.test(name);
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
files.forEach(function(file){
|
|
46
|
-
var ast;
|
|
47
|
-
var filepath = path.join(test_dir, file);
|
|
48
|
-
var failed = false;
|
|
49
|
-
try {
|
|
50
|
-
ast = RapydScript.parse(fs.readFileSync(filepath, "utf-8"), {
|
|
51
|
-
filename: file,
|
|
52
|
-
toplevel: ast,
|
|
53
|
-
basedir: test_dir,
|
|
54
|
-
libdir: path.join(src_path, 'lib'),
|
|
55
|
-
});
|
|
56
|
-
} catch(e) {
|
|
57
|
-
failures.push(file);
|
|
58
|
-
failed = true;
|
|
59
|
-
console.log(colored(file, 'red') + ': ' + e + "\n\n");
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
var js_version = 5;
|
|
64
|
-
while (js_version < 7) {
|
|
65
|
-
// generate output
|
|
66
|
-
var output = new RapydScript.OutputStream({
|
|
67
|
-
baselib_plain: baselib,
|
|
68
|
-
beautify: true,
|
|
69
|
-
js_version: js_version,
|
|
70
|
-
keep_docstrings: true,
|
|
71
|
-
});
|
|
72
|
-
ast.print(output);
|
|
73
|
-
|
|
74
|
-
// test that output performs correct JS operations
|
|
75
|
-
var jsfile = path.join(os.tmpdir(), file + '-es' + js_version + '.js');
|
|
76
|
-
var code = output.toString();
|
|
77
|
-
try {
|
|
78
|
-
vm.runInNewContext(code, {
|
|
79
|
-
'assrt':assert,
|
|
80
|
-
'__name__': jsfile,
|
|
81
|
-
'require':require,
|
|
82
|
-
'fs':fs,
|
|
83
|
-
'RapydScript':RapydScript,
|
|
84
|
-
'console':console,
|
|
85
|
-
'compiler_dir': compiler_dir,
|
|
86
|
-
'test_path':test_dir,
|
|
87
|
-
'Buffer': Buffer,
|
|
88
|
-
}, {'filename':jsfile});
|
|
89
|
-
} catch (e) {
|
|
90
|
-
failures.push(file);
|
|
91
|
-
failed = true;
|
|
92
|
-
fs.writeFileSync(jsfile, code);
|
|
93
|
-
console.error('Failed running: ' + colored(jsfile, 'red'));
|
|
94
|
-
if (e.stack)
|
|
95
|
-
console.error(colored(file, 'red') + ":\n" + e.stack + "\n\n");
|
|
96
|
-
else
|
|
97
|
-
console.error(colored(file, 'red') + ": " + e + "\n\n");
|
|
98
|
-
js_version = 1000;
|
|
99
|
-
}
|
|
100
|
-
js_version++;
|
|
101
|
-
}
|
|
102
|
-
if (!failed) console.log(colored(file, 'green') + ": test completed successfully\n");
|
|
103
|
-
else { console.log(colored(file, 'red') + ":\ttest failed\n"); }
|
|
104
|
-
});
|
|
105
|
-
if (failures.length) {
|
|
106
|
-
console.log(colored('There were ' + failures.length + ' test failure(s):', 'red'));
|
|
107
|
-
console.log.apply(console, failures);
|
|
108
|
-
} else console.log(colored('All tests passed!', 'green'));
|
|
109
|
-
process.exit((failures.length) ? 1 : 0);
|
|
110
|
-
};
|