prism 1.2.0 → 1.3.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.
@@ -188,7 +188,7 @@ module Prism
188
188
  rescue_clause.exceptions.any? ? builder.array(nil, visit_all(rescue_clause.exceptions), nil) : nil,
189
189
  token(rescue_clause.operator_loc),
190
190
  visit(rescue_clause.reference),
191
- srange_find(find_start_offset, find_end_offset, [";"]),
191
+ srange_find(find_start_offset, find_end_offset, ";"),
192
192
  visit(rescue_clause.statements)
193
193
  )
194
194
  end until (rescue_clause = rescue_clause.subsequent).nil?
@@ -294,7 +294,7 @@ module Prism
294
294
  visit_all(arguments),
295
295
  token(node.closing_loc),
296
296
  ),
297
- srange_find(node.message_loc.end_offset, node.arguments.arguments.last.location.start_offset, ["="]),
297
+ srange_find(node.message_loc.end_offset, node.arguments.arguments.last.location.start_offset, "="),
298
298
  visit(node.arguments.arguments.last)
299
299
  ),
300
300
  block
@@ -311,7 +311,7 @@ module Prism
311
311
  if name.end_with?("=") && !message_loc.slice.end_with?("=") && node.arguments && block.nil?
312
312
  builder.assign(
313
313
  builder.attr_asgn(visit(node.receiver), call_operator, token(message_loc)),
314
- srange_find(message_loc.end_offset, node.arguments.location.start_offset, ["="]),
314
+ srange_find(message_loc.end_offset, node.arguments.location.start_offset, "="),
315
315
  visit(node.arguments.arguments.last)
316
316
  )
317
317
  else
@@ -733,10 +733,10 @@ module Prism
733
733
  visit(node.index),
734
734
  token(node.in_keyword_loc),
735
735
  visit(node.collection),
736
- if node.do_keyword_loc
737
- token(node.do_keyword_loc)
736
+ if (do_keyword_loc = node.do_keyword_loc)
737
+ token(do_keyword_loc)
738
738
  else
739
- srange_find(node.collection.location.end_offset, (node.statements&.location || node.end_keyword_loc).start_offset, [";"])
739
+ srange_find(node.collection.location.end_offset, (node.statements&.location || node.end_keyword_loc).start_offset, ";")
740
740
  end,
741
741
  visit(node.statements),
742
742
  token(node.end_keyword_loc)
@@ -865,10 +865,10 @@ module Prism
865
865
  builder.condition(
866
866
  token(node.if_keyword_loc),
867
867
  visit(node.predicate),
868
- if node.then_keyword_loc
869
- token(node.then_keyword_loc)
868
+ if (then_keyword_loc = node.then_keyword_loc)
869
+ token(then_keyword_loc)
870
870
  else
871
- srange_find(node.predicate.location.end_offset, (node.statements&.location || node.subsequent&.location || node.end_keyword_loc).start_offset, [";"])
871
+ srange_find(node.predicate.location.end_offset, (node.statements&.location || node.subsequent&.location || node.end_keyword_loc).start_offset, ";")
872
872
  end,
873
873
  visit(node.statements),
874
874
  case node.subsequent
@@ -931,7 +931,11 @@ module Prism
931
931
  token(node.in_loc),
932
932
  pattern,
933
933
  guard,
934
- srange_find(node.pattern.location.end_offset, node.statements&.location&.start_offset, [";", "then"]),
934
+ if (then_loc = node.then_loc)
935
+ token(then_loc)
936
+ else
937
+ srange_find(node.pattern.location.end_offset, node.statements&.location&.start_offset, ";")
938
+ end,
935
939
  visit(node.statements)
936
940
  )
937
941
  end
