Module: Raabro
- Extended by:
- ModuleMethods
- Defined in:
- lib/raabro.rb
Defined Under Namespace
Modules: ModuleMethods Classes: Input, Tree
Constant Summary collapse
- VERSION =
'1.3.1'
Instance Attribute Summary
Attributes included from ModuleMethods
Class Method Summary collapse
-
.pp(tree, depth = 0, opts = {}) ⇒ Object
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.
Methods included from ModuleMethods
_match, _narrow, _parse, _quantify, all, alt, altg, eseq, included, make_includable, method_added, nott, parse, ren, rep, reparse_for_error, rewrite, rewrite_, rex, seq, str
Class Method Details
.pp(tree, depth = 0, opts = {}) ⇒ Object
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
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 |
# File 'lib/raabro.rb', line 598 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 |