@@ -36,6 +36,44 @@ module Prism
36
36
def to_dot
37
37
DotVisitor.new.tap { |visitor| accept(visitor) }.to_dot
38
38
end
39
+
40
+ # --------------------------------------------------------------------------
41
+ # :section: Node interface
42
+ # These methods are effectively abstract methods that must be implemented by
43
+ # the various subclasses of Node. They are here to make it easier to work
44
+ # with typecheckers.
45
+ # --------------------------------------------------------------------------
46
+
47
+ # Accepts a visitor and calls back into the specialized visit function.
48
+ def accept(visitor)
49
+ raise NoMethodError, "undefined method `accept' for #{inspect}"
50
+ end
51
+
52
+ # Returns an array of child nodes, including `nil`s in the place of optional
53
+ # nodes that were not present.
54
+ def child_nodes
55
+ raise NoMethodError, "undefined method `#{__method__}' for #{inspect}"
56
+ end
57
+
58
+ alias deconstruct child_nodes
59
+
60
+ # Returns an array of child nodes, excluding any `nil`s in the place of
61
+ # optional nodes that were not present.
62
+ def compact_child_nodes
63
+ raise NoMethodError, "undefined method `compact_child_nodes' for #{inspect}"
64
+ end
65
+
66
+ # Returns an array of child nodes and locations that could potentially have
67
+ # comments attached to them.
68
+ def comment_targets
69
+ raise NoMethodError, "undefined method `comment_targets' for #{inspect}"
70
+ end
71
+
72
+ # Returns a symbol symbolizing the type of node that this represents. This
73
+ # is particularly useful for case statements and array comparisons.
74
+ def type
75
+ raise NoMethodError, "undefined method `type' for #{inspect}"
76
+ end
39
77
end
40
78
<%- nodes . each do |node | -%>
41
79
0 commit comments