class Rley::Formatter::Debug
A formatter class that renders the visit notification events from a parse tree visitor
Attributes
Current indentation level
Public Class Methods
Source
# File lib/rley/formatter/debug.rb, line 18 def initialize(anIO) super(anIO) @indentation = 0 end
Constructor. @param anIO [IO] The output stream to which the rendered grammar is written.
Calls superclass method
Rley::Formatter::BaseFormatter::new
Public Instance Methods
Source
# File lib/rley/formatter/debug.rb, line 26 def accept_all return true end
Indicates that this formatter accepts all visit events provided their names start with ‘before_’ or ‘after_’ @return [Boolean]
Source
# File lib/rley/formatter/debug.rb, line 31 def method_missing(mth, *args) mth_name = mth.to_s case mth_name when /^before_/ output_event(mth_name, indentation) indent unless mth_name == 'before_terminal' when /^after_/ dedent unless mth_name == 'after_terminal' output_event(mth_name, indentation) else super(mth, args) end end
Ghost method pattern.
Calls superclass method
Private Instance Methods
Source
# File lib/rley/formatter/debug.rb, line 55 def output_event(anEvent, indentationLevel) output.puts "#{' ' * 2 * indentationLevel}#{anEvent}" end