mootool 0.1.2 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.DS_Store +0 -0
  3. data/.github/workflows/ci.yml +15 -15
  4. data/.github/workflows/gem-push.yml +26 -26
  5. data/.overcommit.yml +79 -0
  6. data/.rubocop.yml +147 -0
  7. data/.ruby-version +1 -1
  8. data/.run/All Specs.run.xml +46 -0
  9. data/CODE_OF_CONDUCT.md +2 -1
  10. data/Gemfile +14 -11
  11. data/Gemfile.lock +90 -32
  12. data/README.md +12 -6
  13. data/bin/tapioca +27 -0
  14. data/lib/mootool/command.rb +1 -0
  15. data/lib/mootool/controller_base.rb +4 -1
  16. data/lib/mootool/controllers/dwarf.rb +8 -0
  17. data/lib/mootool/controllers/dyld_linker.rb +8 -0
  18. data/lib/mootool/controllers/dyld_shared_cache.rb +8 -0
  19. data/lib/mootool/controllers/fat_binary.rb +8 -0
  20. data/lib/mootool/controllers/kernel_collection.rb +21 -15
  21. data/lib/mootool/controllers/sections.rb +8 -0
  22. data/lib/mootool/core_extensions.rb +26 -0
  23. data/lib/mootool/models/device_tree.rb +85 -0
  24. data/lib/mootool/models/img4.rb +49 -0
  25. data/lib/mootool/models/ipsw.rb +19 -0
  26. data/lib/mootool/version.rb +1 -1
  27. data/lib/mootool/views/sections.full.erb +2 -2
  28. data/lib/mootool.rb +10 -3
  29. data/mootool.gemspec +17 -12
  30. data/sorbet/rbi/annotations/rainbow.rbi +269 -0
  31. data/sorbet/rbi/gems/ast@2.4.2.rbi +618 -0
  32. data/sorbet/rbi/gems/childprocess@4.1.0.rbi +447 -0
  33. data/sorbet/rbi/gems/coderay@1.1.3.rbi +8 -0
  34. data/sorbet/rbi/gems/diff-lcs@1.5.0.rbi +1219 -0
  35. data/sorbet/rbi/gems/iniparse@1.5.0.rbi +1007 -0
  36. data/sorbet/rbi/gems/json@2.6.2.rbi +1650 -0
  37. data/sorbet/rbi/gems/method_source@1.0.0.rbi +8 -0
  38. data/sorbet/rbi/gems/netrc@0.11.0.rbi +186 -0
  39. data/sorbet/rbi/gems/overcommit@0.59.1.rbi +2747 -0
  40. data/sorbet/rbi/gems/parallel@1.22.1.rbi +353 -0
  41. data/sorbet/rbi/gems/parser@3.1.2.1.rbi +6198 -0
  42. data/sorbet/rbi/gems/plist@3.6.0.rbi +212 -0
  43. data/sorbet/rbi/gems/pry@0.14.1.rbi +8 -0
  44. data/sorbet/rbi/gems/rainbow@3.1.1.rbi +452 -0
  45. data/sorbet/rbi/gems/rake@13.0.6.rbi +3587 -0
  46. data/sorbet/rbi/gems/rbi@0.0.15.rbi +3619 -0
  47. data/sorbet/rbi/gems/regexp_parser@2.5.0.rbi +3927 -0
  48. data/sorbet/rbi/gems/rexml@3.2.5.rbi +5238 -0
  49. data/sorbet/rbi/gems/rspec-core@3.11.0.rbi +12834 -0
  50. data/sorbet/rbi/gems/rspec-expectations@3.11.0.rbi +9151 -0
  51. data/sorbet/rbi/gems/rspec-mocks@3.11.1.rbi +6506 -0
  52. data/sorbet/rbi/gems/rspec-support@3.11.0.rbi +2040 -0
  53. data/sorbet/rbi/gems/rspec@3.11.0.rbi +120 -0
  54. data/sorbet/rbi/gems/rubocop-ast@1.21.0.rbi +7990 -0
  55. data/sorbet/rbi/gems/rubocop-rake@0.6.0.rbi +413 -0
  56. data/sorbet/rbi/gems/rubocop-rspec@2.12.1.rbi +7604 -0
  57. data/sorbet/rbi/gems/rubocop@1.35.0.rbi +62260 -0
  58. data/sorbet/rbi/gems/ruby-macho@3.0.0.rbi +5039 -0
  59. data/sorbet/rbi/gems/ruby-progressbar@1.11.0.rbi +1445 -0
  60. data/sorbet/rbi/gems/rubyzip@2.3.2.rbi +2868 -0
  61. data/sorbet/rbi/gems/spoom@1.1.12.rbi +2829 -0
  62. data/sorbet/rbi/gems/tapioca@0.9.3.rbi +2151 -0
  63. data/sorbet/rbi/gems/thor@1.2.1.rbi +4532 -0
  64. data/sorbet/rbi/gems/unicode-display_width@2.2.0.rbi +60 -0
  65. data/sorbet/rbi/gems/unparser@0.6.5.rbi +8 -0
  66. data/sorbet/rbi/gems/webrick@1.7.0.rbi +3075 -0
  67. data/sorbet/rbi/gems/yard-sorbet@0.6.1.rbi +458 -0
  68. data/sorbet/rbi/gems/yard@0.9.28.rbi +20844 -0
  69. data/sorbet/rbi/sorbet-typed/lib/rainbow/all/rainbow.rbi +72 -24
  70. data/sorbet/rbi/sorbet-typed/lib/rake/all/rake.rbi +1697 -385
  71. data/sorbet/rbi/sorbet-typed/lib/rspec-core/all/rspec-core.rbi +30 -7
  72. data/sorbet/rbi/sorbet-typed/lib/rubocop/>=1.8/rubocop.rbi +3 -1
  73. data/sorbet/rbi/todo.rbi +7 -0
  74. data/sorbet/tapioca/config.yml +13 -0
  75. data/sorbet/tapioca/require.rb +4 -0
  76. metadata +90 -10
