prism 1.2.0 → 1.4.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.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +46 -1
  3. data/Makefile +1 -1
  4. data/config.yml +429 -2
  5. data/docs/build_system.md +8 -11
  6. data/docs/releasing.md +1 -1
  7. data/docs/relocation.md +34 -0
  8. data/docs/ruby_api.md +1 -1
  9. data/ext/prism/api_node.c +1824 -1305
  10. data/ext/prism/extconf.rb +13 -36
  11. data/ext/prism/extension.c +298 -109
  12. data/ext/prism/extension.h +4 -4
  13. data/include/prism/ast.h +442 -2
  14. data/include/prism/defines.h +26 -8
  15. data/include/prism/options.h +47 -1
  16. data/include/prism/util/pm_buffer.h +10 -0
  17. data/include/prism/version.h +2 -2
  18. data/include/prism.h +51 -4
  19. data/lib/prism/dot_visitor.rb +26 -0
  20. data/lib/prism/dsl.rb +14 -6
  21. data/lib/prism/ffi.rb +93 -28
  22. data/lib/prism/inspect_visitor.rb +4 -1
  23. data/lib/prism/node.rb +1886 -105
  24. data/lib/prism/parse_result/errors.rb +1 -1
  25. data/lib/prism/parse_result/newlines.rb +1 -1
  26. data/lib/prism/parse_result.rb +54 -2
  27. data/lib/prism/polyfill/append_as_bytes.rb +15 -0
  28. data/lib/prism/reflection.rb +4 -4
  29. data/lib/prism/relocation.rb +504 -0
  30. data/lib/prism/serialize.rb +1252 -765
  31. data/lib/prism/string_query.rb +30 -0
  32. data/lib/prism/translation/parser/builder.rb +61 -0
  33. data/lib/prism/translation/parser/compiler.rb +228 -162
  34. data/lib/prism/translation/parser/lexer.rb +435 -61
  35. data/lib/prism/translation/parser.rb +51 -3
  36. data/lib/prism/translation/parser35.rb +12 -0
  37. data/lib/prism/translation/ripper.rb +13 -3
  38. data/lib/prism/translation/ruby_parser.rb +17 -7
  39. data/lib/prism/translation.rb +1 -0
  40. data/lib/prism.rb +9 -7
  41. data/prism.gemspec +11 -1
  42. data/rbi/prism/dsl.rbi +10 -7
  43. data/rbi/prism/node.rbi +44 -17
  44. data/rbi/prism/parse_result.rbi +17 -0
  45. data/rbi/prism/string_query.rbi +12 -0
  46. data/rbi/prism/translation/parser35.rbi +6 -0
  47. data/rbi/prism.rbi +39 -36
  48. data/sig/prism/dsl.rbs +6 -4
  49. data/sig/prism/node.rbs +29 -15
  50. data/sig/prism/parse_result.rbs +10 -0
  51. data/sig/prism/relocation.rbs +185 -0
  52. data/sig/prism/serialize.rbs +4 -2
  53. data/sig/prism/string_query.rbs +11 -0
  54. data/sig/prism.rbs +22 -1
  55. data/src/diagnostic.c +2 -2
  56. data/src/node.c +39 -0
  57. data/src/options.c +31 -0
  58. data/src/prettyprint.c +62 -0
  59. data/src/prism.c +738 -199
  60. data/src/regexp.c +7 -3
  61. data/src/serialize.c +18 -0
  62. data/src/static_literals.c +1 -1
  63. data/src/util/pm_buffer.c +40 -0
  64. data/src/util/pm_char.c +1 -1
  65. data/src/util/pm_constant_pool.c +6 -2
  66. data/src/util/pm_string.c +1 -0
  67. data/src/util/pm_strncasecmp.c +13 -1
  68. metadata +13 -7
@@ -33,6 +33,37 @@ module Prism
33
33
 
34
34
  Racc_debug_parser = false # :nodoc:
35
35
 
36
+ # The `builder` argument is used to create the parser using our custom builder class by default.
37
+ #
38
+ # By using the `:parser` keyword argument, you can translate in a way that is compatible with
39
+ # the Parser gem using any parser.
40
+ #
41
+ # For example, in RuboCop for Ruby LSP, the following approach can be used to improve performance
42
+ # by reusing a pre-parsed `Prism::ParseLexResult`:
43
+ #
44
+ # class PrismPreparsed
45
+ # def initialize(prism_result)
46
+ # @prism_result = prism_result
47
+ # end
48
+ #
49
+ # def parse_lex(source, **options)
50
+ # @prism_result
51
+ # end
52
+ # end
53
+ #
54
+ # prism_preparsed = PrismPreparsed.new(prism_result)
55
+ #
56
+ # Prism::Translation::Ruby34.new(builder, parser: prism_preparsed)
57
+ #
58
+ # In an object passed to the `:parser` keyword argument, the `parse` and `parse_lex` methods
59
+ # should be implemented as needed.
60
+ #
61
+ def initialize(builder = Prism::Translation::Parser::Builder.new, parser: Prism)
62
+ @parser = parser
63
+
64
+ super(builder)
65
+ end
66
+
36
67
  def version # :nodoc:
37
68
  34
38
69
  end
@@ -51,7 +82,7 @@ module Prism
51
82
  source = source_buffer.source
52
83
 
53
84
  offset_cache = build_offset_cache(source)
54
- result = unwrap(Prism.parse(source, filepath: source_buffer.name, version: convert_for_prism(version), partial_script: true, encoding: false), offset_cache)
85
+ result = unwrap(@parser.parse(source, **prism_options), offset_cache)
55
86
 
56
87
  build_ast(result.value, offset_cache)
57
88
  ensure
@@ -64,7 +95,7 @@ module Prism
64
95
  source = source_buffer.source
