prism 0.16.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -1
  3. data/Makefile +6 -0
  4. data/README.md +1 -1
  5. data/config.yml +50 -35
  6. data/docs/fuzzing.md +1 -1
  7. data/docs/serialization.md +28 -29
  8. data/ext/prism/api_node.c +802 -770
  9. data/ext/prism/api_pack.c +20 -9
  10. data/ext/prism/extension.c +464 -162
  11. data/ext/prism/extension.h +1 -1
  12. data/include/prism/ast.h +3173 -763
  13. data/include/prism/defines.h +32 -9
  14. data/include/prism/diagnostic.h +36 -3
  15. data/include/prism/enc/pm_encoding.h +118 -28
  16. data/include/prism/node.h +38 -13
  17. data/include/prism/options.h +204 -0
  18. data/include/prism/pack.h +44 -33
  19. data/include/prism/parser.h +445 -200
  20. data/include/prism/prettyprint.h +12 -1
  21. data/include/prism/regexp.h +16 -2
  22. data/include/prism/util/pm_buffer.h +94 -16
  23. data/include/prism/util/pm_char.h +162 -48
  24. data/include/prism/util/pm_constant_pool.h +126 -32
  25. data/include/prism/util/pm_list.h +68 -38
  26. data/include/prism/util/pm_memchr.h +18 -3
  27. data/include/prism/util/pm_newline_list.h +70 -27
  28. data/include/prism/util/pm_state_stack.h +25 -7
  29. data/include/prism/util/pm_string.h +115 -27
  30. data/include/prism/util/pm_string_list.h +25 -6
  31. data/include/prism/util/pm_strncasecmp.h +32 -0
  32. data/include/prism/util/pm_strpbrk.h +31 -17
  33. data/include/prism/version.h +27 -2
  34. data/include/prism.h +224 -31
  35. data/lib/prism/compiler.rb +6 -3
  36. data/lib/prism/debug.rb +23 -7
  37. data/lib/prism/dispatcher.rb +33 -18
  38. data/lib/prism/dsl.rb +10 -5
  39. data/lib/prism/ffi.rb +132 -80
  40. data/lib/prism/lex_compat.rb +25 -15
  41. data/lib/prism/mutation_compiler.rb +10 -5
  42. data/lib/prism/node.rb +370 -135
  43. data/lib/prism/node_ext.rb +1 -1
  44. data/lib/prism/node_inspector.rb +1 -1
  45. data/lib/prism/pack.rb +79 -40
  46. data/lib/prism/parse_result/comments.rb +7 -2
  47. data/lib/prism/parse_result/newlines.rb +4 -0
  48. data/lib/prism/parse_result.rb +150 -30
  49. data/lib/prism/pattern.rb +11 -0
  50. data/lib/prism/ripper_compat.rb +28 -10
  51. data/lib/prism/serialize.rb +86 -54
  52. data/lib/prism/visitor.rb +10 -3
  53. data/lib/prism.rb +20 -2
  54. data/prism.gemspec +4 -2
  55. data/rbi/prism.rbi +104 -60
  56. data/rbi/prism_static.rbi +16 -2
  57. data/sig/prism.rbs +72 -43
  58. data/sig/prism_static.rbs +14 -1
  59. data/src/diagnostic.c +56 -53
  60. data/src/enc/pm_big5.c +1 -0
  61. data/src/enc/pm_euc_jp.c +1 -0
  62. data/src/enc/pm_gbk.c +1 -0
  63. data/src/enc/pm_shift_jis.c +1 -0
  64. data/src/enc/pm_tables.c +316 -80
  65. data/src/enc/pm_unicode.c +53 -8
  66. data/src/enc/pm_windows_31j.c +1 -0
  67. data/src/node.c +334 -321
  68. data/src/options.c +170 -0
  69. data/src/prettyprint.c +74 -47
  70. data/src/prism.c +1642 -856
  71. data/src/regexp.c +151 -95
  72. data/src/serialize.c +44 -20
  73. data/src/token_type.c +3 -1
  74. data/src/util/pm_buffer.c +45 -15
  75. data/src/util/pm_char.c +103 -57
  76. data/src/util/pm_constant_pool.c +51 -21
  77. data/src/util/pm_list.c +12 -4
  78. data/src/util/pm_memchr.c +5 -3
  79. data/src/util/pm_newline_list.c +20 -12
  80. data/src/util/pm_state_stack.c +9 -3
  81. data/src/util/pm_string.c +95 -85
  82. data/src/util/pm_string_list.c +14 -15
  83. data/src/util/pm_strncasecmp.c +10 -3
  84. data/src/util/pm_strpbrk.c +25 -19
  85. metadata +5 -3
  86. data/docs/prism.png +0 -0
