class Rley::ParseRep::CSTBuilder
The purpose of a CSTBuilder
is to build piece by piece a CST (Concrete Syntax
Tree) from a sequence of input tokens and visit events produced by walking over a GFGParsing object. Uses 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.
Protected Instance Methods
Source
# File lib/rley/parse_rep/cst_builder.rb, line 23 def create_tree(aRootNode) return Rley::PTree::ParseTree.new(aRootNode) end
Method to override Create a parse tree object with given node as root node.
Source
# File lib/rley/parse_rep/cst_builder.rb, line 33 def new_leaf_node(_production, _terminal, aTokenPosition, aToken) PTree::TerminalNode.new(aToken, aTokenPosition) end
Method to override Factory method for creating a node object for the given input token. @param _terminal [Terminal] Terminal symbol associated with the token @param aTokenPosition [Integer] Position of token in the input stream @param aToken [Token] The input token
Source
# File lib/rley/parse_rep/cst_builder.rb, line 43 def new_parent_node(aProduction, aRange, _tokens, theChildren) node = Rley::PTree::NonTerminalNode.new(aProduction.lhs, aRange) theChildren&.reverse_each { |child| node.add_subnode(child) } node end
Method to override. Factory method for creating a parent node object. @param aProduction [Production] Production rule @param aRange [Range] Range of tokens matched by the rule @param _tokens [Array] The input tokens @param theChildren [Array] Children nodes (one per rhs symbol)