Class: Rley::Formatter::Asciitree
- Inherits:
-
BaseFormatter
- Object
- BaseFormatter
- Rley::Formatter::Asciitree
- Defined in:
- lib/rley/formatter/asciitree.rb
Overview
A formatter class that draws parse trees by using characters
Instance Attribute Summary collapse
-
#blank_indent ⇒ Object
readonly
Returns the value of attribute blank_indent.
-
#continuation_indent ⇒ Object
readonly
Returns the value of attribute continuation_indent.
-
#curr_path ⇒ Object
readonly
TODO.
-
#nesting_prefix ⇒ Object
readonly
Returns the value of attribute nesting_prefix.
-
#ranks ⇒ Object
readonly
For each node in curr_path, there is a corresponding string value.
Attributes inherited from BaseFormatter
Instance Method Summary collapse
-
#after_subnodes(_parent, _children) ⇒ 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_subnodes(parent, children) ⇒ 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) ⇒ Asciitree
constructor
Constructor.
Methods inherited from BaseFormatter
Constructor Details
#initialize(anIO) ⇒ Asciitree
Constructor. is written.
25 26 27 28 29 30 31 32 33 |
# File 'lib/rley/formatter/asciitree.rb', line 25 def initialize(anIO) super(anIO) @curr_path = [] @ranks = [] @nesting_prefix = '+-- ' @blank_indent = ' ' @continuation_indent = '| ' end |
Instance Attribute Details
#blank_indent ⇒ Object (readonly)
Returns the value of attribute blank_indent.
18 19 20 |
# File 'lib/rley/formatter/asciitree.rb', line 18 def blank_indent @blank_indent end |
#continuation_indent ⇒ Object (readonly)
Returns the value of attribute continuation_indent.
20 21 22 |
# File 'lib/rley/formatter/asciitree.rb', line 20 def continuation_indent @continuation_indent end |
#curr_path ⇒ Object (readonly)
TODO
10 11 12 |
# File 'lib/rley/formatter/asciitree.rb', line 10 def curr_path @curr_path end |
#nesting_prefix ⇒ Object (readonly)
Returns the value of attribute nesting_prefix.
16 17 18 |
# File 'lib/rley/formatter/asciitree.rb', line 16 def nesting_prefix @nesting_prefix end |
#ranks ⇒ Object (readonly)
For each node in curr_path, there is a corresponding string value. Allowed string values are: 'first', 'last', 'first_and_last', 'other'
14 15 16 |
# File 'lib/rley/formatter/asciitree.rb', line 14 def ranks @ranks end |
Instance Method Details
#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.
70 71 72 73 |
# File 'lib/rley/formatter/asciitree.rb', line 70 def after_subnodes(_parent, _children) curr_path.pop ranks.pop 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
51 52 53 |
# File 'lib/rley/formatter/asciitree.rb', line 51 def before_non_terminal(aNonTerm) emit(aNonTerm) 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
41 42 43 44 |
# File 'lib/rley/formatter/asciitree.rb', line 41 def before_subnodes(parent, children) rank_of(parent) curr_path << parent 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
60 61 62 |
# File 'lib/rley/formatter/asciitree.rb', line 60 def before_terminal(aTerm) emit(aTerm, ": '#{aTerm.token.lexeme}'") end |