Class: Rley::ParseRep::ParseTreeBuilder
- Inherits:
-
Object
- Object
- Rley::ParseRep::ParseTreeBuilder
- Defined in:
- lib/rley/parse_rep/parse_tree_builder.rb
Overview
The purpose of a ParseTreeBuilder is to build piece by piece a parse 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.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Link to Parse tree object (being) built.
-
#tokens ⇒ Array<Token>
readonly
The sequence of input tokens.
Instance Method Summary collapse
-
#done! ⇒ Object
Notify the builder that the parse tree construction is complete.
-
#initialize(theTokens) ⇒ ParseTreeBuilder
constructor
Create a new builder instance.
-
#receive_event(anEvent, anEntry, anIndex) ⇒ Object
Receive events resulting from a visit of GFGParsing object.
Constructor Details
#initialize(theTokens) ⇒ ParseTreeBuilder
Create a new builder instance.
44 45 46 47 48 |
# File 'lib/rley/parse_rep/parse_tree_builder.rb', line 44 def initialize(theTokens) @tokens = theTokens @stack = [] @dummy_node = Object.new.freeze end |
Instance Attribute Details
#result ⇒ Object (readonly)
Link to Parse tree object (being) built.
39 40 41 |
# File 'lib/rley/parse_rep/parse_tree_builder.rb', line 39 def result @result end |
#tokens ⇒ Array<Token> (readonly)
Returns The sequence of input tokens.
36 37 38 |
# File 'lib/rley/parse_rep/parse_tree_builder.rb', line 36 def tokens @tokens end |
Instance Method Details
#done! ⇒ Object
Notify the builder that the parse tree construction is complete.
51 52 53 |
# File 'lib/rley/parse_rep/parse_tree_builder.rb', line 51 def done!() result.done! end |
#receive_event(anEvent, anEntry, anIndex) ⇒ Object
Receive events resulting from a visit of GFGParsing object. These events are produced by a specialized Enumerator created with a ParseWalkerFactory instance.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rley/parse_rep/parse_tree_builder.rb', line 61 def receive_event(anEvent, anEntry, anIndex) # puts "Event: #{anEvent} #{anEntry} #{anIndex}" if anEntry.dotted_entry? # N => alpha . beta pattern? process_item_entry(anEvent, anEntry, anIndex) elsif anEntry.start_entry? # .N pattern? process_start_entry(anEvent, anEntry, anIndex) elsif anEntry.end_entry? # N. pattern? process_end_entry(anEvent, anEntry, anIndex) else raise NotImplementedError end @last_visitee = anEntry end |