class SyntaxTree::PrettyPrintVisitor

This visitor pretty-prints the AST into an equivalent s-expression.

Attributes

q[R]

Public Class Methods

new(q) click to toggle source
# File lib/syntax_tree/pretty_print_visitor.rb, line 8
def initialize(q)
  @q = q
end

Public Instance Methods

visit_binary(node) click to toggle source

This is here because we need to make sure the operator is cast to a string before we print it out.

# 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
visit_label(node) click to toggle source

This is here to make it a little nicer to look at labels since they typically have their : at the end of the value.

# 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