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.
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.
37 38 39 |
# File 'lib/rley/parse_rep/ast_base_builder.rb', line 37 def method_name(aProductionName) return 'reduce_' + aProductionName end |
#return_epsilon(_range, _tokens, _children) ⇒ Object
Simply return an epsilon symbol
72 73 74 |
# File 'lib/rley/parse_rep/ast_base_builder.rb', line 72 def return_epsilon(_range, _tokens, _children) return nil end |
#return_first_child(_range, _tokens, theChildren) ⇒ Object
Utility method. Simply return the first child node
46 47 48 |
# File 'lib/rley/parse_rep/ast_base_builder.rb', line 46 def return_first_child(_range, _tokens, theChildren) return theChildren[0] end |
#return_last_child(_range, _tokens, theChildren) ⇒ Object
Utility method. Simply return the last child node
64 65 66 |
# File 'lib/rley/parse_rep/ast_base_builder.rb', line 64 def return_last_child(_range, _tokens, theChildren) return theChildren[-1] end |
#return_second_child(_range, _tokens, theChildren) ⇒ Object
Utility method. Simply return the second child node
55 56 57 |
# File 'lib/rley/parse_rep/ast_base_builder.rb', line 55 def return_second_child(_range, _tokens, theChildren) return theChildren[1] end |
#terminal2node ⇒ Hash{String => Class}, Hash{String => Hash{String => Class}}
Method to override in subclass. Returns a Hash
21 22 23 |
# File 'lib/rley/parse_rep/ast_base_builder.rb', line 21 def terminal2node() raise NotImplementedError end |
#terminalnode_class ⇒ Class
Method to override in subclass. Default class for representing terminal nodes.
28 29 30 |
# File 'lib/rley/parse_rep/ast_base_builder.rb', line 28 def terminalnode_class() PTree::TerminalNode end |