yarp 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -1
- data/CONTRIBUTING.md +7 -0
- data/config.yml +154 -43
- data/docs/configuration.md +0 -1
- data/docs/mapping.md +91 -91
- data/docs/serialization.md +23 -20
- data/ext/yarp/api_node.c +1074 -391
- data/ext/yarp/extension.c +1 -1
- data/ext/yarp/extension.h +2 -2
- data/include/yarp/ast.h +501 -301
- data/include/yarp/diagnostic.h +198 -1
- data/include/yarp/node.h +0 -4
- data/include/yarp/util/yp_char.h +1 -1
- data/include/yarp/util/yp_constant_pool.h +11 -4
- data/include/yarp/version.h +2 -2
- data/lib/yarp/desugar_visitor.rb +19 -19
- data/lib/yarp/mutation_visitor.rb +22 -12
- data/lib/yarp/node.rb +2883 -293
- data/lib/yarp/parse_result/comments.rb +172 -0
- data/lib/yarp/parse_result/newlines.rb +60 -0
- data/lib/yarp/pattern.rb +239 -0
- data/lib/yarp/serialize.rb +152 -129
- data/lib/yarp.rb +104 -44
- data/src/diagnostic.c +254 -2
- data/src/node.c +901 -868
- data/src/prettyprint.c +380 -186
- data/src/serialize.c +325 -170
- data/src/unescape.c +20 -20
- data/src/util/yp_char.c +2 -7
- data/src/util/yp_constant_pool.c +41 -8
- data/src/util/yp_newline_list.c +5 -1
- data/src/util/yp_string_list.c +4 -1
- data/src/yarp.c +946 -818
- data/yarp.gemspec +4 -1
- metadata +6 -3
data/lib/yarp/serialize.rb
CHANGED
@@ -21,11 +21,17 @@ end
|
|
21
21
|
module YARP
|
22
22
|
module Serialize
|
23
23
|
MAJOR_VERSION = 0
|
24
|
-
MINOR_VERSION =
|
24
|
+
MINOR_VERSION = 11
|
25
25
|
PATCH_VERSION = 0
|
26
26
|
|
27
27
|
def self.load(input, serialized)
|
28
|
-
|
28
|
+
input = input.dup
|
29
|
+
source = Source.new(input)
|
30
|
+
loader = Loader.new(source, serialized)
|
31
|
+
result = loader.load_result
|
32
|
+
|
33
|
+
input.force_encoding(loader.encoding)
|
34
|
+
result
|
29
35
|
end
|
30
36
|
|
31
37
|
def self.load_tokens(source, serialized)
|
@@ -159,23 +165,36 @@ module YARP
|
|
159
165
|
load_location if io.getbyte != 0
|
160
166
|
end
|
161
167
|
|
162
|
-
def load_constant
|
163
|
-
index = load_varint - 1
|
168
|
+
def load_constant(index)
|
164
169
|
constant = constant_pool[index]
|
165
170
|
|
166
171
|
unless constant
|
167
172
|
offset = constant_pool_offset + index * 8
|
168
|
-
|
169
173
|
start = serialized.unpack1("L", offset: offset)
|
170
174
|
length = serialized.unpack1("L", offset: offset + 4)
|
171
175
|
|
172
|
-
constant =
|
176
|
+
constant =
|
177
|
+
if start.nobits?(1 << 31)
|
178
|
+
input.byteslice(start, length).to_sym
|
179
|
+
else
|
180
|
+
serialized.byteslice(start & ((1 << 31) - 1), length).to_sym
|
181
|
+
end
|
182
|
+
|
173
183
|
constant_pool[index] = constant
|
174
184
|
end
|
175
185
|
|
176
186
|
constant
|
177
187
|
end
|
178
188
|
|
189
|
+
def load_required_constant
|
190
|
+
load_constant(load_varint - 1)
|
191
|
+
end
|
192
|
+
|
193
|
+
def load_optional_constant
|
194
|
+
index = load_varint
|
195
|
+
load_constant(index - 1) if index != 0
|
196
|
+
end
|
197
|
+
|
179
198
|
def load_node
|
180
199
|
type = io.getbyte
|
181
200
|
location = load_location
|
@@ -204,251 +223,255 @@ module YARP
|
|
204
223
|
when 11 then
|
205
224
|
BlockArgumentNode.new(load_optional_node, load_location, location)
|
206
225
|
when 12 then
|
207
|
-
|
226
|
+
BlockLocalVariableNode.new(load_required_constant, location)
|
208
227
|
when 13 then
|
209
|
-
|
228
|
+
BlockNode.new(Array.new(load_varint) { load_required_constant }, load_optional_node, load_optional_node, load_location, load_location, location)
|
210
229
|
when 14 then
|
211
|
-
|
230
|
+
BlockParameterNode.new(load_optional_constant, load_optional_location, load_location, location)
|
212
231
|
when 15 then
|
213
|
-
|
232
|
+
BlockParametersNode.new(load_optional_node, Array.new(load_varint) { load_node }, load_optional_location, load_optional_location, location)
|
214
233
|
when 16 then
|
215
|
-
|
234
|
+
BreakNode.new(load_optional_node, load_location, location)
|
216
235
|
when 17 then
|
217
|
-
|
236
|
+
CallAndWriteNode.new(load_optional_node, load_optional_location, load_optional_location, load_optional_location, load_optional_node, load_optional_location, load_varint, load_string, load_string, load_location, load_node, location)
|
218
237
|
when 18 then
|
219
|
-
|
238
|
+
CallNode.new(load_optional_node, load_optional_location, load_optional_location, load_optional_location, load_optional_node, load_optional_location, load_optional_node, load_varint, load_string, location)
|
220
239
|
when 19 then
|
221
|
-
CallOperatorWriteNode.new(
|
240
|
+
CallOperatorWriteNode.new(load_optional_node, load_optional_location, load_optional_location, load_optional_location, load_optional_node, load_optional_location, load_varint, load_string, load_string, load_required_constant, load_location, load_node, location)
|
222
241
|
when 20 then
|
223
|
-
|
242
|
+
CallOrWriteNode.new(load_optional_node, load_optional_location, load_optional_location, load_optional_location, load_optional_node, load_optional_location, load_varint, load_string, load_string, load_location, load_node, location)
|
224
243
|
when 21 then
|
225
|
-
|
244
|
+
CapturePatternNode.new(load_node, load_node, load_location, location)
|
226
245
|
when 22 then
|
227
|
-
|
246
|
+
CaseNode.new(load_optional_node, Array.new(load_varint) { load_node }, load_optional_node, load_location, load_location, location)
|
228
247
|
when 23 then
|
229
|
-
|
248
|
+
ClassNode.new(Array.new(load_varint) { load_required_constant }, load_location, load_node, load_optional_location, load_optional_node, load_optional_node, load_location, load_required_constant, location)
|
230
249
|
when 24 then
|
231
|
-
|
250
|
+
ClassVariableAndWriteNode.new(load_required_constant, load_location, load_location, load_node, location)
|
232
251
|
when 25 then
|
233
|
-
|
252
|
+
ClassVariableOperatorWriteNode.new(load_required_constant, load_location, load_location, load_node, load_required_constant, location)
|
234
253
|
when 26 then
|
235
|
-
|
254
|
+
ClassVariableOrWriteNode.new(load_required_constant, load_location, load_location, load_node, location)
|
236
255
|
when 27 then
|
237
|
-
|
256
|
+
ClassVariableReadNode.new(load_required_constant, location)
|
238
257
|
when 28 then
|
239
|
-
|
258
|
+
ClassVariableTargetNode.new(load_required_constant, location)
|
240
259
|
when 29 then
|
241
|
-
|
260
|
+
ClassVariableWriteNode.new(load_required_constant, load_location, load_node, load_optional_location, location)
|
242
261
|
when 30 then
|
243
|
-
|
262
|
+
ConstantAndWriteNode.new(load_required_constant, load_location, load_location, load_node, location)
|
244
263
|
when 31 then
|
245
|
-
|
264
|
+
ConstantOperatorWriteNode.new(load_required_constant, load_location, load_location, load_node, load_required_constant, location)
|
246
265
|
when 32 then
|
247
|
-
|
266
|
+
ConstantOrWriteNode.new(load_required_constant, load_location, load_location, load_node, location)
|
248
267
|
when 33 then
|
249
|
-
|
268
|
+
ConstantPathAndWriteNode.new(load_node, load_location, load_node, location)
|
250
269
|
when 34 then
|
251
|
-
|
270
|
+
ConstantPathNode.new(load_optional_node, load_node, load_location, location)
|
252
271
|
when 35 then
|
253
|
-
|
272
|
+
ConstantPathOperatorWriteNode.new(load_node, load_location, load_node, load_required_constant, location)
|
254
273
|
when 36 then
|
255
|
-
|
274
|
+
ConstantPathOrWriteNode.new(load_node, load_location, load_node, location)
|
256
275
|
when 37 then
|
257
|
-
|
276
|
+
ConstantPathTargetNode.new(load_optional_node, load_node, load_location, location)
|
258
277
|
when 38 then
|
259
|
-
|
278
|
+
ConstantPathWriteNode.new(load_node, load_location, load_node, location)
|
260
279
|
when 39 then
|
261
|
-
|
280
|
+
ConstantReadNode.new(load_required_constant, location)
|
262
281
|
when 40 then
|
263
|
-
|
282
|
+
ConstantTargetNode.new(load_required_constant, location)
|
264
283
|
when 41 then
|
265
|
-
|
266
|
-
DefNode.new(load_location, load_optional_node, load_optional_node, load_optional_node, Array.new(load_varint) { load_constant }, load_location, load_optional_location, load_optional_location, load_optional_location, load_optional_location, load_optional_location, location)
|
284
|
+
ConstantWriteNode.new(load_required_constant, load_location, load_node, load_location, location)
|
267
285
|
when 42 then
|
268
|
-
|
286
|
+
load_serialized_length
|
287
|
+
DefNode.new(load_required_constant, load_location, load_optional_node, load_optional_node, load_optional_node, Array.new(load_varint) { load_required_constant }, load_location, load_optional_location, load_optional_location, load_optional_location, load_optional_location, load_optional_location, location)
|
269
288
|
when 43 then
|
270
|
-
|
289
|
+
DefinedNode.new(load_optional_location, load_node, load_optional_location, load_location, location)
|
271
290
|
when 44 then
|
272
|
-
|
291
|
+
ElseNode.new(load_location, load_optional_node, load_optional_location, location)
|
273
292
|
when 45 then
|
274
|
-
|
293
|
+
EmbeddedStatementsNode.new(load_location, load_optional_node, load_location, location)
|
275
294
|
when 46 then
|
276
|
-
|
295
|
+
EmbeddedVariableNode.new(load_location, load_node, location)
|
277
296
|
when 47 then
|
278
|
-
|
297
|
+
EnsureNode.new(load_location, load_optional_node, load_location, location)
|
279
298
|
when 48 then
|
280
|
-
|
299
|
+
FalseNode.new(location)
|
281
300
|
when 49 then
|
282
|
-
|
301
|
+
FindPatternNode.new(load_optional_node, load_node, Array.new(load_varint) { load_node }, load_node, load_optional_location, load_optional_location, location)
|
283
302
|
when 50 then
|
284
|
-
|
303
|
+
FlipFlopNode.new(load_optional_node, load_optional_node, load_location, load_varint, location)
|
285
304
|
when 51 then
|
286
|
-
|
305
|
+
FloatNode.new(location)
|
287
306
|
when 52 then
|
288
|
-
|
307
|
+
ForNode.new(load_node, load_node, load_optional_node, load_location, load_location, load_optional_location, load_location, location)
|
289
308
|
when 53 then
|
290
|
-
|
309
|
+
ForwardingArgumentsNode.new(location)
|
291
310
|
when 54 then
|
292
|
-
|
311
|
+
ForwardingParameterNode.new(location)
|
293
312
|
when 55 then
|
294
|
-
|
313
|
+
ForwardingSuperNode.new(load_optional_node, location)
|
295
314
|
when 56 then
|
296
|
-
|
315
|
+
GlobalVariableAndWriteNode.new(load_required_constant, load_location, load_location, load_node, location)
|
297
316
|
when 57 then
|
298
|
-
|
317
|
+
GlobalVariableOperatorWriteNode.new(load_required_constant, load_location, load_location, load_node, load_required_constant, location)
|
299
318
|
when 58 then
|
300
|
-
|
319
|
+
GlobalVariableOrWriteNode.new(load_required_constant, load_location, load_location, load_node, location)
|
301
320
|
when 59 then
|
302
|
-
|
321
|
+
GlobalVariableReadNode.new(load_required_constant, location)
|
303
322
|
when 60 then
|
304
|
-
|
323
|
+
GlobalVariableTargetNode.new(load_required_constant, location)
|
305
324
|
when 61 then
|
306
|
-
|
325
|
+
GlobalVariableWriteNode.new(load_required_constant, load_location, load_node, load_location, location)
|
307
326
|
when 62 then
|
308
|
-
|
327
|
+
HashNode.new(load_location, Array.new(load_varint) { load_node }, load_location, location)
|
309
328
|
when 63 then
|
310
|
-
|
329
|
+
HashPatternNode.new(load_optional_node, Array.new(load_varint) { load_node }, load_optional_node, load_optional_location, load_optional_location, location)
|
311
330
|
when 64 then
|
312
|
-
|
331
|
+
IfNode.new(load_optional_location, load_node, load_optional_node, load_optional_node, load_optional_location, location)
|
313
332
|
when 65 then
|
314
|
-
|
333
|
+
ImaginaryNode.new(load_node, location)
|
315
334
|
when 66 then
|
316
|
-
|
335
|
+
InNode.new(load_node, load_optional_node, load_location, load_optional_location, location)
|
317
336
|
when 67 then
|
318
|
-
|
337
|
+
InstanceVariableAndWriteNode.new(load_required_constant, load_location, load_location, load_node, location)
|
319
338
|
when 68 then
|
320
|
-
|
339
|
+
InstanceVariableOperatorWriteNode.new(load_required_constant, load_location, load_location, load_node, load_required_constant, location)
|
321
340
|
when 69 then
|
322
|
-
|
341
|
+
InstanceVariableOrWriteNode.new(load_required_constant, load_location, load_location, load_node, location)
|
323
342
|
when 70 then
|
324
|
-
|
343
|
+
InstanceVariableReadNode.new(load_required_constant, location)
|
325
344
|
when 71 then
|
326
|
-
|
345
|
+
InstanceVariableTargetNode.new(load_required_constant, location)
|
327
346
|
when 72 then
|
328
|
-
|
347
|
+
InstanceVariableWriteNode.new(load_required_constant, load_location, load_node, load_location, location)
|
329
348
|
when 73 then
|
330
|
-
|
349
|
+
IntegerNode.new(location)
|
331
350
|
when 74 then
|
332
|
-
|
351
|
+
InterpolatedRegularExpressionNode.new(load_location, Array.new(load_varint) { load_node }, load_location, load_varint, location)
|
333
352
|
when 75 then
|
334
|
-
|
353
|
+
InterpolatedStringNode.new(load_optional_location, Array.new(load_varint) { load_node }, load_optional_location, location)
|
335
354
|
when 76 then
|
336
|
-
|
355
|
+
InterpolatedSymbolNode.new(load_optional_location, Array.new(load_varint) { load_node }, load_optional_location, location)
|
337
356
|
when 77 then
|
338
|
-
|
357
|
+
InterpolatedXStringNode.new(load_location, Array.new(load_varint) { load_node }, load_location, location)
|
339
358
|
when 78 then
|
340
|
-
|
359
|
+
KeywordHashNode.new(Array.new(load_varint) { load_node }, location)
|
341
360
|
when 79 then
|
342
|
-
|
361
|
+
KeywordParameterNode.new(load_required_constant, load_location, load_optional_node, location)
|
343
362
|
when 80 then
|
344
|
-
|
363
|
+
KeywordRestParameterNode.new(load_optional_constant, load_optional_location, load_location, location)
|
345
364
|
when 81 then
|
346
|
-
|
365
|
+
LambdaNode.new(Array.new(load_varint) { load_required_constant }, load_location, load_location, load_location, load_optional_node, load_optional_node, location)
|
347
366
|
when 82 then
|
348
|
-
|
367
|
+
LocalVariableAndWriteNode.new(load_location, load_location, load_node, load_required_constant, load_varint, location)
|
349
368
|
when 83 then
|
350
|
-
|
369
|
+
LocalVariableOperatorWriteNode.new(load_location, load_location, load_node, load_required_constant, load_required_constant, load_varint, location)
|
351
370
|
when 84 then
|
352
|
-
|
371
|
+
LocalVariableOrWriteNode.new(load_location, load_location, load_node, load_required_constant, load_varint, location)
|
353
372
|
when 85 then
|
354
|
-
|
373
|
+
LocalVariableReadNode.new(load_required_constant, load_varint, location)
|
355
374
|
when 86 then
|
356
|
-
|
375
|
+
LocalVariableTargetNode.new(load_required_constant, load_varint, location)
|
357
376
|
when 87 then
|
358
|
-
|
377
|
+
LocalVariableWriteNode.new(load_required_constant, load_varint, load_location, load_node, load_location, location)
|
359
378
|
when 88 then
|
360
|
-
|
379
|
+
MatchPredicateNode.new(load_node, load_node, load_location, location)
|
361
380
|
when 89 then
|
362
|
-
|
381
|
+
MatchRequiredNode.new(load_node, load_node, load_location, location)
|
363
382
|
when 90 then
|
364
|
-
|
383
|
+
MissingNode.new(location)
|
365
384
|
when 91 then
|
366
|
-
|
385
|
+
ModuleNode.new(Array.new(load_varint) { load_required_constant }, load_location, load_node, load_optional_node, load_location, load_required_constant, location)
|
367
386
|
when 92 then
|
368
|
-
|
387
|
+
MultiTargetNode.new(Array.new(load_varint) { load_node }, load_optional_location, load_optional_location, location)
|
369
388
|
when 93 then
|
370
|
-
|
389
|
+
MultiWriteNode.new(Array.new(load_varint) { load_node }, load_optional_location, load_optional_location, load_location, load_node, location)
|
371
390
|
when 94 then
|
372
|
-
|
391
|
+
NextNode.new(load_optional_node, load_location, location)
|
373
392
|
when 95 then
|
374
|
-
|
393
|
+
NilNode.new(location)
|
375
394
|
when 96 then
|
376
|
-
|
395
|
+
NoKeywordsParameterNode.new(load_location, load_location, location)
|
377
396
|
when 97 then
|
378
|
-
|
397
|
+
NumberedReferenceReadNode.new(load_varint, location)
|
379
398
|
when 98 then
|
380
|
-
|
399
|
+
OptionalParameterNode.new(load_required_constant, load_location, load_location, load_node, location)
|
381
400
|
when 99 then
|
382
|
-
|
401
|
+
OrNode.new(load_node, load_node, load_location, location)
|
383
402
|
when 100 then
|
384
|
-
|
403
|
+
ParametersNode.new(Array.new(load_varint) { load_node }, Array.new(load_varint) { load_node }, Array.new(load_varint) { load_node }, load_optional_node, Array.new(load_varint) { load_node }, load_optional_node, load_optional_node, location)
|
385
404
|
when 101 then
|
386
|
-
|
405
|
+
ParenthesesNode.new(load_optional_node, load_location, load_location, location)
|
387
406
|
when 102 then
|
388
|
-
|
407
|
+
PinnedExpressionNode.new(load_node, load_location, load_location, load_location, location)
|
389
408
|
when 103 then
|
390
|
-
|
409
|
+
PinnedVariableNode.new(load_node, load_location, location)
|
391
410
|
when 104 then
|
392
|
-
|
411
|
+
PostExecutionNode.new(load_optional_node, load_location, load_location, load_location, location)
|
393
412
|
when 105 then
|
394
|
-
|
413
|
+
PreExecutionNode.new(load_optional_node, load_location, load_location, load_location, location)
|
395
414
|
when 106 then
|
396
|
-
|
415
|
+
ProgramNode.new(Array.new(load_varint) { load_required_constant }, load_node, location)
|
397
416
|
when 107 then
|
398
|
-
|
417
|
+
RangeNode.new(load_optional_node, load_optional_node, load_location, load_varint, location)
|
399
418
|
when 108 then
|
400
|
-
|
419
|
+
RationalNode.new(load_node, location)
|
401
420
|
when 109 then
|
402
|
-
|
421
|
+
RedoNode.new(location)
|
403
422
|
when 110 then
|
404
|
-
|
423
|
+
RegularExpressionNode.new(load_location, load_location, load_location, load_string, load_varint, location)
|
405
424
|
when 111 then
|
406
|
-
|
425
|
+
RequiredDestructuredParameterNode.new(Array.new(load_varint) { load_node }, load_location, load_location, location)
|
407
426
|
when 112 then
|
408
|
-
|
427
|
+
RequiredParameterNode.new(load_required_constant, location)
|
409
428
|
when 113 then
|
410
|
-
|
429
|
+
RescueModifierNode.new(load_node, load_location, load_node, location)
|
411
430
|
when 114 then
|
412
|
-
|
431
|
+
RescueNode.new(load_location, Array.new(load_varint) { load_node }, load_optional_location, load_optional_node, load_optional_node, load_optional_node, location)
|
413
432
|
when 115 then
|
414
|
-
|
433
|
+
RestParameterNode.new(load_optional_constant, load_optional_location, load_location, location)
|
415
434
|
when 116 then
|
416
|
-
|
435
|
+
RetryNode.new(location)
|
417
436
|
when 117 then
|
418
|
-
|
437
|
+
ReturnNode.new(load_location, load_optional_node, location)
|
419
438
|
when 118 then
|
420
|
-
|
439
|
+
SelfNode.new(location)
|
421
440
|
when 119 then
|
422
|
-
|
441
|
+
SingletonClassNode.new(Array.new(load_varint) { load_required_constant }, load_location, load_location, load_node, load_optional_node, load_location, location)
|
423
442
|
when 120 then
|
424
|
-
|
443
|
+
SourceEncodingNode.new(location)
|
425
444
|
when 121 then
|
426
|
-
|
445
|
+
SourceFileNode.new(load_string, location)
|
427
446
|
when 122 then
|
428
|
-
|
447
|
+
SourceLineNode.new(location)
|
429
448
|
when 123 then
|
430
|
-
|
449
|
+
SplatNode.new(load_location, load_optional_node, location)
|
431
450
|
when 124 then
|
432
|
-
|
451
|
+
StatementsNode.new(Array.new(load_varint) { load_node }, location)
|
433
452
|
when 125 then
|
434
|
-
|
453
|
+
StringConcatNode.new(load_node, load_node, location)
|
435
454
|
when 126 then
|
436
|
-
|
455
|
+
StringNode.new(load_optional_location, load_location, load_optional_location, load_string, location)
|
437
456
|
when 127 then
|
438
|
-
|
457
|
+
SuperNode.new(load_location, load_optional_location, load_optional_node, load_optional_location, load_optional_node, location)
|
439
458
|
when 128 then
|
440
|
-
|
459
|
+
SymbolNode.new(load_optional_location, load_optional_location, load_optional_location, load_string, location)
|
441
460
|
when 129 then
|
442
|
-
|
461
|
+
TrueNode.new(location)
|
443
462
|
when 130 then
|
444
|
-
|
463
|
+
UndefNode.new(Array.new(load_varint) { load_node }, load_location, location)
|
445
464
|
when 131 then
|
446
|
-
|
465
|
+
UnlessNode.new(load_location, load_node, load_optional_node, load_optional_node, load_optional_location, location)
|
447
466
|
when 132 then
|
448
|
-
|
467
|
+
UntilNode.new(load_location, load_optional_location, load_node, load_optional_node, load_varint, location)
|
449
468
|
when 133 then
|
450
|
-
|
469
|
+
WhenNode.new(load_location, Array.new(load_varint) { load_node }, load_optional_node, location)
|
451
470
|
when 134 then
|
471
|
+
WhileNode.new(load_location, load_optional_location, load_node, load_optional_node, load_varint, location)
|
472
|
+
when 135 then
|
473
|
+
XStringNode.new(load_location, load_location, load_location, load_string, location)
|
474
|
+
when 136 then
|
452
475
|
YieldNode.new(load_location, load_optional_location, load_optional_node, load_optional_location, location)
|
453
476
|
end
|
454
477
|
end
|