Class: BracketNotation

Inherits:
BaseFormatter show all
Defined in:
lib/dendroid/formatters/bracket_notation.rb

Instance Attribute Summary

Attributes inherited from BaseFormatter

#output

Instance Method Summary collapse

Methods inherited from BaseFormatter

#initialize, #render

Constructor Details

This class inherits a constructor from BaseFormatter

Instance Method Details

#after_and_node(_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)


41
42
43
# File 'lib/dendroid/formatters/bracket_notation.rb', line 41

def after_and_node(_nonterm)
  write(']')
end

#after_terminal(aTerm) ⇒ 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:

  • aTerm (TerminalNode)


30
31
32
33
34
35
# File 'lib/dendroid/formatters/bracket_notation.rb', line 30

def after_terminal(aTerm)
  # Escape all opening and closing square brackets
  escape_lbrackets = aTerm.token.source.gsub(/\[/, '\[')
  escaped = escape_lbrackets.gsub(/\]/, '\]')
  write("#{escaped}]")
end

#before_and_node(and_node) ⇒ 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:

  • and_node (AndNode)


10
11
12
# File 'lib/dendroid/formatters/bracket_notation.rb', line 10

def before_and_node(and_node)
  write("[#{and_node.rule.lhs.name} ")
end

#before_empty_rule_node(anEmptyRuleNode) ⇒ Object



14
15
16
# File 'lib/dendroid/formatters/bracket_notation.rb', line 14

def before_empty_rule_node(anEmptyRuleNode)
  write("[#{anEmptyRuleNode.rule.lhs.name}]")
end

#before_terminal(aTerm) ⇒ 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:

  • aTerm (TerminalNode)


22
23
24
# File 'lib/dendroid/formatters/bracket_notation.rb', line 22

def before_terminal(aTerm)
  write("[#{aTerm.symbol.name} ")
end