@@ -1781,10 +1785,10 @@ module Prism
1781
1785
  builder.condition(
1782
1786
  token(node.keyword_loc),
1783
1787
  visit(node.predicate),
1784
- if node.then_keyword_loc
1785
- token(node.then_keyword_loc)
1788
+ if (then_keyword_loc = node.then_keyword_loc)
1789
+ token(then_keyword_loc)
1786
1790
  else
1787
- srange_find(node.predicate.location.end_offset, (node.statements&.location || node.else_clause&.location || node.end_keyword_loc).start_offset, [";"])
1791
+ srange_find(node.predicate.location.end_offset, (node.statements&.location || node.else_clause&.location || node.end_keyword_loc).start_offset, ";")
1788
1792
  end,
1789
1793
  visit(node.else_clause),
1790
1794
  token(node.else_clause&.else_keyword_loc),
@@ -1812,7 +1816,11 @@ module Prism
1812
1816
  :until,
1813
1817
  token(node.keyword_loc),
1814
1818
  visit(node.predicate),
1815
- srange_find(node.predicate.location.end_offset, (node.statements&.location || node.closing_loc).start_offset, [";", "do"]),
1819
+ if (do_keyword_loc = node.do_keyword_loc)
1820
+ token(do_keyword_loc)
1821
+ else
1822
+ srange_find(node.predicate.location.end_offset, (node.statements&.location || node.closing_loc).start_offset, ";")
1823
+ end,
1816
1824
  visit(node.statements),
1817
1825
  token(node.closing_loc)
1818
1826
  )
@@ -1832,10 +1840,10 @@ module Prism
1832
1840
  builder.when(
1833
1841
  token(node.keyword_loc),
1834
1842
  visit_all(node.conditions),
1835
- if node.then_keyword_loc
1836
- token(node.then_keyword_loc)
1843
+ if (then_keyword_loc = node.then_keyword_loc)
1844
+ token(then_keyword_loc)
1837
1845
  else
1838
- srange_find(node.conditions.last.location.end_offset, node.statements&.location&.start_offset, [";"])
1846
+ srange_find(node.conditions.last.location.end_offset, node.statements&.location&.start_offset, ";")
1839
1847
  end,
1840
1848
  visit(node.statements)
1841
1849
  )
@@ -1852,7 +1860,11 @@ module Prism
1852
1860
  :while,
1853
1861
  token(node.keyword_loc),
1854
1862
  visit(node.predicate),
1855
- srange_find(node.predicate.location.end_offset, (node.statements&.location || node.closing_loc).start_offset, [";", "do"]),
1863
+ if (do_keyword_loc = node.do_keyword_loc)
1864
+ token(do_keyword_loc)
1865
+ else
1866
+ srange_find(node.predicate.location.end_offset, (node.statements&.location || node.closing_loc).start_offset, ";")
1867
+ end,
1856
1868
  visit(node.statements),
1857
1869
  token(node.closing_loc)
1858
1870
  )
@@ -1985,18 +1997,16 @@ module Prism
1985
1997
  Range.new(source_buffer, offset_cache[start_offset], offset_cache[end_offset])
1986
1998
  end
1987
1999
 
1988
- # Constructs a new source range by finding the given tokens between the
1989
- # given start offset and end offset. If the needle is not found, it
2000
+ # Constructs a new source range by finding the given character between
2001
+ # the given start offset and end offset. If the needle is not found, it
1990
2002
  # returns nil. Importantly it does not search past newlines or comments.
1991
2003
  #
1992
2004
  # Note that end_offset is allowed to be nil, in which case this will
1993
2005
  # search until the end of the string.
