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.
Files changed (132) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +80 -26
  3. package/bin/build.ts +117 -0
  4. package/bin/package.json +1 -0
  5. package/bin/rapydscript +65 -62
  6. package/build_wheels.py +133 -0
  7. package/editor-plugins/README.md +80 -0
  8. package/editor-plugins/nvim.lua +321 -0
  9. package/local-agent.md +28 -0
  10. package/package.json +4 -5
  11. package/publish.py +27 -17
  12. package/release/baselib-plain-pretty.js +448 -326
  13. package/release/baselib-plain-ugly.js +3 -3
  14. package/release/compiler.js +9027 -8139
  15. package/release/signatures.json +27 -27
  16. package/release/stdlib_modules.json +1 -0
  17. package/src/ast.pyj +428 -280
  18. package/src/baselib-builtins.pyj +49 -28
  19. package/src/baselib-containers.pyj +241 -226
  20. package/src/baselib-errors.pyj +8 -1
  21. package/src/baselib-internal.pyj +38 -23
  22. package/src/baselib-itertools.pyj +13 -7
  23. package/src/baselib-str.pyj +59 -84
  24. package/src/compiler.pyj +4 -4
  25. package/src/errors.pyj +3 -4
  26. package/src/lib/aes.pyj +46 -32
  27. package/src/lib/elementmaker.pyj +11 -9
  28. package/src/lib/encodings.pyj +15 -5
  29. package/src/lib/gettext.pyj +9 -4
  30. package/src/lib/math.pyj +106 -45
  31. package/src/lib/operator.pyj +10 -10
  32. package/src/lib/pythonize.pyj +2 -1
  33. package/src/lib/random.pyj +28 -21
  34. package/src/lib/re.pyj +492 -19
  35. package/src/lib/traceback.pyj +171 -29
  36. package/src/lib/uuid.pyj +2 -2
  37. package/src/output/classes.pyj +28 -27
  38. package/src/output/codegen.pyj +87 -83
  39. package/src/output/comments.pyj +8 -8
  40. package/src/output/exceptions.pyj +20 -21
  41. package/src/output/functions.pyj +66 -64
  42. package/src/output/literals.pyj +24 -23
  43. package/src/output/loops.pyj +84 -142
  44. package/src/output/modules.pyj +55 -68
  45. package/src/output/operators.pyj +40 -29
  46. package/src/output/statements.pyj +21 -15
  47. package/src/output/stream.pyj +82 -56
  48. package/src/output/utils.pyj +12 -8
  49. package/src/parse.pyj +971 -620
  50. package/src/string_interpolation.pyj +5 -3
  51. package/src/tokenizer.pyj +188 -148
  52. package/src/utils.pyj +32 -15
  53. package/test/_treeshake_mod.pyj +30 -0
  54. package/test/_treeshake_side_effect.pyj +9 -0
  55. package/test/ast_serialization.pyj +392 -0
  56. package/test/async.pyj +95 -0
  57. package/test/baselib.pyj +1 -2
  58. package/test/embedded_compiler.pyj +57 -0
  59. package/test/fmt.pyj +291 -0
  60. package/test/generic.pyj +16 -3
  61. package/test/imports.pyj +8 -6
  62. package/test/internationalization.pyj +38 -37
  63. package/test/lint.pyj +120 -117
  64. package/test/lsp.pyj +257 -0
  65. package/test/repl.pyj +70 -65
  66. package/test/sourcemaps.pyj +315 -0
  67. package/test/starargs.pyj +46 -39
  68. package/test/str.pyj +8 -0
  69. package/test/traceback.pyj +263 -0
  70. package/test/treeshaking.pyj +181 -0
  71. package/test/web_repl_export.pyj +88 -0
  72. package/tools/ast_serialize.mjs +557 -0
  73. package/tools/cli.mjs +531 -0
  74. package/tools/compile.mjs +205 -0
  75. package/tools/compiler.mjs +159 -0
  76. package/tools/{completer.js → completer.mjs} +6 -6
  77. package/tools/{embedded_compiler.js → embedded_compiler.mjs} +17 -13
  78. package/tools/export.js +109 -56
  79. package/tools/fmt.mjs +975 -0
  80. package/tools/{gettext.js → gettext.mjs} +46 -53
  81. package/tools/ini.mjs +175 -0
  82. package/tools/{lint.js → lint.mjs} +78 -55
  83. package/tools/lsp.mjs +964 -0
  84. package/tools/lsp_protocol.mjs +259 -0
  85. package/tools/lsp_symbols.mjs +418 -0
  86. package/tools/{msgfmt.js → msgfmt.mjs} +18 -18
  87. package/tools/{repl.js → repl.mjs} +56 -42
  88. package/tools/{self.js → self.mjs} +71 -46
  89. package/tools/sourcemap.mjs +123 -0
  90. package/tools/test.mjs +252 -0
  91. package/tools/treeshake.mjs +400 -0
  92. package/tools/{utils.js → utils.mjs} +26 -23
  93. package/tools/{web_repl.js → web_repl.mjs} +15 -13
  94. package/tools/web_repl_export.mjs +97 -0
  95. package/tree-sitter/README.md +101 -0
  96. package/tree-sitter/grammar.js +992 -0
  97. package/tree-sitter/package.json +43 -0
  98. package/tree-sitter/queries/highlights.scm +232 -0
  99. package/tree-sitter/queries/indents.scm +64 -0
  100. package/tree-sitter/queries/injections.scm +14 -0
  101. package/tree-sitter/queries/locals.scm +108 -0
  102. package/tree-sitter/src/grammar.json +4976 -0
  103. package/tree-sitter/src/node-types.json +2901 -0
  104. package/tree-sitter/src/parser.c +196465 -0
  105. package/tree-sitter/src/scanner.c +294 -0
  106. package/tree-sitter/src/tree_sitter/alloc.h +54 -0
  107. package/tree-sitter/src/tree_sitter/array.h +330 -0
  108. package/tree-sitter/src/tree_sitter/parser.h +286 -0
  109. package/tree-sitter/test/corpus/chaining.txt +99 -0
  110. package/tree-sitter/test/corpus/classes.txt +147 -0
  111. package/tree-sitter/test/corpus/comprehensions.txt +155 -0
  112. package/tree-sitter/test/corpus/containers.txt +242 -0
  113. package/tree-sitter/test/corpus/control_flow.txt +361 -0
  114. package/tree-sitter/test/corpus/decorators.txt +64 -0
  115. package/tree-sitter/test/corpus/existential.txt +102 -0
  116. package/tree-sitter/test/corpus/functions.txt +293 -0
  117. package/tree-sitter/test/corpus/imports.txt +117 -0
  118. package/tree-sitter/test/corpus/literals.txt +135 -0
  119. package/tree-sitter/test/corpus/operators.txt +296 -0
  120. package/tree-sitter/test/corpus/statements.txt +189 -0
  121. package/tree-sitter/test/corpus/strings.txt +90 -0
  122. package/tree-sitter/test/corpus/subscripts.txt +227 -0
  123. package/tree-sitter/tree-sitter.json +36 -0
  124. package/web-repl/env.js +35 -23
  125. package/web-repl/main.js +8 -8
  126. package/bin/export +0 -75
  127. package/bin/web-repl-export +0 -102
  128. package/tools/cli.js +0 -523
  129. package/tools/compile.js +0 -184
  130. package/tools/compiler.js +0 -84
  131. package/tools/ini.js +0 -65
  132. package/tools/test.js +0 -110
