class Puppet::Pops::Parser::CodeMerger

Public Instance Methods

concatenate(parse_results) click to toggle source

Concatenates the logic in the array of parse results into one parse result. @return Puppet::Parser::AST::BlockExpression

   # File lib/puppet/pops/parser/code_merger.rb
 8 def concatenate(parse_results)
 9   # this is a bit brute force as the result is already 3x ast with wrapped 4x content
10   # this could be combined in a more elegant way, but it is only used to process a handful of files
11   # at the beginning of a puppet run. TODO: Revisit for Puppet 4x when there is no 3x ast at the top.
12   # PUP-5299, some sites have thousands of entries, and run out of stack when evaluating - the logic
13   # below maps the logic as flatly as possible.
14   #
15   children = parse_results.select {|x| !x.nil? && x.code}.flat_map do |parsed_class|
16     case parsed_class.code
17     when Puppet::Parser::AST::BlockExpression
18       # the BlockExpression wraps a single 4x instruction that is most likely wrapped in a Factory
19       parsed_class.code.children.map {|c| c.is_a?(Puppet::Pops::Model::Factory) ? c.model : c }
20     when Puppet::Pops::Model::Factory
21       # If it is a 4x instruction wrapped in a Factory
22       parsed_class.code.model
23     else
24       # It is the instruction directly
25       parsed_class.code
26     end
27   end
28   Puppet::Parser::AST::BlockExpression.new(:children => children)
29 end