data/rbi/prism.rbi CHANGED
@@ -1030,10 +1030,10 @@ module Prism
1030
1030
 
1031
1031
  # Represents the use of a case statement.
1032
1032
  #
1033
- # case true
1034
- # ^^^^^^^^^
1035
- # when false
1036
- # end
1033
+ # case true
1034
+ # when false
1035
+ # end
1036
+ # ^^^^^^^^^^
1037
1037
  class CaseNode < Node
1038
1038
  sig { returns(T.nilable(Node)) }
1039
1039
  attr_reader :predicate
@@ -1141,7 +1141,7 @@ module Prism
1141
1141
  # Represents the use of the `&&=` operator for assignment to a class variable.
1142
1142
  #
1143
1143
  # @@target &&= value
1144
- # ^^^^^^^^^^^^^^^^
1144
+ # ^^^^^^^^^^^^^^^^^^
1145
1145
  class ClassVariableAndWriteNode < Node
1146
1146
  sig { returns(Symbol) }
1147
1147
  attr_reader :name
@@ -2160,13 +2160,13 @@ module Prism
2160
2160
  # Represents a find pattern in pattern matching.
2161
2161
  #
2162
2162
  # foo in *bar, baz, *qux
2163
- # ^^^^^^^^^^^^^^^^^^^^^^
2163
+ # ^^^^^^^^^^^^^^^
2164
2164
  #
2165
2165
  # foo in [*bar, baz, *qux]
2166
- # ^^^^^^^^^^^^^^^^^^^^^^^^
2166
+ # ^^^^^^^^^^^^^^^^^
2167
2167
  #
2168
2168
  # foo in Foo(*bar, baz, *qux)
2169
- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2169
+ # ^^^^^^^^^^^^^^^^^^^^
2170
2170
  class FindPatternNode < Node
2171
2171
  sig { returns(T.nilable(Node)) }
2172
2172
  attr_reader :constant
@@ -2350,7 +2350,7 @@ module Prism
2350
2350
  #
2351
2351
  # def foo(...)
2352
2352
  # bar(...)
2353
- # ^^^^^^^^
2353
+ # ^^^
2354
2354
  # end
2355
2355
  class ForwardingArgumentsNode < Node
2356
2356
  sig { params(location: Location).void }
@@ -3708,47 +3708,6 @@ module Prism
3708
3708
  def inspect(inspector); end
3709
3709
  end
3710
3710
 
3711
- # Represents a keyword parameter to a method, block, or lambda definition.
3712
- #
3713
- # def a(b:)
3714
- # ^^
3715
- # end
3716
- #
3717
- # def a(b: 1)
3718
- # ^^^^
3719
- # end
3720
- class KeywordParameterNode < Node
3721
- sig { returns(Symbol) }
3722
- attr_reader :name
3723
-
3724
- sig { returns(Location) }
3725
- attr_reader :name_loc
3726
-
3727
- sig { returns(T.nilable(Node)) }
3728
- attr_reader :value
3729
-
3730
- sig { params(name: Symbol, name_loc: Location, value: T.nilable(Node), location: Location).void }
3731
- def initialize(name, name_loc, value, location); end
3732
-
3733
- sig { params(visitor: Visitor).void }
3734
- def accept(visitor); end
3735
-
3736
- sig { returns(T::Array[T.nilable(Node)]) }
3737
- def child_nodes; end
3738
-
3739
- sig { returns(T::Array[T.nilable(Node)]) }
3740
- def deconstruct; end
3741
-
3742
- sig { params(params: T.untyped).returns(KeywordParameterNode) }
3743
- def copy(**params); end
3744
-
3745
- sig { params(keys: T::Array[Symbol]).returns(T::Hash[Symbol, T.nilable(T.any(Node, T::Array[Node], String, Token, T::Array[Token], Location))]) }
3746
- def deconstruct_keys(keys); end
3747
-
3748
- sig { params(inspector: NodeInspector).returns(String) }
3749
- def inspect(inspector); end
3750
- end
3751
-
3752
3711
  # Represents a keyword rest parameter to a method, block, or lambda definition.
3753
3712
  #
3754
3713
  # def a(**b)
@@ -4594,6 +4553,43 @@ module Prism
4594
4553
  def inspect(inspector); end
