Class: SyntaxTree::Translation::Parser
- Inherits:
-
BasicVisitor
- Object
- BasicVisitor
- SyntaxTree::Translation::Parser
- Defined in:
- lib/syntax_tree/translation/parser.rb
Overview
This visitor is responsible for converting the syntax tree produced by Syntax Tree into the syntax tree produced by the whitequark/parser gem.
Direct Known Subclasses
Defined Under Namespace
Classes: HeredocBuilder
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Instance Method Summary collapse
-
#initialize(buffer) ⇒ Parser
constructor
A new instance of Parser.
-
#visit(node) ⇒ Object
For each node that we visit, we keep track of it in a stack as we descend into its children.
Methods inherited from BasicVisitor
valid_visit_methods, #visit_all, #visit_child_nodes, visit_method, visit_methods
Constructor Details
#initialize(buffer) ⇒ Parser
Returns a new instance of Parser.
77 78 79 80 |
# File 'lib/syntax_tree/translation/parser.rb', line 77 def initialize(buffer) @buffer = buffer @stack = [] end |
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
75 76 77 |
# File 'lib/syntax_tree/translation/parser.rb', line 75 def buffer @buffer end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
75 76 77 |
# File 'lib/syntax_tree/translation/parser.rb', line 75 def stack @stack end |
Instance Method Details
#visit(node) ⇒ Object
For each node that we visit, we keep track of it in a stack as we descend into its children. We do this so that child nodes can reflect on their parents if they need additional information about their context.
85 86 87 88 89 90 |
# File 'lib/syntax_tree/translation/parser.rb', line 85 def visit(node) stack << node result = super stack.pop result end |