prism 0.26.0 → 0.27.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -805,17 +805,29 @@ module Prism
805
805
  # if /foo #{bar}/ then end
806
806
  # ^^^^^^^^^^^^
807
807
  def visit_interpolated_match_last_line_node(node)
808
- s(node, :match, s(node, :dregx).concat(visit_interpolated_parts(node.parts)))
808
+ parts = visit_interpolated_parts(node.parts)
809
+ regexp =
810
+ if parts.length == 1
811
+ s(node, :lit, Regexp.new(parts.first, node.options))
812
+ else
813
+ s(node, :dregx).concat(parts).tap do |result|
814
+ options = node.options
815
+ result << options if options != 0
816
+ end
817
+ end
818
+
819
+ s(node, :match, regexp)
809
820
  end
810
821
 
811
822
  # /foo #{bar}/
812
823
  # ^^^^^^^^^^^^
813
824
  def visit_interpolated_regular_expression_node(node)
814
- if node.parts.all? { |part| part.is_a?(StringNode) || (part.is_a?(EmbeddedStatementsNode) && part.statements&.body&.length == 1 && part.statements.body.first.is_a?(StringNode)) }
815
- unescaped = node.parts.map { |part| part.is_a?(StringNode) ? part.unescaped : part.statements.body.first.unescaped }.join
816
- s(node, :lit, Regexp.new(unescaped, node.options))
825
+ parts = visit_interpolated_parts(node.parts)
826
+
827
+ if parts.length == 1
828
+ s(node, :lit, Regexp.new(parts.first, node.options))
817
829
  else
818
- s(node, :dregx).concat(visit_interpolated_parts(node.parts)).tap do |result|
830
+ s(node, :dregx).concat(parts).tap do |result|
819
831
  options = node.options
820
832
  result << options if options != 0
821
833
  end
@@ -825,45 +837,71 @@ module Prism
825
837
  # "foo #{bar}"
826
838
  # ^^^^^^^^^^^^
827
839
  def visit_interpolated_string_node(node)
828
- if (node.parts.all? { |part| part.is_a?(StringNode) || (part.is_a?(EmbeddedStatementsNode) && part.statements&.body&.length == 1 && part.statements.body.first.is_a?(StringNode)) }) ||
829
- (node.opening.nil? && node.parts.all? { |part| part.is_a?(StringNode) && !part.opening_loc.nil? })
830
- unescaped = node.parts.map { |part| part.is_a?(StringNode) ? part.unescaped : part.statements.body.first.unescaped }.join
831
- s(node, :str, unescaped)
832
- else
833
- s(node, :dstr).concat(visit_interpolated_parts(node.parts))
834
- end
840
+ parts = visit_interpolated_parts(node.parts)
841
+ parts.length == 1 ? s(node, :str, parts.first) : s(node, :dstr).concat(parts)
835
842
  end
836
843
 
837
844
  # :"foo #{bar}"
838
845
  # ^^^^^^^^^^^^^
839
846
  def visit_interpolated_symbol_node(node)
840
- if node.parts.all? { |part| part.is_a?(StringNode) || (part.is_a?(EmbeddedStatementsNode) && part.statements&.body&.length == 1 && part.statements.body.first.is_a?(StringNode)) }
841
- unescaped = node.parts.map { |part| part.is_a?(StringNode) ? part.unescaped : part.statements.body.first.unescaped }.join
842
- s(node, :lit, unescaped.to_sym)
843
- else
844
- s(node, :dsym).concat(visit_interpolated_parts(node.parts))
845
- end
847
+ parts = visit_interpolated_parts(node.parts)
848
+ parts.length == 1 ? s(node, :lit, parts.first.to_sym) : s(node, :dsym).concat(parts)
846
849
  end
847
850
 
848
851
  # `foo #{bar}`
849
852
  # ^^^^^^^^^^^^
850
853
  def visit_interpolated_x_string_node(node)
851
- children = visit_interpolated_parts(node.parts)
852
- s(node.heredoc? ? node.parts.first : node, :dxstr).concat(children)
854
+ source = node.heredoc? ? node.parts.first : node
855
+ parts = visit_interpolated_parts(node.parts)
856
+ parts.length == 1 ? s(source, :xstr, parts.first) : s(source, :dxstr).concat(parts)
853
857
  end
854
858
 
