class Juli::Visitor::Tree

Another VISITOR-pattern for Absyn tree to print tree structure around each node.

Public Instance Methods

run_file(in_file, root) click to toggle source

visit root to generate absyn-tree structure.

Calls superclass method Juli::Absyn::Visitor#run_file
# File lib/juli/visitor/tree.rb, line 39
def run_file(in_file, root)
  @depth = 0
  super
end
visit_array(n) click to toggle source
# File lib/juli/visitor/tree.rb, line 57
def visit_array(n)
  print_depth
  printf("Array\n")
  @depth += 1
  for child in n.array do
    child.accept(self)
  end
  @depth -= 1
end
visit_chapter(n) click to toggle source
# File lib/juli/visitor/tree.rb, line 67
def visit_chapter(n)
  print_depth
  printf("Chapter(%d %s)\n", n.level, n.str)
  @depth += 1
  n.blocks.accept(self)
  @depth -= 1
end
visit_compact_dictionary_list(n) click to toggle source
# File lib/juli/visitor/tree.rb, line 83
def visit_compact_dictionary_list(n)
  visit_list("CompactDictionaryList\n", n)
end
visit_compact_dictionary_list_item(n) click to toggle source
# File lib/juli/visitor/tree.rb, line 87
def visit_compact_dictionary_list_item(n)
  visit_x_dictionary_list_item(n, "CompactDictionaryListItem\n")
end
visit_dictionary_list(n) click to toggle source
# File lib/juli/visitor/tree.rb, line 91
def visit_dictionary_list(n)
  visit_list("DictionaryList\n", n)
end
visit_dictionary_list_item(n) click to toggle source
# File lib/juli/visitor/tree.rb, line 95
def visit_dictionary_list_item(n)
  visit_x_dictionary_list_item(n, "DictionaryListItem\n")
end
visit_ordered_list(n) click to toggle source
# File lib/juli/visitor/tree.rb, line 75
def visit_ordered_list(n)
  visit_list("OrderedList\n", n)
end
visit_quote(n) click to toggle source
# File lib/juli/visitor/tree.rb, line 99
def visit_quote(n)
  print_depth
  printf("QuoteNode(%s)\n", str_trim(n.str))
end
visit_str(n) click to toggle source
# File lib/juli/visitor/tree.rb, line 44
def visit_str(n)
  print_depth
  printf("StrNode(%d)\n", -1)
  @depth += 1
    process_str(n.str)
  @depth -= 1
end
visit_unordered_list(n) click to toggle source
# File lib/juli/visitor/tree.rb, line 79
def visit_unordered_list(n)
  visit_list("UnorderedList\n", n)
end
visit_verbatim(n) click to toggle source
# File lib/juli/visitor/tree.rb, line 52
def visit_verbatim(n)
  print_depth
  printf("verbatim: %s\n", str_trim(n.str))
end

Private Instance Methods

print_depth() click to toggle source
process_str(str) click to toggle source

str -> Juli::LineAbsyn -> print with depth

# File lib/juli/visitor/tree.rb, line 130
def process_str(str)
  Juli::LineParser.new.parse(str, Juli::Wiki.wikinames).
      accept(LineTree.new(@depth))
end
visit_list(class_str, n) click to toggle source
# File lib/juli/visitor/tree.rb, line 109
def visit_list(class_str, n)
  print_depth
  printf(class_str)
  @depth += 1
  for child in n.array do
    child.accept(self)
  end
  @depth -= 1
end
visit_x_dictionary_list_item(n, node_name) click to toggle source

common for both dictionary list item and compact dictionary list item

# File lib/juli/visitor/tree.rb, line 120
def visit_x_dictionary_list_item(n, node_name)
  print_depth
  printf(node_name)
  @depth += 1
  process_str(n.term)
  process_str(n.str)
  @depth -= 1
end