Module: Puppet::Pops::Evaluator::ExternalSyntaxSupport

Included in:
EvaluatorImpl
Defined in:
lib/puppet/pops/evaluator/external_syntax_support.rb

Instance Method Summary collapse

Instance Method Details

#assert_external_syntax(scope, result, syntax, reference_expr) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/puppet/pops/evaluator/external_syntax_support.rb', line 6

def assert_external_syntax(scope, result, syntax, reference_expr)
  # 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()
  checker.check(result, syntax, acceptor, reference_expr)

  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

#checker_for_syntax(scope, syntax) ⇒ Object

Finds the most significant checker for the given syntax (most significant is to the right). Returns nil if there is no registered checker.



29
30
31
32
# File 'lib/puppet/pops/evaluator/external_syntax_support.rb', line 29

def checker_for_syntax(scope, syntax)
  checkers_hash = Puppet.lookup(:plugins)[Puppet::Plugins::SyntaxCheckers::SYNTAX_CHECKERS_KEY]
  checkers_hash[lookup_keys_for_syntax(syntax).find {|x| checkers_hash[x] }]
end

#lookup_keys_for_syntax(syntax) ⇒ Object

Returns an array of possible syntax names



35
36
37
38
39
40
41
42
43
# File 'lib/puppet/pops/evaluator/external_syntax_support.rb', line 35

def lookup_keys_for_syntax(syntax)
  segments = syntax.split(/\+/)
  result = []
  begin
    result << segments.join("+")
    segments.shift
  end until segments.empty?
  result
end