4595
4554
  end
4596
4555
 
4556
+ # Represents an optional keyword parameter to a method, block, or lambda definition.
4557
+ #
4558
+ # def a(b: 1)
4559
+ # ^^^^
4560
+ # end
4561
+ class OptionalKeywordParameterNode < Node
4562
+ sig { returns(Symbol) }
4563
+ attr_reader :name
4564
+
4565
+ sig { returns(Location) }
4566
+ attr_reader :name_loc
4567
+
4568
+ sig { returns(Node) }
4569
+ attr_reader :value
4570
+
4571
+ sig { params(name: Symbol, name_loc: Location, value: Node, location: Location).void }
4572
+ def initialize(name, name_loc, value, location); end
4573
+
4574
+ sig { params(visitor: Visitor).void }
4575
+ def accept(visitor); end
4576
+
4577
+ sig { returns(T::Array[T.nilable(Node)]) }
4578
+ def child_nodes; end
4579
+
4580
+ sig { returns(T::Array[T.nilable(Node)]) }
4581
+ def deconstruct; end
4582
+
4583
+ sig { params(params: T.untyped).returns(OptionalKeywordParameterNode) }
4584
+ def copy(**params); end
4585
+
4586
+ sig { params(keys: T::Array[Symbol]).returns(T::Hash[Symbol, T.nilable(T.any(Node, T::Array[Node], String, Token, T::Array[Token], Location))]) }
4587
+ def deconstruct_keys(keys); end
4588
+
4589
+ sig { params(inspector: NodeInspector).returns(String) }
4590
+ def inspect(inspector); end
4591
+ end
4592
+
4597
4593
  # Represents an optional parameter to a method, block, or lambda definition.
4598
4594
  #
4599
4595
  # def a(b = 1)
@@ -5161,6 +5157,40 @@ module Prism
5161
5157
  def inspect(inspector); end
5162
5158
  end
5163
5159
 
5160
+ # Represents a required keyword parameter to a method, block, or lambda definition.
5161
+ #
5162
+ # def a(b: )
5163
+ # ^^
5164
+ # end
5165
+ class RequiredKeywordParameterNode < Node
5166
+ sig { returns(Symbol) }
5167
+ attr_reader :name
5168
+
5169
+ sig { returns(Location) }
5170
+ attr_reader :name_loc
5171
+
5172
+ sig { params(name: Symbol, name_loc: Location, location: Location).void }
5173
+ def initialize(name, name_loc, location); end
5174
+
5175
+ sig { params(visitor: Visitor).void }
5176
+ def accept(visitor); end
5177
+
5178
+ sig { returns(T::Array[T.nilable(Node)]) }
5179
+ def child_nodes; end
5180
+
5181
+ sig { returns(T::Array[T.nilable(Node)]) }
5182
+ def deconstruct; end
5183
+
5184
+ sig { params(params: T.untyped).returns(RequiredKeywordParameterNode) }
5185
+ def copy(**params); end
5186
+
5187
+ sig { params(keys: T::Array[Symbol]).returns(T::Hash[Symbol, T.nilable(T.any(Node, T::Array[Node], String, Token, T::Array[Token], Location))]) }
5188
+ def deconstruct_keys(keys); end
5189
+
5190
+ sig { params(inspector: NodeInspector).returns(String) }
5191
+ def inspect(inspector); end
5192
+ end
5193
+
5164
5194
  # Represents a required parameter to a method, block, or lambda definition.
5165
5195
  #
5166
5196
  # def a(b)
@@ -5194,8 +5224,8 @@ module Prism
5194
5224
 
5195
5225
  # Represents an expression modified with a rescue.
5196
5226
  #
5197
- # foo rescue nil
5198
- # ^^^^^^^^^^^^^^
5227
+ # foo rescue nil
5228
+ # ^^^^^^^^^^^^^^
5199
5229
  class RescueModifierNode < Node
5200
5230
  sig { returns(Node) }
5201
5231
  attr_reader :expression
@@ -5237,8 +5267,8 @@ module Prism
5237
5267
  #
5238
5268
  # begin
5239
5269
  # rescue Foo, *splat, Bar => ex
5240
- # ^^^^^^
5241
5270
  # foo
5271
+ # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5242
5272
  # end
5243
5273
  #
5244
5274
  # `Foo, *splat, Bar` are in the `exceptions` field.
@@ -6189,11 +6219,13 @@ module Prism
6189
6219
  end
6190
6220
 
6191
6221
 
