Class: Puppet::Pops::Parser::EvaluatingParser
- Inherits:
-
Object
- Object
- Puppet::Pops::Parser::EvaluatingParser
show all
- Defined in:
- lib/puppet/pops/parser/evaluating_parser.rb
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
Constructor Details
Returns a new instance of EvaluatingParser.
8
9
10
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 8
def initialize()
@parser = Puppet::Pops::Parser::Parser.new()
end
|
Instance Attribute Details
6
7
8
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 6
def parser
@parser
end
|
Class Method Details
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 ??
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 110
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
#assert_and_report(parse_result) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 81
def assert_and_report(parse_result)
return nil unless parse_result
if parse_result.source_ref.nil? or parse_result.source_ref == ''
parse_result.source_ref = @file_source
end
validation_result = validate(parse_result)
Puppet::Pops::IssueReporter.assert_and_report(validation_result,
:emit_warnings => true)
parse_result
end
|
44
45
46
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 44
def clear()
@acceptor = nil
end
|
#closure(model, scope) ⇒ Object
Create a closure that can be called in the given scope
49
50
51
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 49
def closure(model, scope)
Puppet::Pops::Evaluator::Closure.new(evaluator, model, scope)
end
|
#convert_to_3x(object, scope) ⇒ Object
63
64
65
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 63
def convert_to_3x(object, scope)
val = @@evaluator.convert(object, scope, nil)
end
|
#evaluate(scope, model) ⇒ Object
53
54
55
56
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 53
def evaluate(scope, model)
return nil unless model
evaluator.evaluate(model, scope)
end
|
#evaluate_file(file) ⇒ Object
40
41
42
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 40
def evaluate_file(file)
evaluate(parse_file(file))
end
|
#evaluate_string(scope, s, file_source = 'unknown') ⇒ Object
36
37
38
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 36
def evaluate_string(scope, s, file_source='unknown')
evaluate(scope, parse_string(s, file_source))
end
|
#parse_file(file) ⇒ Object
30
31
32
33
34
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 30
def parse_file(file)
@file_source = file
clear()
assert_and_report(parser.parse_file(file))
end
|
#parse_string(s, file_source = 'unknown') ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 12
def parse_string(s, file_source = 'unknown')
@file_source = file_source
clear()
begin
assert_and_report(parser.parse_string(s))
rescue Puppet::ParseError => e
e.file = @file_source unless e.file.is_a?(String) && !e.file.empty?
raise e
end
end
|
93
94
95
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 93
def quote(x)
self.class.quote(x)
end
|
#validate(parse_result) ⇒ Object
67
68
69
70
71
|
# File 'lib/puppet/pops/parser/evaluating_parser.rb', line 67
def validate(parse_result)
resulting_acceptor = acceptor()
validator(resulting_acceptor).validate(parse_result)
resulting_acceptor
end
|