Class: Rley::Formatter::BracketNotation
- Inherits:
-
BaseFormatter
- Object
- BaseFormatter
- Rley::Formatter::BracketNotation
- Defined in:
- lib/rley/formatter/bracket_notation.rb
Overview
A formatter class that generates the labelled bracket notation (LBN) representation of a parse tree. The output can be then fed to an application or library that is capable of displaying parse tree diagrams. For Ruby developers, there is RSyntaxTree by Yoichiro Hasebe. (accessible via: http://yohasebe.com/rsyntaxtree/)
Instance Attribute Summary
Attributes inherited from BaseFormatter
Instance Method Summary collapse
-
#after_non_terminal(_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_non_terminal(aNonTerm) ⇒ Object
Method called by a ParseTreeVisitor to which the formatter subscribed.
-
#before_terminal(aTerm) ⇒ Object
Method called by a ParseTreeVisitor to which the formatter subscribed.
-
#initialize(anIO) ⇒ BracketNotation
constructor
Constructor.
Methods inherited from BaseFormatter
Constructor Details
#initialize(anIO) ⇒ BracketNotation
Constructor. is written.
19 20 21 |
# File 'lib/rley/formatter/bracket_notation.rb', line 19 def initialize(anIO) super(anIO) 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
54 55 56 |
# File 'lib/rley/formatter/bracket_notation.rb', line 54 def after_non_terminal(_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.
43 44 45 46 47 48 |
# File 'lib/rley/formatter/bracket_notation.rb', line 43 def after_terminal(aTerm) # Escape all opening and closing square brackets escape_lbrackets = aTerm.token.lexeme.gsub(/\[/, '\[') escaped = escape_lbrackets.gsub(/\]/, '\]') write(escaped + ']') end |
#before_non_terminal(aNonTerm) ⇒ 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
27 28 29 |
# File 'lib/rley/formatter/bracket_notation.rb', line 27 def before_non_terminal(aNonTerm) write("[#{aNonTerm.symbol.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
35 36 37 |
# File 'lib/rley/formatter/bracket_notation.rb', line 35 def before_terminal(aTerm) write("[#{aTerm.symbol.name} ") end |