6222
+ # Flags for arguments nodes.
6192
6223
  module ArgumentsNodeFlags
6193
6224
  # if arguments contain keyword splat
6194
6225
  KEYWORD_SPLAT = T.let(1 << 0, Integer)
6195
6226
  end
6196
6227
 
6228
+ # Flags for call nodes.
6197
6229
  module CallNodeFlags
6198
6230
  # &. operator
6199
6231
  SAFE_NAVIGATION = T.let(1 << 0, Integer)
@@ -6201,6 +6233,7 @@ module Prism
6201
6233
  VARIABLE_CALL = T.let(1 << 1, Integer)
6202
6234
  end
6203
6235
 
6236
+ # Flags for integer nodes that correspond to the base of the integer.
6204
6237
  module IntegerBaseFlags
6205
6238
  # 0b prefix
6206
6239
  BINARY = T.let(1 << 0, Integer)
@@ -6212,16 +6245,19 @@ module Prism
6212
6245
  HEXADECIMAL = T.let(1 << 3, Integer)
6213
6246
  end
6214
6247
 
6248
+ # Flags for while and until loop nodes.
6215
6249
  module LoopFlags
6216
6250
  # a loop after a begin statement, so the body is executed first before the condition
6217
6251
  BEGIN_MODIFIER = T.let(1 << 0, Integer)
6218
6252
  end
6219
6253
 
6254
+ # Flags for range and flip-flop nodes.
6220
6255
  module RangeFlags
6221
6256
  # ... operator
6222
6257
  EXCLUDE_END = T.let(1 << 0, Integer)
6223
6258
  end
6224
6259
 
6260
+ # Flags for regular expression and match last line nodes.
6225
6261
  module RegularExpressionFlags
6226
6262
  # i - ignores the case of characters when matching
6227
6263
  IGNORE_CASE = T.let(1 << 0, Integer)
@@ -6241,6 +6277,7 @@ module Prism
6241
6277
  UTF_8 = T.let(1 << 7, Integer)
6242
6278
  end
6243
6279
 
6280
+ # Flags for string nodes.
6244
6281
  module StringFlags
6245
6282
  # frozen by virtue of a `frozen_string_literal` comment
6246
6283
  FROZEN = T.let(1 << 0, Integer)
@@ -6584,10 +6621,6 @@ module Prism
6584
6621
  sig { params(node: KeywordHashNode).void }
6585
6622
  def visit_keyword_hash_node(node); end
6586
6623
 
6587
- # Visit a KeywordParameterNode node
6588
- sig { params(node: KeywordParameterNode).void }
6589
- def visit_keyword_parameter_node(node); end
6590
-
6591
6624
  # Visit a KeywordRestParameterNode node
6592
6625
  sig { params(node: KeywordRestParameterNode).void }
6593
6626
  def visit_keyword_rest_parameter_node(node); end
@@ -6668,6 +6701,10 @@ module Prism
6668
6701
  sig { params(node: NumberedReferenceReadNode).void }
6669
6702
  def visit_numbered_reference_read_node(node); end
6670
6703
 
6704
+ # Visit a OptionalKeywordParameterNode node
6705
+ sig { params(node: OptionalKeywordParameterNode).void }
6706
+ def visit_optional_keyword_parameter_node(node); end
6707
+
6671
6708
  # Visit a OptionalParameterNode node
6672
6709
  sig { params(node: OptionalParameterNode).void }
6673
6710
  def visit_optional_parameter_node(node); end
@@ -6720,6 +6757,10 @@ module Prism
6720
6757
  sig { params(node: RegularExpressionNode).void }
6721
6758
  def visit_regular_expression_node(node); end
6722
6759
 
6760
+ # Visit a RequiredKeywordParameterNode node
6761
+ sig { params(node: RequiredKeywordParameterNode).void }
6762
+ def visit_required_keyword_parameter_node(node); end
6763
+
6723
6764
  # Visit a RequiredParameterNode node
6724
6765
  sig { params(node: RequiredParameterNode).void }
6725
6766
  def visit_required_parameter_node(node); end
@@ -7080,9 +7121,6 @@ module Prism
7080
7121
  # Create a new KeywordHashNode node
7081
7122
  sig { params(elements: T::Array[Node], location: Location).returns(KeywordHashNode) }
7082
7123
  def KeywordHashNode(elements, location); end
7083
- # Create a new KeywordParameterNode node
7084
- sig { params(name: Symbol, name_loc: Location, value: T.nilable(Node), location: Location).returns(KeywordParameterNode) }
7085
- def KeywordParameterNode(name, name_loc, value, location); end
7086
7124
  # Create a new KeywordRestParameterNode node
