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



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

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

Instance Attribute Details

#indentationObject (readonly)

Current indentation level



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

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



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

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)


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

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



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

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)


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

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)


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

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:



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

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



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

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)


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

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)


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

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)


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

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