Sha256: 3c5ea0e23e771db41efa30e5cc4bf8e65ae1a9e5eb87932251a410994b2e96fa

Contents?: true

Size: 1.96 KB

Versions: 68

Compression:

Stored size: 1.96 KB

Contents

# This module is an integral part of the evaluator. It deals with the concern of validating
# external syntax in text produced by heredoc and templates.
#
module Puppet::Pops::Evaluator::ExternalSyntaxSupport
  # TODO: This can be simplified if the Factory directly supporteded hash_of/type_of
  TYPES = Puppet::Pops::Types::TypeFactory

  def assert_external_syntax(scope, result, syntax, reference_expr)
    @@HASH_OF_SYNTAX_CHECKERS ||= TYPES.hash_of(TYPES.type_of(::Puppetx::SYNTAX_CHECKERS_TYPE))
    # ignore 'unspecified syntax'
    return if syntax.nil? || syntax == ''

    checker = checker_for_syntax(scope, syntax)
    # ignore syntax with no matching checker
    return unless checker

    # Call checker and give it the location information from the expression
    # (as opposed to where the heredoc tag is (somewhere on the line above)).
    acceptor = Puppet::Pops::Validation::Acceptor.new()
    source_pos = find_closest_positioned(reference_expr)
    checker.check(result, syntax, acceptor, source_pos)

    if acceptor.error_count > 0
      checker_message = "Invalid produced text having syntax: '#{syntax}'."
      Puppet::Pops::IssueReporter.assert_and_report(acceptor, :message => checker_message)
      raise ArgumentError, "Internal Error: Configuration of runtime error handling wrong: should have raised exception"
    end
  end

  # Finds the most significant checker for the given syntax (most significant is to the right).
  # Returns nil if there is no registered checker.
  #
  def checker_for_syntax(scope, syntax)
    checkers_hash = scope.compiler.injector.lookup(scope, @@HASH_OF_SYNTAX_CHECKERS, ::Puppetx::SYNTAX_CHECKERS) || {}
    checkers_hash[lookup_keys_for_syntax(syntax).find {|x| checkers_hash[x] }]
  end

  # Returns an array of possible syntax names
  def lookup_keys_for_syntax(syntax)
    segments = syntax.split(/\+/)
    result = []
    begin
      result << segments.join("+")
      segments.shift
    end until segments.empty?
    result
  end

end

Version data entries

68 entries across 68 versions & 2 rubygems

Version Path
puppet-3.7.3-x64-mingw32 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-3.7.2 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-3.7.2-x86-mingw32 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-3.7.2-x64-mingw32 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-3.7.1 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-3.7.1-x86-mingw32 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-3.7.1-x64-mingw32 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-3.7.0 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-3.7.0-x86-mingw32 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-3.7.0-x64-mingw32 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-3.6.2 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-3.6.2-x86-mingw32 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-3.6.1 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-3.6.1-x86-mingw32 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-3.6.0 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-3.6.0-x86-mingw32 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-3.6.0.rc1 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-3.6.0.rc1-x86-mingw32 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-3.5.1 lib/puppet/pops/evaluator/external_syntax_support.rb
puppet-3.5.1-x86-mingw32 lib/puppet/pops/evaluator/external_syntax_support.rb