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
data/lib/prism/node_ext.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
# :markup: markdown
|
|
3
|
+
#--
|
|
4
|
+
# rbs_inline: enabled
|
|
3
5
|
|
|
4
6
|
#--
|
|
5
7
|
# Here we are reopening the prism module to provide methods on nodes that aren't
|
|
@@ -7,9 +9,9 @@
|
|
|
7
9
|
#++
|
|
8
10
|
module Prism
|
|
9
11
|
class Node
|
|
12
|
+
#: (*String replacements) -> void
|
|
10
13
|
def deprecated(*replacements) # :nodoc:
|
|
11
|
-
location = caller_locations(1, 1)
|
|
12
|
-
location = location[0].label if location
|
|
14
|
+
location = caller_locations(1, 1)&.[](0)&.label
|
|
13
15
|
suggest = replacements.map { |replacement| "#{self.class}##{replacement}" }
|
|
14
16
|
|
|
15
17
|
warn(<<~MSG, uplevel: 1, category: :deprecated)
|
|
@@ -23,7 +25,9 @@ module Prism
|
|
|
23
25
|
module RegularExpressionOptions # :nodoc:
|
|
24
26
|
# Returns a numeric value that represents the flags that were used to create
|
|
25
27
|
# the regular expression.
|
|
26
|
-
|
|
28
|
+
#
|
|
29
|
+
#: (Integer flags) -> Integer
|
|
30
|
+
def self.options(flags)
|
|
27
31
|
o = 0
|
|
28
32
|
o |= Regexp::IGNORECASE if flags.anybits?(RegularExpressionFlags::IGNORE_CASE)
|
|
29
33
|
o |= Regexp::EXTENDED if flags.anybits?(RegularExpressionFlags::EXTENDED)
|
|
@@ -35,43 +39,87 @@ module Prism
|
|
|
35
39
|
end
|
|
36
40
|
|
|
37
41
|
class InterpolatedMatchLastLineNode < Node
|
|
38
|
-
|
|
42
|
+
# Returns a numeric value that represents the flags that were used to create
|
|
43
|
+
# the regular expression.
|
|
44
|
+
#
|
|
45
|
+
#: () -> Integer
|
|
46
|
+
def options
|
|
47
|
+
RegularExpressionOptions.options(flags)
|
|
48
|
+
end
|
|
39
49
|
end
|
|
40
50
|
|
|
41
51
|
class InterpolatedRegularExpressionNode < Node
|
|
42
|
-
|
|
52
|
+
# Returns a numeric value that represents the flags that were used to create
|
|
53
|
+
# the regular expression.
|
|
54
|
+
#
|
|
55
|
+
#: () -> Integer
|
|
56
|
+
def options
|
|
57
|
+
RegularExpressionOptions.options(flags)
|
|
58
|
+
end
|
|
43
59
|
end
|
|
44
60
|
|
|
45
61
|
class MatchLastLineNode < Node
|
|
46
|
-
|
|
62
|
+
# Returns a numeric value that represents the flags that were used to create
|
|
63
|
+
# the regular expression.
|
|
64
|
+
#
|
|
65
|
+
#: () -> Integer
|
|
66
|
+
def options
|
|
67
|
+
RegularExpressionOptions.options(flags)
|
|
68
|
+
end
|
|
47
69
|
end
|
|
48
70
|
|
|
49
71
|
class RegularExpressionNode < Node
|
|
50
|
-
|
|
72
|
+
# Returns a numeric value that represents the flags that were used to create
|
|
73
|
+
# the regular expression.
|
|
74
|
+
#
|
|
75
|
+
#: () -> Integer
|
|
76
|
+
def options
|
|
77
|
+
RegularExpressionOptions.options(flags)
|
|
78
|
+
end
|
|
51
79
|
end
|
|
52
80
|
|
|
53
81
|
private_constant :RegularExpressionOptions
|
|
54
82
|
|
|
55
83
|
module HeredocQuery # :nodoc:
|
|
56
84
|
# Returns true if this node was represented as a heredoc in the source code.
|
|
57
|
-
|
|
85
|
+
#
|
|
86
|
+
#: (String? opening) -> bool?
|
|
87
|
+
def self.heredoc?(opening)
|
|
88
|
+
# @type self: InterpolatedStringNode | InterpolatedXStringNode | StringNode | XStringNode
|
|
58
89
|
opening&.start_with?("<<")
|
|
59
90
|
end
|
|
60
91
|
end
|
|
61
92
|
|
|
62
93
|
class InterpolatedStringNode < Node
|
|
63
|
-
|
|
94
|
+
# Returns true if this node was represented as a heredoc in the source code.
|
|
95
|
+
#
|
|
96
|
+
#: () -> bool?
|
|
97
|
+
def heredoc?
|
|
98
|
+
HeredocQuery.heredoc?(opening)
|
|
99
|
+
end
|
|
64
100
|
end
|
|
65
101
|
|
|
66
102
|
class InterpolatedXStringNode < Node
|
|
67
|
-
|
|
103
|
+
# Returns true if this node was represented as a heredoc in the source code.
|
|
104
|
+
#
|
|
105
|
+
#: () -> bool?
|
|
106
|
+
def heredoc?
|
|
107
|
+
HeredocQuery.heredoc?(opening)
|
|
108
|
+
end
|
|
68
109
|
end
|
|
69
110
|
|
|
70
111
|
class StringNode < Node
|
|
71
|
-
|
|
112
|
+
# Returns true if this node was represented as a heredoc in the source code.
|
|
113
|
+
#
|
|
114
|
+
#: () -> bool?
|
|
115
|
+
def heredoc?
|
|
116
|
+
HeredocQuery.heredoc?(opening)
|
|
117
|
+
end
|
|
72
118
|
|
|
73
119
|
# Occasionally it's helpful to treat a string as if it were interpolated so
|
|
74
120
|
# that there's a consistent interface for working with strings.
|
|
121
|
+
#
|
|
122
|
+
#: () -> InterpolatedStringNode
|
|
75
123
|
def to_interpolated
|
|
76
124
|
InterpolatedStringNode.new(
|
|
77
125
|
source,
|
|
@@ -86,10 +134,17 @@ module Prism
|
|
|
86
134
|
end
|
|
87
135
|
|
|
88
136
|
class XStringNode < Node
|
|
89
|
-
|
|
137
|
+
# Returns true if this node was represented as a heredoc in the source code.
|
|
138
|
+
#
|
|
139
|
+
#: () -> bool?
|
|
140
|
+
def heredoc?
|
|
141
|
+
HeredocQuery.heredoc?(opening)
|
|
142
|
+
end
|
|
90
143
|
|
|
91
144
|
# Occasionally it's helpful to treat a string as if it were interpolated so
|
|
92
145
|
# that there's a consistent interface for working with strings.
|
|
146
|
+
#
|
|
147
|
+
#: () -> InterpolatedXStringNode
|
|
93
148
|
def to_interpolated
|
|
94
149
|
InterpolatedXStringNode.new(
|
|
95
150
|
source,
|
|
@@ -107,6 +162,8 @@ module Prism
|
|
|
107
162
|
|
|
108
163
|
class ImaginaryNode < Node
|
|
109
164
|
# Returns the value of the node as a Ruby Complex.
|
|
165
|
+
#
|
|
166
|
+
#: () -> Complex
|
|
110
167
|
def value
|
|
111
168
|
Complex(0, numeric.value)
|
|
112
169
|
end
|
|
@@ -114,31 +171,25 @@ module Prism
|
|
|
114
171
|
|
|
115
172
|
class RationalNode < Node
|
|
116
173
|
# Returns the value of the node as a Ruby Rational.
|
|
174
|
+
#
|
|
175
|
+
#: () -> Rational
|
|
117
176
|
def value
|
|
118
177
|
Rational(numerator, denominator)
|
|
119
178
|
end
|
|
120
|
-
|
|
121
|
-
# Returns the value of the node as an IntegerNode or a FloatNode. This
|
|
122
|
-
# method is deprecated in favor of #value or #numerator/#denominator.
|
|
123
|
-
def numeric
|
|
124
|
-
deprecated("value", "numerator", "denominator")
|
|
125
|
-
|
|
126
|
-
if denominator == 1
|
|
127
|
-
IntegerNode.new(source, -1, location.chop, flags, numerator)
|
|
128
|
-
else
|
|
129
|
-
FloatNode.new(source, -1, location.chop, 0, numerator.to_f / denominator)
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
179
|
end
|
|
133
180
|
|
|
134
181
|
class ConstantReadNode < Node
|
|
135
182
|
# Returns the list of parts for the full name of this constant.
|
|
136
183
|
# For example: [:Foo]
|
|
184
|
+
#
|
|
185
|
+
#: () -> Array[Symbol]
|
|
137
186
|
def full_name_parts
|
|
138
187
|
[name]
|
|
139
188
|
end
|
|
140
189
|
|
|
141
190
|
# Returns the full name of this constant. For example: "Foo"
|
|
191
|
+
#
|
|
192
|
+
#: () -> String
|
|
142
193
|
def full_name
|
|
143
194
|
name.to_s
|
|
144
195
|
end
|
|
@@ -147,11 +198,15 @@ module Prism
|
|
|
147
198
|
class ConstantWriteNode < Node
|
|
148
199
|
# Returns the list of parts for the full name of this constant.
|
|
149
200
|
# For example: [:Foo]
|
|
201
|
+
#
|
|
202
|
+
#: () -> Array[Symbol]
|
|
150
203
|
def full_name_parts
|
|
151
204
|
[name]
|
|
152
205
|
end
|
|
153
206
|
|
|
154
207
|
# Returns the full name of this constant. For example: "Foo"
|
|
208
|
+
#
|
|
209
|
+
#: () -> String
|
|
155
210
|
def full_name
|
|
156
211
|
name.to_s
|
|
157
212
|
end
|
|
@@ -166,13 +221,15 @@ module Prism
|
|
|
166
221
|
# local variable
|
|
167
222
|
class DynamicPartsInConstantPathError < StandardError; end
|
|
168
223
|
|
|
169
|
-
# An error class raised when
|
|
224
|
+
# An error class raised when error recovery nodes are found while computing a
|
|
170
225
|
# constant path's full name. For example:
|
|
171
226
|
# Foo:: -> raises because the constant path is missing the last part
|
|
172
|
-
class
|
|
227
|
+
class ErrorRecoveryNodesInConstantPathError < StandardError; end
|
|
173
228
|
|
|
174
229
|
# Returns the list of parts for the full name of this constant path.
|
|
175
230
|
# For example: [:Foo, :Bar]
|
|
231
|
+
#
|
|
232
|
+
#: () -> Array[Symbol]
|
|
176
233
|
def full_name_parts
|
|
177
234
|
parts = [] #: Array[Symbol]
|
|
178
235
|
current = self #: node?
|
|
@@ -180,7 +237,7 @@ module Prism
|
|
|
180
237
|
while current.is_a?(ConstantPathNode)
|
|
181
238
|
name = current.name
|
|
182
239
|
if name.nil?
|
|
183
|
-
raise
|
|
240
|
+
raise ErrorRecoveryNodesInConstantPathError, "Constant path contains error recovery nodes. Cannot compute full name"
|
|
184
241
|
end
|
|
185
242
|
|
|
186
243
|
parts.unshift(name)
|
|
@@ -195,30 +252,21 @@ module Prism
|
|
|
195
252
|
end
|
|
196
253
|
|
|
197
254
|
# Returns the full name of this constant path. For example: "Foo::Bar"
|
|
255
|
+
#
|
|
256
|
+
#: () -> String
|
|
198
257
|
def full_name
|
|
199
258
|
full_name_parts.join("::")
|
|
200
259
|
end
|
|
201
|
-
|
|
202
|
-
# Previously, we had a child node on this class that contained either a
|
|
203
|
-
# constant read or a missing node. To not cause a breaking change, we
|
|
204
|
-
# continue to supply that API.
|
|
205
|
-
def child
|
|
206
|
-
deprecated("name", "name_loc")
|
|
207
|
-
|
|
208
|
-
if name
|
|
209
|
-
ConstantReadNode.new(source, -1, name_loc, 0, name)
|
|
210
|
-
else
|
|
211
|
-
MissingNode.new(source, -1, location, 0)
|
|
212
|
-
end
|
|
213
|
-
end
|
|
214
260
|
end
|
|
215
261
|
|
|
216
262
|
class ConstantPathTargetNode < Node
|
|
217
263
|
# Returns the list of parts for the full name of this constant path.
|
|
218
264
|
# For example: [:Foo, :Bar]
|
|
265
|
+
#
|
|
266
|
+
#: () -> Array[Symbol]
|
|
219
267
|
def full_name_parts
|
|
220
268
|
parts =
|
|
221
|
-
case parent
|
|
269
|
+
case (parent = self.parent)
|
|
222
270
|
when ConstantPathNode, ConstantReadNode
|
|
223
271
|
parent.full_name_parts
|
|
224
272
|
when nil
|
|
@@ -228,40 +276,33 @@ module Prism
|
|
|
228
276
|
raise ConstantPathNode::DynamicPartsInConstantPathError, "Constant target path contains dynamic parts. Cannot compute full name"
|
|
229
277
|
end
|
|
230
278
|
|
|
231
|
-
if name.nil?
|
|
232
|
-
raise ConstantPathNode::
|
|
279
|
+
if (name = self.name).nil?
|
|
280
|
+
raise ConstantPathNode::ErrorRecoveryNodesInConstantPathError, "Constant target path contains error recovery nodes. Cannot compute full name"
|
|
233
281
|
end
|
|
234
282
|
|
|
235
283
|
parts.push(name)
|
|
236
284
|
end
|
|
237
285
|
|
|
238
286
|
# Returns the full name of this constant path. For example: "Foo::Bar"
|
|
287
|
+
#
|
|
288
|
+
#: () -> String
|
|
239
289
|
def full_name
|
|
240
290
|
full_name_parts.join("::")
|
|
241
291
|
end
|
|
242
|
-
|
|
243
|
-
# Previously, we had a child node on this class that contained either a
|
|
244
|
-
# constant read or a missing node. To not cause a breaking change, we
|
|
245
|
-
# continue to supply that API.
|
|
246
|
-
def child
|
|
247
|
-
deprecated("name", "name_loc")
|
|
248
|
-
|
|
249
|
-
if name
|
|
250
|
-
ConstantReadNode.new(source, -1, name_loc, 0, name)
|
|
251
|
-
else
|
|
252
|
-
MissingNode.new(source, -1, location, 0)
|
|
253
|
-
end
|
|
254
|
-
end
|
|
255
292
|
end
|
|
256
293
|
|
|
257
294
|
class ConstantTargetNode < Node
|
|
258
295
|
# Returns the list of parts for the full name of this constant.
|
|
259
296
|
# For example: [:Foo]
|
|
297
|
+
#
|
|
298
|
+
#: () -> Array[Symbol]
|
|
260
299
|
def full_name_parts
|
|
261
300
|
[name]
|
|
262
301
|
end
|
|
263
302
|
|
|
264
303
|
# Returns the full name of this constant. For example: "Foo"
|
|
304
|
+
#
|
|
305
|
+
#: () -> String
|
|
265
306
|
def full_name
|
|
266
307
|
name.to_s
|
|
267
308
|
end
|
|
@@ -269,6 +310,8 @@ module Prism
|
|
|
269
310
|
|
|
270
311
|
class ParametersNode < Node
|
|
271
312
|
# Mirrors the Method#parameters method.
|
|
313
|
+
#
|
|
314
|
+
#: () -> Array[[Symbol, Symbol] | [Symbol]]
|
|
272
315
|
def signature
|
|
273
316
|
names = [] #: Array[[Symbol, Symbol] | [Symbol]]
|
|
274
317
|
|
|
@@ -278,7 +321,7 @@ module Prism
|
|
|
278
321
|
|
|
279
322
|
optionals.each { |param| names << [:opt, param.name] }
|
|
280
323
|
|
|
281
|
-
if rest
|
|
324
|
+
if (rest = self.rest).is_a?(RestParameterNode)
|
|
282
325
|
names << [:rest, rest.name || :*]
|
|
283
326
|
end
|
|
284
327
|
|
|
@@ -286,8 +329,7 @@ module Prism
|
|
|
286
329
|
case param
|
|
287
330
|
when MultiTargetNode
|
|
288
331
|
names << [:req]
|
|
289
|
-
when
|
|
290
|
-
# Invalid syntax, e.g. "def f(**nil, ...)" moves the NoKeywordsParameterNode to posts
|
|
332
|
+
when ErrorRecoveryNode
|
|
291
333
|
raise "Invalid syntax"
|
|
292
334
|
else
|
|
293
335
|
names << [:req, param.name]
|
|
@@ -307,7 +349,7 @@ module Prism
|
|
|
307
349
|
|
|
308
350
|
keyopt.each { |param| names << [:key, param.name] }
|
|
309
351
|
|
|
310
|
-
case keyword_rest
|
|
352
|
+
case (keyword_rest = self.keyword_rest)
|
|
311
353
|
when ForwardingParameterNode
|
|
312
354
|
names.concat([[:rest, :*], [:keyrest, :**], [:block, :&]])
|
|
313
355
|
when KeywordRestParameterNode
|
|
@@ -316,7 +358,13 @@ module Prism
|
|
|
316
358
|
names << [:nokey]
|
|
317
359
|
end
|
|
318
360
|
|
|
319
|
-
|
|
361
|
+
case (block = self.block)
|
|
362
|
+
when BlockParameterNode
|
|
363
|
+
names << [:block, block.name || :&]
|
|
364
|
+
when NoBlockParameterNode
|
|
365
|
+
names << [:noblock]
|
|
366
|
+
end
|
|
367
|
+
|
|
320
368
|
names
|
|
321
369
|
end
|
|
322
370
|
end
|
|
@@ -331,181 +379,126 @@ module Prism
|
|
|
331
379
|
# can be any amount of space between the message and the = sign. However,
|
|
332
380
|
# sometimes you want the location of the full message including the inner
|
|
333
381
|
# space and the = sign. This method provides that.
|
|
382
|
+
#
|
|
383
|
+
#: () -> Location?
|
|
334
384
|
def full_message_loc
|
|
335
385
|
attribute_write? ? message_loc&.adjoin("=") : message_loc
|
|
336
386
|
end
|
|
337
387
|
end
|
|
338
388
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
def
|
|
343
|
-
|
|
344
|
-
binary_operator
|
|
389
|
+
# :stopdoc:
|
|
390
|
+
class InNode < Node
|
|
391
|
+
#: () -> String
|
|
392
|
+
def in # :nodoc
|
|
393
|
+
in_keyword
|
|
345
394
|
end
|
|
346
395
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
deprecated("binary_operator_loc")
|
|
351
|
-
binary_operator_loc
|
|
396
|
+
#: () -> Location
|
|
397
|
+
def in_loc # :nodoc
|
|
398
|
+
in_keyword_loc
|
|
352
399
|
end
|
|
353
|
-
end
|
|
354
400
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
def operator
|
|
359
|
-
deprecated("binary_operator")
|
|
360
|
-
binary_operator
|
|
401
|
+
#: () -> String?
|
|
402
|
+
def then # :nodoc
|
|
403
|
+
then_keyword
|
|
361
404
|
end
|
|
362
405
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
deprecated("binary_operator_loc")
|
|
367
|
-
binary_operator_loc
|
|
406
|
+
#: () -> Location?
|
|
407
|
+
def then_loc # :nodoc
|
|
408
|
+
then_keyword_loc
|
|
368
409
|
end
|
|
369
410
|
end
|
|
370
411
|
|
|
371
|
-
class
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
deprecated("binary_operator")
|
|
376
|
-
binary_operator
|
|
412
|
+
class MatchPredicateNode < Node
|
|
413
|
+
#: () -> String
|
|
414
|
+
def operator # :nodoc
|
|
415
|
+
keyword
|
|
377
416
|
end
|
|
378
417
|
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
deprecated("binary_operator_loc")
|
|
383
|
-
binary_operator_loc
|
|
418
|
+
#: () -> Location
|
|
419
|
+
def operator_loc # :nodoc
|
|
420
|
+
keyword_loc
|
|
384
421
|
end
|
|
385
422
|
end
|
|
386
423
|
|
|
387
|
-
class
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
deprecated("binary_operator")
|
|
392
|
-
binary_operator
|
|
424
|
+
class UnlessNode < Node
|
|
425
|
+
#: () -> String
|
|
426
|
+
def keyword # :nodoc
|
|
427
|
+
unless_keyword
|
|
393
428
|
end
|
|
394
429
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
deprecated("binary_operator_loc")
|
|
399
|
-
binary_operator_loc
|
|
430
|
+
#: () -> Location
|
|
431
|
+
def keyword_loc # :nodoc
|
|
432
|
+
unless_keyword_loc
|
|
400
433
|
end
|
|
401
434
|
end
|
|
402
435
|
|
|
403
|
-
class
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
deprecated("binary_operator")
|
|
408
|
-
binary_operator
|
|
436
|
+
class UntilNode < Node
|
|
437
|
+
#: () -> String
|
|
438
|
+
def keyword # :nodoc
|
|
439
|
+
until_keyword
|
|
409
440
|
end
|
|
410
441
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
deprecated("binary_operator_loc")
|
|
415
|
-
binary_operator_loc
|
|
442
|
+
#: () -> Location
|
|
443
|
+
def keyword_loc # :nodoc
|
|
444
|
+
until_keyword_loc
|
|
416
445
|
end
|
|
417
|
-
end
|
|
418
446
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
def operator
|
|
423
|
-
deprecated("binary_operator")
|
|
424
|
-
binary_operator
|
|
447
|
+
#: () -> String?
|
|
448
|
+
def closing # :nodoc
|
|
449
|
+
end_keyword
|
|
425
450
|
end
|
|
426
451
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
deprecated("binary_operator_loc")
|
|
431
|
-
binary_operator_loc
|
|
452
|
+
#: () -> Location?
|
|
453
|
+
def closing_loc # :nodoc
|
|
454
|
+
end_keyword_loc
|
|
432
455
|
end
|
|
433
456
|
end
|
|
434
457
|
|
|
435
|
-
class
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
deprecated("binary_operator")
|
|
440
|
-
binary_operator
|
|
458
|
+
class WhenNode < Node
|
|
459
|
+
#: () -> String
|
|
460
|
+
def keyword # :nodoc
|
|
461
|
+
when_keyword
|
|
441
462
|
end
|
|
442
463
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
deprecated("binary_operator_loc")
|
|
447
|
-
binary_operator_loc
|
|
464
|
+
#: () -> Location
|
|
465
|
+
def keyword_loc # :nodoc
|
|
466
|
+
when_keyword_loc
|
|
448
467
|
end
|
|
449
468
|
end
|
|
450
469
|
|
|
451
|
-
class
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
deprecated("binary_operator")
|
|
456
|
-
binary_operator
|
|
457
|
-
end
|
|
458
|
-
|
|
459
|
-
# Returns the location of the binary operator used to modify the receiver.
|
|
460
|
-
# This method is deprecated in favor of #binary_operator_loc.
|
|
461
|
-
def operator_loc
|
|
462
|
-
deprecated("binary_operator_loc")
|
|
463
|
-
binary_operator_loc
|
|
470
|
+
class WhileNode < Node
|
|
471
|
+
#: () -> String
|
|
472
|
+
def keyword # :nodoc
|
|
473
|
+
while_keyword
|
|
464
474
|
end
|
|
465
|
-
end
|
|
466
475
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
def consequent
|
|
471
|
-
deprecated("else_clause")
|
|
472
|
-
else_clause
|
|
476
|
+
#: () -> Location
|
|
477
|
+
def keyword_loc # :nodoc
|
|
478
|
+
while_keyword_loc
|
|
473
479
|
end
|
|
474
|
-
end
|
|
475
480
|
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
def consequent
|
|
480
|
-
deprecated("else_clause")
|
|
481
|
-
else_clause
|
|
481
|
+
#: () -> String?
|
|
482
|
+
def closing # :nodoc
|
|
483
|
+
end_keyword
|
|
482
484
|
end
|
|
483
|
-
end
|
|
484
485
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
def consequent
|
|
489
|
-
deprecated("subsequent")
|
|
490
|
-
subsequent
|
|
486
|
+
#: () -> Location?
|
|
487
|
+
def closing_loc # :nodoc
|
|
488
|
+
end_keyword_loc
|
|
491
489
|
end
|
|
492
490
|
end
|
|
493
491
|
|
|
494
|
-
class
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
deprecated("subsequent")
|
|
499
|
-
subsequent
|
|
492
|
+
class SymbolNode < Node
|
|
493
|
+
#: () -> String
|
|
494
|
+
def value # :nodoc
|
|
495
|
+
content
|
|
500
496
|
end
|
|
501
|
-
end
|
|
502
497
|
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
def consequent
|
|
507
|
-
deprecated("else_clause")
|
|
508
|
-
else_clause
|
|
498
|
+
#: () -> Location
|
|
499
|
+
def value_loc # :nodoc
|
|
500
|
+
content_loc
|
|
509
501
|
end
|
|
510
502
|
end
|
|
503
|
+
# :startdoc:
|
|
511
504
|
end
|