prism 1.9.0 → 2.0.0.rc2
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 +88 -0
- data/CODE_OF_CONDUCT.md +1 -1
- data/LICENSE.md +1 -1
- data/Makefile +41 -12
- data/README.md +35 -97
- data/config.yml +174 -161
- data/docs/build_system.md +2 -2
- data/docs/configuration.md +5 -4
- data/docs/encoding.md +2 -2
- data/docs/fuzzing.md +4 -11
- data/docs/javascript.md +19 -4
- data/docs/mapping.md +1 -1
- data/docs/releasing.md +77 -5
- data/docs/relocation.md +2 -4
- data/docs/serialization.md +22 -24
- data/docs/testing.md +46 -29
- data/ext/prism/api_node.c +1461 -1401
- data/ext/prism/extconf.rb +3 -4
- data/ext/prism/extension.c +796 -422
- data/ext/prism/extension.h +3 -3
- data/include/prism/arena.h +37 -0
- data/include/prism/ast.h +2727 -610
- data/include/prism/buffer.h +52 -0
- data/include/prism/comments.h +55 -0
- data/include/prism/compiler/accel.h +26 -0
- data/include/prism/compiler/align.h +36 -0
- data/include/prism/compiler/assume.h +25 -0
- data/include/prism/compiler/bswap.h +46 -0
- data/include/prism/compiler/endianness.h +34 -0
- data/include/prism/compiler/exported.h +24 -0
- data/include/prism/compiler/fallthrough.h +22 -0
- data/include/prism/compiler/filesystem.h +32 -0
- data/include/prism/compiler/flex_array.h +19 -0
- data/include/prism/compiler/force_inline.h +21 -0
- data/include/prism/compiler/format.h +25 -0
- data/include/prism/compiler/inline.h +17 -0
- data/include/prism/compiler/nodiscard.h +22 -0
- data/include/prism/compiler/nonnull.h +18 -0
- data/include/prism/compiler/unused.h +18 -0
- data/include/prism/constant_pool.h +81 -0
- data/include/prism/diagnostic.h +38 -403
- data/include/prism/errors_format.h +53 -0
- data/include/prism/excludes.h +29 -0
- data/include/prism/integer.h +41 -0
- data/include/prism/internal/allocator.h +68 -0
- data/include/prism/internal/allocator_debug.h +88 -0
- data/include/prism/internal/arena.h +108 -0
- data/include/prism/internal/bit.h +42 -0
- data/include/prism/internal/buffer.h +94 -0
- data/include/prism/internal/char.h +145 -0
- data/include/prism/internal/comments.h +53 -0
- data/include/prism/internal/constant_pool.h +152 -0
- data/include/prism/internal/diagnostic.h +389 -0
- data/include/prism/{encoding.h → internal/encoding.h} +27 -68
- data/include/prism/internal/integer.h +68 -0
- data/include/prism/internal/isinf.h +16 -0
- data/include/prism/internal/line_offset_list.h +34 -0
- data/include/prism/{util/pm_list.h → internal/list.h} +11 -52
- data/include/prism/internal/magic_comments.h +23 -0
- data/include/prism/internal/memchr.h +15 -0
- data/include/prism/internal/node.h +38 -0
- data/include/prism/internal/options.h +232 -0
- data/include/prism/internal/parser.h +1004 -0
- data/include/prism/internal/regexp.h +26 -0
- data/include/prism/internal/serialize.h +39 -0
- data/include/prism/internal/source.h +72 -0
- data/include/prism/{static_literals.h → internal/static_literals.h} +26 -47
- data/include/prism/internal/stringy.h +35 -0
- data/include/prism/{util/pm_strncasecmp.h → internal/strncasecmp.h} +3 -17
- data/include/prism/{util/pm_strpbrk.h → internal/strpbrk.h} +7 -20
- data/include/prism/internal/tokens.h +11 -0
- data/include/prism/internal/xxh3.h +16 -0
- data/include/prism/json.h +32 -0
- data/include/prism/line_offset_list.h +61 -0
- data/include/prism/magic_comments.h +35 -0
- data/include/prism/node.h +18 -53
- data/include/prism/options.h +146 -280
- data/include/prism/parser.h +356 -867
- data/include/prism/prettyprint.h +6 -9
- data/include/prism/serialize.h +115 -0
- data/include/prism/source.h +155 -0
- data/include/prism/stream.h +28 -0
- data/include/prism/string_query.h +74 -0
- data/include/prism/stringy.h +72 -0
- data/include/prism/version.h +12 -3
- data/include/prism.h +43 -320
- data/lib/prism/compiler.rb +319 -305
- data/lib/prism/desugar_compiler.rb +105 -34
- data/lib/prism/dispatcher.rb +646 -473
- data/lib/prism/dot_visitor.rb +592 -511
- data/lib/prism/dsl.rb +391 -25
- data/lib/prism/ffi.rb +258 -90
- data/lib/prism/inspect_visitor.rb +357 -325
- data/lib/prism/lex_compat.rb +254 -212
- data/lib/prism/mutation_compiler.rb +313 -305
- data/lib/prism/node.rb +20966 -6992
- data/lib/prism/node_ext.rb +180 -187
- data/lib/prism/node_find.rb +215 -0
- data/lib/prism/parse_result/errors.rb +7 -1
- data/lib/prism/parse_result/newlines.rb +276 -8
- data/lib/prism/parse_result.rb +468 -139
- data/lib/prism/pattern.rb +65 -20
- data/lib/prism/reflection.rb +23 -12
- data/lib/prism/relocation.rb +149 -87
- data/lib/prism/serialize.rb +3460 -539
- data/lib/prism/string_query.rb +24 -1
- data/lib/prism/translation/parser/builder.rb +10 -2
- data/lib/prism/translation/parser/compiler.rb +44 -52
- data/lib/prism/translation/parser/lexer.rb +41 -92
- data/lib/prism/translation/parser.rb +1 -1
- data/lib/prism/translation/parser_current.rb +1 -1
- data/lib/prism/translation/ripper/lexer.rb +8 -10
- data/lib/prism/translation/ripper/sexp.rb +2 -10
- data/lib/prism/translation/ripper/shim.rb +2 -0
- data/lib/prism/translation/ripper.rb +967 -209
- data/lib/prism/translation/ruby_parser.rb +73 -316
- data/lib/prism/translation.rb +2 -0
- data/lib/prism/visitor.rb +632 -5
- data/lib/prism.rb +79 -9
- data/prism.gemspec +128 -62
- data/rbi/generated/prism/compiler.rbi +489 -0
- data/rbi/generated/prism/desugar_compiler.rbi +306 -0
- data/rbi/generated/prism/dispatcher.rbi +1138 -0
- data/rbi/generated/prism/dot_visitor.rbi +618 -0
- data/rbi/generated/prism/dsl.rbi +751 -0
- data/rbi/generated/prism/inspect_visitor.rbi +503 -0
- data/rbi/generated/prism/lex_compat.rbi +162 -0
- data/rbi/generated/prism/mutation_compiler.rbi +464 -0
- data/rbi/generated/prism/node.rbi +14407 -0
- data/rbi/generated/prism/node_ext.rbi +259 -0
- data/rbi/generated/prism/node_find.rbi +79 -0
- data/rbi/generated/prism/parse_result/errors.rbi +21 -0
- data/rbi/generated/prism/parse_result/newlines.rbi +208 -0
- data/rbi/generated/prism/parse_result.rbi +776 -0
- data/rbi/generated/prism/pattern.rbi +134 -0
- data/rbi/generated/prism/reflection.rbi +89 -0
- data/rbi/generated/prism/relocation.rbi +329 -0
- data/rbi/generated/prism/serialize.rbi +184 -0
- data/rbi/generated/prism/string_query.rbi +43 -0
- data/rbi/generated/prism/translation.rbi +7 -0
- data/rbi/generated/prism/visitor.rbi +650 -0
- data/rbi/generated/prism.rbi +86 -0
- data/rbi/prism/translation/parser_versions.rbi +5 -0
- data/rbi/rubyvm/node_find.rbi +14 -0
- data/sig/generated/prism/compiler.rbs +492 -0
- data/sig/generated/prism/desugar_compiler.rbs +305 -0
- data/sig/generated/prism/dispatcher.rbs +1292 -0
- data/sig/generated/prism/dot_visitor.rbs +635 -0
- data/sig/generated/prism/dsl.rbs +928 -0
- data/sig/generated/prism/inspect_visitor.rbs +509 -0
- data/sig/generated/prism/lex_compat.rbs +166 -0
- data/sig/{prism → generated/prism}/mutation_compiler.rbs +309 -4
- data/sig/generated/prism/node.rbs +20896 -0
- data/sig/generated/prism/node_ext.rbs +290 -0
- data/sig/generated/prism/node_find.rbs +90 -0
- data/sig/generated/prism/parse_result/errors.rbs +22 -0
- data/sig/generated/prism/parse_result/newlines.rbs +223 -0
- data/sig/generated/prism/parse_result.rbs +871 -0
- data/sig/generated/prism/pattern.rbs +156 -0
- data/sig/generated/prism/reflection.rbs +101 -0
- data/sig/generated/prism/relocation.rbs +428 -0
- data/sig/generated/prism/serialize.rbs +198 -0
- data/sig/generated/prism/string_query.rbs +43 -0
- data/sig/generated/prism/translation.rbs +8 -0
- data/sig/generated/prism/visitor.rbs +1111 -0
- data/sig/generated/prism.rbs +84 -0
- data/sig/manifest.yaml +2 -0
- data/src/arena.c +117 -0
- data/src/{util/pm_buffer.c → buffer.c} +53 -21
- data/src/{util/pm_char.c → char.c} +28 -57
- data/src/comments.c +454 -0
- data/src/constant_pool.c +406 -0
- data/src/diagnostic.c +97 -65
- data/src/encoding.c +8 -3
- data/src/errors_format.c +519 -0
- data/src/{util/pm_integer.c → integer.c} +33 -22
- data/src/json.c +5733 -0
- data/src/line_offset_list.c +100 -0
- data/src/list.c +24 -0
- data/src/{util/pm_memchr.c → memchr.c} +8 -6
- data/src/node.c +3504 -7674
- data/src/options.c +162 -49
- data/src/parser.c +367 -0
- data/src/prettyprint.c +421 -354
- data/src/prism.c +8402 -7161
- data/src/regexp.c +961 -45
- data/src/serialize.c +460 -424
- data/src/source.c +518 -0
- data/src/static_literals.c +111 -43
- data/src/string_query.c +180 -0
- data/src/stringy.c +91 -0
- data/src/{util/pm_strncasecmp.c → strncasecmp.c} +5 -4
- data/src/strpbrk.c +447 -0
- data/src/{token_type.c → tokens.c} +39 -18
- data/src/xxh3.c +292 -0
- metadata +128 -63
- data/ext/prism/api_pack.c +0 -276
- data/include/prism/defines.h +0 -260
- data/include/prism/pack.h +0 -163
- data/include/prism/regexp.h +0 -43
- data/include/prism/util/pm_buffer.h +0 -236
- data/include/prism/util/pm_char.h +0 -204
- data/include/prism/util/pm_constant_pool.h +0 -218
- data/include/prism/util/pm_integer.h +0 -130
- data/include/prism/util/pm_memchr.h +0 -29
- data/include/prism/util/pm_newline_list.h +0 -113
- data/include/prism/util/pm_string.h +0 -200
- data/lib/prism/pack.rb +0 -230
- data/lib/prism/parse_result/comments.rb +0 -188
- data/rbi/prism/compiler.rbi +0 -12
- data/rbi/prism/dsl.rbi +0 -524
- data/rbi/prism/inspect_visitor.rbi +0 -12
- data/rbi/prism/node.rbi +0 -8750
- data/rbi/prism/node_ext.rbi +0 -107
- data/rbi/prism/parse_result.rbi +0 -404
- data/rbi/prism/reflection.rbi +0 -58
- data/rbi/prism/string_query.rbi +0 -12
- data/rbi/prism/visitor.rbi +0 -473
- data/rbi/prism.rbi +0 -63
- data/sig/prism/compiler.rbs +0 -9
- data/sig/prism/dispatcher.rbs +0 -19
- data/sig/prism/dot_visitor.rbs +0 -6
- data/sig/prism/dsl.rbs +0 -351
- data/sig/prism/inspect_visitor.rbs +0 -22
- data/sig/prism/lex_compat.rbs +0 -10
- data/sig/prism/node.rbs +0 -4042
- data/sig/prism/node_ext.rbs +0 -149
- data/sig/prism/pack.rbs +0 -43
- data/sig/prism/parse_result/comments.rbs +0 -38
- data/sig/prism/parse_result.rbs +0 -197
- data/sig/prism/pattern.rbs +0 -13
- data/sig/prism/reflection.rbs +0 -50
- data/sig/prism/relocation.rbs +0 -185
- data/sig/prism/serialize.rbs +0 -8
- data/sig/prism/string_query.rbs +0 -11
- data/sig/prism/visitor.rbs +0 -169
- data/sig/prism.rbs +0 -272
- data/src/pack.c +0 -509
- data/src/util/pm_constant_pool.c +0 -342
- data/src/util/pm_list.c +0 -49
- data/src/util/pm_newline_list.c +0 -125
- data/src/util/pm_string.c +0 -381
- data/src/util/pm_strpbrk.c +0 -206
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
# :markup: markdown
|
|
3
|
+
#--
|
|
4
|
+
# rbs_inline: enabled
|
|
3
5
|
|
|
4
6
|
module Prism
|
|
5
7
|
class DesugarAndWriteNode # :nodoc:
|
|
6
8
|
include DSL
|
|
7
9
|
|
|
8
|
-
attr_reader :node
|
|
10
|
+
attr_reader :node #: ClassVariableAndWriteNode | ConstantAndWriteNode | GlobalVariableAndWriteNode | InstanceVariableAndWriteNode | LocalVariableAndWriteNode
|
|
11
|
+
attr_reader :default_source #: Source
|
|
12
|
+
attr_reader :read_class, :write_class #: Symbol
|
|
13
|
+
attr_reader :arguments #: Hash[Symbol, untyped]
|
|
9
14
|
|
|
15
|
+
#: ((ClassVariableAndWriteNode | ConstantAndWriteNode | GlobalVariableAndWriteNode | InstanceVariableAndWriteNode | LocalVariableAndWriteNode) node, Source default_source, Symbol read_class, Symbol write_class, **untyped arguments) -> void
|
|
10
16
|
def initialize(node, default_source, read_class, write_class, **arguments)
|
|
11
17
|
@node = node
|
|
12
18
|
@default_source = default_source
|
|
@@ -16,6 +22,8 @@ module Prism
|
|
|
16
22
|
end
|
|
17
23
|
|
|
18
24
|
# Desugar `x &&= y` to `x && x = y`
|
|
25
|
+
#
|
|
26
|
+
#: () -> node
|
|
19
27
|
def compile
|
|
20
28
|
and_node(
|
|
21
29
|
location: node.location,
|
|
@@ -36,8 +44,12 @@ module Prism
|
|
|
36
44
|
class DesugarOrWriteDefinedNode # :nodoc:
|
|
37
45
|
include DSL
|
|
38
46
|
|
|
39
|
-
attr_reader :node
|
|
47
|
+
attr_reader :node #: ClassVariableOrWriteNode | ConstantOrWriteNode | GlobalVariableOrWriteNode
|
|
48
|
+
attr_reader :default_source #: Source
|
|
49
|
+
attr_reader :read_class, :write_class #: Symbol
|
|
50
|
+
attr_reader :arguments #: Hash[Symbol, untyped]
|
|
40
51
|
|
|
52
|
+
#: ((ClassVariableOrWriteNode | ConstantOrWriteNode | GlobalVariableOrWriteNode) node, Source default_source, Symbol read_class, Symbol write_class, **untyped arguments) -> void
|
|
41
53
|
def initialize(node, default_source, read_class, write_class, **arguments)
|
|
42
54
|
@node = node
|
|
43
55
|
@default_source = default_source
|
|
@@ -47,6 +59,8 @@ module Prism
|
|
|
47
59
|
end
|
|
48
60
|
|
|
49
61
|
# Desugar `x ||= y` to `defined?(x) ? x : x = y`
|
|
62
|
+
#
|
|
63
|
+
#: () -> node
|
|
50
64
|
def compile
|
|
51
65
|
if_node(
|
|
52
66
|
location: node.location,
|
|
@@ -87,8 +101,12 @@ module Prism
|
|
|
87
101
|
class DesugarOperatorWriteNode # :nodoc:
|
|
88
102
|
include DSL
|
|
89
103
|
|
|
90
|
-
attr_reader :node
|
|
104
|
+
attr_reader :node #: ClassVariableOperatorWriteNode | ConstantOperatorWriteNode | GlobalVariableOperatorWriteNode | InstanceVariableOperatorWriteNode | LocalVariableOperatorWriteNode
|
|
105
|
+
attr_reader :default_source #: Source
|
|
106
|
+
attr_reader :read_class, :write_class #: Symbol
|
|
107
|
+
attr_reader :arguments #: Hash[Symbol, untyped]
|
|
91
108
|
|
|
109
|
+
#: ((ClassVariableOperatorWriteNode | ConstantOperatorWriteNode | GlobalVariableOperatorWriteNode | InstanceVariableOperatorWriteNode | LocalVariableOperatorWriteNode) node, Source default_source, Symbol read_class, Symbol write_class, **untyped arguments) -> void
|
|
92
110
|
def initialize(node, default_source, read_class, write_class, **arguments)
|
|
93
111
|
@node = node
|
|
94
112
|
@default_source = default_source
|
|
@@ -98,6 +116,8 @@ module Prism
|
|
|
98
116
|
end
|
|
99
117
|
|
|
100
118
|
# Desugar `x += y` to `x = x + y`
|
|
119
|
+
#
|
|
120
|
+
#: () -> node
|
|
101
121
|
def compile
|
|
102
122
|
binary_operator_loc = node.binary_operator_loc.chop
|
|
103
123
|
|
|
@@ -131,8 +151,12 @@ module Prism
|
|
|
131
151
|
class DesugarOrWriteNode # :nodoc:
|
|
132
152
|
include DSL
|
|
133
153
|
|
|
134
|
-
attr_reader :node
|
|
154
|
+
attr_reader :node #: InstanceVariableOrWriteNode | LocalVariableOrWriteNode
|
|
155
|
+
attr_reader :default_source #: Source
|
|
156
|
+
attr_reader :read_class, :write_class #: Symbol
|
|
157
|
+
attr_reader :arguments #: Hash[Symbol, untyped]
|
|
135
158
|
|
|
159
|
+
#: ((InstanceVariableOrWriteNode | LocalVariableOrWriteNode) node, Source default_source, Symbol read_class, Symbol write_class, **untyped arguments) -> void
|
|
136
160
|
def initialize(node, default_source, read_class, write_class, **arguments)
|
|
137
161
|
@node = node
|
|
138
162
|
@default_source = default_source
|
|
@@ -142,6 +166,8 @@ module Prism
|
|
|
142
166
|
end
|
|
143
167
|
|
|
144
168
|
# Desugar `x ||= y` to `x || x = y`
|
|
169
|
+
#
|
|
170
|
+
#: () -> node
|
|
145
171
|
def compile
|
|
146
172
|
or_node(
|
|
147
173
|
location: node.location,
|
|
@@ -162,90 +188,105 @@ module Prism
|
|
|
162
188
|
private_constant :DesugarAndWriteNode, :DesugarOrWriteNode, :DesugarOrWriteDefinedNode, :DesugarOperatorWriteNode
|
|
163
189
|
|
|
164
190
|
class ClassVariableAndWriteNode
|
|
191
|
+
#: () -> node
|
|
165
192
|
def desugar # :nodoc:
|
|
166
193
|
DesugarAndWriteNode.new(self, source, :class_variable_read_node, :class_variable_write_node, name: name).compile
|
|
167
194
|
end
|
|
168
195
|
end
|
|
169
196
|
|
|
170
197
|
class ClassVariableOrWriteNode
|
|
198
|
+
#: () -> node
|
|
171
199
|
def desugar # :nodoc:
|
|
172
200
|
DesugarOrWriteDefinedNode.new(self, source, :class_variable_read_node, :class_variable_write_node, name: name).compile
|
|
173
201
|
end
|
|
174
202
|
end
|
|
175
203
|
|
|
176
204
|
class ClassVariableOperatorWriteNode
|
|
205
|
+
#: () -> node
|
|
177
206
|
def desugar # :nodoc:
|
|
178
207
|
DesugarOperatorWriteNode.new(self, source, :class_variable_read_node, :class_variable_write_node, name: name).compile
|
|
179
208
|
end
|
|
180
209
|
end
|
|
181
210
|
|
|
182
211
|
class ConstantAndWriteNode
|
|
212
|
+
#: () -> node
|
|
183
213
|
def desugar # :nodoc:
|
|
184
214
|
DesugarAndWriteNode.new(self, source, :constant_read_node, :constant_write_node, name: name).compile
|
|
185
215
|
end
|
|
186
216
|
end
|
|
187
217
|
|
|
188
218
|
class ConstantOrWriteNode
|
|
219
|
+
#: () -> node
|
|
189
220
|
def desugar # :nodoc:
|
|
190
221
|
DesugarOrWriteDefinedNode.new(self, source, :constant_read_node, :constant_write_node, name: name).compile
|
|
191
222
|
end
|
|
192
223
|
end
|
|
193
224
|
|
|
194
225
|
class ConstantOperatorWriteNode
|
|
226
|
+
#: () -> node
|
|
195
227
|
def desugar # :nodoc:
|
|
196
228
|
DesugarOperatorWriteNode.new(self, source, :constant_read_node, :constant_write_node, name: name).compile
|
|
197
229
|
end
|
|
198
230
|
end
|
|
199
231
|
|
|
200
232
|
class GlobalVariableAndWriteNode
|
|
233
|
+
#: () -> node
|
|
201
234
|
def desugar # :nodoc:
|
|
202
235
|
DesugarAndWriteNode.new(self, source, :global_variable_read_node, :global_variable_write_node, name: name).compile
|
|
203
236
|
end
|
|
204
237
|
end
|
|
205
238
|
|
|
206
239
|
class GlobalVariableOrWriteNode
|
|
240
|
+
#: () -> node
|
|
207
241
|
def desugar # :nodoc:
|
|
208
242
|
DesugarOrWriteDefinedNode.new(self, source, :global_variable_read_node, :global_variable_write_node, name: name).compile
|
|
209
243
|
end
|
|
210
244
|
end
|
|
211
245
|
|
|
212
246
|
class GlobalVariableOperatorWriteNode
|
|
247
|
+
#: () -> node
|
|
213
248
|
def desugar # :nodoc:
|
|
214
249
|
DesugarOperatorWriteNode.new(self, source, :global_variable_read_node, :global_variable_write_node, name: name).compile
|
|
215
250
|
end
|
|
216
251
|
end
|
|
217
252
|
|
|
218
253
|
class InstanceVariableAndWriteNode
|
|
254
|
+
#: () -> node
|
|
219
255
|
def desugar # :nodoc:
|
|
220
256
|
DesugarAndWriteNode.new(self, source, :instance_variable_read_node, :instance_variable_write_node, name: name).compile
|
|
221
257
|
end
|
|
222
258
|
end
|
|
223
259
|
|
|
224
260
|
class InstanceVariableOrWriteNode
|
|
261
|
+
#: () -> node
|
|
225
262
|
def desugar # :nodoc:
|
|
226
263
|
DesugarOrWriteNode.new(self, source, :instance_variable_read_node, :instance_variable_write_node, name: name).compile
|
|
227
264
|
end
|
|
228
265
|
end
|
|
229
266
|
|
|
230
267
|
class InstanceVariableOperatorWriteNode
|
|
268
|
+
#: () -> node
|
|
231
269
|
def desugar # :nodoc:
|
|
232
270
|
DesugarOperatorWriteNode.new(self, source, :instance_variable_read_node, :instance_variable_write_node, name: name).compile
|
|
233
271
|
end
|
|
234
272
|
end
|
|
235
273
|
|
|
236
274
|
class LocalVariableAndWriteNode
|
|
275
|
+
#: () -> node
|
|
237
276
|
def desugar # :nodoc:
|
|
238
277
|
DesugarAndWriteNode.new(self, source, :local_variable_read_node, :local_variable_write_node, name: name, depth: depth).compile
|
|
239
278
|
end
|
|
240
279
|
end
|
|
241
280
|
|
|
242
281
|
class LocalVariableOrWriteNode
|
|
282
|
+
#: () -> node
|
|
243
283
|
def desugar # :nodoc:
|
|
244
284
|
DesugarOrWriteNode.new(self, source, :local_variable_read_node, :local_variable_write_node, name: name, depth: depth).compile
|
|
245
285
|
end
|
|
246
286
|
end
|
|
247
287
|
|
|
248
288
|
class LocalVariableOperatorWriteNode
|
|
289
|
+
#: () -> node
|
|
249
290
|
def desugar # :nodoc:
|
|
250
291
|
DesugarOperatorWriteNode.new(self, source, :local_variable_read_node, :local_variable_write_node, name: name, depth: depth).compile
|
|
251
292
|
end
|
|
@@ -254,137 +295,167 @@ module Prism
|
|
|
254
295
|
# DesugarCompiler is a compiler that desugars Ruby code into a more primitive
|
|
255
296
|
# form. This is useful for consumers that want to deal with fewer node types.
|
|
256
297
|
class DesugarCompiler < MutationCompiler
|
|
257
|
-
#
|
|
298
|
+
# `@@foo &&= bar`
|
|
258
299
|
#
|
|
259
300
|
# becomes
|
|
260
301
|
#
|
|
261
|
-
#
|
|
302
|
+
# `@@foo && @@foo = bar`
|
|
303
|
+
#
|
|
304
|
+
#: (ClassVariableAndWriteNode node) -> node
|
|
262
305
|
def visit_class_variable_and_write_node(node)
|
|
263
306
|
node.desugar
|
|
264
307
|
end
|
|
265
308
|
|
|
266
|
-
#
|
|
309
|
+
# `@@foo ||= bar`
|
|
267
310
|
#
|
|
268
311
|
# becomes
|
|
269
312
|
#
|
|
270
|
-
# defined?(@@foo) ? @@foo : @@foo = bar
|
|
313
|
+
# `defined?(@@foo) ? @@foo : @@foo = bar`
|
|
314
|
+
#
|
|
315
|
+
#: (ClassVariableOrWriteNode node) -> node
|
|
271
316
|
def visit_class_variable_or_write_node(node)
|
|
272
317
|
node.desugar
|
|
273
318
|
end
|
|
274
319
|
|
|
275
|
-
#
|
|
320
|
+
# `@@foo += bar`
|
|
276
321
|
#
|
|
277
322
|
# becomes
|
|
278
323
|
#
|
|
279
|
-
#
|
|
324
|
+
# `@@foo = @@foo + bar`
|
|
325
|
+
#
|
|
326
|
+
#: (ClassVariableOperatorWriteNode node) -> node
|
|
280
327
|
def visit_class_variable_operator_write_node(node)
|
|
281
328
|
node.desugar
|
|
282
329
|
end
|
|
283
330
|
|
|
284
|
-
# Foo &&= bar
|
|
331
|
+
# `Foo &&= bar`
|
|
285
332
|
#
|
|
286
333
|
# becomes
|
|
287
334
|
#
|
|
288
|
-
# Foo && Foo = bar
|
|
335
|
+
# `Foo && Foo = bar`
|
|
336
|
+
#
|
|
337
|
+
#: (ConstantAndWriteNode node) -> node
|
|
289
338
|
def visit_constant_and_write_node(node)
|
|
290
339
|
node.desugar
|
|
291
340
|
end
|
|
292
341
|
|
|
293
|
-
# Foo ||= bar
|
|
342
|
+
# `Foo ||= bar`
|
|
294
343
|
#
|
|
295
344
|
# becomes
|
|
296
345
|
#
|
|
297
|
-
# defined?(Foo) ? Foo : Foo = bar
|
|
346
|
+
# `defined?(Foo) ? Foo : Foo = bar`
|
|
347
|
+
#
|
|
348
|
+
#: (ConstantOrWriteNode node) -> node
|
|
298
349
|
def visit_constant_or_write_node(node)
|
|
299
350
|
node.desugar
|
|
300
351
|
end
|
|
301
352
|
|
|
302
|
-
# Foo += bar
|
|
353
|
+
# `Foo += bar`
|
|
303
354
|
#
|
|
304
355
|
# becomes
|
|
305
356
|
#
|
|
306
|
-
# Foo = Foo + bar
|
|
357
|
+
# `Foo = Foo + bar`
|
|
358
|
+
#
|
|
359
|
+
#: (ConstantOperatorWriteNode node) -> node
|
|
307
360
|
def visit_constant_operator_write_node(node)
|
|
308
361
|
node.desugar
|
|
309
362
|
end
|
|
310
363
|
|
|
311
|
-
#
|
|
364
|
+
# `$foo &&= bar`
|
|
312
365
|
#
|
|
313
366
|
# becomes
|
|
314
367
|
#
|
|
315
|
-
#
|
|
368
|
+
# `$foo && $foo = bar`
|
|
369
|
+
#
|
|
370
|
+
#: (GlobalVariableAndWriteNode node) -> node
|
|
316
371
|
def visit_global_variable_and_write_node(node)
|
|
317
372
|
node.desugar
|
|
318
373
|
end
|
|
319
374
|
|
|
320
|
-
#
|
|
375
|
+
# `$foo ||= bar`
|
|
321
376
|
#
|
|
322
377
|
# becomes
|
|
323
378
|
#
|
|
324
|
-
# defined?($foo) ? $foo : $foo = bar
|
|
379
|
+
# `defined?($foo) ? $foo : $foo = bar`
|
|
380
|
+
#
|
|
381
|
+
#: (GlobalVariableOrWriteNode node) -> node
|
|
325
382
|
def visit_global_variable_or_write_node(node)
|
|
326
383
|
node.desugar
|
|
327
384
|
end
|
|
328
385
|
|
|
329
|
-
#
|
|
386
|
+
# `$foo += bar`
|
|
330
387
|
#
|
|
331
388
|
# becomes
|
|
332
389
|
#
|
|
333
|
-
#
|
|
390
|
+
# `$foo = $foo + bar`
|
|
391
|
+
#
|
|
392
|
+
#: (GlobalVariableOperatorWriteNode node) -> node
|
|
334
393
|
def visit_global_variable_operator_write_node(node)
|
|
335
394
|
node.desugar
|
|
336
395
|
end
|
|
337
396
|
|
|
338
|
-
#
|
|
397
|
+
# `@foo &&= bar`
|
|
339
398
|
#
|
|
340
399
|
# becomes
|
|
341
400
|
#
|
|
342
|
-
#
|
|
401
|
+
# `@foo && @foo = bar`
|
|
402
|
+
#
|
|
403
|
+
#: (InstanceVariableAndWriteNode node) -> node
|
|
343
404
|
def visit_instance_variable_and_write_node(node)
|
|
344
405
|
node.desugar
|
|
345
406
|
end
|
|
346
407
|
|
|
347
|
-
#
|
|
408
|
+
# `@foo ||= bar`
|
|
348
409
|
#
|
|
349
410
|
# becomes
|
|
350
411
|
#
|
|
351
|
-
#
|
|
412
|
+
# `@foo || @foo = bar`
|
|
413
|
+
#
|
|
414
|
+
#: (InstanceVariableOrWriteNode node) -> node
|
|
352
415
|
def visit_instance_variable_or_write_node(node)
|
|
353
416
|
node.desugar
|
|
354
417
|
end
|
|
355
418
|
|
|
356
|
-
#
|
|
419
|
+
# `@foo += bar`
|
|
357
420
|
#
|
|
358
421
|
# becomes
|
|
359
422
|
#
|
|
360
|
-
#
|
|
423
|
+
# `@foo = @foo + bar`
|
|
424
|
+
#
|
|
425
|
+
#: (InstanceVariableOperatorWriteNode node) -> node
|
|
361
426
|
def visit_instance_variable_operator_write_node(node)
|
|
362
427
|
node.desugar
|
|
363
428
|
end
|
|
364
429
|
|
|
365
|
-
# foo &&= bar
|
|
430
|
+
# `foo &&= bar`
|
|
366
431
|
#
|
|
367
432
|
# becomes
|
|
368
433
|
#
|
|
369
|
-
# foo && foo = bar
|
|
434
|
+
# `foo && foo = bar`
|
|
435
|
+
#
|
|
436
|
+
#: (LocalVariableAndWriteNode node) -> node
|
|
370
437
|
def visit_local_variable_and_write_node(node)
|
|
371
438
|
node.desugar
|
|
372
439
|
end
|
|
373
440
|
|
|
374
|
-
# foo ||= bar
|
|
441
|
+
# `foo ||= bar`
|
|
375
442
|
#
|
|
376
443
|
# becomes
|
|
377
444
|
#
|
|
378
|
-
# foo || foo = bar
|
|
445
|
+
# `foo || foo = bar`
|
|
446
|
+
#
|
|
447
|
+
#: (LocalVariableOrWriteNode node) -> node
|
|
379
448
|
def visit_local_variable_or_write_node(node)
|
|
380
449
|
node.desugar
|
|
381
450
|
end
|
|
382
451
|
|
|
383
|
-
# foo += bar
|
|
452
|
+
# `foo += bar`
|
|
384
453
|
#
|
|
385
454
|
# becomes
|
|
386
455
|
#
|
|
387
|
-
# foo = foo + bar
|
|
456
|
+
# `foo = foo + bar`
|
|
457
|
+
#
|
|
458
|
+
#: (LocalVariableOperatorWriteNode node) -> node
|
|
388
459
|
def visit_local_variable_operator_write_node(node)
|
|
389
460
|
node.desugar
|
|
390
461
|
end
|