855
859
  # Visit the interpolated content of the string-like node.
856
860
  private def visit_interpolated_parts(parts)
857
- parts.each_with_object([]).with_index do |(part, results), index|
858
- if index == 0
859
- if part.is_a?(StringNode)
860
- results << part.unescaped
861
+ visited = []
862
+ parts.each do |part|
863
+ result = visit(part)
864
+
865
+ if result[0] == :evstr && result[1]
866
+ if result[1][0] == :str
867
+ visited << result[1]
868
+ elsif result[1][0] == :dstr
869
+ visited.concat(result[1][1..-1])
870
+ else
871
+ visited << result
872
+ end
873
+ else
874
+ visited << result
875
+ end
876
+ end
877
+
878
+ state = :beginning #: :beginning | :string_content | :interpolated_content
879
+
880
+ visited.each_with_object([]) do |result, results|
881
+ case state
882
+ when :beginning
883
+ if result.is_a?(String)
884
+ results << result
885
+ state = :string_content
886
+ elsif result.is_a?(Array) && result[0] == :str
887
+ results << result[1]
888
+ state = :string_content
861
889
  else
862
890
  results << ""
863
- results << visit(part)
891
+ results << result
892
+ state = :interpolated_content
893
+ end
894
+ when :string_content
895
+ if result.is_a?(String)
896
+ results[0] << result
897
+ elsif result.is_a?(Array) && result[0] == :str
898
+ results[0] << result[1]
899
+ else
900
+ results << result
901
+ state = :interpolated_content
864
902
  end
865
903
  else
866
- results << visit(part)
904
+ results << result
867
905
  end
868
906
  end
869
907
  end
@@ -1297,7 +1335,7 @@ module Prism
1297
1335
  # __FILE__
1298
1336
  # ^^^^^^^^
1299
1337
  def visit_source_file_node(node)
1300
- s(node, :str, file)
1338
+ s(node, :str, node.filepath)
1301
1339
  end
1302
1340
 
1303
1341
  # __LINE__
@@ -1498,7 +1536,7 @@ module Prism
1498
1536
  # Parse the given source and translate it into the seattlerb/ruby_parser
1499
1537
  # gem's Sexp format.
1500
1538
  def parse(source, filepath = "(string)")
1501
- translate(Prism.parse(source), filepath)
1539
+ translate(Prism.parse(source, filepath: filepath), filepath)
1502
1540
  end
1503
1541
 
1504
1542
  # Parse the given file and translate it into the seattlerb/ruby_parser
data/lib/prism.rb CHANGED
@@ -37,7 +37,7 @@ module Prism
37
37
  private_constant :LexRipper
38
38
 
39
39
  # :call-seq:
40
- # Prism::lex_compat(source, **options) -> ParseResult
40
+ # Prism::lex_compat(source, **options) -> LexCompat::Result
41
41
  #
42
42
  # Returns a parse result whose value is an array of tokens that closely
43
43
  # resembles the return value of Ripper::lex. The main difference is that the
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 = "0.26.0"
5
+ spec.version = "0.27.0"
6
6
  spec.authors = ["Shopify"]
7
7
  spec.email = ["ruby@shopify.com"]
8
8
 
data/rbi/prism/node.rbi CHANGED
@@ -10,7 +10,7 @@ class Prism::Node
10
10
  abstract!
11
11
 
12
12
  sig { returns(Prism::Source) }
13
- attr_reader :source
13
+ def source; end
14
14
 
15
15
  sig { returns(Prism::Location) }
16
16
  def location; end
@@ -3754,13 +3754,16 @@ class Prism::HashPatternNode < Prism::Node
3754
3754
  def type; end
3755
3755
  end
3756
3756
 
3757
- # Represents the use of the `if` keyword, either in the block form or the modifier form.
3757
+ # Represents the use of the `if` keyword, either in the block form or the modifier form, or a ternary expression.
3758
3758
  #
3759
3759
  # bar if foo
3760
3760
  # ^^^^^^^^^^
3761
3761
  #
3762
3762
  # if foo then bar end
3763
3763
  # ^^^^^^^^^^^^^^^^^^^
3764
+ #
3765
+ # foo ? bar : baz
3766
+ # ^^^^^^^^^^^^^^^
3764
3767
  class Prism::IfNode < Prism::Node
