Object
# File lib/rkelly/nodes/node.rb, line 21 def ==(other) other.is_a?(self.class) && @value == other.value end
# File lib/rkelly/nodes/node.rb, line 26 def ===(other) other.is_a?(self.class) && @value === other.value end
Loops through all the syntax nodes.
# File lib/rkelly/nodes/node.rb, line 95 def each(&block) EnumerableVisitor.new(block).accept(self) end
For backwards compatibility
# File lib/rkelly/nodes/node.rb, line 17 def line @range.from.line end
Matches nodes with the given pattern (usually a class name of the node) and returns an instance of PointcutVisitor on which matches can be invoked to get the list of AST nodes that matched.
ast.pointcut(RKelly::Nodes::IfNode).matches --> array of nodes
# File lib/rkelly/nodes/node.rb, line 37 def pointcut(pattern) case pattern when String ast = RKelly::Parser.new.parse(pattern) # Only take the first statement finder = ast.value.first.class.to_s =~ /StatementNode$/ ? ast.value.first.value : ast.value.first visitor = PointcutVisitor.new(finder) else visitor = PointcutVisitor.new(pattern) end visitor.accept(self) visitor end
Generates a graph description in DOT language. This can be fed into the dot program to generate a graph of the AST:
$ dot -Tpng generated-graph.dot -o graph.png
# File lib/rkelly/nodes/node.rb, line 72 def to_dots visitor = DotVisitor.new visitor.accept(self) header = digraph g {graph [ rankdir = "TB" ];node [ fontsize = "16" shape = "ellipse"];edge [ ]; nodes = visitor.nodes.map { |x| x.to_s }.join("\n") counter = 0 arrows = visitor.arrows.map { |x| s = "#{x} [\nid = #{counter}\n];" counter += 1 s }.join("\n") "#{header}\n#{nodes}\n#{arrows}\n}" end
Generates formatted and intented JavaScript source code.
# File lib/rkelly/nodes/node.rb, line 63 def to_ecma ECMAVisitor.new.accept(self) end
Generated with the Darkfish Rdoc Generator 2.