1994
- def srange_find(start_offset, end_offset, tokens)
1995
- if (match = source_buffer.source.byteslice(start_offset...end_offset).match(/\A(\s*)(#{tokens.join("|")})/))
1996
- _, whitespace, token = *match
1997
- token_offset = start_offset + whitespace.bytesize
1998
-
1999
- [token, Range.new(source_buffer, offset_cache[token_offset], offset_cache[token_offset + token.bytesize])]
2006
+ def srange_find(start_offset, end_offset, character)
2007
+ if (match = source_buffer.source.byteslice(start_offset...end_offset)[/\A\s*#{character}/])
2008
+ final_offset = start_offset + match.bytesize
2009
+ [character, Range.new(source_buffer, offset_cache[final_offset - character.bytesize], offset_cache[final_offset])]
2000
2010
  end
2001
2011
  end
2002
2012
 
@@ -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,7 +926,9 @@ module Prism
923
926
  state = :interpolated_content
924
927
  end
925
928
  when :string_content
926
- if result.is_a?(String)
929
+ if result == :space
930
+ # continue
931
+ elsif result.is_a?(String)
927
932
  results[0] << result
928
933
  elsif result.is_a?(Array) && result[0] == :str
929
934
  results[0] << result[1]
@@ -932,7 +937,9 @@ module Prism
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)
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)
936
943
  results[-1][1] << result[1]
937
944
  results[-1].line_max = result.line_max
938
945
  else
@@ -940,6 +947,8 @@ module Prism
940
947
  end
941
948
  end
942
949
  end
950
+
951
+ results
943
952
  end
944
953
 
945
954
  # -> { it }
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
 
@@ -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.3.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",
@@ -88,7 +89,9 @@ Gem::Specification.new do |spec|
88
89
  "lib/prism/polyfill/byteindex.rb",
89
90
  "lib/prism/polyfill/unpack1.rb",
90
91
  "lib/prism/reflection.rb",
92
+ "lib/prism/relocation.rb",
91
93
  "lib/prism/serialize.rb",
94
+ "lib/prism/string_query.rb",
92
95
  "lib/prism/translation.rb",
93
96
  "lib/prism/translation/parser.rb",
94
97
  "lib/prism/translation/parser33.rb",
@@ -109,6 +112,7 @@ Gem::Specification.new do |spec|
109
112
  "rbi/prism/node.rbi",
110
113
  "rbi/prism/parse_result.rbi",
111
114
  "rbi/prism/reflection.rbi",
115
+ "rbi/prism/string_query.rbi",
112
116
  "rbi/prism/translation/parser.rbi",
113
117
  "rbi/prism/translation/parser33.rbi",
114
118
  "rbi/prism/translation/parser34.rbi",
@@ -128,7 +132,9 @@ Gem::Specification.new do |spec|
128
132
  "sig/prism/parse_result.rbs",
129
133
  "sig/prism/pattern.rbs",
130
134
  "sig/prism/reflection.rbs",
135
+ "sig/prism/relocation.rbs",
131
136
  "sig/prism/serialize.rbs",
137
+ "sig/prism/string_query.rbs",
132
138
  "sig/prism/visitor.rbs",
133
139
  "src/diagnostic.c",
134
140
  "src/encoding.c",
data/rbi/prism/dsl.rbi CHANGED
@@ -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
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
  # ^^^^^^^^^^^^
@@ -8244,6 +8244,9 @@ class Prism::UntilNode < Prism::Node
8244
8244
  sig { returns(Prism::Location) }
8245
8245
  def keyword_loc; end
8246
8246
 
8247
+ sig { returns(T.nilable(Prism::Location)) }
8248
+ def do_keyword_loc; end
8249
+
8247
8250
  sig { returns(T.nilable(Prism::Location)) }
8248
8251
  def closing_loc; end
8249
8252
 
@@ -8253,8 +8256,8 @@ class Prism::UntilNode < Prism::Node
8253
8256
  sig { returns(T.nilable(Prism::StatementsNode)) }
8254
8257
  def statements; end
8255
8258
 
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
8259
+ 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 }
8260
+ def initialize(source, node_id, location, flags, keyword_loc, do_keyword_loc, closing_loc, predicate, statements); end
8258
8261
 
8259
8262
  sig { override.params(visitor: Prism::Visitor).returns(T.untyped) }
8260
8263
  def accept(visitor); end
@@ -8271,8 +8274,8 @@ class Prism::UntilNode < Prism::Node
8271
8274
  sig { override.returns(T::Array[T.any(Prism::Node, Prism::Location)]) }
8272
8275
  def comment_targets; end
8273
8276
 
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
8277
+ 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) }
8278
+ 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
8279
 
8277
8280
  sig { params(keys: T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, T.untyped]) }
8278
8281
  def deconstruct_keys(keys); end
@@ -8280,6 +8283,9 @@ class Prism::UntilNode < Prism::Node
8280
8283
  sig { returns(String) }
8281
8284
  def keyword; end
8282
8285
 
8286
+ sig { returns(T.nilable(String)) }
8287
+ def do_keyword; end
8288
+
8283
8289
  sig { returns(T.nilable(String)) }
8284
8290
  def closing; end
8285
8291
 
@@ -8366,6 +8372,9 @@ class Prism::WhileNode < Prism::Node
8366
8372
  sig { returns(Prism::Location) }
8367
8373
  def keyword_loc; end
8368
8374
 
8375
+ sig { returns(T.nilable(Prism::Location)) }
8376
+ def do_keyword_loc; end
8377
+
8369
8378
  sig { returns(T.nilable(Prism::Location)) }
8370
8379
  def closing_loc; end
8371
8380
 
@@ -8375,8 +8384,8 @@ class Prism::WhileNode < Prism::Node
8375
8384
  sig { returns(T.nilable(Prism::StatementsNode)) }
