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.
Files changed (244) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +88 -0
  3. data/CODE_OF_CONDUCT.md +1 -1
  4. data/LICENSE.md +1 -1
  5. data/Makefile +41 -12
  6. data/README.md +35 -97
  7. data/config.yml +174 -161
  8. data/docs/build_system.md +2 -2
  9. data/docs/configuration.md +5 -4
  10. data/docs/encoding.md +2 -2
  11. data/docs/fuzzing.md +4 -11
  12. data/docs/javascript.md +19 -4
  13. data/docs/mapping.md +1 -1
  14. data/docs/releasing.md +77 -5
  15. data/docs/relocation.md +2 -4
  16. data/docs/serialization.md +22 -24
  17. data/docs/testing.md +46 -29
  18. data/ext/prism/api_node.c +1461 -1401
  19. data/ext/prism/extconf.rb +3 -4
  20. data/ext/prism/extension.c +796 -422
  21. data/ext/prism/extension.h +3 -3
  22. data/include/prism/arena.h +37 -0
  23. data/include/prism/ast.h +2727 -610
  24. data/include/prism/buffer.h +52 -0
  25. data/include/prism/comments.h +55 -0
  26. data/include/prism/compiler/accel.h +26 -0
  27. data/include/prism/compiler/align.h +36 -0
  28. data/include/prism/compiler/assume.h +25 -0
  29. data/include/prism/compiler/bswap.h +46 -0
  30. data/include/prism/compiler/endianness.h +34 -0
  31. data/include/prism/compiler/exported.h +24 -0
  32. data/include/prism/compiler/fallthrough.h +22 -0
  33. data/include/prism/compiler/filesystem.h +32 -0
  34. data/include/prism/compiler/flex_array.h +19 -0
  35. data/include/prism/compiler/force_inline.h +21 -0
  36. data/include/prism/compiler/format.h +25 -0
  37. data/include/prism/compiler/inline.h +17 -0
  38. data/include/prism/compiler/nodiscard.h +22 -0
  39. data/include/prism/compiler/nonnull.h +18 -0
  40. data/include/prism/compiler/unused.h +18 -0
  41. data/include/prism/constant_pool.h +81 -0
  42. data/include/prism/diagnostic.h +38 -403
  43. data/include/prism/errors_format.h +53 -0
  44. data/include/prism/excludes.h +29 -0
  45. data/include/prism/integer.h +41 -0
  46. data/include/prism/internal/allocator.h +68 -0
  47. data/include/prism/internal/allocator_debug.h +88 -0
  48. data/include/prism/internal/arena.h +108 -0
  49. data/include/prism/internal/bit.h +42 -0
  50. data/include/prism/internal/buffer.h +94 -0
  51. data/include/prism/internal/char.h +145 -0
  52. data/include/prism/internal/comments.h +53 -0
  53. data/include/prism/internal/constant_pool.h +152 -0
  54. data/include/prism/internal/diagnostic.h +389 -0
  55. data/include/prism/{encoding.h → internal/encoding.h} +27 -68
  56. data/include/prism/internal/integer.h +68 -0
  57. data/include/prism/internal/isinf.h +16 -0
  58. data/include/prism/internal/line_offset_list.h +34 -0
  59. data/include/prism/{util/pm_list.h → internal/list.h} +11 -52
  60. data/include/prism/internal/magic_comments.h +23 -0
  61. data/include/prism/internal/memchr.h +15 -0
  62. data/include/prism/internal/node.h +38 -0
  63. data/include/prism/internal/options.h +232 -0
  64. data/include/prism/internal/parser.h +1004 -0
  65. data/include/prism/internal/regexp.h +26 -0
  66. data/include/prism/internal/serialize.h +39 -0
  67. data/include/prism/internal/source.h +72 -0
  68. data/include/prism/{static_literals.h → internal/static_literals.h} +26 -47
  69. data/include/prism/internal/stringy.h +35 -0
  70. data/include/prism/{util/pm_strncasecmp.h → internal/strncasecmp.h} +3 -17
  71. data/include/prism/{util/pm_strpbrk.h → internal/strpbrk.h} +7 -20
  72. data/include/prism/internal/tokens.h +11 -0
  73. data/include/prism/internal/xxh3.h +16 -0
  74. data/include/prism/json.h +32 -0
  75. data/include/prism/line_offset_list.h +61 -0
  76. data/include/prism/magic_comments.h +35 -0
  77. data/include/prism/node.h +18 -53
  78. data/include/prism/options.h +146 -280
  79. data/include/prism/parser.h +356 -867
  80. data/include/prism/prettyprint.h +6 -9
  81. data/include/prism/serialize.h +115 -0
  82. data/include/prism/source.h +155 -0
  83. data/include/prism/stream.h +28 -0
  84. data/include/prism/string_query.h +74 -0
  85. data/include/prism/stringy.h +72 -0
  86. data/include/prism/version.h +12 -3
  87. data/include/prism.h +43 -320
  88. data/lib/prism/compiler.rb +319 -305
  89. data/lib/prism/desugar_compiler.rb +105 -34
  90. data/lib/prism/dispatcher.rb +646 -473
  91. data/lib/prism/dot_visitor.rb +592 -511
  92. data/lib/prism/dsl.rb +391 -25
  93. data/lib/prism/ffi.rb +258 -90
  94. data/lib/prism/inspect_visitor.rb +357 -325
  95. data/lib/prism/lex_compat.rb +254 -212
  96. data/lib/prism/mutation_compiler.rb +313 -305
  97. data/lib/prism/node.rb +20966 -6992
  98. data/lib/prism/node_ext.rb +180 -187
  99. data/lib/prism/node_find.rb +215 -0
  100. data/lib/prism/parse_result/errors.rb +7 -1
  101. data/lib/prism/parse_result/newlines.rb +276 -8
  102. data/lib/prism/parse_result.rb +468 -139
  103. data/lib/prism/pattern.rb +65 -20
  104. data/lib/prism/reflection.rb +23 -12
  105. data/lib/prism/relocation.rb +149 -87
  106. data/lib/prism/serialize.rb +3460 -539
  107. data/lib/prism/string_query.rb +24 -1
  108. data/lib/prism/translation/parser/builder.rb +10 -2
  109. data/lib/prism/translation/parser/compiler.rb +44 -52
  110. data/lib/prism/translation/parser/lexer.rb +41 -92
  111. data/lib/prism/translation/parser.rb +1 -1
  112. data/lib/prism/translation/parser_current.rb +1 -1
  113. data/lib/prism/translation/ripper/lexer.rb +8 -10
  114. data/lib/prism/translation/ripper/sexp.rb +2 -10
  115. data/lib/prism/translation/ripper/shim.rb +2 -0
  116. data/lib/prism/translation/ripper.rb +967 -209
  117. data/lib/prism/translation/ruby_parser.rb +73 -316
  118. data/lib/prism/translation.rb +2 -0
  119. data/lib/prism/visitor.rb +632 -5
  120. data/lib/prism.rb +79 -9
  121. data/prism.gemspec +128 -62
  122. data/rbi/generated/prism/compiler.rbi +489 -0
  123. data/rbi/generated/prism/desugar_compiler.rbi +306 -0
  124. data/rbi/generated/prism/dispatcher.rbi +1138 -0
  125. data/rbi/generated/prism/dot_visitor.rbi +618 -0
  126. data/rbi/generated/prism/dsl.rbi +751 -0
  127. data/rbi/generated/prism/inspect_visitor.rbi +503 -0
  128. data/rbi/generated/prism/lex_compat.rbi +162 -0
  129. data/rbi/generated/prism/mutation_compiler.rbi +464 -0
  130. data/rbi/generated/prism/node.rbi +14407 -0
  131. data/rbi/generated/prism/node_ext.rbi +259 -0
  132. data/rbi/generated/prism/node_find.rbi +79 -0
  133. data/rbi/generated/prism/parse_result/errors.rbi +21 -0
  134. data/rbi/generated/prism/parse_result/newlines.rbi +208 -0
  135. data/rbi/generated/prism/parse_result.rbi +776 -0
  136. data/rbi/generated/prism/pattern.rbi +134 -0
  137. data/rbi/generated/prism/reflection.rbi +89 -0
  138. data/rbi/generated/prism/relocation.rbi +329 -0
  139. data/rbi/generated/prism/serialize.rbi +184 -0
  140. data/rbi/generated/prism/string_query.rbi +43 -0
  141. data/rbi/generated/prism/translation.rbi +7 -0
  142. data/rbi/generated/prism/visitor.rbi +650 -0
  143. data/rbi/generated/prism.rbi +86 -0
  144. data/rbi/prism/translation/parser_versions.rbi +5 -0
  145. data/rbi/rubyvm/node_find.rbi +14 -0
  146. data/sig/generated/prism/compiler.rbs +492 -0
  147. data/sig/generated/prism/desugar_compiler.rbs +305 -0
  148. data/sig/generated/prism/dispatcher.rbs +1292 -0
  149. data/sig/generated/prism/dot_visitor.rbs +635 -0
  150. data/sig/generated/prism/dsl.rbs +928 -0
  151. data/sig/generated/prism/inspect_visitor.rbs +509 -0
  152. data/sig/generated/prism/lex_compat.rbs +166 -0
  153. data/sig/{prism → generated/prism}/mutation_compiler.rbs +309 -4
  154. data/sig/generated/prism/node.rbs +20896 -0
  155. data/sig/generated/prism/node_ext.rbs +290 -0
  156. data/sig/generated/prism/node_find.rbs +90 -0
  157. data/sig/generated/prism/parse_result/errors.rbs +22 -0
  158. data/sig/generated/prism/parse_result/newlines.rbs +223 -0
  159. data/sig/generated/prism/parse_result.rbs +871 -0
  160. data/sig/generated/prism/pattern.rbs +156 -0
  161. data/sig/generated/prism/reflection.rbs +101 -0
  162. data/sig/generated/prism/relocation.rbs +428 -0
  163. data/sig/generated/prism/serialize.rbs +198 -0
  164. data/sig/generated/prism/string_query.rbs +43 -0
  165. data/sig/generated/prism/translation.rbs +8 -0
  166. data/sig/generated/prism/visitor.rbs +1111 -0
  167. data/sig/generated/prism.rbs +84 -0
  168. data/sig/manifest.yaml +2 -0
  169. data/src/arena.c +117 -0
  170. data/src/{util/pm_buffer.c → buffer.c} +53 -21
  171. data/src/{util/pm_char.c → char.c} +28 -57
  172. data/src/comments.c +454 -0
  173. data/src/constant_pool.c +406 -0
  174. data/src/diagnostic.c +97 -65
  175. data/src/encoding.c +8 -3
  176. data/src/errors_format.c +519 -0
  177. data/src/{util/pm_integer.c → integer.c} +33 -22
  178. data/src/json.c +5733 -0
  179. data/src/line_offset_list.c +100 -0
  180. data/src/list.c +24 -0
  181. data/src/{util/pm_memchr.c → memchr.c} +8 -6
  182. data/src/node.c +3504 -7674
  183. data/src/options.c +162 -49
  184. data/src/parser.c +367 -0
  185. data/src/prettyprint.c +421 -354
  186. data/src/prism.c +8402 -7161
  187. data/src/regexp.c +961 -45
  188. data/src/serialize.c +460 -424
  189. data/src/source.c +518 -0
  190. data/src/static_literals.c +111 -43
  191. data/src/string_query.c +180 -0
  192. data/src/stringy.c +91 -0
  193. data/src/{util/pm_strncasecmp.c → strncasecmp.c} +5 -4
  194. data/src/strpbrk.c +447 -0
  195. data/src/{token_type.c → tokens.c} +39 -18
  196. data/src/xxh3.c +292 -0
  197. metadata +128 -63
  198. data/ext/prism/api_pack.c +0 -276
  199. data/include/prism/defines.h +0 -260
  200. data/include/prism/pack.h +0 -163
  201. data/include/prism/regexp.h +0 -43
  202. data/include/prism/util/pm_buffer.h +0 -236
  203. data/include/prism/util/pm_char.h +0 -204
  204. data/include/prism/util/pm_constant_pool.h +0 -218
  205. data/include/prism/util/pm_integer.h +0 -130
  206. data/include/prism/util/pm_memchr.h +0 -29
  207. data/include/prism/util/pm_newline_list.h +0 -113
  208. data/include/prism/util/pm_string.h +0 -200
  209. data/lib/prism/pack.rb +0 -230
  210. data/lib/prism/parse_result/comments.rb +0 -188
  211. data/rbi/prism/compiler.rbi +0 -12
  212. data/rbi/prism/dsl.rbi +0 -524
  213. data/rbi/prism/inspect_visitor.rbi +0 -12
  214. data/rbi/prism/node.rbi +0 -8750
  215. data/rbi/prism/node_ext.rbi +0 -107
  216. data/rbi/prism/parse_result.rbi +0 -404
  217. data/rbi/prism/reflection.rbi +0 -58
  218. data/rbi/prism/string_query.rbi +0 -12
  219. data/rbi/prism/visitor.rbi +0 -473
  220. data/rbi/prism.rbi +0 -63
  221. data/sig/prism/compiler.rbs +0 -9
  222. data/sig/prism/dispatcher.rbs +0 -19
  223. data/sig/prism/dot_visitor.rbs +0 -6
  224. data/sig/prism/dsl.rbs +0 -351
  225. data/sig/prism/inspect_visitor.rbs +0 -22
  226. data/sig/prism/lex_compat.rbs +0 -10
  227. data/sig/prism/node.rbs +0 -4042
  228. data/sig/prism/node_ext.rbs +0 -149
  229. data/sig/prism/pack.rbs +0 -43
  230. data/sig/prism/parse_result/comments.rbs +0 -38
  231. data/sig/prism/parse_result.rbs +0 -197
  232. data/sig/prism/pattern.rbs +0 -13
  233. data/sig/prism/reflection.rbs +0 -50
  234. data/sig/prism/relocation.rbs +0 -185
  235. data/sig/prism/serialize.rbs +0 -8
  236. data/sig/prism/string_query.rbs +0 -11
  237. data/sig/prism/visitor.rbs +0 -169
  238. data/sig/prism.rbs +0 -272
  239. data/src/pack.c +0 -509
  240. data/src/util/pm_constant_pool.c +0 -342
  241. data/src/util/pm_list.c +0 -49
  242. data/src/util/pm_newline_list.c +0 -125
  243. data/src/util/pm_string.c +0 -381
  244. data/src/util/pm_strpbrk.c +0 -206
