Class: Puppet::Parser::BoltCompiler

Inherits:
Compiler
  • Object
show all
Defined in:
lib/bolt/catalog/compiler.rb

Instance Method Summary collapse

Instance Method Details

#dump_ast(ast) ⇒ Object



13
14
15
# File 'lib/bolt/catalog/compiler.rb', line 13

def dump_ast(ast)
  Puppet::Pops::Serialization::ToDataConverter.convert(ast, rich_data: true, symbol_to_string: true)
end

#evaluate_mainObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/bolt/catalog/compiler.rb', line 25

def evaluate_main
  main = Puppet.lookup(:pal_main)
  ast = if main.is_a?(String)
          parse_string(main)
        else
          load_ast(main)
        end

  bridge = Puppet::Parser::AST::PopsBridge::Program.new(ast)

  # This is more or less copypaste from the super but we don't use the
  # original host_class.
  krt = environment.known_resource_types
  @main = krt.add(Puppet::Resource::Type.new(:hostclass, '', code: bridge))
  @topscope.source = @main
  @main_resource = Puppet::Parser::Resource.new('class', :main, scope: @topscope, source: @main)
  @topscope.resource = @main_resource
  add_resource(@topscope, @main_resource)

  @main_resource.evaluate
end

#internal_evaluatorObject



9
10
11
# File 'lib/bolt/catalog/compiler.rb', line 9

def internal_evaluator
  @internal_evaluator ||= Puppet::Pops::Parser::EvaluatingParser.new
end

#load_ast(ast_data) ⇒ Object



17
18
19
# File 'lib/bolt/catalog/compiler.rb', line 17

def load_ast(ast_data)
  Puppet::Pops::Serialization::FromDataConverter.convert(ast_data)
end

#parse_string(string, file = '') ⇒ Object



21
22
23
# File 'lib/bolt/catalog/compiler.rb', line 21

def parse_string(string, file = '')
  internal_evaluator.parse_string(string, file)
end