7087
7125
  sig { params(name: T.nilable(Symbol), name_loc: T.nilable(Location), operator_loc: Location, location: Location).returns(KeywordRestParameterNode) }
7088
7126
  def KeywordRestParameterNode(name, name_loc, operator_loc, location); end
@@ -7143,6 +7181,9 @@ module Prism
7143
7181
  # Create a new NumberedReferenceReadNode node
7144
7182
  sig { params(number: Integer, location: Location).returns(NumberedReferenceReadNode) }
7145
7183
  def NumberedReferenceReadNode(number, location); end
7184
+ # Create a new OptionalKeywordParameterNode node
7185
+ sig { params(name: Symbol, name_loc: Location, value: Node, location: Location).returns(OptionalKeywordParameterNode) }
7186
+ def OptionalKeywordParameterNode(name, name_loc, value, location); end
7146
7187
  # Create a new OptionalParameterNode node
7147
7188
  sig { params(name: Symbol, name_loc: Location, operator_loc: Location, value: Node, location: Location).returns(OptionalParameterNode) }
7148
7189
  def OptionalParameterNode(name, name_loc, operator_loc, value, location); end
@@ -7182,6 +7223,9 @@ module Prism
7182
7223
  # Create a new RegularExpressionNode node
7183
7224
  sig { params(opening_loc: Location, content_loc: Location, closing_loc: Location, unescaped: String, flags: Integer, location: Location).returns(RegularExpressionNode) }
7184
7225
  def RegularExpressionNode(opening_loc, content_loc, closing_loc, unescaped, flags, location); end
7226
+ # Create a new RequiredKeywordParameterNode node
7227
+ sig { params(name: Symbol, name_loc: Location, location: Location).returns(RequiredKeywordParameterNode) }
7228
+ def RequiredKeywordParameterNode(name, name_loc, location); end
7185
7229
  # Create a new RequiredParameterNode node
7186
7230
  sig { params(name: Symbol, location: Location).returns(RequiredParameterNode) }
7187
7231
  def RequiredParameterNode(name, location); end
data/rbi/prism_static.rbi CHANGED
@@ -48,6 +48,20 @@ module Prism
48
48
  class Comment
49
49
  sig { returns(Location) }
50
50
  def location; end
51
+
52
+ sig { returns(T::Boolean) }
53
+ def trailing?; end
54
+ end
55
+
56
+ class InlineComment < Comment
57
+ sig { override.returns(T::Boolean) }
58
+ def trailing?; end
59
+ end
60
+
61
+ class EmbDocComment < Comment
62
+ end
63
+
64
+ class DATAComment < Comment
51
65
  end
52
66
 
53
67
  class Location
@@ -83,8 +97,8 @@ module Prism
83
97
  end
84
98
 
85
99
  class Source
86
- sig { params(source: String, offsets: T::Array[Integer]).void }
87
- def initialize(source, offsets); end
100
+ sig { params(source: String, start_line: Integer, offsets: T::Array[Integer]).void }
101
+ def initialize(source, start_line, offsets); end
88
102
 
89
103
  sig { params(offset: Integer, length: Integer).returns(String) }
90
104
  def slice(offset, length); end
data/sig/prism.rbs CHANGED
@@ -607,10 +607,10 @@ module Prism
607
607
  end
608
608
  # Represents the use of a case statement.
609
609
  #
610
- # case true
611
- # ^^^^^^^^^
612
- # when false
613
- # end
610
+ # case true
611
+ # when false
612
+ # end
613
+ # ^^^^^^^^^^
614
614
  class CaseNode < Node
615
615
  attr_reader predicate: Node?
616
616
  attr_reader conditions: Array[Node]
@@ -669,7 +669,7 @@ module Prism
669
669
  # Represents the use of the `&&=` operator for assignment to a class variable.
670
670
  #
671
671
  # @@target &&= value
672
- # ^^^^^^^^^^^^^^^^
672
+ # ^^^^^^^^^^^^^^^^^^
673
673
  class ClassVariableAndWriteNode < Node
674
674
  attr_reader name: Symbol
675
675
  attr_reader name_loc: Location
@@ -1268,13 +1268,13 @@ module Prism
1268
1268
  # Represents a find pattern in pattern matching.
1269
1269
  #
1270
1270
  # foo in *bar, baz, *qux
