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



16
17
18
19
# File 'lib/rley/formatter/debug.rb', line 16

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.



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rley/formatter/debug.rb', line 29

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



11
12
13
# File 'lib/rley/formatter/debug.rb', line 11

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)


24
25
26
# File 'lib/rley/formatter/debug.rb', line 24

def accept_all
  return true
end