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/src/output/codegen.pyj
CHANGED
|
@@ -2,10 +2,6 @@
|
|
|
2
2
|
# License: BSD Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
|
3
3
|
from __python__ import hash_literals
|
|
4
4
|
|
|
5
|
-
# globals:console,regenerate,writefile
|
|
6
|
-
|
|
7
|
-
from utils import noop
|
|
8
|
-
from parse import PRECEDENCE
|
|
9
5
|
from ast import (
|
|
10
6
|
AST_Array, AST_Assign, AST_BaseCall, AST_Binary, AST_BlockStatement, AST_Break,
|
|
11
7
|
AST_Class, AST_Conditional, AST_Constant, AST_Continue,
|
|
@@ -18,22 +14,25 @@ from ast import (
|
|
|
18
14
|
AST_Statement, AST_StatementWithBody, AST_String, AST_Sub, AST_ItemAccess,
|
|
19
15
|
AST_Symbol, AST_This, AST_Throw, AST_Toplevel, AST_Try, AST_Unary,
|
|
20
16
|
AST_UnaryPrefix, AST_Undefined, AST_Var, AST_VarDef, AST_Assert,
|
|
21
|
-
AST_Verbatim, AST_While, AST_With, AST_Yield, TreeWalker, AST_Existential
|
|
17
|
+
AST_Verbatim, AST_While, AST_With, AST_Yield, AST_Await, TreeWalker, AST_Existential
|
|
22
18
|
)
|
|
23
|
-
from output.exceptions import print_try
|
|
24
19
|
from output.classes import print_class
|
|
20
|
+
from output.comments import print_comments
|
|
21
|
+
from output.exceptions import print_try
|
|
22
|
+
from output.functions import print_function, print_function_call
|
|
25
23
|
from output.literals import print_array, print_obj_literal, print_object, print_set, print_regexp
|
|
26
24
|
from output.loops import print_do_loop, print_while_loop, print_for_loop_body, print_for_in, print_list_comprehension
|
|
27
25
|
from output.modules import print_top_level, print_imports
|
|
28
|
-
from output.comments import print_comments
|
|
29
26
|
from output.operators import (
|
|
30
27
|
print_getattr, print_getitem, print_rich_getitem, print_splice_assignment,
|
|
31
28
|
print_unary_prefix, print_binary_op, print_assign,
|
|
32
29
|
print_conditional, print_seq, print_existential
|
|
33
30
|
)
|
|
34
|
-
from output.functions import print_function, print_function_call
|
|
35
31
|
from output.statements import print_bracketed, first_in_statement, force_statement, print_with, print_assert
|
|
36
32
|
from output.utils import make_block, make_num
|
|
33
|
+
from parse import PRECEDENCE
|
|
34
|
+
from utils import noop
|
|
35
|
+
|
|
37
36
|
|
|
38
37
|
# -----[ code generators ]-----
|
|
39
38
|
def generate_code():
|
|
@@ -41,23 +40,25 @@ def generate_code():
|
|
|
41
40
|
def DEFPRINT(nodetype, generator):
|
|
42
41
|
nodetype.prototype._codegen = generator
|
|
43
42
|
|
|
44
|
-
AST_Node.prototype.print = def(stream, force_parens):
|
|
43
|
+
AST_Node.prototype.print = def (stream, force_parens):
|
|
45
44
|
self = this
|
|
46
45
|
generator = self._codegen
|
|
47
46
|
stream.push_node(self)
|
|
48
47
|
if force_parens or self.needs_parens(stream):
|
|
49
|
-
stream.with_parens(def():
|
|
48
|
+
stream.with_parens(def ():
|
|
50
49
|
self.add_comments(stream)
|
|
50
|
+
stream.add_mapping(self)
|
|
51
51
|
generator(self, stream)
|
|
52
52
|
)
|
|
53
53
|
else:
|
|
54
54
|
self.add_comments(stream)
|
|
55
|
+
stream.add_mapping(self)
|
|
55
56
|
generator(self, stream)
|
|
56
57
|
|
|
57
58
|
stream.pop_node()
|
|
58
59
|
|
|
59
60
|
# -----[ comments ]-----
|
|
60
|
-
AST_Node.prototype.add_comments = def(output):
|
|
61
|
+
AST_Node.prototype.add_comments = def (output):
|
|
61
62
|
if not is_node_type(this, AST_Toplevel):
|
|
62
63
|
print_comments(this, output)
|
|
63
64
|
|
|
@@ -65,51 +66,48 @@ def generate_code():
|
|
|
65
66
|
def PARENS(nodetype, func):
|
|
66
67
|
nodetype.prototype.needs_parens = func
|
|
67
68
|
|
|
68
|
-
PARENS(AST_Node, def():
|
|
69
|
+
PARENS(AST_Node, def ():
|
|
69
70
|
return False
|
|
70
71
|
)
|
|
71
72
|
# a function expression needs parens around it when it's provably
|
|
72
73
|
# the first token to appear in a statement.
|
|
73
|
-
PARENS(AST_Function, def(output):
|
|
74
|
+
PARENS(AST_Function, def (output):
|
|
74
75
|
return first_in_statement(output)
|
|
75
76
|
)
|
|
76
77
|
# same goes for an object literal, because otherwise it would be
|
|
77
78
|
# interpreted as a block of code.
|
|
78
|
-
PARENS(AST_Object, def(output):
|
|
79
|
+
PARENS(AST_Object, def (output):
|
|
79
80
|
return first_in_statement(output)
|
|
80
81
|
)
|
|
81
|
-
PARENS(AST_Unary, def(output):
|
|
82
|
+
PARENS(AST_Unary, def (output):
|
|
82
83
|
p = output.parent()
|
|
83
84
|
return is_node_type(p, AST_PropAccess) and p.expression is this
|
|
84
85
|
)
|
|
85
|
-
PARENS(AST_Seq, def(output):
|
|
86
|
+
PARENS(AST_Seq, def (output):
|
|
86
87
|
p = output.parent()
|
|
87
88
|
return is_node_type(p, AST_Unary) or is_node_type(p, AST_VarDef) or is_node_type(p, AST_Dot) or is_node_type(p, AST_ObjectProperty) or is_node_type(p, AST_Conditional)
|
|
88
89
|
)
|
|
89
|
-
PARENS(AST_Binary, def(output):
|
|
90
|
+
PARENS(AST_Binary, def (output):
|
|
90
91
|
p = output.parent()
|
|
91
92
|
# (foo && bar)()
|
|
92
93
|
if is_node_type(p, AST_BaseCall) and p.expression is this:
|
|
93
94
|
return True
|
|
94
|
-
|
|
95
95
|
# typeof (foo && bar)
|
|
96
96
|
if is_node_type(p, AST_Unary):
|
|
97
97
|
return True
|
|
98
|
-
|
|
99
98
|
# (foo && bar)["prop"], (foo && bar).prop
|
|
100
99
|
if is_node_type(p, AST_PropAccess) and p.expression is this:
|
|
101
100
|
return True
|
|
102
|
-
|
|
103
101
|
# this deals with precedence: 3 * (2 + 1)
|
|
104
102
|
if is_node_type(p, AST_Binary):
|
|
105
103
|
po = p.operator
|
|
106
104
|
pp = PRECEDENCE[po]
|
|
107
105
|
so = this.operator
|
|
108
106
|
sp = PRECEDENCE[so]
|
|
109
|
-
if pp > sp or pp is sp and this is p.right and not (so is po and (so is
|
|
107
|
+
if pp > sp or pp is sp and this is p.right and not (so is po and (so is '*' or so is '&&' or so is '||')):
|
|
110
108
|
return True
|
|
111
109
|
)
|
|
112
|
-
PARENS(AST_PropAccess, def(output):
|
|
110
|
+
PARENS(AST_PropAccess, def (output):
|
|
113
111
|
p = output.parent()
|
|
114
112
|
if is_node_type(p, AST_New) and p.expression is this:
|
|
115
113
|
# i.e. new (foo.bar().baz)
|
|
@@ -119,7 +117,7 @@ def generate_code():
|
|
|
119
117
|
# interpreted as passing the arguments to the upper New
|
|
120
118
|
# expression.
|
|
121
119
|
try:
|
|
122
|
-
this.walk(new TreeWalker(def(node):
|
|
120
|
+
this.walk(new TreeWalker(def (node):
|
|
123
121
|
if is_node_type(node, AST_BaseCall):
|
|
124
122
|
raise p
|
|
125
123
|
))
|
|
@@ -128,26 +126,27 @@ def generate_code():
|
|
|
128
126
|
raise ex
|
|
129
127
|
return True
|
|
130
128
|
)
|
|
131
|
-
PARENS(AST_BaseCall, def(output):
|
|
129
|
+
PARENS(AST_BaseCall, def (output):
|
|
132
130
|
p = output.parent()
|
|
133
131
|
return is_node_type(p, AST_New) and p.expression is this
|
|
134
132
|
)
|
|
135
|
-
PARENS(AST_New, def(output):
|
|
133
|
+
PARENS(AST_New, def (output):
|
|
136
134
|
p = output.parent()
|
|
137
|
-
if this.args.length is 0 and (is_node_type(p, AST_PropAccess) or is_node_type(p, AST_BaseCall) and p.expression is this):
|
|
135
|
+
if this.args.args.length is 0 and (is_node_type(p, AST_PropAccess) or is_node_type(p, AST_BaseCall) and p.expression is this):
|
|
138
136
|
# (new foo)(bar)
|
|
139
137
|
return True
|
|
140
138
|
)
|
|
141
|
-
PARENS(AST_Number, def(output):
|
|
139
|
+
PARENS(AST_Number, def (output):
|
|
142
140
|
p = output.parent()
|
|
143
141
|
if this.value < 0 and is_node_type(p, AST_PropAccess) and p.expression is this:
|
|
144
142
|
return True
|
|
145
143
|
)
|
|
146
|
-
PARENS(AST_NaN, def(output):
|
|
144
|
+
PARENS(AST_NaN, def (output):
|
|
147
145
|
p = output.parent()
|
|
148
146
|
if is_node_type(p, AST_PropAccess) and p.expression is this:
|
|
149
147
|
return True
|
|
150
148
|
)
|
|
149
|
+
|
|
151
150
|
def assign_and_conditional_paren_rules(output):
|
|
152
151
|
p = output.parent()
|
|
153
152
|
# !(a = false) → true
|
|
@@ -174,18 +173,18 @@ def generate_code():
|
|
|
174
173
|
PARENS(AST_Conditional, assign_and_conditional_paren_rules)
|
|
175
174
|
|
|
176
175
|
# -----[ PRINTERS ]-----
|
|
177
|
-
DEFPRINT(AST_Directive, def(self, output):
|
|
176
|
+
DEFPRINT(AST_Directive, def (self, output):
|
|
178
177
|
output.print_string(self.value)
|
|
179
178
|
output.semicolon()
|
|
180
179
|
)
|
|
181
|
-
DEFPRINT(AST_Debugger, def(self, output):
|
|
182
|
-
output.print(
|
|
180
|
+
DEFPRINT(AST_Debugger, def (self, output):
|
|
181
|
+
output.print('debugger')
|
|
183
182
|
output.semicolon()
|
|
184
183
|
)
|
|
185
|
-
AST_StatementWithBody.prototype._do_print_body = def(output):
|
|
184
|
+
AST_StatementWithBody.prototype._do_print_body = def (output):
|
|
186
185
|
force_statement(this.body, output)
|
|
187
186
|
|
|
188
|
-
DEFPRINT(AST_Statement, def(self, output):
|
|
187
|
+
DEFPRINT(AST_Statement, def (self, output):
|
|
189
188
|
self.body.print(output)
|
|
190
189
|
output.semicolon()
|
|
191
190
|
)
|
|
@@ -193,16 +192,16 @@ def generate_code():
|
|
|
193
192
|
|
|
194
193
|
DEFPRINT(AST_Imports, print_imports)
|
|
195
194
|
|
|
196
|
-
DEFPRINT(AST_SimpleStatement, def(self, output):
|
|
195
|
+
DEFPRINT(AST_SimpleStatement, def (self, output):
|
|
197
196
|
if not (is_node_type(self.body, AST_EmptyStatement)):
|
|
198
197
|
self.body.print(output)
|
|
199
198
|
output.semicolon()
|
|
200
199
|
)
|
|
201
|
-
DEFPRINT(AST_BlockStatement, def(self, output):
|
|
200
|
+
DEFPRINT(AST_BlockStatement, def (self, output):
|
|
202
201
|
print_bracketed(self, output)
|
|
203
202
|
)
|
|
204
203
|
|
|
205
|
-
DEFPRINT(AST_EmptyStatement, def(self, output):
|
|
204
|
+
DEFPRINT(AST_EmptyStatement, def (self, output):
|
|
206
205
|
pass
|
|
207
206
|
)
|
|
208
207
|
|
|
@@ -214,19 +213,19 @@ def generate_code():
|
|
|
214
213
|
|
|
215
214
|
DEFPRINT(AST_ForIn, print_for_in)
|
|
216
215
|
|
|
217
|
-
AST_ForJS.prototype._do_print_body = def(output):
|
|
216
|
+
AST_ForJS.prototype._do_print_body = def (output):
|
|
218
217
|
self = this
|
|
219
|
-
output.with_block(def():
|
|
218
|
+
output.with_block(def ():
|
|
220
219
|
for stmt in self.body.body:
|
|
221
220
|
output.indent()
|
|
222
221
|
stmt.print(output)
|
|
223
222
|
output.newline()
|
|
224
223
|
)
|
|
225
224
|
|
|
226
|
-
DEFPRINT(AST_ForJS, def(self, output):
|
|
227
|
-
output.print(
|
|
225
|
+
DEFPRINT(AST_ForJS, def (self, output):
|
|
226
|
+
output.print('for')
|
|
228
227
|
output.space()
|
|
229
|
-
output.with_parens(def():
|
|
228
|
+
output.with_parens(def ():
|
|
230
229
|
self.condition.print(output)
|
|
231
230
|
)
|
|
232
231
|
output.space()
|
|
@@ -241,15 +240,15 @@ def generate_code():
|
|
|
241
240
|
|
|
242
241
|
AST_Lambda.prototype._do_print = print_function
|
|
243
242
|
|
|
244
|
-
DEFPRINT(AST_Lambda, def(self, output):
|
|
243
|
+
DEFPRINT(AST_Lambda, def (self, output):
|
|
245
244
|
self._do_print(output)
|
|
246
245
|
)
|
|
247
246
|
AST_Class.prototype._do_print = print_class
|
|
248
|
-
DEFPRINT(AST_Class, def(self, output):
|
|
247
|
+
DEFPRINT(AST_Class, def (self, output):
|
|
249
248
|
self._do_print(output)
|
|
250
249
|
)
|
|
251
250
|
# -----[ exits ]-----
|
|
252
|
-
AST_Exit.prototype._do_print = def(output, kind):
|
|
251
|
+
AST_Exit.prototype._do_print = def (output, kind):
|
|
253
252
|
self = this
|
|
254
253
|
output.print(kind)
|
|
255
254
|
if self.value:
|
|
@@ -258,18 +257,23 @@ def generate_code():
|
|
|
258
257
|
|
|
259
258
|
output.semicolon()
|
|
260
259
|
|
|
261
|
-
DEFPRINT(AST_Yield, def(self, output):
|
|
262
|
-
self._do_print(output,
|
|
260
|
+
DEFPRINT(AST_Yield, def (self, output):
|
|
261
|
+
self._do_print(output, 'yield' + ('*' if self.is_yield_from else ''))
|
|
263
262
|
)
|
|
264
|
-
DEFPRINT(
|
|
265
|
-
|
|
263
|
+
DEFPRINT(AST_Await, def (self, output):
|
|
264
|
+
output.print('await')
|
|
265
|
+
output.space()
|
|
266
|
+
self.value.print(output)
|
|
267
|
+
)
|
|
268
|
+
DEFPRINT(AST_Return, def (self, output):
|
|
269
|
+
self._do_print(output, 'return')
|
|
266
270
|
)
|
|
267
|
-
DEFPRINT(AST_Throw, def(self, output):
|
|
268
|
-
self._do_print(output,
|
|
271
|
+
DEFPRINT(AST_Throw, def (self, output):
|
|
272
|
+
self._do_print(output, 'throw')
|
|
269
273
|
)
|
|
270
274
|
|
|
271
275
|
# -----[ loop control ]-----
|
|
272
|
-
AST_LoopControl.prototype._do_print = def(output, kind):
|
|
276
|
+
AST_LoopControl.prototype._do_print = def (output, kind):
|
|
273
277
|
output.print(kind)
|
|
274
278
|
if this.label:
|
|
275
279
|
output.space()
|
|
@@ -277,11 +281,11 @@ def generate_code():
|
|
|
277
281
|
|
|
278
282
|
output.semicolon()
|
|
279
283
|
|
|
280
|
-
DEFPRINT(AST_Break, def(self, output):
|
|
281
|
-
self._do_print(output,
|
|
284
|
+
DEFPRINT(AST_Break, def (self, output):
|
|
285
|
+
self._do_print(output, 'break')
|
|
282
286
|
)
|
|
283
|
-
DEFPRINT(AST_Continue, def(self, output):
|
|
284
|
-
self._do_print(output,
|
|
287
|
+
DEFPRINT(AST_Continue, def (self, output):
|
|
288
|
+
self._do_print(output, 'continue')
|
|
285
289
|
)
|
|
286
290
|
|
|
287
291
|
# -----[ if ]-----
|
|
@@ -323,27 +327,26 @@ def generate_code():
|
|
|
323
327
|
|
|
324
328
|
force_statement(self.body, output)
|
|
325
329
|
|
|
326
|
-
DEFPRINT(AST_If, def(self, output):
|
|
327
|
-
output.print(
|
|
330
|
+
DEFPRINT(AST_If, def (self, output):
|
|
331
|
+
output.print('if')
|
|
328
332
|
output.space()
|
|
329
|
-
output.with_parens(def(): self.condition.print(output);)
|
|
333
|
+
output.with_parens(def (): self.condition.print(output);)
|
|
330
334
|
output.space()
|
|
331
335
|
if self.alternative:
|
|
332
336
|
make_then(self, output)
|
|
333
337
|
output.space()
|
|
334
|
-
output.print(
|
|
338
|
+
output.print('else')
|
|
335
339
|
output.space()
|
|
336
340
|
force_statement(self.alternative, output)
|
|
337
341
|
else:
|
|
338
342
|
self._do_print_body(output)
|
|
339
|
-
|
|
340
343
|
)
|
|
341
344
|
|
|
342
345
|
# -----[ exceptions ]-----
|
|
343
346
|
DEFPRINT(AST_Try, print_try)
|
|
344
347
|
|
|
345
348
|
# -----[ var/const ]-----
|
|
346
|
-
AST_Definitions.prototype._do_print = def(output, kind):
|
|
349
|
+
AST_Definitions.prototype._do_print = def (output, kind):
|
|
347
350
|
output.print(kind)
|
|
348
351
|
output.space()
|
|
349
352
|
for i, def_ in enumerate(this.definitions):
|
|
@@ -356,9 +359,10 @@ def generate_code():
|
|
|
356
359
|
if not avoid_semicolon:
|
|
357
360
|
output.semicolon()
|
|
358
361
|
|
|
359
|
-
DEFPRINT(AST_Var, def(self, output):
|
|
360
|
-
self._do_print(output,
|
|
362
|
+
DEFPRINT(AST_Var, def (self, output):
|
|
363
|
+
self._do_print(output, 'var')
|
|
361
364
|
)
|
|
365
|
+
|
|
362
366
|
def parenthesize_for_noin(node, output, noin):
|
|
363
367
|
if not noin:
|
|
364
368
|
node.print(output)
|
|
@@ -366,8 +370,8 @@ def generate_code():
|
|
|
366
370
|
try:
|
|
367
371
|
# need to take some precautions here:
|
|
368
372
|
# https://github.com/mishoo/RapydScript2/issues/60
|
|
369
|
-
node.walk(new TreeWalker(def(node):
|
|
370
|
-
if is_node_type(node, AST_Binary) and node.operator is
|
|
373
|
+
node.walk(new TreeWalker(def (node):
|
|
374
|
+
if is_node_type(node, AST_Binary) and node.operator is 'in':
|
|
371
375
|
raise output
|
|
372
376
|
))
|
|
373
377
|
node.print(output)
|
|
@@ -376,10 +380,10 @@ def generate_code():
|
|
|
376
380
|
raise ex
|
|
377
381
|
node.print(output, True)
|
|
378
382
|
|
|
379
|
-
DEFPRINT(AST_VarDef, def(self, output):
|
|
383
|
+
DEFPRINT(AST_VarDef, def (self, output):
|
|
380
384
|
self.name.print(output)
|
|
381
385
|
if self.value:
|
|
382
|
-
output.assign(
|
|
386
|
+
output.assign('')
|
|
383
387
|
# output.space()
|
|
384
388
|
# output.print("=")
|
|
385
389
|
# output.space()
|
|
@@ -393,7 +397,7 @@ def generate_code():
|
|
|
393
397
|
|
|
394
398
|
AST_Seq.prototype._do_print = print_seq
|
|
395
399
|
|
|
396
|
-
DEFPRINT(AST_Seq, def(self, output):
|
|
400
|
+
DEFPRINT(AST_Seq, def (self, output):
|
|
397
401
|
self._do_print(output)
|
|
398
402
|
)
|
|
399
403
|
DEFPRINT(AST_Dot, print_getattr)
|
|
@@ -421,44 +425,44 @@ def generate_code():
|
|
|
421
425
|
|
|
422
426
|
DEFPRINT(AST_Object, print_object)
|
|
423
427
|
|
|
424
|
-
DEFPRINT(AST_ObjectKeyVal, def(self, output):
|
|
428
|
+
DEFPRINT(AST_ObjectKeyVal, def (self, output):
|
|
425
429
|
self.key.print(output)
|
|
426
430
|
output.colon()
|
|
427
431
|
self.value.print(output)
|
|
428
432
|
)
|
|
429
433
|
DEFPRINT(AST_Set, print_set)
|
|
430
434
|
|
|
431
|
-
AST_Symbol.prototype.definition = def():
|
|
435
|
+
AST_Symbol.prototype.definition = def ():
|
|
432
436
|
return this.thedef
|
|
433
437
|
|
|
434
|
-
DEFPRINT(AST_Symbol, def(self, output):
|
|
438
|
+
DEFPRINT(AST_Symbol, def (self, output):
|
|
435
439
|
def_ = self.definition()
|
|
436
440
|
output.print_name((def_.mangled_name or def_.name) if def_ else self.name)
|
|
437
441
|
)
|
|
438
|
-
DEFPRINT(AST_Undefined, def(self, output):
|
|
439
|
-
output.print(
|
|
442
|
+
DEFPRINT(AST_Undefined, def (self, output):
|
|
443
|
+
output.print('void 0')
|
|
440
444
|
)
|
|
441
445
|
DEFPRINT(AST_Hole, noop)
|
|
442
446
|
|
|
443
|
-
DEFPRINT(AST_Infinity, def(self, output):
|
|
444
|
-
output.print(
|
|
447
|
+
DEFPRINT(AST_Infinity, def (self, output):
|
|
448
|
+
output.print('1/0')
|
|
445
449
|
)
|
|
446
|
-
DEFPRINT(AST_NaN, def(self, output):
|
|
447
|
-
output.print(
|
|
450
|
+
DEFPRINT(AST_NaN, def (self, output):
|
|
451
|
+
output.print('0/0')
|
|
448
452
|
)
|
|
449
|
-
DEFPRINT(AST_This, def(self, output):
|
|
450
|
-
output.print(
|
|
453
|
+
DEFPRINT(AST_This, def (self, output):
|
|
454
|
+
output.print('this')
|
|
451
455
|
)
|
|
452
|
-
DEFPRINT(AST_Constant, def(self, output):
|
|
456
|
+
DEFPRINT(AST_Constant, def (self, output):
|
|
453
457
|
output.print(self.value)
|
|
454
458
|
)
|
|
455
|
-
DEFPRINT(AST_String, def(self, output):
|
|
459
|
+
DEFPRINT(AST_String, def (self, output):
|
|
456
460
|
output.print_string(self.value)
|
|
457
461
|
)
|
|
458
|
-
DEFPRINT(AST_Verbatim, def(self, output):
|
|
462
|
+
DEFPRINT(AST_Verbatim, def (self, output):
|
|
459
463
|
output.print(self.value)
|
|
460
464
|
)
|
|
461
|
-
DEFPRINT(AST_Number, def(self, output):
|
|
465
|
+
DEFPRINT(AST_Number, def (self, output):
|
|
462
466
|
output.print(make_num(self.value))
|
|
463
467
|
)
|
|
464
468
|
DEFPRINT(AST_RegExp, print_regexp)
|
package/src/output/comments.pyj
CHANGED
|
@@ -7,13 +7,13 @@ from ast import AST_Exit, is_node_type
|
|
|
7
7
|
|
|
8
8
|
def output_comments(comments, output, nlb):
|
|
9
9
|
for comm in comments:
|
|
10
|
-
if comm.type is
|
|
11
|
-
output.print(
|
|
10
|
+
if comm.type is 'comment1':
|
|
11
|
+
output.print('//' + comm.value + '\n')
|
|
12
12
|
output.indent()
|
|
13
|
-
elif comm.type is
|
|
14
|
-
output.print(
|
|
13
|
+
elif comm.type is 'comment2':
|
|
14
|
+
output.print('/*' + comm.value + '*/')
|
|
15
15
|
if nlb:
|
|
16
|
-
output.print(
|
|
16
|
+
output.print('\n')
|
|
17
17
|
output.indent()
|
|
18
18
|
else:
|
|
19
19
|
output.space()
|
|
@@ -34,11 +34,11 @@ def print_comments(self, output):
|
|
|
34
34
|
self.value.start.comments_before = v'[]'
|
|
35
35
|
|
|
36
36
|
if c.test:
|
|
37
|
-
comments = comments.filter(def(comment):
|
|
37
|
+
comments = comments.filter(def (comment):
|
|
38
38
|
return c.test(comment.value)
|
|
39
39
|
)
|
|
40
|
-
elif jstype(c) is
|
|
41
|
-
comments = comments.filter(def(comment):
|
|
40
|
+
elif jstype(c) is 'function':
|
|
41
|
+
comments = comments.filter(def (comment):
|
|
42
42
|
return c(self, comment)
|
|
43
43
|
)
|
|
44
44
|
|
|
@@ -7,12 +7,13 @@ from output.statements import print_bracketed
|
|
|
7
7
|
|
|
8
8
|
def print_try(self, output):
|
|
9
9
|
else_var_name = None
|
|
10
|
+
|
|
10
11
|
def update_output_var(output):
|
|
11
12
|
output.indent(), output.assign(else_var_name), output.print('true'), output.end_statement()
|
|
12
13
|
if self.belse:
|
|
13
14
|
else_var_name = output.new_try_else_counter()
|
|
14
15
|
output.assign('var ' + else_var_name), output.print('false'), output.end_statement(), output.indent()
|
|
15
|
-
output.print(
|
|
16
|
+
output.print('try')
|
|
16
17
|
output.space()
|
|
17
18
|
print_bracketed(self, output, False, None, None, update_output_var if else_var_name else None)
|
|
18
19
|
if self.bcatch:
|
|
@@ -28,35 +29,33 @@ def print_try(self, output):
|
|
|
28
29
|
|
|
29
30
|
|
|
30
31
|
def print_catch(self, output):
|
|
31
|
-
output.print(
|
|
32
|
+
output.print('catch')
|
|
32
33
|
output.space()
|
|
33
|
-
output.with_parens(def():
|
|
34
|
-
output.print(
|
|
34
|
+
output.with_parens(def ():
|
|
35
|
+
output.print('ρσ_Exception')
|
|
35
36
|
)
|
|
36
37
|
output.space()
|
|
37
|
-
output.with_block(def():
|
|
38
|
+
output.with_block(def ():
|
|
38
39
|
output.indent()
|
|
39
40
|
output.spaced('ρσ_last_exception', '=', 'ρσ_Exception'), output.end_statement()
|
|
40
41
|
output.indent()
|
|
41
42
|
no_default = True
|
|
42
43
|
for i, exception in enumerate(self.body):
|
|
43
44
|
if i:
|
|
44
|
-
output.print(
|
|
45
|
-
|
|
45
|
+
output.print('else ')
|
|
46
46
|
if exception.errors.length:
|
|
47
|
-
output.print(
|
|
47
|
+
output.print('if')
|
|
48
48
|
output.space()
|
|
49
|
-
output.with_parens(def():
|
|
49
|
+
output.with_parens(def ():
|
|
50
50
|
for i, err in enumerate(exception.errors):
|
|
51
51
|
if i:
|
|
52
52
|
output.newline()
|
|
53
53
|
output.indent()
|
|
54
|
-
output.print(
|
|
54
|
+
output.print('||')
|
|
55
55
|
output.space()
|
|
56
|
-
|
|
57
|
-
output.print("ρσ_Exception")
|
|
56
|
+
output.print('ρσ_Exception')
|
|
58
57
|
output.space()
|
|
59
|
-
output.print(
|
|
58
|
+
output.print('instanceof')
|
|
60
59
|
output.space()
|
|
61
60
|
if err.name is 'Exception':
|
|
62
61
|
output.print('Error')
|
|
@@ -69,13 +68,13 @@ def print_catch(self, output):
|
|
|
69
68
|
print_bracketed(exception, output, True)
|
|
70
69
|
output.space()
|
|
71
70
|
if no_default:
|
|
72
|
-
output.print(
|
|
71
|
+
output.print('else')
|
|
73
72
|
output.space()
|
|
74
|
-
output.with_block(def():
|
|
73
|
+
output.with_block(def ():
|
|
75
74
|
output.indent()
|
|
76
|
-
output.print(
|
|
75
|
+
output.print('throw')
|
|
77
76
|
output.space()
|
|
78
|
-
output.print(
|
|
77
|
+
output.print('ρσ_Exception')
|
|
79
78
|
output.semicolon()
|
|
80
79
|
output.newline()
|
|
81
80
|
)
|
|
@@ -84,13 +83,13 @@ def print_catch(self, output):
|
|
|
84
83
|
|
|
85
84
|
|
|
86
85
|
def print_finally(self, output, belse, else_var_name):
|
|
87
|
-
output.print(
|
|
86
|
+
output.print('finally')
|
|
88
87
|
output.space()
|
|
89
88
|
if else_var_name:
|
|
90
|
-
output.with_block(def():
|
|
91
|
-
output.indent(), output.print(
|
|
89
|
+
output.with_block(def ():
|
|
90
|
+
output.indent(), output.print('try')
|
|
92
91
|
output.space()
|
|
93
|
-
output.with_block(def():
|
|
92
|
+
output.with_block(def ():
|
|
94
93
|
print_else(belse, else_var_name, output)
|
|
95
94
|
)
|
|
96
95
|
print_finally(self, output)
|