Class: BracketNotation
- Inherits:
-
BaseFormatter
- Object
- BaseFormatter
- BracketNotation
- Defined in:
- lib/dendroid/formatters/bracket_notation.rb
Instance Attribute Summary
Attributes inherited from BaseFormatter
Instance Method Summary collapse
-
#after_and_node(_nonterm) ⇒ Object
Method called by a ParseTreeVisitor to which the formatter subscribed.
-
#after_terminal(aTerm) ⇒ Object
Method called by a ParseTreeVisitor to which the formatter subscribed.
-
#before_and_node(and_node) ⇒ Object
Method called by a ParseTreeVisitor to which the formatter subscribed.
- #before_empty_rule_node(anEmptyRuleNode) ⇒ Object
-
#before_terminal(aTerm) ⇒ Object
Method called by a ParseTreeVisitor to which the formatter subscribed.
Methods inherited from BaseFormatter
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
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.
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
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
22 23 24 |
# File 'lib/dendroid/formatters/bracket_notation.rb', line 22 def before_terminal(aTerm) write("[#{aTerm.symbol.name} ") end |