ed-precompiled_prism 1.5.2-arm64-darwin

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 (159) hide show
  1. checksums.yaml +7 -0
  2. data/BSDmakefile +58 -0
  3. data/CHANGELOG.md +723 -0
  4. data/CODE_OF_CONDUCT.md +76 -0
  5. data/CONTRIBUTING.md +58 -0
  6. data/LICENSE.md +7 -0
  7. data/Makefile +110 -0
  8. data/README.md +143 -0
  9. data/config.yml +4714 -0
  10. data/docs/build_system.md +119 -0
  11. data/docs/configuration.md +68 -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 +88 -0
  16. data/docs/heredocs.md +36 -0
  17. data/docs/javascript.md +118 -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 +98 -0
  23. data/docs/relocation.md +34 -0
  24. data/docs/ripper_translation.md +72 -0
  25. data/docs/ruby_api.md +44 -0
  26. data/docs/ruby_parser_translation.md +19 -0
  27. data/docs/serialization.md +233 -0
  28. data/docs/testing.md +55 -0
  29. data/ext/prism/api_node.c +6941 -0
  30. data/ext/prism/api_pack.c +276 -0
  31. data/ext/prism/extconf.rb +127 -0
  32. data/ext/prism/extension.c +1419 -0
  33. data/ext/prism/extension.h +19 -0
  34. data/include/prism/ast.h +8220 -0
  35. data/include/prism/defines.h +260 -0
  36. data/include/prism/diagnostic.h +456 -0
  37. data/include/prism/encoding.h +283 -0
  38. data/include/prism/node.h +129 -0
  39. data/include/prism/options.h +482 -0
  40. data/include/prism/pack.h +163 -0
  41. data/include/prism/parser.h +933 -0
  42. data/include/prism/prettyprint.h +34 -0
  43. data/include/prism/regexp.h +43 -0
  44. data/include/prism/static_literals.h +121 -0
  45. data/include/prism/util/pm_buffer.h +236 -0
  46. data/include/prism/util/pm_char.h +204 -0
  47. data/include/prism/util/pm_constant_pool.h +218 -0
  48. data/include/prism/util/pm_integer.h +130 -0
  49. data/include/prism/util/pm_list.h +103 -0
  50. data/include/prism/util/pm_memchr.h +29 -0
  51. data/include/prism/util/pm_newline_list.h +113 -0
  52. data/include/prism/util/pm_string.h +200 -0
  53. data/include/prism/util/pm_strncasecmp.h +32 -0
  54. data/include/prism/util/pm_strpbrk.h +46 -0
  55. data/include/prism/version.h +29 -0
  56. data/include/prism.h +408 -0
  57. data/lib/prism/3.0/prism.bundle +0 -0
  58. data/lib/prism/3.1/prism.bundle +0 -0
  59. data/lib/prism/3.2/prism.bundle +0 -0
  60. data/lib/prism/3.3/prism.bundle +0 -0
  61. data/lib/prism/3.4/prism.bundle +0 -0
  62. data/lib/prism/compiler.rb +801 -0
  63. data/lib/prism/desugar_compiler.rb +392 -0
  64. data/lib/prism/dispatcher.rb +2210 -0
  65. data/lib/prism/dot_visitor.rb +4762 -0
  66. data/lib/prism/dsl.rb +1003 -0
  67. data/lib/prism/ffi.rb +570 -0
  68. data/lib/prism/inspect_visitor.rb +2392 -0
  69. data/lib/prism/lex_compat.rb +928 -0
  70. data/lib/prism/mutation_compiler.rb +772 -0
  71. data/lib/prism/node.rb +18816 -0
  72. data/lib/prism/node_ext.rb +511 -0
  73. data/lib/prism/pack.rb +230 -0
  74. data/lib/prism/parse_result/comments.rb +188 -0
  75. data/lib/prism/parse_result/errors.rb +66 -0
  76. data/lib/prism/parse_result/newlines.rb +155 -0
  77. data/lib/prism/parse_result.rb +911 -0
  78. data/lib/prism/pattern.rb +269 -0
  79. data/lib/prism/polyfill/append_as_bytes.rb +15 -0
  80. data/lib/prism/polyfill/byteindex.rb +13 -0
  81. data/lib/prism/polyfill/scan_byte.rb +14 -0
  82. data/lib/prism/polyfill/unpack1.rb +14 -0
  83. data/lib/prism/polyfill/warn.rb +36 -0
  84. data/lib/prism/reflection.rb +416 -0
  85. data/lib/prism/relocation.rb +505 -0
  86. data/lib/prism/serialize.rb +2398 -0
  87. data/lib/prism/string_query.rb +31 -0
  88. data/lib/prism/translation/parser/builder.rb +62 -0
  89. data/lib/prism/translation/parser/compiler.rb +2234 -0
  90. data/lib/prism/translation/parser/lexer.rb +820 -0
  91. data/lib/prism/translation/parser.rb +374 -0
  92. data/lib/prism/translation/parser33.rb +13 -0
  93. data/lib/prism/translation/parser34.rb +13 -0
  94. data/lib/prism/translation/parser35.rb +13 -0
  95. data/lib/prism/translation/parser_current.rb +24 -0
  96. data/lib/prism/translation/ripper/sexp.rb +126 -0
  97. data/lib/prism/translation/ripper/shim.rb +5 -0
  98. data/lib/prism/translation/ripper.rb +3474 -0
  99. data/lib/prism/translation/ruby_parser.rb +1929 -0
  100. data/lib/prism/translation.rb +16 -0
  101. data/lib/prism/visitor.rb +813 -0
  102. data/lib/prism.rb +97 -0
  103. data/prism.gemspec +174 -0
  104. data/rbi/prism/compiler.rbi +12 -0
  105. data/rbi/prism/dsl.rbi +524 -0
  106. data/rbi/prism/inspect_visitor.rbi +12 -0
  107. data/rbi/prism/node.rbi +8734 -0
  108. data/rbi/prism/node_ext.rbi +107 -0
  109. data/rbi/prism/parse_result.rbi +404 -0
  110. data/rbi/prism/reflection.rbi +58 -0
  111. data/rbi/prism/string_query.rbi +12 -0
  112. data/rbi/prism/translation/parser.rbi +11 -0
  113. data/rbi/prism/translation/parser33.rbi +6 -0
  114. data/rbi/prism/translation/parser34.rbi +6 -0
  115. data/rbi/prism/translation/parser35.rbi +6 -0
  116. data/rbi/prism/translation/ripper.rbi +15 -0
  117. data/rbi/prism/visitor.rbi +473 -0
  118. data/rbi/prism.rbi +66 -0
  119. data/sig/prism/compiler.rbs +9 -0
  120. data/sig/prism/dispatcher.rbs +19 -0
  121. data/sig/prism/dot_visitor.rbs +6 -0
  122. data/sig/prism/dsl.rbs +351 -0
  123. data/sig/prism/inspect_visitor.rbs +22 -0
  124. data/sig/prism/lex_compat.rbs +10 -0
  125. data/sig/prism/mutation_compiler.rbs +159 -0
  126. data/sig/prism/node.rbs +4028 -0
  127. data/sig/prism/node_ext.rbs +149 -0
  128. data/sig/prism/pack.rbs +43 -0
  129. data/sig/prism/parse_result/comments.rbs +38 -0
  130. data/sig/prism/parse_result.rbs +196 -0
  131. data/sig/prism/pattern.rbs +13 -0
  132. data/sig/prism/reflection.rbs +50 -0
  133. data/sig/prism/relocation.rbs +185 -0
  134. data/sig/prism/serialize.rbs +8 -0
  135. data/sig/prism/string_query.rbs +11 -0
  136. data/sig/prism/visitor.rbs +169 -0
  137. data/sig/prism.rbs +254 -0
  138. data/src/diagnostic.c +850 -0
  139. data/src/encoding.c +5235 -0
  140. data/src/node.c +8676 -0
  141. data/src/options.c +328 -0
  142. data/src/pack.c +509 -0
  143. data/src/prettyprint.c +8941 -0
  144. data/src/prism.c +23361 -0
  145. data/src/regexp.c +790 -0
  146. data/src/serialize.c +2268 -0
  147. data/src/static_literals.c +617 -0
  148. data/src/token_type.c +703 -0
  149. data/src/util/pm_buffer.c +357 -0
  150. data/src/util/pm_char.c +318 -0
  151. data/src/util/pm_constant_pool.c +342 -0
  152. data/src/util/pm_integer.c +670 -0
  153. data/src/util/pm_list.c +49 -0
  154. data/src/util/pm_memchr.c +35 -0
  155. data/src/util/pm_newline_list.c +125 -0
  156. data/src/util/pm_string.c +381 -0
  157. data/src/util/pm_strncasecmp.c +36 -0
  158. data/src/util/pm_strpbrk.c +206 -0
  159. metadata +202 -0