3765
3768
  sig { returns(T.nilable(Prism::Location)) }
3766
3769
  def if_keyword_loc; end
@@ -2,13 +2,13 @@
2
2
 
3
3
  class Prism::Source
4
4
  sig { returns(String) }
5
- attr_reader :source
5
+ def source; end
6
6
 
7
7
  sig { returns(Integer) }
8
- attr_reader :start_line
8
+ def start_line; end
9
9
 
10
10
  sig { returns(T::Array[Integer]) }
11
- attr_reader :offsets
11
+ def offsets; end
12
12
 
13
13
  sig { params(source: String, start_line: Integer, offsets: T::Array[Integer]).void }
14
14
  def initialize(source, start_line = 1, offsets = []); end
@@ -43,13 +43,13 @@ end
43
43
 
44
44
  class Prism::Location
45
45
  sig { returns(Prism::Source) }
46
- attr_reader :source
46
+ def source; end
47
47
 
48
48
  sig { returns(Integer) }
49
- attr_reader :start_offset
49
+ def start_offset; end
50
50
 
51
51
  sig { returns(Integer) }
52
- attr_reader :length
52
+ def length; end
53
53
 
54
54
  sig { params(source: Prism::Source, start_offset: Integer, length: Integer).void }
55
55
  def initialize(source, start_offset, length); end
@@ -140,7 +140,7 @@ class Prism::Comment
140
140
  abstract!
141
141
 
142
142
  sig { returns(Prism::Location) }
143
- attr_reader :location
143
+ def location; end
144
144
 
145
145
  sig { params(location: Prism::Location).void }
146
146
  def initialize(location); end
@@ -173,10 +173,10 @@ end
173
173
 
174
174
  class Prism::MagicComment
175
175
  sig { returns(Prism::Location) }
176
- attr_reader :key_loc
176
+ def key_loc; end
177
177
 
178
178
  sig { returns(Prism::Location) }
179
- attr_reader :value_loc
179
+ def value_loc; end
180
180
 
181
181
  sig { params(key_loc: Prism::Location, value_loc: Prism::Location).void }
182
182
  def initialize(key_loc, value_loc); end
@@ -196,16 +196,16 @@ end
196
196
 
197
197
  class Prism::ParseError
198
198
  sig { returns(Symbol) }
199
- attr_reader :type
199
+ def type; end
200
200
 
201
201
  sig { returns(String) }
202
- attr_reader :message
202
+ def message; end
203
203
 
204
204
  sig { returns(Prism::Location) }
205
- attr_reader :location
205
+ def location; end
206
206
 
207
207
  sig { returns(Symbol) }
208
- attr_reader :level
208
+ def level; end
209
209
 
210
210
  sig { params(type: Symbol, message: String, location: Prism::Location, level: Symbol).void }
211
211
  def initialize(type, message, location, level); end
@@ -219,16 +219,16 @@ end
219
219
 
220
220
  class Prism::ParseWarning
221
221
  sig { returns(Symbol) }
222
- attr_reader :type
222
+ def type; end
223
223
 
224
224
  sig { returns(String) }
225
- attr_reader :message
225
+ def message; end
226
226
 
227
227
  sig { returns(Prism::Location) }
228
- attr_reader :location
228
+ def location; end
229
229
 
230
230
  sig { returns(Symbol) }
231
- attr_reader :level
231
+ def level; end
232
232
 
233
233
  sig { params(type: Symbol, message: String, location: Prism::Location, level: Symbol).void }
234
234
  def initialize(type, message, location, level); end
@@ -240,32 +240,27 @@ class Prism::ParseWarning
240
240
  def inspect; end
241
241
  end
242
242
 
243
- class Prism::ParseResult
244
- Value = type_member
245
-
246
- sig { returns(Value) }
247
- attr_reader :value
243
+ class Prism::Result
244
+ sig { params(comments: T::Array[Prism::Comment], magic_comments: T::Array[Prism::MagicComment], data_loc: T.nilable(Prism::Location), errors: T::Array[Prism::ParseError], warnings: T::Array[Prism::ParseWarning], source: Prism::Source).void }
245
+ def initialize(comments, magic_comments, data_loc, errors, warnings, source); end
248
246
 
249
247
  sig { returns(T::Array[Prism::Comment]) }
250
- attr_reader :comments
248
+ def comments; end
251
249
 