65
96
 
66
97
  offset_cache = build_offset_cache(source)
67
- result = unwrap(Prism.parse(source, filepath: source_buffer.name, version: convert_for_prism(version), partial_script: true, encoding: false), offset_cache)
98
+ result = unwrap(@parser.parse(source, **prism_options), offset_cache)
68
99
 
69
100
  [
70
101
  build_ast(result.value, offset_cache),
@@ -83,7 +114,7 @@ module Prism
83
114
  offset_cache = build_offset_cache(source)
84
115
  result =
85
116
  begin
86
- unwrap(Prism.parse_lex(source, filepath: source_buffer.name, version: convert_for_prism(version), partial_script: true, encoding: false), offset_cache)
117
+ unwrap(@parser.parse_lex(source, **prism_options), offset_cache)
87
118
  rescue ::Parser::SyntaxError
88
119
  raise if !recover
89
120
  end
@@ -285,6 +316,20 @@ module Prism
285
316
  )
286
317
  end
287
318
 
319
+ # Options for how prism should parse/lex the source.
320
+ def prism_options
321
+ options = {
322
+ filepath: @source_buffer.name,
323
+ version: convert_for_prism(version),
324
+ partial_script: true,
325
+ }
326
+ # The parser gem always encodes to UTF-8, unless it is binary.
327
+ # https://github.com/whitequark/parser/blob/v3.3.6.0/lib/parser/source/buffer.rb#L80-L107
328
+ options[:encoding] = false if @source_buffer.source.encoding != Encoding::BINARY
329
+
330
+ options
331
+ end
332
+
288
333
  # Converts the version format handled by Parser to the format handled by Prism.
289
334
  def convert_for_prism(version)
290
335
  case version
@@ -292,11 +337,14 @@ module Prism
292
337
  "3.3.1"
293
338
  when 34
294
339
  "3.4.0"
340
+ when 35
341
+ "3.5.0"
295
342
  else
296
343
  "latest"
297
344
  end
298
345
  end
299
346
 
347
+ require_relative "parser/builder"
300
348
  require_relative "parser/compiler"
301
349
  require_relative "parser/lexer"
302
350
 
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Prism
4
+ module Translation
5
+ # This class is the entry-point for Ruby 3.5 of `Prism::Translation::Parser`.
6
+ class Parser35 < Parser
7
+ def version # :nodoc:
8
+ 35
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1045,10 +1045,20 @@ module Prism
1045
1045
  bounds(node.location)
1046
1046
  on_unary(node.name, receiver)
1047
1047
  when :!
1048
- receiver = visit(node.receiver)
1048
+ if node.message == "not"
1049
+ receiver =
1050
+ if !node.receiver.is_a?(ParenthesesNode) || !node.receiver.body.nil?
1051
+ visit(node.receiver)
1052
+ end
1049
1053
 
1050
- bounds(node.location)
1051
- on_unary(node.message == "not" ? :not : :!, receiver)
1054
+ bounds(node.location)
1055
+ on_unary(:not, receiver)
1056
+ else
1057
+ receiver = visit(node.receiver)
1058
+
1059
+ bounds(node.location)
1060
+ on_unary(:!, receiver)
1061
+ end
1052
1062
  when *BINARY_OPERATORS
1053
1063
  receiver = visit(node.receiver)
1054
1064
  value = visit(node.arguments.arguments.first)
@@ -881,6 +881,7 @@ module Prism
881
881
  # Visit the interpolated content of the string-like node.
882
882
  private def visit_interpolated_parts(parts)
883
883
  visited = []
884
+
884
885
  parts.each do |part|
885
886
  result = visit(part)
886
887
 
@@ -892,6 +893,7 @@ module Prism
892
893
  else
893
894
  visited << result
894
895
  end
896
+ visited << :space
895
897
  elsif result[0] == :dstr
896
898
  if !visited.empty? && part.parts[0].is_a?(StringNode)
897
899
  # If we are in the middle of an implicitly concatenated string,
@@ -907,8 +909,9 @@ module Prism
907
909
  end
908
910
 
909
911
  state = :beginning #: :beginning | :string_content | :interpolated_content
912
+ results = []
910
913
 
911
- visited.each_with_object([]) do |result, results|
914
+ visited.each_with_index do |result, index|
912
915
  case state
913
916
  when :beginning
914
917
  if result.is_a?(String)
@@ -923,23 +926,29 @@ module Prism
923
926
  state = :interpolated_content
924
927
  end
925
928
  when :string_content
926
- if result.is_a?(String)
927
- results[0] << result
929
+ if result == :space
930
+ # continue
931
+ elsif result.is_a?(String)
932
+ results[0] = "#{results[0]}#{result}"
928
933
  elsif result.is_a?(Array) && result[0] == :str
929
- results[0] << result[1]
934
+ results[0] = "#{results[0]}#{result[1]}"
930
935
  else
931
936
  results << result
932
937
  state = :interpolated_content
933
938
  end
934
939
  when :interpolated_content
935
- if result.is_a?(Array) && result[0] == :str && results[-1][0] == :str && (results[-1].line_max == result.line)
936
- results[-1][1] << result[1]
940
+ if result == :space
941
+ # continue
942
+ elsif visited[index - 1] != :space && result.is_a?(Array) && result[0] == :str && results[-1][0] == :str && (results[-1].line_max == result.line)
943
+ results[-1][1] = "#{results[-1][1]}#{result[1]}"
937
944
  results[-1].line_max = result.line_max
938
945
  else
939
946
  results << result
940
947
  end
941
948
  end
942
949
  end
950
+
951
+ results
943
952
  end
944
953
 
945
954
  # -> { it }
@@ -1431,6 +1440,7 @@ module Prism
1431
1440
  unescaped = node.unescaped
