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
package/tools/cli.js
ADDED
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* cli.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
|
+
|
|
9
|
+
var path = require('path');
|
|
10
|
+
var utils = require('./utils');
|
|
11
|
+
var colored = utils.safe_colored;
|
|
12
|
+
var has_prop = Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty);
|
|
13
|
+
|
|
14
|
+
function OptionGroup(name) {
|
|
15
|
+
this.name = name;
|
|
16
|
+
this.description = undefined;
|
|
17
|
+
this.extra = undefined;
|
|
18
|
+
this.options = {
|
|
19
|
+
'string': {},
|
|
20
|
+
'boolean': {},
|
|
21
|
+
'alias': {},
|
|
22
|
+
'default': {},
|
|
23
|
+
'choices': {},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
this.help = {};
|
|
27
|
+
this.seen = {};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var groups = {}, group;
|
|
31
|
+
|
|
32
|
+
function create_group(name, usage, description, extra) {
|
|
33
|
+
group = new OptionGroup(name);
|
|
34
|
+
var match = utils.comment_contents.exec(description.toString());
|
|
35
|
+
if (!match) {
|
|
36
|
+
throw new TypeError('Multiline comment missing for: ' + name);
|
|
37
|
+
}
|
|
38
|
+
group.description = match[1];
|
|
39
|
+
group.usage = name + ' [options] ' + usage;
|
|
40
|
+
groups[name] = group;
|
|
41
|
+
|
|
42
|
+
if (extra) {
|
|
43
|
+
match = utils.comment_contents.exec(extra.toString());
|
|
44
|
+
if (match) group.extra = match[1];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
opt('help', 'h', 'bool', false, function(){/*
|
|
48
|
+
show this help message and exit
|
|
49
|
+
*/});
|
|
50
|
+
|
|
51
|
+
opt('version', 'V', 'bool', false, function(){/*
|
|
52
|
+
show the version and exit
|
|
53
|
+
*/});
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
var COL1 = 'yellow', COL2 = 'green';
|
|
59
|
+
|
|
60
|
+
function print_usage(group) { // {{{
|
|
61
|
+
var COL_WIDTH = 79;
|
|
62
|
+
var OPT_WIDTH = 23;
|
|
63
|
+
|
|
64
|
+
var usage = (group) ? group.usage : "[sub-command] ...";
|
|
65
|
+
console.log(colored('Usage:', COL1), colored(path.basename(process.argv[1]), COL2), usage, '\n');
|
|
66
|
+
if (!group) {
|
|
67
|
+
// Overall usage
|
|
68
|
+
help = ('RapydScript can perform many actions, depending on which' +
|
|
69
|
+
'\nsub-command is invoked. With no arguments, it will start a REPL,' +
|
|
70
|
+
'\nunless STDIN is a pipe, in which case it will compile whatever' +
|
|
71
|
+
'\nyou pass on STDIN and write the output to STDOUT. See the full' +
|
|
72
|
+
'\nlist of sub-commands below.');
|
|
73
|
+
console.log(help, '\n');
|
|
74
|
+
console.log(colored('Sub-commands:', COL1));
|
|
75
|
+
Object.keys(groups).forEach(function (name) {
|
|
76
|
+
console.log();
|
|
77
|
+
var dt = utils.wrap(groups[name].description.split('\n'), COL_WIDTH - OPT_WIDTH);
|
|
78
|
+
console.log(colored((name + utils.repeat(' ', OPT_WIDTH)).slice(0, OPT_WIDTH), COL2), dt[0]);
|
|
79
|
+
dt.slice(1).forEach(function (line) {
|
|
80
|
+
console.log(utils.repeat(' ', OPT_WIDTH), line);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Group specific usage
|
|
87
|
+
|
|
88
|
+
console.log(group.description);
|
|
89
|
+
if (group.extra) console.log('\n' + group.extra);
|
|
90
|
+
console.log(colored('\nOptions:', COL1));
|
|
91
|
+
var options = group.options;
|
|
92
|
+
var help = group.help;
|
|
93
|
+
|
|
94
|
+
Object.getOwnPropertyNames(options.alias).forEach(function (name) {
|
|
95
|
+
var optstr = ' --' + name.replace(/_/g, '-');
|
|
96
|
+
options.alias[name].forEach(function (alias) {
|
|
97
|
+
optstr += ', ' + ((alias.length > 1) ? '--' : '-') + alias.replace(/_/g, '-');
|
|
98
|
+
});
|
|
99
|
+
var ht = utils.wrap(help[name].split('\n'), COL_WIDTH - OPT_WIDTH);
|
|
100
|
+
|
|
101
|
+
if (optstr.length > OPT_WIDTH) console.log(colored(optstr, COL2));
|
|
102
|
+
else {
|
|
103
|
+
console.log(colored((optstr + utils.repeat(' ', OPT_WIDTH)).slice(0, OPT_WIDTH), COL2), ht[0]);
|
|
104
|
+
ht = ht.splice(1);
|
|
105
|
+
}
|
|
106
|
+
ht.forEach(function (line) {
|
|
107
|
+
console.log(utils.repeat(' ', OPT_WIDTH), line);
|
|
108
|
+
});
|
|
109
|
+
console.log();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
} // }}}
|
|
113
|
+
|
|
114
|
+
// Process options {{{
|
|
115
|
+
|
|
116
|
+
function opt(name, aliases, type, default_val, help_text, choices) {
|
|
117
|
+
var match = utils.comment_contents.exec(help_text.toString());
|
|
118
|
+
var options = group.options;
|
|
119
|
+
var seen = group.seen;
|
|
120
|
+
var help = group.help;
|
|
121
|
+
|
|
122
|
+
if (!match) {
|
|
123
|
+
throw new TypeError('Multiline comment missing for: ' + name);
|
|
124
|
+
}
|
|
125
|
+
help_text = match[1];
|
|
126
|
+
|
|
127
|
+
if (!type || type == 'bool') options.boolean[name] = true;
|
|
128
|
+
else if (type == 'string') {
|
|
129
|
+
options.string[name] = true;
|
|
130
|
+
if (choices) options.choices[name] = choices;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (default_val !== undefined) options.default[name] = default_val;
|
|
134
|
+
|
|
135
|
+
if (aliases && aliases.length) {
|
|
136
|
+
aliases.split(',').forEach(function(alias) {
|
|
137
|
+
if (has_prop(seen, alias)) throw "The option name:" + alias + " has already been used.";
|
|
138
|
+
seen[alias] = true;
|
|
139
|
+
});
|
|
140
|
+
options.alias[name] = aliases.split(',');
|
|
141
|
+
} else options.alias[name] = [];
|
|
142
|
+
|
|
143
|
+
if (has_prop(seen, name)) throw "The option name:" + name + " has already been used.";
|
|
144
|
+
seen[name] = true;
|
|
145
|
+
|
|
146
|
+
help[name] = help_text;
|
|
147
|
+
}
|
|
148
|
+
// }}}
|
|
149
|
+
|
|
150
|
+
function parse_args() { // {{{
|
|
151
|
+
var ans = {'files':[]};
|
|
152
|
+
var name_map = {};
|
|
153
|
+
var state, options, group;
|
|
154
|
+
|
|
155
|
+
function plain_arg(arg) {
|
|
156
|
+
if (state !== undefined) ans[state] = arg;
|
|
157
|
+
else ans.files.push(arg);
|
|
158
|
+
state = undefined;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function handle_opt(arg) {
|
|
162
|
+
var oarg = arg;
|
|
163
|
+
var is_long_opt = (arg[0] === '-') ? true : false;
|
|
164
|
+
if (is_long_opt) arg = arg.substr(1);
|
|
165
|
+
if (state !== undefined) ans[state] = '';
|
|
166
|
+
state = undefined;
|
|
167
|
+
if (!is_long_opt && arg.length > 1) {
|
|
168
|
+
arg.split('').forEach(handle_opt);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
var val = arg.indexOf('=');
|
|
172
|
+
if (val > -1) {
|
|
173
|
+
var t = arg.substr(val + 1);
|
|
174
|
+
arg = arg.substr(0, val);
|
|
175
|
+
val = t;
|
|
176
|
+
} else val = undefined;
|
|
177
|
+
|
|
178
|
+
var name = name_map[arg.replace(/-/g, '_')];
|
|
179
|
+
if (!name) {
|
|
180
|
+
print_usage(group);
|
|
181
|
+
console.error('\nThe option:', colored('-' + oarg, 'red'), 'is not recognized');
|
|
182
|
+
process.exit(1);
|
|
183
|
+
}
|
|
184
|
+
if (has_prop(options.boolean, name)) {
|
|
185
|
+
if (!val) val = 'true';
|
|
186
|
+
if (val === 'true' || val === '1') val = true;
|
|
187
|
+
else if (val === 'false' || val === '0') val = false;
|
|
188
|
+
else { console.error('The value:', colored(val, 'red'), 'is invalid for the boolean option:', colored(name, 'red')); process.exit(1); }
|
|
189
|
+
ans[name] = val;
|
|
190
|
+
} else {
|
|
191
|
+
if (val !== undefined) ans[name] = val;
|
|
192
|
+
else state = name;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
var all_args = process.argv.slice(2);
|
|
197
|
+
ans.auto_mode = false;
|
|
198
|
+
if (has_prop(groups, all_args[0])) {
|
|
199
|
+
ans.mode = all_args[0];
|
|
200
|
+
all_args = all_args.slice(1);
|
|
201
|
+
} else {
|
|
202
|
+
// this check is not robust, but, it will only fail if the repl mode takes any non-boolean options
|
|
203
|
+
var has_files = all_args.filter(function (a) { return a[0] !== '-'; }).length > 0;
|
|
204
|
+
ans.mode = (!has_files && process.stdin.isTTY) ? 'repl' : 'compile';
|
|
205
|
+
ans.auto_mode = true;
|
|
206
|
+
}
|
|
207
|
+
options = groups[ans.mode].options;
|
|
208
|
+
|
|
209
|
+
Object.getOwnPropertyNames(options.default).forEach(function(name) { ans[name] = options['default'][name]; });
|
|
210
|
+
|
|
211
|
+
Object.getOwnPropertyNames(options.alias).forEach(function(name) {
|
|
212
|
+
name_map[name] = name;
|
|
213
|
+
options.alias[name].forEach(function (alias) { name_map[alias] = name; });
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
var options_ended = false;
|
|
217
|
+
|
|
218
|
+
all_args.forEach(function(arg) {
|
|
219
|
+
if (options_ended) plain_arg(arg);
|
|
220
|
+
else if (arg === '--') options_ended = true;
|
|
221
|
+
else if (arg === '-') plain_arg(arg);
|
|
222
|
+
|
|
223
|
+
else if (arg[0] === '-') handle_opt(arg.substr(1));
|
|
224
|
+
|
|
225
|
+
else plain_arg(arg);
|
|
226
|
+
});
|
|
227
|
+
if (state !== undefined) plain_arg('');
|
|
228
|
+
Object.keys(options.choices).forEach(function(name) {
|
|
229
|
+
var allowed = options.choices[name];
|
|
230
|
+
if (allowed.indexOf(ans[name]) < 0) {
|
|
231
|
+
print_usage(groups[ans.mode]);
|
|
232
|
+
console.error('The value "' + colored(ans[name], 'red') + '" is not allowed for ' + colored(name, 'red') + '. Allowed values: ' + options.choices[name].join(', '));
|
|
233
|
+
process.exit(1);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
return ans;
|
|
237
|
+
} // }}}
|
|
238
|
+
|
|
239
|
+
create_group('compile', "[input1.pyj input2.pyj ...]", function(){/*
|
|
240
|
+
Compile RapydScript source code into JavaScript
|
|
241
|
+
output. You can also pipe the source code into
|
|
242
|
+
stdin.
|
|
243
|
+
*/});
|
|
244
|
+
|
|
245
|
+
opt("output", 'o', 'string', '', function(){/*
|
|
246
|
+
Output file (default STDOUT)
|
|
247
|
+
*/});
|
|
248
|
+
|
|
249
|
+
opt("bare", 'b', 'bool', false, function(){/*
|
|
250
|
+
Remove the module wrapper that prevents RapydScript
|
|
251
|
+
scope from bleeding into other JavaScript logic
|
|
252
|
+
*/});
|
|
253
|
+
|
|
254
|
+
opt("keep_docstrings", 'd', 'bool', false, function(){/*
|
|
255
|
+
Keep the docstrings in the generated JavaScript as __doc__
|
|
256
|
+
attributes on functions, classes and modules. Normally,
|
|
257
|
+
the docstring are deleted to reduce download size.
|
|
258
|
+
*/});
|
|
259
|
+
|
|
260
|
+
opt("discard_asserts", 'a', 'bool', false, function(){/*
|
|
261
|
+
Discard any assert statements. If you use assert statements
|
|
262
|
+
for debugging, then use this option to generate an optimized build
|
|
263
|
+
without the assert statements.
|
|
264
|
+
*/});
|
|
265
|
+
|
|
266
|
+
opt("uglify", 'u', 'bool', false, function(){/*
|
|
267
|
+
Minify the output instead of pretty printing it.
|
|
268
|
+
*/});
|
|
269
|
+
|
|
270
|
+
opt("omit_baselib", 'm', 'bool', false, function(){/*
|
|
271
|
+
Omit baselib functions. Use this if you have a
|
|
272
|
+
different way of ensuring they're imported. For example,
|
|
273
|
+
you could import one of the baselib-plain-*.js files directly
|
|
274
|
+
into the global namespace.
|
|
275
|
+
*/});
|
|
276
|
+
|
|
277
|
+
opt("js_version", 'js,j', 'string', '5', function(){/*
|
|
278
|
+
The JavaScript version to output. By default, ES 5
|
|
279
|
+
compatible JavaScript is output. You can specify 6
|
|
280
|
+
to output ES 6 compatible JavaScript instead. The ES 6
|
|
281
|
+
version of the code will be smaller and faster by making
|
|
282
|
+
use of some ES 6 only features, such as iterators and
|
|
283
|
+
generators.
|
|
284
|
+
*/}, ['5', '6']);
|
|
285
|
+
|
|
286
|
+
opt("import_path", "p", 'string', '', function(){/*
|
|
287
|
+
A list of paths in which to look for imported modules.
|
|
288
|
+
Multiple paths must be separated by the path separator
|
|
289
|
+
(: on Unix and ; on Windows). You can also use the
|
|
290
|
+
environment variable RAPYDSCRIPT_IMPORT_PATH for this,
|
|
291
|
+
with identical syntax. Note that these directories
|
|
292
|
+
are searched before the builtin paths, which means you
|
|
293
|
+
can use them to replace builtin modules.
|
|
294
|
+
*/});
|
|
295
|
+
|
|
296
|
+
opt("filename_for_stdin", "P", 'string', '', function(){/*
|
|
297
|
+
filename to use for data piped into STDIN. Imports will
|
|
298
|
+
be resolved relative to the directory this filename is in.
|
|
299
|
+
Note, that you can also use the --import-path option to
|
|
300
|
+
add directories to the import path.
|
|
301
|
+
*/});
|
|
302
|
+
|
|
303
|
+
opt("cache_dir", "C", 'string', '', function(){/*
|
|
304
|
+
directory to use to store the cached files generated
|
|
305
|
+
by the compiler. Normally, these are stored right next to
|
|
306
|
+
every compiled pyj file, with the extension pyj-cached. This
|
|
307
|
+
option allows them to be consolidated in a single directory.
|
|
308
|
+
*/});
|
|
309
|
+
|
|
310
|
+
opt("comments", undefined, 'string', '', function(){/*
|
|
311
|
+
Preserve copyright comments in the output.
|
|
312
|
+
By default this works like Google Closure, keeping
|
|
313
|
+
JSDoc-style comments that contain "@license" or
|
|
314
|
+
"@preserve". You can optionally pass one of the
|
|
315
|
+
following arguments to this flag:
|
|
316
|
+
- "all" to keep all comments
|
|
317
|
+
- a valid JS regexp (needs to start with a slash) to
|
|
318
|
+
keep only comments that match.
|
|
319
|
+
|
|
320
|
+
Note that currently not *all* comments can be kept
|
|
321
|
+
when compression is on, because of dead code removal
|
|
322
|
+
or cascading statements into sequences.
|
|
323
|
+
*/});
|
|
324
|
+
|
|
325
|
+
opt("stats", undefined, 'bool', false, function(){/*
|
|
326
|
+
Display operations run time on STDERR.
|
|
327
|
+
*/});
|
|
328
|
+
|
|
329
|
+
opt("execute", 'x,exec', 'bool', false, function(){/*
|
|
330
|
+
Compile and execute the RapydScript code, all in
|
|
331
|
+
one invocation. Useful if you wish to use RapydScript for
|
|
332
|
+
scripting. Note that you can also use the -o option to
|
|
333
|
+
have the compiled JavaScript written out to a file
|
|
334
|
+
before being executed. If you specify this option you
|
|
335
|
+
should not specify the -m option to omit the baselib, or
|
|
336
|
+
execution will fail.
|
|
337
|
+
*/});
|
|
338
|
+
|
|
339
|
+
opt("module", '', 'bool', false, function(){/*
|
|
340
|
+
Output the compiled JavaScript as an ES module. Adds
|
|
341
|
+
the export keyword before top-level function and const
|
|
342
|
+
declarations, and removes the private scope wrapper
|
|
343
|
+
(implies --bare).
|
|
344
|
+
*/});
|
|
345
|
+
|
|
346
|
+
opt("pythonize_strings", 'S', 'bool', false, function(){/*
|
|
347
|
+
Patch String.prototype with Python-style string methods
|
|
348
|
+
(strip, join, split, format, etc.) at startup, equivalent
|
|
349
|
+
to calling strings() from the pythonize module. This allows
|
|
350
|
+
Python-style string methods to be used directly on any
|
|
351
|
+
string in RapydScript without an explicit import.
|
|
352
|
+
*/});
|
|
353
|
+
|
|
354
|
+
opt("python_flags", "F", 'string', '', function(){/*
|
|
355
|
+
Comma-separated list of Python compatibility flags to enable
|
|
356
|
+
globally for all compiled files. Equivalent to adding
|
|
357
|
+
"from __python__ import <flags>" at the top of every file.
|
|
358
|
+
Available flags: dict_literals, overload_getitem, bound_methods,
|
|
359
|
+
hash_literals, overload_operators. Prefix a flag with no_ to
|
|
360
|
+
explicitly disable it (e.g. no_bound_methods).
|
|
361
|
+
*/});
|
|
362
|
+
|
|
363
|
+
create_group('repl', '', function(){/*
|
|
364
|
+
Run a Read-Eval-Print-Loop (REPL). This allows
|
|
365
|
+
you to type and run RapydScript at a live
|
|
366
|
+
command prompt.
|
|
367
|
+
*/});
|
|
368
|
+
|
|
369
|
+
opt("no_js", '', 'bool', false, function(){/*
|
|
370
|
+
Do not display the compiled JavaScript before executing
|
|
371
|
+
it.
|
|
372
|
+
*/});
|
|
373
|
+
|
|
374
|
+
create_group('lint', "[input1.pyj input2.pyj ...]", function(){/*
|
|
375
|
+
Run the RapydScript linter. This will find various
|
|
376
|
+
possible problems in the .pyj files you specify and
|
|
377
|
+
write messages about them to stdout. Use - to read from STDIN.
|
|
378
|
+
The main check it performs is for unused/undefined
|
|
379
|
+
symbols, like pyflakes does for python.
|
|
380
|
+
*/}, function() {/*
|
|
381
|
+
In addition to the command line options listed below,
|
|
382
|
+
you can also control the linter in a couple of other ways.
|
|
383
|
+
|
|
384
|
+
In the actual source files, you can turn off specific checks
|
|
385
|
+
on a line by line basis by adding: # noqa:check1,check2...
|
|
386
|
+
to the end of the line. For example:
|
|
387
|
+
|
|
388
|
+
f() # noqa: undef
|
|
389
|
+
|
|
390
|
+
will prevent the linter from showing undefined symbol
|
|
391
|
+
errors for this line. You can also turn off individual checks
|
|
392
|
+
at the file level, by putting the noqa directive on a
|
|
393
|
+
line by itself near the top of the file, for example:
|
|
394
|
+
|
|
395
|
+
# noqa: undef
|
|
396
|
+
|
|
397
|
+
Similarly, you can tell the linter
|
|
398
|
+
about global (builtin) symbols with a comment near the top
|
|
399
|
+
of the file, for example:
|
|
400
|
+
|
|
401
|
+
# globals:assert,myglobalvar
|
|
402
|
+
|
|
403
|
+
This will prevent the linter form treating these names as
|
|
404
|
+
undefined symbols.
|
|
405
|
+
|
|
406
|
+
Finally, the linter looks for a setup.cfg file in the
|
|
407
|
+
directory containing the file being linted or any of its
|
|
408
|
+
parent directories. You can both turn off individual checks
|
|
409
|
+
and define project specific global symbols in the setup.cfg
|
|
410
|
+
file, like this:
|
|
411
|
+
|
|
412
|
+
[rapydscript]
|
|
413
|
+
globals=myglobalvar,otherglobalvar
|
|
414
|
+
noqa=undef,eol-semicolon
|
|
415
|
+
|
|
416
|
+
*/
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
opt("globals", 'g,b,builtins', 'string', '', function(){/*
|
|
420
|
+
Comma separated list of additional names that the linter will
|
|
421
|
+
treat as global symbols. It ignores undefined errors for
|
|
422
|
+
global symbols.
|
|
423
|
+
*/});
|
|
424
|
+
|
|
425
|
+
opt("noqa", 'e,ignore,exclude', 'string', '', function(){/*
|
|
426
|
+
Comma separated list of linter checks to skip. The linter
|
|
427
|
+
will not report errors corresponding to these checks.
|
|
428
|
+
The check names are output in the linter's normal output, you
|
|
429
|
+
can also list all check names with --noqa-list.
|
|
430
|
+
*/});
|
|
431
|
+
|
|
432
|
+
opt("errorformat", 'f,s,style', 'string', 'human', function(){/*
|
|
433
|
+
Output the results in the specified format. Valid formats are:
|
|
434
|
+
human - output is suited for reading by humans (the default)
|
|
435
|
+
json - output is in JSON format
|
|
436
|
+
vim - output can be consumed easily by vim's errorformat
|
|
437
|
+
directive. Format is:
|
|
438
|
+
filename:line:col:errortype:token:message [identifier]
|
|
439
|
+
undef - output only the names of undefined symbols in a form that
|
|
440
|
+
can be easily copy/pasted
|
|
441
|
+
*/}, ['human', 'json', 'vim', 'undef']);
|
|
442
|
+
|
|
443
|
+
opt("noqa_list", '', 'bool', false, function(){/*
|
|
444
|
+
List all available linter checks, with a brief
|
|
445
|
+
description, and exit.
|
|
446
|
+
*/});
|
|
447
|
+
|
|
448
|
+
opt('stdin_filename', '', 'string', 'STDIN', function(){/*
|
|
449
|
+
The filename for data read from STDIN. If not specified
|
|
450
|
+
STDIN is used.
|
|
451
|
+
*/});
|
|
452
|
+
|
|
453
|
+
create_group('test', '[test1 test2...]', function(){/*
|
|
454
|
+
Run RapydScript tests. You can specify the name of
|
|
455
|
+
individual test files to only run tests from those
|
|
456
|
+
files. For example:
|
|
457
|
+
test baselib functions
|
|
458
|
+
*/});
|
|
459
|
+
|
|
460
|
+
create_group('self', '', function(){/*
|
|
461
|
+
Compile the compiler itself. It will only actually
|
|
462
|
+
compile if something has changed since the last time
|
|
463
|
+
it was called. To force a recompilation, simply
|
|
464
|
+
delete lib/signatures.json
|
|
465
|
+
*/});
|
|
466
|
+
|
|
467
|
+
opt("complete", 'c,f,full', 'bool', false, function(){/*
|
|
468
|
+
Run the compilation repeatedly, as many times as neccessary,
|
|
469
|
+
so that the compiler is built with the most upto date version
|
|
470
|
+
of itself.
|
|
471
|
+
*/});
|
|
472
|
+
|
|
473
|
+
opt("test", 't', 'bool', false, function(){/*
|
|
474
|
+
Run the test suite after building completes.
|
|
475
|
+
*/});
|
|
476
|
+
|
|
477
|
+
opt("profile", 'p', 'bool', false, function(){/*
|
|
478
|
+
Run a CPU profiler which will output its data to
|
|
479
|
+
self.cpuprofile. The data can then be analysed with
|
|
480
|
+
node-inspector.
|
|
481
|
+
*/});
|
|
482
|
+
|
|
483
|
+
create_group('gettext', "[input1.pyj input_dir ...]", function(){/*
|
|
484
|
+
Extract strings marked for translation from the specified
|
|
485
|
+
source files and directories.
|
|
486
|
+
*/}, function() {/*
|
|
487
|
+
Directories are scanned recursively for .pyj files. If no
|
|
488
|
+
arguments are specified, the source code is read from stdin.
|
|
489
|
+
|
|
490
|
+
Translatable string are output on stdout in the .po format.
|
|
491
|
+
Translatable strings are detected in the input as literal
|
|
492
|
+
string arguments to the functions _(), gettext() and ngettext().
|
|
493
|
+
*/
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
opt("omit_header", 'm', 'bool', false, function(){/*
|
|
497
|
+
Do not write header with 'msgid ""' entry.
|
|
498
|
+
*/});
|
|
499
|
+
|
|
500
|
+
opt("package_name", '', 'string', 'XXX', function(){/*
|
|
501
|
+
Set the package name in the header
|
|
502
|
+
*/});
|
|
503
|
+
|
|
504
|
+
opt("package_version", '', 'string', 'XXX', function(){/*
|
|
505
|
+
Set the package version in the header
|
|
506
|
+
*/});
|
|
507
|
+
|
|
508
|
+
opt("bugs_address", 'bug_address', 'string', 'bugs@example.com', function(){/*
|
|
509
|
+
Set the email address for bug reports in the header
|
|
510
|
+
*/});
|
|
511
|
+
|
|
512
|
+
create_group('msgfmt', "", function(){/*
|
|
513
|
+
Compile a .po file into a .json file that can
|
|
514
|
+
be used to load translations in a browser.
|
|
515
|
+
*/}, function() {/*
|
|
516
|
+
The .po file is read from
|
|
517
|
+
stdin and the .json file written to stdout. Note
|
|
518
|
+
that it is assumed the .po file is encoded in UTF-8.
|
|
519
|
+
If you .po file is in some other encoding, you will need to
|
|
520
|
+
convert it to UTF-8 first.
|
|
521
|
+
*/
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
opt("use_fuzzy", 'f', 'bool', false, function(){/*
|
|
525
|
+
Use fuzzy translations, they are ignored by default.
|
|
526
|
+
*/});
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
var argv = module.exports.argv = parse_args();
|
|
530
|
+
if (typeof argv.js_version === 'string') {
|
|
531
|
+
argv.js_version = parseInt(argv.js_version);
|
|
532
|
+
if (isNaN(argv.js_version)) {
|
|
533
|
+
console.log('--js-version must be a number');
|
|
534
|
+
process.exit(1);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
if (argv.help) {
|
|
539
|
+
print_usage((!argv.auto_mode) ? groups[argv.mode]: undefined);
|
|
540
|
+
process.exit(0);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
if (argv.version) {
|
|
544
|
+
var json = require("../package.json");
|
|
545
|
+
console.log(json.name + ' ' + json.version);
|
|
546
|
+
process.exit(0);
|
|
547
|
+
}
|