Class: Rley::ParseRep::ASTBaseBuilder
- Inherits:
-
ParseTreeBuilder
- Object
- ParseTreeBuilder
- Rley::ParseRep::ASTBaseBuilder
- Defined in:
- lib/rley/parse_rep/ast_base_builder.rb
Overview
Abstract class (to be subclassed). The purpose of an ASTBaseBuilder is to build piece by piece an AST (Abstract Syntax Tree) from a sequence of input tokens and visit events produced by walking over a GFGParsing object. It is an implementation of the Builder GoF pattern. The Builder pattern creates a complex object (say, a parse tree) from simpler objects (terminal and non-terminal nodes) and using a step by step approach.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from ParseTreeBuilder
Instance Method Summary collapse
-
#method_name(aProductionName) ⇒ String
Default method name to invoke when production with given name is invoked.
-
#return_epsilon(_range, _tokens, _children) ⇒ Object
Simply return an epsilon symbol.
-
#return_first_child(_range, _tokens, theChildren) ⇒ Object
Utility method.
-
#return_last_child(_range, _tokens, theChildren) ⇒ Object
Utility method.
-
#return_second_child(_range, _tokens, theChildren) ⇒ Object
Utility method.
-
#terminal2node ⇒ Hash{String => Class}, Hash{String => Hash{String => Class}}
Method to override in subclass.
-
#terminalnode_class ⇒ Class
Method to override in subclass.
Methods inherited from ParseTreeBuilder
#done!, #initialize, #receive_event
Constructor Details
This class inherits a constructor from Rley::ParseRep::ParseTreeBuilder
Instance Method Details
#method_name(aProductionName) ⇒ String
Default method name to invoke when production with given name is invoked. Override this method for other method naming convention.
39 40 41 |
# File 'lib/rley/parse_rep/ast_base_builder.rb', line 39 def method_name(aProductionName) "reduce_#{aProductionName}" end |
#return_epsilon(_range, _tokens, _children) ⇒ Object
Simply return an epsilon symbol
74 75 76 |
# File 'lib/rley/parse_rep/ast_base_builder.rb', line 74 def return_epsilon(_range, _tokens, _children) nil end |
#return_first_child(_range, _tokens, theChildren) ⇒ Object
Utility method. Simply return the first child node
48 49 50 |
# File 'lib/rley/parse_rep/ast_base_builder.rb', line 48 def return_first_child(_range, _tokens, theChildren) theChildren[0] end |
#return_last_child(_range, _tokens, theChildren) ⇒ Object
Utility method. Simply return the last child node
66 67 68 |
# File 'lib/rley/parse_rep/ast_base_builder.rb', line 66 def return_last_child(_range, _tokens, theChildren) theChildren[-1] end |
#return_second_child(_range, _tokens, theChildren) ⇒ Object
Utility method. Simply return the second child node
57 58 59 |
# File 'lib/rley/parse_rep/ast_base_builder.rb', line 57 def return_second_child(_range, _tokens, theChildren) theChildren[1] end |
#terminal2node ⇒ Hash{String => Class}, Hash{String => Hash{String => Class}}
Method to override in subclass. Returns a Hash
23 24 25 |
# File 'lib/rley/parse_rep/ast_base_builder.rb', line 23 def terminal2node raise NotImplementedError end |
#terminalnode_class ⇒ Class
Method to override in subclass. Default class for representing terminal nodes.
30 31 32 |
# File 'lib/rley/parse_rep/ast_base_builder.rb', line 30 def terminalnode_class PTree::TerminalNode end |