@@ -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
- def options
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
- include RegularExpressionOptions
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
- include RegularExpressionOptions
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
- include RegularExpressionOptions
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
- include RegularExpressionOptions
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
- def heredoc?
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
- include HeredocQuery
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
- include HeredocQuery
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
- include HeredocQuery
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
- include HeredocQuery
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 missing nodes are found while computing a
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 MissingNodesInConstantPathError < StandardError; end
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 MissingNodesInConstantPathError, "Constant path contains missing nodes. Cannot compute full name"
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::MissingNodesInConstantPathError, "Constant target path contains missing nodes. Cannot compute full name"
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 && rest.is_a?(RestParameterNode)
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 NoKeywordsParameterNode, KeywordRestParameterNode, ForwardingParameterNode
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
- names << [:block, block.name || :&] if block
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
- class CallOperatorWriteNode < Node
340
- # Returns the binary operator used to modify the receiver. This method is
341
- # deprecated in favor of #binary_operator.
342
- def operator
343
- deprecated("binary_operator")
344
- binary_operator
389
+ # :stopdoc:
390
+ class InNode < Node
391
+ #: () -> String
392
+ def in # :nodoc
393
+ in_keyword
345
394
  end
346
395
 
347
- # Returns the location of the binary operator used to modify the receiver.
348
- # This method is deprecated in favor of #binary_operator_loc.
349
- def operator_loc
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
- class ClassVariableOperatorWriteNode < Node
356
- # Returns the binary operator used to modify the receiver. This method is
357
- # deprecated in favor of #binary_operator.
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
- # Returns the location of the binary operator used to modify the receiver.
364
- # This method is deprecated in favor of #binary_operator_loc.
365
- def operator_loc
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 ConstantOperatorWriteNode < Node
372
- # Returns the binary operator used to modify the receiver. This method is
373
- # deprecated in favor of #binary_operator.
374
- def operator
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
- # Returns the location of the binary operator used to modify the receiver.
380
- # This method is deprecated in favor of #binary_operator_loc.
381
- def operator_loc
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 ConstantPathOperatorWriteNode < Node
388
- # Returns the binary operator used to modify the receiver. This method is
389
- # deprecated in favor of #binary_operator.
390
- def operator
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
- # Returns the location of the binary operator used to modify the receiver.
396
- # This method is deprecated in favor of #binary_operator_loc.
397
- def operator_loc
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 GlobalVariableOperatorWriteNode < Node
404
- # Returns the binary operator used to modify the receiver. This method is
405
- # deprecated in favor of #binary_operator.
406
- def operator
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
- # Returns the location of the binary operator used to modify the receiver.
412
- # This method is deprecated in favor of #binary_operator_loc.
413
- def operator_loc
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
- class IndexOperatorWriteNode < Node
420
- # Returns the binary operator used to modify the receiver. This method is
421
- # deprecated in favor of #binary_operator.
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
- # Returns the location of the binary operator used to modify the receiver.
428
- # This method is deprecated in favor of #binary_operator_loc.
429
- def operator_loc
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 InstanceVariableOperatorWriteNode < Node
436
- # Returns the binary operator used to modify the receiver. This method is
437
- # deprecated in favor of #binary_operator.
438
- def operator
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
- # Returns the location of the binary operator used to modify the receiver.
444
- # This method is deprecated in favor of #binary_operator_loc.
445
- def operator_loc
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 LocalVariableOperatorWriteNode < Node
452
- # Returns the binary operator used to modify the receiver. This method is
453
- # deprecated in favor of #binary_operator.
454
- def operator
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
- class CaseMatchNode < Node
468
- # Returns the else clause of the case match node. This method is deprecated
469
- # in favor of #else_clause.
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
- class CaseNode < Node
477
- # Returns the else clause of the case node. This method is deprecated in
478
- # favor of #else_clause.
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
- class IfNode < Node
486
- # Returns the subsequent if/elsif/else clause of the if node. This method is
487
- # deprecated in favor of #subsequent.
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 RescueNode < Node
495
- # Returns the subsequent rescue clause of the rescue node. This method is
496
- # deprecated in favor of #subsequent.
497
- def consequent
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
- class UnlessNode < Node
504
- # Returns the else clause of the unless node. This method is deprecated in
505
- # favor of #else_clause.
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