class Sequitur::Formatter::Debug

A formatter class that can render the notification events from a grammar visitor @example

some_grammar = ... # Points to a DynamicGrammar-like object
# Output the result to the standard console output
formatter = Sequitur::Formatter::Debug.new(STDOUT)
# Render the visit notifications
formatter.run(some_grammar.visitor)

Attributes

indentation[RW]

@return [Integer] Current indentation level

Public Class Methods

new(anIO) click to toggle source

Constructor. @param anIO [IO] The output stream to which the rendered grammar is written.

Calls superclass method Sequitur::Formatter::BaseFormatter::new
# File lib/sequitur/formatter/debug.rb, line 22
def initialize(anIO)
  super(anIO)
  @indentation = 0
end

Public Instance Methods

after_grammar(_) click to toggle source

Method called by a GrammarVisitor to which the formatter subscribed. Notification of a visit event: the visitor completed the visit of a grammar @param _ [DynamicGrammar]

# File lib/sequitur/formatter/debug.rb, line 108
def after_grammar(_)
  dedent
  output_event(__method__, indentation)
end
after_non_terminal(_) click to toggle source

Method called by a GrammarVisitor to which the formatter subscribed. Notification of a visit event: the visitor completed the visit of a non-terminal symbol from the rhs of a production. @param _ [Object]

# File lib/sequitur/formatter/debug.rb, line 82
def after_non_terminal(_)
  output_event(__method__, indentation)
end
after_production(_) click to toggle source

Method called by a GrammarVisitor to which the formatter subscribed. Notification of a visit event: the visitor completed the visit of a production @param _ [Production]

# File lib/sequitur/formatter/debug.rb, line 99
def after_production(_)
  dedent
  output_event(__method__, indentation)
end
after_rhs(_) click to toggle source

Method called by a GrammarVisitor to which the formatter subscribed. Notification of a visit event: the visitor completed the visit of the rhs of a production @param _ [Array]

# File lib/sequitur/formatter/debug.rb, line 90
def after_rhs(_)
  dedent
  output_event(__method__, indentation)
end
after_terminal(_) click to toggle source

Method called by a GrammarVisitor to which the formatter subscribed. Notification of a visit event: the visitor completed the visit of a terminal symbol from the rhs of a production @param _ [Object]

# File lib/sequitur/formatter/debug.rb, line 65
def after_terminal(_)
  output_event(__method__, indentation)
end
before_grammar(_) click to toggle source

Method called by a GrammarVisitor to which the formatter subscribed. Notification of a visit event: the visitor is about to visit a grammar @param _ [DynamicGrammar]

# File lib/sequitur/formatter/debug.rb, line 30
def before_grammar(_)
  output_event(__method__, indentation)
  indent
end
before_non_terminal(_) click to toggle source

Method called by a GrammarVisitor to which the formatter subscribed. Notification of a visit event: the visitor is about to visit a non-terminal (= an allusion to a production) in the rhs of a production @param _ [Production] a production occurring in the rhs

# File lib/sequitur/formatter/debug.rb, line 74
def before_non_terminal(_)
  output_event(__method__, indentation)
end
before_production(_) click to toggle source

Method called by a GrammarVisitor to which the formatter subscribed. Notification of a visit event: the visitor is about to visit a production @param _ [Production]

# File lib/sequitur/formatter/debug.rb, line 39
def before_production(_)
  output_event(__method__, indentation)
  indent
end
before_rhs(_) click to toggle source

Method called by a GrammarVisitor to which the formatter subscribed. Notification of a visit event: the visitor is about to visit the rhs of a production @param _ [Array]

# File lib/sequitur/formatter/debug.rb, line 48
def before_rhs(_)
  output_event(__method__, indentation)
  indent
end
before_terminal(_) click to toggle source

Method called by a GrammarVisitor to which the formatter subscribed. Notification of a visit event: the visitor is about to visit a terminal symbol from the rhs of a production @param _ [Object]

# File lib/sequitur/formatter/debug.rb, line 57
def before_terminal(_)
  output_event(__method__, indentation)
end

Private Instance Methods

dedent() click to toggle source

@return [Integer]

# File lib/sequitur/formatter/debug.rb, line 121
def dedent
  @indentation -= 1
end
indent() click to toggle source

@return [Integer]

# File lib/sequitur/formatter/debug.rb, line 116
def indent
  @indentation += 1
end
output_event(anEvent, indentationLevel) click to toggle source

@param anEvent [Symbol] @param indentationLevel [Integer] @return [NilClass]

# File lib/sequitur/formatter/debug.rb, line 128
def output_event(anEvent, indentationLevel)
  output.puts "#{' ' * 2 * indentationLevel}#{anEvent}"
end