1432
1441
 
1433
1442
  if node.forced_binary_encoding?
1443
+ unescaped = unescaped.dup
1434
1444
  unescaped.force_encoding(Encoding::BINARY)
1435
1445
  end
1436
1446
 
@@ -1549,7 +1559,7 @@ module Prism
1549
1559
  else
1550
1560
  parameters =
1551
1561
  case block.parameters
1552
- when nil, NumberedParametersNode
1562
+ when nil, ItParametersNode, NumberedParametersNode
1553
1563
  0
1554
1564
  else
1555
1565
  visit(block.parameters)
@@ -7,6 +7,7 @@ module Prism
7
7
  autoload :Parser, "prism/translation/parser"
8
8
  autoload :Parser33, "prism/translation/parser33"
9
9
  autoload :Parser34, "prism/translation/parser34"
10
+ autoload :Parser35, "prism/translation/parser35"
10
11
  autoload :Ripper, "prism/translation/ripper"
11
12
  autoload :RubyParser, "prism/translation/ruby_parser"
12
13
  end
data/lib/prism.rb CHANGED
@@ -24,7 +24,9 @@ module Prism
24
24
  autoload :Pack, "prism/pack"
25
25
  autoload :Pattern, "prism/pattern"
26
26
  autoload :Reflection, "prism/reflection"
27
+ autoload :Relocation, "prism/relocation"
27
28
  autoload :Serialize, "prism/serialize"
29
+ autoload :StringQuery, "prism/string_query"
28
30
  autoload :Translation, "prism/translation"
29
31
  autoload :Visitor, "prism/visitor"
30
32
 
@@ -57,11 +59,11 @@ module Prism
57
59
  end
58
60
 
59
61
  # :call-seq:
60
- # Prism::load(source, serialized) -> ParseResult
62
+ # Prism::load(source, serialized, freeze) -> ParseResult
61
63
  #
62
64
  # Load the serialized AST using the source as a reference into a tree.
63
- def self.load(source, serialized)
64
- Serialize.load(source, serialized)
65
+ def self.load(source, serialized, freeze = false)
66
+ Serialize.load_parse(source, serialized, freeze)
65
67
  end
66
68
  end
67
69
 
@@ -75,13 +77,13 @@ require_relative "prism/parse_result"
75
77
  # it's going to require the built library. Otherwise, it's going to require a
76
78
  # module that uses FFI to call into the library.
77
79
  if RUBY_ENGINE == "ruby" and !ENV["PRISM_FFI_BACKEND"]
78
- require "prism/prism"
79
-
80
80
  # The C extension is the default backend on CRuby.
81
81
  Prism::BACKEND = :CEXT
82
- else
83
- require_relative "prism/ffi"
84
82
 
83
+ require "prism/prism"
84
+ else
85
85
  # The FFI backend is used on other Ruby implementations.
86
86
  Prism::BACKEND = :FFI
87
+
88
+ require_relative "prism/ffi"
87
89
  end
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 = "1.2.0"
5
+ spec.version = "1.4.0"
6
6
  spec.authors = ["Shopify"]
7
7
  spec.email = ["ruby@shopify.com"]
8
8
 
@@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
35
35
  "docs/parser_translation.md",
36
36
  "docs/parsing_rules.md",
37
37
  "docs/releasing.md",
38
+ "docs/relocation.md",
38
39
  "docs/ripper_translation.md",
39
40
  "docs/ruby_api.md",
40
41
  "docs/ruby_parser_translation.md",
@@ -85,14 +86,19 @@ Gem::Specification.new do |spec|
85
86
  "lib/prism/parse_result/errors.rb",
86
87
  "lib/prism/parse_result/newlines.rb",
87
88
  "lib/prism/pattern.rb",
89
+ "lib/prism/polyfill/append_as_bytes.rb",
88
90
  "lib/prism/polyfill/byteindex.rb",
89
91
  "lib/prism/polyfill/unpack1.rb",
90
92
  "lib/prism/reflection.rb",
93
+ "lib/prism/relocation.rb",
91
94
  "lib/prism/serialize.rb",
95
+ "lib/prism/string_query.rb",
92
96
  "lib/prism/translation.rb",
93
97
  "lib/prism/translation/parser.rb",
94
98
  "lib/prism/translation/parser33.rb",
95
99
  "lib/prism/translation/parser34.rb",
100
+ "lib/prism/translation/parser35.rb",
101
+ "lib/prism/translation/parser/builder.rb",
96
102
  "lib/prism/translation/parser/compiler.rb",
97
103
  "lib/prism/translation/parser/lexer.rb",
98
104
  "lib/prism/translation/ripper.rb",
@@ -109,9 +115,11 @@ Gem::Specification.new do |spec|
109
115
  "rbi/prism/node.rbi",
110
116
  "rbi/prism/parse_result.rbi",
111
117
  "rbi/prism/reflection.rbi",
118
+ "rbi/prism/string_query.rbi",
112
119
  "rbi/prism/translation/parser.rbi",
113
120
  "rbi/prism/translation/parser33.rbi",
114
121
  "rbi/prism/translation/parser34.rbi",
122
+ "rbi/prism/translation/parser35.rbi",
115
123
  "rbi/prism/translation/ripper.rbi",
116
124
  "rbi/prism/visitor.rbi",
117
125
  "sig/prism.rbs",
@@ -128,7 +136,9 @@ Gem::Specification.new do |spec|
128
136
  "sig/prism/parse_result.rbs",
129
137
  "sig/prism/pattern.rbs",
130
138
  "sig/prism/reflection.rbs",
139
+ "sig/prism/relocation.rbs",
131
140
  "sig/prism/serialize.rbs",
141
+ "sig/prism/string_query.rbs",
132
142
  "sig/prism/visitor.rbs",
