class SyntaxTree::PrettyPrintVisitor
This visitor pretty-prints the AST into an equivalent s-expression.
Attributes
Public Class Methods
Public Instance Methods
Source
# File lib/syntax_tree/pretty_print_visitor.rb, line 14 def visit_binary(node) node(node, "binary") do field("left", node.left) text("operator", node.operator.to_s) field("right", node.right) comments(node) end end
This is here because we need to make sure the operator is cast to a string before we print it out.
Source
# File lib/syntax_tree/pretty_print_visitor.rb, line 25 def visit_label(node) node(node, "label") do q.breakable q.text(":") q.text(node.value[0...-1]) comments(node) end end
This is here to make it a little nicer to look at labels since they typically have their : at the end of the value.