252
250
  sig { returns(T::Array[Prism::MagicComment]) }
253
- attr_reader :magic_comments
251
+ def magic_comments; end
254
252
 
255
253
  sig { returns(T.nilable(Prism::Location)) }
256
- attr_reader :data_loc
254
+ def data_loc; end
257
255
 
258
256
  sig { returns(T::Array[Prism::ParseError]) }
259
- attr_reader :errors
257
+ def errors; end
260
258
 
261
259
  sig { returns(T::Array[Prism::ParseWarning]) }
262
- attr_reader :warnings
260
+ def warnings; end
263
261
 
264
262
  sig { returns(Prism::Source) }
265
- attr_reader :source
266
-
267
- sig { params(value: Value, comments: T::Array[Prism::Comment], magic_comments: T::Array[Prism::MagicComment], data_loc: T.nilable(Prism::Location), errors: T::Array[Prism::ParseError], warnings: T::Array[Prism::ParseWarning], source: Prism::Source).void }
268
- def initialize(value, comments, magic_comments, data_loc, errors, warnings, source); end
263
+ def source; end
269
264
 
270
265
  sig { params(keys: T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, T.untyped]) }
271
266
  def deconstruct_keys(keys); end
@@ -280,15 +275,48 @@ class Prism::ParseResult
280
275
  def failure?; end
281
276
  end
282
277
 
278
+ class Prism::ParseResult < Prism::Result
279
+ sig { params(value: Prism::ProgramNode, comments: T::Array[Prism::Comment], magic_comments: T::Array[Prism::MagicComment], data_loc: T.nilable(Prism::Location), errors: T::Array[Prism::ParseError], warnings: T::Array[Prism::ParseWarning], source: Prism::Source).void }
280
+ def initialize(value, comments, magic_comments, data_loc, errors, warnings, source); end
281
+
282
+ sig { returns(Prism::ProgramNode) }
283
+ def value; end
284
+
285
+ sig { params(keys: T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, T.untyped]) }
286
+ def deconstruct_keys(keys); end
287
+ end
288
+
289
+ class Prism::LexResult < Prism::Result
290
+ sig { params(value: T::Array[T.untyped], comments: T::Array[Prism::Comment], magic_comments: T::Array[Prism::MagicComment], data_loc: T.nilable(Prism::Location), errors: T::Array[Prism::ParseError], warnings: T::Array[Prism::ParseWarning], source: Prism::Source).void }
291
+ def initialize(value, comments, magic_comments, data_loc, errors, warnings, source); end
292
+
293
+ sig { returns(T::Array[T.untyped]) }
294
+ def value; end
295
+
296
+ sig { params(keys: T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, T.untyped]) }
297
+ def deconstruct_keys(keys); end
298
+ end
299
+
300
+ class Prism::ParseLexResult < Prism::Result
301
+ sig { params(value: [Prism::ProgramNode, T::Array[T.untyped]], comments: T::Array[Prism::Comment], magic_comments: T::Array[Prism::MagicComment], data_loc: T.nilable(Prism::Location), errors: T::Array[Prism::ParseError], warnings: T::Array[Prism::ParseWarning], source: Prism::Source).void }
302
+ def initialize(value, comments, magic_comments, data_loc, errors, warnings, source); end
303
+
304
+ sig { returns([Prism::ProgramNode, T::Array[T.untyped]]) }
305
+ def value; end
306
+
307
+ sig { params(keys: T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, T.untyped]) }
308
+ def deconstruct_keys(keys); end
309
+ end
310
+
283
311
  class Prism::Token
284
312
  sig { returns(Prism::Source) }
285
- attr_reader :source
313
+ def source; end
286
314
 
287
315
  sig { returns(Symbol) }
288
- attr_reader :type
316
+ def type; end
289
317
 
290
318
  sig { returns(String) }
291
- attr_reader :value
319
+ def value; end
292
320
 
293
321
  sig { params(source: Prism::Source, type: Symbol, value: String, location: T.any(Integer, Prism::Location)).void }
294
322
  def initialize(source, type, value, location); end
@@ -4,11 +4,11 @@ module Prism::Reflection
4
4
  end
5
5
 
6
6
  class Prism::Reflection::Field
7
- sig { returns(Symbol) }
8
- attr_reader :name
9
-
10
7
  sig { params(name: Symbol).void }
