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
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
==================
|
|
2
|
+
index access
|
|
3
|
+
==================
|
|
4
|
+
|
|
5
|
+
a = arr[0]
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
(module
|
|
10
|
+
(assignment
|
|
11
|
+
left: (pattern
|
|
12
|
+
(identifier))
|
|
13
|
+
right: (subscript
|
|
14
|
+
object: (identifier)
|
|
15
|
+
subscript: (number))))
|
|
16
|
+
|
|
17
|
+
==================
|
|
18
|
+
attribute access
|
|
19
|
+
==================
|
|
20
|
+
|
|
21
|
+
a = obj.prop.nested
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
(module
|
|
26
|
+
(assignment
|
|
27
|
+
left: (pattern
|
|
28
|
+
(identifier))
|
|
29
|
+
right: (attribute
|
|
30
|
+
object: (attribute
|
|
31
|
+
object: (identifier)
|
|
32
|
+
attribute: (identifier))
|
|
33
|
+
attribute: (identifier))))
|
|
34
|
+
|
|
35
|
+
==================
|
|
36
|
+
full slice
|
|
37
|
+
==================
|
|
38
|
+
|
|
39
|
+
a = arr[:]
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
(module
|
|
44
|
+
(assignment
|
|
45
|
+
left: (pattern
|
|
46
|
+
(identifier))
|
|
47
|
+
right: (subscript
|
|
48
|
+
object: (identifier)
|
|
49
|
+
subscript: (slice))))
|
|
50
|
+
|
|
51
|
+
==================
|
|
52
|
+
slice with start stop
|
|
53
|
+
==================
|
|
54
|
+
|
|
55
|
+
a = arr[1:2]
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
(module
|
|
60
|
+
(assignment
|
|
61
|
+
left: (pattern
|
|
62
|
+
(identifier))
|
|
63
|
+
right: (subscript
|
|
64
|
+
object: (identifier)
|
|
65
|
+
subscript: (slice
|
|
66
|
+
(number)
|
|
67
|
+
(number)))))
|
|
68
|
+
|
|
69
|
+
==================
|
|
70
|
+
slice with step
|
|
71
|
+
==================
|
|
72
|
+
|
|
73
|
+
a = arr[1:2:3]
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
(module
|
|
78
|
+
(assignment
|
|
79
|
+
left: (pattern
|
|
80
|
+
(identifier))
|
|
81
|
+
right: (subscript
|
|
82
|
+
object: (identifier)
|
|
83
|
+
subscript: (slice
|
|
84
|
+
(number)
|
|
85
|
+
(number)
|
|
86
|
+
(number)))))
|
|
87
|
+
|
|
88
|
+
==================
|
|
89
|
+
slice start only
|
|
90
|
+
==================
|
|
91
|
+
|
|
92
|
+
a = arr[1:]
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
(module
|
|
97
|
+
(assignment
|
|
98
|
+
left: (pattern
|
|
99
|
+
(identifier))
|
|
100
|
+
right: (subscript
|
|
101
|
+
object: (identifier)
|
|
102
|
+
subscript: (slice
|
|
103
|
+
(number)))))
|
|
104
|
+
|
|
105
|
+
==================
|
|
106
|
+
negative index
|
|
107
|
+
==================
|
|
108
|
+
|
|
109
|
+
a = arr[-1]
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
(module
|
|
114
|
+
(assignment
|
|
115
|
+
left: (pattern
|
|
116
|
+
(identifier))
|
|
117
|
+
right: (subscript
|
|
118
|
+
object: (identifier)
|
|
119
|
+
subscript: (unary_operator
|
|
120
|
+
argument: (number)))))
|
|
121
|
+
|
|
122
|
+
==================
|
|
123
|
+
method chaining
|
|
124
|
+
==================
|
|
125
|
+
|
|
126
|
+
result = obj.css("x").show().hide()
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
(module
|
|
131
|
+
(assignment
|
|
132
|
+
left: (pattern
|
|
133
|
+
(identifier))
|
|
134
|
+
right: (call
|
|
135
|
+
function: (attribute
|
|
136
|
+
object: (call
|
|
137
|
+
function: (attribute
|
|
138
|
+
object: (call
|
|
139
|
+
function: (attribute
|
|
140
|
+
object: (identifier)
|
|
141
|
+
attribute: (identifier))
|
|
142
|
+
arguments: (argument_list
|
|
143
|
+
(string)))
|
|
144
|
+
attribute: (identifier))
|
|
145
|
+
arguments: (argument_list))
|
|
146
|
+
attribute: (identifier))
|
|
147
|
+
arguments: (argument_list))))
|
|
148
|
+
|
|
149
|
+
==================
|
|
150
|
+
call with keyword args
|
|
151
|
+
==================
|
|
152
|
+
|
|
153
|
+
E.div(id="container", class_="xxx")
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
(module
|
|
158
|
+
(call
|
|
159
|
+
function: (attribute
|
|
160
|
+
object: (identifier)
|
|
161
|
+
attribute: (identifier))
|
|
162
|
+
arguments: (argument_list
|
|
163
|
+
(keyword_argument
|
|
164
|
+
name: (identifier)
|
|
165
|
+
value: (string))
|
|
166
|
+
(keyword_argument
|
|
167
|
+
name: (identifier)
|
|
168
|
+
value: (string)))))
|
|
169
|
+
|
|
170
|
+
==================
|
|
171
|
+
call with star args
|
|
172
|
+
==================
|
|
173
|
+
|
|
174
|
+
f(a, *args, **kwargs)
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
(module
|
|
179
|
+
(call
|
|
180
|
+
function: (identifier)
|
|
181
|
+
arguments: (argument_list
|
|
182
|
+
(identifier)
|
|
183
|
+
(list_splat_argument
|
|
184
|
+
(identifier))
|
|
185
|
+
(dictionary_splat_argument
|
|
186
|
+
(identifier)))))
|
|
187
|
+
|
|
188
|
+
==================
|
|
189
|
+
generator as sole argument
|
|
190
|
+
==================
|
|
191
|
+
|
|
192
|
+
total = sum(x for x in items)
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
(module
|
|
197
|
+
(assignment
|
|
198
|
+
left: (pattern
|
|
199
|
+
(identifier))
|
|
200
|
+
right: (call
|
|
201
|
+
function: (identifier)
|
|
202
|
+
arguments: (argument_list
|
|
203
|
+
body: (identifier)
|
|
204
|
+
(for_in_clause
|
|
205
|
+
left: (pattern
|
|
206
|
+
(identifier))
|
|
207
|
+
right: (identifier))))))
|
|
208
|
+
|
|
209
|
+
==================
|
|
210
|
+
new expression
|
|
211
|
+
==================
|
|
212
|
+
|
|
213
|
+
x = new Foo(1, 2)
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
(module
|
|
218
|
+
(assignment
|
|
219
|
+
left: (pattern
|
|
220
|
+
(identifier))
|
|
221
|
+
right: (new_expression
|
|
222
|
+
constructor: (call
|
|
223
|
+
function: (identifier)
|
|
224
|
+
arguments: (argument_list
|
|
225
|
+
(number)
|
|
226
|
+
(number))))))
|
|
227
|
+
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/config.schema.json",
|
|
3
|
+
"grammars": [
|
|
4
|
+
{
|
|
5
|
+
"name": "rapydscript",
|
|
6
|
+
"camelcase": "RapydScript",
|
|
7
|
+
"scope": "source.rapydscript",
|
|
8
|
+
"path": ".",
|
|
9
|
+
"file-types": [
|
|
10
|
+
"pyj"
|
|
11
|
+
],
|
|
12
|
+
"highlights": [
|
|
13
|
+
"queries/highlights.scm"
|
|
14
|
+
],
|
|
15
|
+
"injection-regex": "^(rapydscript|pyj)$"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"metadata": {
|
|
19
|
+
"version": "0.1.0",
|
|
20
|
+
"license": "BSD-2-Clause",
|
|
21
|
+
"description": "RapydScript grammar for tree-sitter",
|
|
22
|
+
"authors": [
|
|
23
|
+
{
|
|
24
|
+
"name": "rapydscript-ng contributors"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
"bindings": {
|
|
29
|
+
"c": false,
|
|
30
|
+
"go": false,
|
|
31
|
+
"node": true,
|
|
32
|
+
"python": false,
|
|
33
|
+
"rust": false,
|
|
34
|
+
"swift": false
|
|
35
|
+
}
|
|
36
|
+
}
|
package/web-repl/env.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* vim:fileencoding=utf-8
|
|
2
|
-
*
|
|
2
|
+
*
|
|
3
3
|
* Copyright (C) 2016 Kovid Goyal <kovid at kovidgoyal.net>
|
|
4
4
|
*
|
|
5
5
|
* Distributed under terms of the BSD license
|
|
@@ -9,6 +9,39 @@ var namespace = {}, jsSHA = {};
|
|
|
9
9
|
|
|
10
10
|
var write_cache = {};
|
|
11
11
|
|
|
12
|
+
async function readfile(name, encoding) {
|
|
13
|
+
if (name.startsWith('__vfs__/')) {
|
|
14
|
+
if (namespace.virtual_file_system && namespace.virtual_file_system.read_file) {
|
|
15
|
+
return namespace.virtual_file_system.read_file(name, encoding);
|
|
16
|
+
}
|
|
17
|
+
var err = new Error('ENOENT: no such file or directory: ' + name);
|
|
18
|
+
err.code = 'ENOENT';
|
|
19
|
+
throw err;
|
|
20
|
+
}
|
|
21
|
+
var data = write_cache[name];
|
|
22
|
+
if (data !== undefined) return data;
|
|
23
|
+
data = namespace.file_data[name];
|
|
24
|
+
if (data !== undefined) return data;
|
|
25
|
+
var err = new Error('ENOENT: no such file or directory: ' + name);
|
|
26
|
+
err.code = 'ENOENT';
|
|
27
|
+
throw err;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function writefile(name, data) {
|
|
31
|
+
if (name.startsWith('__vfs__/') && namespace.virtual_file_system && namespace.virtual_file_system.write_file) {
|
|
32
|
+
return namespace.virtual_file_system.write_file(name, data);
|
|
33
|
+
}
|
|
34
|
+
write_cache[name] = data;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function stat_file(name) {
|
|
38
|
+
if (name.startsWith('__vfs__/') && namespace.virtual_file_system && namespace.virtual_file_system.stat_file) {
|
|
39
|
+
return namespace.virtual_file_system.stat_file(name);
|
|
40
|
+
}
|
|
41
|
+
const content = await readfile(name, 'utf-8');
|
|
42
|
+
return { mtimeMs: null, content: content };
|
|
43
|
+
}
|
|
44
|
+
|
|
12
45
|
var builtin_modules = {
|
|
13
46
|
'crypto' : {
|
|
14
47
|
'createHash': function create_hash() {
|
|
@@ -45,28 +78,7 @@ var builtin_modules = {
|
|
|
45
78
|
},
|
|
46
79
|
'inspect': function inspect(x) { return x.toString(); },
|
|
47
80
|
|
|
48
|
-
'fs': {
|
|
49
|
-
'readFileSync': function readfile(name) {
|
|
50
|
-
if (namespace.virtual_file_system && namespace.virtual_file_system.read_file_sync) {
|
|
51
|
-
data = namespace.virtual_file_system.read_file_sync(name);
|
|
52
|
-
if (data !== null) return data;
|
|
53
|
-
}
|
|
54
|
-
var data = namespace.file_data[name];
|
|
55
|
-
if (data) return data;
|
|
56
|
-
data = write_cache[name];
|
|
57
|
-
if (data) return data;
|
|
58
|
-
var err = Error();
|
|
59
|
-
err.code = 'ENOENT';
|
|
60
|
-
throw err;
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
'writeFileSync': function writefile(name, data) {
|
|
64
|
-
if (namespace.virtual_file_system && namespace.virtual_file_system.write_file_sync) {
|
|
65
|
-
namespace.virtual_file_system.write_file_sync(name, data);
|
|
66
|
-
} else write_cache[name] = data;
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
},
|
|
81
|
+
'fs': {},
|
|
70
82
|
};
|
|
71
83
|
|
|
72
84
|
function require(name) {
|
package/web-repl/main.js
CHANGED
|
@@ -72,11 +72,11 @@
|
|
|
72
72
|
output.lastChild.scrollIntoView();
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
function read_eval(code) {
|
|
75
|
+
async function read_eval(code) {
|
|
76
76
|
var js, obj, text;
|
|
77
77
|
hide_completions();
|
|
78
78
|
try {
|
|
79
|
-
js = compile(code);
|
|
79
|
+
js = await compile(code);
|
|
80
80
|
} catch(e) {
|
|
81
81
|
var text, line = null, col = null;
|
|
82
82
|
if (e.message && e.line) {
|
|
@@ -98,11 +98,11 @@
|
|
|
98
98
|
return false;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
function run_code() {
|
|
101
|
+
async function run_code() {
|
|
102
102
|
var input = document.getElementById('input');
|
|
103
103
|
var code = input.value;
|
|
104
104
|
input.value = '';
|
|
105
|
-
if (code) read_eval(code);
|
|
105
|
+
if (code) await read_eval(code);
|
|
106
106
|
document.getElementById('input').focus();
|
|
107
107
|
}
|
|
108
108
|
|
|
@@ -183,14 +183,14 @@
|
|
|
183
183
|
return a1.substr(0, i);
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
function on_input(ev) {
|
|
186
|
+
async function on_input(ev) {
|
|
187
187
|
var input, source;
|
|
188
188
|
var code = ev.keyCode || ev.which;
|
|
189
189
|
if (code === 13 && !ev.ctrlKey && !ev.shiftKey && !ev.altKey && !ev.metaKey) { // Enter
|
|
190
190
|
input = document.getElementById('input');
|
|
191
191
|
source = input.value;
|
|
192
192
|
ev.preventDefault();
|
|
193
|
-
if (web_repl.is_input_complete(source)) {
|
|
193
|
+
if (await web_repl.is_input_complete(source)) {
|
|
194
194
|
setTimeout(run_code, 0);
|
|
195
195
|
return;
|
|
196
196
|
}
|
|
@@ -220,8 +220,8 @@
|
|
|
220
220
|
|
|
221
221
|
}
|
|
222
222
|
|
|
223
|
-
function on_load() {
|
|
224
|
-
web_repl = RapydScript.web_repl();
|
|
223
|
+
async function on_load() {
|
|
224
|
+
web_repl = await RapydScript.web_repl();
|
|
225
225
|
web_repl.replace_print(println);
|
|
226
226
|
web_repl.init_completions(RapydScript.completer);
|
|
227
227
|
document.getElementById('loading').style.display = 'none';
|
package/bin/export
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// vim:ft=javascript:ts=4:et
|
|
3
|
-
|
|
4
|
-
"use strict";
|
|
5
|
-
|
|
6
|
-
var fs = require('fs');
|
|
7
|
-
var path = require('path');
|
|
8
|
-
var crypto = require('crypto');
|
|
9
|
-
|
|
10
|
-
var base = path.join(path.dirname(__dirname));
|
|
11
|
-
var meta = JSON.parse(fs.readFileSync(path.join(base, 'package.json'), {'encoding':'utf-8'}));
|
|
12
|
-
var compiler_dir = path.join(base, 'dev');
|
|
13
|
-
if (!path_exists(path.join(compiler_dir, 'compiler.js'))) compiler_dir = path.join(base, 'release');
|
|
14
|
-
|
|
15
|
-
var manifest = {}, total = 0;
|
|
16
|
-
['compiler.js', 'baselib-plain-pretty.js', 'baselib-plain-ugly.js'].forEach(function(x) {
|
|
17
|
-
manifest[x] = fs.readFileSync(path.join(compiler_dir, x), {'encoding':'utf-8'});
|
|
18
|
-
total += manifest[x].length;
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
['web_repl.js', 'repl.js', 'completer.js', 'utils.js', 'gettext.js', 'msgfmt.js'].forEach(function(x) {
|
|
22
|
-
x = 'tools/' + x;
|
|
23
|
-
manifest[x] = fs.readFileSync(path.join(base, x), {'encoding':'utf-8'});
|
|
24
|
-
total += manifest[x].length;
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
var dedup = {};
|
|
29
|
-
|
|
30
|
-
function path_exists(path) {
|
|
31
|
-
try {
|
|
32
|
-
fs.statSync(path);
|
|
33
|
-
return true;
|
|
34
|
-
} catch(e) {
|
|
35
|
-
if (e.code != 'ENOENT') throw e;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function sha1sum(data) {
|
|
40
|
-
var h = crypto.createHash('sha1');
|
|
41
|
-
h.update(data);
|
|
42
|
-
return h.digest('hex');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function process_dir(name) {
|
|
46
|
-
var dpath = path.join(base, name);
|
|
47
|
-
var items = fs.readdirSync(dpath);
|
|
48
|
-
items.forEach(function (x) {
|
|
49
|
-
var iname = name + '/' + x;
|
|
50
|
-
var ipath = path.join(dpath, x);
|
|
51
|
-
var s = fs.statSync(ipath);
|
|
52
|
-
if (s.isDirectory()) return process_dir(iname);
|
|
53
|
-
var raw = fs.readFileSync(ipath, {'encoding':'utf-8'});
|
|
54
|
-
var sig = sha1sum(raw);
|
|
55
|
-
if (dedup.hasOwnProperty(sig)) {
|
|
56
|
-
manifest[iname] = [dedup[sig]];
|
|
57
|
-
} else {
|
|
58
|
-
manifest[iname] = raw;
|
|
59
|
-
dedup[sig] = iname;
|
|
60
|
-
total += s.size;
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
Object.keys(meta.dependencies).forEach(function (x) {
|
|
66
|
-
process_dir('node_modules/' + x);
|
|
67
|
-
});
|
|
68
|
-
console.log('// vim:fileencoding=utf-8');
|
|
69
|
-
console.log('(function() {');
|
|
70
|
-
console.log('var rs_version = ' + JSON.stringify(meta.version) + ';');
|
|
71
|
-
console.log('var data = ' + JSON.stringify(manifest) + ';');
|
|
72
|
-
console.log();
|
|
73
|
-
console.log(fs.readFileSync(path.join(base, 'tools', 'export.js'), {'encoding':'utf-8'}));
|
|
74
|
-
console.log('})()');
|
|
75
|
-
console.error('RapydScript compiler (uncompressed) size: ' + (total/(1024 * 1024)).toFixed(1) + ' MB');
|
package/bin/web-repl-export
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// vim:ft=javascript:ts=4:et
|
|
3
|
-
|
|
4
|
-
"use strict";
|
|
5
|
-
|
|
6
|
-
var fs = require('fs');
|
|
7
|
-
var path = require('path');
|
|
8
|
-
|
|
9
|
-
var base = path.normalize(path.resolve(path.join(path.dirname(__dirname))));
|
|
10
|
-
var meta = JSON.parse(fs.readFileSync(path.join(base, 'package.json'), {'encoding':'utf-8'}));
|
|
11
|
-
var commit_sha = fs.readFileSync(path.join(base, '.git', 'refs', 'heads', 'master'), {'encoding':'utf-8'}).trim();
|
|
12
|
-
var compiler_dir = path.join(base, 'dev');
|
|
13
|
-
if (!path_exists(path.join(compiler_dir, 'compiler.js'))) compiler_dir = path.join(base, 'release');
|
|
14
|
-
|
|
15
|
-
var manifest = {}, total = 0;
|
|
16
|
-
['compiler.js', 'baselib-plain-pretty.js'].forEach(function(x) {
|
|
17
|
-
manifest[x] = fs.readFileSync(path.join(compiler_dir, x), {'encoding':'utf-8'});
|
|
18
|
-
total += manifest[x].length;
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
['web_repl.js', 'embedded_compiler.js', 'utils.js', 'completer.js', 'msgfmt.js', 'gettext.js'].forEach(function(x) {
|
|
22
|
-
x = 'tools/' + x;
|
|
23
|
-
manifest[x] = fs.readFileSync(path.join(base, x), {'encoding':'utf-8'});
|
|
24
|
-
total += manifest[x].length;
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
var stdlib = path.join(base, 'src', 'lib');
|
|
28
|
-
|
|
29
|
-
function path_exists(path) {
|
|
30
|
-
try {
|
|
31
|
-
fs.statSync(path);
|
|
32
|
-
return true;
|
|
33
|
-
} catch(e) {
|
|
34
|
-
if (e.code != 'ENOENT') throw e;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function process_dir(relpath) {
|
|
39
|
-
var fullpath = (relpath) ? path.join(stdlib, relpath) : stdlib;
|
|
40
|
-
fs.readdirSync(fullpath).forEach(function (x) {
|
|
41
|
-
var q = path.join(fullpath, x);
|
|
42
|
-
var s = fs.statSync(q);
|
|
43
|
-
if (s.isDirectory()) return process_dir(relpath + '/' + x);
|
|
44
|
-
if (!x.endsWith('.pyj')) return;
|
|
45
|
-
var iname = path.normalize('__stdlib__' + '/' + relpath + '/' + x);
|
|
46
|
-
var raw = fs.readFileSync(q, {'encoding':'utf-8'});
|
|
47
|
-
manifest[iname] = raw;
|
|
48
|
-
total += s.size;
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
process_dir('');
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
var rs = '// vim:fileencoding=utf-8\n';
|
|
55
|
-
rs += '(function(external_namespace) {\n';
|
|
56
|
-
rs += '"use strict;"\n';
|
|
57
|
-
rs += 'var rs_version = ' + JSON.stringify(meta.version) + ';\n';
|
|
58
|
-
rs += 'var rs_commit_sha = ' + JSON.stringify(commit_sha) + ';\n';
|
|
59
|
-
rs += '\n// Embedded modules {{{\n';
|
|
60
|
-
rs += 'var data = ' + JSON.stringify(manifest) + ';\n\n';
|
|
61
|
-
rs += '// End embedded modules }}}\n\n';
|
|
62
|
-
rs += fs.readFileSync(path.join(base, 'web-repl', 'env.js'));
|
|
63
|
-
rs += '\n// Embedded sha1 implementation {{{\n';
|
|
64
|
-
rs += '(function() {\n';
|
|
65
|
-
rs += fs.readFileSync(path.join(base, 'web-repl', 'sha1.js'));
|
|
66
|
-
rs += '}).call(jsSHA);\n';
|
|
67
|
-
rs += '// End embedded sha1 implementation }}}\n\n';
|
|
68
|
-
rs += 'var exports = namespace;\n';
|
|
69
|
-
rs += fs.readFileSync(path.join(base, 'tools', 'export.js'), {'encoding':'utf-8'});
|
|
70
|
-
rs += 'external_namespace.RapydScript = namespace;\n';
|
|
71
|
-
rs += '})(this);\n';
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
var base_dir = process.argv.slice(-1)[0];
|
|
75
|
-
if (process.argv.length !== 3) {
|
|
76
|
-
console.error('Usage: web-repl-export /path/to/export/directory');
|
|
77
|
-
process.exit(1);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
base_dir = path.normalize(path.resolve(base_dir));
|
|
81
|
-
|
|
82
|
-
try {
|
|
83
|
-
fs.mkdirSync(base_dir);
|
|
84
|
-
} catch(e) {
|
|
85
|
-
if (e.code !== 'EEXIST') throw e;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
try {
|
|
89
|
-
process.chdir(base_dir);
|
|
90
|
-
} catch(e) {
|
|
91
|
-
if (e.code === 'ENOTDIR') { console.error(base_dir + ' is not a directory'); process.exit(1); }
|
|
92
|
-
throw e;
|
|
93
|
-
}
|
|
94
|
-
fs.writeFileSync('rapydscript.js', rs, {'encoding':'utf-8'});
|
|
95
|
-
var web_repl = path.join(base, 'web-repl');
|
|
96
|
-
fs.readdirSync(web_repl).forEach(function(x) {
|
|
97
|
-
if (['sha1.js', 'env.js'].indexOf(x) !== -1) return;
|
|
98
|
-
var data = fs.readFileSync(path.join(web_repl, x), {'encoding':'utf-8'});
|
|
99
|
-
fs.writeFileSync(x, data, {'encoding':'utf-8'});
|
|
100
|
-
});
|
|
101
|
-
console.log('RapydScript compiler (uncompressed) size: ' + (total/(1024)).toFixed(1) + ' KB');
|
|
102
|
-
console.log('web-repl exported to: ' + base_dir);
|