1271
- # ^^^^^^^^^^^^^^^^^^^^^^
1271
+ # ^^^^^^^^^^^^^^^
1272
1272
  #
1273
1273
  # foo in [*bar, baz, *qux]
1274
- # ^^^^^^^^^^^^^^^^^^^^^^^^
1274
+ # ^^^^^^^^^^^^^^^^^
1275
1275
  #
1276
1276
  # foo in Foo(*bar, baz, *qux)
1277
- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1277
+ # ^^^^^^^^^^^^^^^^^^^^
1278
1278
  class FindPatternNode < Node
1279
1279
  attr_reader constant: Node?
1280
1280
  attr_reader left: Node
@@ -1380,7 +1380,7 @@ module Prism
1380
1380
  #
1381
1381
  # def foo(...)
1382
1382
  # bar(...)
1383
- # ^^^^^^^^
1383
+ # ^^^
1384
1384
  # end
1385
1385
  class ForwardingArgumentsNode < Node
1386
1386
 
@@ -2176,32 +2176,6 @@ module Prism
2176
2176
 
2177
2177
  def inspect: (inspector: NodeInspector) -> String
2178
2178
  end
2179
- # Represents a keyword parameter to a method, block, or lambda definition.
2180
- #
2181
- # def a(b:)
2182
- # ^^
2183
- # end
2184
- #
2185
- # def a(b: 1)
2186
- # ^^^^
2187
- # end
2188
- class KeywordParameterNode < Node
2189
- attr_reader name: Symbol
2190
- attr_reader name_loc: Location
2191
- attr_reader value: Node?
2192
-
2193
- def initialize: (name: Symbol, name_loc: Location, value: Node?, location: Location) -> void
2194
- def accept: (visitor: Visitor) -> void
2195
- def set_newline_flag: (newline_marked: Array[bool]) -> void
2196
- def child_nodes: () -> Array[Node?]
2197
- def deconstruct: () -> Array[Node?]
2198
-
2199
- def copy: (**untyped) -> KeywordParameterNode
2200
-
2201
- def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, (Node | Array[Node] | String | Token | Array[Token] | Location)?]
2202
-
2203
- def inspect: (inspector: NodeInspector) -> String
2204
- end
2205
2179
  # Represents a keyword rest parameter to a method, block, or lambda definition.
2206
2180
  #
2207
2181
  # def a(**b)
@@ -2697,6 +2671,28 @@ module Prism
2697
2671
 
2698
2672
  def inspect: (inspector: NodeInspector) -> String
2699
2673
  end
2674
+ # Represents an optional keyword parameter to a method, block, or lambda definition.
2675
+ #
2676
+ # def a(b: 1)
2677
+ # ^^^^
2678
+ # end
2679
+ class OptionalKeywordParameterNode < Node
2680
+ attr_reader name: Symbol
2681
+ attr_reader name_loc: Location
2682
+ attr_reader value: Node
2683
+
2684
+ def initialize: (name: Symbol, name_loc: Location, value: Node, location: Location) -> void
2685
+ def accept: (visitor: Visitor) -> void
2686
+ def set_newline_flag: (newline_marked: Array[bool]) -> void
2687
+ def child_nodes: () -> Array[Node?]
2688
+ def deconstruct: () -> Array[Node?]
2689
+
2690
+ def copy: (**untyped) -> OptionalKeywordParameterNode
2691
+
2692
+ def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, (Node | Array[Node] | String | Token | Array[Token] | Location)?]
2693
+
2694
+ def inspect: (inspector: NodeInspector) -> String
2695
+ end
2700
2696
  # Represents an optional parameter to a method, block, or lambda definition.
2701
2697
  #
2702
2698
  # def a(b = 1)
@@ -3032,6 +3028,27 @@ module Prism
3032
3028
 
3033
3029
  def inspect: (inspector: NodeInspector) -> String
3034
3030
  end
3031
+ # Represents a required keyword parameter to a method, block, or lambda definition.
3032
+ #
3033
+ # def a(b: )
3034
+ # ^^
3035
+ # end
3036
+ class RequiredKeywordParameterNode < Node
3037
+ attr_reader name: Symbol
3038
+ attr_reader name_loc: Location
3039
+
3040
+ def initialize: (name: Symbol, name_loc: Location, location: Location) -> void
3041
+ def accept: (visitor: Visitor) -> void
3042
+ def set_newline_flag: (newline_marked: Array[bool]) -> void
3043
+ def child_nodes: () -> Array[Node?]
3044
+ def deconstruct: () -> Array[Node?]
3045
+
3046
+ def copy: (**untyped) -> RequiredKeywordParameterNode
3047
+
3048
+ def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, (Node | Array[Node] | String | Token | Array[Token] | Location)?]
3049
+
3050
+ def inspect: (inspector: NodeInspector) -> String
3051
+ end
3035
3052
  # Represents a required parameter to a method, block, or lambda definition.
