Class: Asciitree
- Inherits:
-
BaseFormatter
- Object
- BaseFormatter
- Asciitree
- Defined in:
- lib/dendroid/formatters/ascii_tree.rb
Overview
A formatter class that draws parse trees by using characters
Instance Attribute Summary collapse
-
#and_nesting_prefix ⇒ String
readonly
a parent - child nesting.
-
#blank_indent ⇒ String
readonly
The character pattern used for a blank indentation.
-
#continuation_indent ⇒ String
readonly
continuation.
-
#curr_path ⇒ Object
readonly
TODO.
-
#or_nesting_prefix ⇒ Object
readonly
TODO: comment.
-
#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_and_node(aNonTerm) ⇒ Object
Method called by a ParseTreeVisitor to which the formatter subscribed.
- #before_empty_rule_node(anEmptyRuleNode) ⇒ Object
- #before_or_node(aNonTerm) ⇒ Object
-
#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.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/dendroid/formatters/ascii_tree.rb', line 31 def initialize(anIO) super(anIO) @curr_path = [] @ranks = [] @and_nesting_prefix = '+-- ' @or_nesting_prefix = '/-- ' @blank_indent = ' ' @continuation_indent = '| ' end |
Instance Attribute Details
#and_nesting_prefix ⇒ String (readonly)
a parent - child nesting
16 17 18 |
# File 'lib/dendroid/formatters/ascii_tree.rb', line 16 def and_nesting_prefix @and_nesting_prefix end |
#blank_indent ⇒ String (readonly)
Returns The character pattern used for a blank indentation.
22 23 24 |
# File 'lib/dendroid/formatters/ascii_tree.rb', line 22 def blank_indent @blank_indent end |
#continuation_indent ⇒ String (readonly)
continuation.
26 27 28 |
# File 'lib/dendroid/formatters/ascii_tree.rb', line 26 def continuation_indent @continuation_indent end |
#curr_path ⇒ Object (readonly)
TODO
8 9 10 |
# File 'lib/dendroid/formatters/ascii_tree.rb', line 8 def curr_path @curr_path end |
#or_nesting_prefix ⇒ Object (readonly)
TODO: comment
19 20 21 |
# File 'lib/dendroid/formatters/ascii_tree.rb', line 19 def or_nesting_prefix @or_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’
12 13 14 |
# File 'lib/dendroid/formatters/ascii_tree.rb', line 12 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.
81 82 83 84 |
# File 'lib/dendroid/formatters/ascii_tree.rb', line 81 def after_subnodes(_parent, _children) curr_path.pop ranks.pop end |
#before_and_node(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
56 57 58 |
# File 'lib/dendroid/formatters/ascii_tree.rb', line 56 def before_and_node(aNonTerm) emit_and(aNonTerm) end |
#before_empty_rule_node(anEmptyRuleNode) ⇒ Object
64 65 66 |
# File 'lib/dendroid/formatters/ascii_tree.rb', line 64 def before_empty_rule_node(anEmptyRuleNode) emit_and(anEmptyRuleNode, ': .') end |
#before_or_node(aNonTerm) ⇒ Object
60 61 62 |
# File 'lib/dendroid/formatters/ascii_tree.rb', line 60 def before_or_node(aNonTerm) emit_or(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
47 48 49 50 |
# File 'lib/dendroid/formatters/ascii_tree.rb', line 47 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
72 73 74 |
# File 'lib/dendroid/formatters/ascii_tree.rb', line 72 def before_terminal(aTerm) emit_terminal(aTerm, ": '#{aTerm.token.source}'") end |