prism 2.0.0.rc1-x86_64-linux-gnu

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. checksums.yaml +7 -0
  2. data/BSDmakefile +58 -0
  3. data/CHANGELOG.md +870 -0
  4. data/CODE_OF_CONDUCT.md +76 -0
  5. data/CONTRIBUTING.md +58 -0
  6. data/LICENSE.md +7 -0
  7. data/Makefile +145 -0
  8. data/README.md +81 -0
  9. data/config.yml +4752 -0
  10. data/docs/build_system.md +119 -0
  11. data/docs/configuration.md +69 -0
  12. data/docs/cruby_compilation.md +27 -0
  13. data/docs/design.md +53 -0
  14. data/docs/encoding.md +121 -0
  15. data/docs/fuzzing.md +81 -0
  16. data/docs/heredocs.md +36 -0
  17. data/docs/javascript.md +133 -0
  18. data/docs/local_variable_depth.md +229 -0
  19. data/docs/mapping.md +117 -0
  20. data/docs/parser_translation.md +24 -0
  21. data/docs/parsing_rules.md +22 -0
  22. data/docs/releasing.md +147 -0
  23. data/docs/relocation.md +32 -0
  24. data/docs/ripper_translation.md +63 -0
  25. data/docs/ruby_api.md +45 -0
  26. data/docs/ruby_parser_translation.md +19 -0
  27. data/docs/serialization.md +230 -0
  28. data/docs/testing.md +72 -0
  29. data/ext/prism/api_node.c +7005 -0
  30. data/ext/prism/extconf.rb +126 -0
  31. data/ext/prism/extension.c +1783 -0
  32. data/ext/prism/extension.h +19 -0
  33. data/include/prism/arena.h +37 -0
  34. data/include/prism/ast.h +10371 -0
  35. data/include/prism/buffer.h +52 -0
  36. data/include/prism/comments.h +55 -0
  37. data/include/prism/compiler/accel.h +24 -0
  38. data/include/prism/compiler/align.h +36 -0
  39. data/include/prism/compiler/assume.h +25 -0
  40. data/include/prism/compiler/exported.h +24 -0
  41. data/include/prism/compiler/fallthrough.h +22 -0
  42. data/include/prism/compiler/filesystem.h +32 -0
  43. data/include/prism/compiler/flex_array.h +19 -0
  44. data/include/prism/compiler/force_inline.h +21 -0
  45. data/include/prism/compiler/format.h +25 -0
  46. data/include/prism/compiler/inline.h +17 -0
  47. data/include/prism/compiler/nodiscard.h +22 -0
  48. data/include/prism/compiler/nonnull.h +18 -0
  49. data/include/prism/compiler/unused.h +18 -0
  50. data/include/prism/constant_pool.h +81 -0
  51. data/include/prism/diagnostic.h +93 -0
  52. data/include/prism/errors_format.h +53 -0
  53. data/include/prism/excludes.h +29 -0
  54. data/include/prism/integer.h +41 -0
  55. data/include/prism/internal/allocator.h +68 -0
  56. data/include/prism/internal/allocator_debug.h +88 -0
  57. data/include/prism/internal/arena.h +108 -0
  58. data/include/prism/internal/bit.h +42 -0
  59. data/include/prism/internal/buffer.h +91 -0
  60. data/include/prism/internal/char.h +145 -0
  61. data/include/prism/internal/comments.h +53 -0
  62. data/include/prism/internal/constant_pool.h +152 -0
  63. data/include/prism/internal/diagnostic.h +389 -0
  64. data/include/prism/internal/encoding.h +242 -0
  65. data/include/prism/internal/integer.h +68 -0
  66. data/include/prism/internal/isinf.h +16 -0
  67. data/include/prism/internal/line_offset_list.h +34 -0
  68. data/include/prism/internal/list.h +62 -0
  69. data/include/prism/internal/magic_comments.h +23 -0
  70. data/include/prism/internal/memchr.h +15 -0
  71. data/include/prism/internal/node.h +38 -0
  72. data/include/prism/internal/options.h +232 -0
  73. data/include/prism/internal/parser.h +984 -0
  74. data/include/prism/internal/regexp.h +26 -0
  75. data/include/prism/internal/serialize.h +39 -0
  76. data/include/prism/internal/source.h +72 -0
  77. data/include/prism/internal/static_literals.h +100 -0
  78. data/include/prism/internal/stringy.h +35 -0
  79. data/include/prism/internal/strncasecmp.h +18 -0
  80. data/include/prism/internal/strpbrk.h +33 -0
  81. data/include/prism/internal/tokens.h +11 -0
  82. data/include/prism/json.h +32 -0
  83. data/include/prism/line_offset_list.h +61 -0
  84. data/include/prism/magic_comments.h +35 -0
  85. data/include/prism/node.h +94 -0
  86. data/include/prism/options.h +354 -0
  87. data/include/prism/parser.h +404 -0
  88. data/include/prism/prettyprint.h +31 -0
  89. data/include/prism/serialize.h +115 -0
  90. data/include/prism/source.h +155 -0
  91. data/include/prism/stream.h +28 -0
  92. data/include/prism/string_query.h +63 -0
  93. data/include/prism/stringy.h +72 -0
  94. data/include/prism/version.h +38 -0
  95. data/include/prism.h +131 -0
  96. data/lib/prism/3.3/prism.so +0 -0
  97. data/lib/prism/3.4/prism.so +0 -0
  98. data/lib/prism/4.0/prism.so +0 -0
  99. data/lib/prism/compiler.rb +815 -0
  100. data/lib/prism/desugar_compiler.rb +463 -0
  101. data/lib/prism/dispatcher.rb +2383 -0
  102. data/lib/prism/dot_visitor.rb +4848 -0
  103. data/lib/prism/dsl.rb +1369 -0
  104. data/lib/prism/ffi.rb +740 -0
  105. data/lib/prism/inspect_visitor.rb +2425 -0
  106. data/lib/prism/lex_compat.rb +953 -0
  107. data/lib/prism/mutation_compiler.rb +780 -0
  108. data/lib/prism/node.rb +33204 -0
  109. data/lib/prism/node_ext.rb +504 -0
  110. data/lib/prism/node_find.rb +215 -0
  111. data/lib/prism/parse_result/errors.rb +72 -0
  112. data/lib/prism/parse_result/newlines.rb +423 -0
  113. data/lib/prism/parse_result.rb +1221 -0
  114. data/lib/prism/pattern.rb +314 -0
  115. data/lib/prism/polyfill/append_as_bytes.rb +15 -0
  116. data/lib/prism/polyfill/byteindex.rb +13 -0
  117. data/lib/prism/polyfill/scan_byte.rb +14 -0
  118. data/lib/prism/polyfill/unpack1.rb +14 -0
  119. data/lib/prism/polyfill/warn.rb +36 -0
  120. data/lib/prism/reflection.rb +427 -0
  121. data/lib/prism/relocation.rb +567 -0
  122. data/lib/prism/serialize.rb +5308 -0
  123. data/lib/prism/string_query.rb +46 -0
  124. data/lib/prism/translation/parser/builder.rb +70 -0
  125. data/lib/prism/translation/parser/compiler.rb +2226 -0
  126. data/lib/prism/translation/parser/lexer.rb +769 -0
  127. data/lib/prism/translation/parser.rb +376 -0
  128. data/lib/prism/translation/parser_current.rb +26 -0
  129. data/lib/prism/translation/parser_versions.rb +36 -0
  130. data/lib/prism/translation/ripper/filter.rb +53 -0
  131. data/lib/prism/translation/ripper/lexer.rb +133 -0
  132. data/lib/prism/translation/ripper/sexp.rb +118 -0
  133. data/lib/prism/translation/ripper/shim.rb +7 -0
  134. data/lib/prism/translation/ripper.rb +4278 -0
  135. data/lib/prism/translation/ruby_parser.rb +1721 -0
  136. data/lib/prism/translation.rb +20 -0
  137. data/lib/prism/visitor.rb +1440 -0
  138. data/lib/prism.rb +168 -0
  139. data/prism.gemspec +234 -0
  140. data/rbi/generated/prism/compiler.rbi +489 -0
  141. data/rbi/generated/prism/desugar_compiler.rbi +306 -0
  142. data/rbi/generated/prism/dispatcher.rbi +1138 -0
  143. data/rbi/generated/prism/dot_visitor.rbi +618 -0
  144. data/rbi/generated/prism/dsl.rbi +751 -0
  145. data/rbi/generated/prism/inspect_visitor.rbi +503 -0
  146. data/rbi/generated/prism/lex_compat.rbi +162 -0
  147. data/rbi/generated/prism/mutation_compiler.rbi +464 -0
  148. data/rbi/generated/prism/node.rbi +13681 -0
  149. data/rbi/generated/prism/node_ext.rbi +259 -0
  150. data/rbi/generated/prism/node_find.rbi +79 -0
  151. data/rbi/generated/prism/parse_result/errors.rbi +21 -0
  152. data/rbi/generated/prism/parse_result/newlines.rbi +208 -0
  153. data/rbi/generated/prism/parse_result.rbi +764 -0
  154. data/rbi/generated/prism/pattern.rbi +134 -0
  155. data/rbi/generated/prism/reflection.rbi +89 -0
  156. data/rbi/generated/prism/relocation.rbi +329 -0
  157. data/rbi/generated/prism/serialize.rbi +181 -0
  158. data/rbi/generated/prism/string_query.rbi +36 -0
  159. data/rbi/generated/prism/translation.rbi +7 -0
  160. data/rbi/generated/prism/visitor.rbi +650 -0
  161. data/rbi/generated/prism.rbi +86 -0
  162. data/rbi/prism/translation/parser.rbi +11 -0
  163. data/rbi/prism/translation/parser_versions.rbi +28 -0
  164. data/rbi/prism/translation/ripper.rbi +15 -0
  165. data/rbi/rubyvm/node_find.rbi +14 -0
  166. data/sig/generated/prism/compiler.rbs +492 -0
  167. data/sig/generated/prism/desugar_compiler.rbs +305 -0
  168. data/sig/generated/prism/dispatcher.rbs +1292 -0
  169. data/sig/generated/prism/dot_visitor.rbs +635 -0
  170. data/sig/generated/prism/dsl.rbs +928 -0
  171. data/sig/generated/prism/inspect_visitor.rbs +509 -0
  172. data/sig/generated/prism/lex_compat.rbs +166 -0
  173. data/sig/generated/prism/mutation_compiler.rbs +464 -0
  174. data/sig/generated/prism/node.rbs +20160 -0
  175. data/sig/generated/prism/node_ext.rbs +290 -0
  176. data/sig/generated/prism/node_find.rbs +90 -0
  177. data/sig/generated/prism/parse_result/errors.rbs +22 -0
  178. data/sig/generated/prism/parse_result/newlines.rbs +223 -0
  179. data/sig/generated/prism/parse_result.rbs +859 -0
  180. data/sig/generated/prism/pattern.rbs +156 -0
  181. data/sig/generated/prism/reflection.rbs +101 -0
  182. data/sig/generated/prism/relocation.rbs +428 -0
  183. data/sig/generated/prism/serialize.rbs +195 -0
  184. data/sig/generated/prism/string_query.rbs +36 -0
  185. data/sig/generated/prism/translation.rbs +8 -0
  186. data/sig/generated/prism/visitor.rbs +1111 -0
  187. data/sig/generated/prism.rbs +84 -0
  188. data/sig/manifest.yaml +2 -0
  189. data/src/arena.c +117 -0
  190. data/src/buffer.c +380 -0
  191. data/src/char.c +289 -0
  192. data/src/comments.c +454 -0
  193. data/src/constant_pool.c +406 -0
  194. data/src/diagnostic.c +886 -0
  195. data/src/encoding.c +5345 -0
  196. data/src/errors_format.c +519 -0
  197. data/src/integer.c +681 -0
  198. data/src/json.c +5733 -0
  199. data/src/line_offset_list.c +100 -0
  200. data/src/list.c +24 -0
  201. data/src/memchr.c +37 -0
  202. data/src/node.c +4515 -0
  203. data/src/options.c +451 -0
  204. data/src/parser.c +349 -0
  205. data/src/prettyprint.c +9024 -0
  206. data/src/prism.c +23739 -0
  207. data/src/regexp.c +1706 -0
  208. data/src/serialize.c +2309 -0
  209. data/src/source.c +518 -0
  210. data/src/static_literals.c +685 -0
  211. data/src/string_query.c +166 -0
  212. data/src/stringy.c +91 -0
  213. data/src/strncasecmp.c +37 -0
  214. data/src/strpbrk.c +447 -0
  215. data/src/tokens.c +724 -0
  216. metadata +259 -0
