Class: Rley::Formatter::Debug

Inherits:
BaseFormatter show all
Defined in:
lib/rley/formatter/debug.rb

Overview

A formatter class that renders the visit notification events from a parse tree visitor

Instance Attribute Summary collapse

Attributes inherited from BaseFormatter

#output

Instance Method Summary collapse

Methods inherited from BaseFormatter

#render

Constructor Details

#initialize(anIO) ⇒ Debug

Constructor. is written.

Parameters:

  • anIO (IO)

    The output stream to which the rendered grammar



18
19
20
21
# File 'lib/rley/formatter/debug.rb', line 18

def initialize(anIO)
  super(anIO)
  @indentation = 0
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(mth, *args) ⇒ Object

Ghost method pattern.



31
32
33
34
35
36
37
38
39
40
41
42
43
# 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

Instance Attribute Details

#indentationObject (readonly)

Current indentation level



13
14
15
# File 'lib/rley/formatter/debug.rb', line 13

def indentation
  @indentation
end

Instance Method Details

#accept_allBoolean

Indicates that this formatter accepts all visit events provided their names start with 'before_' or 'after_'

Returns:

  • (Boolean)


26
27
28
# File 'lib/rley/formatter/debug.rb', line 26

def accept_all
  return true
end