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

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

#after_non_terminal(_nonterm) ⇒ Object

Method called by a ParseTreeVisitor to which the formatter subscribed. Notification of a visit event: the visitor completed the visit of a non-terminal node

Parameters:

  • _nonterm (NonTerminalNode)


69
70
71
72
# File 'lib/rley/formatter/debug.rb', line 69

def after_non_terminal(_nonterm)
  dedent
  output_event(__method__, indentation)
end

#after_ptree(_ptree) ⇒ Object

Method called by a ParseTreeVisitor to which the formatter subscribed. Notification of a visit event: the visitor completed the visit of the given parse tree

Parameters:

  • _ptree (ParseTree)


89
90
91
92
# File 'lib/rley/formatter/debug.rb', line 89

def after_ptree(_ptree)
  dedent
  output_event(__method__, indentation)
end

#after_subnodes(_parent, _children) ⇒ Object

Method called by a ParseTreeVisitor to which the formatter subscribed. Notification of a visit event: the visitor completed the visit of the children of a non-terminal node.

Parameters:

  • _parent (NonTerminalNode)
  • _children (Array)

    array of children nodes



79
80
81
82
# File 'lib/rley/formatter/debug.rb', line 79

def after_subnodes(_parent, _children)
  dedent
  output_event(__method__, indentation)
end

#after_terminal(_term) ⇒ Object

Method called by a ParseTreeVisitor to which the formatter subscribed. Notification of a visit event: the visitor completed the visit of a terminal node.

Parameters:

  • _term (TerminalNode)


61
62
63
# File 'lib/rley/formatter/debug.rb', line 61

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

#before_non_terminal(_nonterm) ⇒ Object

Method called by a ParseTreeVisitor to which the formatter subscribed. Notification of a visit event: the visitor is about to visit a non-terminal node

Parameters:

  • _nonterm (NonTerminalNode)


34
35
36
37
# File 'lib/rley/formatter/debug.rb', line 34

def before_non_terminal(_nonterm)
  output_event(__method__, indentation)
  indent
end

#before_ptree(_ptree) ⇒ Object

Method called by a ParseTreeVisitor to which the formatter subscribed. Notification of a visit event: the visitor is about to visit the given parse tree

Parameters:

  • _ptree (ParseTree)


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

def before_ptree(_ptree)
  output_event(__method__, indentation)
  indent
end

#before_subnodes(_parent, _children) ⇒ Object

Method called by a ParseTreeVisitor to which the formatter subscribed. Notification of a visit event: the visitor is about to visit the children of a non-terminal node

Parameters:

  • _parent (NonTerminalNode)
  • _children (Array)

    array of children nodes



44
45
46
47
# File 'lib/rley/formatter/debug.rb', line 44

def before_subnodes(_parent, _children)
  output_event(__method__, indentation)
  indent
end

#before_terminal(_term) ⇒ Object

Method called by a ParseTreeVisitor to which the formatter subscribed. Notification of a visit event: the visitor is about to visit a terminal node

Parameters:

  • _term (TerminalNode)


53
54
55
# File 'lib/rley/formatter/debug.rb', line 53

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