package/tools/cli.js DELETED
@@ -1,523 +0,0 @@
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
- create_group('repl', '', function(){/*
340
- Run a Read-Eval-Print-Loop (REPL). This allows
341
- you to type and run RapydScript at a live
342
- command prompt.
343
- */});
344
-
345
- opt("no_js", '', 'bool', false, function(){/*
346
- Do not display the compiled JavaScript before executing
347
- it.
348
- */});
349
-
350
- create_group('lint', "[input1.pyj input2.pyj ...]", function(){/*
351
- Run the RapydScript linter. This will find various
352
- possible problems in the .pyj files you specify and
353
- write messages about them to stdout. Use - to read from STDIN.
354
- The main check it performs is for unused/undefined
355
- symbols, like pyflakes does for python.
356
- */}, function() {/*
357
- In addition to the command line options listed below,
358
- you can also control the linter in a couple of other ways.
359
-
360
- In the actual source files, you can turn off specific checks
361
- on a line by line basis by adding: # noqa:check1,check2...
362
- to the end of the line. For example:
363
-
364
- f() # noqa: undef
365
-
366
- will prevent the linter from showing undefined symbol
367
- errors for this line. You can also turn off individual checks
368
- at the file level, by putting the noqa directive on a
369
- line by itself near the top of the file, for example:
370
-
371
- # noqa: undef
372
-
373
- Similarly, you can tell the linter
374
- about global (builtin) symbols with a comment near the top
375
- of the file, for example:
376
-
377
- # globals:assert,myglobalvar
378
-
379
- This will prevent the linter form treating these names as
380
- undefined symbols.
381
-
382
- Finally, the linter looks for a setup.cfg file in the
383
- directory containing the file being linted or any of its
384
- parent directories. You can both turn off individual checks
385
- and define project specific global symbols in the setup.cfg
386
- file, like this:
387
-
388
- [rapydscript]
389
- globals=myglobalvar,otherglobalvar
390
- noqa=undef,eol-semicolon
391
-
392
- */
393
- });
394
-
395
- opt("globals", 'g,b,builtins', 'string', '', function(){/*
396
- Comma separated list of additional names that the linter will
397
- treat as global symbols. It ignores undefined errors for
398
- global symbols.
399
- */});
400
-
401
- opt("noqa", 'e,ignore,exclude', 'string', '', function(){/*
402
- Comma separated list of linter checks to skip. The linter
403
- will not report errors corresponding to these checks.
404
- The check names are output in the linter's normal output, you
405
- can also list all check names with --noqa-list.
406
- */});
407
-
408
- opt("errorformat", 'f,s,style', 'string', 'human', function(){/*
409
- Output the results in the specified format. Valid formats are:
410
- human - output is suited for reading by humans (the default)
411
- json - output is in JSON format
412
- vim - output can be consumed easily by vim's errorformat
413
- directive. Format is:
414
- filename:line:col:errortype:token:message [identifier]
415
- undef - output only the names of undefined symbols in a form that
416
- can be easily copy/pasted
417
- */}, ['human', 'json', 'vim', 'undef']);
418
-
419
- opt("noqa_list", '', 'bool', false, function(){/*
420
- List all available linter checks, with a brief
421
- description, and exit.
422
- */});
423
-
424
- opt('stdin_filename', '', 'string', 'STDIN', function(){/*
425
- The filename for data read from STDIN. If not specified
426
- STDIN is used.
427
- */});
428
-
429
- create_group('test', '[test1 test2...]', function(){/*
430
- Run RapydScript tests. You can specify the name of
431
- individual test files to only run tests from those
432
- files. For example:
433
- test baselib functions
434
- */});
435
-
436
- create_group('self', '', function(){/*
437
- Compile the compiler itself. It will only actually
438
- compile if something has changed since the last time
439
- it was called. To force a recompilation, simply
440
- delete lib/signatures.json
441
- */});
442
-
443
- opt("complete", 'c,f,full', 'bool', false, function(){/*
444
- Run the compilation repeatedly, as many times as neccessary,
445
- so that the compiler is built with the most upto date version
446
- of itself.
447
- */});
448
-
449
- opt("test", 't', 'bool', false, function(){/*
450
- Run the test suite after building completes.
451
- */});
452
-
453
- opt("profile", 'p', 'bool', false, function(){/*
454
- Run a CPU profiler which will output its data to
455
- self.cpuprofile. The data can then be analysed with
456
- node-inspector.
457
- */});
458
-
459
- create_group('gettext', "[input1.pyj input_dir ...]", function(){/*
460
- Extract strings marked for translation from the specified
461
- source files and directories.
462
- */}, function() {/*
463
- Directories are scanned recursively for .pyj files. If no
464
- arguments are specified, the source code is read from stdin.
465
-
466
- Translatable string are output on stdout in the .po format.
467
- Translatable strings are detected in the input as literal
468
- string arguments to the functions _(), gettext() and ngettext().
469
- */
470
- });
471
-
472
- opt("omit_header", 'm', 'bool', false, function(){/*
473
- Do not write header with 'msgid ""' entry.
474
- */});
475
-
476
- opt("package_name", '', 'string', 'XXX', function(){/*
477
- Set the package name in the header
478
- */});
479
-
480
- opt("package_version", '', 'string', 'XXX', function(){/*
481
- Set the package version in the header
482
- */});
483
-
484
- opt("bugs_address", 'bug_address', 'string', 'bugs@example.com', function(){/*
485
- Set the email address for bug reports in the header
486
- */});
487
-
488
- create_group('msgfmt', "", function(){/*
489
- Compile a .po file into a .json file that can
490
- be used to load translations in a browser.
491
- */}, function() {/*
492
- The .po file is read from
493
- stdin and the .json file written to stdout. Note
494
- that it is assumed the .po file is encoded in UTF-8.
495
- If you .po file is in some other encoding, you will need to
496
- convert it to UTF-8 first.
497
- */
498
- });
499
-
500
- opt("use_fuzzy", 'f', 'bool', false, function(){/*
501
- Use fuzzy translations, they are ignored by default.
502
- */});
503
-
504
-
505
- var argv = module.exports.argv = parse_args();
506
- if (typeof argv.js_version === 'string') {
507
- argv.js_version = parseInt(argv.js_version);
508
- if (isNaN(argv.js_version)) {
509
- console.log('--js-version must be a number');
510
- process.exit(1);
511
- }
512
- }
513
-
514
- if (argv.help) {
515
- print_usage((!argv.auto_mode) ? groups[argv.mode]: undefined);
516
- process.exit(0);
517
- }
518
-
519
- if (argv.version) {
520
- var json = require("../package.json");
521
- console.log(json.name + ' ' + json.version);
522
- process.exit(0);
523
- }
package/tools/compile.js DELETED
@@ -1,184 +0,0 @@
1
- /*
2
- * compile.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 fs = require('fs');
10
- var path = require('path');
11
- var vm = require('vm');
12
- var RapydScript = require("./compiler").create_compiler();
13
- var utils = require('./utils');
14
-
15
- function read_whole_file(filename, cb) {
16
- if (!filename) {
17
- var chunks = [];
18
- process.stdin.setEncoding('utf-8');
19
- process.stdin.on('data', function (chunk) {
20
- chunks.push(chunk);
21
- }).on('end', function () {
22
- cb(null, chunks.join(""));
23
- });
24
- process.openStdin();
25
- } else {
26
- fs.readFile(filename, "utf-8", cb);
27
- }
28
- }
29
-
30
- function makedirs(dir) {
31
- try {
32
- fs.mkdirSync(dir);
33
- } catch(e) {
34
- if (e.code == 'EEXIST') return;
35
- if (e.code == 'ENOENT') { makedirs(path.dirname(dir)); fs.mkdirSync(dir); }
36
- throw e;
37
- }
38
- }
39
-
40
- function process_cache_dir(dir) {
41
- dir = path.resolve(path.normalize(dir));
42
- makedirs(dir);
43
- return dir;
44
- }
45
-
46
- module.exports = function(start_time, argv, base_path, src_path, lib_path) {
47
- // configure settings for the output
48
- var cache_dir = argv.cache_dir ? process_cache_dir(argv.cache_dir) : '';
49
- var OUTPUT_OPTIONS = {
50
- beautify: !argv.uglify,
51
- private_scope: !argv.bare,
52
- omit_baselib: argv.omit_baselib,
53
- js_version: parseInt(argv.js_version),
54
- keep_docstrings: argv.keep_docstrings,
55
- discard_asserts: argv.discard_asserts,
56
- module_cache_dir: cache_dir,
57
- };
58
-
59
- var files = argv.files.slice();
60
- var STATS = {}, TOPLEVEL;
61
- var num_of_files = files.length || 1;
62
-
63
- function parse_file(code, file, toplevel) {
64
- return RapydScript.parse(code, {
65
- filename: file,
66
- toplevel: toplevel,
67
- basedir: (file !== '<stdin>') ? path.dirname(file) : undefined,
68
- libdir: path.join(src_path, 'lib'),
69
- import_dirs: utils.get_import_dirs(argv.import_path),
70
- discard_asserts: argv.discard_asserts,
71
- module_cache_dir: cache_dir,
72
- });
73
- }
74
-
75
- function write_output(output) {
76
- if (argv.output) {
77
- // Node's filesystem module cannot write directly to /dev/stdout
78
- if (argv.output == '/dev/stdout') console.log(output);
79
- else if (argv.output == '/dev/stderr') console.error(output);
80
- else fs.writeFileSync(argv.output, output, "utf8");
81
- } else if (!argv.execute){
82
- console.log(output);
83
- }
84
- if (argv.execute) {
85
- vm.runInNewContext(output, {'console':console, 'require':require}, {'filename':files[0]});
86
- }
87
- }
88
-
89
- function time_it(name, cont) {
90
- var t1 = new Date().getTime();
91
- var ret = cont();
92
- if (argv.stats) {
93
- var spent = new Date().getTime() - t1;
94
- if (STATS[name]) STATS[name] += spent;
95
- else STATS[name] = spent;
96
- }
97
- return ret;
98
- }
99
-
100
- function compile_single_file(err, code) {
101
- var output;
102
- if (err) {
103
- console.error("ERROR: can't read file: " + files[0]);
104
- process.exit(1);
105
- }
106
- time_it("parse", function(){
107
- var file = files[0] || argv.filename_for_stdin || '<stdin>';
108
- try {
109
- TOPLEVEL = parse_file(code, file, TOPLEVEL);
110
- } catch (e) {
111
- if (!(e instanceof RapydScript.SyntaxError)) throw e;
112
- console.error(e.toString());
113
- process.exit(1);
114
- }
115
- });
116
-
117
- try {
118
- output = new RapydScript.OutputStream(OUTPUT_OPTIONS);
119
- } catch(ex) {
120
- if (ex instanceof RapydScript.DefaultsError) {
121
- console.error(ex.message);
122
- process.exit(1);
123
- }
124
- throw ex;
125
- }
126
-
127
- time_it("generate", function(){
128
- TOPLEVEL.print(output);
129
- });
130
-
131
- output = output.get();
132
-
133
- write_output(output);
134
-
135
- files = files.slice(1);
136
- if (files.length) {
137
- setImmediate(read_whole_file, files[0], compile_single_file);
138
- return;
139
- }
140
- if (argv.stats) {
141
- console.error(RapydScript.string_template("Timing information (compressed {count} files):", {
142
- count: num_of_files
143
- }));
144
- for (var i in STATS) if (Object.prototype.hasOwnProperty.call(STATS, i)) {
145
- console.error(RapydScript.string_template("- {name}: {time}s", {
146
- name: i,
147
- time: (STATS[i] / 1000).toFixed(3)
148
- }));
149
- }
150
- }
151
- }
152
-
153
-
154
- if (argv.comments) {
155
- if (/^\//.test(argv.comments)) {
156
- OUTPUT_OPTIONS.comments = new Function("return(" + argv.comments + ")")(); // jshint ignore:line
157
- } else if (argv.comments == "all") {
158
- OUTPUT_OPTIONS.comments = true;
159
- } else {
160
- OUTPUT_OPTIONS.comments = function(node, comment) {
161
- var text = comment.value;
162
- var type = comment.type;
163
- if (type == "comment2") {
164
- // multiline comment
165
- return /@preserve|@license|@cc_on/i.test(text);
166
- }
167
- };
168
- }
169
- }
170
-
171
- if (!argv.omit_baselib) {
172
- var which = (OUTPUT_OPTIONS.beautify) ? 'pretty' : 'ugly';
173
- OUTPUT_OPTIONS.baselib_plain = fs.readFileSync(path.join(lib_path, 'baselib-plain-' + which + '.js'), 'utf-8');
174
- }
175
-
176
- if (files.filter(function(el){ return el == "-"; }).length > 1) {
177
- console.error("ERROR: Can read a single file from STDIN (two or more dashes specified)");
178
- process.exit(1);
179
- }
180
-
181
- setImmediate(read_whole_file, files[0], compile_single_file);
182
-
183
- };
184
-