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 14 def initialize() 15 @parser = Parser.new() 16 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 127 def self.quote(x) 128 escaped = String.new('"') 129 p = nil 130 x.each_char do |c| 131 case p 132 when nil 133 # do nothing 134 when "\t" 135 escaped << '\\t' 136 when "\n" 137 escaped << '\\n' 138 when "\f" 139 escaped << '\\f' 140 # TODO: \cx is a range of characters - skip for now 141 # when "\c" 142 # escaped << '\\c' 143 when '"' 144 escaped << '\\"' 145 when '\\' 146 escaped << if c == '$' || c == 's'; p; else '\\\\'; end # don't escape \ when followed by s or $ 147 else 148 escaped << p 149 end 150 p = c 151 end 152 escaped << p unless p.nil? 153 escaped << '"' 154 end
Public Instance Methods
# File lib/puppet/pops/parser/evaluating_parser.rb 90 def acceptor() 91 Validation::Acceptor.new 92 end
# File lib/puppet/pops/parser/evaluating_parser.rb 98 def assert_and_report(parse_result, file_source) 99 return nil unless parse_result 100 if parse_result['source_ref'].nil? || parse_result['source_ref'] == '' 101 parse_result['source_ref'] = file_source 102 end 103 validation_result = validate(parse_result.model) 104 105 IssueReporter.assert_and_report(validation_result, 106 :emit_warnings => true) 107 parse_result 108 end
# File lib/puppet/pops/parser/evaluating_parser.rb 50 def clear() 51 @acceptor = nil 52 end
Create a closure that can be called in the given scope
# File lib/puppet/pops/parser/evaluating_parser.rb 55 def closure(model, scope) 56 Evaluator::Closure::Dynamic.new(evaluator, model, scope) 57 end
# File lib/puppet/pops/parser/evaluating_parser.rb 80 def convert_to_3x(object, scope) 81 evaluator.convert(object, scope, nil) 82 end
# File lib/puppet/pops/parser/evaluating_parser.rb 59 def evaluate(scope, model) 60 return nil unless model 61 evaluator.evaluate(model, scope) 62 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 67 def evaluate_expression_with_bindings(scope, variable_bindings, expression) 68 evaluator.evaluate_block_with_bindings(scope, variable_bindings, expression) 69 end
# File lib/puppet/pops/parser/evaluating_parser.rb 46 def evaluate_file(scope, file) 47 evaluate(scope, parse_file(file)) 48 end
# File lib/puppet/pops/parser/evaluating_parser.rb 42 def evaluate_string(scope, s, file_source = nil) 43 evaluate(scope, parse_string(s, file_source)) 44 end
# File lib/puppet/pops/parser/evaluating_parser.rb 71 def evaluator 72 # Do not use the cached evaluator if this is a migration run 73 if (Puppet.lookup(:migration_checker) { nil }) 74 return Evaluator::EvaluatorImpl.new() 75 end 76 @@evaluator ||= Evaluator::EvaluatorImpl.new() 77 @@evaluator 78 end
# File lib/puppet/pops/parser/evaluating_parser.rb 37 def parse_file(file) 38 clear() 39 assert_and_report(parser.parse_file(file), file).model 40 end
# File lib/puppet/pops/parser/evaluating_parser.rb 18 def parse_string(s, file_source = nil) 19 clear() 20 # Handling of syntax error can be much improved (in general), now it bails out of the parser 21 # and does not have as rich information (when parsing a string), need to update it with the file source 22 # (ideally, a syntax error should be entered as an issue, and not just thrown - but that is a general problem 23 # and an improvement that can be made in the eparser (rather than here). 24 # Also a possible improvement (if the YAML parser returns positions) is to provide correct output of position. 25 # 26 begin 27 assert_and_report(parser.parse_string(s, file_source), file_source).model 28 rescue Puppet::ParseErrorWithIssue => e 29 raise e 30 rescue Puppet::ParseError => e 31 # TODO: This is not quite right, why does not the exception have the correct file? 32 e.file = file_source unless e.file.is_a?(String) && !e.file.empty? 33 raise e 34 end 35 end
# File lib/puppet/pops/parser/evaluating_parser.rb 110 def quote(x) 111 self.class.quote(x) 112 end
# File lib/puppet/pops/parser/evaluating_parser.rb 84 def validate(parse_result) 85 resulting_acceptor = acceptor() 86 validator(resulting_acceptor).validate(parse_result) 87 resulting_acceptor 88 end
# File lib/puppet/pops/parser/evaluating_parser.rb 94 def validator(acceptor) 95 Validation::ValidatorFactory_4_0.new().validator(acceptor) 96 end