Class: Bake::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/bake/model/loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLoader

Returns a new instance of Loader.



22
23
24
25
26
27
28
29
# File 'lib/bake/model/loader.rb', line 22

def initialize
  @env = RGen::Environment.new

  fcm = RGen::Util::FileCacheMap.new(".bake", ".cache")
  fcm.version_info = Version.number
  @DumpFileCache = RGen::Fragment::DumpFileCache.new(fcm)
  @model = RGen::Fragment::FragmentedModel.new(:env => @env)
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



20
21
22
# File 'lib/bake/model/loader.rb', line 20

def model
  @model
end

Instance Method Details

#load(filename) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/bake/model/loader.rb', line 31

def load(filename)
  sumErrors = 0

  if Bake.options.nocache
    def @DumpFileCache.load(fragment)
      :invalid
    end
  end
        
  if not File.exists?filename
    Bake.formatter.printError("Error: #{filename} does not exist")
    ExitHelper.exit(1) 
  end

  loader = RText::DefaultLoader.new(
    Bake::Language,
    @model,
    :file_provider => proc { [filename] },
    :cache => @DumpFileCache)
  loader.load(:before_load => proc {|fragment, kind|
    case kind
    when :load_update_cache
      if Bake.options.verbose >= 3
        puts "Loading and caching #{fragment.location}"
      else
        puts "Loading #{fragment.location}"
      end
    when :load_cached
      if Bake.options.verbose >= 3
        puts "Loading cached #{fragment.location}"
      else
        puts "Loading #{fragment.location}"
      end
    when :load
      puts "Loading #{fragment.location}"
    else
      Bake.formatter.printError("Error: Could not load #{fragment.location}")
      ExitHelper.exit(1)     
    end
  })

  f = @model.fragments[0]
  @model.remove_fragment(f)

  f.data[:problems].each do |p|
    Bake.formatter.printError(p.message, p.file, p.line)
  end
  
  if f.data[:problems].length > 0
    ExitHelper.exit(1) 
  end
  
  return f

end