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,764 @@
1
+ # typed: true
2
+
3
+ module Prism
4
+ # This represents a source of Ruby code that has been parsed. It is used in
5
+ # conjunction with locations to allow them to resolve line numbers and source
6
+ # ranges.
7
+ class Source
8
+ # Create a new source object with the given source code. This method should
9
+ # be used instead of `new` and it will return either a `Source` or a
10
+ # specialized and more performant `ASCIISource` if no multibyte characters
11
+ # are present in the source code.
12
+ #
13
+ # Note that if you are calling this method manually, you will need to supply
14
+ # the start_line and offsets parameters. start_line is the line number that
15
+ # the source starts on, which is typically 1 but can be different if this
16
+ # source is a subset of a larger source or if this is an eval. offsets is an
17
+ # array of byte offsets for the start of each line in the source code, which
18
+ # can be calculated by iterating through the source code and recording the
19
+ # byte offset whenever a newline character is encountered. The first
20
+ # element is always 0 to mark the first line.
21
+ #
22
+ # The comments, comment_attachments, and comment_ranges parameters are the
23
+ # lists described by the attributes of the same names. They are passed in
24
+ # empty when the source is created by the parser and filled in afterward,
25
+ # because the comments themselves refer to the source.
26
+ sig { params(source: String, start_line: Integer, offsets: T::Array[Integer], comments: T::Array[Comment], comment_attachments: T::Array[Comment], comment_ranges: T::Array[::T.nilable(Integer)]).returns(Source) }
27
+ def self.for(source, start_line, offsets, comments = T.unsafe(nil), comment_attachments = T.unsafe(nil), comment_ranges = T.unsafe(nil)); end
28
+
29
+ # The source code that this source object represents.
30
+ sig { returns(String) }
31
+ attr_reader :source
32
+
33
+ # The line number where this source starts.
34
+ sig { returns(Integer) }
35
+ attr_reader :start_line
36
+
37
+ # The list of comments that were encountered during parsing. When the source
38
+ # is parsed with the attach_comments option, these are sorted by start
39
+ # offset.
40
+ sig { returns(T::Array[Comment]) }
41
+ attr_reader :comments
42
+
43
+ # The comments attached to nodes, grouped by node in order of node id. This
44
+ # is empty unless the source was parsed with the attach_comments option.
45
+ sig { returns(T::Array[Comment]) }
46
+ attr_reader :comment_attachments
47
+
48
+ # Indices into comment_attachments, indexed by node id. For each node that
49
+ # owns comments, the index at which its comments begin is stored at its node
50
+ # id and the index at which they end is stored at the following node id. The
51
+ # other entries are nil. This is empty unless the source was parsed with the
52
+ # attach_comments option.
53
+ sig { returns(T::Array[::T.nilable(Integer)]) }
54
+ attr_reader :comment_ranges
55
+
56
+ # The list of newline byte offsets in the source code. When initialized from
57
+ # the C extension, this may be a packed binary string of uint32_t values
58
+ # that is lazily unpacked on first access.
59
+ sig { returns(T::Array[Integer]) }
60
+ def offsets; end
61
+
62
+ # Create a new source object with the given source code. The offsets
63
+ # parameter can be either an Array of Integer byte offsets or a packed
64
+ # binary string of uint32_t values (from the C extension).
65
+ sig { params(source: String, start_line: Integer, offsets: ::T.any(T::Array[Integer], String), comments: T::Array[Comment], comment_attachments: T::Array[Comment], comment_ranges: T::Array[::T.nilable(Integer)]).void }
66
+ def initialize(source, start_line, offsets, comments = T.unsafe(nil), comment_attachments = T.unsafe(nil), comment_ranges = T.unsafe(nil)); end
67
+
68
+ # Replace the value of start_line with the given value.
69
+ sig { params(start_line: Integer).void }
70
+ def replace_start_line(start_line); end
71
+
72
+ # Replace the value of offsets with the given value.
73
+ sig { params(offsets: T::Array[Integer]).void }
74
+ def replace_offsets(offsets); end
75
+
76
+ # The comments attached to the node with the given id, ordered by start
77
+ # offset. Comments are only attached when the source is parsed with the
78
+ # attach_comments option.
79
+ sig { params(node_id: Integer).returns(T::Array[Comment]) }
80
+ def comments_for(node_id); end
81
+
82
+ # Returns the encoding of the source code, which is set by parameters to the
83
+ # parser or by the encoding magic comment.
84
+ sig { returns(Encoding) }
85
+ def encoding; end
86
+
87
+ # Returns the lines of the source code as an array of strings.
88
+ sig { returns(T::Array[String]) }
89
+ def lines; end
90
+
91
+ # Perform a byteslice on the source code using the given byte offset and
92
+ # byte length.
93
+ sig { params(byte_offset: Integer, length: Integer).returns(String) }
94
+ def slice(byte_offset, length); end
95
+
96
+ # Converts the line number and column in bytes to a byte offset.
97
+ sig { params(line: Integer, column: Integer).returns(Integer) }
98
+ def byte_offset(line, column); end
99
+
100
+ # Binary search through the offsets to find the line number for the given
101
+ # byte offset.
102
+ sig { params(byte_offset: Integer).returns(Integer) }
103
+ def line(byte_offset); end
104
+
105
+ # Return the byte offset of the start of the line corresponding to the given
106
+ # byte offset.
107
+ sig { params(byte_offset: Integer).returns(Integer) }
108
+ def line_start(byte_offset); end
109
+
110
+ # Returns the byte offset of the end of the line corresponding to the given
111
+ # byte offset.
112
+ sig { params(byte_offset: Integer).returns(Integer) }
113
+ def line_end(byte_offset); end
114
+
115
+ # Return the column in bytes for the given byte offset.
116
+ sig { params(byte_offset: Integer).returns(Integer) }
117
+ def column(byte_offset); end
118
+
119
+ # Return the character offset for the given byte offset.
120
+ sig { params(byte_offset: Integer).returns(Integer) }
121
+ def character_offset(byte_offset); end
122
+
123
+ # Return the column in characters for the given byte offset.
124
+ sig { params(byte_offset: Integer).returns(Integer) }
125
+ def character_column(byte_offset); end
126
+
127
+ # Returns the offset from the start of the file for the given byte offset
128
+ # counting in code units for the given encoding.
129
+ #
130
+ # This method is tested with UTF-8, UTF-16, and UTF-32. If there is the
131
+ # concept of code units that differs from the number of characters in other
132
+ # encodings, it is not captured here.
133
+ #
134
+ # We purposefully replace invalid and undefined characters with replacement
135
+ # characters in this conversion. This happens for two reasons. First, it's
136
+ # possible that the given byte offset will not occur on a character
137
+ # boundary. Second, it's possible that the source code will contain a
138
+ # character that has no equivalent in the given encoding.
139
+ sig { params(byte_offset: Integer, encoding: Encoding).returns(Integer) }
140
+ def code_units_offset(byte_offset, encoding); end
141
+
142
+ # Generate a cache that targets a specific encoding for calculating code
143
+ # unit offsets.
144
+ sig { params(encoding: Encoding).returns(CodeUnitsCache) }
145
+ def code_units_cache(encoding); end
146
+
147
+ # Returns the column in code units for the given encoding for the
148
+ # given byte offset.
149
+ sig { params(byte_offset: Integer, encoding: Encoding).returns(Integer) }
150
+ def code_units_column(byte_offset, encoding); end
151
+
152
+ # Freeze this object and the objects it contains.
153
+ sig { void }
154
+ def deep_freeze; end
155
+
156
+ # Binary search through the offsets to find the index for the given
157
+ # byte offset.
158
+ sig { params(byte_offset: Integer).returns(Integer) }
159
+ def find_line(byte_offset); end
160
+ end
161
+
162
+ # A cache that can be used to quickly compute code unit offsets from byte
163
+ # offsets. It purposefully provides only a single #[] method to access the
164
+ # cache in order to minimize surface area.
165
+ #
166
+ # Note that there are some known issues here that may or may not be addressed
167
+ # in the future:
168
+ #
169
+ # * The first is that there are issues when the cache computes values that are
170
+ # not on character boundaries. This can result in subsequent computations
171
+ # being off by one or more code units.
172
+ # * The second is that this cache is currently unbounded. In theory we could
173
+ # introduce some kind of LRU cache to limit the number of entries, but this
174
+ # has not yet been implemented.
175
+ class CodeUnitsCache
176
+ # Counter used for UTF-8, where one code unit equals one byte.
177
+ class UTF8Counter
178
+ sig { params(byte_offset: Integer, byte_length: Integer).returns(Integer) }
179
+ def count(byte_offset, byte_length); end
180
+ end
181
+
182
+ class UTF16Counter
183
+ sig { params(source: String, encoding: Encoding).void }
184
+ def initialize(source, encoding); end
185
+
186
+ sig { params(byte_offset: Integer, byte_length: Integer).returns(Integer) }
187
+ def count(byte_offset, byte_length); end
188
+ end
189
+
190
+ # Counter used for UTF-32, where one code unit equals one code point and
191
+ # matches String#length. Also used as a best-effort fallback for any other
192
+ # encoding that does not have a dedicated counter.
193
+ class UTF32Counter
194
+ sig { params(source: String, encoding: Encoding).void }
195
+ def initialize(source, encoding); end
196
+
197
+ sig { params(byte_offset: Integer, byte_length: Integer).returns(Integer) }
198
+ def count(byte_offset, byte_length); end
199
+ end
200
+
201
+ # Initialize a new cache with the given source and encoding.
202
+ sig { params(source: String, encoding: Encoding).void }
203
+ def initialize(source, encoding); end
204
+
205
+ # Retrieve the code units offset from the given byte offset.
206
+ sig { params(byte_offset: Integer).returns(Integer) }
207
+ def [](byte_offset); end
208
+ end
209
+
210
+ # Specialized version of Prism::Source for source code that includes ASCII
211
+ # characters only. This class is used to apply performance optimizations that
212
+ # cannot be applied to sources that include multibyte characters.
213
+ #
214
+ # In the extremely rare case that a source includes multi-byte characters but
215
+ # is marked as binary because of a magic encoding comment and it cannot be
216
+ # eagerly converted to UTF-8, this class will be used as well. This is because
217
+ # at that point we will treat everything as single-byte characters.
218
+ class ASCIISource < Source
219
+ # Return the character offset for the given byte offset.
220
+ sig { params(byte_offset: Integer).returns(Integer) }
221
+ def character_offset(byte_offset); end
222
+
223
+ # Return the column in characters for the given byte offset.
224
+ sig { params(byte_offset: Integer).returns(Integer) }
225
+ def character_column(byte_offset); end
226
+
227
+ # Returns the offset from the start of the file for the given byte offset
228
+ # counting in code units for the given encoding.
229
+ #
230
+ # This method is tested with UTF-8, UTF-16, and UTF-32. If there is the
231
+ # concept of code units that differs from the number of characters in other
232
+ # encodings, it is not captured here.
233
+ sig { params(byte_offset: Integer, encoding: Encoding).returns(Integer) }
234
+ def code_units_offset(byte_offset, encoding); end
235
+
236
+ # Returns a cache that is the identity function in order to maintain the
237
+ # same interface. We can do this because code units are always equivalent to
238
+ # byte offsets for ASCII-only sources.
239
+ sig { params(encoding: Encoding).returns(::T.untyped) }
240
+ def code_units_cache(encoding); end
241
+
242
+ # Specialized version of `code_units_column` that does not depend on
243
+ # `code_units_offset`, which is a more expensive operation. This is
244
+ # essentially the same as `Prism::Source#column`.
245
+ sig { params(byte_offset: Integer, encoding: Encoding).returns(Integer) }
246
+ def code_units_column(byte_offset, encoding); end
247
+ end
248
+
249
+ # This represents a location in the source.
250
+ class Location
251
+ # A Source object that is used to determine more information from the given
252
+ # offset and length.
253
+ sig { returns(Source) }
254
+ attr_reader :source
255
+
256
+ # The byte offset from the beginning of the source where this location
257
+ # starts.
258
+ sig { returns(Integer) }
259
+ attr_reader :start_offset
260
+
261
+ # The length of this location in bytes.
262
+ sig { returns(Integer) }
263
+ attr_reader :length
264
+
265
+ # Create a new location object with the given source, start byte offset, and
266
+ # byte length.
267
+ sig { params(source: Source, start_offset: Integer, length: Integer).void }
268
+ def initialize(source, start_offset, length); end
269
+
270
+ # Create a new location object with the given options.
271
+ sig { params(source: Source, start_offset: Integer, length: Integer).returns(Location) }
272
+ def copy(source: T.unsafe(nil), start_offset: T.unsafe(nil), length: T.unsafe(nil)); end
273
+
274
+ # Returns a new location that is the result of chopping off the last byte.
275
+ sig { returns(Location) }
276
+ def chop; end
277
+
278
+ # Returns a string representation of this location.
279
+ sig { returns(String) }
280
+ def inspect; end
281
+
282
+ # Returns all of the lines of the source code associated with this location.
283
+ sig { returns(T::Array[String]) }
284
+ def source_lines; end
285
+
286
+ # The source code that this location represents.
287
+ sig { returns(String) }
288
+ def slice; end
289
+
290
+ # The source code that this location represents starting from the beginning
291
+ # of the line that this location starts on to the end of the line that this
292
+ # location ends on.
293
+ sig { returns(String) }
294
+ def slice_lines; end
295
+
296
+ # The character offset from the beginning of the source where this location
297
+ # starts.
298
+ sig { returns(Integer) }
299
+ def start_character_offset; end
300
+
301
+ # The offset from the start of the file in code units of the given encoding.
302
+ sig { params(encoding: Encoding).returns(Integer) }
303
+ def start_code_units_offset(encoding); end
304
+
305
+ # The start offset from the start of the file in code units using the given
306
+ # cache to fetch or calculate the value.
307
+ sig { params(cache: ::T.untyped).returns(Integer) }
308
+ def cached_start_code_units_offset(cache); end
309
+
310
+ # The byte offset from the beginning of the source where this location ends.
311
+ sig { returns(Integer) }
312
+ def end_offset; end
313
+
314
+ # The character offset from the beginning of the source where this location
315
+ # ends.
316
+ sig { returns(Integer) }
317
+ def end_character_offset; end
318
+
319
+ # The offset from the start of the file in code units of the given encoding.
320
+ sig { params(encoding: Encoding).returns(Integer) }
321
+ def end_code_units_offset(encoding); end
322
+
323
+ # The end offset from the start of the file in code units using the given
324
+ # cache to fetch or calculate the value.
325
+ sig { params(cache: ::T.untyped).returns(Integer) }
326
+ def cached_end_code_units_offset(cache); end
327
+
328
+ # The line number where this location starts.
329
+ sig { returns(Integer) }
330
+ def start_line; end
331
+
332
+ # The content of the line where this location starts before this location.
333
+ sig { returns(String) }
334
+ def start_line_slice; end
335
+
336
+ # The line number where this location ends.
337
+ sig { returns(Integer) }
338
+ def end_line; end
339
+
340
+ # The column in bytes where this location starts from the start of
341
+ # the line.
342
+ sig { returns(Integer) }
343
+ def start_column; end
344
+
345
+ # The column in characters where this location ends from the start of
346
+ # the line.
347
+ sig { returns(Integer) }
348
+ def start_character_column; end
349
+
350
+ # The column in code units of the given encoding where this location
351
+ # starts from the start of the line.
352
+ sig { params(encoding: Encoding).returns(Integer) }
353
+ def start_code_units_column(encoding = T.unsafe(nil)); end
354
+
355
+ # The start column in code units using the given cache to fetch or calculate
356
+ # the value.
357
+ sig { params(cache: ::T.untyped).returns(Integer) }
358
+ def cached_start_code_units_column(cache); end
359
+
360
+ # The column in bytes where this location ends from the start of the
361
+ # line.
362
+ sig { returns(Integer) }
363
+ def end_column; end
364
+
365
+ # The column in characters where this location ends from the start of
366
+ # the line.
367
+ sig { returns(Integer) }
368
+ def end_character_column; end
369
+
370
+ # The column in code units of the given encoding where this location
371
+ # ends from the start of the line.
372
+ sig { params(encoding: Encoding).returns(Integer) }
373
+ def end_code_units_column(encoding = T.unsafe(nil)); end
374
+
375
+ # The end column in code units using the given cache to fetch or calculate
376
+ # the value.
377
+ sig { params(cache: ::T.untyped).returns(Integer) }
378
+ def cached_end_code_units_column(cache); end
379
+
380
+ # Implement the hash pattern matching interface for Location.
381
+ sig { params(keys: ::T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, ::T.untyped]) }
382
+ def deconstruct_keys(keys); end
383
+
384
+ # Implement the pretty print interface for Location.
385
+ sig { params(q: PP).void }
386
+ def pretty_print(q); end
387
+
388
+ # Returns true if the given other location is equal to this location.
389
+ sig { params(other: ::T.untyped).returns(T::Boolean) }
390
+ def ==(other); end
391
+
392
+ # Returns a new location that stretches from this location to the given
393
+ # other location. Raises an error if this location is not before the other
394
+ # location or if they don't share the same source.
395
+ sig { params(other: Location).returns(Location) }
396
+ def join(other); end
397
+
398
+ # Join this location with the first occurrence of the string in the source
399
+ # that occurs after this location on the same line, and return the new
400
+ # location. This will raise an error if the string does not exist.
401
+ sig { params(string: String).returns(Location) }
402
+ def adjoin(string); end
403
+ end
404
+
405
+ # This represents a comment that was encountered during parsing. It is the
406
+ # base class for all comment types.
407
+ class Comment
408
+ # The Location of this comment in the source.
409
+ sig { returns(Location) }
410
+ attr_reader :location
411
+
412
+ # Create a new comment object with the given location.
413
+ sig { params(location: Location).void }
414
+ def initialize(location); end
415
+
416
+ # Implement the hash pattern matching interface for Comment.
417
+ sig { params(keys: ::T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, ::T.untyped]) }
418
+ def deconstruct_keys(keys); end
419
+
420
+ # Returns the content of the comment by slicing it from the source code.
421
+ sig { returns(String) }
422
+ def slice; end
423
+
424
+ # Returns true if this comment happens on the same line as other code and
425
+ # false if the comment is by itself. This can only be true for inline
426
+ # comments and should be false for block comments.
427
+ sig { returns(T::Boolean) }
428
+ def trailing?; end
429
+ end
430
+
431
+ # InlineComment objects are the most common. They correspond to comments in
432
+ # the source file like this one that start with #.
433
+ class InlineComment < Comment
434
+ # Returns true if this comment happens on the same line as other code and
435
+ # false if the comment is by itself.
436
+ sig { returns(T::Boolean) }
437
+ def trailing?; end
438
+
439
+ # Returns a string representation of this comment.
440
+ sig { returns(String) }
441
+ def inspect; end
442
+ end
443
+
444
+ # EmbDocComment objects correspond to comments that are surrounded by =begin
445
+ # and =end.
446
+ class EmbDocComment < Comment
447
+ # Returns false. This can only be true for inline comments.
448
+ sig { returns(T::Boolean) }
449
+ def trailing?; end
450
+
451
+ # Returns a string representation of this comment.
452
+ sig { returns(String) }
453
+ def inspect; end
454
+ end
455
+
456
+ # This represents a magic comment that was encountered during parsing.
457
+ class MagicComment
458
+ # A Location object representing the location of the key in the source.
459
+ sig { returns(Location) }
460
+ attr_reader :key_loc
461
+
462
+ # A Location object representing the location of the value in the source.
463
+ sig { returns(Location) }
464
+ attr_reader :value_loc
465
+
466
+ # Create a new magic comment object with the given key and value locations.
467
+ sig { params(key_loc: Location, value_loc: Location).void }
468
+ def initialize(key_loc, value_loc); end
469
+
470
+ # Returns the key of the magic comment by slicing it from the source code.
471
+ sig { returns(String) }
472
+ def key; end
473
+
474
+ # Returns the value of the magic comment by slicing it from the source code.
475
+ sig { returns(String) }
476
+ def value; end
477
+
478
+ # Implement the hash pattern matching interface for MagicComment.
479
+ sig { params(keys: ::T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, ::T.untyped]) }
480
+ def deconstruct_keys(keys); end
481
+
482
+ # Returns a string representation of this magic comment.
483
+ sig { returns(String) }
484
+ def inspect; end
485
+ end
486
+
487
+ # This represents an error that was encountered during parsing.
488
+ class ParseError
489
+ # The type of error. This is an _internal_ symbol that is used for
490
+ # communicating with translation layers. It is not meant to be public API.
491
+ sig { returns(Symbol) }
492
+ attr_reader :type
493
+
494
+ # The message associated with this error.
495
+ sig { returns(String) }
496
+ attr_reader :message
497
+
498
+ # A Location object representing the location of this error in the source.
499
+ sig { returns(Location) }
500
+ attr_reader :location
501
+
502
+ # The level of this error.
503
+ sig { returns(Symbol) }
504
+ attr_reader :level
505
+
506
+ # Create a new error object with the given message and location.
507
+ sig { params(type: Symbol, message: String, location: Location, level: Symbol).void }
508
+ def initialize(type, message, location, level); end
509
+
510
+ # Implement the hash pattern matching interface for ParseError.
511
+ sig { params(keys: ::T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, ::T.untyped]) }
512
+ def deconstruct_keys(keys); end
513
+
514
+ # Returns a string representation of this error.
515
+ sig { returns(String) }
516
+ def inspect; end
517
+ end
518
+
519
+ # This represents a warning that was encountered during parsing.
520
+ class ParseWarning
521
+ # The type of warning. This is an _internal_ symbol that is used for
522
+ # communicating with translation layers. It is not meant to be public API.
523
+ sig { returns(Symbol) }
524
+ attr_reader :type
525
+
526
+ # The message associated with this warning.
527
+ sig { returns(String) }
528
+ attr_reader :message
529
+
530
+ # A Location object representing the location of this warning in the source.
531
+ sig { returns(Location) }
532
+ attr_reader :location
533
+
534
+ # The level of this warning.
535
+ sig { returns(Symbol) }
536
+ attr_reader :level
537
+
538
+ # Create a new warning object with the given message and location.
539
+ sig { params(type: Symbol, message: String, location: Location, level: Symbol).void }
540
+ def initialize(type, message, location, level); end
541
+
542
+ # Implement the hash pattern matching interface for ParseWarning.
543
+ sig { params(keys: ::T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, ::T.untyped]) }
544
+ def deconstruct_keys(keys); end
545
+
546
+ # Returns a string representation of this warning.
547
+ sig { returns(String) }
548
+ def inspect; end
549
+ end
550
+
551
+ # This represents the result of a call to Prism.parse or Prism.parse_file.
552
+ # It contains the requested structure, any comments that were encounters,
553
+ # and any errors that were encountered.
554
+ class Result
555
+ # The list of magic comments that were encountered during parsing.
556
+ sig { returns(T::Array[MagicComment]) }
557
+ attr_reader :magic_comments
558
+
559
+ # An optional location that represents the location of the __END__ marker
560
+ # and the rest of the content of the file. This content is loaded into the
561
+ # DATA constant when the file being parsed is the main file being executed.
562
+ sig { returns(::T.nilable(Location)) }
563
+ attr_reader :data_loc
564
+
565
+ # The list of errors that were generated during parsing.
566
+ sig { returns(T::Array[ParseError]) }
567
+ attr_reader :errors
568
+
569
+ # The list of warnings that were generated during parsing.
570
+ sig { returns(T::Array[ParseWarning]) }
571
+ attr_reader :warnings
572
+
573
+ # A Source instance that represents the source code that was parsed.
574
+ sig { returns(Source) }
575
+ attr_reader :source
576
+
577
+ # Create a new result object with the given values.
578
+ sig { params(magic_comments: T::Array[MagicComment], data_loc: ::T.nilable(Location), errors: T::Array[ParseError], warnings: T::Array[ParseWarning], continuable: T::Boolean, source: Source).void }
579
+ def initialize(magic_comments, data_loc, errors, warnings, continuable, source); end
580
+
581
+ # The list of comments that were encountered during parsing.
582
+ sig { returns(T::Array[Comment]) }
583
+ def comments; end
584
+
585
+ # Implement the hash pattern matching interface for Result.
586
+ sig { params(keys: ::T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, ::T.untyped]) }
587
+ def deconstruct_keys(keys); end
588
+
589
+ # Returns the encoding of the source code that was parsed.
590
+ sig { returns(Encoding) }
591
+ def encoding; end
592
+
593
+ # Returns true if there were no errors during parsing and false if there
594
+ # were.
595
+ sig { returns(T::Boolean) }
596
+ def success?; end
597
+
598
+ # Returns true if there were errors during parsing and false if there were
599
+ # not.
600
+ sig { returns(T::Boolean) }
601
+ def failure?; end
602
+
603
+ # Returns true if the parsed source is an incomplete expression that could
604
+ # become valid with additional input. This is useful for REPL contexts (such
605
+ # as IRB) where the user may be entering a multi-line expression one line at
606
+ # a time and the implementation needs to determine whether to wait for more
607
+ # input or to evaluate what has been entered so far.
608
+ #
609
+ # Concretely, this returns true when every error present is caused by the
610
+ # parser reaching the end of the input before a construct was closed (e.g.
611
+ # an unclosed string, array, block, or keyword), and returns false when any
612
+ # error is caused by a token that makes the input structurally invalid
613
+ # regardless of what might follow (e.g. a stray `end`, `]`, or `)` with no
614
+ # matching opener).
615
+ #
616
+ # Examples:
617
+ #
618
+ # Prism.parse("1 + [").continuable? #=> true (unclosed array)
619
+ # Prism.parse("1 + ]").continuable? #=> false (stray ])
620
+ # Prism.parse("tap do").continuable? #=> true (unclosed block)
621
+ # Prism.parse("end.tap do").continuable? #=> false (stray end)
622
+ sig { returns(T::Boolean) }
623
+ def continuable?; end
624
+
625
+ # Create a code units cache for the given encoding.
626
+ sig { params(encoding: Encoding).returns(::T.untyped) }
627
+ def code_units_cache(encoding); end
628
+ end
629
+
630
+ # This is a result specific to the `parse` and `parse_file` methods.
631
+ class ParseResult < Result
632
+ # The syntax tree that was parsed from the source code.
633
+ sig { returns(ProgramNode) }
634
+ attr_reader :value
635
+
636
+ # Create a new parse result object with the given values.
637
+ sig { params(value: ProgramNode, magic_comments: T::Array[MagicComment], data_loc: ::T.nilable(Location), errors: T::Array[ParseError], warnings: T::Array[ParseWarning], continuable: T::Boolean, source: Source).void }
638
+ def initialize(value, magic_comments, data_loc, errors, warnings, continuable, source); end
639
+
640
+ # Implement the hash pattern matching interface for ParseResult.
641
+ sig { params(keys: ::T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, ::T.untyped]) }
642
+ def deconstruct_keys(keys); end
643
+
644
+ # Walk the tree and mark nodes that are on a new line, loosely emulating
645
+ # the behavior of CRuby's `:line` tracepoint event.
646
+ sig { void }
647
+ def mark_newlines!; end
648
+
649
+ # Returns a string representation of the syntax tree with the errors
650
+ # displayed inline.
651
+ sig { returns(String) }
652
+ def errors_format; end
653
+ end
654
+
655
+ # This is a result specific to the `lex` and `lex_file` methods.
656
+ class LexResult < Result
657
+ # The list of tokens that were parsed from the source code.
658
+ sig { returns(T::Array[Token]) }
659
+ attr_reader :value
660
+
661
+ # Create a new lex result object with the given values.
662
+ sig { params(value: T::Array[Token], magic_comments: T::Array[MagicComment], data_loc: ::T.nilable(Location), errors: T::Array[ParseError], warnings: T::Array[ParseWarning], continuable: T::Boolean, source: Source).void }
663
+ def initialize(value, magic_comments, data_loc, errors, warnings, continuable, source); end
664
+
665
+ # Implement the hash pattern matching interface for LexResult.
666
+ sig { params(keys: ::T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, ::T.untyped]) }
667
+ def deconstruct_keys(keys); end
668
+ end
669
+
670
+ # This is a result specific to the `parse_lex` and `parse_lex_file` methods.
671
+ class ParseLexResult < Result
672
+ # A tuple of the syntax tree and the list of tokens that were parsed from
673
+ # the source code.
674
+ sig { returns([ProgramNode, T::Array[Token]]) }
675
+ attr_reader :value
676
+
677
+ # Create a new parse lex result object with the given values.
678
+ sig { params(value: [ProgramNode, T::Array[Token]], magic_comments: T::Array[MagicComment], data_loc: ::T.nilable(Location), errors: T::Array[ParseError], warnings: T::Array[ParseWarning], continuable: T::Boolean, source: Source).void }
679
+ def initialize(value, magic_comments, data_loc, errors, warnings, continuable, source); end
680
+
681
+ # Implement the hash pattern matching interface for ParseLexResult.
682
+ sig { params(keys: ::T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, ::T.untyped]) }
683
+ def deconstruct_keys(keys); end
684
+ end
685
+
686
+ # This represents a token from the Ruby source.
687
+ class Token
688
+ # The Source object that represents the source this token came from.
689
+ sig { returns(Source) }
690
+ attr_reader :source
691
+
692
+ # The type of token that this token is.
693
+ sig { returns(Symbol) }
694
+ attr_reader :type
695
+
696
+ # A byteslice of the source that this token represents.
697
+ sig { returns(String) }
698
+ attr_reader :value
699
+
700
+ # Create a new token object with the given type, value, and location.
701
+ sig { params(source: Source, type: Symbol, value: String, location: ::T.any(Location, Integer), state: Integer).void }
702
+ def initialize(source, type, value, location, state); end
703
+
704
+ # Implement the hash pattern matching interface for Token.
705
+ sig { params(keys: ::T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, ::T.untyped]) }
706
+ def deconstruct_keys(keys); end
707
+
708
+ # A Location object representing the location of this token in the source.
709
+ sig { returns(Location) }
710
+ def location; end
711
+
712
+ # Implement the pretty print interface for Token.
713
+ sig { params(q: PP).void }
714
+ def pretty_print(q); end
715
+
716
+ # Returns true if the given other token is equal to this token.
717
+ sig { params(other: ::T.untyped).returns(T::Boolean) }
718
+ def ==(other); end
719
+
720
+ # Returns a string representation of this token.
721
+ sig { returns(String) }
722
+ def inspect; end
723
+
724
+ # Freeze this object and the objects it contains.
725
+ sig { void }
726
+ def deep_freeze; end
727
+
728
+ # For internal use only.
729
+ sig { returns(Integer) }
730
+ def _ripper_state; end
731
+
732
+ sig { params(index: Integer).returns(Token) }
733
+ def [](index); end
734
+
735
+ sig { returns(Token) }
736
+ def first; end
737
+ end
738
+
739
+ # This object is passed to the various Prism.* methods that accept the
740
+ # `scopes` option as an element of the list. It defines both the local
741
+ # variables visible at that scope as well as the forwarding parameters
742
+ # available at that scope.
743
+ class Scope
744
+ # The list of local variables that are defined in this scope. This should be
745
+ # defined as an array of symbols.
746
+ sig { returns(T::Array[Symbol]) }
747
+ attr_reader :locals
748
+
749
+ # The list of local variables that are forwarded to the next scope. This
750
+ # should by defined as an array of symbols containing the specific values of
751
+ sig { returns(T::Array[Symbol]) }
752
+ attr_reader :forwarding
753
+
754
+ # Create a new scope object with the given locals and forwarding.
755
+ sig { params(locals: T::Array[Symbol], forwarding: T::Array[Symbol]).void }
756
+ def initialize(locals, forwarding); end
757
+ end
758
+
759
+ # Create a new scope with the given locals and forwarding options that is
760
+ # suitable for passing into one of the Prism.* methods that accepts the
761
+ # `scopes` option.
762
+ sig { params(locals: T::Array[Symbol], forwarding: T::Array[Symbol]).returns(Scope) }
763
+ def self.scope(locals: T.unsafe(nil), forwarding: T.unsafe(nil)); end
764
+ end