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