module Raabro
Constants
- VERSION
Public Class Methods
pp(tree, depth=0, opts={})
click to toggle source
Black 0;30 Dark Gray 1;30 Blue 0;34 Light Blue 1;34 Green 0;32 Light Green 1;32 Cyan 0;36 Light Cyan 1;36 Red 0;31 Light Red 1;31 Purple 0;35 Light Purple 1;35 Brown 0;33 Yellow 1;33 Light Gray 0;37 White 1;37
# File lib/raabro.rb, line 618 def self.pp(tree, depth=0, opts={}) fail ArgumentError.new( 'tree is not an instance of Raabro::Tree' ) unless tree.is_a?(Raabro::Tree) depth, opts = 0, depth if depth.is_a?(Hash) _rs, _dg, _gn, _yl, _bl, _lg = (opts[:colors] || opts[:colours] || $stdout.tty?) ? [ "[0;0m", "[1;30m", "[0;32m", "[1;33m", "[0;34m", "[0;37m" ] : [ '', '', '', '', '', '' ] lc = tree.result == 1 ? _gn : _dg nc = tree.result == 1 ? _bl : _lg nc = lc if tree.name == nil sc = tree.result == 1 ? _yl : _dg str = if tree.children.size == 0 " #{sc}#{tree.string.length == 0 ? "#{_dg} >#{tree.nonstring(14).inspect[1..-2]}<" : tree.string.inspect}" else '' end print "#{_dg}t---\n" if depth == 0 #print "#{' ' * depth}" depth.times do |i| pipe = i % 3 == 0 ? ': ' : '| ' print i.even? ? "#{_dg}#{pipe} " : ' ' end print "#{lc}#{tree.result}" print " #{nc}#{tree.name.inspect} #{lc}#{tree.offset},#{tree.length}" print str print "#{_rs}\n" tree.children.each { |c| self.pp(c, depth + 1, opts) } if depth == 0 print _dg print "input ln: #{tree.input.string.length}, tree ln: #{tree.length} " print "---t\n" print _rs end end