prism 0.13.0 → 0.15.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 +37 -1
- data/README.md +4 -1
- data/config.yml +96 -35
- data/docs/fuzzing.md +5 -10
- data/docs/prism.png +0 -0
- data/docs/serialization.md +10 -0
- data/ext/prism/api_node.c +239 -86
- data/ext/prism/extension.c +35 -48
- data/ext/prism/extension.h +1 -1
- data/include/prism/ast.h +170 -118
- data/include/prism/diagnostic.h +1 -0
- data/include/prism/node.h +8 -0
- data/include/prism/parser.h +26 -0
- data/include/prism/util/pm_buffer.h +3 -0
- data/include/prism/util/pm_constant_pool.h +21 -2
- data/include/prism/util/pm_string.h +2 -1
- data/include/prism/version.h +2 -2
- data/include/prism.h +1 -2
- data/lib/prism/compiler.rb +150 -141
- data/lib/prism/debug.rb +30 -26
- data/lib/prism/dispatcher.rb +42 -0
- data/lib/prism/dsl.rb +23 -8
- data/lib/prism/ffi.rb +4 -4
- data/lib/prism/lex_compat.rb +42 -8
- data/lib/prism/mutation_compiler.rb +18 -3
- data/lib/prism/node.rb +2061 -191
- data/lib/prism/node_ext.rb +44 -0
- data/lib/prism/parse_result.rb +32 -5
- data/lib/prism/pattern.rb +1 -1
- data/lib/prism/serialize.rb +95 -87
- data/lib/prism/visitor.rb +9 -0
- data/prism.gemspec +2 -3
- data/src/diagnostic.c +2 -1
- data/src/node.c +99 -32
- data/src/prettyprint.c +137 -80
- data/src/prism.c +1960 -843
- data/src/serialize.c +140 -79
- data/src/util/pm_buffer.c +9 -7
- data/src/util/pm_constant_pool.c +25 -11
- metadata +3 -4
- data/include/prism/unescape.h +0 -48
- data/src/unescape.c +0 -637
data/lib/prism/node_ext.rb
CHANGED
@@ -52,4 +52,48 @@ module Prism
|
|
52
52
|
o
|
53
53
|
end
|
54
54
|
end
|
55
|
+
|
56
|
+
class ConstantReadNode < Node
|
57
|
+
# Returns the list of parts for the full name of this constant. For example: [:Foo]
|
58
|
+
def full_name_parts
|
59
|
+
[name]
|
60
|
+
end
|
61
|
+
|
62
|
+
# Returns the full name of this constant. For example: "Foo"
|
63
|
+
def full_name
|
64
|
+
name.name
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
class ConstantPathNode < Node
|
69
|
+
# Returns the list of parts for the full name of this constant path. For example: [:Foo, :Bar]
|
70
|
+
def full_name_parts
|
71
|
+
parts = [child.name]
|
72
|
+
current = parent
|
73
|
+
|
74
|
+
while current.is_a?(ConstantPathNode)
|
75
|
+
parts.unshift(current.child.name)
|
76
|
+
current = current.parent
|
77
|
+
end
|
78
|
+
|
79
|
+
parts.unshift(current&.name || :"")
|
80
|
+
end
|
81
|
+
|
82
|
+
# Returns the full name of this constant path. For example: "Foo::Bar"
|
83
|
+
def full_name
|
84
|
+
full_name_parts.join("::")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
class ConstantPathTargetNode < Node
|
89
|
+
# Returns the list of parts for the full name of this constant path. For example: [:Foo, :Bar]
|
90
|
+
def full_name_parts
|
91
|
+
(parent&.full_name_parts || [:""]).push(child.name)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Returns the full name of this constant path. For example: "Foo::Bar"
|
95
|
+
def full_name
|
96
|
+
full_name_parts.join("::")
|
97
|
+
end
|
98
|
+
end
|
55
99
|
end
|
data/lib/prism/parse_result.rb
CHANGED
@@ -117,7 +117,7 @@ module Prism
|
|
117
117
|
end
|
118
118
|
|
119
119
|
def pretty_print(q)
|
120
|
-
q.text("(#{start_line},#{start_column})-(#{end_line},#{end_column})
|
120
|
+
q.text("(#{start_line},#{start_column})-(#{end_line},#{end_column})")
|
121
121
|
end
|
122
122
|
|
123
123
|
def ==(other)
|
@@ -137,7 +137,7 @@ module Prism
|
|
137
137
|
end
|
138
138
|
|
139
139
|
def self.null
|
140
|
-
new(0, 0)
|
140
|
+
new(nil, 0, 0)
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
@@ -166,6 +166,32 @@ module Prism
|
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
169
|
+
# This represents a magic comment that was encountered during parsing.
|
170
|
+
class MagicComment
|
171
|
+
attr_reader :key_loc, :value_loc
|
172
|
+
|
173
|
+
def initialize(key_loc, value_loc)
|
174
|
+
@key_loc = key_loc
|
175
|
+
@value_loc = value_loc
|
176
|
+
end
|
177
|
+
|
178
|
+
def key
|
179
|
+
key_loc.slice
|
180
|
+
end
|
181
|
+
|
182
|
+
def value
|
183
|
+
value_loc.slice
|
184
|
+
end
|
185
|
+
|
186
|
+
def deconstruct_keys(keys)
|
187
|
+
{ key_loc: key_loc, value_loc: value_loc }
|
188
|
+
end
|
189
|
+
|
190
|
+
def inspect
|
191
|
+
"#<Prism::MagicComment @key=#{key.inspect} @value=#{value.inspect}>"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
169
195
|
# This represents an error that was encountered during parsing.
|
170
196
|
class ParseError
|
171
197
|
attr_reader :message, :location
|
@@ -206,18 +232,19 @@ module Prism
|
|
206
232
|
# the AST, any comments that were encounters, and any errors that were
|
207
233
|
# encountered.
|
208
234
|
class ParseResult
|
209
|
-
attr_reader :value, :comments, :errors, :warnings, :source
|
235
|
+
attr_reader :value, :comments, :magic_comments, :errors, :warnings, :source
|
210
236
|
|
211
|
-
def initialize(value, comments, errors, warnings, source)
|
237
|
+
def initialize(value, comments, magic_comments, errors, warnings, source)
|
212
238
|
@value = value
|
213
239
|
@comments = comments
|
240
|
+
@magic_comments = magic_comments
|
214
241
|
@errors = errors
|
215
242
|
@warnings = warnings
|
216
243
|
@source = source
|
217
244
|
end
|
218
245
|
|
219
246
|
def deconstruct_keys(keys)
|
220
|
-
{ value: value, comments: comments, errors: errors, warnings: warnings }
|
247
|
+
{ value: value, comments: comments, magic_comments: magic_comments, errors: errors, warnings: warnings }
|
221
248
|
end
|
222
249
|
|
223
250
|
def success?
|
data/lib/prism/pattern.rb
CHANGED
@@ -10,7 +10,7 @@ module Prism
|
|
10
10
|
# in ConstantPathNode[ConstantReadNode[name: :Prism], ConstantReadNode[name: :Pattern]]
|
11
11
|
# end
|
12
12
|
#
|
13
|
-
# the pattern is the
|
13
|
+
# the pattern is the <tt>ConstantPathNode[...]</tt> expression.
|
14
14
|
#
|
15
15
|
# The pattern gets compiled into an object that responds to #call by running
|
16
16
|
# the #compile method. This method itself will run back through Prism to
|
data/lib/prism/serialize.rb
CHANGED
@@ -21,7 +21,7 @@ end
|
|
21
21
|
module Prism
|
22
22
|
module Serialize
|
23
23
|
MAJOR_VERSION = 0
|
24
|
-
MINOR_VERSION =
|
24
|
+
MINOR_VERSION = 15
|
25
25
|
PATCH_VERSION = 0
|
26
26
|
|
27
27
|
def self.load(input, serialized)
|
@@ -62,9 +62,10 @@ module Prism
|
|
62
62
|
|
63
63
|
def load_metadata
|
64
64
|
comments = load_varint.times.map { Comment.new(Comment::TYPES.fetch(load_varint), load_location) }
|
65
|
+
magic_comments = load_varint.times.map { MagicComment.new(load_location, load_location) }
|
65
66
|
errors = load_varint.times.map { ParseError.new(load_embedded_string, load_location) }
|
66
67
|
warnings = load_varint.times.map { ParseWarning.new(load_embedded_string, load_location) }
|
67
|
-
[comments, errors, warnings]
|
68
|
+
[comments, magic_comments, errors, warnings]
|
68
69
|
end
|
69
70
|
|
70
71
|
def load_tokens
|
@@ -83,14 +84,14 @@ module Prism
|
|
83
84
|
def load_tokens_result
|
84
85
|
tokens = load_tokens
|
85
86
|
encoding = load_encoding
|
86
|
-
comments, errors, warnings = load_metadata
|
87
|
+
comments, magic_comments, errors, warnings = load_metadata
|
87
88
|
|
88
89
|
if encoding != @encoding
|
89
90
|
tokens.each { |token,| token.value.force_encoding(encoding) }
|
90
91
|
end
|
91
92
|
|
92
93
|
raise "Expected to consume all bytes while deserializing" unless @io.eof?
|
93
|
-
Prism::ParseResult.new(tokens, comments, errors, warnings, @source)
|
94
|
+
Prism::ParseResult.new(tokens, comments, magic_comments, errors, warnings, @source)
|
94
95
|
end
|
95
96
|
|
96
97
|
def load_nodes
|
@@ -104,17 +105,17 @@ module Prism
|
|
104
105
|
@encoding = load_encoding
|
105
106
|
@input = input.force_encoding(@encoding).freeze
|
106
107
|
|
107
|
-
comments, errors, warnings = load_metadata
|
108
|
+
comments, magic_comments, errors, warnings = load_metadata
|
108
109
|
|
109
110
|
@constant_pool_offset = io.read(4).unpack1("L")
|
110
111
|
@constant_pool = Array.new(load_varint, nil)
|
111
112
|
|
112
|
-
[load_node, comments, errors, warnings]
|
113
|
+
[load_node, comments, magic_comments, errors, warnings]
|
113
114
|
end
|
114
115
|
|
115
116
|
def load_result
|
116
|
-
node, comments, errors, warnings = load_nodes
|
117
|
-
Prism::ParseResult.new(node, comments, errors, warnings, @source)
|
117
|
+
node, comments, magic_comments, errors, warnings = load_nodes
|
118
|
+
Prism::ParseResult.new(node, comments, magic_comments, errors, warnings, @source)
|
118
119
|
end
|
119
120
|
|
120
121
|
private
|
@@ -151,13 +152,14 @@ module Prism
|
|
151
152
|
end
|
152
153
|
|
153
154
|
def load_string
|
154
|
-
|
155
|
+
type = io.getbyte
|
156
|
+
case type
|
155
157
|
when 1
|
156
158
|
input.byteslice(load_varint, load_varint).force_encoding(encoding)
|
157
159
|
when 2
|
158
160
|
load_embedded_string
|
159
161
|
else
|
160
|
-
raise
|
162
|
+
raise "Unknown serialized string type: #{type}"
|
161
163
|
end
|
162
164
|
end
|
163
165
|
|
@@ -223,7 +225,7 @@ module Prism
|
|
223
225
|
when 9 then
|
224
226
|
AssocSplatNode.new(load_optional_node, load_location, location)
|
225
227
|
when 10 then
|
226
|
-
BackReferenceReadNode.new(location)
|
228
|
+
BackReferenceReadNode.new(load_required_constant, location)
|
227
229
|
when 11 then
|
228
230
|
BeginNode.new(load_optional_location, load_optional_node, load_optional_node, load_optional_node, load_optional_node, load_optional_location, location)
|
229
231
|
when 12 then
|
@@ -239,13 +241,13 @@ module Prism
|
|
239
241
|
when 17 then
|
240
242
|
BreakNode.new(load_optional_node, load_location, location)
|
241
243
|
when 18 then
|
242
|
-
CallAndWriteNode.new(load_optional_node, load_optional_location, load_optional_location,
|
244
|
+
CallAndWriteNode.new(load_optional_node, load_optional_location, load_optional_location, load_varint, load_required_constant, load_required_constant, load_location, load_node, location)
|
243
245
|
when 19 then
|
244
|
-
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,
|
246
|
+
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_required_constant, location)
|
245
247
|
when 20 then
|
246
|
-
CallOperatorWriteNode.new(load_optional_node, load_optional_location, load_optional_location,
|
248
|
+
CallOperatorWriteNode.new(load_optional_node, load_optional_location, load_optional_location, load_varint, load_required_constant, load_required_constant, load_required_constant, load_location, load_node, location)
|
247
249
|
when 21 then
|
248
|
-
CallOrWriteNode.new(load_optional_node, load_optional_location, load_optional_location,
|
250
|
+
CallOrWriteNode.new(load_optional_node, load_optional_location, load_optional_location, load_varint, load_required_constant, load_required_constant, load_location, load_node, location)
|
249
251
|
when 22 then
|
250
252
|
CapturePatternNode.new(load_node, load_node, load_location, location)
|
251
253
|
when 23 then
|
@@ -342,150 +344,156 @@ module Prism
|
|
342
344
|
when 68 then
|
343
345
|
InNode.new(load_node, load_optional_node, load_location, load_optional_location, location)
|
344
346
|
when 69 then
|
345
|
-
|
347
|
+
IndexAndWriteNode.new(load_optional_node, load_optional_location, load_location, load_optional_node, load_location, load_optional_node, load_varint, load_location, load_node, location)
|
346
348
|
when 70 then
|
347
|
-
|
349
|
+
IndexOperatorWriteNode.new(load_optional_node, load_optional_location, load_location, load_optional_node, load_location, load_optional_node, load_varint, load_required_constant, load_location, load_node, location)
|
348
350
|
when 71 then
|
349
|
-
|
351
|
+
IndexOrWriteNode.new(load_optional_node, load_optional_location, load_location, load_optional_node, load_location, load_optional_node, load_varint, load_location, load_node, location)
|
350
352
|
when 72 then
|
351
|
-
|
353
|
+
InstanceVariableAndWriteNode.new(load_required_constant, load_location, load_location, load_node, location)
|
352
354
|
when 73 then
|
353
|
-
|
355
|
+
InstanceVariableOperatorWriteNode.new(load_required_constant, load_location, load_location, load_node, load_required_constant, location)
|
354
356
|
when 74 then
|
355
|
-
|
357
|
+
InstanceVariableOrWriteNode.new(load_required_constant, load_location, load_location, load_node, location)
|
356
358
|
when 75 then
|
357
|
-
|
359
|
+
InstanceVariableReadNode.new(load_required_constant, location)
|
358
360
|
when 76 then
|
359
|
-
|
361
|
+
InstanceVariableTargetNode.new(load_required_constant, location)
|
360
362
|
when 77 then
|
361
|
-
|
363
|
+
InstanceVariableWriteNode.new(load_required_constant, load_location, load_node, load_location, location)
|
362
364
|
when 78 then
|
363
|
-
|
365
|
+
IntegerNode.new(load_varint, location)
|
364
366
|
when 79 then
|
365
|
-
|
367
|
+
InterpolatedMatchLastLineNode.new(load_location, Array.new(load_varint) { load_node }, load_location, load_varint, location)
|
366
368
|
when 80 then
|
367
|
-
|
369
|
+
InterpolatedRegularExpressionNode.new(load_location, Array.new(load_varint) { load_node }, load_location, load_varint, location)
|
368
370
|
when 81 then
|
369
|
-
|
371
|
+
InterpolatedStringNode.new(load_optional_location, Array.new(load_varint) { load_node }, load_optional_location, location)
|
370
372
|
when 82 then
|
371
|
-
|
373
|
+
InterpolatedSymbolNode.new(load_optional_location, Array.new(load_varint) { load_node }, load_optional_location, location)
|
372
374
|
when 83 then
|
373
|
-
|
375
|
+
InterpolatedXStringNode.new(load_location, Array.new(load_varint) { load_node }, load_location, location)
|
374
376
|
when 84 then
|
375
|
-
|
377
|
+
KeywordHashNode.new(Array.new(load_varint) { load_node }, location)
|
376
378
|
when 85 then
|
377
|
-
|
379
|
+
KeywordParameterNode.new(load_required_constant, load_location, load_optional_node, location)
|
378
380
|
when 86 then
|
379
|
-
|
381
|
+
KeywordRestParameterNode.new(load_optional_constant, load_optional_location, load_location, location)
|
380
382
|
when 87 then
|
381
|
-
|
383
|
+
LambdaNode.new(Array.new(load_varint) { load_required_constant }, load_location, load_location, load_location, load_optional_node, load_optional_node, location)
|
382
384
|
when 88 then
|
383
|
-
|
385
|
+
LocalVariableAndWriteNode.new(load_location, load_location, load_node, load_required_constant, load_varint, location)
|
384
386
|
when 89 then
|
385
|
-
|
387
|
+
LocalVariableOperatorWriteNode.new(load_location, load_location, load_node, load_required_constant, load_required_constant, load_varint, location)
|
386
388
|
when 90 then
|
387
|
-
|
389
|
+
LocalVariableOrWriteNode.new(load_location, load_location, load_node, load_required_constant, load_varint, location)
|
388
390
|
when 91 then
|
389
|
-
|
391
|
+
LocalVariableReadNode.new(load_required_constant, load_varint, location)
|
390
392
|
when 92 then
|
391
|
-
|
393
|
+
LocalVariableTargetNode.new(load_required_constant, load_varint, location)
|
392
394
|
when 93 then
|
393
|
-
|
395
|
+
LocalVariableWriteNode.new(load_required_constant, load_varint, load_location, load_node, load_location, location)
|
394
396
|
when 94 then
|
395
|
-
|
397
|
+
MatchLastLineNode.new(load_location, load_location, load_location, load_string, load_varint, location)
|
396
398
|
when 95 then
|
397
|
-
|
399
|
+
MatchPredicateNode.new(load_node, load_node, load_location, location)
|
398
400
|
when 96 then
|
399
|
-
|
401
|
+
MatchRequiredNode.new(load_node, load_node, load_location, location)
|
400
402
|
when 97 then
|
401
|
-
|
403
|
+
MatchWriteNode.new(load_node, Array.new(load_varint) { load_required_constant }, location)
|
402
404
|
when 98 then
|
403
|
-
|
405
|
+
MissingNode.new(location)
|
404
406
|
when 99 then
|
405
|
-
|
407
|
+
ModuleNode.new(Array.new(load_varint) { load_required_constant }, load_location, load_node, load_optional_node, load_location, load_required_constant, location)
|
406
408
|
when 100 then
|
407
|
-
|
409
|
+
MultiTargetNode.new(Array.new(load_varint) { load_node }, load_optional_location, load_optional_location, location)
|
408
410
|
when 101 then
|
409
|
-
|
411
|
+
MultiWriteNode.new(Array.new(load_varint) { load_node }, load_optional_location, load_optional_location, load_location, load_node, location)
|
410
412
|
when 102 then
|
411
|
-
|
413
|
+
NextNode.new(load_optional_node, load_location, location)
|
412
414
|
when 103 then
|
413
|
-
|
415
|
+
NilNode.new(location)
|
414
416
|
when 104 then
|
415
|
-
|
417
|
+
NoKeywordsParameterNode.new(load_location, load_location, location)
|
416
418
|
when 105 then
|
417
|
-
|
419
|
+
NumberedReferenceReadNode.new(load_varint, location)
|
418
420
|
when 106 then
|
419
|
-
|
421
|
+
OptionalParameterNode.new(load_required_constant, load_location, load_location, load_node, location)
|
420
422
|
when 107 then
|
421
|
-
|
423
|
+
OrNode.new(load_node, load_node, load_location, location)
|
422
424
|
when 108 then
|
423
|
-
|
425
|
+
ParametersNode.new(Array.new(load_varint) { load_node }, Array.new(load_varint) { load_node }, load_optional_node, Array.new(load_varint) { load_node }, Array.new(load_varint) { load_node }, load_optional_node, load_optional_node, location)
|
424
426
|
when 109 then
|
425
|
-
|
427
|
+
ParenthesesNode.new(load_optional_node, load_location, load_location, location)
|
426
428
|
when 110 then
|
427
|
-
|
429
|
+
PinnedExpressionNode.new(load_node, load_location, load_location, load_location, location)
|
428
430
|
when 111 then
|
429
|
-
|
431
|
+
PinnedVariableNode.new(load_node, load_location, location)
|
430
432
|
when 112 then
|
431
|
-
|
433
|
+
PostExecutionNode.new(load_optional_node, load_location, load_location, load_location, location)
|
432
434
|
when 113 then
|
433
|
-
|
435
|
+
PreExecutionNode.new(load_optional_node, load_location, load_location, load_location, location)
|
434
436
|
when 114 then
|
435
|
-
|
437
|
+
ProgramNode.new(Array.new(load_varint) { load_required_constant }, load_node, location)
|
436
438
|
when 115 then
|
437
|
-
|
439
|
+
RangeNode.new(load_optional_node, load_optional_node, load_location, load_varint, location)
|
438
440
|
when 116 then
|
439
|
-
|
441
|
+
RationalNode.new(load_node, location)
|
440
442
|
when 117 then
|
441
|
-
|
443
|
+
RedoNode.new(location)
|
442
444
|
when 118 then
|
443
|
-
|
445
|
+
RegularExpressionNode.new(load_location, load_location, load_location, load_string, load_varint, location)
|
444
446
|
when 119 then
|
445
|
-
|
447
|
+
RequiredDestructuredParameterNode.new(Array.new(load_varint) { load_node }, load_location, load_location, location)
|
446
448
|
when 120 then
|
447
|
-
|
449
|
+
RequiredParameterNode.new(load_required_constant, location)
|
448
450
|
when 121 then
|
449
|
-
|
451
|
+
RescueModifierNode.new(load_node, load_location, load_node, location)
|
450
452
|
when 122 then
|
451
|
-
|
453
|
+
RescueNode.new(load_location, Array.new(load_varint) { load_node }, load_optional_location, load_optional_node, load_optional_node, load_optional_node, location)
|
452
454
|
when 123 then
|
453
|
-
|
455
|
+
RestParameterNode.new(load_optional_constant, load_optional_location, load_location, location)
|
454
456
|
when 124 then
|
455
|
-
|
457
|
+
RetryNode.new(location)
|
456
458
|
when 125 then
|
457
|
-
|
459
|
+
ReturnNode.new(load_location, load_optional_node, location)
|
458
460
|
when 126 then
|
459
|
-
|
461
|
+
SelfNode.new(location)
|
460
462
|
when 127 then
|
461
|
-
|
463
|
+
SingletonClassNode.new(Array.new(load_varint) { load_required_constant }, load_location, load_location, load_node, load_optional_node, load_location, location)
|
462
464
|
when 128 then
|
463
|
-
|
465
|
+
SourceEncodingNode.new(location)
|
464
466
|
when 129 then
|
465
|
-
|
467
|
+
SourceFileNode.new(load_string, location)
|
466
468
|
when 130 then
|
467
|
-
|
469
|
+
SourceLineNode.new(location)
|
468
470
|
when 131 then
|
469
|
-
|
471
|
+
SplatNode.new(load_location, load_optional_node, location)
|
470
472
|
when 132 then
|
471
|
-
|
473
|
+
StatementsNode.new(Array.new(load_varint) { load_node }, location)
|
472
474
|
when 133 then
|
473
|
-
|
475
|
+
StringConcatNode.new(load_node, load_node, location)
|
474
476
|
when 134 then
|
475
|
-
|
477
|
+
StringNode.new(load_varint, load_optional_location, load_location, load_optional_location, load_string, location)
|
476
478
|
when 135 then
|
477
|
-
|
479
|
+
SuperNode.new(load_location, load_optional_location, load_optional_node, load_optional_location, load_optional_node, location)
|
478
480
|
when 136 then
|
479
|
-
|
481
|
+
SymbolNode.new(load_optional_location, load_optional_location, load_optional_location, load_string, location)
|
480
482
|
when 137 then
|
481
|
-
|
483
|
+
TrueNode.new(location)
|
482
484
|
when 138 then
|
483
|
-
|
485
|
+
UndefNode.new(Array.new(load_varint) { load_node }, load_location, location)
|
484
486
|
when 139 then
|
485
|
-
|
487
|
+
UnlessNode.new(load_location, load_node, load_optional_node, load_optional_node, load_optional_location, location)
|
486
488
|
when 140 then
|
487
|
-
|
489
|
+
UntilNode.new(load_location, load_optional_location, load_node, load_optional_node, load_varint, location)
|
488
490
|
when 141 then
|
491
|
+
WhenNode.new(load_location, Array.new(load_varint) { load_node }, load_optional_node, location)
|
492
|
+
when 142 then
|
493
|
+
WhileNode.new(load_location, load_optional_location, load_node, load_optional_node, load_varint, location)
|
494
|
+
when 143 then
|
495
|
+
XStringNode.new(load_location, load_location, load_location, load_string, location)
|
496
|
+
when 144 then
|
489
497
|
YieldNode.new(load_location, load_optional_location, load_optional_node, load_optional_location, location)
|
490
498
|
end
|
491
499
|
end
|
data/lib/prism/visitor.rb
CHANGED
@@ -248,6 +248,15 @@ module Prism
|
|
248
248
|
# Visit a InNode node
|
249
249
|
alias visit_in_node visit_child_nodes
|
250
250
|
|
251
|
+
# Visit a IndexAndWriteNode node
|
252
|
+
alias visit_index_and_write_node visit_child_nodes
|
253
|
+
|
254
|
+
# Visit a IndexOperatorWriteNode node
|
255
|
+
alias visit_index_operator_write_node visit_child_nodes
|
256
|
+
|
257
|
+
# Visit a IndexOrWriteNode node
|
258
|
+
alias visit_index_or_write_node visit_child_nodes
|
259
|
+
|
251
260
|
# Visit a InstanceVariableAndWriteNode node
|
252
261
|
alias visit_instance_variable_and_write_node visit_child_nodes
|
253
262
|
|
data/prism.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "prism"
|
5
|
-
spec.version = "0.
|
5
|
+
spec.version = "0.15.0"
|
6
6
|
spec.authors = ["Shopify"]
|
7
7
|
spec.email = ["ruby@shopify.com"]
|
8
8
|
|
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
"docs/fuzzing.md",
|
30
30
|
"docs/heredocs.md",
|
31
31
|
"docs/mapping.md",
|
32
|
+
"docs/prism.png",
|
32
33
|
"docs/ripper.md",
|
33
34
|
"docs/ruby_api.md",
|
34
35
|
"docs/serialization.md",
|
@@ -46,7 +47,6 @@ Gem::Specification.new do |spec|
|
|
46
47
|
"include/prism/pack.h",
|
47
48
|
"include/prism/parser.h",
|
48
49
|
"include/prism/regexp.h",
|
49
|
-
"include/prism/unescape.h",
|
50
50
|
"include/prism/util/pm_buffer.h",
|
51
51
|
"include/prism/util/pm_char.h",
|
52
52
|
"include/prism/util/pm_constant_pool.h",
|
@@ -92,7 +92,6 @@ Gem::Specification.new do |spec|
|
|
92
92
|
"src/regexp.c",
|
93
93
|
"src/serialize.c",
|
94
94
|
"src/token_type.c",
|
95
|
-
"src/unescape.c",
|
96
95
|
"src/util/pm_buffer.c",
|
97
96
|
"src/util/pm_char.c",
|
98
97
|
"src/util/pm_constant_pool.c",
|
data/src/diagnostic.c
CHANGED
@@ -192,6 +192,7 @@ static const char* const diagnostic_messages[PM_DIAGNOSTIC_ID_LEN] = {
|
|
192
192
|
[PM_ERR_NUMBERED_PARAMETER_NOT_ALLOWED] = "Numbered parameters are not allowed alongside explicit parameters",
|
193
193
|
[PM_ERR_NUMBERED_PARAMETER_OUTER_SCOPE] = "Numbered parameter is already used in outer scope",
|
194
194
|
[PM_ERR_OPERATOR_MULTI_ASSIGN] = "Unexpected operator for a multiple assignment",
|
195
|
+
[PM_ERR_OPERATOR_WRITE_ARGUMENTS] = "Unexpected operator after a call with arguments",
|
195
196
|
[PM_ERR_OPERATOR_WRITE_BLOCK] = "Unexpected operator after a call with a block",
|
196
197
|
[PM_ERR_PARAMETER_ASSOC_SPLAT_MULTI] = "Unexpected multiple `**` splat parameters",
|
197
198
|
[PM_ERR_PARAMETER_BLOCK_MULTI] = "Multiple block parameters; only one block is allowed",
|
@@ -265,7 +266,7 @@ pm_diagnostic_message(pm_diagnostic_id_t diag_id) {
|
|
265
266
|
// Append an error to the given list of diagnostic.
|
266
267
|
bool
|
267
268
|
pm_diagnostic_list_append(pm_list_t *list, const uint8_t *start, const uint8_t *end, pm_diagnostic_id_t diag_id) {
|
268
|
-
pm_diagnostic_t *diagnostic = (pm_diagnostic_t *)
|
269
|
+
pm_diagnostic_t *diagnostic = (pm_diagnostic_t *) calloc(sizeof(pm_diagnostic_t), 1);
|
269
270
|
if (diagnostic == NULL) return false;
|
270
271
|
|
271
272
|
*diagnostic = (pm_diagnostic_t) { .start = start, .end = end, .message = pm_diagnostic_message(diag_id) };
|