8376
8385
  def statements; end
8377
8386
 
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
8387
+ 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 }
8388
+ def initialize(source, node_id, location, flags, keyword_loc, do_keyword_loc, closing_loc, predicate, statements); end
8380
8389
 
8381
8390
  sig { override.params(visitor: Prism::Visitor).returns(T.untyped) }
8382
8391
  def accept(visitor); end
@@ -8393,8 +8402,8 @@ class Prism::WhileNode < Prism::Node
8393
8402
  sig { override.returns(T::Array[T.any(Prism::Node, Prism::Location)]) }
8394
8403
  def comment_targets; end
8395
8404
 
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
8405
+ 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) }
8406
+ 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
8407
 
8399
8408
  sig { params(keys: T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, T.untyped]) }
8400
8409
  def deconstruct_keys(keys); end
@@ -8402,6 +8411,9 @@ class Prism::WhileNode < Prism::Node
8402
8411
  sig { returns(String) }
8403
8412
  def keyword; end
8404
8413
 
8414
+ sig { returns(T.nilable(String)) }
8415
+ def do_keyword; end
8416
+
8405
8417
  sig { returns(T.nilable(String)) }
8406
8418
  def closing; end
8407
8419
 
@@ -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
data/sig/prism/dsl.rbs CHANGED
@@ -300,11 +300,11 @@ module Prism
300
300
 
301
301
  def unless_node: (?source: Source, ?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?predicate: Prism::node, ?then_keyword_loc: Location?, ?statements: StatementsNode?, ?else_clause: ElseNode?, ?end_keyword_loc: Location?) -> UnlessNode
302
302
 
303
- def until_node: (?source: Source, ?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?closing_loc: Location?, ?predicate: Prism::node, ?statements: StatementsNode?) -> UntilNode
303
+ def until_node: (?source: Source, ?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?do_keyword_loc: Location?, ?closing_loc: Location?, ?predicate: Prism::node, ?statements: StatementsNode?) -> UntilNode
304
304
 
305
305
  def when_node: (?source: Source, ?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?conditions: Array[Prism::node], ?then_keyword_loc: Location?, ?statements: StatementsNode?) -> WhenNode
306
306
 
307
- def while_node: (?source: Source, ?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?closing_loc: Location?, ?predicate: Prism::node, ?statements: StatementsNode?) -> WhileNode
307
+ def while_node: (?source: Source, ?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?do_keyword_loc: Location?, ?closing_loc: Location?, ?predicate: Prism::node, ?statements: StatementsNode?) -> WhileNode
308
308
 
309
309
  def x_string_node: (?source: Source, ?node_id: Integer, ?location: Location, ?flags: Integer, ?opening_loc: Location, ?content_loc: Location, ?closing_loc: Location, ?unescaped: String) -> XStringNode
310
310
 
data/sig/prism/node.rbs CHANGED
@@ -184,8 +184,8 @@ module Prism
184
184
  # foo in [1, 2]
185
185
  # ^^^^^^^^^^^^^
186
186
  #
187
- # foo in *1
188
- # ^^^^^^^^^
187
+ # foo in *bar
188
+ # ^^^^^^^^^^^
189
189
  #
190
190
  # foo in Bar[]
191
191
  # ^^^^^^^^^^^^
@@ -3336,14 +3336,16 @@ module Prism
3336
3336
  def begin_modifier?: () -> bool
3337
3337
 
3338
3338
  attr_reader keyword_loc: Location
3339
+ attr_reader do_keyword_loc: Location?
3339
3340
  attr_reader closing_loc: Location?
3340
3341
  attr_reader predicate: Prism::node
3341
3342
  attr_reader statements: StatementsNode?
3342
3343
 
3343
- def initialize: (Source source, Integer node_id, Location location, Integer flags, Location keyword_loc, Location? closing_loc, Prism::node predicate, StatementsNode? statements) -> void
3344
- def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?closing_loc: Location?, ?predicate: Prism::node, ?statements: StatementsNode?) -> UntilNode
3345
- def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, keyword_loc: Location, closing_loc: Location?, predicate: Prism::node, statements: StatementsNode? }
3344
+ def initialize: (Source source, Integer node_id, Location location, Integer flags, Location keyword_loc, Location? do_keyword_loc, Location? closing_loc, Prism::node predicate, StatementsNode? statements) -> void
3345
+ def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?do_keyword_loc: Location?, ?closing_loc: Location?, ?predicate: Prism::node, ?statements: StatementsNode?) -> UntilNode
3346
+ def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, keyword_loc: Location, do_keyword_loc: Location?, closing_loc: Location?, predicate: Prism::node, statements: StatementsNode? }
3346
3347
  def keyword: () -> String