@@ -0,0 +1,269 @@
1
+ # frozen_string_literal: true
2
+ # :markup: markdown
3
+
4
+ module Prism
5
+ # A pattern is an object that wraps a Ruby pattern matching expression. The
6
+ # expression would normally be passed to an `in` clause within a `case`
7
+ # expression or a rightward assignment expression. For example, in the
8
+ # following snippet:
9
+ #
10
+ # case node
11
+ # in ConstantPathNode[ConstantReadNode[name: :Prism], ConstantReadNode[name: :Pattern]]
12
+ # end
13
+ #
14
+ # the pattern is the <tt>ConstantPathNode[...]</tt> expression.
15
+ #
16
+ # The pattern gets compiled into an object that responds to #call by running
17
+ # the #compile method. This method itself will run back through Prism to
18
+ # parse the expression into a tree, then walk the tree to generate the
19
+ # necessary callable objects. For example, if you wanted to compile the
20
+ # expression above into a callable, you would:
21
+ #
22
+ # callable = Prism::Pattern.new("ConstantPathNode[ConstantReadNode[name: :Prism], ConstantReadNode[name: :Pattern]]").compile
23
+ # callable.call(node)
24
+ #
25
+ # The callable object returned by #compile is guaranteed to respond to #call
26
+ # with a single argument, which is the node to match against. It also is
27
+ # guaranteed to respond to #===, which means it itself can be used in a `case`
28
+ # expression, as in:
29
+ #
30
+ # case node
31
+ # when callable
32
+ # end
33
+ #
34
+ # If the query given to the initializer cannot be compiled into a valid
35
+ # matcher (either because of a syntax error or because it is using syntax we
36
+ # do not yet support) then a Prism::Pattern::CompilationError will be
37
+ # raised.
38
+ class Pattern
39
+ # Raised when the query given to a pattern is either invalid Ruby syntax or
40
+ # is using syntax that we don't yet support.
41
+ class CompilationError < StandardError
42
+ # Create a new CompilationError with the given representation of the node
43
+ # that caused the error.
44
+ def initialize(repr)
45
+ super(<<~ERROR)
46
+ prism was unable to compile the pattern you provided into a usable
47
+ expression. It failed on to understand the node represented by:
48
+
49
+ #{repr}
50
+
51
+ Note that not all syntax supported by Ruby's pattern matching syntax
52
+ is also supported by prism's patterns. If you're using some syntax
53
+ that you believe should be supported, please open an issue on
54
+ GitHub at https://github.com/ruby/prism/issues/new.
55
+ ERROR
56
+ end
57
+ end
58
+
59
+ # The query that this pattern was initialized with.
60
+ attr_reader :query
61
+
62
+ # Create a new pattern with the given query. The query should be a string
63
+ # containing a Ruby pattern matching expression.
64
+ def initialize(query)
65
+ @query = query
66
+ @compiled = nil
67
+ end
68
+
69
+ # Compile the query into a callable object that can be used to match against
70
+ # nodes.
71
+ def compile
72
+ result = Prism.parse("case nil\nin #{query}\nend")
73
+
74
+ case_match_node = result.value.statements.body.last
75
+ raise CompilationError, case_match_node.inspect unless case_match_node.is_a?(CaseMatchNode)
76
+
77
+ in_node = case_match_node.conditions.last
78
+ raise CompilationError, in_node.inspect unless in_node.is_a?(InNode)
79
+
80
+ compile_node(in_node.pattern)
81
+ end
82
+
83
+ # Scan the given node and all of its children for nodes that match the
84
+ # pattern. If a block is given, it will be called with each node that
85
+ # matches the pattern. If no block is given, an enumerator will be returned
86
+ # that will yield each node that matches the pattern.
87
+ def scan(root)
88
+ return to_enum(:scan, root) unless block_given?
89
+
90
+ @compiled ||= compile
91
+ queue = [root]
92
+
93
+ while (node = queue.shift)
94
+ yield node if @compiled.call(node) # steep:ignore
95
+ queue.concat(node.compact_child_nodes)
96
+ end
97
+ end
98
+
99
+ private
100
+
101
+ # Shortcut for combining two procs into one that returns true if both return
102
+ # true.
103
+ def combine_and(left, right)
104
+ ->(other) { left.call(other) && right.call(other) }
105
+ end
106
+
107
+ # Shortcut for combining two procs into one that returns true if either
108
+ # returns true.
109
+ def combine_or(left, right)
110
+ ->(other) { left.call(other) || right.call(other) }
111
+ end
112
+
113
+ # Raise an error because the given node is not supported.
114
+ def compile_error(node)
115
+ raise CompilationError, node.inspect
116
+ end
117
+
118
+ # in [foo, bar, baz]
119
+ def compile_array_pattern_node(node)
120
+ compile_error(node) if !node.rest.nil? || node.posts.any?
121
+
122
+ constant = node.constant
123
+ compiled_constant = compile_node(constant) if constant
124
+
125
+ preprocessed = node.requireds.map { |required| compile_node(required) }
126
+
127
+ compiled_requireds = ->(other) do
128
+ deconstructed = other.deconstruct
129
+
130
+ deconstructed.length == preprocessed.length &&
131
+ preprocessed
132
+ .zip(deconstructed)
133
+ .all? { |(matcher, value)| matcher.call(value) }
134
+ end
135
+
136
+ if compiled_constant
137
+ combine_and(compiled_constant, compiled_requireds)
138
+ else
139
+ compiled_requireds
140
+ end
141
+ end
142
+
143
+ # in foo | bar
144
+ def compile_alternation_pattern_node(node)
145
+ combine_or(compile_node(node.left), compile_node(node.right))
146
+ end
147
+
148
+ # in Prism::ConstantReadNode
149
+ def compile_constant_path_node(node)
150
+ parent = node.parent
151
+
152
+ if parent.is_a?(ConstantReadNode) && parent.slice == "Prism"
153
+ name = node.name
154
+ raise CompilationError, node.inspect if name.nil?
155
+
156
+ compile_constant_name(node, name)
157
+ else
158
+ compile_error(node)
159
+ end
160
+ end
161
+
162
+ # in ConstantReadNode
163
+ # in String
164
+ def compile_constant_read_node(node)
165
+ compile_constant_name(node, node.name)
166
+ end
167
+
168
+ # Compile a name associated with a constant.
169
+ def compile_constant_name(node, name)
170
+ if Prism.const_defined?(name, false)
171
+ clazz = Prism.const_get(name)
172
+
173
+ ->(other) { clazz === other }
174
+ elsif Object.const_defined?(name, false)
175
+ clazz = Object.const_get(name)
176
+
177
+ ->(other) { clazz === other }
178
+ else
179
+ compile_error(node)
180
+ end
181
+ end
182
+
183
+ # in InstanceVariableReadNode[name: Symbol]
184
+ # in { name: Symbol }
185
+ def compile_hash_pattern_node(node)
186
+ compile_error(node) if node.rest
187
+ compiled_constant = compile_node(node.constant) if node.constant
188
+
189
+ preprocessed =
190
+ node.elements.to_h do |element|
191
+ key = element.key
192
+ if key.is_a?(SymbolNode)
193
+ [key.unescaped.to_sym, compile_node(element.value)]
194
+ else
195
+ raise CompilationError, element.inspect
196
+ end
197
+ end
198
+
199
+ compiled_keywords = ->(other) do
200
+ deconstructed = other.deconstruct_keys(preprocessed.keys)
201
+
202
+ preprocessed.all? do |keyword, matcher|
203
+ deconstructed.key?(keyword) && matcher.call(deconstructed[keyword])
204
+ end
205
+ end
206
+
207
+ if compiled_constant
208
+ combine_and(compiled_constant, compiled_keywords)
209
+ else
210
+ compiled_keywords
211
+ end
212
+ end
213
+
214
+ # in nil
215
+ def compile_nil_node(node)
216
+ ->(attribute) { attribute.nil? }
217
+ end
218
+
219
+ # in /foo/
220
+ def compile_regular_expression_node(node)
221
+ regexp = Regexp.new(node.unescaped, node.closing[1..])
222
+
223
+ ->(attribute) { regexp === attribute }
224
+ end
225
+
226
+ # in ""
227
+ # in "foo"
228
+ def compile_string_node(node)
229
+ string = node.unescaped
230
+
231
+ ->(attribute) { string === attribute }
232
+ end
233
+
234
+ # in :+
235
+ # in :foo
236
+ def compile_symbol_node(node)
237
+ symbol = node.unescaped.to_sym
238
+
239
+ ->(attribute) { symbol === attribute }
240
+ end
241
+
242
+ # Compile any kind of node. Dispatch out to the individual compilation
243
+ # methods based on the type of node.
244
+ def compile_node(node)
245
+ case node
246
+ when AlternationPatternNode
247
+ compile_alternation_pattern_node(node)
248
+ when ArrayPatternNode
249
+ compile_array_pattern_node(node)
250
+ when ConstantPathNode
251
+ compile_constant_path_node(node)
252
+ when ConstantReadNode
253
+ compile_constant_read_node(node)
254
+ when HashPatternNode
255
+ compile_hash_pattern_node(node)
256
+ when NilNode
257
+ compile_nil_node(node)
258
+ when RegularExpressionNode
259
+ compile_regular_expression_node(node)
260
+ when StringNode
261
+ compile_string_node(node)
262
+ when SymbolNode
263
+ compile_symbol_node(node)
264
+ else
265
+ compile_error(node)
266
+ end
267
+ end
268
+ end
269
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Polyfill for String#append_as_bytes, which didn't exist until Ruby 3.4.
4
+ if !("".respond_to?(:append_as_bytes))
5
+ String.include(
6
+ Module.new {
7
+ def append_as_bytes(*args)
8
+ args.each do |arg|
9
+ arg = Integer === arg ? [arg].pack("C") : arg.b
10
+ self.<<(arg) # steep:ignore
11
+ end
12
+ end
13
+ }
14
+ )
15
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Polyfill for String#byteindex, which didn't exist until Ruby 3.2.
4
+ if !("".respond_to?(:byteindex))
5
+ String.include(
6
+ Module.new {
7
+ def byteindex(needle, offset = 0)
8
+ charindex = index(needle, offset)
9
+ slice(0...charindex).bytesize if charindex
10
+ end
11
+ }
12
+ )
13
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "strscan"
4
+
5
+ # Polyfill for StringScanner#scan_byte, which didn't exist until Ruby 3.4.
6
+ if !(StringScanner.instance_methods.include?(:scan_byte))
7
+ StringScanner.include(
8
+ Module.new {
9
+ def scan_byte # :nodoc:
10
+ get_byte&.b&.ord
11
+ end
12
+ }
13
+ )
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Polyfill for String#unpack1 with the offset parameter. Not all Ruby engines
4
+ # have Method#parameters implemented, so we check the arity instead if
5
+ # necessary.
6
+ if (unpack1 = String.instance_method(:unpack1)).respond_to?(:parameters) ? unpack1.parameters.none? { |_, name| name == :offset } : (unpack1.arity == 1)
7
+ String.prepend(
8
+ Module.new {
9
+ def unpack1(format, offset: 0) # :nodoc:
10
+ offset == 0 ? super(format) : self[offset..].unpack1(format) # steep:ignore
11
+ end
12
+ }
13
+ )
14
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Polyfill for Kernel#warn with the category parameter. Not all Ruby engines
4
+ # have Method#parameters implemented, so we check the arity instead if
5
+ # necessary.
6
+ if (method = Kernel.instance_method(:warn)).respond_to?(:parameters) ? method.parameters.none? { |_, name| name == :category } : (method.arity == -1)
7
+ Kernel.prepend(
8
+ Module.new {
9
+ def warn(*msgs, uplevel: nil, category: nil) # :nodoc:
10
+ case uplevel
11
+ when nil
12
+ super(*msgs)
13
+ when Integer
14
+ super(*msgs, uplevel: uplevel + 1)
15
+ else
16
+ super(*msgs, uplevel: uplevel.to_int + 1)
17
+ end
18
+ end
19
+ }
20
+ )
21
+
22
+ Object.prepend(
23
+ Module.new {
24
+ def warn(*msgs, uplevel: nil, category: nil) # :nodoc:
25
+ case uplevel
26
+ when nil
27
+ super(*msgs)
28
+ when Integer
29
+ super(*msgs, uplevel: uplevel + 1)
30
+ else
31
+ super(*msgs, uplevel: uplevel.to_int + 1)
32
+ end
33
+ end
34
+ }
35
+ )
36
+ end