133
143
  "src/diagnostic.c",
134
144
  "src/encoding.c",
data/rbi/prism/dsl.rbi CHANGED
@@ -265,7 +265,7 @@ module Prism::DSL
265
265
  sig { params(source: Prism::Source, node_id: Integer, location: Prism::Location, flags: Integer, opening_loc: Prism::Location, parts: T::Array[T.any(Prism::StringNode, Prism::EmbeddedStatementsNode, Prism::EmbeddedVariableNode)], closing_loc: Prism::Location).returns(Prism::InterpolatedRegularExpressionNode) }
266
266
  def interpolated_regular_expression_node(source: default_source, node_id: 0, location: default_location, flags: 0, opening_loc: location, parts: [], closing_loc: location); end
267
267
 
268
- sig { params(source: Prism::Source, node_id: Integer, location: Prism::Location, flags: Integer, opening_loc: T.nilable(Prism::Location), parts: T::Array[T.any(Prism::StringNode, Prism::EmbeddedStatementsNode, Prism::EmbeddedVariableNode, Prism::InterpolatedStringNode)], closing_loc: T.nilable(Prism::Location)).returns(Prism::InterpolatedStringNode) }
268
+ sig { params(source: Prism::Source, node_id: Integer, location: Prism::Location, flags: Integer, opening_loc: T.nilable(Prism::Location), parts: T::Array[T.any(Prism::StringNode, Prism::EmbeddedStatementsNode, Prism::EmbeddedVariableNode, Prism::InterpolatedStringNode, Prism::XStringNode)], closing_loc: T.nilable(Prism::Location)).returns(Prism::InterpolatedStringNode) }
269
269
  def interpolated_string_node(source: default_source, node_id: 0, location: default_location, flags: 0, opening_loc: nil, parts: [], closing_loc: nil); end
270
270
 
271
271
  sig { params(source: Prism::Source, node_id: Integer, location: Prism::Location, flags: Integer, opening_loc: T.nilable(Prism::Location), parts: T::Array[T.any(Prism::StringNode, Prism::EmbeddedStatementsNode, Prism::EmbeddedVariableNode)], closing_loc: T.nilable(Prism::Location)).returns(Prism::InterpolatedSymbolNode) }
@@ -397,8 +397,8 @@ module Prism::DSL
397
397
  sig { params(source: Prism::Source, node_id: Integer, location: Prism::Location, flags: Integer, expression: Prism::Node, keyword_loc: Prism::Location, rescue_expression: Prism::Node).returns(Prism::RescueModifierNode) }
398
398
  def rescue_modifier_node(source: default_source, node_id: 0, location: default_location, flags: 0, expression: default_node(source, location), keyword_loc: location, rescue_expression: default_node(source, location)); end
399
399
 
400
- sig { params(source: Prism::Source, node_id: Integer, location: Prism::Location, flags: Integer, keyword_loc: Prism::Location, exceptions: T::Array[Prism::Node], operator_loc: T.nilable(Prism::Location), reference: T.nilable(T.any(Prism::LocalVariableTargetNode, Prism::InstanceVariableTargetNode, Prism::ClassVariableTargetNode, Prism::GlobalVariableTargetNode, Prism::ConstantTargetNode, Prism::ConstantPathTargetNode, Prism::CallTargetNode, Prism::IndexTargetNode, Prism::BackReferenceReadNode, Prism::NumberedReferenceReadNode, Prism::MissingNode)), statements: T.nilable(Prism::StatementsNode), subsequent: T.nilable(Prism::RescueNode)).returns(Prism::RescueNode) }
401
- def rescue_node(source: default_source, node_id: 0, location: default_location, flags: 0, keyword_loc: location, exceptions: [], operator_loc: nil, reference: nil, statements: nil, subsequent: nil); end
400
+ sig { params(source: Prism::Source, node_id: Integer, location: Prism::Location, flags: Integer, keyword_loc: Prism::Location, exceptions: T::Array[Prism::Node], operator_loc: T.nilable(Prism::Location), reference: T.nilable(T.any(Prism::LocalVariableTargetNode, Prism::InstanceVariableTargetNode, Prism::ClassVariableTargetNode, Prism::GlobalVariableTargetNode, Prism::ConstantTargetNode, Prism::ConstantPathTargetNode, Prism::CallTargetNode, Prism::IndexTargetNode, Prism::BackReferenceReadNode, Prism::NumberedReferenceReadNode, Prism::MissingNode)), then_keyword_loc: T.nilable(Prism::Location), statements: T.nilable(Prism::StatementsNode), subsequent: T.nilable(Prism::RescueNode)).returns(Prism::RescueNode) }
401
+ def rescue_node(source: default_source, node_id: 0, location: default_location, flags: 0, keyword_loc: location, exceptions: [], operator_loc: nil, reference: nil, then_keyword_loc: nil, statements: nil, subsequent: nil); end
402
402
 
403
403
  sig { params(source: Prism::Source, node_id: Integer, location: Prism::Location, flags: Integer, name: T.nilable(Symbol), name_loc: T.nilable(Prism::Location), operator_loc: Prism::Location).returns(Prism::RestParameterNode) }
404
404
  def rest_parameter_node(source: default_source, node_id: 0, location: default_location, flags: 0, name: nil, name_loc: nil, operator_loc: location); end
@@ -451,14 +451,14 @@ module Prism::DSL
451
451
  sig { params(source: Prism::Source, node_id: Integer, location: Prism::Location, flags: Integer, keyword_loc: Prism::Location, predicate: Prism::Node, then_keyword_loc: T.nilable(Prism::Location), statements: T.nilable(Prism::StatementsNode), else_clause: T.nilable(Prism::ElseNode), end_keyword_loc: T.nilable(Prism::Location)).returns(Prism::UnlessNode) }
