lib/raabro.rb in raabro-1.1.1 vs lib/raabro.rb in raabro-1.1.2

- old
+ new

@@ -1,6 +1,5 @@ - #-- # Copyright (c) 2015-2016, John Mettraux, jmettraux@gmail.com # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -24,11 +23,11 @@ #++ module Raabro - VERSION = '1.1.1' + VERSION = '1.1.2' class Input attr_accessor :string, :offset attr_reader :options @@ -504,7 +503,53 @@ end end extend ModuleMethods make_includable + + # 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 + + def self.pp(tree, depth=0) + + _rs, _dg, _gn, _yl, _bl, _lg = + $stdout.tty? ? + [ "", "", "", "", "", "" ] : + [ '', '', '', '', '', '' ] + + 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 ? "''" : tree.string.inspect}" + else + '' + end + + print "#{_dg}t---\n" if depth == 0 + + print "#{' ' * depth}" + 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) } + + if depth == 0 + print _dg + print "input ln: #{tree.input.string.length}, tree ln: #{tree.length} " + print "---t\n" + print _rs + end + end end