Class: Rley::ParseRep::ParseRepCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/rley/parse_rep/parse_rep_creator.rb

Overview

Utility class that helps to create a representation of a parse from a given Parsing object.

Direct Known Subclasses

ParseForestFactory, ParseTreeFactory

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aParsingResult) ⇒ ParseRepCreator

Constructor. Creates and initialize a ParseRepCreator instance.



16
17
18
# File 'lib/rley/parse_rep/parse_rep_creator.rb', line 16

def initialize(aParsingResult)
  @parsing = aParsingResult
end

Instance Attribute Details

#parsingRley::Parser::GFGParsing (readonly)

Returns Link to Parsing object (= results of recognizer).

Returns:



12
13
14
# File 'lib/rley/parse_rep/parse_rep_creator.rb', line 12

def parsing
  @parsing
end

Instance Method Details

#create(aBuilder = nil) ⇒ Rley::PTree::ParseTree, Rley::SPPF::ParseForest

Factory method that produces the representation of the parse.

Returns:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rley/parse_rep/parse_rep_creator.rb', line 23

def create(aBuilder = nil)
  a_walker = walker(parsing)
  a_builder = builder(parsing, aBuilder)

  begin
    loop do
      event = a_walker.next
      # puts "EVENT #{event[0]} #{event[1]}"
      a_builder.receive_event(*event)
    end
  rescue StopIteration
    # Do nothing: gobble the exception
  rescue StandardError => e
    if e.message =~ /^Ambiguous/
      $stderr.puts parsing
    end
    raise e
  end

  a_builder.done!

  a_builder.result
end