@@ -0,0 +1,618 @@
1
+ # typed: true
2
+
3
+ # DO NOT EDIT MANUALLY
4
+ # This is an autogenerated file for types exported from the `ast` gem.
5
+ # Please instead update this file by running `bin/tapioca gem ast`.
6
+
7
+ # {AST} is a library for manipulating abstract syntax trees.
8
+ #
9
+ # It embraces immutability; each AST node is inherently frozen at
10
+ # creation, and updating a child node requires recreating that node
11
+ # and its every parent, recursively.
12
+ # This is a design choice. It does create some pressure on
13
+ # garbage collector, but completely eliminates all concurrency
14
+ # and aliasing problems.
15
+ #
16
+ # See also {AST::Node}, {AST::Processor::Mixin} and {AST::Sexp} for
17
+ # additional recommendations and design patterns.
18
+ #
19
+ # source://ast-2.4.2/lib/ast.rb:13
20
+ module AST
21
+ ;
22
+ end
23
+
24
+ # Node is an immutable class, instances of which represent abstract
25
+ # syntax tree nodes. It combines semantic information (i.e. anything
26
+ # that affects the algorithmic properties of a program) with
27
+ # meta-information (line numbers or compiler intermediates).
28
+ #
29
+ # Notes on inheritance
30
+ # ====================
31
+ #
32
+ # The distinction between semantics and metadata is important. Complete
33
+ # semantic information should be contained within just the {#type} and
34
+ # {#children} of a Node instance; in other words, if an AST was to be
35
+ # stripped of all meta-information, it should remain a valid AST which
36
+ # could be successfully processed to yield a result with the same
37
+ # algorithmic properties.
38
+ #
39
+ # Thus, Node should never be inherited in order to define methods which
40
+ # affect or return semantic information, such as getters for `class_name`,
41
+ # `superclass` and `body` in the case of a hypothetical `ClassNode`. The
42
+ # correct solution is to use a generic Node with a {#type} of `:class`
43
+ # and three children. See also {Processor} for tips on working with such
44
+ # ASTs.
45
+ #
46
+ # On the other hand, Node can and should be inherited to define
47
+ # application-specific metadata (see also {#initialize}) or customize the
48
+ # printing format. It is expected that an application would have one or two
49
+ # such classes and use them across the entire codebase.
50
+ #
51
+ # The rationale for this pattern is extensibility and maintainability.
52
+ # Unlike static ones, dynamic languages do not require the presence of a
53
+ # predefined, rigid structure, nor does it improve dispatch efficiency,
54
+ # and while such a structure can certainly be defined, it does not add
55
+ # any value but incurs a maintaining cost.
56
+ # For example, extending the AST even with a transformation-local
57
+ # temporary node type requires making globally visible changes to
58
+ # the codebase.
59
+ #
60
+ # source://ast-2.4.2/lib/ast/node.rb:40
61
+ class AST::Node
62
+ # Constructs a new instance of Node.
63
+ #
64
+ # The arguments `type` and `children` are converted with `to_sym` and
65
+ # `to_a` respectively. Additionally, the result of converting `children`
66
+ # is frozen. While mutating the arguments is generally considered harmful,
67
+ # the most common case is to pass an array literal to the constructor. If
68
+ # your code does not expect the argument to be frozen, use `#dup`.
69
+ #
70
+ # The `properties` hash is passed to {#assign_properties}.
71
+ #
72
+ # @return [Node] a new instance of Node
73
+ #
74
+ # source://ast-2.4.2/lib/ast/node.rb:72
75
+ def initialize(type, children = T.unsafe(nil), properties = T.unsafe(nil))
76
+ ;
77
+ end
78
+
79
+ # Concatenates `array` with `children` and returns the resulting node.
80
+ #
81
+ # @return [AST::Node]
82
+ #
83
+ # source://ast-2.4.2/lib/ast/node.rb:168
84
+ def +(array)
85
+ ;
86
+ end
87
+
88
+ # Appends `element` to `children` and returns the resulting node.
89
+ #
90
+ # @return [AST::Node]
91
+ #
92
+ # source://ast-2.4.2/lib/ast/node.rb:177
93
+ def <<(element)
94
+ ;
95
+ end
96
+
97
+ # Compares `self` to `other`, possibly converting with `to_ast`. Only
98
+ # `type` and `children` are compared; metadata is deliberately ignored.
99
+ #
100
+ # @return [Boolean]
101
+ #
102
+ # source://ast-2.4.2/lib/ast/node.rb:153
103
+ def ==(other)
104
+ ;
105
+ end
106
+
107
+ # Appends `element` to `children` and returns the resulting node.
108
+ #
109
+ # @return [AST::Node]
110
+ #
111
+ # source://ast-2.4.2/lib/ast/node.rb:177
112
+ def append(element)
113
+ ;
114
+ end
115
+
116
+ # Returns the children of this node.
117
+ # The returned value is frozen.
118
+ # The to_a alias is useful for decomposing nodes concisely.
119
+ # For example:
120
+ #
121
+ # node = s(:gasgn, :$foo, s(:integer, 1))
122
+ # var_name, value = *node
123
+ # p var_name # => :$foo
124
+ # p value # => (integer 1)
125
+ #
126
+ # @return [Array]
127
+ #
128
+ # source://ast-2.4.2/lib/ast/node.rb:56
129
+ def children; end
130
+
131
+ # Nodes are already frozen, so there is no harm in returning the
132
+ # current node as opposed to initializing from scratch and freezing
133
+ # another one.
134
+ #
135
+ # @return self
136
+ #
137
+ # source://ast-2.4.2/lib/ast/node.rb:115
138
+ def clone; end
139
+
140
+ # Concatenates `array` with `children` and returns the resulting node.
141
+ #
142
+ # @return [AST::Node]
143
+ #
144
+ # source://ast-2.4.2/lib/ast/node.rb:168
145
+ def concat(array)
146
+ ;
147
+ end
148
+
149
+ # Enables matching for Node, where type is the first element
150
+ # and the children are remaining items.
151
+ #
152
+ # @return [Array]
153
+ #
154
+ # source://ast-2.4.2/lib/ast/node.rb:253
155
+ def deconstruct; end
156
+
157
+ # Nodes are already frozen, so there is no harm in returning the
158
+ # current node as opposed to initializing from scratch and freezing
159
+ # another one.
160
+ #
161
+ # @return self
162
+ #
163
+ # source://ast-2.4.2/lib/ast/node.rb:115
164
+ def dup; end
165
+
166
+ # Test if other object is equal to
167
+ #
168
+ # @param other [Object]
169
+ # @return [Boolean]
170
+ #
171
+ # source://ast-2.4.2/lib/ast/node.rb:85
172
+ def eql?(other)
173
+ ;
174
+ end
175
+
176
+ # Returns the precomputed hash value for this node
177
+ #
178
+ # @return [Fixnum]
179
+ #
180
+ # source://ast-2.4.2/lib/ast/node.rb:61
181
+ def hash; end
182
+
183
+ # Converts `self` to a s-expression ruby string.
184
+ # The code return will recreate the node, using the sexp module s()
185
+ #
186
+ # @param indent [Integer] Base indentation level.
187
+ # @return [String]
188
+ #
189
+ # source://ast-2.4.2/lib/ast/node.rb:211
190
+ def inspect(indent = T.unsafe(nil))
191
+ ;
192
+ end
193
+
194
+ # Returns the children of this node.
195
+ # The returned value is frozen.
196
+ # The to_a alias is useful for decomposing nodes concisely.
197
+ # For example:
198
+ #
199
+ # node = s(:gasgn, :$foo, s(:integer, 1))
200
+ # var_name, value = *node
201
+ # p var_name # => :$foo
202
+ # p value # => (integer 1)
203
+ #
204
+ # @return [Array]
205
+ #
206
+ # source://ast-2.4.2/lib/ast/node.rb:56
207
+ def to_a; end
208
+
209
+ # @return [AST::Node] self
210
+ #
211
+ # source://ast-2.4.2/lib/ast/node.rb:229
212
+ def to_ast; end
213
+
214
+ # Converts `self` to a pretty-printed s-expression.
215
+ #
216
+ # @param indent [Integer] Base indentation level.
217
+ # @return [String]
218
+ #
219
+ # source://ast-2.4.2/lib/ast/node.rb:187
220
+ def to_s(indent = T.unsafe(nil))
221
+ ;
222
+ end
223
+
224
+ # Converts `self` to a pretty-printed s-expression.
225
+ #
226
+ # @param indent [Integer] Base indentation level.
227
+ # @return [String]
228
+ #
229
+ # source://ast-2.4.2/lib/ast/node.rb:187
230
+ def to_sexp(indent = T.unsafe(nil))
231
+ ;
232
+ end
233
+
234
+ # Converts `self` to an Array where the first element is the type as a Symbol,
235
+ # and subsequent elements are the same representation of its children.
236
+ #
237
+ # @return [Array<Symbol, [...Array]>]
238
+ #
239
+ # source://ast-2.4.2/lib/ast/node.rb:237
240
+ def to_sexp_array; end
241
+
242
+ # Returns the type of this node.
243
+ #
244
+ # @return [Symbol]
245
+ #
246
+ # source://ast-2.4.2/lib/ast/node.rb:43
247
+ def type; end
248
+
249
+ # Returns a new instance of Node where non-nil arguments replace the
250
+ # corresponding fields of `self`.
251
+ #
252
+ # For example, `Node.new(:foo, [ 1, 2 ]).updated(:bar)` would yield
253
+ # `(bar 1 2)`, and `Node.new(:foo, [ 1, 2 ]).updated(nil, [])` would
254
+ # yield `(foo)`.
255
+ #
256
+ # If the resulting node would be identical to `self`, does nothing.
257
+ #
258
+ # @param type [Symbol, nil]
259
+ # @param children [Array, nil]
260
+ # @param properties [Hash, nil]
261
+ # @return [AST::Node]
262
+ #
263
+ # source://ast-2.4.2/lib/ast/node.rb:133
264
+ def updated(type = T.unsafe(nil), children = T.unsafe(nil), properties = T.unsafe(nil))
265
+ ;
266
+ end
267
+
268
+ protected
269
+
270
+ # By default, each entry in the `properties` hash is assigned to
271
+ # an instance variable in this instance of Node. A subclass should define
272
+ # attribute readers for such variables. The values passed in the hash
273
+ # are not frozen or whitelisted; such behavior can also be implemented
274
+ # by subclassing Node and overriding this method.
275
+ #
276
+ # @return [nil]
277
+ #
278
+ # source://ast-2.4.2/lib/ast/node.rb:98
279
+ def assign_properties(properties)
280
+ ;
281
+ end
282
+
283
+ # Returns `@type` with all underscores replaced by dashes. This allows
284
+ # to write symbol literals without quotes in Ruby sources and yet have
285
+ # nicely looking s-expressions.
286
+ #
287
+ # @return [String]
288
+ #
289
+ # source://ast-2.4.2/lib/ast/node.rb:264
290
+ def fancy_type; end
291
+
292
+ private
293
+
294
+ def original_dup; end
295
+ end
296
+
297
+ # This class includes {AST::Processor::Mixin}; however, it is
298
+ # deprecated, since the module defines all of the behaviors that
299
+ # the processor includes. Any new libraries should use
300
+ # {AST::Processor::Mixin} instead of subclassing this.
301
+ #
302
+ # @deprecated Use {AST::Processor::Mixin} instead.
303
+ #
304
+ # source://ast-2.4.2/lib/ast/processor.rb:8
305
+ class AST::Processor
306
+ include ::AST::Processor::Mixin
307
+ end
308
+
309
+ # The processor module is a module which helps transforming one
310
+ # AST into another. In a nutshell, the {#process} method accepts
311
+ # a {Node} and dispatches it to a handler corresponding to its
312
+ # type, and returns a (possibly) updated variant of the node.
313
+ #
314
+ # The processor module has a set of associated design patterns.
315
+ # They are best explained with a concrete example. Let's define a
316
+ # simple arithmetic language and an AST format for it:
317
+ #
318
+ # Terminals (AST nodes which do not have other AST nodes inside):
319
+ #
320
+ # * `(integer <int-literal>)`,
321
+ #
322
+ # Nonterminals (AST nodes with other nodes as children):
323
+ #
324
+ # * `(add <node> <node>)`,
325
+ # * `(multiply <node> <node>)`,
326
+ # * `(divide <node> <node>)`,
327
+ # * `(negate <node>)`,
328
+ # * `(store <node> <string-literal>)`: stores value of `<node>`
329
+ # into a variable named `<string-literal>`,
330
+ # * `(load <string-literal>)`: loads value of a variable named
331
+ # `<string-literal>`,
332
+ # * `(each <node> ...)`: computes each of the `<node>`s and
333
+ # prints the result.
334
+ #
335
+ # All AST nodes have the same Ruby class, and therefore they don't
336
+ # know how to traverse themselves. (A solution which dynamically
337
+ # checks the type of children is possible, but is slow and
338
+ # error-prone.) So, a class including the module which knows how
339
+ # to traverse the entire tree should be defined. Such classes
340
+ # have a handler for each nonterminal node which recursively
341
+ # processes children nodes:
342
+ #
343
+ # require 'ast'
344
+ #
345
+ # class ArithmeticsProcessor
346
+ # include AST::Processor::Mixin
347
+ # # This method traverses any binary operators such as (add)
348
+ # # or (multiply).
349
+ # def process_binary_op(node)
350
+ # # Children aren't decomposed automatically; it is
351
+ # # suggested to use Ruby multiple assignment expansion,
352
+ # # as it is very convenient here.
353
+ # left_expr, right_expr = *node
354
+ #
355
+ # # AST::Node#updated won't change node type if nil is
356
+ # # passed as a first argument, which allows to reuse the
357
+ # # same handler for multiple node types using `alias'
358
+ # # (below).
359
+ # node.updated(nil, [
360
+ # process(left_expr),
361
+ # process(right_expr)
362
+ # ])
363
+ # end
364
+ # alias_method :on_add, :process_binary_op
365
+ # alias_method :on_multiply, :process_binary_op
366
+ # alias_method :on_divide, :process_binary_op
367
+ #
368
+ # def on_negate(node)
369
+ # # It is also possible to use #process_all for more
370
+ # # compact code if every child is a Node.
371
+ # node.updated(nil, process_all(node))
372
+ # end
373
+ #
374
+ # def on_store(node)
375
+ # expr, variable_name = *node
376
+ #
377
+ # # Note that variable_name is not a Node and thus isn't
378
+ # # passed to #process.
379
+ # node.updated(nil, [
380
+ # process(expr),
381
+ # variable_name
382
+ # ])
383
+ # end
384
+ #
385
+ # # (load) is effectively a terminal node, and so it does
386
+ # # not need an explicit handler, as the following is the
387
+ # # default behavior. Essentially, for any nodes that don't
388
+ # # have a defined handler, the node remains unchanged.
389
+ # def on_load(node)
390
+ # nil
391
+ # end
392
+ #
393
+ # def on_each(node)
394
+ # node.updated(nil, process_all(node))
395
+ # end
396
+ # end
397
+ #
398
+ # Let's test our ArithmeticsProcessor:
399
+ #
400
+ # include AST::Sexp
401
+ # expr = s(:add, s(:integer, 2), s(:integer, 2))
402
+ #
403
+ # p ArithmeticsProcessor.new.process(expr) == expr # => true
404
+ #
405
+ # As expected, it does not change anything at all. This isn't
406
+ # actually very useful, so let's now define a Calculator, which
407
+ # will compute the expression values:
408
+ #
409
+ # # This Processor folds nonterminal nodes and returns an
410
+ # # (integer) terminal node.
411
+ # class ArithmeticsCalculator < ArithmeticsProcessor
412
+ # def compute_op(node)
413
+ # # First, node children are processed and then unpacked
414
+ # # to local variables.
415
+ # nodes = process_all(node)
416
+ #
417
+ # if nodes.all? { |node| node.type == :integer }
418
+ # # If each of those nodes represents a literal, we can
419
+ # # fold this node!
420
+ # values = nodes.map { |node| node.children.first }
421
+ # AST::Node.new(:integer, [
422
+ # yield(values)
423
+ # ])
424
+ # else
425
+ # # Otherwise, we can just leave the current node in the
426
+ # # tree and only update it with processed children
427
+ # # nodes, which can be partially folded.
428
+ # node.updated(nil, nodes)
429
+ # end
430
+ # end
431
+ #
432
+ # def on_add(node)
433
+ # compute_op(node) { |left, right| left + right }
434
+ # end
435
+ #
436
+ # def on_multiply(node)
437
+ # compute_op(node) { |left, right| left * right }
438
+ # end
439
+ # end
440
+ #
441
+ # Let's check:
442
+ #
443
+ # p ArithmeticsCalculator.new.process(expr) # => (integer 4)
444
+ #
445
+ # Excellent, the calculator works! Now, a careful reader could
446
+ # notice that the ArithmeticsCalculator does not know how to
447
+ # divide numbers. What if we pass an expression with division to
448
+ # it?
449
+ #
450
+ # expr_with_division = \
451
+ # s(:add,
452
+ # s(:integer, 1),
453
+ # s(:divide,
454
+ # s(:add, s(:integer, 8), s(:integer, 4)),
455
+ # s(:integer, 3))) # 1 + (8 + 4) / 3
456
+ #
457
+ # folded_expr_with_division = ArithmeticsCalculator.new.process(expr_with_division)
458
+ # p folded_expr_with_division
459
+ # # => (add
460
+ # # (integer 1)
461
+ # # (divide
462
+ # # (integer 12)
463
+ # # (integer 3)))
464
+ #
465
+ # As you can see, the expression was folded _partially_: the inner
466
+ # `(add)` node which could be computed was folded to
467
+ # `(integer 12)`, the `(divide)` node is left as-is because there
468
+ # is no computing handler for it, and the root `(add)` node was
469
+ # also left as it is because some of its children were not
470
+ # literals.
471
+ #
472
+ # Note that this partial folding is only possible because the
473
+ # _data_ format, i.e. the format in which the computed values of
474
+ # the nodes are represented, is the same as the AST itself.
475
+ #
476
+ # Let's extend our ArithmeticsCalculator class further.
477
+ #
478
+ # class ArithmeticsCalculator
479
+ # def on_divide(node)
480
+ # compute_op(node) { |left, right| left / right }
481
+ # end
482
+ #
483
+ # def on_negate(node)
484
+ # # Note how #compute_op works regardless of the operator
485
+ # # arity.
486
+ # compute_op(node) { |value| -value }
487
+ # end
488
+ # end
489
+ #
490
+ # Now, let's apply our renewed ArithmeticsCalculator to a partial
491
+ # result of previous evaluation:
492
+ #
493
+ # p ArithmeticsCalculator.new.process(expr_with_division) # => (integer 5)
494
+ #
495
+ # Five! Excellent. This is also pretty much how CRuby 1.8 executed
496
+ # its programs.
497
+ #
498
+ # Now, let's do some automated bug searching. Division by zero is
499
+ # an error, right? So if we could detect that someone has divided
500
+ # by zero before the program is even run, that could save some
501
+ # debugging time.
502
+ #
503
+ # class DivisionByZeroVerifier < ArithmeticsProcessor
504
+ # class VerificationFailure < Exception; end
505
+ #
506
+ # def on_divide(node)
507
+ # # You need to process the children to handle nested divisions
508
+ # # such as:
509
+ # # (divide
510
+ # # (integer 1)
511
+ # # (divide (integer 1) (integer 0))
512
+ # left, right = process_all(node)
513
+ #
514
+ # if right.type == :integer &&
515
+ # right.children.first == 0
516
+ # raise VerificationFailure, "Ouch! This code divides by zero."
517
+ # end
518
+ # end
519
+ #
520
+ # def divides_by_zero?(ast)
521
+ # process(ast)
522
+ # false
523
+ # rescue VerificationFailure
524
+ # true
525
+ # end
526
+ # end
527
+ #
528
+ # nice_expr = \
529
+ # s(:divide,
530
+ # s(:add, s(:integer, 10), s(:integer, 2)),
531
+ # s(:integer, 4))
532
+ #
533
+ # p DivisionByZeroVerifier.new.divides_by_zero?(nice_expr)
534
+ # # => false. Good.
535
+ #
536
+ # bad_expr = \
537
+ # s(:add, s(:integer, 10),
538
+ # s(:divide, s(:integer, 1), s(:integer, 0)))
539
+ #
540
+ # p DivisionByZeroVerifier.new.divides_by_zero?(bad_expr)
541
+ # # => true. WHOOPS. DO NOT RUN THIS.
542
+ #
543
+ # Of course, this won't detect more complex cases... unless you
544
+ # use some partial evaluation before! The possibilites are
545
+ # endless. Have fun.
546
+ #
547
+ # source://ast-2.4.2/lib/ast/processor/mixin.rb:240
548
+ module AST::Processor::Mixin
549
+ # Default handler. Does nothing.
550
+ #
551
+ # @param node [AST::Node]
552
+ # @return [AST::Node, nil]
553
+ #
554
+ # source://ast-2.4.2/lib/ast/processor/mixin.rb:284
555
+ def handler_missing(node)
556
+ ;
557
+ end
558
+
559
+ # Dispatches `node`. If a node has type `:foo`, then a handler
560
+ # named `on_foo` is invoked with one argument, the `node`; if
561
+ # there isn't such a handler, {#handler_missing} is invoked
562
+ # with the same argument.
563
+ #
564
+ # If the handler returns `nil`, `node` is returned; otherwise,
565
+ # the return value of the handler is passed along.
566
+ #
567
+ # @param node [AST::Node, nil]
568
+ # @return [AST::Node, nil]
569
+ #
570
+ # source://ast-2.4.2/lib/ast/processor/mixin.rb:251
571
+ def process(node)
572
+ ;
573
+ end
574
+
575
+ # {#process}es each node from `nodes` and returns an array of
576
+ # results.
577
+ #
578
+ # @param nodes [Array<AST::Node>]
579
+ # @return [Array<AST::Node>]
580
+ #
581
+ # source://ast-2.4.2/lib/ast/processor/mixin.rb:274
582
+ def process_all(nodes)
583
+ ;
584
+ end
585
+ end
586
+
587
+ # This simple module is very useful in the cases where one needs
588
+ # to define deeply nested ASTs from Ruby code, for example, in
589
+ # tests. It should be used like this:
590
+ #
591
+ # describe YourLanguage::AST do
592
+ # include Sexp
593
+ #
594
+ # it "should correctly parse expressions" do
595
+ # YourLanguage.parse("1 + 2 * 3").should ==
596
+ # s(:add,
597
+ # s(:integer, 1),
598
+ # s(:multiply,
599
+ # s(:integer, 2),
600
+ # s(:integer, 3)))
601
+ # end
602
+ # end
603
+ #
604
+ # This way the amount of boilerplate code is greatly reduced.
605
+ #
606
+ # source://ast-2.4.2/lib/ast/sexp.rb:20
607
+ module AST::Sexp
608
+ # Creates a {Node} with type `type` and children `children`.
609
+ # Note that the resulting node is of the type AST::Node and not a
610
+ # subclass.
611
+ # This would not pose a problem with comparisons, as {Node#==}
612
+ # ignores metadata.
613
+ #
614
+ # source://ast-2.4.2/lib/ast/sexp.rb:26
615
+ def s(type, *children)
616
+ ;
617
+ end
618
+ end