3036
3053
  #
3037
3054
  # def a(b)
@@ -3054,8 +3071,8 @@ module Prism
3054
3071
  end
3055
3072
  # Represents an expression modified with a rescue.
3056
3073
  #
3057
- # foo rescue nil
3058
- # ^^^^^^^^^^^^^^
3074
+ # foo rescue nil
3075
+ # ^^^^^^^^^^^^^^
3059
3076
  class RescueModifierNode < Node
3060
3077
  attr_reader expression: Node
3061
3078
  attr_reader keyword_loc: Location
@@ -3079,8 +3096,8 @@ module Prism
3079
3096
  #
3080
3097
  # begin
3081
3098
  # rescue Foo, *splat, Bar => ex
3082
- # ^^^^^^
3083
3099
  # foo
3100
+ # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3084
3101
  # end
3085
3102
  #
3086
3103
  # `Foo, *splat, Bar` are in the `exceptions` field.
@@ -3654,11 +3671,13 @@ module Prism
3654
3671
  def inspect: (inspector: NodeInspector) -> String
3655
3672
  end
3656
3673
 
3674
+ # Flags for arguments nodes.
3657
3675
  module ArgumentsNodeFlags
3658
3676
  # if arguments contain keyword splat
3659
3677
  KEYWORD_SPLAT: Integer
3660
3678
  end
3661
3679
 
3680
+ # Flags for call nodes.
3662
3681
  module CallNodeFlags
3663
3682
  # &. operator
3664
3683
  SAFE_NAVIGATION: Integer
@@ -3666,6 +3685,7 @@ module Prism
3666
3685
  VARIABLE_CALL: Integer
3667
3686
  end
3668
3687
 
3688
+ # Flags for integer nodes that correspond to the base of the integer.
3669
3689
  module IntegerBaseFlags
3670
3690
  # 0b prefix
3671
3691
  BINARY: Integer
@@ -3677,16 +3697,19 @@ module Prism
3677
3697
  HEXADECIMAL: Integer
3678
3698
  end
3679
3699
 
3700
+ # Flags for while and until loop nodes.
3680
3701
  module LoopFlags
3681
3702
  # a loop after a begin statement, so the body is executed first before the condition
3682
3703
  BEGIN_MODIFIER: Integer
3683
3704
  end
3684
3705
 
3706
+ # Flags for range and flip-flop nodes.
3685
3707
  module RangeFlags
3686
3708
  # ... operator
3687
3709
  EXCLUDE_END: Integer
3688
3710
  end
3689
3711
 
3712
+ # Flags for regular expression and match last line nodes.
3690
3713
  module RegularExpressionFlags
3691
3714
  # i - ignores the case of characters when matching
3692
3715
  IGNORE_CASE: Integer
@@ -3706,6 +3729,7 @@ module Prism
3706
3729
  UTF_8: Integer
3707
3730
  end
3708
3731
 
3732
+ # Flags for string nodes.
3709
3733
  module StringFlags
3710
3734
  # frozen by virtue of a `frozen_string_literal` comment
3711
3735
  FROZEN: Integer
@@ -3965,9 +3989,6 @@ module Prism
3965
3989
  # Visit a KeywordHashNode node
3966
3990
  def visit_keyword_hash_node: (node: KeywordHashNode) -> void
3967
3991
 
3968
- # Visit a KeywordParameterNode node
3969
- def visit_keyword_parameter_node: (node: KeywordParameterNode) -> void
3970
-
3971
3992
  # Visit a KeywordRestParameterNode node
3972
3993
  def visit_keyword_rest_parameter_node: (node: KeywordRestParameterNode) -> void
3973
3994
 
@@ -4028,6 +4049,9 @@ module Prism
4028
4049
  # Visit a NumberedReferenceReadNode node
4029
4050
  def visit_numbered_reference_read_node: (node: NumberedReferenceReadNode) -> void
4030
4051
 
4052
+ # Visit a OptionalKeywordParameterNode node
4053
+ def visit_optional_keyword_parameter_node: (node: OptionalKeywordParameterNode) -> void
4054
+
4031
4055
  # Visit a OptionalParameterNode node
