Class: Puppet::Pops::Parser::EvaluatingParser
Overview
Does not support “import” and parsing ruby files
Defined Under Namespace
Classes: EvaluatingEppParser
Instance Attribute Summary collapse
Class Method Summary
collapse
-
.quote(x) ⇒ String
Translates an already parsed string that contains control characters, quotes and backslashes into a quoted string where all such constructs have been escaped.
Instance Method Summary
collapse
-
#acceptor ⇒ Object
-
#assert_and_report(parse_result, file_source) ⇒ Object
-
#clear ⇒ Object
-
#closure(model, scope) ⇒ Object
Create a closure that can be called in the given scope.
-
#convert_to_3x(object, scope) ⇒ Object
-
#evaluate(scope, model) ⇒ Object
-
#evaluate_expression_with_bindings(scope, variable_bindings, expression) ⇒ Object
Evaluates the given expression in a local scope with the given variable bindings set in this local scope, returns what the expression returns.
-
#evaluate_file(scope, file) ⇒ Object
-
#evaluate_string(scope, s, file_source = nil) ⇒ Object
-
#evaluator ⇒ Object
-
#initialize ⇒ EvaluatingParser
constructor
A new instance of EvaluatingParser.
-
#parse_file(file) ⇒ Object
-
#parse_string(s, file_source = nil) ⇒ Object
-
#quote(x) ⇒ Object
-
#validate(parse_result) ⇒ Object
-
#validator(acceptor) ⇒ Object
singleton
Constructor Details
Returns a new instance of EvaluatingParser.
13
14
15
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 13
def initialize()
@parser = Parser.new()
end
|
Instance Attribute Details
11
12
13
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 11
def parser
@parser
end
|
Class Method Details
.quote(x) ⇒ String
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 ??
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 126
def self.quote(x)
escaped = '"'
p = nil
x.each_char do |c|
case p
when nil
when "\t"
escaped << '\\t'
when "\n"
escaped << '\\n'
when "\f"
escaped << '\\f'
when '"'
escaped << '\\"'
when '\\'
escaped << if c == '$' || c == 's'; p; else '\\\\'; end else
escaped << p
end
p = c
end
escaped << p unless p.nil?
escaped << '"'
end
|
Instance Method Details
89
90
91
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 89
def acceptor()
Validation::Acceptor.new
end
|
#assert_and_report(parse_result, file_source) ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 97
def assert_and_report(parse_result, file_source)
return nil unless parse_result
if parse_result['source_ref'].nil? || parse_result['source_ref'] == ''
parse_result['source_ref'] = file_source
end
validation_result = validate(parse_result.model)
IssueReporter.assert_and_report(validation_result,
:emit_warnings => true)
parse_result
end
|
49
50
51
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 49
def clear()
@acceptor = nil
end
|
#closure(model, scope) ⇒ Object
Create a closure that can be called in the given scope
54
55
56
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 54
def closure(model, scope)
Evaluator::Closure::Dynamic.new(evaluator, model, scope)
end
|
#convert_to_3x(object, scope) ⇒ Object
79
80
81
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 79
def convert_to_3x(object, scope)
evaluator.convert(object, scope, nil)
end
|
#evaluate(scope, model) ⇒ Object
58
59
60
61
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 58
def evaluate(scope, model)
return nil unless model
evaluator.evaluate(model, scope)
end
|
#evaluate_expression_with_bindings(scope, variable_bindings, expression) ⇒ Object
Evaluates the given expression in a local scope with the given variable bindings set in this local scope, returns what the expression returns.
66
67
68
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 66
def evaluate_expression_with_bindings(scope, variable_bindings, expression)
evaluator.evaluate_block_with_bindings(scope, variable_bindings, expression)
end
|
#evaluate_file(scope, file) ⇒ Object
45
46
47
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 45
def evaluate_file(scope, file)
evaluate(scope, parse_file(file))
end
|
#evaluate_string(scope, s, file_source = nil) ⇒ Object
41
42
43
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 41
def evaluate_string(scope, s, file_source = nil)
evaluate(scope, parse_string(s, file_source))
end
|
#parse_file(file) ⇒ Object
36
37
38
39
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 36
def parse_file(file)
clear()
assert_and_report(parser.parse_file(file), file).model
end
|
#parse_string(s, file_source = nil) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 17
def parse_string(s, file_source = nil)
clear()
begin
assert_and_report(parser.parse_string(s, file_source), file_source).model
rescue Puppet::ParseErrorWithIssue => e
raise e
rescue Puppet::ParseError => e
e.file = file_source unless e.file.is_a?(String) && !e.file.empty?
raise e
end
end
|
109
110
111
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 109
def quote(x)
self.class.quote(x)
end
|
#validate(parse_result) ⇒ Object
83
84
85
86
87
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 83
def validate(parse_result)
resulting_acceptor = acceptor()
validator(resulting_acceptor).validate(parse_result)
resulting_acceptor
end
|