class Puppet::Pops::Parser::EvaluatingParser
Does not support “import” and parsing ruby files
Attributes
Public Class Methods
# File lib/puppet/pops/parser/evaluating_parser.rb 13 def initialize() 14 @parser = Parser.new() 15 end
Translates an already parsed string that contains control characters, quotes and backslashes into a quoted string where all such constructs have been escaped. Parsing the return value of this method using the puppet parser should yield exactly the same string as the argument passed to this method
The method makes an exception for the two character sequences $ and s. They will not be escaped since they have a special meaning in puppet syntax.
TODO: Handle uXXXX characters ??
@param x [String] The string to quote and “unparse” @return [String] The quoted string
# File lib/puppet/pops/parser/evaluating_parser.rb 126 def self.quote(x) 127 escaped = '"' 128 p = nil 129 x.each_char do |c| 130 case p 131 when nil 132 # do nothing 133 when "\t" 134 escaped << '\\t' 135 when "\n" 136 escaped << '\\n' 137 when "\f" 138 escaped << '\\f' 139 # TODO: \cx is a range of characters - skip for now 140 # when "\c" 141 # escaped << '\\c' 142 when '"' 143 escaped << '\\"' 144 when '\\' 145 escaped << if c == '$' || c == 's'; p; else '\\\\'; end # don't escape \ when followed by s or $ 146 else 147 escaped << p 148 end 149 p = c 150 end 151 escaped << p unless p.nil? 152 escaped << '"' 153 end
Public Instance Methods
# File lib/puppet/pops/parser/evaluating_parser.rb 89 def acceptor() 90 Validation::Acceptor.new 91 end
# File lib/puppet/pops/parser/evaluating_parser.rb 97 def assert_and_report(parse_result, file_source) 98 return nil unless parse_result 99 if parse_result['source_ref'].nil? || parse_result['source_ref'] == '' 100 parse_result['source_ref'] = file_source 101 end 102 validation_result = validate(parse_result.model) 103 104 IssueReporter.assert_and_report(validation_result, 105 :emit_warnings => true) 106 parse_result 107 end
# File lib/puppet/pops/parser/evaluating_parser.rb 49 def clear() 50 @acceptor = nil 51 end
Create a closure that can be called in the given scope
# File lib/puppet/pops/parser/evaluating_parser.rb 54 def closure(model, scope) 55 Evaluator::Closure::Dynamic.new(evaluator, model, scope) 56 end
# File lib/puppet/pops/parser/evaluating_parser.rb 79 def convert_to_3x(object, scope) 80 evaluator.convert(object, scope, nil) 81 end
# File lib/puppet/pops/parser/evaluating_parser.rb 58 def evaluate(scope, model) 59 return nil unless model 60 evaluator.evaluate(model, scope) 61 end
Evaluates the given expression in a local scope with the given variable bindings set in this local scope, returns what the expression returns.
# File lib/puppet/pops/parser/evaluating_parser.rb 66 def evaluate_expression_with_bindings(scope, variable_bindings, expression) 67 evaluator.evaluate_block_with_bindings(scope, variable_bindings, expression) 68 end
# File lib/puppet/pops/parser/evaluating_parser.rb 45 def evaluate_file(scope, file) 46 evaluate(scope, parse_file(file)) 47 end
# File lib/puppet/pops/parser/evaluating_parser.rb 41 def evaluate_string(scope, s, file_source = nil) 42 evaluate(scope, parse_string(s, file_source)) 43 end
# File lib/puppet/pops/parser/evaluating_parser.rb 70 def evaluator 71 # Do not use the cached evaluator if this is a migration run 72 if (Puppet.lookup(:migration_checker) { nil }) 73 return Evaluator::EvaluatorImpl.new() 74 end 75 @@evaluator ||= Evaluator::EvaluatorImpl.new() 76 @@evaluator 77 end
# File lib/puppet/pops/parser/evaluating_parser.rb 36 def parse_file(file) 37 clear() 38 assert_and_report(parser.parse_file(file), file).model 39 end
# File lib/puppet/pops/parser/evaluating_parser.rb 17 def parse_string(s, file_source = nil) 18 clear() 19 # Handling of syntax error can be much improved (in general), now it bails out of the parser 20 # and does not have as rich information (when parsing a string), need to update it with the file source 21 # (ideally, a syntax error should be entered as an issue, and not just thrown - but that is a general problem 22 # and an improvement that can be made in the eparser (rather than here). 23 # Also a possible improvement (if the YAML parser returns positions) is to provide correct output of position. 24 # 25 begin 26 assert_and_report(parser.parse_string(s, file_source), file_source).model 27 rescue Puppet::ParseErrorWithIssue => e 28 raise e 29 rescue Puppet::ParseError => e 30 # TODO: This is not quite right, why does not the exception have the correct file? 31 e.file = file_source unless e.file.is_a?(String) && !e.file.empty? 32 raise e 33 end 34 end
# File lib/puppet/pops/parser/evaluating_parser.rb 109 def quote(x) 110 self.class.quote(x) 111 end
# File lib/puppet/pops/parser/evaluating_parser.rb 83 def validate(parse_result) 84 resulting_acceptor = acceptor() 85 validator(resulting_acceptor).validate(parse_result) 86 resulting_acceptor 87 end
# File lib/puppet/pops/parser/evaluating_parser.rb 93 def validator(acceptor) 94 Validation::ValidatorFactory_4_0.new().validator(acceptor) 95 end