@@ -0,0 +1,259 @@
1
+ # typed: true
2
+
3
+ module Prism
4
+ class Node
5
+ abstract!
6
+
7
+ sig { params(replacements: String).void }
8
+ def deprecated(*replacements); end
9
+ end
10
+
11
+ module RegularExpressionOptions
12
+ # Returns a numeric value that represents the flags that were used to create
13
+ # the regular expression.
14
+ sig { params(flags: Integer).returns(Integer) }
15
+ def self.options(flags); end
16
+ end
17
+
18
+ class InterpolatedMatchLastLineNode < Node
19
+ # Returns a numeric value that represents the flags that were used to create
20
+ # the regular expression.
21
+ sig { returns(Integer) }
22
+ def options; end
23
+ end
24
+
25
+ class InterpolatedRegularExpressionNode < Node
26
+ # Returns a numeric value that represents the flags that were used to create
27
+ # the regular expression.
28
+ sig { returns(Integer) }
29
+ def options; end
30
+ end
31
+
32
+ class MatchLastLineNode < Node
33
+ # Returns a numeric value that represents the flags that were used to create
34
+ # the regular expression.
35
+ sig { returns(Integer) }
36
+ def options; end
37
+ end
38
+
39
+ class RegularExpressionNode < Node
40
+ # Returns a numeric value that represents the flags that were used to create
41
+ # the regular expression.
42
+ sig { returns(Integer) }
43
+ def options; end
44
+ end
45
+
46
+ module HeredocQuery
47
+ # Returns true if this node was represented as a heredoc in the source code.
48
+ sig { params(opening: ::T.nilable(String)).returns(::T.nilable(T::Boolean)) }
49
+ def self.heredoc?(opening); end
50
+ end
51
+
52
+ class InterpolatedStringNode < Node
53
+ # Returns true if this node was represented as a heredoc in the source code.
54
+ sig { returns(::T.nilable(T::Boolean)) }
55
+ def heredoc?; end
56
+ end
57
+
58
+ class InterpolatedXStringNode < Node
59
+ # Returns true if this node was represented as a heredoc in the source code.
60
+ sig { returns(::T.nilable(T::Boolean)) }
61
+ def heredoc?; end
62
+ end
63
+
64
+ class StringNode < Node
65
+ # Returns true if this node was represented as a heredoc in the source code.
66
+ sig { returns(::T.nilable(T::Boolean)) }
67
+ def heredoc?; end
68
+
69
+ # Occasionally it's helpful to treat a string as if it were interpolated so
70
+ # that there's a consistent interface for working with strings.
71
+ sig { returns(InterpolatedStringNode) }
72
+ def to_interpolated; end
73
+ end
74
+
75
+ class XStringNode < Node
76
+ # Returns true if this node was represented as a heredoc in the source code.
77
+ sig { returns(::T.nilable(T::Boolean)) }
78
+ def heredoc?; end
79
+
80
+ # Occasionally it's helpful to treat a string as if it were interpolated so
81
+ # that there's a consistent interface for working with strings.
82
+ sig { returns(InterpolatedXStringNode) }
83
+ def to_interpolated; end
84
+ end
85
+
86
+ class ImaginaryNode < Node
87
+ # Returns the value of the node as a Ruby Complex.
88
+ sig { returns(Complex) }
89
+ def value; end
90
+ end
91
+
92
+ class RationalNode < Node
93
+ # Returns the value of the node as a Ruby Rational.
94
+ sig { returns(Rational) }
95
+ def value; end
96
+ end
97
+
98
+ class ConstantReadNode < Node
99
+ # Returns the list of parts for the full name of this constant.
100
+ # For example: [:Foo]
101
+ sig { returns(T::Array[Symbol]) }
102
+ def full_name_parts; end
103
+
104
+ # Returns the full name of this constant. For example: "Foo"
105
+ sig { returns(String) }
106
+ def full_name; end
107
+ end
108
+
109
+ class ConstantWriteNode < Node
110
+ # Returns the list of parts for the full name of this constant.
111
+ # For example: [:Foo]
112
+ sig { returns(T::Array[Symbol]) }
113
+ def full_name_parts; end
114
+
115
+ # Returns the full name of this constant. For example: "Foo"
116
+ sig { returns(String) }
117
+ def full_name; end
118
+ end
119
+
120
+ class ConstantPathNode < Node
121
+ # An error class raised when dynamic parts are found while computing a
122
+ # constant path's full name. For example:
123
+ # Foo::Bar::Baz -> does not raise because all parts of the constant path are
124
+ # simple constants
125
+ # var::Bar::Baz -> raises because the first part of the constant path is a
126
+ # local variable
127
+ class DynamicPartsInConstantPathError < StandardError; end
128
+
129
+ # An error class raised when error recovery nodes are found while computing a
130
+ # constant path's full name. For example:
131
+ # Foo:: -> raises because the constant path is missing the last part
132
+ class ErrorRecoveryNodesInConstantPathError < StandardError; end
133
+
134
+ # Returns the list of parts for the full name of this constant path.
135
+ # For example: [:Foo, :Bar]
136
+ sig { returns(T::Array[Symbol]) }
137
+ def full_name_parts; end
138
+
139
+ # Returns the full name of this constant path. For example: "Foo::Bar"
140
+ sig { returns(String) }
141
+ def full_name; end
142
+ end
143
+
144
+ class ConstantPathTargetNode < Node
145
+ # Returns the list of parts for the full name of this constant path.
146
+ # For example: [:Foo, :Bar]
147
+ sig { returns(T::Array[Symbol]) }
148
+ def full_name_parts; end
149
+
150
+ # Returns the full name of this constant path. For example: "Foo::Bar"
151
+ sig { returns(String) }
152
+ def full_name; end
153
+ end
154
+
155
+ class ConstantTargetNode < Node
156
+ # Returns the list of parts for the full name of this constant.
157
+ # For example: [:Foo]
158
+ sig { returns(T::Array[Symbol]) }
159
+ def full_name_parts; end
160
+
161
+ # Returns the full name of this constant. For example: "Foo"
162
+ sig { returns(String) }
163
+ def full_name; end
164
+ end
165
+
166
+ class ParametersNode < Node
167
+ # Mirrors the Method#parameters method.
168
+ sig { returns(T::Array[::T.any([Symbol, Symbol], [Symbol])]) }
169
+ def signature; end
170
+ end
171
+
172
+ class CallNode < Node
173
+ # When a call node has the attribute_write flag set, it means that the call
174
+ # is using the attribute write syntax. This is either a method call to []=
175
+ # or a method call to a method that ends with =. Either way, the = sign is
176
+ # present in the source.
177
+ #
178
+ # Prism returns the message_loc _without_ the = sign attached, because there
179
+ # can be any amount of space between the message and the = sign. However,
180
+ # sometimes you want the location of the full message including the inner
181
+ # space and the = sign. This method provides that.
182
+ sig { returns(::T.nilable(Location)) }
183
+ def full_message_loc; end
184
+ end
185
+
186
+ class InNode < Node
187
+ sig { returns(String) }
188
+ def in; end
189
+
190
+ sig { returns(Location) }
191
+ def in_loc; end
192
+
193
+ sig { returns(::T.nilable(String)) }
194
+ def then; end
195
+
196
+ sig { returns(::T.nilable(Location)) }
197
+ def then_loc; end
198
+ end
199
+
200
+ class MatchPredicateNode < Node
201
+ sig { returns(String) }
202
+ def operator; end
203
+
204
+ sig { returns(Location) }
205
+ def operator_loc; end
206
+ end
207
+
208
+ class UnlessNode < Node
209
+ sig { returns(String) }
210
+ def keyword; end
211
+
212
+ sig { returns(Location) }
213
+ def keyword_loc; end
214
+ end
215
+
216
+ class UntilNode < Node
217
+ sig { returns(String) }
218
+ def keyword; end
219
+
220
+ sig { returns(Location) }
221
+ def keyword_loc; end
222
+
223
+ sig { returns(::T.nilable(String)) }
224
+ def closing; end
225
+
226
+ sig { returns(::T.nilable(Location)) }
227
+ def closing_loc; end
228
+ end
229
+
230
+ class WhenNode < Node
231
+ sig { returns(String) }
232
+ def keyword; end
233
+
234
+ sig { returns(Location) }
235
+ def keyword_loc; end
236
+ end
237
+
238
+ class WhileNode < Node
239
+ sig { returns(String) }
240
+ def keyword; end
241
+
242
+ sig { returns(Location) }
243
+ def keyword_loc; end
244
+
245
+ sig { returns(::T.nilable(String)) }
246
+ def closing; end
247
+
248
+ sig { returns(::T.nilable(Location)) }
249
+ def closing_loc; end
250
+ end
251
+
252
+ class SymbolNode < Node
253
+ sig { returns(String) }
254
+ def value; end
255
+
256
+ sig { returns(Location) }
257
+ def value_loc; end
258
+ end
259
+ end
@@ -0,0 +1,79 @@
1
+ # typed: true
2
+
3
+ module Prism
4
+ # Finds the Prism AST node corresponding to a given Method, UnboundMethod,
5
+ # Proc, or Thread::Backtrace::Location. On CRuby, uses node_id from the
6
+ # instruction sequence for an exact match. On other implementations, falls
7
+ # back to best-effort matching by source location line number.
8
+ #
9
+ # This module is autoloaded so that programs that don't use Prism.find don't
10
+ # pay for its definition.
11
+ module NodeFind
12
+ # Find the node for the given callable or backtrace location.
13
+ sig { params(callable: ::T.any(Method, UnboundMethod, Proc, Thread::Backtrace::Location)).returns(::T.nilable(Node)) }
14
+ def self.find(callable); end
15
+
16
+ # Base class that handles parsing a file.
17
+ class Find
18
+ # Parse the given file path, returning a ParseResult or nil.
19
+ sig { params(file: ::T.nilable(String)).returns(::T.nilable(ParseResult)) }
20
+ private def parse_file(file); end
21
+ end
22
+
23
+ # Finds the AST node for a Method, UnboundMethod, Proc or Thread::Backtrace::Location
24
+ # using the #source_range
25
+ class SourceRangeFind < Find
26
+ # Find the node for the given callable using the #source_range.
27
+ sig { params(callable: ::T.any(Method, UnboundMethod, Proc, Thread::Backtrace::Location)).returns(::T.nilable(Node)) }
28
+ def find(callable); end
29
+ end
30
+
31
+ # Finds the AST node for a Method, UnboundMethod, or Proc using the node_id
32
+ # from the instruction sequence.
33
+ class RubyVMCallableFind < Find
34
+ # Find the node for the given callable using the ISeq node_id.
35
+ sig { params(callable: ::T.any(Method, UnboundMethod, Proc)).returns(::T.nilable(Node)) }
36
+ def find(callable); end
37
+ end
38
+
39
+ # Finds the AST node for a Thread::Backtrace::Location using the node_id
40
+ # from the backtrace location.
41
+ class RubyVMBacktraceLocationFind < Find
42
+ # Find the node for the given backtrace location using node_id.
43
+ sig { params(location: Thread::Backtrace::Location).returns(::T.nilable(Node)) }
44
+ def find(location); end
45
+ end
46
+
47
+ # Finds the AST node for a Method or UnboundMethod using best-effort line
48
+ # matching. Used on non-CRuby implementations.
49
+ class LineMethodFind < Find
50
+ # Find the node for the given method by matching on name and line.
51
+ sig { params(callable: ::T.any(Method, UnboundMethod)).returns(::T.nilable(Node)) }
52
+ def find(callable); end
53
+ end
54
+
55
+ # Finds the AST node for a lambda using best-effort line matching. Used
56
+ # on non-CRuby implementations.
57
+ class LineLambdaFind < Find
58
+ # Find the node for the given lambda by matching on line.
59
+ sig { params(callable: Proc).returns(::T.nilable(Node)) }
60
+ def find(callable); end
61
+ end
62
+
63
+ # Finds the AST node for a non-lambda Proc using best-effort line
64
+ # matching. Used on non-CRuby implementations.
65
+ class LineProcFind < Find
66
+ # Find the node for the given proc by matching on line.
67
+ sig { params(callable: Proc).returns(::T.nilable(Node)) }
68
+ def find(callable); end
69
+ end
70
+
71
+ # Finds the AST node for a Thread::Backtrace::Location using best-effort
72
+ # line matching. Used on non-CRuby implementations.
73
+ class LineBacktraceLocationFind < Find
74
+ # Find the node for the given backtrace location by matching on line.
75
+ sig { params(location: Thread::Backtrace::Location).returns(::T.nilable(Node)) }
76
+ def find(location); end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,21 @@
1
+ # typed: true
2
+
3
+ module Prism
4
+ class ParseResult < Result
5
+ # An object to represent the set of errors on a parse result. This object
6
+ # can be used to format the errors in a human-readable way.
7
+ class Errors
8
+ # The parse result that contains the errors.
9
+ sig { returns(ParseResult) }
10
+ attr_reader :parse_result
11
+
12
+ # Initialize a new set of errors from the given parse result.
13
+ sig { params(parse_result: ParseResult).void }
14
+ def initialize(parse_result); end
15
+
16
+ # Formats the errors in a human-readable way and return them as a string.
17
+ sig { returns(String) }
18
+ def format; end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,208 @@
1
+ # typed: true
2
+
3
+ module Prism
4
+ class ParseResult < Result
5
+ # The :line tracepoint event gets fired whenever the Ruby VM encounters an
6
+ # expression on a new line. The types of expressions that can trigger this
7
+ # event are:
8
+ #
9
+ # * if statements
10
+ # * unless statements
11
+ # * nodes that are children of statements lists
12
+ #
13
+ # In order to keep track of the newlines, we have a list of offsets that
14
+ # come back from the parser. We assign these offsets to the first nodes that
15
+ # we find in the tree that are on those lines.
16
+ #
17
+ # Note that the logic in this file should be kept in sync with the Java
18
+ # MarkNewlinesVisitor, since that visitor is responsible for marking the
19
+ # newlines for JRuby/TruffleRuby.
20
+ #
21
+ # This file is autoloaded only when `mark_newlines!` is called, so the
22
+ # re-opening of the various nodes in this file will only be performed in
23
+ # that case. We do that to avoid storing the extra `@newline` instance
24
+ # variable on every node if we don't need it.
25
+ class Newlines < Visitor
26
+ # Create a new Newlines visitor with the given newline offsets.
27
+ sig { params(lines: Integer).void }
28
+ def initialize(lines); end
29
+
30
+ # Permit block nodes to mark newlines within themselves.
31
+ sig { params(node: BlockNode).void }
32
+ def visit_block_node(node); end
33
+
34
+ # Permit lambda nodes to mark newlines within themselves.
35
+ sig { params(node: LambdaNode).void }
36
+ def visit_lambda_node(node); end
37
+
38
+ # Permit def nodes to mark newlines within themselves. The body of an
39
+ # endless method definition never emits newline events, so in that case
40
+ # mark every line as already seen while visiting it instead. Nested
41
+ # scopes (blocks, lambdas, etc.) reset the lines and emit events again.
42
+ sig { params(node: DefNode).void }
43
+ def visit_def_node(node); end
44
+
45
+ # Permit class nodes to mark newlines within themselves.
46
+ sig { params(node: ClassNode).void }
47
+ def visit_class_node(node); end
48
+
49
+ # Permit module nodes to mark newlines within themselves.
50
+ sig { params(node: ModuleNode).void }
51
+ def visit_module_node(node); end
52
+
53
+ # Permit singleton class nodes to mark newlines within themselves.
54
+ sig { params(node: SingletonClassNode).void }
55
+ def visit_singleton_class_node(node); end
56
+
57
+ # Statements inside string interpolation do not emit newline events, so
58
+ # mark every line as already seen while visiting them. Nested scopes
59
+ # (blocks, lambdas, defs, etc.) reset the lines and emit events again.
60
+ sig { params(node: EmbeddedStatementsNode).void }
61
+ def visit_embedded_statements_node(node); end
62
+
63
+ # The predicate of a while loop is compiled at the end of the loop,
64
+ # after the body, so any statements it contains (from parentheses)
65
+ # emit their line events again even if the lines were already seen.
66
+ sig { params(node: WhileNode).void }
67
+ def visit_while_node(node); end
68
+
69
+ # The predicate of an until loop is compiled at the end of the loop,
70
+ # after the body, so any statements it contains (from parentheses)
71
+ # emit their line events again even if the lines were already seen.
72
+ sig { params(node: UntilNode).void }
73
+ def visit_until_node(node); end
74
+
75
+ # Mark if nodes as newlines.
76
+ sig { params(node: IfNode).void }
77
+ def visit_if_node(node); end
78
+
79
+ # Mark unless nodes as newlines.
80
+ sig { params(node: UnlessNode).void }
81
+ def visit_unless_node(node); end
82
+
83
+ # Permit statements lists to mark newlines within themselves.
84
+ sig { params(node: StatementsNode).void }
85
+ def visit_statements_node(node); end
86
+ end
87
+ end
88
+
89
+ class Node
90
+ abstract!
91
+
92
+ sig { returns(T::Boolean) }
93
+ def newline_flag?; end
94
+
95
+ sig { params(lines: T::Array[T::Boolean]).void }
96
+ def newline_flag!(lines); end
97
+ end
98
+
99
+ class BeginNode < Node
100
+ sig { params(lines: T::Array[T::Boolean]).void }
101
+ def newline_flag!(lines); end
102
+ end
103
+
104
+ class ParenthesesNode < Node
105
+ sig { params(lines: T::Array[T::Boolean]).void }
106
+ def newline_flag!(lines); end
107
+ end
108
+
109
+ class IfNode < Node
110
+ sig { params(lines: T::Array[T::Boolean]).void }
111
+ def newline_flag!(lines); end
112
+ end
113
+
114
+ class UnlessNode < Node
115
+ sig { params(lines: T::Array[T::Boolean]).void }
116
+ def newline_flag!(lines); end
117
+ end
118
+
119
+ class UntilNode < Node
120
+ sig { params(lines: T::Array[T::Boolean]).void }
121
+ def newline_flag!(lines); end
122
+ end
123
+
124
+ class WhileNode < Node
125
+ sig { params(lines: T::Array[T::Boolean]).void }
126
+ def newline_flag!(lines); end
127
+ end
128
+
129
+ class RescueModifierNode < Node
130
+ sig { params(lines: T::Array[T::Boolean]).void }
131
+ def newline_flag!(lines); end
132
+ end
133
+
134
+ class LocalVariableWriteNode < Node
135
+ sig { params(lines: T::Array[T::Boolean]).void }
136
+ def newline_flag!(lines); end
137
+ end
138
+
139
+ class InstanceVariableWriteNode < Node
140
+ sig { params(lines: T::Array[T::Boolean]).void }
141
+ def newline_flag!(lines); end
142
+ end
143
+
144
+ class ClassVariableWriteNode < Node
145
+ sig { params(lines: T::Array[T::Boolean]).void }
146
+ def newline_flag!(lines); end
147
+ end
148
+
149
+ class GlobalVariableWriteNode < Node
150
+ sig { params(lines: T::Array[T::Boolean]).void }
151
+ def newline_flag!(lines); end
152
+ end
153
+
154
+ class ConstantWriteNode < Node
155
+ sig { params(lines: T::Array[T::Boolean]).void }
156
+ def newline_flag!(lines); end
157
+ end
158
+
159
+ class ConstantPathWriteNode < Node
160
+ sig { params(lines: T::Array[T::Boolean]).void }
161
+ def newline_flag!(lines); end
162
+ end
163
+
164
+ class MultiWriteNode < Node
165
+ sig { params(lines: T::Array[T::Boolean]).void }
166
+ def newline_flag!(lines); end
167
+ end
168
+
169
+ class CallNode < Node
170
+ sig { params(lines: T::Array[T::Boolean]).void }
171
+ def newline_flag!(lines); end
172
+ end
173
+
174
+ class ArrayNode < Node
175
+ sig { params(lines: T::Array[T::Boolean]).void }
176
+ def newline_flag!(lines); end
177
+ end
178
+
179
+ class HashNode < Node
180
+ sig { params(lines: T::Array[T::Boolean]).void }
181
+ def newline_flag!(lines); end
182
+ end
183
+
184
+ class InterpolatedMatchLastLineNode < Node
185
+ sig { params(lines: T::Array[T::Boolean]).void }
186
+ def newline_flag!(lines); end
187
+ end
188
+
189
+ class InterpolatedRegularExpressionNode < Node
190
+ sig { params(lines: T::Array[T::Boolean]).void }
191
+ def newline_flag!(lines); end
192
+ end
193
+
194
+ class InterpolatedStringNode < Node
195
+ sig { params(lines: T::Array[T::Boolean]).void }
196
+ def newline_flag!(lines); end
197
+ end
198
+
199
+ class InterpolatedSymbolNode < Node
200
+ sig { params(lines: T::Array[T::Boolean]).void }
201
+ def newline_flag!(lines); end
202
+ end
203
+
204
+ class InterpolatedXStringNode < Node
205
+ sig { params(lines: T::Array[T::Boolean]).void }
206
+ def newline_flag!(lines); end
207
+ end
208
+ end