3348
+ def do_keyword: () -> String?
3347
3349
  def closing: () -> String?
3348
3350
  def type: () -> :until_node
3349
3351
  | ...
@@ -3387,14 +3389,16 @@ module Prism
3387
3389
  def begin_modifier?: () -> bool
3388
3390
 
3389
3391
  attr_reader keyword_loc: Location
3392
+ attr_reader do_keyword_loc: Location?
3390
3393
  attr_reader closing_loc: Location?
3391
3394
  attr_reader predicate: Prism::node
3392
3395
  attr_reader statements: StatementsNode?
3393
3396
 
3394
- def initialize: (Source source, Integer node_id, Location location, Integer flags, Location keyword_loc, Location? closing_loc, Prism::node predicate, StatementsNode? statements) -> void
3395
- def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?closing_loc: Location?, ?predicate: Prism::node, ?statements: StatementsNode?) -> WhileNode
3396
- def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, keyword_loc: Location, closing_loc: Location?, predicate: Prism::node, statements: StatementsNode? }
3397
+ def initialize: (Source source, Integer node_id, Location location, Integer flags, Location keyword_loc, Location? do_keyword_loc, Location? closing_loc, Prism::node predicate, StatementsNode? statements) -> void
3398
+ def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?do_keyword_loc: Location?, ?closing_loc: Location?, ?predicate: Prism::node, ?statements: StatementsNode?) -> WhileNode
3399
+ def deconstruct_keys: (Array[Symbol] keys) -> { node_id: Integer, location: Location, keyword_loc: Location, do_keyword_loc: Location?, closing_loc: Location?, predicate: Prism::node, statements: StatementsNode? }
3397
3400
  def keyword: () -> String
3401
+ def do_keyword: () -> String?
3398
3402
  def closing: () -> String?
3399
3403
  def type: () -> :while_node
3400
3404
  | ...
