Class: Sequitur::Formatter::Debug

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

Overview

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

Examples:

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)

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



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

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

Instance Attribute Details

#indentationObject

Current indentation level



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

def indentation
  @indentation
end

Instance Method Details

#after_grammar(_) ⇒ Object

Method called by a GrammarVisitor to which the formatter subscribed. Notification of a visit event: the visitor completed the visit of a grammar



107
108
109
110
# File 'lib/sequitur/formatter/debug.rb', line 107

def after_grammar(_)
  dedent
  output_event(__method__, indentation)
end

#after_non_terminal(_) ⇒ Object

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.

Parameters:

  • _ (Object)


83
84
85
# File 'lib/sequitur/formatter/debug.rb', line 83

def after_non_terminal(_)
  output_event(__method__, indentation)
end

#after_production(_) ⇒ Object

Method called by a GrammarVisitor to which the formatter subscribed. Notification of a visit event: the visitor completed the visit of a production



99
100
101
102
# File 'lib/sequitur/formatter/debug.rb', line 99

def after_production(_)
  dedent
  output_event(__method__, indentation)
end

#after_rhs(_) ⇒ Object

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

Parameters:

  • _ (Array)


91
92
93
94
# File 'lib/sequitur/formatter/debug.rb', line 91

def after_rhs(_)
  dedent
  output_event(__method__, indentation)
end

#after_terminal(_) ⇒ Object

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

Parameters:

  • _ (Object)


66
67
68
# File 'lib/sequitur/formatter/debug.rb', line 66

def after_terminal(_)
  output_event(__method__, indentation)
end

#before_grammar(_) ⇒ Object

Method called by a GrammarVisitor to which the formatter subscribed. Notification of a visit event: the visitor is about to visit a grammar

Parameters:



31
32
33
34
# File 'lib/sequitur/formatter/debug.rb', line 31

def before_grammar(_)
  output_event(__method__, indentation)
  indent
end

#before_non_terminal(_) ⇒ Object

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

Parameters:

  • _ (Production)

    a production occurring in the rhs



75
76
77
# File 'lib/sequitur/formatter/debug.rb', line 75

def before_non_terminal(_)
  output_event(__method__, indentation)
end

#before_production(_) ⇒ Object

Method called by a GrammarVisitor to which the formatter subscribed. Notification of a visit event: the visitor is about to visit a production

Parameters:

  • _ (aProduction)


40
41
42
43
# File 'lib/sequitur/formatter/debug.rb', line 40

def before_production(_)
  output_event(__method__, indentation)
  indent
end

#before_rhs(_) ⇒ Object

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

Parameters:

  • _ (Array)


49
50
51
52
# File 'lib/sequitur/formatter/debug.rb', line 49

def before_rhs(_)
  output_event(__method__, indentation)
  indent
end

#before_terminal(_) ⇒ Object

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

Parameters:

  • _ (Object)


58
59
60
# File 'lib/sequitur/formatter/debug.rb', line 58

def before_terminal(_)
  output_event(__method__, indentation)
end