puppet 4.3.1-x86-mingw32 → 4.3.2-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of puppet might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/ext/build_defaults.yaml +1 -1
- data/lib/hiera/scope.rb +1 -1
- data/lib/puppet/application/lookup.rb +41 -43
- data/lib/puppet/data_providers/lookup_adapter.rb +73 -26
- data/lib/puppet/functions/lookup.rb +126 -150
- data/lib/puppet/functions/match.rb +1 -0
- data/lib/puppet/indirector/hiera.rb +3 -1
- data/lib/puppet/indirector/indirection.rb +6 -2
- data/lib/puppet/indirector/json.rb +2 -2
- data/lib/puppet/module.rb +3 -2
- data/lib/puppet/node.rb +11 -2
- data/lib/puppet/parser/compiler.rb +1 -8
- data/lib/puppet/parser/functions/lookup.rb +128 -149
- data/lib/puppet/parser/functions/match.rb +1 -0
- data/lib/puppet/plugins/data_providers/data_provider.rb +3 -2
- data/lib/puppet/pops/adapters.rb +43 -0
- data/lib/puppet/pops/evaluator/access_operator.rb +3 -3
- data/lib/puppet/pops/evaluator/closure.rb +51 -51
- data/lib/puppet/pops/evaluator/collector_transformer.rb +16 -0
- data/lib/puppet/pops/evaluator/runtime3_support.rb +11 -2
- data/lib/puppet/pops/functions/function.rb +6 -2
- data/lib/puppet/pops/issues.rb +16 -0
- data/lib/puppet/pops/loader/puppet_function_instantiator.rb +3 -2
- data/lib/puppet/pops/lookup.rb +3 -0
- data/lib/puppet/pops/lookup/explainer.rb +73 -3
- data/lib/puppet/pops/lookup/invocation.rb +21 -19
- data/lib/puppet/pops/model/factory.rb +153 -155
- data/lib/puppet/pops/model/model.rb +9 -0
- data/lib/puppet/pops/model/model_label_provider.rb +1 -0
- data/lib/puppet/pops/parser/evaluating_parser.rb +3 -3
- data/lib/puppet/pops/parser/lexer2.rb +411 -393
- data/lib/puppet/pops/parser/slurp_support.rb +5 -1
- data/lib/puppet/pops/types/type_calculator.rb +2 -6
- data/lib/puppet/pops/types/types.rb +3 -9
- data/lib/puppet/pops/validation/checker4_0.rb +36 -12
- data/lib/puppet/provider/group/windows_adsi.rb +2 -2
- data/lib/puppet/provider/package/pip.rb +11 -1
- data/lib/puppet/provider/package/rpm.rb +0 -1
- data/lib/puppet/provider/package/yum.rb +1 -1
- data/lib/puppet/provider/service/debian.rb +5 -18
- data/lib/puppet/provider/service/init.rb +7 -0
- data/lib/puppet/provider/service/launchd.rb +6 -0
- data/lib/puppet/provider/service/systemd.rb +1 -1
- data/lib/puppet/provider/user/windows_adsi.rb +2 -2
- data/lib/puppet/provider/yumrepo/inifile.rb +6 -3
- data/lib/puppet/resource/type.rb +2 -1
- data/lib/puppet/transaction/additional_resource_generator.rb +17 -3
- data/lib/puppet/type/group.rb +6 -2
- data/lib/puppet/util/windows.rb +4 -0
- data/lib/puppet/util/windows/adsi.rb +61 -24
- data/lib/puppet/util/windows/principal.rb +181 -0
- data/lib/puppet/util/windows/registry.rb +21 -15
- data/lib/puppet/util/windows/sid.rb +42 -11
- data/lib/puppet/version.rb +1 -1
- data/spec/fixtures/unit/application/environments/production/data/common.yaml +4 -0
- data/spec/fixtures/unit/application/environments/production/manifests/site.pp +1 -0
- data/spec/fixtures/unit/application/environments/puppet_func_provider/environment.conf +1 -0
- data/spec/fixtures/unit/application/environments/puppet_func_provider/functions/data.pp +10 -0
- data/spec/fixtures/unit/application/environments/puppet_func_provider/manifests/site.pp +1 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_module_config/data/common.yaml +4 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_module_config/data/specific.yaml +4 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_module_config/hiera.yaml +7 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/data/common.yaml +4 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/data/specific.yaml +4 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/environment.conf +2 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/hiera.yaml +7 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/manifests/site.pp +1 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/one/data/common.yaml +6 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/one/hiera.yaml +5 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/one/manifests/init.pp +2 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/one/metadata.json +9 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/two/data/common.yaml +4 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/two/hiera.yaml +5 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/two/manifests/init.pp +3 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/two/metadata.json +9 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee/functions/usee_puppet.pp +3 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/{usee → modules/usee}/lib/puppet/functions/usee/callee.rb +0 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee/lib/puppet/functions/usee/usee_ruby.rb +6 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee/manifests/init.pp +6 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee2/lib/puppet/functions/usee2/callee.rb +5 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/functions/puppet_calling_puppet.pp +5 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/functions/puppet_calling_puppet_init.pp +5 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/functions/puppet_calling_ruby.pp +5 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/{user → modules/user}/lib/puppet/functions/user/caller.rb +0 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/lib/puppet/functions/user/caller2.rb +5 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/lib/puppet/functions/user/ruby_calling_puppet.rb +5 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/lib/puppet/functions/user/ruby_calling_puppet_init.rb +5 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/lib/puppet/functions/user/ruby_calling_ruby.rb +5 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/manifests/init.pp +81 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/{user → modules/user}/metadata.json +2 -1
- data/spec/integration/parser/collection_spec.rb +8 -0
- data/spec/integration/util/windows/principal_spec.rb +115 -0
- data/spec/{unit → integration}/util/windows/registry_spec.rb +91 -1
- data/spec/integration/util/windows/security_spec.rb +2 -2
- data/spec/unit/application/lookup_spec.rb +138 -28
- data/spec/unit/data_providers/hiera_data_provider_spec.rb +182 -5
- data/spec/unit/face/epp_face_spec.rb +2 -2
- data/spec/unit/functions/epp_spec.rb +6 -6
- data/spec/unit/functions/inline_epp_spec.rb +4 -4
- data/spec/unit/functions/lookup_spec.rb +30 -3
- data/spec/unit/functions4_spec.rb +1 -1
- data/spec/unit/hiera/scope_spec.rb +5 -2
- data/spec/unit/indirector/json_spec.rb +1 -1
- data/spec/unit/node_spec.rb +8 -0
- data/spec/unit/parser/compiler_spec.rb +0 -18
- data/spec/unit/pops/evaluator/access_ops_spec.rb +4 -4
- data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +1 -1
- data/spec/unit/pops/loaders/loaders_spec.rb +84 -2
- data/spec/unit/pops/parser/lexer2_spec.rb +6 -0
- data/spec/unit/pops/parser/parser_rspec_helper.rb +5 -0
- data/spec/unit/pops/types/type_calculator_spec.rb +0 -17
- data/spec/unit/pops/validator/validator_spec.rb +87 -0
- data/spec/unit/provider/group/windows_adsi_spec.rb +8 -8
- data/spec/unit/provider/package/pip_spec.rb +41 -13
- data/spec/unit/provider/package/rpm_spec.rb +2 -25
- data/spec/unit/provider/package/yum_spec.rb +1 -1
- data/spec/unit/provider/service/debian_spec.rb +6 -24
- data/spec/unit/provider/service/init_spec.rb +11 -1
- data/spec/unit/provider/service/launchd_spec.rb +11 -0
- data/spec/unit/provider/service/systemd_spec.rb +18 -12
- data/spec/unit/provider/service/upstart_spec.rb +57 -0
- data/spec/unit/provider/user/windows_adsi_spec.rb +5 -5
- data/spec/unit/provider/yumrepo/inifile_spec.rb +16 -0
- data/spec/unit/resource_spec.rb +12 -2
- data/spec/unit/util/windows/adsi_spec.rb +44 -36
- data/spec/unit/util/windows/sid_spec.rb +47 -10
- metadata +77 -10
@@ -1,6 +1,7 @@
|
|
1
1
|
module Puppet::Pops::Lookup
|
2
2
|
class Invocation
|
3
|
-
attr_reader :scope, :override_values, :default_values, :explainer
|
3
|
+
attr_reader :scope, :override_values, :default_values, :explainer
|
4
|
+
attr_accessor :module_name, :top_key
|
4
5
|
|
5
6
|
# Creates a context object for a lookup invocation. The object contains the current scope, overrides, and default
|
6
7
|
# values and may optionally contain an {ExplanationAcceptor} instance that will receive book-keeping information
|
@@ -50,34 +51,31 @@ module Puppet::Pops::Lookup
|
|
50
51
|
# :merge - qualifier is a MergeStrategy instance
|
51
52
|
# :module - qualifier is the name of a module
|
52
53
|
# :interpolation - qualifier is the unresolved interpolation expression
|
53
|
-
# :meta - qualifier is the
|
54
|
+
# :meta - qualifier is the module name
|
55
|
+
# :data - qualifier is the key
|
54
56
|
#
|
55
57
|
# @param qualifier [Object] A branch, a provider, or a path
|
56
58
|
def with(qualifier_type, qualifier)
|
57
|
-
is_meta = qualifier_type == :meta
|
58
|
-
@module_name = qualifier if is_meta
|
59
59
|
if @explainer.nil?
|
60
60
|
yield
|
61
61
|
else
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
ensure
|
68
|
-
@explainer = save_explainer
|
69
|
-
end
|
70
|
-
else
|
71
|
-
@explainer.push(qualifier_type, qualifier)
|
72
|
-
begin
|
73
|
-
yield
|
74
|
-
ensure
|
75
|
-
@explainer.pop
|
76
|
-
end
|
62
|
+
@explainer.push(qualifier_type, qualifier)
|
63
|
+
begin
|
64
|
+
yield
|
65
|
+
ensure
|
66
|
+
@explainer.pop
|
77
67
|
end
|
78
68
|
end
|
79
69
|
end
|
80
70
|
|
71
|
+
def only_explain_options?
|
72
|
+
@explainer.nil? ? false : @explainer.only_explain_options?
|
73
|
+
end
|
74
|
+
|
75
|
+
def explain_options?
|
76
|
+
@explainer.nil? ? false : @explainer.explain_options?
|
77
|
+
end
|
78
|
+
|
81
79
|
def report_found_in_overrides(key, value)
|
82
80
|
@explainer.accept_found_in_overrides(key, value) unless @explainer.nil?
|
83
81
|
value
|
@@ -93,6 +91,10 @@ module Puppet::Pops::Lookup
|
|
93
91
|
value
|
94
92
|
end
|
95
93
|
|
94
|
+
def report_merge_source(merge_source)
|
95
|
+
@explainer.accept_merge_source(merge_source) unless @explainer.nil?
|
96
|
+
end
|
97
|
+
|
96
98
|
# Report the result of a merge or fully resolved interpolated string
|
97
99
|
# @param value [Object] The result to report
|
98
100
|
# @return [Object] the given value
|
@@ -6,49 +6,40 @@
|
|
6
6
|
# @todo All those uppercase methods ... they look bad in one way, but stand out nicely in the grammar...
|
7
7
|
# decide if they should change into lower case names (some of the are lower case)...
|
8
8
|
#
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
module Puppet::Pops
|
10
|
+
module Model
|
11
|
+
class Factory
|
12
12
|
attr_accessor :current
|
13
13
|
|
14
14
|
alias_method :model, :current
|
15
15
|
|
16
16
|
# Shared build_visitor, since there are many instances of Factory being used
|
17
|
-
@@build_visitor =
|
18
|
-
@@interpolation_visitor =
|
17
|
+
@@build_visitor = Visitor.new(self, "build")
|
18
|
+
@@interpolation_visitor = Visitor.new(self, "interpolate")
|
19
19
|
|
20
20
|
# Initialize a factory with a single object, or a class with arguments applied to build of
|
21
21
|
# created instance
|
22
22
|
#
|
23
|
-
def initialize
|
24
|
-
@current =
|
25
|
-
|
23
|
+
def initialize(o, *args)
|
24
|
+
@current = if o.instance_of?(Class)
|
25
|
+
@@build_visitor.visit_this(self, o.new, args)
|
26
|
+
elsif o.is_a?(PopsObject)
|
26
27
|
o
|
27
|
-
|
28
|
+
elsif o.instance_of?(Factory)
|
28
29
|
o.current
|
29
30
|
else
|
30
|
-
|
31
|
+
@@build_visitor.visit_this(self, o, args)
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
34
35
|
# Polymorphic build
|
35
36
|
def build(o, *args)
|
36
|
-
|
37
|
-
@@build_visitor.visit_this(self, o, args)
|
38
|
-
rescue =>e
|
39
|
-
# debug here when in trouble...
|
40
|
-
raise e
|
41
|
-
end
|
37
|
+
@@build_visitor.visit_this(self, o, args)
|
42
38
|
end
|
43
39
|
|
44
40
|
# Polymorphic interpolate
|
45
41
|
def interpolate()
|
46
|
-
|
47
|
-
@@interpolation_visitor.visit_this_0(self, current)
|
48
|
-
rescue =>e
|
49
|
-
# debug here when in trouble...
|
50
|
-
raise e
|
51
|
-
end
|
42
|
+
@@interpolation_visitor.visit_this_0(self, current)
|
52
43
|
end
|
53
44
|
|
54
45
|
# Building of Model classes
|
@@ -142,10 +133,10 @@ class Puppet::Pops::Model::Factory
|
|
142
133
|
end
|
143
134
|
|
144
135
|
# @param name [String] a valid classname
|
145
|
-
# @param parameters [Array<
|
136
|
+
# @param parameters [Array<Parameter>] may be empty
|
146
137
|
# @param parent_class_name [String, nil] a valid classname referencing a parent class, optional.
|
147
138
|
# @param body [Array<Expression>, Expression, nil] expression that constitute the body
|
148
|
-
# @return [
|
139
|
+
# @return [HostClassDefinition] configured from the parameters
|
149
140
|
#
|
150
141
|
def build_HostClassDefinition(o, name, parameters, parent_class_name, body)
|
151
142
|
build_NamedDefinition(o, name, parameters, body)
|
@@ -218,7 +209,7 @@ class Puppet::Pops::Model::Factory
|
|
218
209
|
when NilClass
|
219
210
|
nil
|
220
211
|
when Array
|
221
|
-
|
212
|
+
Factory.new(BlockExpression, *body)
|
222
213
|
else
|
223
214
|
build(body)
|
224
215
|
end
|
@@ -241,14 +232,14 @@ class Puppet::Pops::Model::Factory
|
|
241
232
|
|
242
233
|
def build_CapabilityMapping(o, kind, component, capability, mappings)
|
243
234
|
o.kind = kind
|
244
|
-
component = component.current if component.
|
235
|
+
component = component.current if component.instance_of?(Factory)
|
245
236
|
o.component = component
|
246
237
|
o.capability = capability
|
247
238
|
o.mappings = mappings.map { |m| build(m) }
|
248
239
|
o
|
249
240
|
end
|
250
241
|
|
251
|
-
# @param o [
|
242
|
+
# @param o [NodeDefinition]
|
252
243
|
# @param hosts [Array<Expression>] host matches
|
253
244
|
# @param parent [Expression] parent node matcher
|
254
245
|
# @param body [Object] see {#f_build_body}
|
@@ -260,7 +251,7 @@ class Puppet::Pops::Model::Factory
|
|
260
251
|
o
|
261
252
|
end
|
262
253
|
|
263
|
-
# @param o [
|
254
|
+
# @param o [SiteDefinition]
|
264
255
|
# @param body [Object] see {#f_build_body}
|
265
256
|
def build_SiteDefinition(o, body)
|
266
257
|
b = f_build_body(body)
|
@@ -339,13 +330,13 @@ class Puppet::Pops::Model::Factory
|
|
339
330
|
|
340
331
|
def build_QueryExpression(o, expr)
|
341
332
|
ops = to_ops(expr)
|
342
|
-
o.expr = ops unless
|
333
|
+
o.expr = ops unless Factory.nop? ops
|
343
334
|
o
|
344
335
|
end
|
345
336
|
|
346
337
|
def build_UnaryExpression(o, expr)
|
347
338
|
ops = to_ops(expr)
|
348
|
-
o.expr = ops unless
|
339
|
+
o.expr = ops unless Factory.nop? ops
|
349
340
|
o
|
350
341
|
end
|
351
342
|
|
@@ -369,55 +360,55 @@ class Puppet::Pops::Model::Factory
|
|
369
360
|
raise "Factory can not deal with a Lexer Token. Got token: #{o}. Probably caused by wrong index in grammar val[n]."
|
370
361
|
end
|
371
362
|
|
372
|
-
#
|
363
|
+
# Factory helpers
|
373
364
|
def f_build_unary(klazz, expr)
|
374
|
-
|
365
|
+
Factory.new(build(klazz, expr))
|
375
366
|
end
|
376
367
|
|
377
368
|
def f_build_binary_op(klazz, op, left, right)
|
378
|
-
|
369
|
+
Factory.new(build(klazz, op, left, right))
|
379
370
|
end
|
380
371
|
|
381
372
|
def f_build_binary(klazz, left, right)
|
382
|
-
|
373
|
+
Factory.new(build(klazz, left, right))
|
383
374
|
end
|
384
375
|
|
385
376
|
def f_build_vararg(klazz, left, *arg)
|
386
|
-
|
377
|
+
Factory.new(build(klazz, left, *arg))
|
387
378
|
end
|
388
379
|
|
389
380
|
def f_arithmetic(op, r)
|
390
|
-
f_build_binary_op(
|
381
|
+
f_build_binary_op(ArithmeticExpression, op, current, r)
|
391
382
|
end
|
392
383
|
|
393
384
|
def f_comparison(op, r)
|
394
|
-
f_build_binary_op(
|
385
|
+
f_build_binary_op(ComparisonExpression, op, current, r)
|
395
386
|
end
|
396
387
|
|
397
388
|
def f_match(op, r)
|
398
|
-
f_build_binary_op(
|
389
|
+
f_build_binary_op(MatchExpression, op, current, r)
|
399
390
|
end
|
400
391
|
|
401
392
|
# Operator helpers
|
402
|
-
def in(r) f_build_binary(
|
393
|
+
def in(r) f_build_binary(InExpression, current, r); end
|
403
394
|
|
404
|
-
def or(r) f_build_binary(
|
395
|
+
def or(r) f_build_binary(OrExpression, current, r); end
|
405
396
|
|
406
|
-
def and(r) f_build_binary(
|
397
|
+
def and(r) f_build_binary(AndExpression, current, r); end
|
407
398
|
|
408
|
-
def not(); f_build_unary(
|
399
|
+
def not(); f_build_unary(NotExpression, self); end
|
409
400
|
|
410
|
-
def minus(); f_build_unary(
|
401
|
+
def minus(); f_build_unary(UnaryMinusExpression, self); end
|
411
402
|
|
412
|
-
def unfold(); f_build_unary(
|
403
|
+
def unfold(); f_build_unary(UnfoldExpression, self); end
|
413
404
|
|
414
|
-
def text(); f_build_unary(
|
405
|
+
def text(); f_build_unary(TextExpression, self); end
|
415
406
|
|
416
|
-
def var(); f_build_unary(
|
407
|
+
def var(); f_build_unary(VariableExpression, self); end
|
417
408
|
|
418
|
-
def [](*r); f_build_vararg(
|
409
|
+
def [](*r); f_build_vararg(AccessExpression, current, *r); end
|
419
410
|
|
420
|
-
def dot r; f_build_binary(
|
411
|
+
def dot r; f_build_binary(NamedAccessExpression, current, r); end
|
421
412
|
|
422
413
|
def + r; f_arithmetic(:+, r); end
|
423
414
|
|
@@ -449,19 +440,19 @@ class Puppet::Pops::Model::Factory
|
|
449
440
|
|
450
441
|
def mne r; f_match(:'!~', r); end
|
451
442
|
|
452
|
-
def paren(); f_build_unary(
|
443
|
+
def paren(); f_build_unary(ParenthesizedExpression, current); end
|
453
444
|
|
454
445
|
def relop op, r
|
455
|
-
f_build_binary_op(
|
446
|
+
f_build_binary_op(RelationshipExpression, op.to_sym, current, r)
|
456
447
|
end
|
457
448
|
|
458
449
|
def select *args
|
459
|
-
|
450
|
+
Factory.new(build(SelectorExpression, current, *args))
|
460
451
|
end
|
461
452
|
|
462
453
|
# For CaseExpression, setting the default for an already build CaseExpression
|
463
454
|
def default r
|
464
|
-
current.addOptions(
|
455
|
+
current.addOptions(Factory.WHEN(:default, r).current)
|
465
456
|
self
|
466
457
|
end
|
467
458
|
|
@@ -472,17 +463,17 @@ class Puppet::Pops::Model::Factory
|
|
472
463
|
|
473
464
|
# Assignment =
|
474
465
|
def set(r)
|
475
|
-
f_build_binary_op(
|
466
|
+
f_build_binary_op(AssignmentExpression, :'=', current, r)
|
476
467
|
end
|
477
468
|
|
478
469
|
# Assignment +=
|
479
470
|
def plus_set(r)
|
480
|
-
f_build_binary_op(
|
471
|
+
f_build_binary_op(AssignmentExpression, :'+=', current, r)
|
481
472
|
end
|
482
473
|
|
483
474
|
# Assignment -=
|
484
475
|
def minus_set(r)
|
485
|
-
f_build_binary_op(
|
476
|
+
f_build_binary_op(AssignmentExpression, :'-=', current, r)
|
486
477
|
end
|
487
478
|
|
488
479
|
def attributes(*args)
|
@@ -507,31 +498,35 @@ class Puppet::Pops::Model::Factory
|
|
507
498
|
new(o).record_position(start_locatable, end_locateable)
|
508
499
|
end
|
509
500
|
|
501
|
+
def offset
|
502
|
+
@current.offset
|
503
|
+
end
|
504
|
+
|
505
|
+
def length
|
506
|
+
@current.length
|
507
|
+
end
|
508
|
+
|
510
509
|
# Records the position (start -> end) and computes the resulting length.
|
511
510
|
#
|
512
511
|
def record_position(start_locatable, end_locatable)
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
o = current
|
517
|
-
# record information directly in the Model::Positioned object
|
518
|
-
o.offset = from.offset
|
519
|
-
o.length ||= to.offset - from.offset + to.length
|
512
|
+
# record information directly in the Positioned object
|
513
|
+
start_offset = start_locatable.offset
|
514
|
+
@current.set_loc(start_offset, end_locatable ? end_locatable.offset - start_offset + end_locatable.length : start_locatable.length)
|
520
515
|
self
|
521
516
|
end
|
522
517
|
|
523
518
|
# @return [Puppet::Pops::Adapters::SourcePosAdapter] with location information
|
524
519
|
def loc()
|
525
|
-
|
520
|
+
Adapters::SourcePosAdapter.adapt(current)
|
526
521
|
end
|
527
522
|
|
528
523
|
# Sets the form of the resource expression (:regular (the default), :virtual, or :exported).
|
529
524
|
# Produces true if the expression was a resource expression, false otherwise.
|
530
525
|
#
|
531
526
|
def self.set_resource_form(expr, form)
|
532
|
-
expr = expr.current if expr.
|
527
|
+
expr = expr.current if expr.instance_of?(Factory)
|
533
528
|
# Note: Validation handles illegal combinations
|
534
|
-
return false unless expr.is_a?(
|
529
|
+
return false unless expr.is_a?(AbstractResource)
|
535
530
|
expr.form = form
|
536
531
|
return true
|
537
532
|
end
|
@@ -544,15 +539,15 @@ class Puppet::Pops::Model::Factory
|
|
544
539
|
# * _any other_ => ':error', all other are considered illegal
|
545
540
|
#
|
546
541
|
def self.resource_shape(expr)
|
547
|
-
expr = expr.current if expr.
|
542
|
+
expr = expr.current if expr.instance_of?(Factory)
|
548
543
|
case expr
|
549
|
-
when
|
544
|
+
when QualifiedName
|
550
545
|
:resource
|
551
|
-
when
|
546
|
+
when QualifiedReference
|
552
547
|
:defaults
|
553
|
-
when
|
548
|
+
when AccessExpression
|
554
549
|
# if Resource[e], then it is not resource specific
|
555
|
-
if expr.left_expr.is_a?(
|
550
|
+
if expr.left_expr.is_a?(QualifiedReference) && expr.left_expr.value == 'resource' && expr.keys.size == 1
|
556
551
|
:defaults
|
557
552
|
else
|
558
553
|
:override
|
@@ -573,43 +568,43 @@ class Puppet::Pops::Model::Factory
|
|
573
568
|
|
574
569
|
def self.var(o); new(o).var; end
|
575
570
|
|
576
|
-
def self.block(*args); new(
|
571
|
+
def self.block(*args); new(BlockExpression, *args); end
|
577
572
|
|
578
|
-
def self.string(*args); new(
|
573
|
+
def self.string(*args); new(ConcatenatedString, *args); end
|
579
574
|
|
580
575
|
def self.text(o); new(o).text; end
|
581
576
|
|
582
|
-
def self.IF(test_e,then_e,else_e); new(
|
577
|
+
def self.IF(test_e,then_e,else_e); new(IfExpression, test_e, then_e, else_e); end
|
583
578
|
|
584
|
-
def self.UNLESS(test_e,then_e,else_e); new(
|
579
|
+
def self.UNLESS(test_e,then_e,else_e); new(UnlessExpression, test_e, then_e, else_e); end
|
585
580
|
|
586
|
-
def self.CASE(test_e,*options); new(
|
581
|
+
def self.CASE(test_e,*options); new(CaseExpression, test_e, *options); end
|
587
582
|
|
588
|
-
def self.WHEN(values_list, block); new(
|
583
|
+
def self.WHEN(values_list, block); new(CaseOption, values_list, block); end
|
589
584
|
|
590
|
-
def self.MAP(match, value); new(
|
585
|
+
def self.MAP(match, value); new(SelectorEntry, match, value); end
|
591
586
|
|
592
|
-
def self.TYPE(name, super_name=nil); new(
|
587
|
+
def self.TYPE(name, super_name=nil); new(CreateTypeExpression, name, super_name); end
|
593
588
|
|
594
|
-
def self.ATTR(name, type_expr=nil); new(
|
589
|
+
def self.ATTR(name, type_expr=nil); new(CreateAttributeExpression, name, type_expr); end
|
595
590
|
|
596
|
-
def self.ENUM(*args); new(
|
591
|
+
def self.ENUM(*args); new(CreateEnumExpression, *args); end
|
597
592
|
|
598
|
-
def self.KEY_ENTRY(key, val); new(
|
593
|
+
def self.KEY_ENTRY(key, val); new(KeyedEntry, key, val); end
|
599
594
|
|
600
|
-
def self.HASH(entries); new(
|
595
|
+
def self.HASH(entries); new(LiteralHash, *entries); end
|
601
596
|
|
602
|
-
def self.HEREDOC(name, expr); new(
|
597
|
+
def self.HEREDOC(name, expr); new(HeredocExpression, name, expr); end
|
603
598
|
|
604
|
-
def self.SUBLOCATE(token, expr) new(
|
599
|
+
def self.SUBLOCATE(token, expr) new(SubLocatedExpression, token, expr); end
|
605
600
|
|
606
|
-
def self.LIST(entries); new(
|
601
|
+
def self.LIST(entries); new(LiteralList, *entries); end
|
607
602
|
|
608
|
-
def self.PARAM(name, expr=nil); new(
|
603
|
+
def self.PARAM(name, expr=nil); new(Parameter, name, expr); end
|
609
604
|
|
610
|
-
def self.NODE(hosts, parent, body); new(
|
605
|
+
def self.NODE(hosts, parent, body); new(NodeDefinition, hosts, parent, body); end
|
611
606
|
|
612
|
-
def self.SITE(body); new(
|
607
|
+
def self.SITE(body); new(SiteDefinition, body); end
|
613
608
|
|
614
609
|
# Parameters
|
615
610
|
|
@@ -627,8 +622,8 @@ class Puppet::Pops::Model::Factory
|
|
627
622
|
# case it is returned.
|
628
623
|
#
|
629
624
|
def self.fqn(o)
|
630
|
-
o = o.current if o.
|
631
|
-
o = new(
|
625
|
+
o = o.current if o.instance_of?(Factory)
|
626
|
+
o = new(QualifiedName, o) unless o.is_a? QualifiedName
|
632
627
|
o
|
633
628
|
end
|
634
629
|
|
@@ -636,22 +631,22 @@ class Puppet::Pops::Model::Factory
|
|
636
631
|
# case it is returned.
|
637
632
|
#
|
638
633
|
def self.fqr(o)
|
639
|
-
o = o.current if o.
|
640
|
-
o = new(
|
634
|
+
o = o.current if o.instance_of?(Factory)
|
635
|
+
o = new(QualifiedReference, o) unless o.is_a? QualifiedReference
|
641
636
|
o
|
642
637
|
end
|
643
638
|
|
644
639
|
def self.TEXT(expr)
|
645
|
-
new(
|
640
|
+
new(TextExpression, new(expr).interpolate)
|
646
641
|
end
|
647
642
|
|
648
643
|
# TODO_EPP
|
649
644
|
def self.RENDER_STRING(o)
|
650
|
-
new(
|
645
|
+
new(RenderStringExpression, o)
|
651
646
|
end
|
652
647
|
|
653
648
|
def self.RENDER_EXPR(expr)
|
654
|
-
new(
|
649
|
+
new(RenderExpression, expr)
|
655
650
|
end
|
656
651
|
|
657
652
|
def self.EPP(parameters, body)
|
@@ -662,27 +657,27 @@ class Puppet::Pops::Model::Factory
|
|
662
657
|
params = parameters
|
663
658
|
parameters_specified = true
|
664
659
|
end
|
665
|
-
LAMBDA(params, new(
|
660
|
+
LAMBDA(params, new(EppExpression, parameters_specified, body))
|
666
661
|
end
|
667
662
|
|
668
663
|
def self.RESERVED(name, future=false)
|
669
|
-
new(
|
664
|
+
new(ReservedWord, name, future)
|
670
665
|
end
|
671
666
|
|
672
667
|
# TODO: This is the same a fqn factory method, don't know if callers to fqn and QNAME can live with the
|
673
668
|
# same result or not yet - refactor into one method when decided.
|
674
669
|
#
|
675
670
|
def self.QNAME(name)
|
676
|
-
new(
|
671
|
+
new(QualifiedName, name)
|
677
672
|
end
|
678
673
|
|
679
674
|
def self.NUMBER(name_or_numeric)
|
680
|
-
if n_radix =
|
675
|
+
if n_radix = Utils.to_n_with_radix(name_or_numeric)
|
681
676
|
val, radix = n_radix
|
682
677
|
if val.is_a?(Float)
|
683
|
-
new(
|
678
|
+
new(LiteralFloat, val)
|
684
679
|
else
|
685
|
-
new(
|
680
|
+
new(LiteralInteger, val, radix)
|
686
681
|
end
|
687
682
|
else
|
688
683
|
# Bad number should already have been caught by lexer - this should never happen
|
@@ -693,112 +688,112 @@ class Puppet::Pops::Model::Factory
|
|
693
688
|
# Convert input string to either a qualified name, a LiteralInteger with radix, or a LiteralFloat
|
694
689
|
#
|
695
690
|
def self.QNAME_OR_NUMBER(name)
|
696
|
-
if n_radix =
|
691
|
+
if n_radix = Utils.to_n_with_radix(name)
|
697
692
|
val, radix = n_radix
|
698
693
|
if val.is_a?(Float)
|
699
|
-
new(
|
694
|
+
new(LiteralFloat, val)
|
700
695
|
else
|
701
|
-
new(
|
696
|
+
new(LiteralInteger, val, radix)
|
702
697
|
end
|
703
698
|
else
|
704
|
-
new(
|
699
|
+
new(QualifiedName, name)
|
705
700
|
end
|
706
701
|
end
|
707
702
|
|
708
703
|
def self.QREF(name)
|
709
|
-
new(
|
704
|
+
new(QualifiedReference, name)
|
710
705
|
end
|
711
706
|
|
712
707
|
def self.VIRTUAL_QUERY(query_expr)
|
713
|
-
new(
|
708
|
+
new(VirtualQuery, query_expr)
|
714
709
|
end
|
715
710
|
|
716
711
|
def self.EXPORTED_QUERY(query_expr)
|
717
|
-
new(
|
712
|
+
new(ExportedQuery, query_expr)
|
718
713
|
end
|
719
714
|
|
720
715
|
def self.ATTRIBUTE_OP(name, op, expr)
|
721
|
-
new(
|
716
|
+
new(AttributeOperation, name, op, expr)
|
722
717
|
end
|
723
718
|
|
724
719
|
def self.ATTRIBUTES_OP(expr)
|
725
|
-
new(
|
720
|
+
new(AttributesOperation, expr)
|
726
721
|
end
|
727
722
|
|
728
723
|
def self.CALL_NAMED(name, rval_required, argument_list)
|
729
|
-
unless name.kind_of?(
|
730
|
-
name =
|
724
|
+
unless name.kind_of?(PopsObject)
|
725
|
+
name = Factory.fqn(name) unless name.instance_of?(Factory)
|
731
726
|
end
|
732
|
-
new(
|
727
|
+
new(CallNamedFunctionExpression, name, rval_required, *argument_list)
|
733
728
|
end
|
734
729
|
|
735
730
|
def self.CALL_METHOD(functor, argument_list)
|
736
|
-
new(
|
731
|
+
new(CallMethodExpression, functor, true, nil, *argument_list)
|
737
732
|
end
|
738
733
|
|
739
734
|
def self.COLLECT(type_expr, query_expr, attribute_operations)
|
740
|
-
new(
|
735
|
+
new(CollectExpression, type_expr, query_expr, attribute_operations)
|
741
736
|
end
|
742
737
|
|
743
738
|
def self.NAMED_ACCESS(type_name, bodies)
|
744
|
-
new(
|
739
|
+
new(NamedAccessExpression, type_name, bodies)
|
745
740
|
end
|
746
741
|
|
747
742
|
def self.RESOURCE(type_name, bodies)
|
748
|
-
new(
|
743
|
+
new(ResourceExpression, type_name, bodies)
|
749
744
|
end
|
750
745
|
|
751
746
|
def self.RESOURCE_DEFAULTS(type_name, attribute_operations)
|
752
|
-
new(
|
747
|
+
new(ResourceDefaultsExpression, type_name, attribute_operations)
|
753
748
|
end
|
754
749
|
|
755
750
|
def self.RESOURCE_OVERRIDE(resource_ref, attribute_operations)
|
756
|
-
new(
|
751
|
+
new(ResourceOverrideExpression, resource_ref, attribute_operations)
|
757
752
|
end
|
758
753
|
|
759
754
|
def self.RESOURCE_BODY(resource_title, attribute_operations)
|
760
|
-
new(
|
755
|
+
new(ResourceBody, resource_title, attribute_operations)
|
761
756
|
end
|
762
757
|
|
763
758
|
def self.PROGRAM(body, definitions, locator)
|
764
|
-
new(
|
759
|
+
new(Program, body, definitions, locator)
|
765
760
|
end
|
766
761
|
|
767
762
|
# Builds a BlockExpression if args size > 1, else the single expression/value in args
|
768
763
|
def self.block_or_expression(*args)
|
769
764
|
if args.size > 1
|
770
|
-
new(
|
765
|
+
new(BlockExpression, *args)
|
771
766
|
else
|
772
767
|
new(args[0])
|
773
768
|
end
|
774
769
|
end
|
775
770
|
|
776
771
|
def self.HOSTCLASS(name, parameters, parent, body)
|
777
|
-
new(
|
772
|
+
new(HostClassDefinition, name, parameters, parent, body)
|
778
773
|
end
|
779
774
|
|
780
775
|
def self.DEFINITION(name, parameters, body)
|
781
|
-
new(
|
776
|
+
new(ResourceTypeDefinition, name, parameters, body)
|
782
777
|
end
|
783
778
|
|
784
779
|
def self.CAPABILITY_MAPPING(kind, component, cap_name, mappings)
|
785
|
-
new(
|
780
|
+
new(CapabilityMapping, kind, component, cap_name, mappings)
|
786
781
|
end
|
787
782
|
|
788
783
|
def self.APPLICATION(name, parameters, body)
|
789
|
-
new(
|
784
|
+
new(Application, name, parameters, body)
|
790
785
|
end
|
791
786
|
|
792
787
|
def self.FUNCTION(name, parameters, body)
|
793
|
-
new(
|
788
|
+
new(FunctionDefinition, name, parameters, body)
|
794
789
|
end
|
795
790
|
|
796
791
|
def self.LAMBDA(parameters, body)
|
797
|
-
new(
|
792
|
+
new(LambdaExpression, parameters, body)
|
798
793
|
end
|
799
794
|
|
800
795
|
def self.nop? o
|
801
|
-
o.nil? || o.is_a?(
|
796
|
+
o.nil? || o.is_a?(Nop)
|
802
797
|
end
|
803
798
|
|
804
799
|
STATEMENT_CALLS = {
|
@@ -837,19 +832,19 @@ class Puppet::Pops::Model::Factory
|
|
837
832
|
#
|
838
833
|
def self.transform_calls(expressions)
|
839
834
|
expressions.reduce([]) do |memo, expr|
|
840
|
-
expr = expr.current if expr.
|
835
|
+
expr = expr.current if expr.instance_of?(Factory)
|
841
836
|
name = memo[-1]
|
842
|
-
if name.is_a?(
|
837
|
+
if name.is_a?(QualifiedName) && STATEMENT_CALLS[name.value]
|
843
838
|
if expr.is_a?(Array)
|
844
|
-
expr = expr.reject {|e| e.is_a?(
|
839
|
+
expr = expr.reject {|e| e.is_a?(Parser::LexerSupport::TokenValue) }
|
845
840
|
else
|
846
841
|
expr = [expr]
|
847
842
|
end
|
848
|
-
the_call =
|
843
|
+
the_call = Factory.CALL_NAMED(name, false, expr)
|
849
844
|
# last positioned is last arg if there are several
|
850
845
|
record_position(the_call, name, expr.is_a?(Array) ? expr[-1] : expr)
|
851
846
|
memo[-1] = the_call
|
852
|
-
if expr.is_a?(
|
847
|
+
if expr.is_a?(CallNamedFunctionExpression)
|
853
848
|
# Patch statement function call to expression style
|
854
849
|
# This is needed because it is first parsed as a "statement" and the requirement changes as it becomes
|
855
850
|
# an argument to the name to call transform above.
|
@@ -859,7 +854,7 @@ class Puppet::Pops::Model::Factory
|
|
859
854
|
raise ArgsToNonCallError.new(expr, name)
|
860
855
|
else
|
861
856
|
memo << expr
|
862
|
-
if expr.is_a?(
|
857
|
+
if expr.is_a?(CallNamedFunctionExpression)
|
863
858
|
# Patch rvalue expression function call to statement style.
|
864
859
|
# This is not really required but done to be AST model compliant
|
865
860
|
expr.rval_required = false
|
@@ -875,7 +870,7 @@ class Puppet::Pops::Model::Factory
|
|
875
870
|
def self.transform_resource_wo_title(left, attribute_ops)
|
876
871
|
# Returning nil means accepting the given as a potential resource expression
|
877
872
|
return nil unless attribute_ops.is_a? Array
|
878
|
-
return nil unless left.current.is_a?(
|
873
|
+
return nil unless left.current.is_a?(QualifiedName)
|
879
874
|
keyed_entries = attribute_ops.map do |ao|
|
880
875
|
return nil if ao.operator == :'+>'
|
881
876
|
KEY_ENTRY(ao.attribute_name, ao.value_expr)
|
@@ -890,42 +885,42 @@ class Puppet::Pops::Model::Factory
|
|
890
885
|
# that when evaluated produce the same thing.
|
891
886
|
|
892
887
|
def build_String(o)
|
893
|
-
x =
|
888
|
+
x = LiteralString.new
|
894
889
|
x.value = o;
|
895
890
|
x
|
896
891
|
end
|
897
892
|
|
898
893
|
def build_NilClass(o)
|
899
|
-
x =
|
894
|
+
x = Nop.new
|
900
895
|
x
|
901
896
|
end
|
902
897
|
|
903
898
|
def build_TrueClass(o)
|
904
|
-
x =
|
899
|
+
x = LiteralBoolean.new
|
905
900
|
x.value = o
|
906
901
|
x
|
907
902
|
end
|
908
903
|
|
909
904
|
def build_FalseClass(o)
|
910
|
-
x =
|
905
|
+
x = LiteralBoolean.new
|
911
906
|
x.value = o
|
912
907
|
x
|
913
908
|
end
|
914
909
|
|
915
910
|
def build_Fixnum(o)
|
916
|
-
x =
|
911
|
+
x = LiteralInteger.new
|
917
912
|
x.value = o;
|
918
913
|
x
|
919
914
|
end
|
920
915
|
|
921
916
|
def build_Float(o)
|
922
|
-
x =
|
917
|
+
x = LiteralFloat.new
|
923
918
|
x.value = o;
|
924
919
|
x
|
925
920
|
end
|
926
921
|
|
927
922
|
def build_Regexp(o)
|
928
|
-
x =
|
923
|
+
x = LiteralRegularExpression.new
|
929
924
|
x.value = o;
|
930
925
|
x
|
931
926
|
end
|
@@ -948,9 +943,9 @@ class Puppet::Pops::Model::Factory
|
|
948
943
|
def build_Symbol(o)
|
949
944
|
case o
|
950
945
|
when :undef
|
951
|
-
|
946
|
+
LiteralUndef.new
|
952
947
|
when :default
|
953
|
-
|
948
|
+
LiteralDefault.new
|
954
949
|
else
|
955
950
|
build_String(o.to_s)
|
956
951
|
end
|
@@ -958,7 +953,7 @@ class Puppet::Pops::Model::Factory
|
|
958
953
|
|
959
954
|
# Creates a LiteralList instruction from an Array, where the entries are built.
|
960
955
|
def build_Array(o)
|
961
|
-
x =
|
956
|
+
x = LiteralList.new
|
962
957
|
o.each { |v| x.addValues(build(v)) }
|
963
958
|
x
|
964
959
|
end
|
@@ -967,8 +962,8 @@ class Puppet::Pops::Model::Factory
|
|
967
962
|
# The hash entries are added in sorted order based on key.to_s
|
968
963
|
#
|
969
964
|
def build_Hash(o)
|
970
|
-
x =
|
971
|
-
(o.sort_by {|k,v| k.to_s}).each {|k,v| x.addEntries(build(
|
965
|
+
x = LiteralHash.new
|
966
|
+
(o.sort_by {|k,v| k.to_s}).each {|k,v| x.addEntries(build(KeyedEntry.new, k, v)) }
|
972
967
|
x
|
973
968
|
end
|
974
969
|
|
@@ -1051,10 +1046,10 @@ class Puppet::Pops::Model::Factory
|
|
1051
1046
|
|
1052
1047
|
def is_interop_rewriteable?(o)
|
1053
1048
|
case o
|
1054
|
-
when
|
1055
|
-
|
1049
|
+
when AccessExpression, QualifiedName,
|
1050
|
+
NamedAccessExpression, CallMethodExpression
|
1056
1051
|
true
|
1057
|
-
when
|
1052
|
+
when LiteralInteger
|
1058
1053
|
# Only decimal integers can represent variables, else it is a number
|
1059
1054
|
o.radix == 10
|
1060
1055
|
else
|
@@ -1065,9 +1060,9 @@ class Puppet::Pops::Model::Factory
|
|
1065
1060
|
# Checks if the object is already a model object, or build it
|
1066
1061
|
def to_ops(o, *args)
|
1067
1062
|
case o
|
1068
|
-
when
|
1063
|
+
when PopsObject
|
1069
1064
|
o
|
1070
|
-
when
|
1065
|
+
when Factory
|
1071
1066
|
o.current
|
1072
1067
|
else
|
1073
1068
|
build(o, *args)
|
@@ -1078,7 +1073,7 @@ class Puppet::Pops::Model::Factory
|
|
1078
1073
|
new(args.map do |e|
|
1079
1074
|
e = e.current if e.is_a?(self)
|
1080
1075
|
case e
|
1081
|
-
when
|
1076
|
+
when LiteralString
|
1082
1077
|
e.value
|
1083
1078
|
when String
|
1084
1079
|
e
|
@@ -1089,6 +1084,9 @@ class Puppet::Pops::Model::Factory
|
|
1089
1084
|
end
|
1090
1085
|
|
1091
1086
|
def to_s
|
1092
|
-
|
1087
|
+
ModelTreeDumper.new.dump(self)
|
1093
1088
|
end
|
1094
1089
|
end
|
1090
|
+
end
|
1091
|
+
end
|
1092
|
+
|