11
8
  def initialize(name); end
9
+
10
+ sig { returns(Symbol) }
11
+ def name; end
12
12
  end
13
13
 
14
14
  class Prism::Reflection::NodeField < Prism::Reflection::Field
@@ -38,24 +38,18 @@ end
38
38
  class Prism::Reflection::OptionalLocationField < Prism::Reflection::Field
39
39
  end
40
40
 
41
- class Prism::Reflection::UInt8Field < Prism::Reflection::Field
41
+ class Prism::Reflection::IntegerField < Prism::Reflection::Field
42
42
  end
43
43
 
44
- class Prism::Reflection::UInt32Field < Prism::Reflection::Field
44
+ class Prism::Reflection::FloatField < Prism::Reflection::Field
45
45
  end
46
46
 
47
47
  class Prism::Reflection::FlagsField < Prism::Reflection::Field
48
- sig { returns(T::Array[Symbol]) }
49
- attr_reader :flags
50
-
51
48
  sig { params(name: Symbol, flags: T::Array[Symbol]).void }
52
49
  def initialize(name, flags); end
53
- end
54
-
55
- class Prism::Reflection::IntegerField < Prism::Reflection::Field
56
- end
57
50
 
58
- class Prism::Reflection::DoubleField < Prism::Reflection::Field
51
+ sig { returns(T::Array[Symbol]) }
52
+ def flags; end
59
53
  end
60
54
 
61
55
  module Prism::Reflection
