syntax_tree 5.0.1 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +4 -0
- data/.github/workflows/auto-merge.yml +1 -1
- data/.github/workflows/main.yml +5 -2
- data/.gitmodules +6 -0
- data/.rubocop.yml +58 -1
- data/CHANGELOG.md +28 -1
- data/Gemfile.lock +12 -12
- data/README.md +5 -5
- data/Rakefile +7 -0
- data/exe/yarv +63 -0
- data/lib/syntax_tree/dsl.rb +1004 -0
- data/lib/syntax_tree/formatter.rb +2 -2
- data/lib/syntax_tree/language_server.rb +2 -0
- data/lib/syntax_tree/node.rb +26 -17
- data/lib/syntax_tree/parser.rb +21 -22
- data/lib/syntax_tree/version.rb +1 -1
- data/lib/syntax_tree/yarv/assembler.rb +459 -0
- data/lib/syntax_tree/yarv/bf.rb +176 -0
- data/lib/syntax_tree/yarv/compiler.rb +2298 -0
- data/lib/syntax_tree/yarv/decompiler.rb +263 -0
- data/lib/syntax_tree/yarv/disassembler.rb +212 -0
- data/lib/syntax_tree/yarv/instruction_sequence.rb +1275 -0
- data/lib/syntax_tree/yarv/instructions.rb +5372 -0
- data/lib/syntax_tree/yarv/legacy.rb +215 -0
- data/lib/syntax_tree/yarv/local_table.rb +89 -0
- data/lib/syntax_tree/yarv/vm.rb +624 -0
- data/lib/syntax_tree/yarv.rb +18 -0
- data/lib/syntax_tree.rb +20 -1
- data/syntax_tree.gemspec +1 -1
- metadata +20 -5
@@ -0,0 +1,1004 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SyntaxTree
|
4
|
+
# This module provides shortcuts for creating AST nodes.
|
5
|
+
module DSL
|
6
|
+
# Create a new BEGINBlock node.
|
7
|
+
def BEGINBlock(lbrace, statements)
|
8
|
+
BEGINBlock.new(
|
9
|
+
lbrace: lbrace,
|
10
|
+
statements: statements,
|
11
|
+
location: Location.default
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Create a new CHAR node.
|
16
|
+
def CHAR(value)
|
17
|
+
CHAR.new(value: value, location: Location.default)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Create a new ENDBlock node.
|
21
|
+
def ENDBlock(lbrace, statements)
|
22
|
+
ENDBlock.new(
|
23
|
+
lbrace: lbrace,
|
24
|
+
statements: statements,
|
25
|
+
location: Location.default
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Create a new EndContent node.
|
30
|
+
def EndContent(value)
|
31
|
+
EndContent.new(value: value, location: Location.default)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Create a new AliasNode node.
|
35
|
+
def AliasNode(left, right)
|
36
|
+
AliasNode.new(left: left, right: right, location: Location.default)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Create a new ARef node.
|
40
|
+
def ARef(collection, index)
|
41
|
+
ARef.new(collection: collection, index: index, location: Location.default)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Create a new ARefField node.
|
45
|
+
def ARefField(collection, index)
|
46
|
+
ARefField.new(
|
47
|
+
collection: collection,
|
48
|
+
index: index,
|
49
|
+
location: Location.default
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Create a new ArgParen node.
|
54
|
+
def ArgParen(arguments)
|
55
|
+
ArgParen.new(arguments: arguments, location: Location.default)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Create a new Args node.
|
59
|
+
def Args(parts)
|
60
|
+
Args.new(parts: parts, location: Location.default)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Create a new ArgBlock node.
|
64
|
+
def ArgBlock(value)
|
65
|
+
ArgBlock.new(value: value, location: Location.default)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Create a new ArgStar node.
|
69
|
+
def ArgStar(value)
|
70
|
+
ArgStar.new(value: value, location: Location.default)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Create a new ArgsForward node.
|
74
|
+
def ArgsForward
|
75
|
+
ArgsForward.new(location: Location.default)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Create a new ArrayLiteral node.
|
79
|
+
def ArrayLiteral(lbracket, contents)
|
80
|
+
ArrayLiteral.new(
|
81
|
+
lbracket: lbracket,
|
82
|
+
contents: contents,
|
83
|
+
location: Location.default
|
84
|
+
)
|
85
|
+
end
|
86
|
+
|
87
|
+
# Create a new AryPtn node.
|
88
|
+
def AryPtn(constant, requireds, rest, posts)
|
89
|
+
AryPtn.new(
|
90
|
+
constant: constant,
|
91
|
+
requireds: requireds,
|
92
|
+
rest: rest,
|
93
|
+
posts: posts,
|
94
|
+
location: Location.default
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Create a new Assign node.
|
99
|
+
def Assign(target, value)
|
100
|
+
Assign.new(target: target, value: value, location: Location.default)
|
101
|
+
end
|
102
|
+
|
103
|
+
# Create a new Assoc node.
|
104
|
+
def Assoc(key, value)
|
105
|
+
Assoc.new(key: key, value: value, location: Location.default)
|
106
|
+
end
|
107
|
+
|
108
|
+
# Create a new AssocSplat node.
|
109
|
+
def AssocSplat(value)
|
110
|
+
AssocSplat.new(value: value, location: Location.default)
|
111
|
+
end
|
112
|
+
|
113
|
+
# Create a new Backref node.
|
114
|
+
def Backref(value)
|
115
|
+
Backref.new(value: value, location: Location.default)
|
116
|
+
end
|
117
|
+
|
118
|
+
# Create a new Backtick node.
|
119
|
+
def Backtick(value)
|
120
|
+
Backtick.new(value: value, location: Location.default)
|
121
|
+
end
|
122
|
+
|
123
|
+
# Create a new BareAssocHash node.
|
124
|
+
def BareAssocHash(assocs)
|
125
|
+
BareAssocHash.new(assocs: assocs, location: Location.default)
|
126
|
+
end
|
127
|
+
|
128
|
+
# Create a new Begin node.
|
129
|
+
def Begin(bodystmt)
|
130
|
+
Begin.new(bodystmt: bodystmt, location: Location.default)
|
131
|
+
end
|
132
|
+
|
133
|
+
# Create a new PinnedBegin node.
|
134
|
+
def PinnedBegin(statement)
|
135
|
+
PinnedBegin.new(statement: statement, location: Location.default)
|
136
|
+
end
|
137
|
+
|
138
|
+
# Create a new Binary node.
|
139
|
+
def Binary(left, operator, right)
|
140
|
+
Binary.new(
|
141
|
+
left: left,
|
142
|
+
operator: operator,
|
143
|
+
right: right,
|
144
|
+
location: Location.default
|
145
|
+
)
|
146
|
+
end
|
147
|
+
|
148
|
+
# Create a new BlockVar node.
|
149
|
+
def BlockVar(params, locals)
|
150
|
+
BlockVar.new(params: params, locals: locals, location: Location.default)
|
151
|
+
end
|
152
|
+
|
153
|
+
# Create a new BlockArg node.
|
154
|
+
def BlockArg(name)
|
155
|
+
BlockArg.new(name: name, location: Location.default)
|
156
|
+
end
|
157
|
+
|
158
|
+
# Create a new BodyStmt node.
|
159
|
+
def BodyStmt(
|
160
|
+
statements,
|
161
|
+
rescue_clause,
|
162
|
+
else_keyword,
|
163
|
+
else_clause,
|
164
|
+
ensure_clause
|
165
|
+
)
|
166
|
+
BodyStmt.new(
|
167
|
+
statements: statements,
|
168
|
+
rescue_clause: rescue_clause,
|
169
|
+
else_keyword: else_keyword,
|
170
|
+
else_clause: else_clause,
|
171
|
+
ensure_clause: ensure_clause,
|
172
|
+
location: Location.default
|
173
|
+
)
|
174
|
+
end
|
175
|
+
|
176
|
+
# Create a new Break node.
|
177
|
+
def Break(arguments)
|
178
|
+
Break.new(arguments: arguments, location: Location.default)
|
179
|
+
end
|
180
|
+
|
181
|
+
# Create a new CallNode node.
|
182
|
+
def CallNode(receiver, operator, message, arguments)
|
183
|
+
CallNode.new(
|
184
|
+
receiver: receiver,
|
185
|
+
operator: operator,
|
186
|
+
message: message,
|
187
|
+
arguments: arguments,
|
188
|
+
location: Location.default
|
189
|
+
)
|
190
|
+
end
|
191
|
+
|
192
|
+
# Create a new Case node.
|
193
|
+
def Case(keyword, value, consequent)
|
194
|
+
Case.new(
|
195
|
+
keyword: keyword,
|
196
|
+
value: value,
|
197
|
+
consequent: consequent,
|
198
|
+
location: Location.default
|
199
|
+
)
|
200
|
+
end
|
201
|
+
|
202
|
+
# Create a new RAssign node.
|
203
|
+
def RAssign(value, operator, pattern)
|
204
|
+
RAssign.new(
|
205
|
+
value: value,
|
206
|
+
operator: operator,
|
207
|
+
pattern: pattern,
|
208
|
+
location: Location.default
|
209
|
+
)
|
210
|
+
end
|
211
|
+
|
212
|
+
# Create a new ClassDeclaration node.
|
213
|
+
def ClassDeclaration(constant, superclass, bodystmt)
|
214
|
+
ClassDeclaration.new(
|
215
|
+
constant: constant,
|
216
|
+
superclass: superclass,
|
217
|
+
bodystmt: bodystmt,
|
218
|
+
location: Location.default
|
219
|
+
)
|
220
|
+
end
|
221
|
+
|
222
|
+
# Create a new Comma node.
|
223
|
+
def Comma(value)
|
224
|
+
Comma.new(value: value, location: Location.default)
|
225
|
+
end
|
226
|
+
|
227
|
+
# Create a new Command node.
|
228
|
+
def Command(message, arguments, block)
|
229
|
+
Command.new(
|
230
|
+
message: message,
|
231
|
+
arguments: arguments,
|
232
|
+
block: block,
|
233
|
+
location: Location.default
|
234
|
+
)
|
235
|
+
end
|
236
|
+
|
237
|
+
# Create a new CommandCall node.
|
238
|
+
def CommandCall(receiver, operator, message, arguments, block)
|
239
|
+
CommandCall.new(
|
240
|
+
receiver: receiver,
|
241
|
+
operator: operator,
|
242
|
+
message: message,
|
243
|
+
arguments: arguments,
|
244
|
+
block: block,
|
245
|
+
location: Location.default
|
246
|
+
)
|
247
|
+
end
|
248
|
+
|
249
|
+
# Create a new Comment node.
|
250
|
+
def Comment(value, inline)
|
251
|
+
Comment.new(value: value, inline: inline, location: Location.default)
|
252
|
+
end
|
253
|
+
|
254
|
+
# Create a new Const node.
|
255
|
+
def Const(value)
|
256
|
+
Const.new(value: value, location: Location.default)
|
257
|
+
end
|
258
|
+
|
259
|
+
# Create a new ConstPathField node.
|
260
|
+
def ConstPathField(parent, constant)
|
261
|
+
ConstPathField.new(
|
262
|
+
parent: parent,
|
263
|
+
constant: constant,
|
264
|
+
location: Location.default
|
265
|
+
)
|
266
|
+
end
|
267
|
+
|
268
|
+
# Create a new ConstPathRef node.
|
269
|
+
def ConstPathRef(parent, constant)
|
270
|
+
ConstPathRef.new(
|
271
|
+
parent: parent,
|
272
|
+
constant: constant,
|
273
|
+
location: Location.default
|
274
|
+
)
|
275
|
+
end
|
276
|
+
|
277
|
+
# Create a new ConstRef node.
|
278
|
+
def ConstRef(constant)
|
279
|
+
ConstRef.new(constant: constant, location: Location.default)
|
280
|
+
end
|
281
|
+
|
282
|
+
# Create a new CVar node.
|
283
|
+
def CVar(value)
|
284
|
+
CVar.new(value: value, location: Location.default)
|
285
|
+
end
|
286
|
+
|
287
|
+
# Create a new DefNode node.
|
288
|
+
def DefNode(target, operator, name, params, bodystmt)
|
289
|
+
DefNode.new(
|
290
|
+
target: target,
|
291
|
+
operator: operator,
|
292
|
+
name: name,
|
293
|
+
params: params,
|
294
|
+
bodystmt: bodystmt,
|
295
|
+
location: Location.default
|
296
|
+
)
|
297
|
+
end
|
298
|
+
|
299
|
+
# Create a new Defined node.
|
300
|
+
def Defined(value)
|
301
|
+
Defined.new(value: value, location: Location.default)
|
302
|
+
end
|
303
|
+
|
304
|
+
# Create a new BlockNode node.
|
305
|
+
def BlockNode(opening, block_var, bodystmt)
|
306
|
+
BlockNode.new(
|
307
|
+
opening: opening,
|
308
|
+
block_var: block_var,
|
309
|
+
bodystmt: bodystmt,
|
310
|
+
location: Location.default
|
311
|
+
)
|
312
|
+
end
|
313
|
+
|
314
|
+
# Create a new RangeNode node.
|
315
|
+
def RangeNode(left, operator, right)
|
316
|
+
RangeNode.new(
|
317
|
+
left: left,
|
318
|
+
operator: operator,
|
319
|
+
right: right,
|
320
|
+
location: Location.default
|
321
|
+
)
|
322
|
+
end
|
323
|
+
|
324
|
+
# Create a new DynaSymbol node.
|
325
|
+
def DynaSymbol(parts, quote)
|
326
|
+
DynaSymbol.new(parts: parts, quote: quote, location: Location.default)
|
327
|
+
end
|
328
|
+
|
329
|
+
# Create a new Else node.
|
330
|
+
def Else(keyword, statements)
|
331
|
+
Else.new(
|
332
|
+
keyword: keyword,
|
333
|
+
statements: statements,
|
334
|
+
location: Location.default
|
335
|
+
)
|
336
|
+
end
|
337
|
+
|
338
|
+
# Create a new Elsif node.
|
339
|
+
def Elsif(predicate, statements, consequent)
|
340
|
+
Elsif.new(
|
341
|
+
predicate: predicate,
|
342
|
+
statements: statements,
|
343
|
+
consequent: consequent,
|
344
|
+
location: Location.default
|
345
|
+
)
|
346
|
+
end
|
347
|
+
|
348
|
+
# Create a new EmbDoc node.
|
349
|
+
def EmbDoc(value)
|
350
|
+
EmbDoc.new(value: value, location: Location.default)
|
351
|
+
end
|
352
|
+
|
353
|
+
# Create a new EmbExprBeg node.
|
354
|
+
def EmbExprBeg(value)
|
355
|
+
EmbExprBeg.new(value: value, location: Location.default)
|
356
|
+
end
|
357
|
+
|
358
|
+
# Create a new EmbExprEnd node.
|
359
|
+
def EmbExprEnd(value)
|
360
|
+
EmbExprEnd.new(value: value, location: Location.default)
|
361
|
+
end
|
362
|
+
|
363
|
+
# Create a new EmbVar node.
|
364
|
+
def EmbVar(value)
|
365
|
+
EmbVar.new(value: value, location: Location.default)
|
366
|
+
end
|
367
|
+
|
368
|
+
# Create a new Ensure node.
|
369
|
+
def Ensure(keyword, statements)
|
370
|
+
Ensure.new(
|
371
|
+
keyword: keyword,
|
372
|
+
statements: statements,
|
373
|
+
location: Location.default
|
374
|
+
)
|
375
|
+
end
|
376
|
+
|
377
|
+
# Create a new ExcessedComma node.
|
378
|
+
def ExcessedComma(value)
|
379
|
+
ExcessedComma.new(value: value, location: Location.default)
|
380
|
+
end
|
381
|
+
|
382
|
+
# Create a new Field node.
|
383
|
+
def Field(parent, operator, name)
|
384
|
+
Field.new(
|
385
|
+
parent: parent,
|
386
|
+
operator: operator,
|
387
|
+
name: name,
|
388
|
+
location: Location.default
|
389
|
+
)
|
390
|
+
end
|
391
|
+
|
392
|
+
# Create a new FloatLiteral node.
|
393
|
+
def FloatLiteral(value)
|
394
|
+
FloatLiteral.new(value: value, location: Location.default)
|
395
|
+
end
|
396
|
+
|
397
|
+
# Create a new FndPtn node.
|
398
|
+
def FndPtn(constant, left, values, right)
|
399
|
+
FndPtn.new(
|
400
|
+
constant: constant,
|
401
|
+
left: left,
|
402
|
+
values: values,
|
403
|
+
right: right,
|
404
|
+
location: Location.default
|
405
|
+
)
|
406
|
+
end
|
407
|
+
|
408
|
+
# Create a new For node.
|
409
|
+
def For(index, collection, statements)
|
410
|
+
For.new(
|
411
|
+
index: index,
|
412
|
+
collection: collection,
|
413
|
+
statements: statements,
|
414
|
+
location: Location.default
|
415
|
+
)
|
416
|
+
end
|
417
|
+
|
418
|
+
# Create a new GVar node.
|
419
|
+
def GVar(value)
|
420
|
+
GVar.new(value: value, location: Location.default)
|
421
|
+
end
|
422
|
+
|
423
|
+
# Create a new HashLiteral node.
|
424
|
+
def HashLiteral(lbrace, assocs)
|
425
|
+
HashLiteral.new(
|
426
|
+
lbrace: lbrace,
|
427
|
+
assocs: assocs,
|
428
|
+
location: Location.default
|
429
|
+
)
|
430
|
+
end
|
431
|
+
|
432
|
+
# Create a new Heredoc node.
|
433
|
+
def Heredoc(beginning, ending, dedent, parts)
|
434
|
+
Heredoc.new(
|
435
|
+
beginning: beginning,
|
436
|
+
ending: ending,
|
437
|
+
dedent: dedent,
|
438
|
+
parts: parts,
|
439
|
+
location: Location.default
|
440
|
+
)
|
441
|
+
end
|
442
|
+
|
443
|
+
# Create a new HeredocBeg node.
|
444
|
+
def HeredocBeg(value)
|
445
|
+
HeredocBeg.new(value: value, location: Location.default)
|
446
|
+
end
|
447
|
+
|
448
|
+
# Create a new HeredocEnd node.
|
449
|
+
def HeredocEnd(value)
|
450
|
+
HeredocEnd.new(value: value, location: Location.default)
|
451
|
+
end
|
452
|
+
|
453
|
+
# Create a new HshPtn node.
|
454
|
+
def HshPtn(constant, keywords, keyword_rest)
|
455
|
+
HshPtn.new(
|
456
|
+
constant: constant,
|
457
|
+
keywords: keywords,
|
458
|
+
keyword_rest: keyword_rest,
|
459
|
+
location: Location.default
|
460
|
+
)
|
461
|
+
end
|
462
|
+
|
463
|
+
# Create a new Ident node.
|
464
|
+
def Ident(value)
|
465
|
+
Ident.new(value: value, location: Location.default)
|
466
|
+
end
|
467
|
+
|
468
|
+
# Create a new IfNode node.
|
469
|
+
def IfNode(predicate, statements, consequent)
|
470
|
+
IfNode.new(
|
471
|
+
predicate: predicate,
|
472
|
+
statements: statements,
|
473
|
+
consequent: consequent,
|
474
|
+
location: Location.default
|
475
|
+
)
|
476
|
+
end
|
477
|
+
|
478
|
+
# Create a new IfOp node.
|
479
|
+
def IfOp(predicate, truthy, falsy)
|
480
|
+
IfOp.new(
|
481
|
+
predicate: predicate,
|
482
|
+
truthy: truthy,
|
483
|
+
falsy: falsy,
|
484
|
+
location: Location.default
|
485
|
+
)
|
486
|
+
end
|
487
|
+
|
488
|
+
# Create a new Imaginary node.
|
489
|
+
def Imaginary(value)
|
490
|
+
Imaginary.new(value: value, location: Location.default)
|
491
|
+
end
|
492
|
+
|
493
|
+
# Create a new In node.
|
494
|
+
def In(pattern, statements, consequent)
|
495
|
+
In.new(
|
496
|
+
pattern: pattern,
|
497
|
+
statements: statements,
|
498
|
+
consequent: consequent,
|
499
|
+
location: Location.default
|
500
|
+
)
|
501
|
+
end
|
502
|
+
|
503
|
+
# Create a new Int node.
|
504
|
+
def Int(value)
|
505
|
+
Int.new(value: value, location: Location.default)
|
506
|
+
end
|
507
|
+
|
508
|
+
# Create a new IVar node.
|
509
|
+
def IVar(value)
|
510
|
+
IVar.new(value: value, location: Location.default)
|
511
|
+
end
|
512
|
+
|
513
|
+
# Create a new Kw node.
|
514
|
+
def Kw(value)
|
515
|
+
Kw.new(value: value, location: Location.default)
|
516
|
+
end
|
517
|
+
|
518
|
+
# Create a new KwRestParam node.
|
519
|
+
def KwRestParam(name)
|
520
|
+
KwRestParam.new(name: name, location: Location.default)
|
521
|
+
end
|
522
|
+
|
523
|
+
# Create a new Label node.
|
524
|
+
def Label(value)
|
525
|
+
Label.new(value: value, location: Location.default)
|
526
|
+
end
|
527
|
+
|
528
|
+
# Create a new LabelEnd node.
|
529
|
+
def LabelEnd(value)
|
530
|
+
LabelEnd.new(value: value, location: Location.default)
|
531
|
+
end
|
532
|
+
|
533
|
+
# Create a new Lambda node.
|
534
|
+
def Lambda(params, statements)
|
535
|
+
Lambda.new(
|
536
|
+
params: params,
|
537
|
+
statements: statements,
|
538
|
+
location: Location.default
|
539
|
+
)
|
540
|
+
end
|
541
|
+
|
542
|
+
# Create a new LambdaVar node.
|
543
|
+
def LambdaVar(params, locals)
|
544
|
+
LambdaVar.new(params: params, locals: locals, location: Location.default)
|
545
|
+
end
|
546
|
+
|
547
|
+
# Create a new LBrace node.
|
548
|
+
def LBrace(value)
|
549
|
+
LBrace.new(value: value, location: Location.default)
|
550
|
+
end
|
551
|
+
|
552
|
+
# Create a new LBracket node.
|
553
|
+
def LBracket(value)
|
554
|
+
LBracket.new(value: value, location: Location.default)
|
555
|
+
end
|
556
|
+
|
557
|
+
# Create a new LParen node.
|
558
|
+
def LParen(value)
|
559
|
+
LParen.new(value: value, location: Location.default)
|
560
|
+
end
|
561
|
+
|
562
|
+
# Create a new MAssign node.
|
563
|
+
def MAssign(target, value)
|
564
|
+
MAssign.new(target: target, value: value, location: Location.default)
|
565
|
+
end
|
566
|
+
|
567
|
+
# Create a new MethodAddBlock node.
|
568
|
+
def MethodAddBlock(call, block)
|
569
|
+
MethodAddBlock.new(call: call, block: block, location: Location.default)
|
570
|
+
end
|
571
|
+
|
572
|
+
# Create a new MLHS node.
|
573
|
+
def MLHS(parts, comma)
|
574
|
+
MLHS.new(parts: parts, comma: comma, location: Location.default)
|
575
|
+
end
|
576
|
+
|
577
|
+
# Create a new MLHSParen node.
|
578
|
+
def MLHSParen(contents, comma)
|
579
|
+
MLHSParen.new(
|
580
|
+
contents: contents,
|
581
|
+
comma: comma,
|
582
|
+
location: Location.default
|
583
|
+
)
|
584
|
+
end
|
585
|
+
|
586
|
+
# Create a new ModuleDeclaration node.
|
587
|
+
def ModuleDeclaration(constant, bodystmt)
|
588
|
+
ModuleDeclaration.new(
|
589
|
+
constant: constant,
|
590
|
+
bodystmt: bodystmt,
|
591
|
+
location: Location.default
|
592
|
+
)
|
593
|
+
end
|
594
|
+
|
595
|
+
# Create a new MRHS node.
|
596
|
+
def MRHS(parts)
|
597
|
+
MRHS.new(parts: parts, location: Location.default)
|
598
|
+
end
|
599
|
+
|
600
|
+
# Create a new Next node.
|
601
|
+
def Next(arguments)
|
602
|
+
Next.new(arguments: arguments, location: Location.default)
|
603
|
+
end
|
604
|
+
|
605
|
+
# Create a new Op node.
|
606
|
+
def Op(value)
|
607
|
+
Op.new(value: value, location: Location.default)
|
608
|
+
end
|
609
|
+
|
610
|
+
# Create a new OpAssign node.
|
611
|
+
def OpAssign(target, operator, value)
|
612
|
+
OpAssign.new(
|
613
|
+
target: target,
|
614
|
+
operator: operator,
|
615
|
+
value: value,
|
616
|
+
location: Location.default
|
617
|
+
)
|
618
|
+
end
|
619
|
+
|
620
|
+
# Create a new Params node.
|
621
|
+
def Params(requireds, optionals, rest, posts, keywords, keyword_rest, block)
|
622
|
+
Params.new(
|
623
|
+
requireds: requireds,
|
624
|
+
optionals: optionals,
|
625
|
+
rest: rest,
|
626
|
+
posts: posts,
|
627
|
+
keywords: keywords,
|
628
|
+
keyword_rest: keyword_rest,
|
629
|
+
block: block,
|
630
|
+
location: Location.default
|
631
|
+
)
|
632
|
+
end
|
633
|
+
|
634
|
+
# Create a new Paren node.
|
635
|
+
def Paren(lparen, contents)
|
636
|
+
Paren.new(lparen: lparen, contents: contents, location: Location.default)
|
637
|
+
end
|
638
|
+
|
639
|
+
# Create a new Period node.
|
640
|
+
def Period(value)
|
641
|
+
Period.new(value: value, location: Location.default)
|
642
|
+
end
|
643
|
+
|
644
|
+
# Create a new Program node.
|
645
|
+
def Program(statements)
|
646
|
+
Program.new(statements: statements, location: Location.default)
|
647
|
+
end
|
648
|
+
|
649
|
+
# Create a new QSymbols node.
|
650
|
+
def QSymbols(beginning, elements)
|
651
|
+
QSymbols.new(
|
652
|
+
beginning: beginning,
|
653
|
+
elements: elements,
|
654
|
+
location: Location.default
|
655
|
+
)
|
656
|
+
end
|
657
|
+
|
658
|
+
# Create a new QSymbolsBeg node.
|
659
|
+
def QSymbolsBeg(value)
|
660
|
+
QSymbolsBeg.new(value: value, location: Location.default)
|
661
|
+
end
|
662
|
+
|
663
|
+
# Create a new QWords node.
|
664
|
+
def QWords(beginning, elements)
|
665
|
+
QWords.new(
|
666
|
+
beginning: beginning,
|
667
|
+
elements: elements,
|
668
|
+
location: Location.default
|
669
|
+
)
|
670
|
+
end
|
671
|
+
|
672
|
+
# Create a new QWordsBeg node.
|
673
|
+
def QWordsBeg(value)
|
674
|
+
QWordsBeg.new(value: value, location: Location.default)
|
675
|
+
end
|
676
|
+
|
677
|
+
# Create a new RationalLiteral node.
|
678
|
+
def RationalLiteral(value)
|
679
|
+
RationalLiteral.new(value: value, location: Location.default)
|
680
|
+
end
|
681
|
+
|
682
|
+
# Create a new RBrace node.
|
683
|
+
def RBrace(value)
|
684
|
+
RBrace.new(value: value, location: Location.default)
|
685
|
+
end
|
686
|
+
|
687
|
+
# Create a new RBracket node.
|
688
|
+
def RBracket(value)
|
689
|
+
RBracket.new(value: value, location: Location.default)
|
690
|
+
end
|
691
|
+
|
692
|
+
# Create a new Redo node.
|
693
|
+
def Redo
|
694
|
+
Redo.new(location: Location.default)
|
695
|
+
end
|
696
|
+
|
697
|
+
# Create a new RegexpContent node.
|
698
|
+
def RegexpContent(beginning, parts)
|
699
|
+
RegexpContent.new(
|
700
|
+
beginning: beginning,
|
701
|
+
parts: parts,
|
702
|
+
location: Location.default
|
703
|
+
)
|
704
|
+
end
|
705
|
+
|
706
|
+
# Create a new RegexpBeg node.
|
707
|
+
def RegexpBeg(value)
|
708
|
+
RegexpBeg.new(value: value, location: Location.default)
|
709
|
+
end
|
710
|
+
|
711
|
+
# Create a new RegexpEnd node.
|
712
|
+
def RegexpEnd(value)
|
713
|
+
RegexpEnd.new(value: value, location: Location.default)
|
714
|
+
end
|
715
|
+
|
716
|
+
# Create a new RegexpLiteral node.
|
717
|
+
def RegexpLiteral(beginning, ending, parts)
|
718
|
+
RegexpLiteral.new(
|
719
|
+
beginning: beginning,
|
720
|
+
ending: ending,
|
721
|
+
parts: parts,
|
722
|
+
location: Location.default
|
723
|
+
)
|
724
|
+
end
|
725
|
+
|
726
|
+
# Create a new RescueEx node.
|
727
|
+
def RescueEx(exceptions, variable)
|
728
|
+
RescueEx.new(
|
729
|
+
exceptions: exceptions,
|
730
|
+
variable: variable,
|
731
|
+
location: Location.default
|
732
|
+
)
|
733
|
+
end
|
734
|
+
|
735
|
+
# Create a new Rescue node.
|
736
|
+
def Rescue(keyword, exception, statements, consequent)
|
737
|
+
Rescue.new(
|
738
|
+
keyword: keyword,
|
739
|
+
exception: exception,
|
740
|
+
statements: statements,
|
741
|
+
consequent: consequent,
|
742
|
+
location: Location.default
|
743
|
+
)
|
744
|
+
end
|
745
|
+
|
746
|
+
# Create a new RescueMod node.
|
747
|
+
def RescueMod(statement, value)
|
748
|
+
RescueMod.new(
|
749
|
+
statement: statement,
|
750
|
+
value: value,
|
751
|
+
location: Location.default
|
752
|
+
)
|
753
|
+
end
|
754
|
+
|
755
|
+
# Create a new RestParam node.
|
756
|
+
def RestParam(name)
|
757
|
+
RestParam.new(name: name, location: Location.default)
|
758
|
+
end
|
759
|
+
|
760
|
+
# Create a new Retry node.
|
761
|
+
def Retry
|
762
|
+
Retry.new(location: Location.default)
|
763
|
+
end
|
764
|
+
|
765
|
+
# Create a new ReturnNode node.
|
766
|
+
def ReturnNode(arguments)
|
767
|
+
ReturnNode.new(arguments: arguments, location: Location.default)
|
768
|
+
end
|
769
|
+
|
770
|
+
# Create a new RParen node.
|
771
|
+
def RParen(value)
|
772
|
+
RParen.new(value: value, location: Location.default)
|
773
|
+
end
|
774
|
+
|
775
|
+
# Create a new SClass node.
|
776
|
+
def SClass(target, bodystmt)
|
777
|
+
SClass.new(target: target, bodystmt: bodystmt, location: Location.default)
|
778
|
+
end
|
779
|
+
|
780
|
+
# Create a new Statements node.
|
781
|
+
def Statements(body)
|
782
|
+
Statements.new(nil, body: body, location: Location.default)
|
783
|
+
end
|
784
|
+
|
785
|
+
# Create a new StringContent node.
|
786
|
+
def StringContent(parts)
|
787
|
+
StringContent.new(parts: parts, location: Location.default)
|
788
|
+
end
|
789
|
+
|
790
|
+
# Create a new StringConcat node.
|
791
|
+
def StringConcat(left, right)
|
792
|
+
StringConcat.new(left: left, right: right, location: Location.default)
|
793
|
+
end
|
794
|
+
|
795
|
+
# Create a new StringDVar node.
|
796
|
+
def StringDVar(variable)
|
797
|
+
StringDVar.new(variable: variable, location: Location.default)
|
798
|
+
end
|
799
|
+
|
800
|
+
# Create a new StringEmbExpr node.
|
801
|
+
def StringEmbExpr(statements)
|
802
|
+
StringEmbExpr.new(statements: statements, location: Location.default)
|
803
|
+
end
|
804
|
+
|
805
|
+
# Create a new StringLiteral node.
|
806
|
+
def StringLiteral(parts, quote)
|
807
|
+
StringLiteral.new(parts: parts, quote: quote, location: Location.default)
|
808
|
+
end
|
809
|
+
|
810
|
+
# Create a new Super node.
|
811
|
+
def Super(arguments)
|
812
|
+
Super.new(arguments: arguments, location: Location.default)
|
813
|
+
end
|
814
|
+
|
815
|
+
# Create a new SymBeg node.
|
816
|
+
def SymBeg(value)
|
817
|
+
SymBeg.new(value: value, location: Location.default)
|
818
|
+
end
|
819
|
+
|
820
|
+
# Create a new SymbolContent node.
|
821
|
+
def SymbolContent(value)
|
822
|
+
SymbolContent.new(value: value, location: Location.default)
|
823
|
+
end
|
824
|
+
|
825
|
+
# Create a new SymbolLiteral node.
|
826
|
+
def SymbolLiteral(value)
|
827
|
+
SymbolLiteral.new(value: value, location: Location.default)
|
828
|
+
end
|
829
|
+
|
830
|
+
# Create a new Symbols node.
|
831
|
+
def Symbols(beginning, elements)
|
832
|
+
Symbols.new(
|
833
|
+
beginning: beginning,
|
834
|
+
elements: elements,
|
835
|
+
location: Location.default
|
836
|
+
)
|
837
|
+
end
|
838
|
+
|
839
|
+
# Create a new SymbolsBeg node.
|
840
|
+
def SymbolsBeg(value)
|
841
|
+
SymbolsBeg.new(value: value, location: Location.default)
|
842
|
+
end
|
843
|
+
|
844
|
+
# Create a new TLambda node.
|
845
|
+
def TLambda(value)
|
846
|
+
TLambda.new(value: value, location: Location.default)
|
847
|
+
end
|
848
|
+
|
849
|
+
# Create a new TLamBeg node.
|
850
|
+
def TLamBeg(value)
|
851
|
+
TLamBeg.new(value: value, location: Location.default)
|
852
|
+
end
|
853
|
+
|
854
|
+
# Create a new TopConstField node.
|
855
|
+
def TopConstField(constant)
|
856
|
+
TopConstField.new(constant: constant, location: Location.default)
|
857
|
+
end
|
858
|
+
|
859
|
+
# Create a new TopConstRef node.
|
860
|
+
def TopConstRef(constant)
|
861
|
+
TopConstRef.new(constant: constant, location: Location.default)
|
862
|
+
end
|
863
|
+
|
864
|
+
# Create a new TStringBeg node.
|
865
|
+
def TStringBeg(value)
|
866
|
+
TStringBeg.new(value: value, location: Location.default)
|
867
|
+
end
|
868
|
+
|
869
|
+
# Create a new TStringContent node.
|
870
|
+
def TStringContent(value)
|
871
|
+
TStringContent.new(value: value, location: Location.default)
|
872
|
+
end
|
873
|
+
|
874
|
+
# Create a new TStringEnd node.
|
875
|
+
def TStringEnd(value)
|
876
|
+
TStringEnd.new(value: value, location: Location.default)
|
877
|
+
end
|
878
|
+
|
879
|
+
# Create a new Not node.
|
880
|
+
def Not(statement, parentheses)
|
881
|
+
Not.new(
|
882
|
+
statement: statement,
|
883
|
+
parentheses: parentheses,
|
884
|
+
location: Location.default
|
885
|
+
)
|
886
|
+
end
|
887
|
+
|
888
|
+
# Create a new Unary node.
|
889
|
+
def Unary(operator, statement)
|
890
|
+
Unary.new(
|
891
|
+
operator: operator,
|
892
|
+
statement: statement,
|
893
|
+
location: Location.default
|
894
|
+
)
|
895
|
+
end
|
896
|
+
|
897
|
+
# Create a new Undef node.
|
898
|
+
def Undef(symbols)
|
899
|
+
Undef.new(symbols: symbols, location: Location.default)
|
900
|
+
end
|
901
|
+
|
902
|
+
# Create a new UnlessNode node.
|
903
|
+
def UnlessNode(predicate, statements, consequent)
|
904
|
+
UnlessNode.new(
|
905
|
+
predicate: predicate,
|
906
|
+
statements: statements,
|
907
|
+
consequent: consequent,
|
908
|
+
location: Location.default
|
909
|
+
)
|
910
|
+
end
|
911
|
+
|
912
|
+
# Create a new UntilNode node.
|
913
|
+
def UntilNode(predicate, statements)
|
914
|
+
UntilNode.new(
|
915
|
+
predicate: predicate,
|
916
|
+
statements: statements,
|
917
|
+
location: Location.default
|
918
|
+
)
|
919
|
+
end
|
920
|
+
|
921
|
+
# Create a new VarField node.
|
922
|
+
def VarField(value)
|
923
|
+
VarField.new(value: value, location: Location.default)
|
924
|
+
end
|
925
|
+
|
926
|
+
# Create a new VarRef node.
|
927
|
+
def VarRef(value)
|
928
|
+
VarRef.new(value: value, location: Location.default)
|
929
|
+
end
|
930
|
+
|
931
|
+
# Create a new PinnedVarRef node.
|
932
|
+
def PinnedVarRef(value)
|
933
|
+
PinnedVarRef.new(value: value, location: Location.default)
|
934
|
+
end
|
935
|
+
|
936
|
+
# Create a new VCall node.
|
937
|
+
def VCall(value)
|
938
|
+
VCall.new(value: value, location: Location.default)
|
939
|
+
end
|
940
|
+
|
941
|
+
# Create a new VoidStmt node.
|
942
|
+
def VoidStmt
|
943
|
+
VoidStmt.new(location: Location.default)
|
944
|
+
end
|
945
|
+
|
946
|
+
# Create a new When node.
|
947
|
+
def When(arguments, statements, consequent)
|
948
|
+
When.new(
|
949
|
+
arguments: arguments,
|
950
|
+
statements: statements,
|
951
|
+
consequent: consequent,
|
952
|
+
location: Location.default
|
953
|
+
)
|
954
|
+
end
|
955
|
+
|
956
|
+
# Create a new WhileNode node.
|
957
|
+
def WhileNode(predicate, statements)
|
958
|
+
WhileNode.new(
|
959
|
+
predicate: predicate,
|
960
|
+
statements: statements,
|
961
|
+
location: Location.default
|
962
|
+
)
|
963
|
+
end
|
964
|
+
|
965
|
+
# Create a new Word node.
|
966
|
+
def Word(parts)
|
967
|
+
Word.new(parts: parts, location: Location.default)
|
968
|
+
end
|
969
|
+
|
970
|
+
# Create a new Words node.
|
971
|
+
def Words(beginning, elements)
|
972
|
+
Words.new(
|
973
|
+
beginning: beginning,
|
974
|
+
elements: elements,
|
975
|
+
location: Location.default
|
976
|
+
)
|
977
|
+
end
|
978
|
+
|
979
|
+
# Create a new WordsBeg node.
|
980
|
+
def WordsBeg(value)
|
981
|
+
WordsBeg.new(value: value, location: Location.default)
|
982
|
+
end
|
983
|
+
|
984
|
+
# Create a new XString node.
|
985
|
+
def XString(parts)
|
986
|
+
XString.new(parts: parts, location: Location.default)
|
987
|
+
end
|
988
|
+
|
989
|
+
# Create a new XStringLiteral node.
|
990
|
+
def XStringLiteral(parts)
|
991
|
+
XStringLiteral.new(parts: parts, location: Location.default)
|
992
|
+
end
|
993
|
+
|
994
|
+
# Create a new YieldNode node.
|
995
|
+
def YieldNode(arguments)
|
996
|
+
YieldNode.new(arguments: arguments, location: Location.default)
|
997
|
+
end
|
998
|
+
|
999
|
+
# Create a new ZSuper node.
|
1000
|
+
def ZSuper
|
1001
|
+
ZSuper.new(location: Location.default)
|
1002
|
+
end
|
1003
|
+
end
|
1004
|
+
end
|