4032
4056
  def visit_optional_parameter_node: (node: OptionalParameterNode) -> void
4033
4057
 
@@ -4067,6 +4091,9 @@ module Prism
4067
4091
  # Visit a RegularExpressionNode node
4068
4092
  def visit_regular_expression_node: (node: RegularExpressionNode) -> void
4069
4093
 
4094
+ # Visit a RequiredKeywordParameterNode node
4095
+ def visit_required_keyword_parameter_node: (node: RequiredKeywordParameterNode) -> void
4096
+
4070
4097
  # Visit a RequiredParameterNode node
4071
4098
  def visit_required_parameter_node: (node: RequiredParameterNode) -> void
4072
4099
 
@@ -4317,8 +4344,6 @@ module Prism
4317
4344
  def InterpolatedXStringNode: (opening_loc: Location, parts: Array[Node], closing_loc: Location, location: Location) -> InterpolatedXStringNode
4318
4345
  # Create a new KeywordHashNode node
4319
4346
  def KeywordHashNode: (elements: Array[Node], location: Location) -> KeywordHashNode
4320
- # Create a new KeywordParameterNode node
4321
- def KeywordParameterNode: (name: Symbol, name_loc: Location, value: Node?, location: Location) -> KeywordParameterNode
4322
4347
  # Create a new KeywordRestParameterNode node
4323
4348
  def KeywordRestParameterNode: (name: Symbol?, name_loc: Location?, operator_loc: Location, location: Location) -> KeywordRestParameterNode
4324
4349
  # Create a new LambdaNode node
@@ -4359,6 +4384,8 @@ module Prism
4359
4384
  def NoKeywordsParameterNode: (operator_loc: Location, keyword_loc: Location, location: Location) -> NoKeywordsParameterNode
4360
4385
  # Create a new NumberedReferenceReadNode node
4361
4386
  def NumberedReferenceReadNode: (number: Integer, location: Location) -> NumberedReferenceReadNode
4387
+ # Create a new OptionalKeywordParameterNode node
4388
+ def OptionalKeywordParameterNode: (name: Symbol, name_loc: Location, value: Node, location: Location) -> OptionalKeywordParameterNode
4362
4389
  # Create a new OptionalParameterNode node
4363
4390
  def OptionalParameterNode: (name: Symbol, name_loc: Location, operator_loc: Location, value: Node, location: Location) -> OptionalParameterNode
4364
4391
  # Create a new OrNode node
@@ -4385,6 +4412,8 @@ module Prism
4385
4412
  def RedoNode: (location: Location) -> RedoNode
4386
4413
  # Create a new RegularExpressionNode node
4387
4414
  def RegularExpressionNode: (opening_loc: Location, content_loc: Location, closing_loc: Location, unescaped: String, flags: Integer, location: Location) -> RegularExpressionNode
4415
+ # Create a new RequiredKeywordParameterNode node
4416
+ def RequiredKeywordParameterNode: (name: Symbol, name_loc: Location, location: Location) -> RequiredKeywordParameterNode
4388
4417
  # Create a new RequiredParameterNode node
4389
4418
  def RequiredParameterNode: (name: Symbol, location: Location) -> RequiredParameterNode
4390
4419
  # Create a new RescueModifierNode node
data/sig/prism_static.rbs CHANGED
@@ -25,6 +25,17 @@ module Prism
25
25
 
26
26
  class Comment
27
27
  def location: () -> Location
28
+ def trailing?: () -> bool
29
+ end
30
+
31
+ class InlineComment < Comment
32
+ def trailing?: () -> bool
33
+ end
34
+
35
+ class EmbDocComment < Comment
36
+ end
37
+
38
+ class DATAComment < Comment
28
39
  end
29
40
 
30
41
  class Location
@@ -42,12 +53,14 @@ module Prism
42
53
 
43
54
  class Source
44
55
  attr_reader source: String
56
+ attr_reader start_line: Integer
45
57
  attr_reader offsets: Array[Integer]
46
58
 
47
59
  @source: String
60
+ @start_line: Integer
48
61
  @offsets: Array[Integer]
49
62
 
50
- def initialize: (source: String, offsets: Array[Integer]) -> void
63
+ def initialize: (source: String, start_line: Integer, offsets: Array[Integer]) -> void
51
64
  def slice: (offset: Integer, length: Integer) -> String
52
65
  def line: (value: Integer) -> Integer
53
66
  def line_offset: (value: Integer) -> Integer