452
452
  def unless_node(source: default_source, node_id: 0, location: default_location, flags: 0, keyword_loc: location, predicate: default_node(source, location), then_keyword_loc: nil, statements: nil, else_clause: nil, end_keyword_loc: nil); end
453
453
 
454
- sig { params(source: Prism::Source, node_id: Integer, location: Prism::Location, flags: Integer, keyword_loc: Prism::Location, closing_loc: T.nilable(Prism::Location), predicate: Prism::Node, statements: T.nilable(Prism::StatementsNode)).returns(Prism::UntilNode) }
455
- def until_node(source: default_source, node_id: 0, location: default_location, flags: 0, keyword_loc: location, closing_loc: nil, predicate: default_node(source, location), statements: nil); end
454
+ sig { params(source: Prism::Source, node_id: Integer, location: Prism::Location, flags: Integer, keyword_loc: Prism::Location, do_keyword_loc: T.nilable(Prism::Location), closing_loc: T.nilable(Prism::Location), predicate: Prism::Node, statements: T.nilable(Prism::StatementsNode)).returns(Prism::UntilNode) }
455
+ def until_node(source: default_source, node_id: 0, location: default_location, flags: 0, keyword_loc: location, do_keyword_loc: nil, closing_loc: nil, predicate: default_node(source, location), statements: nil); end
456
456
 
457
457
  sig { params(source: Prism::Source, node_id: Integer, location: Prism::Location, flags: Integer, keyword_loc: Prism::Location, conditions: T::Array[Prism::Node], then_keyword_loc: T.nilable(Prism::Location), statements: T.nilable(Prism::StatementsNode)).returns(Prism::WhenNode) }
458
458
  def when_node(source: default_source, node_id: 0, location: default_location, flags: 0, keyword_loc: location, conditions: [], then_keyword_loc: nil, statements: nil); end
459
459
 
460
- sig { params(source: Prism::Source, node_id: Integer, location: Prism::Location, flags: Integer, keyword_loc: Prism::Location, closing_loc: T.nilable(Prism::Location), predicate: Prism::Node, statements: T.nilable(Prism::StatementsNode)).returns(Prism::WhileNode) }
461
- def while_node(source: default_source, node_id: 0, location: default_location, flags: 0, keyword_loc: location, closing_loc: nil, predicate: default_node(source, location), statements: nil); end
460
+ sig { params(source: Prism::Source, node_id: Integer, location: Prism::Location, flags: Integer, keyword_loc: Prism::Location, do_keyword_loc: T.nilable(Prism::Location), closing_loc: T.nilable(Prism::Location), predicate: Prism::Node, statements: T.nilable(Prism::StatementsNode)).returns(Prism::WhileNode) }
461
+ def while_node(source: default_source, node_id: 0, location: default_location, flags: 0, keyword_loc: location, do_keyword_loc: nil, closing_loc: nil, predicate: default_node(source, location), statements: nil); end
462
462
 
463
463
  sig { params(source: Prism::Source, node_id: Integer, location: Prism::Location, flags: Integer, opening_loc: Prism::Location, content_loc: Prism::Location, closing_loc: Prism::Location, unescaped: String).returns(Prism::XStringNode) }
464
464
  def x_string_node(source: default_source, node_id: 0, location: default_location, flags: 0, opening_loc: location, content_loc: location, closing_loc: location, unescaped: ""); end
@@ -493,6 +493,9 @@ module Prism::DSL
493
493
  sig { params(name: Symbol).returns(Integer) }
494
494
  def parameter_flag(name); end
495
495
 
496
+ sig { params(name: Symbol).returns(Integer) }
497
+ def parentheses_node_flag(name); end
498
+
496
499
  sig { params(name: Symbol).returns(Integer) }
497
500
  def range_flag(name); end
498
501
 
data/rbi/prism/node.rbi CHANGED
@@ -408,8 +408,8 @@ end
408
408
  # foo in [1, 2]
409
409
  # ^^^^^^^^^^^^^
410
410
  #
411
- # foo in *1
412
- # ^^^^^^^^^
411
+ # foo in *bar
412
+ # ^^^^^^^^^^^
413
413
  #
414
414
  # foo in Bar[]
415
415
  # ^^^^^^^^^^^^
@@ -4919,13 +4919,13 @@ class Prism::InterpolatedStringNode < Prism::Node
4919
4919
  sig { returns(T.nilable(Prism::Location)) }
4920
4920
  def opening_loc; end
4921
4921
 
4922
- sig { returns(T::Array[T.any(Prism::StringNode, Prism::EmbeddedStatementsNode, Prism::EmbeddedVariableNode, Prism::InterpolatedStringNode)]) }
4922
+ sig { returns(T::Array[T.any(Prism::StringNode, Prism::EmbeddedStatementsNode, Prism::EmbeddedVariableNode, Prism::InterpolatedStringNode, Prism::XStringNode)]) }
4923
4923
  def parts; end
4924
4924
 
4925
4925
  sig { returns(T.nilable(Prism::Location)) }
4926
4926
  def closing_loc; end
4927
4927
 
4928
- sig { params(source: Prism::Source, node_id: Integer, location: Prism::Location, flags: Integer, opening_loc: T.nilable(Prism::Location), parts: T::Array[T.any(Prism::StringNode, Prism::EmbeddedStatementsNode, Prism::EmbeddedVariableNode, Prism::InterpolatedStringNode)], closing_loc: T.nilable(Prism::Location)).void }
4928
+ sig { params(source: Prism::Source, node_id: Integer, location: Prism::Location, flags: Integer, opening_loc: T.nilable(Prism::Location), parts: T::Array[T.any(Prism::StringNode, Prism::EmbeddedStatementsNode, Prism::EmbeddedVariableNode, Prism::InterpolatedStringNode, Prism::XStringNode)], closing_loc: T.nilable(Prism::Location)).void }
4929
4929
  def initialize(source, node_id, location, flags, opening_loc, parts, closing_loc); end