@@ -0,0 +1,185 @@
1
+ module Prism
2
+ module Relocation
3
+ interface _Value
4
+ def start_line: () -> Integer
5
+ def end_line: () -> Integer
6
+ def start_offset: () -> Integer
7
+ def end_offset: () -> Integer
8
+ def start_character_offset: () -> Integer
9
+ def end_character_offset: () -> Integer
10
+ def cached_start_code_units_offset: (_CodeUnitsCache cache) -> Integer
11
+ def cached_end_code_units_offset: (_CodeUnitsCache cache) -> Integer
12
+ def start_column: () -> Integer
13
+ def end_column: () -> Integer
14
+ def start_character_column: () -> Integer
15
+ def end_character_column: () -> Integer
16
+ def cached_start_code_units_column: (_CodeUnitsCache cache) -> Integer
17
+ def cached_end_code_units_column: (_CodeUnitsCache cache) -> Integer
18
+ def leading_comments: () -> Array[Comment]
19
+ def trailing_comments: () -> Array[Comment]
20
+ end
21
+
22
+ interface _Field
23
+ def fields: (_Value value) -> entry_values
24
+ end
25
+
26
+ type entry_value = untyped
27
+ type entry_values = Hash[Symbol, entry_value]
28
+
29
+ class Entry
30
+ class MissingValueError < StandardError
31
+ end
32
+
33
+ def initialize: (Repository repository) -> void
34
+
35
+ def filepath: () -> String
36
+
37
+ def start_line: () -> Integer
38
+ def end_line: () -> Integer
39
+
40
+ def start_offset: () -> Integer
41
+ def end_offset: () -> Integer
42
+ def start_character_offset: () -> Integer
43
+ def end_character_offset: () -> Integer
44
+ def start_code_units_offset: () -> Integer
45
+ def end_code_units_offset: () -> Integer
46
+
47
+ def start_column: () -> Integer
48
+ def end_column: () -> Integer
49
+ def start_character_column: () -> Integer
50
+ def end_character_column: () -> Integer
51
+ def start_code_units_column: () -> Integer
52
+ def end_code_units_column: () -> Integer
53
+
54
+ def leading_comments: () -> Array[CommentsField::Comment]
55
+ def trailing_comments: () -> Array[CommentsField::Comment]
56
+ def comments: () -> Array[CommentsField::Comment]
57
+
58
+ private
59
+
60
+ def fetch_value: (Symbol name) -> entry_value
61
+ def values: () -> entry_values
62
+ end
63
+
64
+ class Source
65
+ attr_reader value: untyped
66
+
67
+ def initialize: (untyped value) -> void
68
+
69
+ def result: () -> ParseResult
70
+ def code_units_cache: (Encoding encoding) -> _CodeUnitsCache
71
+ end
72
+
73
+ class SourceFilepath < Source
74
+ def result: () -> ParseResult
75
+ end
76
+
77
+ class SourceString < Source
78
+ def result: () -> ParseResult
79
+ end
80
+
81
+ class FilepathField
82
+ attr_reader value: String
83
+
84
+ def initialize: (String value) -> void
85
+
86
+ def fields: (_Value value) -> entry_values
87
+ end
88
+
89
+ class LinesField
90
+ def fields: (_Value value) -> entry_values
91
+ end
92
+
93
+ class OffsetsField
94
+ def fields: (_Value value) -> entry_values
95
+ end
96
+
97
+ class CharacterOffsetsField
98
+ def fields: (_Value value) -> entry_values
99
+ end
100
+
101
+ class CodeUnitOffsetsField
102
+ attr_reader repository: Repository
103
+ attr_reader encoding: Encoding
104
+
105
+ def initialize: (Repository repository, Encoding encoding) -> void
106
+ def fields: (_Value value) -> entry_values
107
+
108
+ private
109
+
110
+ def cache: () -> _CodeUnitsCache
111
+ end
112
+
113
+ class ColumnsField
114
+ def fields: (_Value value) -> entry_values
115
+ end
116
+
117
+ class CharacterColumnsField
118
+ def fields: (_Value value) -> entry_values
119
+ end
120
+
121
+ class CodeUnitColumnsField
122
+ attr_reader repository: Repository
123
+ attr_reader encoding: Encoding
124
+
125
+ def initialize: (Repository repository, Encoding encoding) -> void
126
+ def fields: (_Value value) -> entry_values
127
+
128
+ private
129
+
130
+ def cache: () -> _CodeUnitsCache
131
+ end
132
+
133
+ class CommentsField
134
+ class Comment
135
+ attr_reader slice: String
136
+
137
+ def initialize: (String slice) -> void
138
+ end
139
+
140
+ private
141
+
142
+ def comments: (entry_value value) -> Array[Comment]
143
+ end
144
+
145
+ class LeadingCommentsField < CommentsField
146
+ def fields: (_Value value) -> entry_values
147
+ end
148
+
149
+ class TrailingCommentsField < CommentsField
150
+ def fields: (_Value value) -> entry_values
151
+ end
152
+
153
+ class Repository
154
+ class ConfigurationError < StandardError
155
+ end
156
+
157
+ attr_reader source: Source
158
+ attr_reader fields: Hash[Symbol, _Field]
159
+ attr_reader entries: Hash[Integer, Hash[Symbol, Entry]]
160
+
161
+ def initialize: (Source source) -> void
162
+
163
+ def code_units_cache: (Encoding encoding) -> _CodeUnitsCache
164
+
165
+ def filepath: () -> self
166
+ def lines: () -> self
167
+ def offsets: () -> self
168
+ def character_offsets: () -> self
169
+ def code_unit_offsets: (Encoding encoding) -> self
170
+ def columns: () -> self
171
+ def character_columns: () -> self
172
+ def code_unit_columns: (Encoding encoding) -> self
173
+ def leading_comments: () -> self
174
+ def trailing_comments: () -> self
175
+ def comments: () -> self
176
+
177
+ private
178
+
179
+ def field: (Symbol name, _Field) -> self
180
+ end
181
+
182
+ def self.filepath: (String value) -> Repository
183
+ def self.string: (String value) -> Repository
184
+ end
185
+ end
@@ -0,0 +1,11 @@
1
+ module Prism
2
+ class StringQuery
3
+ attr_reader string: String
4
+
5
+ def initialize: (String string) -> void
6
+
7
+ def local?: () -> bool
8
+ def constant?: () -> bool
9
+ def method_name?: () -> bool
10
+ end
11
+ end