yarp 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +34 -1
- data/README.md +4 -3
- data/config.yml +332 -52
- data/docs/configuration.md +1 -0
- data/docs/ruby_api.md +2 -0
- data/docs/serialization.md +1 -1
- data/docs/testing.md +2 -2
- data/ext/yarp/api_node.c +703 -136
- data/ext/yarp/extension.c +73 -24
- data/ext/yarp/extension.h +2 -2
- data/include/yarp/ast.h +331 -137
- data/include/yarp/node.h +10 -0
- data/include/yarp/unescape.h +4 -2
- data/include/yarp/util/yp_newline_list.h +3 -0
- data/include/yarp/version.h +2 -2
- data/include/yarp.h +10 -0
- data/lib/yarp/desugar_visitor.rb +267 -0
- data/lib/yarp/ffi.rb +27 -1
- data/lib/yarp/lex_compat.rb +93 -25
- data/lib/yarp/mutation_visitor.rb +683 -0
- data/lib/yarp/node.rb +3042 -508
- data/lib/yarp/serialize.rb +198 -126
- data/lib/yarp.rb +48 -2
- data/src/node.c +421 -185
- data/src/prettyprint.c +262 -80
- data/src/serialize.c +410 -270
- data/src/token_type.c +2 -2
- data/src/unescape.c +69 -51
- data/src/util/yp_newline_list.c +10 -0
- data/src/yarp.c +1208 -458
- data/yarp.gemspec +3 -1
- metadata +4 -2
data/lib/yarp/serialize.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
=begin
|
3
|
-
This file is generated by the
|
3
|
+
This file is generated by the templates/template.rb script and should not be
|
4
4
|
modified manually. See templates/lib/yarp/serialize.rb.erb
|
5
5
|
if you are looking to modify the template
|
6
6
|
=end
|
@@ -21,15 +21,15 @@ end
|
|
21
21
|
module YARP
|
22
22
|
module Serialize
|
23
23
|
MAJOR_VERSION = 0
|
24
|
-
MINOR_VERSION =
|
24
|
+
MINOR_VERSION = 9
|
25
25
|
PATCH_VERSION = 0
|
26
26
|
|
27
27
|
def self.load(input, serialized)
|
28
|
-
Loader.new(Source.new(input), serialized).
|
28
|
+
Loader.new(Source.new(input), serialized).load_result
|
29
29
|
end
|
30
30
|
|
31
31
|
def self.load_tokens(source, serialized)
|
32
|
-
Loader.new(source, serialized).
|
32
|
+
Loader.new(source, serialized).load_tokens_result
|
33
33
|
end
|
34
34
|
|
35
35
|
class Loader
|
@@ -50,6 +50,17 @@ module YARP
|
|
50
50
|
@source = source
|
51
51
|
end
|
52
52
|
|
53
|
+
def load_encoding
|
54
|
+
Encoding.find(io.read(load_varint))
|
55
|
+
end
|
56
|
+
|
57
|
+
def load_metadata
|
58
|
+
comments = load_varint.times.map { Comment.new(Comment::TYPES.fetch(load_varint), load_location) }
|
59
|
+
errors = load_varint.times.map { ParseError.new(load_embedded_string, load_location) }
|
60
|
+
warnings = load_varint.times.map { ParseWarning.new(load_embedded_string, load_location) }
|
61
|
+
[comments, errors, warnings]
|
62
|
+
end
|
63
|
+
|
53
64
|
def load_tokens
|
54
65
|
tokens = []
|
55
66
|
while type = TOKEN_TYPES.fetch(load_varint)
|
@@ -60,32 +71,40 @@ module YARP
|
|
60
71
|
tokens << [YARP::Token.new(type, location.slice, location), lex_state]
|
61
72
|
end
|
62
73
|
|
63
|
-
|
64
|
-
|
65
|
-
warnings = load_varint.times.map { ParseWarning.new(load_string, load_location) }
|
74
|
+
tokens
|
75
|
+
end
|
66
76
|
|
67
|
-
|
77
|
+
def load_tokens_result
|
78
|
+
tokens = load_tokens
|
79
|
+
encoding = load_encoding
|
80
|
+
comments, errors, warnings = load_metadata
|
81
|
+
|
82
|
+
if encoding != @encoding
|
83
|
+
tokens.each { |token,| token.value.force_encoding(encoding) }
|
84
|
+
end
|
68
85
|
|
86
|
+
raise "Expected to consume all bytes while deserializing" unless @io.eof?
|
69
87
|
YARP::ParseResult.new(tokens, comments, errors, warnings, @source)
|
70
88
|
end
|
71
89
|
|
72
|
-
def
|
90
|
+
def load_nodes
|
73
91
|
raise "Invalid serialization" if io.read(4) != "YARP"
|
74
92
|
raise "Invalid serialization" if io.read(3).unpack("C3") != [MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION]
|
75
93
|
|
76
|
-
@encoding =
|
94
|
+
@encoding = load_encoding
|
77
95
|
@input = input.force_encoding(@encoding).freeze
|
78
96
|
|
79
|
-
comments
|
80
|
-
errors = load_varint.times.map { ParseError.new(load_string, load_location) }
|
81
|
-
warnings = load_varint.times.map { ParseWarning.new(load_string, load_location) }
|
97
|
+
comments, errors, warnings = load_metadata
|
82
98
|
|
83
99
|
@constant_pool_offset = io.read(4).unpack1("L")
|
84
100
|
@constant_pool = Array.new(load_varint, nil)
|
85
101
|
|
86
|
-
|
102
|
+
[load_node, comments, errors, warnings]
|
103
|
+
end
|
87
104
|
|
88
|
-
|
105
|
+
def load_result
|
106
|
+
node, comments, errors, warnings = load_nodes
|
107
|
+
YARP::ParseResult.new(node, comments, errors, warnings, @source)
|
89
108
|
end
|
90
109
|
|
91
110
|
private
|
@@ -117,10 +136,21 @@ module YARP
|
|
117
136
|
end
|
118
137
|
end
|
119
138
|
|
120
|
-
def
|
139
|
+
def load_embedded_string
|
121
140
|
io.read(load_varint).force_encoding(encoding)
|
122
141
|
end
|
123
142
|
|
143
|
+
def load_string
|
144
|
+
case io.getbyte
|
145
|
+
when 1
|
146
|
+
input.byteslice(load_varint, load_varint).force_encoding(encoding)
|
147
|
+
when 2
|
148
|
+
load_embedded_string
|
149
|
+
else
|
150
|
+
raise
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
124
154
|
def load_location
|
125
155
|
Location.new(source, load_varint, load_varint)
|
126
156
|
end
|
@@ -158,225 +188,267 @@ module YARP
|
|
158
188
|
when 3 then
|
159
189
|
AndNode.new(load_node, load_node, load_location, location)
|
160
190
|
when 4 then
|
161
|
-
AndWriteNode.new(load_node, load_node, load_location, location)
|
162
|
-
when 5 then
|
163
191
|
ArgumentsNode.new(Array.new(load_varint) { load_node }, location)
|
164
|
-
when
|
192
|
+
when 5 then
|
165
193
|
ArrayNode.new(Array.new(load_varint) { load_node }, load_optional_location, load_optional_location, location)
|
166
|
-
when
|
194
|
+
when 6 then
|
167
195
|
ArrayPatternNode.new(load_optional_node, Array.new(load_varint) { load_node }, load_optional_node, Array.new(load_varint) { load_node }, load_optional_location, load_optional_location, location)
|
168
|
-
when
|
196
|
+
when 7 then
|
169
197
|
AssocNode.new(load_node, load_optional_node, load_optional_location, location)
|
170
|
-
when
|
198
|
+
when 8 then
|
171
199
|
AssocSplatNode.new(load_optional_node, load_location, location)
|
172
|
-
when
|
200
|
+
when 9 then
|
173
201
|
BackReferenceReadNode.new(location)
|
174
|
-
when
|
202
|
+
when 10 then
|
175
203
|
BeginNode.new(load_optional_location, load_optional_node, load_optional_node, load_optional_node, load_optional_node, load_optional_location, location)
|
176
|
-
when
|
204
|
+
when 11 then
|
177
205
|
BlockArgumentNode.new(load_optional_node, load_location, location)
|
178
|
-
when
|
206
|
+
when 12 then
|
179
207
|
BlockNode.new(Array.new(load_varint) { load_constant }, load_optional_node, load_optional_node, load_location, load_location, location)
|
180
|
-
when
|
208
|
+
when 13 then
|
181
209
|
BlockParameterNode.new(load_optional_location, load_location, location)
|
182
|
-
when
|
210
|
+
when 14 then
|
183
211
|
BlockParametersNode.new(load_optional_node, Array.new(load_varint) { load_location }, load_optional_location, load_optional_location, location)
|
184
|
-
when
|
212
|
+
when 15 then
|
185
213
|
BreakNode.new(load_optional_node, load_location, location)
|
186
|
-
when
|
214
|
+
when 16 then
|
187
215
|
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)
|
188
|
-
when
|
216
|
+
when 17 then
|
189
217
|
CallOperatorAndWriteNode.new(load_node, load_location, load_node, location)
|
190
|
-
when
|
218
|
+
when 18 then
|
191
219
|
CallOperatorOrWriteNode.new(load_node, load_node, load_location, location)
|
192
|
-
when
|
220
|
+
when 19 then
|
193
221
|
CallOperatorWriteNode.new(load_node, load_location, load_node, load_constant, location)
|
194
|
-
when
|
222
|
+
when 20 then
|
195
223
|
CapturePatternNode.new(load_node, load_node, load_location, location)
|
196
|
-
when
|
224
|
+
when 21 then
|
197
225
|
CaseNode.new(load_optional_node, Array.new(load_varint) { load_node }, load_optional_node, load_location, load_location, location)
|
226
|
+
when 22 then
|
227
|
+
ClassNode.new(Array.new(load_varint) { load_constant }, load_location, load_node, load_optional_location, load_optional_node, load_optional_node, load_location, load_string, location)
|
198
228
|
when 23 then
|
199
|
-
|
229
|
+
ClassVariableAndWriteNode.new(load_location, load_location, load_node, location)
|
200
230
|
when 24 then
|
201
|
-
|
231
|
+
ClassVariableOperatorWriteNode.new(load_location, load_location, load_node, load_constant, location)
|
202
232
|
when 25 then
|
203
|
-
|
233
|
+
ClassVariableOrWriteNode.new(load_location, load_location, load_node, location)
|
204
234
|
when 26 then
|
205
|
-
|
235
|
+
ClassVariableReadNode.new(location)
|
206
236
|
when 27 then
|
207
|
-
|
237
|
+
ClassVariableTargetNode.new(location)
|
208
238
|
when 28 then
|
209
|
-
|
239
|
+
ClassVariableWriteNode.new(load_location, load_optional_node, load_optional_location, location)
|
210
240
|
when 29 then
|
211
|
-
|
241
|
+
ConstantAndWriteNode.new(load_location, load_location, load_node, location)
|
212
242
|
when 30 then
|
213
|
-
|
214
|
-
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)
|
243
|
+
ConstantOperatorWriteNode.new(load_location, load_location, load_node, load_constant, location)
|
215
244
|
when 31 then
|
216
|
-
|
245
|
+
ConstantOrWriteNode.new(load_location, load_location, load_node, location)
|
217
246
|
when 32 then
|
218
|
-
|
247
|
+
ConstantPathAndWriteNode.new(load_node, load_location, load_node, location)
|
219
248
|
when 33 then
|
220
|
-
|
249
|
+
ConstantPathNode.new(load_optional_node, load_node, load_location, location)
|
221
250
|
when 34 then
|
222
|
-
|
251
|
+
ConstantPathOperatorWriteNode.new(load_node, load_location, load_node, load_constant, location)
|
223
252
|
when 35 then
|
224
|
-
|
253
|
+
ConstantPathOrWriteNode.new(load_node, load_location, load_node, location)
|
225
254
|
when 36 then
|
226
|
-
|
255
|
+
ConstantPathTargetNode.new(load_optional_node, load_node, load_location, location)
|
227
256
|
when 37 then
|
228
|
-
|
257
|
+
ConstantPathWriteNode.new(load_node, load_location, load_node, location)
|
229
258
|
when 38 then
|
230
|
-
|
259
|
+
ConstantReadNode.new(location)
|
231
260
|
when 39 then
|
232
|
-
|
261
|
+
ConstantTargetNode.new(location)
|
233
262
|
when 40 then
|
234
|
-
|
263
|
+
ConstantWriteNode.new(load_location, load_node, load_location, location)
|
235
264
|
when 41 then
|
236
|
-
|
265
|
+
load_serialized_length
|
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)
|
237
267
|
when 42 then
|
238
|
-
|
268
|
+
DefinedNode.new(load_optional_location, load_node, load_optional_location, load_location, location)
|
239
269
|
when 43 then
|
240
|
-
|
270
|
+
ElseNode.new(load_location, load_optional_node, load_optional_location, location)
|
241
271
|
when 44 then
|
242
|
-
|
272
|
+
EmbeddedStatementsNode.new(load_location, load_optional_node, load_location, location)
|
243
273
|
when 45 then
|
244
|
-
|
274
|
+
EmbeddedVariableNode.new(load_location, load_node, location)
|
245
275
|
when 46 then
|
246
|
-
|
276
|
+
EnsureNode.new(load_location, load_optional_node, load_location, location)
|
247
277
|
when 47 then
|
248
|
-
|
278
|
+
FalseNode.new(location)
|
249
279
|
when 48 then
|
250
|
-
|
280
|
+
FindPatternNode.new(load_optional_node, load_node, Array.new(load_varint) { load_node }, load_node, load_optional_location, load_optional_location, location)
|
251
281
|
when 49 then
|
252
|
-
|
282
|
+
FlipFlopNode.new(load_optional_node, load_optional_node, load_location, load_varint, location)
|
253
283
|
when 50 then
|
254
|
-
|
284
|
+
FloatNode.new(location)
|
255
285
|
when 51 then
|
256
|
-
|
286
|
+
ForNode.new(load_node, load_node, load_optional_node, load_location, load_location, load_optional_location, load_location, location)
|
257
287
|
when 52 then
|
258
|
-
|
288
|
+
ForwardingArgumentsNode.new(location)
|
259
289
|
when 53 then
|
260
|
-
|
290
|
+
ForwardingParameterNode.new(location)
|
261
291
|
when 54 then
|
262
|
-
|
292
|
+
ForwardingSuperNode.new(load_optional_node, location)
|
263
293
|
when 55 then
|
264
|
-
|
294
|
+
GlobalVariableAndWriteNode.new(load_location, load_location, load_node, location)
|
265
295
|
when 56 then
|
266
|
-
|
296
|
+
GlobalVariableOperatorWriteNode.new(load_location, load_location, load_node, load_constant, location)
|
267
297
|
when 57 then
|
268
|
-
|
298
|
+
GlobalVariableOrWriteNode.new(load_location, load_location, load_node, location)
|
269
299
|
when 58 then
|
270
|
-
|
300
|
+
GlobalVariableReadNode.new(location)
|
271
301
|
when 59 then
|
272
|
-
|
302
|
+
GlobalVariableTargetNode.new(location)
|
273
303
|
when 60 then
|
274
|
-
|
304
|
+
GlobalVariableWriteNode.new(load_location, load_location, load_node, location)
|
275
305
|
when 61 then
|
276
|
-
|
306
|
+
HashNode.new(load_location, Array.new(load_varint) { load_node }, load_location, location)
|
277
307
|
when 62 then
|
278
|
-
|
308
|
+
HashPatternNode.new(load_optional_node, Array.new(load_varint) { load_node }, load_optional_node, load_optional_location, load_optional_location, location)
|
279
309
|
when 63 then
|
280
|
-
|
310
|
+
IfNode.new(load_optional_location, load_node, load_optional_node, load_optional_node, load_optional_location, location)
|
281
311
|
when 64 then
|
282
|
-
|
312
|
+
ImaginaryNode.new(load_node, location)
|
283
313
|
when 65 then
|
284
|
-
|
314
|
+
InNode.new(load_node, load_optional_node, load_location, load_optional_location, location)
|
285
315
|
when 66 then
|
286
|
-
|
316
|
+
InstanceVariableAndWriteNode.new(load_location, load_location, load_node, location)
|
287
317
|
when 67 then
|
288
|
-
|
318
|
+
InstanceVariableOperatorWriteNode.new(load_location, load_location, load_node, load_constant, location)
|
289
319
|
when 68 then
|
290
|
-
|
320
|
+
InstanceVariableOrWriteNode.new(load_location, load_location, load_node, location)
|
291
321
|
when 69 then
|
292
|
-
|
322
|
+
InstanceVariableReadNode.new(location)
|
293
323
|
when 70 then
|
294
|
-
|
324
|
+
InstanceVariableTargetNode.new(location)
|
295
325
|
when 71 then
|
296
|
-
|
326
|
+
InstanceVariableWriteNode.new(load_location, load_node, load_location, location)
|
297
327
|
when 72 then
|
298
|
-
|
328
|
+
IntegerNode.new(location)
|
299
329
|
when 73 then
|
300
|
-
|
330
|
+
InterpolatedRegularExpressionNode.new(load_location, Array.new(load_varint) { load_node }, load_location, load_varint, location)
|
301
331
|
when 74 then
|
302
|
-
|
332
|
+
InterpolatedStringNode.new(load_optional_location, Array.new(load_varint) { load_node }, load_optional_location, location)
|
303
333
|
when 75 then
|
304
|
-
|
334
|
+
InterpolatedSymbolNode.new(load_optional_location, Array.new(load_varint) { load_node }, load_optional_location, location)
|
305
335
|
when 76 then
|
306
|
-
|
336
|
+
InterpolatedXStringNode.new(load_location, Array.new(load_varint) { load_node }, load_location, location)
|
307
337
|
when 77 then
|
308
|
-
|
338
|
+
KeywordHashNode.new(Array.new(load_varint) { load_node }, location)
|
309
339
|
when 78 then
|
310
|
-
|
340
|
+
KeywordParameterNode.new(load_location, load_optional_node, location)
|
311
341
|
when 79 then
|
312
|
-
|
342
|
+
KeywordRestParameterNode.new(load_location, load_optional_location, location)
|
313
343
|
when 80 then
|
314
|
-
|
344
|
+
LambdaNode.new(Array.new(load_varint) { load_constant }, load_location, load_location, load_location, load_optional_node, load_optional_node, location)
|
315
345
|
when 81 then
|
316
|
-
|
346
|
+
LocalVariableAndWriteNode.new(load_location, load_location, load_node, load_constant, load_varint, location)
|
317
347
|
when 82 then
|
318
|
-
|
348
|
+
LocalVariableOperatorWriteNode.new(load_location, load_location, load_node, load_constant, load_constant, load_varint, location)
|
319
349
|
when 83 then
|
320
|
-
|
350
|
+
LocalVariableOrWriteNode.new(load_location, load_location, load_node, load_constant, load_varint, location)
|
321
351
|
when 84 then
|
322
|
-
|
352
|
+
LocalVariableReadNode.new(load_constant, load_varint, location)
|
323
353
|
when 85 then
|
324
|
-
|
354
|
+
LocalVariableTargetNode.new(load_constant, load_varint, location)
|
325
355
|
when 86 then
|
326
|
-
|
356
|
+
LocalVariableWriteNode.new(load_constant, load_varint, load_node, load_location, load_location, location)
|
327
357
|
when 87 then
|
328
|
-
|
358
|
+
MatchPredicateNode.new(load_node, load_node, load_location, location)
|
329
359
|
when 88 then
|
330
|
-
|
360
|
+
MatchRequiredNode.new(load_node, load_node, load_location, location)
|
331
361
|
when 89 then
|
332
|
-
|
362
|
+
MissingNode.new(location)
|
333
363
|
when 90 then
|
334
|
-
|
364
|
+
ModuleNode.new(Array.new(load_varint) { load_constant }, load_location, load_node, load_optional_node, load_location, load_string, location)
|
335
365
|
when 91 then
|
336
|
-
|
366
|
+
MultiWriteNode.new(Array.new(load_varint) { load_node }, load_optional_location, load_optional_node, load_optional_location, load_optional_location, location)
|
337
367
|
when 92 then
|
338
|
-
|
368
|
+
NextNode.new(load_optional_node, load_location, location)
|
339
369
|
when 93 then
|
340
|
-
|
370
|
+
NilNode.new(location)
|
341
371
|
when 94 then
|
342
|
-
|
372
|
+
NoKeywordsParameterNode.new(load_location, load_location, location)
|
343
373
|
when 95 then
|
344
|
-
|
374
|
+
NumberedReferenceReadNode.new(location)
|
345
375
|
when 96 then
|
346
|
-
|
376
|
+
OptionalParameterNode.new(load_constant, load_location, load_location, load_node, location)
|
347
377
|
when 97 then
|
348
|
-
|
378
|
+
OrNode.new(load_node, load_node, load_location, location)
|
349
379
|
when 98 then
|
350
|
-
|
380
|
+
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)
|
351
381
|
when 99 then
|
352
|
-
|
382
|
+
ParenthesesNode.new(load_optional_node, load_location, load_location, location)
|
353
383
|
when 100 then
|
354
|
-
|
384
|
+
PinnedExpressionNode.new(load_node, load_location, load_location, load_location, location)
|
355
385
|
when 101 then
|
356
|
-
|
386
|
+
PinnedVariableNode.new(load_node, load_location, location)
|
357
387
|
when 102 then
|
358
|
-
|
388
|
+
PostExecutionNode.new(load_optional_node, load_location, load_location, load_location, location)
|
359
389
|
when 103 then
|
360
|
-
|
390
|
+
PreExecutionNode.new(load_optional_node, load_location, load_location, load_location, location)
|
361
391
|
when 104 then
|
362
|
-
|
392
|
+
ProgramNode.new(Array.new(load_varint) { load_constant }, load_node, location)
|
363
393
|
when 105 then
|
364
|
-
|
394
|
+
RangeNode.new(load_optional_node, load_optional_node, load_location, load_varint, location)
|
365
395
|
when 106 then
|
366
|
-
|
396
|
+
RationalNode.new(load_node, location)
|
367
397
|
when 107 then
|
368
|
-
|
398
|
+
RedoNode.new(location)
|
369
399
|
when 108 then
|
370
|
-
|
400
|
+
RegularExpressionNode.new(load_location, load_location, load_location, load_string, load_varint, location)
|
371
401
|
when 109 then
|
372
|
-
|
402
|
+
RequiredDestructuredParameterNode.new(Array.new(load_varint) { load_node }, load_location, load_location, location)
|
373
403
|
when 110 then
|
374
|
-
|
404
|
+
RequiredParameterNode.new(load_constant, location)
|
375
405
|
when 111 then
|
376
|
-
|
406
|
+
RescueModifierNode.new(load_node, load_location, load_node, location)
|
377
407
|
when 112 then
|
378
|
-
|
408
|
+
RescueNode.new(load_location, Array.new(load_varint) { load_node }, load_optional_location, load_optional_node, load_optional_node, load_optional_node, location)
|
379
409
|
when 113 then
|
410
|
+
RestParameterNode.new(load_location, load_optional_location, location)
|
411
|
+
when 114 then
|
412
|
+
RetryNode.new(location)
|
413
|
+
when 115 then
|
414
|
+
ReturnNode.new(load_location, load_optional_node, location)
|
415
|
+
when 116 then
|
416
|
+
SelfNode.new(location)
|
417
|
+
when 117 then
|
418
|
+
SingletonClassNode.new(Array.new(load_varint) { load_constant }, load_location, load_location, load_node, load_optional_node, load_location, location)
|
419
|
+
when 118 then
|
420
|
+
SourceEncodingNode.new(location)
|
421
|
+
when 119 then
|
422
|
+
SourceFileNode.new(load_string, location)
|
423
|
+
when 120 then
|
424
|
+
SourceLineNode.new(location)
|
425
|
+
when 121 then
|
426
|
+
SplatNode.new(load_location, load_optional_node, location)
|
427
|
+
when 122 then
|
428
|
+
StatementsNode.new(Array.new(load_varint) { load_node }, location)
|
429
|
+
when 123 then
|
430
|
+
StringConcatNode.new(load_node, load_node, location)
|
431
|
+
when 124 then
|
432
|
+
StringNode.new(load_optional_location, load_location, load_optional_location, load_string, location)
|
433
|
+
when 125 then
|
434
|
+
SuperNode.new(load_location, load_optional_location, load_optional_node, load_optional_location, load_optional_node, location)
|
435
|
+
when 126 then
|
436
|
+
SymbolNode.new(load_optional_location, load_optional_location, load_optional_location, load_string, location)
|
437
|
+
when 127 then
|
438
|
+
TrueNode.new(location)
|
439
|
+
when 128 then
|
440
|
+
UndefNode.new(Array.new(load_varint) { load_node }, load_location, location)
|
441
|
+
when 129 then
|
442
|
+
UnlessNode.new(load_location, load_node, load_optional_node, load_optional_node, load_optional_location, location)
|
443
|
+
when 130 then
|
444
|
+
UntilNode.new(load_location, load_optional_location, load_node, load_optional_node, load_varint, location)
|
445
|
+
when 131 then
|
446
|
+
WhenNode.new(load_location, Array.new(load_varint) { load_node }, load_optional_node, location)
|
447
|
+
when 132 then
|
448
|
+
WhileNode.new(load_location, load_optional_location, load_node, load_optional_node, load_varint, location)
|
449
|
+
when 133 then
|
450
|
+
XStringNode.new(load_location, load_location, load_location, load_string, location)
|
451
|
+
when 134 then
|
380
452
|
YieldNode.new(load_location, load_optional_location, load_optional_node, load_optional_location, location)
|
381
453
|
end
|
382
454
|
end
|
data/lib/yarp.rb
CHANGED
@@ -37,7 +37,7 @@ module YARP
|
|
37
37
|
class Location
|
38
38
|
# A Source object that is used to determine more information from the given
|
39
39
|
# offset and length.
|
40
|
-
|
40
|
+
protected attr_reader :source
|
41
41
|
|
42
42
|
# The byte offset from the beginning of the source where this location
|
43
43
|
# starts.
|
@@ -52,6 +52,16 @@ module YARP
|
|
52
52
|
@length = length
|
53
53
|
end
|
54
54
|
|
55
|
+
# Create a new location object with the given options.
|
56
|
+
def copy(**options)
|
57
|
+
Location.new(
|
58
|
+
options.fetch(:source) { source },
|
59
|
+
options.fetch(:start_offset) { start_offset },
|
60
|
+
options.fetch(:length) { length }
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Returns a string representation of this location.
|
55
65
|
def inspect
|
56
66
|
"#<YARP::Location @start_offset=#{@start_offset} @length=#{@length}>"
|
57
67
|
end
|
@@ -102,6 +112,16 @@ module YARP
|
|
102
112
|
other.end_offset == end_offset
|
103
113
|
end
|
104
114
|
|
115
|
+
# Returns a new location that stretches from this location to the given
|
116
|
+
# other location. Raises an error if this location is not before the other
|
117
|
+
# location or if they don't share the same source.
|
118
|
+
def join(other)
|
119
|
+
raise "Incompatible sources" if source != other.source
|
120
|
+
raise "Incompatible locations" if start_offset > other.start_offset
|
121
|
+
|
122
|
+
Location.new(source, start_offset, other.end_offset - start_offset)
|
123
|
+
end
|
124
|
+
|
105
125
|
def self.null
|
106
126
|
new(0, 0)
|
107
127
|
end
|
@@ -313,6 +333,30 @@ module YARP
|
|
313
333
|
end
|
314
334
|
end
|
315
335
|
|
336
|
+
class FloatNode < Node
|
337
|
+
def value
|
338
|
+
Float(slice)
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
class ImaginaryNode < Node
|
343
|
+
def value
|
344
|
+
Complex(0, numeric.value)
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
class IntegerNode < Node
|
349
|
+
def value
|
350
|
+
Integer(slice)
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
class RationalNode < Node
|
355
|
+
def value
|
356
|
+
Rational(slice.chomp("r"))
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
316
360
|
# Load the serialized AST using the source as a reference into a tree.
|
317
361
|
def self.load(source, serialized)
|
318
362
|
Serialize.load(source, serialized)
|
@@ -483,6 +527,8 @@ module YARP
|
|
483
527
|
end
|
484
528
|
|
485
529
|
require_relative "yarp/lex_compat"
|
530
|
+
require_relative "yarp/mutation_visitor"
|
531
|
+
require_relative "yarp/desugar_visitor"
|
486
532
|
require_relative "yarp/node"
|
487
533
|
require_relative "yarp/ripper_compat"
|
488
534
|
require_relative "yarp/serialize"
|
@@ -491,5 +537,5 @@ require_relative "yarp/pack"
|
|
491
537
|
if RUBY_ENGINE == "ruby" and !ENV["YARP_FFI_BACKEND"]
|
492
538
|
require "yarp/yarp"
|
493
539
|
else
|
494
|
-
|
540
|
+
require_relative "yarp/ffi"
|
495
541
|
end
|