4930
4930
 
4931
4931
  sig { override.params(visitor: Prism::Visitor).returns(T.untyped) }
@@ -4943,7 +4943,7 @@ class Prism::InterpolatedStringNode < Prism::Node
4943
4943
  sig { override.returns(T::Array[T.any(Prism::Node, Prism::Location)]) }
4944
4944
  def comment_targets; end
4945
4945
 
4946
- sig { params(node_id: Integer, location: Prism::Location, flags: Integer, opening_loc: T.nilable(Prism::Location), parts: T::Array[T.any(Prism::StringNode, Prism::EmbeddedStatementsNode, Prism::EmbeddedVariableNode, Prism::InterpolatedStringNode)], closing_loc: T.nilable(Prism::Location)).returns(Prism::InterpolatedStringNode) }
4946
+ sig { params(node_id: Integer, location: Prism::Location, flags: Integer, opening_loc: T.nilable(Prism::Location), parts: T::Array[T.any(Prism::StringNode, Prism::EmbeddedStatementsNode, Prism::EmbeddedVariableNode, Prism::InterpolatedStringNode, Prism::XStringNode)], closing_loc: T.nilable(Prism::Location)).returns(Prism::InterpolatedStringNode) }
4947
4947
  def copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, parts: self.parts, closing_loc: self.closing_loc); end
4948
4948
 
4949
4949
  sig { params(keys: T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, T.untyped]) }
@@ -6558,6 +6558,9 @@ end
6558
6558
  # (10 + 34)
6559
6559
  # ^^^^^^^^^
6560
6560
  class Prism::ParenthesesNode < Prism::Node
6561
+ sig { returns(T::Boolean) }
6562
+ def multiple_statements?; end
6563
+
6561
6564
  sig { returns(T.nilable(Prism::Node)) }
6562
6565
  def body; end
6563
6566
 
@@ -7291,14 +7294,17 @@ class Prism::RescueNode < Prism::Node
7291
7294
  sig { returns(T.nilable(T.any(Prism::LocalVariableTargetNode, Prism::InstanceVariableTargetNode, Prism::ClassVariableTargetNode, Prism::GlobalVariableTargetNode, Prism::ConstantTargetNode, Prism::ConstantPathTargetNode, Prism::CallTargetNode, Prism::IndexTargetNode, Prism::BackReferenceReadNode, Prism::NumberedReferenceReadNode, Prism::MissingNode))) }
7292
7295
  def reference; end
7293
7296
 
7297
+ sig { returns(T.nilable(Prism::Location)) }
7298
+ def then_keyword_loc; end
7299
+
7294
7300
  sig { returns(T.nilable(Prism::StatementsNode)) }
7295
7301
  def statements; end
7296
7302
 
7297
7303
  sig { returns(T.nilable(Prism::RescueNode)) }
7298
7304
  def subsequent; end
7299
7305
 
7300
- sig { params(source: Prism::Source, node_id: Integer, location: Prism::Location, flags: Integer, keyword_loc: Prism::Location, exceptions: T::Array[Prism::Node], operator_loc: T.nilable(Prism::Location), reference: T.nilable(T.any(Prism::LocalVariableTargetNode, Prism::InstanceVariableTargetNode, Prism::ClassVariableTargetNode, Prism::GlobalVariableTargetNode, Prism::ConstantTargetNode, Prism::ConstantPathTargetNode, Prism::CallTargetNode, Prism::IndexTargetNode, Prism::BackReferenceReadNode, Prism::NumberedReferenceReadNode, Prism::MissingNode)), statements: T.nilable(Prism::StatementsNode), subsequent: T.nilable(Prism::RescueNode)).void }
7301
- def initialize(source, node_id, location, flags, keyword_loc, exceptions, operator_loc, reference, statements, subsequent); end
7306
+ sig { params(source: Prism::Source, node_id: Integer, location: Prism::Location, flags: Integer, keyword_loc: Prism::Location, exceptions: T::Array[Prism::Node], operator_loc: T.nilable(Prism::Location), reference: T.nilable(T.any(Prism::LocalVariableTargetNode, Prism::InstanceVariableTargetNode, Prism::ClassVariableTargetNode, Prism::GlobalVariableTargetNode, Prism::ConstantTargetNode, Prism::ConstantPathTargetNode, Prism::CallTargetNode, Prism::IndexTargetNode, Prism::BackReferenceReadNode, Prism::NumberedReferenceReadNode, Prism::MissingNode)), then_keyword_loc: T.nilable(Prism::Location), statements: T.nilable(Prism::StatementsNode), subsequent: T.nilable(Prism::RescueNode)).void }
7307
+ def initialize(source, node_id, location, flags, keyword_loc, exceptions, operator_loc, reference, then_keyword_loc, statements, subsequent); end
7302
7308
 
7303
7309
  sig { override.params(visitor: Prism::Visitor).returns(T.untyped) }
7304
7310
  def accept(visitor); end
@@ -7315,8 +7321,8 @@ class Prism::RescueNode < Prism::Node
7315
7321
  sig { override.returns(T::Array[T.any(Prism::Node, Prism::Location)]) }
7316
7322
  def comment_targets; end
7317
7323
 
