class Rley::Formatter::BracketNotation
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: yohasebe.com/rsyntaxtree/)
Public Instance Methods
Source
# File lib/rley/formatter/bracket_notation.rb, line 47 def after_non_terminal(_nonterm) write(']') end
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 @param _nonterm [NonTerminalNode]
Source
# File lib/rley/formatter/bracket_notation.rb, line 36 def after_terminal(aTerm) # Escape all opening and closing square brackets escape_lbrackets = aTerm.token.lexeme.gsub(/\[/, '\[') escaped = escape_lbrackets.gsub(/\]/, '\]') write("#{escaped}]") end
Method called by a ParseTreeVisitor
to which the formatter subscribed. Notification of a visit event: the visitor completed the visit of a terminal node. @param aTerm [TerminalNode]
Source
# File lib/rley/formatter/bracket_notation.rb, line 20 def before_non_terminal(aNonTerm) write("[#{aNonTerm.symbol.name} ") end
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 @param aNonTerm [NonTerminalNode]
Source
# File lib/rley/formatter/bracket_notation.rb, line 28 def before_terminal(aTerm) write("[#{aTerm.symbol.name} ") end
Method called by a ParseTreeVisitor
to which the formatter subscribed. Notification of a visit event: the visitor is about to visit a terminal node @param aTerm [TerminalNode]
Private Instance Methods
Source
# File lib/rley/formatter/bracket_notation.rb, line 53 def write(aText) output.write(aText) end