data/rbi/prism.rbi CHANGED
@@ -7,28 +7,28 @@ module Prism
7
7
  sig { params(filepath: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(String) }
8
8
  def self.dump_file(filepath, command_line: nil, encoding: nil, frozen_string_literal: nil, line: nil, scopes: nil, version: nil); end
9
9
 
10
- sig { params(source: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), filepath: T.nilable(String), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(Prism::ParseResult[T::Array[T.untyped]]) }
10
+ sig { params(source: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), filepath: T.nilable(String), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(Prism::LexResult) }
11
11
  def self.lex(source, command_line: nil, encoding: nil, filepath: nil, frozen_string_literal: nil, line: nil, scopes: nil, version: nil); end
12
12
 
13
- sig { params(filepath: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(Prism::ParseResult[T::Array[T.untyped]]) }
13
+ sig { params(filepath: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(Prism::LexResult) }
14
14
  def self.lex_file(filepath, command_line: nil, encoding: nil, frozen_string_literal: nil, line: nil, scopes: nil, version: nil); end
15
15
 
16
- sig { params(source: String, options: T::Hash[Symbol, T.untyped]).returns(Prism::ParseResult[T::Array[T.untyped]]) }
16
+ sig { params(source: String, options: T::Hash[Symbol, T.untyped]).returns(Prism::LexCompat::Result) }
17
17
  def self.lex_compat(source, **options); end
18
18
 
19
19
  sig { params(source: String).returns(T::Array[T.untyped]) }
20
20
  def self.lex_ripper(source); end
21
21
 
22
- sig { params(source: String, serialized: String).returns(Prism::ParseResult[Prism::ProgramNode]) }
22
+ sig { params(source: String, serialized: String).returns(Prism::ParseResult) }
23
23
  def self.load(source, serialized); end
24
24
 
25
- sig { params(source: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), filepath: T.nilable(String), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(Prism::ParseResult[Prism::ProgramNode]) }
25
+ sig { params(source: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), filepath: T.nilable(String), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(Prism::ParseResult) }
26
26
  def self.parse(source, command_line: nil, encoding: nil, filepath: nil, frozen_string_literal: nil, line: nil, scopes: nil, version: nil); end
27
27
 
28
- sig { params(filepath: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(Prism::ParseResult[Prism::ProgramNode]) }
28
+ sig { params(filepath: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(Prism::ParseResult) }
29
29
  def self.parse_file(filepath, command_line: nil, encoding: nil, frozen_string_literal: nil, line: nil, scopes: nil, version: nil); end
30
30
 
31
- sig { params(stream: T.any(IO, StringIO), command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), filepath: T.nilable(String), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(Prism::ParseResult[Prism::ProgramNode]) }
31
+ sig { params(stream: T.any(IO, StringIO), command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), filepath: T.nilable(String), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(Prism::ParseResult) }
32
32
  def self.parse_stream(stream, command_line: nil, encoding: nil, filepath: nil, frozen_string_literal: nil, line: nil, scopes: nil, version: nil); end
33
33
 
34
34
  sig { params(source: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), filepath: T.nilable(String), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(T::Array[Prism::Comment]) }
@@ -37,10 +37,10 @@ module Prism
37
37
  sig { params(filepath: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(T::Array[Prism::Comment]) }
38
38
  def self.parse_file_comments(filepath, command_line: nil, encoding: nil, frozen_string_literal: nil, line: nil, scopes: nil, version: nil); end
39
39
 
40
- sig { params(source: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), filepath: T.nilable(String), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(Prism::ParseResult[[Prism::ProgramNode, T::Array[T.untyped]]]) }
40
+ sig { params(source: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), filepath: T.nilable(String), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(Prism::ParseLexResult) }
41
41
  def self.parse_lex(source, command_line: nil, encoding: nil, filepath: nil, frozen_string_literal: nil, line: nil, scopes: nil, version: nil); end
42
42
 
43
- sig { params(filepath: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(Prism::ParseResult[[Prism::ProgramNode, T::Array[T.untyped]]]) }
43
+ sig { params(filepath: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(Prism::ParseLexResult) }
44
44
  def self.parse_lex_file(filepath, command_line: nil, encoding: nil, frozen_string_literal: nil, line: nil, scopes: nil, version: nil); end
45
45
 
46
46
  sig { params(source: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), filepath: T.nilable(String), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(T::Boolean) }
data/sig/prism/node.rbs CHANGED
@@ -1515,13 +1515,16 @@ module Prism
1515
1515
  def self.type: () -> :hash_pattern_node
1516
1516
  end
1517
1517
 
1518
- # Represents the use of the `if` keyword, either in the block form or the modifier form.
1518
+ # Represents the use of the `if` keyword, either in the block form or the modifier form, or a ternary expression.
1519
1519
  #
1520
1520
  # bar if foo
1521
1521
  # ^^^^^^^^^^
1522
1522
  #
1523
1523
  # if foo then bar end
1524
1524
  # ^^^^^^^^^^^^^^^^^^^
1525
+ #
1526
+ # foo ? bar : baz
1527
+ # ^^^^^^^^^^^^^^^
1525
1528
  class IfNode < Node
1526
1529
  include _Node
1527
1530
 
@@ -41,7 +41,7 @@ module Prism
41
41
  def start_character_column: () -> Integer
42
42
  def end_column: () -> Integer
43
43
  def end_character_column: () -> Integer
44
- def deconstruct_keys: (Array[Symbol] keys) -> { start_offset: Integer, end_offset: Integer }
44
+ def deconstruct_keys: (Array[Symbol]? keys) -> Hash[Symbol, untyped]
45
45
  def pretty_print: (untyped q) -> untyped
46
46
  def join: (Location other) -> Location
47
47
  end
@@ -50,7 +50,7 @@ module Prism
50
50
  attr_reader location: Location
51
51
 
52
52
  def initialize: (Location location) -> void
53
- def deconstruct_keys: (Array[Symbol] keys) -> { location: Location }
53
+ def deconstruct_keys: (Array[Symbol]? keys) -> Hash[Symbol, untyped]
54
54
  end
55
55
 
56
56
  interface _Comment
@@ -76,7 +76,7 @@ module Prism
76
76
  def key: () -> String
77
77
  def value: () -> String
78
78
 
79
- def deconstruct_keys: (Array[Symbol] keys) -> { key_loc: Location, value_loc: Location }
79
+ def deconstruct_keys: (Array[Symbol]? keys) -> Hash[Symbol, untyped]
80
80
  end
81
81
 
82
82
  class ParseError
@@ -86,7 +86,7 @@ module Prism
86
86
  attr_reader level: Symbol
87
87
 
88
88
  def initialize: (Symbol type, String message, Location location, Symbol level) -> void
89
- def deconstruct_keys: (Array[Symbol] keys) -> { message: String, location: Location, level: Symbol }
89
+ def deconstruct_keys: (Array[Symbol]? keys) -> Hash[Symbol, untyped]
90
90
  end
91
91
 
92
92
  class ParseWarning
@@ -96,11 +96,10 @@ module Prism
96
96
  attr_reader level: Symbol
97
97
 
98
98
  def initialize: (Symbol type, String message, Location location, Symbol level) -> void
99
- def deconstruct_keys: (Array[Symbol] keys) -> { message: String, location: Location, level: Symbol }
99
+ def deconstruct_keys: (Array[Symbol]? keys) -> Hash[Symbol, untyped]
100
100
  end
101
101
 
102
- class ParseResult[out T]
103
- attr_reader value: T
102
+ class Result
104
103
  attr_reader comments: Array[comment]
105
104
  attr_reader magic_comments: Array[MagicComment]
106
105
  attr_reader data_loc: Location?
@@ -108,12 +107,33 @@ module Prism
108
107
  attr_reader warnings: Array[ParseWarning]
109
108
  attr_reader source: Source
110
109
 
111
- def initialize: (T value, Array[comment] comments, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, Source source) -> void
112
- def deconstruct_keys: (Array[Symbol] keys) -> { value: T, comments: Array[comment], magic_comments: Array[MagicComment], data_loc: Location?, errors: Array[ParseError], warnings: Array[ParseWarning] }
110
+ def initialize: (Array[comment] comments, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, Source source) -> void
111
+ def deconstruct_keys: (Array[Symbol]? keys) -> Hash[Symbol, untyped]
113
112
  def success?: () -> bool
114
113
  def failure?: () -> bool
115
114
  end
116
115
 
116
+ class ParseResult < Result
117
+ attr_reader value: ProgramNode
118
+
119
+ def initialize: (ProgramNode value, Array[comment] comments, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, Source source) -> void
120
+ def deconstruct_keys: (Array[Symbol]? keys) -> Hash[Symbol, untyped]
121
+ end
122
+
123
+ class LexResult < Result
124
+ attr_reader value: Array[[Token, Integer]]
125
+
126
+ def initialize: (Array[[Token, Integer]] value, Array[comment] comments, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, Source source) -> void
127
+ def deconstruct_keys: (Array[Symbol]? keys) -> Hash[Symbol, untyped]
128
+ end
129
+
130
+ class ParseLexResult < Result
131
+ attr_reader value: [ProgramNode, Array[[Token, Integer]]]
132
+
133
+ def initialize: ([ProgramNode, Array[[Token, Integer]]] value, Array[comment] comments, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, Source source) -> void
134
+ def deconstruct_keys: (Array[Symbol]? keys) -> Hash[Symbol, untyped]
135
+ end
136
+
117
137
  class Token
118
138
  attr_reader source: Source
119
139
  attr_reader type: Symbol
@@ -121,7 +141,7 @@ module Prism
121
141
  attr_reader location: Location
122
142
 
123
143
  def initialize: (Source source, Symbol type, String value, Location location) -> void
124
- def deconstruct_keys: (Array[Symbol] keys) -> { type: Symbol, value: String, location: Location }
144
+ def deconstruct_keys: (Array[Symbol]? keys) -> Hash[Symbol, untyped]
125
145
  def pretty_print: (untyped q) -> untyped
126
146
  def ==: (untyped other) -> bool
127
147
  end
@@ -33,10 +33,10 @@ module Prism
33
33
  class OptionalLocationField < Field
34
34
  end
35
35
 
36
- class UInt8Field < Field
36
+ class IntegerField < Field
37
37
  end
38
38
 
39
- class UInt32Field < Field
39
+ class FloatField < Field
40
40
  end
41
41
 
42
42
  class FlagsField < Field
@@ -45,12 +45,6 @@ module Prism
45
45
  def initialize: (Symbol name, Array[Symbol] flags) -> void
46
46
  end
47
47
 
48
- class IntegerField < Field
49
- end
50
-
51
- class DoubleField < Field
52
- end
53
-
54
48
  def self.fields_for: (node_singleton node) -> Array[Field]
55
49
  end
56
50
  end
@@ -1,7 +1,6 @@
1
1
  module Prism
2
2
  module Serialize
3
- def self.load: (String, String) -> ParseResult[ProgramNode]
4
-
5
- def self.load_tokens: (Source, String) -> ParseResult[Array[Token]] # TODO: check if array[token] is right
3
+ def self.load: (String, String) -> ParseResult
4
+ def self.load_tokens: (Source, String) -> LexResult
6
5
  end
7
6
  end