7318
- sig { params(node_id: Integer, location: Prism::Location, flags: Integer, keyword_loc: Prism::Location, exceptions: T::Array[Prism::Node], operator_loc: T.nilable(Prism::Location), reference: T.nilable(T.any(Prism::LocalVariableTargetNode, Prism::InstanceVariableTargetNode, Prism::ClassVariableTargetNode, Prism::GlobalVariableTargetNode, Prism::ConstantTargetNode, Prism::ConstantPathTargetNode, Prism::CallTargetNode, Prism::IndexTargetNode, Prism::BackReferenceReadNode, Prism::NumberedReferenceReadNode, Prism::MissingNode)), statements: T.nilable(Prism::StatementsNode), subsequent: T.nilable(Prism::RescueNode)).returns(Prism::RescueNode) }
7319
- def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, exceptions: self.exceptions, operator_loc: self.operator_loc, reference: self.reference, statements: self.statements, subsequent: self.subsequent); end
7324
+ sig { params(node_id: Integer, location: Prism::Location, flags: Integer, keyword_loc: Prism::Location, exceptions: T::Array[Prism::Node], operator_loc: T.nilable(Prism::Location), reference: T.nilable(T.any(Prism::LocalVariableTargetNode, Prism::InstanceVariableTargetNode, Prism::ClassVariableTargetNode, Prism::GlobalVariableTargetNode, Prism::ConstantTargetNode, Prism::ConstantPathTargetNode, Prism::CallTargetNode, Prism::IndexTargetNode, Prism::BackReferenceReadNode, Prism::NumberedReferenceReadNode, Prism::MissingNode)), then_keyword_loc: T.nilable(Prism::Location), statements: T.nilable(Prism::StatementsNode), subsequent: T.nilable(Prism::RescueNode)).returns(Prism::RescueNode) }
7325
+ def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, exceptions: self.exceptions, operator_loc: self.operator_loc, reference: self.reference, then_keyword_loc: self.then_keyword_loc, statements: self.statements, subsequent: self.subsequent); end
7320
7326
 
7321
7327
  sig { params(keys: T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, T.untyped]) }
7322
7328
  def deconstruct_keys(keys); end
@@ -7327,6 +7333,9 @@ class Prism::RescueNode < Prism::Node
7327
7333
  sig { returns(T.nilable(String)) }
7328
7334
  def operator; end
7329
7335
 
7336
+ sig { returns(T.nilable(String)) }
7337
+ def then_keyword; end
7338
+
7330
7339
  sig { override.returns(T::Array[Prism::Reflection::Field]) }
7331
7340
  def fields; end
7332
7341
 
@@ -8244,6 +8253,9 @@ class Prism::UntilNode < Prism::Node
8244
8253
  sig { returns(Prism::Location) }
8245
8254
  def keyword_loc; end
8246
8255
 
8256
+ sig { returns(T.nilable(Prism::Location)) }
8257
+ def do_keyword_loc; end
8258
+
8247
8259
  sig { returns(T.nilable(Prism::Location)) }
8248
8260
  def closing_loc; end
8249
8261
 
@@ -8253,8 +8265,8 @@ class Prism::UntilNode < Prism::Node
8253
8265
  sig { returns(T.nilable(Prism::StatementsNode)) }
8254
8266
  def statements; end
8255
8267
 
8256
- sig { params(source: Prism::Source, node_id: Integer, location: Prism::Location, flags: Integer, keyword_loc: Prism::Location, closing_loc: T.nilable(Prism::Location), predicate: Prism::Node, statements: T.nilable(Prism::StatementsNode)).void }
8257
- def initialize(source, node_id, location, flags, keyword_loc, closing_loc, predicate, statements); end
8268
+ sig { params(source: Prism::Source, node_id: Integer, location: Prism::Location, flags: Integer, keyword_loc: Prism::Location, do_keyword_loc: T.nilable(Prism::Location), closing_loc: T.nilable(Prism::Location), predicate: Prism::Node, statements: T.nilable(Prism::StatementsNode)).void }
8269
+ def initialize(source, node_id, location, flags, keyword_loc, do_keyword_loc, closing_loc, predicate, statements); end
8258
8270
 
8259
8271
  sig { override.params(visitor: Prism::Visitor).returns(T.untyped) }
8260
8272
  def accept(visitor); end
@@ -8271,8 +8283,8 @@ class Prism::UntilNode < Prism::Node
8271
8283
  sig { override.returns(T::Array[T.any(Prism::Node, Prism::Location)]) }
8272
8284
  def comment_targets; end
8273
8285
 
8274
- sig { params(node_id: Integer, location: Prism::Location, flags: Integer, keyword_loc: Prism::Location, closing_loc: T.nilable(Prism::Location), predicate: Prism::Node, statements: T.nilable(Prism::StatementsNode)).returns(Prism::UntilNode) }
8275
- def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, closing_loc: self.closing_loc, predicate: self.predicate, statements: self.statements); end
8286
+ sig { params(node_id: Integer, location: Prism::Location, flags: Integer, keyword_loc: Prism::Location, do_keyword_loc: T.nilable(Prism::Location), closing_loc: T.nilable(Prism::Location), predicate: Prism::Node, statements: T.nilable(Prism::StatementsNode)).returns(Prism::UntilNode) }
8287
+ def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, do_keyword_loc: self.do_keyword_loc, closing_loc: self.closing_loc, predicate: self.predicate, statements: self.statements); end
8276
8288
 
8277
8289
  sig { params(keys: T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, T.untyped]) }
8278
8290
  def deconstruct_keys(keys); end
@@ -8280,6 +8292,9 @@ class Prism::UntilNode < Prism::Node
8280
8292
  sig { returns(String) }
8281
8293
  def keyword; end
8282
8294
 
8295
+ sig { returns(T.nilable(String)) }
8296
+ def do_keyword; end
8297
+
8283
8298
  sig { returns(T.nilable(String)) }
8284
8299
  def closing; end
8285
8300
 
@@ -8366,6 +8381,9 @@ class Prism::WhileNode < Prism::Node
8366
8381
  sig { returns(Prism::Location) }
8367
8382
  def keyword_loc; end
8368
8383
 
8384
+ sig { returns(T.nilable(Prism::Location)) }
8385
+ def do_keyword_loc; end
8386
+
8369
8387
  sig { returns(T.nilable(Prism::Location)) }
8370
8388
  def closing_loc; end
8371
8389
 
@@ -8375,8 +8393,8 @@ class Prism::WhileNode < Prism::Node
8375
8393
  sig { returns(T.nilable(Prism::StatementsNode)) }
8376
8394
  def statements; end
8377
8395
 
8378
- sig { params(source: Prism::Source, node_id: Integer, location: Prism::Location, flags: Integer, keyword_loc: Prism::Location, closing_loc: T.nilable(Prism::Location), predicate: Prism::Node, statements: T.nilable(Prism::StatementsNode)).void }
8379
- def initialize(source, node_id, location, flags, keyword_loc, closing_loc, predicate, statements); end
8396
+ sig { params(source: Prism::Source, node_id: Integer, location: Prism::Location, flags: Integer, keyword_loc: Prism::Location, do_keyword_loc: T.nilable(Prism::Location), closing_loc: T.nilable(Prism::Location), predicate: Prism::Node, statements: T.nilable(Prism::StatementsNode)).void }
8397
+ def initialize(source, node_id, location, flags, keyword_loc, do_keyword_loc, closing_loc, predicate, statements); end
8380
8398
 
8381
8399
  sig { override.params(visitor: Prism::Visitor).returns(T.untyped) }
8382
8400
  def accept(visitor); end
@@ -8393,8 +8411,8 @@ class Prism::WhileNode < Prism::Node
8393
8411
  sig { override.returns(T::Array[T.any(Prism::Node, Prism::Location)]) }
8394
8412
  def comment_targets; end
8395
8413
 
8396
- sig { params(node_id: Integer, location: Prism::Location, flags: Integer, keyword_loc: Prism::Location, closing_loc: T.nilable(Prism::Location), predicate: Prism::Node, statements: T.nilable(Prism::StatementsNode)).returns(Prism::WhileNode) }
8397
- def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, closing_loc: self.closing_loc, predicate: self.predicate, statements: self.statements); end
8414
+ sig { params(node_id: Integer, location: Prism::Location, flags: Integer, keyword_loc: Prism::Location, do_keyword_loc: T.nilable(Prism::Location), closing_loc: T.nilable(Prism::Location), predicate: Prism::Node, statements: T.nilable(Prism::StatementsNode)).returns(Prism::WhileNode) }
8415
+ def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, do_keyword_loc: self.do_keyword_loc, closing_loc: self.closing_loc, predicate: self.predicate, statements: self.statements); end
8398
8416
 
8399
8417
  sig { params(keys: T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, T.untyped]) }
8400
8418
  def deconstruct_keys(keys); end
@@ -8402,6 +8420,9 @@ class Prism::WhileNode < Prism::Node
8402
8420
  sig { returns(String) }
8403
8421
  def keyword; end
8404
8422
 
8423
+ sig { returns(T.nilable(String)) }
8424
+ def do_keyword; end
8425
+
8405
8426
  sig { returns(T.nilable(String)) }
8406
8427
  def closing; end
8407
8428
 
@@ -8619,6 +8640,12 @@ module Prism::ParameterFlags
8619
8640
  REPEATED_PARAMETER = T.let(1 << 2, Integer)
8620
8641
  end
8621
8642
 
8643
+ # Flags for parentheses nodes.
8644
+ module Prism::ParenthesesNodeFlags
8645
+ # parentheses that contain multiple potentially void statements
8646
+ MULTIPLE_STATEMENTS = T.let(1 << 2, Integer)
8647
+ end
8648
+
8622
8649
  # Flags for range and flip-flop nodes.
8623
8650
  module Prism::RangeFlags
8624
8651
  # ... operator
@@ -13,6 +13,12 @@ class Prism::Source
13
13
  sig { params(source: String, start_line: Integer, offsets: T::Array[Integer]).void }
14
14
  def initialize(source, start_line = 1, offsets = []); end
15
15
 
16
+ sig { params(start_line: Integer).void }
17
+ def replace_start_line(start_line); end
18
+
19
+ sig { params(offsets: T::Array[Integer]).void }
20
+ def replace_offsets(offsets); end
21
+
16
22
  sig { returns(Encoding) }
17
23
  def encoding; end
18
24
 
@@ -385,3 +391,14 @@ class Prism::Token
385
391
  sig { params(other: T.untyped).returns(T::Boolean) }
386
392
  def ==(other); end
387
393
  end
394
+
395
+ class Prism::Scope
396
+ sig { returns(T::Array[Symbol]) }
397
+ def locals; end
398
+
399
+ sig { returns(T::Array[Symbol]) }
400
+ def forwarding; end
401
+
402
+ sig { params(locals: T::Array[Symbol], forwarding: T::Array[Symbol]).void }
403
+ def initialize(locals, forwarding); end
404
+ end
@@ -0,0 +1,12 @@
1
+ # typed: strict
2
+
3
+ class Prism::StringQuery
4
+ sig { params(string: String).returns(T::Boolean) }
5
+ def self.local?(string); end
6
+
7
+ sig { params(string: String).returns(T::Boolean) }
8
+ def self.constant?(string); end
9
+
10
+ sig { params(string: String).returns(T::Boolean) }
11
+ def self.method_name?(string); end
12
+ end
@@ -0,0 +1,6 @@
1
+ # typed: strict
2
+
3
+ class Prism::Translation::Parser35 < Prism::Translation::Parser
4
+ sig { override.returns(Integer) }
5
+ def version; end
6
+ end