bolt 0.17.1 → 0.17.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of bolt might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/bolt-modules/boltlib/lib/puppet/functions/run_task.rb +25 -13
- data/lib/bolt/cli.rb +45 -15
- data/lib/bolt/config.rb +48 -132
- data/lib/bolt/executor.rb +3 -10
- data/lib/bolt/inventory.rb +15 -1
- data/lib/bolt/puppetdb.rb +11 -0
- data/lib/bolt/puppetdb/client.rb +68 -0
- data/lib/bolt/puppetdb/config.rb +76 -0
- data/lib/bolt/target.rb +5 -4
- data/lib/bolt/transport/base.rb +11 -2
- data/lib/bolt/transport/local.rb +11 -5
- data/lib/bolt/transport/orch.rb +16 -5
- data/lib/bolt/transport/ssh.rb +32 -1
- data/lib/bolt/transport/ssh/connection.rb +17 -10
- data/lib/bolt/transport/winrm.rb +18 -1
- data/lib/bolt/transport/winrm/connection.rb +15 -16
- data/lib/bolt/util.rb +15 -0
- data/lib/bolt/version.rb +1 -1
- data/lib/bolt_ext/puppetdb_inventory.rb +5 -135
- data/vendored/facter/lib/facter/ec2/rest.rb +1 -1
- data/vendored/hiera/lib/hiera/version.rb +1 -1
- data/vendored/puppet/lib/puppet/application/agent.rb +1 -3
- data/vendored/puppet/lib/puppet/application/apply.rb +2 -4
- data/vendored/puppet/lib/puppet/application/cert.rb +6 -1
- data/vendored/puppet/lib/puppet/application/device.rb +100 -13
- data/vendored/puppet/lib/puppet/application/facts.rb +5 -0
- data/vendored/puppet/lib/puppet/application/lookup.rb +11 -1
- data/vendored/puppet/lib/puppet/configurer.rb +17 -4
- data/vendored/puppet/lib/puppet/configurer/plugin_handler.rb +1 -1
- data/vendored/puppet/lib/puppet/datatypes.rb +1 -1
- data/vendored/puppet/lib/puppet/defaults.rb +1 -1
- data/vendored/puppet/lib/puppet/environments.rb +2 -2
- data/vendored/puppet/lib/puppet/error.rb +6 -3
- data/vendored/puppet/lib/puppet/external/dot.rb +0 -7
- data/vendored/puppet/lib/puppet/external/nagios/parser.rb +1 -1
- data/vendored/puppet/lib/puppet/face/config.rb +41 -8
- data/vendored/puppet/lib/puppet/face/epp.rb +30 -5
- data/vendored/puppet/lib/puppet/face/facts.rb +49 -0
- data/vendored/puppet/lib/puppet/face/help.rb +33 -35
- data/vendored/puppet/lib/puppet/face/man.rb +55 -12
- data/vendored/puppet/lib/puppet/face/parser.rb +30 -3
- data/vendored/puppet/lib/puppet/file_bucket/file.rb +0 -2
- data/vendored/puppet/lib/puppet/file_serving/base.rb +10 -10
- data/vendored/puppet/lib/puppet/functions.rb +1 -3
- data/vendored/puppet/lib/puppet/functions/alert.rb +1 -1
- data/vendored/puppet/lib/puppet/functions/all.rb +6 -6
- data/vendored/puppet/lib/puppet/functions/annotate.rb +10 -10
- data/vendored/puppet/lib/puppet/functions/any.rb +6 -6
- data/vendored/puppet/lib/puppet/functions/assert_type.rb +4 -4
- data/vendored/puppet/lib/puppet/functions/binary_file.rb +14 -2
- data/vendored/puppet/lib/puppet/functions/break.rb +31 -2
- data/vendored/puppet/lib/puppet/functions/call.rb +4 -4
- data/vendored/puppet/lib/puppet/functions/contain.rb +19 -3
- data/vendored/puppet/lib/puppet/functions/convert_to.rb +6 -5
- data/vendored/puppet/lib/puppet/functions/crit.rb +1 -1
- data/vendored/puppet/lib/puppet/functions/debug.rb +1 -1
- data/vendored/puppet/lib/puppet/functions/defined.rb +11 -9
- data/vendored/puppet/lib/puppet/functions/dig.rb +26 -2
- data/vendored/puppet/lib/puppet/functions/each.rb +8 -8
- data/vendored/puppet/lib/puppet/functions/emerg.rb +1 -1
- data/vendored/puppet/lib/puppet/functions/empty.rb +79 -0
- data/vendored/puppet/lib/puppet/functions/err.rb +1 -1
- data/vendored/puppet/lib/puppet/functions/filter.rb +7 -7
- data/vendored/puppet/lib/puppet/functions/find_file.rb +15 -1
- data/vendored/puppet/lib/puppet/functions/flatten.rb +64 -0
- data/vendored/puppet/lib/puppet/functions/hiera.rb +6 -6
- data/vendored/puppet/lib/puppet/functions/hiera_array.rb +6 -6
- data/vendored/puppet/lib/puppet/functions/hiera_hash.rb +6 -6
- data/vendored/puppet/lib/puppet/functions/hiera_include.rb +8 -8
- data/vendored/puppet/lib/puppet/functions/include.rb +28 -2
- data/vendored/puppet/lib/puppet/functions/info.rb +1 -1
- data/vendored/puppet/lib/puppet/functions/inline_epp.rb +2 -2
- data/vendored/puppet/lib/puppet/functions/join.rb +56 -0
- data/vendored/puppet/lib/puppet/functions/keys.rb +25 -0
- data/vendored/puppet/lib/puppet/functions/length.rb +44 -0
- data/vendored/puppet/lib/puppet/functions/lest.rb +39 -1
- data/vendored/puppet/lib/puppet/functions/map.rb +10 -9
- data/vendored/puppet/lib/puppet/functions/match.rb +6 -6
- data/vendored/puppet/lib/puppet/functions/new.rb +995 -2
- data/vendored/puppet/lib/puppet/functions/next.rb +1 -1
- data/vendored/puppet/lib/puppet/functions/notice.rb +1 -1
- data/vendored/puppet/lib/puppet/functions/reduce.rb +6 -6
- data/vendored/puppet/lib/puppet/functions/regsubst.rb +9 -3
- data/vendored/puppet/lib/puppet/functions/require.rb +36 -2
- data/vendored/puppet/lib/puppet/functions/return.rb +1 -1
- data/vendored/puppet/lib/puppet/functions/reverse_each.rb +71 -2
- data/vendored/puppet/lib/puppet/functions/slice.rb +23 -9
- data/vendored/puppet/lib/puppet/functions/split.rb +12 -10
- data/vendored/puppet/lib/puppet/functions/step.rb +73 -1
- data/vendored/puppet/lib/puppet/functions/strftime.rb +176 -2
- data/vendored/puppet/lib/puppet/functions/then.rb +65 -2
- data/vendored/puppet/lib/puppet/functions/tree_each.rb +19 -19
- data/vendored/puppet/lib/puppet/functions/type.rb +42 -1
- data/vendored/puppet/lib/puppet/functions/unique.rb +13 -13
- data/vendored/puppet/lib/puppet/functions/unwrap.rb +8 -4
- data/vendored/puppet/lib/puppet/functions/values.rb +25 -0
- data/vendored/puppet/lib/puppet/functions/versioncmp.rb +1 -1
- data/vendored/puppet/lib/puppet/functions/warning.rb +1 -1
- data/vendored/puppet/lib/puppet/functions/with.rb +6 -4
- data/vendored/puppet/lib/puppet/indirector/certificate_status/file.rb +1 -1
- data/vendored/puppet/lib/puppet/indirector/facts/facter.rb +1 -3
- data/vendored/puppet/lib/puppet/indirector/facts/rest.rb +21 -0
- data/vendored/puppet/lib/puppet/indirector/facts/yaml.rb +0 -4
- data/vendored/puppet/lib/puppet/indirector/file_content/http.rb +3 -1
- data/vendored/puppet/lib/puppet/indirector/indirection.rb +5 -3
- data/vendored/puppet/lib/puppet/indirector/request.rb +6 -2
- data/vendored/puppet/lib/puppet/module/task.rb +2 -2
- data/vendored/puppet/lib/puppet/module_tool/tar/mini.rb +57 -4
- data/vendored/puppet/lib/puppet/network/authconfig.rb +1 -1
- data/vendored/puppet/lib/puppet/network/http/api/indirected_routes.rb +1 -0
- data/vendored/puppet/lib/puppet/network/resolver.rb +1 -2
- data/vendored/puppet/lib/puppet/node.rb +4 -3
- data/vendored/puppet/lib/puppet/parser/compiler.rb +12 -5
- data/vendored/puppet/lib/puppet/parser/compiler/catalog_validator/env_relationship_validator.rb +1 -1
- data/vendored/puppet/lib/puppet/parser/functions/fqdn_rand.rb +15 -4
- data/vendored/puppet/lib/puppet/parser/functions/new.rb +31 -46
- data/vendored/puppet/lib/puppet/parser/parser_factory.rb +1 -1
- data/vendored/puppet/lib/puppet/parser/resource.rb +1 -1
- data/vendored/puppet/lib/puppet/parser/type_loader.rb +11 -11
- data/vendored/puppet/lib/puppet/pops/evaluator/closure.rb +1 -1
- data/vendored/puppet/lib/puppet/pops/evaluator/collector_transformer.rb +1 -1
- data/vendored/puppet/lib/puppet/pops/evaluator/epp_evaluator.rb +2 -2
- data/vendored/puppet/lib/puppet/pops/evaluator/runtime3_resource_support.rb +2 -2
- data/vendored/puppet/lib/puppet/pops/evaluator/runtime3_support.rb +5 -2
- data/vendored/puppet/lib/puppet/pops/functions/dispatch.rb +1 -1
- data/vendored/puppet/lib/puppet/pops/issue_reporter.rb +18 -1
- data/vendored/puppet/lib/puppet/pops/issues.rb +6 -3
- data/vendored/puppet/lib/puppet/pops/loader/ruby_data_type_instantiator.rb +1 -2
- data/vendored/puppet/lib/puppet/pops/loader/ruby_function_instantiator.rb +1 -2
- data/vendored/puppet/lib/puppet/pops/loader/task_instantiator.rb +4 -4
- data/vendored/puppet/lib/puppet/pops/loader/type_definition_instantiator.rb +4 -1
- data/vendored/puppet/lib/puppet/pops/loaders.rb +18 -7
- data/vendored/puppet/lib/puppet/pops/lookup/global_data_provider.rb +1 -1
- data/vendored/puppet/lib/puppet/pops/model/factory.rb +6 -3
- data/vendored/puppet/lib/puppet/pops/model/model_tree_dumper.rb +4 -0
- data/vendored/puppet/lib/puppet/pops/model/pn_transformer.rb +400 -0
- data/vendored/puppet/lib/puppet/pops/parser/eparser.rb +1 -1
- data/vendored/puppet/lib/puppet/pops/parser/heredoc_support.rb +1 -1
- data/vendored/puppet/lib/puppet/pops/parser/lexer_support.rb +3 -2
- data/vendored/puppet/lib/puppet/pops/parser/locator.rb +0 -2
- data/vendored/puppet/lib/puppet/pops/parser/pn_parser.rb +316 -0
- data/vendored/puppet/lib/puppet/pops/pcore.rb +17 -17
- data/vendored/puppet/lib/puppet/pops/pn.rb +236 -0
- data/vendored/puppet/lib/puppet/pops/resource/resource_type_impl.rb +1 -1
- data/vendored/puppet/lib/puppet/pops/types/class_loader.rb +6 -3
- data/vendored/puppet/lib/puppet/pops/types/implementation_registry.rb +28 -35
- data/vendored/puppet/lib/puppet/pops/types/p_object_type.rb +3 -3
- data/vendored/puppet/lib/puppet/pops/types/p_timespan_type.rb +2 -2
- data/vendored/puppet/lib/puppet/pops/types/p_type_set_type.rb +24 -1
- data/vendored/puppet/lib/puppet/pops/types/ruby_generator.rb +3 -4
- data/vendored/puppet/lib/puppet/pops/types/type_calculator.rb +1 -1
- data/vendored/puppet/lib/puppet/pops/types/type_factory.rb +0 -4
- data/vendored/puppet/lib/puppet/pops/types/type_mismatch_describer.rb +1 -1
- data/vendored/puppet/lib/puppet/pops/types/type_parser.rb +14 -7
- data/vendored/puppet/lib/puppet/pops/types/types.rb +1 -1
- data/vendored/puppet/lib/puppet/pops/utils.rb +2 -2
- data/vendored/puppet/lib/puppet/pops/validation/checker4_0.rb +6 -2
- data/vendored/puppet/lib/puppet/provider/group/groupadd.rb +3 -1
- data/vendored/puppet/lib/puppet/provider/group/windows_adsi.rb +4 -7
- data/vendored/puppet/lib/puppet/provider/nameservice.rb +3 -3
- data/vendored/puppet/lib/puppet/provider/package/dnf.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/package/gem.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/package/pacman.rb +4 -4
- data/vendored/puppet/lib/puppet/provider/package/pip.rb +3 -3
- data/vendored/puppet/lib/puppet/provider/package/pkgdmg.rb +3 -3
- data/vendored/puppet/lib/puppet/provider/package/pkgutil.rb +2 -2
- data/vendored/puppet/lib/puppet/provider/package/portage.rb +9 -9
- data/vendored/puppet/lib/puppet/provider/package/zypper.rb +2 -2
- data/vendored/puppet/lib/puppet/provider/service/base.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/service/smf.rb +3 -2
- data/vendored/puppet/lib/puppet/provider/user/useradd.rb +6 -2
- data/vendored/puppet/lib/puppet/provider/user/windows_adsi.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/zfs/zfs.rb +3 -2
- data/vendored/puppet/lib/puppet/reference/configuration.rb +2 -0
- data/vendored/puppet/lib/puppet/reference/type.rb +11 -11
- data/vendored/puppet/lib/puppet/resource.rb +1 -1
- data/vendored/puppet/lib/puppet/resource/capability_finder.rb +2 -2
- data/vendored/puppet/lib/puppet/resource/catalog.rb +2 -2
- data/vendored/puppet/lib/puppet/resource/status.rb +9 -2
- data/vendored/puppet/lib/puppet/resource/type.rb +1 -1
- data/vendored/puppet/lib/puppet/settings.rb +31 -19
- data/vendored/puppet/lib/puppet/settings/base_setting.rb +5 -0
- data/vendored/puppet/lib/puppet/settings/config_file.rb +1 -1
- data/vendored/puppet/lib/puppet/settings/ttl_setting.rb +5 -0
- data/vendored/puppet/lib/puppet/ssl/certificate_factory.rb +2 -2
- data/vendored/puppet/lib/puppet/ssl/certificate_request.rb +0 -2
- data/vendored/puppet/lib/puppet/transaction/additional_resource_generator.rb +2 -2
- data/vendored/puppet/lib/puppet/transaction/event.rb +1 -1
- data/vendored/puppet/lib/puppet/transaction/report.rb +1 -1
- data/vendored/puppet/lib/puppet/type.rb +9 -13
- data/vendored/puppet/lib/puppet/type/augeas.rb +2 -2
- data/vendored/puppet/lib/puppet/type/cron.rb +11 -6
- data/vendored/puppet/lib/puppet/type/exec.rb +1 -1
- data/vendored/puppet/lib/puppet/type/file.rb +4 -5
- data/vendored/puppet/lib/puppet/type/host.rb +1 -1
- data/vendored/puppet/lib/puppet/type/k5login.rb +30 -54
- data/vendored/puppet/lib/puppet/type/package.rb +3 -3
- data/vendored/puppet/lib/puppet/type/schedule.rb +12 -12
- data/vendored/puppet/lib/puppet/type/scheduled_task.rb +2 -2
- data/vendored/puppet/lib/puppet/type/ssh_authorized_key.rb +5 -5
- data/vendored/puppet/lib/puppet/type/sshkey.rb +2 -2
- data/vendored/puppet/lib/puppet/type/tidy.rb +9 -2
- data/vendored/puppet/lib/puppet/type/user.rb +1 -1
- data/vendored/puppet/lib/puppet/type/yumrepo.rb +25 -4
- data/vendored/puppet/lib/puppet/type/zfs.rb +4 -0
- data/vendored/puppet/lib/puppet/util.rb +0 -4
- data/vendored/puppet/lib/puppet/util/backups.rb +1 -1
- data/vendored/puppet/lib/puppet/util/http_proxy.rb +4 -2
- data/vendored/puppet/lib/puppet/util/inifile.rb +3 -4
- data/vendored/puppet/lib/puppet/util/log.rb +2 -5
- data/vendored/puppet/lib/puppet/util/network_device/cisco/facts.rb +1 -1
- data/vendored/puppet/lib/puppet/util/reference.rb +1 -8
- data/vendored/puppet/lib/puppet/util/tagging.rb +1 -1
- data/vendored/puppet/lib/puppet/util/warnings.rb +0 -2
- data/vendored/puppet/lib/puppet/util/windows/adsi.rb +15 -18
- data/vendored/puppet/lib/puppet/util/windows/com.rb +2 -1
- data/vendored/puppet/lib/puppet/util/windows/file.rb +2 -2
- data/vendored/puppet/lib/puppet/util/windows/principal.rb +7 -6
- data/vendored/puppet/lib/puppet/util/windows/sid.rb +60 -7
- data/vendored/puppet/lib/puppet/util/windows/taskscheduler.rb +0 -9
- data/vendored/puppet/lib/puppet/version.rb +1 -1
- data/vendored/puppet/lib/puppet_pal.rb +53 -48
- metadata +15 -2
@@ -16,7 +16,7 @@ module Puppet::Parser
|
|
16
16
|
# EvaluatingParser to the 3x way of parsing.
|
17
17
|
#
|
18
18
|
def self.evaluating_parser
|
19
|
-
unless defined?(Puppet::
|
19
|
+
unless defined?(Puppet::Parser::E4ParserAdapter)
|
20
20
|
require 'puppet/parser/e4_parser_adapter'
|
21
21
|
require 'puppet/pops/parser/code_merger'
|
22
22
|
end
|
@@ -332,7 +332,7 @@ class Puppet::Parser::Resource < Puppet::Resource
|
|
332
332
|
def add_scope_tags
|
333
333
|
scope_resource = scope.resource
|
334
334
|
unless scope_resource.nil? || scope_resource.equal?(self)
|
335
|
-
|
335
|
+
merge_tags_from(scope_resource)
|
336
336
|
end
|
337
337
|
end
|
338
338
|
|
@@ -110,20 +110,20 @@ class Puppet::Parser::TypeLoader
|
|
110
110
|
# There is currently one user in indirector/resourcetype/parser
|
111
111
|
#
|
112
112
|
if Puppet.lookup(:squelch_parse_errors) {|| false }
|
113
|
-
|
114
|
-
loaded_asts << parse_file(file)
|
115
|
-
rescue => e
|
116
|
-
# Resume from errors so that all parseable files may
|
117
|
-
# still be parsed. Mark this file as loaded so that
|
118
|
-
# it would not be parsed next time (handle it as if
|
119
|
-
# it was successfully parsed).
|
120
|
-
Puppet.debug("Unable to parse '#{file}': #{e.message}")
|
121
|
-
end
|
122
|
-
else
|
113
|
+
begin
|
123
114
|
loaded_asts << parse_file(file)
|
115
|
+
rescue => e
|
116
|
+
# Resume from errors so that all parseable files may
|
117
|
+
# still be parsed. Mark this file as loaded so that
|
118
|
+
# it would not be parsed next time (handle it as if
|
119
|
+
# it was successfully parsed).
|
120
|
+
Puppet.debug("Unable to parse '#{file}': #{e.message}")
|
124
121
|
end
|
122
|
+
else
|
123
|
+
loaded_asts << parse_file(file)
|
124
|
+
end
|
125
125
|
|
126
|
-
|
126
|
+
@loaded[file] = true
|
127
127
|
end
|
128
128
|
|
129
129
|
loaded_asts.collect do |ast|
|
@@ -80,7 +80,7 @@ class Closure < CallableSignature
|
|
80
80
|
|
81
81
|
def call_by_name_with_scope(scope, args_hash, enforce_parameters)
|
82
82
|
call_by_name_internal(scope, args_hash, enforce_parameters)
|
83
|
-
|
83
|
+
end
|
84
84
|
|
85
85
|
def call_by_name(args_hash, enforce_parameters)
|
86
86
|
call_by_name_internal(enclosing_scope, args_hash, enforce_parameters)
|
@@ -53,8 +53,6 @@ class Puppet::Pops::Evaluator::EppEvaluator
|
|
53
53
|
evaluate(parser, 'epp', scope, true, result, template_args)
|
54
54
|
end
|
55
55
|
|
56
|
-
private
|
57
|
-
|
58
56
|
def self.evaluate(parser, func_name, scope, use_global_scope_only, parse_result, template_args)
|
59
57
|
template_args, template_args_set = handle_template_args(func_name, template_args)
|
60
58
|
|
@@ -104,6 +102,7 @@ class Puppet::Pops::Evaluator::EppEvaluator
|
|
104
102
|
parser.closure(body, scope).call_by_name(template_args, enforce_parameters)
|
105
103
|
end
|
106
104
|
end
|
105
|
+
private_class_method :evaluate
|
107
106
|
|
108
107
|
def self.handle_template_args(func_name, template_args)
|
109
108
|
if template_args.nil?
|
@@ -117,4 +116,5 @@ class Puppet::Pops::Evaluator::EppEvaluator
|
|
117
116
|
[template_args, true]
|
118
117
|
end
|
119
118
|
end
|
119
|
+
private_class_method :handle_template_args
|
120
120
|
end
|
@@ -89,8 +89,6 @@ module Runtime3ResourceSupport
|
|
89
89
|
scope.environment.known_resource_types.find_hostclass(class_name)
|
90
90
|
end
|
91
91
|
|
92
|
-
private
|
93
|
-
|
94
92
|
def self.find_builtin_resource_type(scope, type_name)
|
95
93
|
if type_name.include?(':')
|
96
94
|
# Skip the search for built in types as they are always in global namespace
|
@@ -106,11 +104,13 @@ module Runtime3ResourceSupport
|
|
106
104
|
# horrible - should be loaded by a "last loader" in 4.x loaders instead.
|
107
105
|
Puppet::Type.type(type_name)
|
108
106
|
end
|
107
|
+
private_class_method :find_builtin_resource_type
|
109
108
|
|
110
109
|
def self.find_defined_resource_type(scope, type_name)
|
111
110
|
krt = scope.environment.known_resource_types
|
112
111
|
krt.find_definition(type_name) || krt.application(type_name)
|
113
112
|
end
|
113
|
+
private_class_method :find_defined_resource_type
|
114
114
|
|
115
115
|
end
|
116
116
|
end
|
@@ -301,10 +301,13 @@ module Runtime3Support
|
|
301
301
|
def call_function(name, args, o, scope, &block)
|
302
302
|
file, line = extract_file_line(o)
|
303
303
|
loader = Adapters::LoaderAdapter.loader_for_model_object(o, file)
|
304
|
-
|
304
|
+
# 'ruby -wc' thinks that _func is unused, because the only reference to it
|
305
|
+
# is inside of the Kernel.eval string below. By prefixing it with the
|
306
|
+
# underscore, we let Ruby know to not worry about whether it's unused or not.
|
307
|
+
if loader && _func = loader.load(:function, name)
|
305
308
|
Puppet::Util::Profiler.profile(name, [:functions, name]) do
|
306
309
|
# Add stack frame when calling. See Puppet::Pops::PuppetStack
|
307
|
-
return Kernel.eval('
|
310
|
+
return Kernel.eval('_func.call(scope, *args, &block)'.freeze, Kernel.binding, file || '', line)
|
308
311
|
end
|
309
312
|
end
|
310
313
|
# Call via 3x API if function exists there
|
@@ -86,6 +86,22 @@ class IssueReporter
|
|
86
86
|
[prefix, message].join(' ')
|
87
87
|
end
|
88
88
|
|
89
|
+
def self.warning(semantic, issue, args)
|
90
|
+
Puppet::Util::Log.create({
|
91
|
+
:level => :warning,
|
92
|
+
:message => issue.format(args),
|
93
|
+
:arguments => args,
|
94
|
+
:issue_code => issue.issue_code,
|
95
|
+
:file => semantic.file,
|
96
|
+
:line => semantic.line,
|
97
|
+
:pos => semantic.pos,
|
98
|
+
})
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.error(exception_class, semantic, issue, args)
|
102
|
+
raise exception_class.new(issue.format(args), semantic.file, semantic.line, semantic.pos, nil, issue.issue_code, args)
|
103
|
+
end
|
104
|
+
|
89
105
|
def self.create_exception(exception_class, emit_message, formatter, diagnostic)
|
90
106
|
file = diagnostic.file
|
91
107
|
file = (file.is_a?(String) && file.empty?) ? nil : file
|
@@ -94,7 +110,7 @@ class IssueReporter
|
|
94
110
|
line = diagnostic.source_pos.line
|
95
111
|
pos = diagnostic.source_pos.pos
|
96
112
|
end
|
97
|
-
exception_class.new(format_with_prefix(emit_message, formatter.format_message(diagnostic)), file, line, pos, nil, diagnostic.issue.issue_code)
|
113
|
+
exception_class.new(format_with_prefix(emit_message, formatter.format_message(diagnostic)), file, line, pos, nil, diagnostic.issue.issue_code, diagnostic.arguments)
|
98
114
|
end
|
99
115
|
private_class_method :create_exception
|
100
116
|
|
@@ -109,6 +125,7 @@ class IssueReporter
|
|
109
125
|
Puppet::Util::Log.create({
|
110
126
|
:level => severity,
|
111
127
|
:message => formatter.format_message(diagnostic),
|
128
|
+
:arguments => diagnostic.arguments,
|
112
129
|
:issue_code => diagnostic.issue.issue_code,
|
113
130
|
:file => file,
|
114
131
|
:line => line,
|
@@ -49,7 +49,6 @@ module Issues
|
|
49
49
|
# Evaluate the message block in the msg data's binding
|
50
50
|
msgdata.format(hash, &message_block)
|
51
51
|
rescue StandardError => e
|
52
|
-
MessageData
|
53
52
|
raise RuntimeError, _("Error while reporting issue: %{code}. %{message}") % { code: issue_code, message: e.message }, caller
|
54
53
|
end
|
55
54
|
end
|
@@ -71,7 +70,7 @@ module Issues
|
|
71
70
|
|
72
71
|
def format(hash, &block)
|
73
72
|
@data = hash
|
74
|
-
instance_eval
|
73
|
+
instance_eval(&block)
|
75
74
|
end
|
76
75
|
|
77
76
|
# Obtains the label provider given as a key `:label` in the hash passed to #format. The label provider is
|
@@ -119,7 +118,7 @@ module Issues
|
|
119
118
|
# @see MessageData
|
120
119
|
# @api public
|
121
120
|
#
|
122
|
-
def self.issue
|
121
|
+
def self.issue(issue_code, *args, &block)
|
123
122
|
Issue.new(issue_code, *args, &block)
|
124
123
|
end
|
125
124
|
|
@@ -741,6 +740,10 @@ module Issues
|
|
741
740
|
_('Heredoc without any following lines of text')
|
742
741
|
end
|
743
742
|
|
743
|
+
HEREDOC_EMPTY_ENDTAG = hard_issue :HEREDOC_EMPTY_ENDTAG do
|
744
|
+
_('Heredoc with an empty endtag')
|
745
|
+
end
|
746
|
+
|
744
747
|
HEREDOC_MULTIPLE_AT_ESCAPES = hard_issue :HEREDOC_MULTIPLE_AT_ESCAPES, :escapes do
|
745
748
|
_("An escape char for @() may only appear once. Got '%{escapes}'") % { escapes: escapes.join(', ') }
|
746
749
|
end
|
@@ -29,12 +29,11 @@ class Puppet::Pops::Loader::RubyDataTypeInstantiator
|
|
29
29
|
created
|
30
30
|
end
|
31
31
|
|
32
|
-
private
|
33
|
-
|
34
32
|
# Produces a binding where the given loader is bound as a local variable (loader_injected_arg). This variable can be used in loaded
|
35
33
|
# ruby code - e.g. to call Puppet::Function.create_loaded_function(:name, loader,...)
|
36
34
|
#
|
37
35
|
def self.get_binding(loader_injected_arg)
|
38
36
|
binding
|
39
37
|
end
|
38
|
+
private_class_method :get_binding
|
40
39
|
end
|
@@ -35,12 +35,11 @@ class Puppet::Pops::Loader::RubyFunctionInstantiator
|
|
35
35
|
created.new(nil, loader_for_function)
|
36
36
|
end
|
37
37
|
|
38
|
-
private
|
39
|
-
|
40
38
|
# Produces a binding where the given loader is bound as a local variable (loader_injected_arg). This variable can be used in loaded
|
41
39
|
# ruby code - e.g. to call Puppet::Function.create_loaded_function(:name, loader,...)
|
42
40
|
#
|
43
41
|
def self.get_binding(loader_injected_arg)
|
44
42
|
binding
|
45
43
|
end
|
44
|
+
private_class_method :get_binding
|
46
45
|
end
|
@@ -27,11 +27,11 @@ class TaskInstantiator
|
|
27
27
|
|
28
28
|
def self.create_task(loader, name, task_source, metadata)
|
29
29
|
if metadata.nil?
|
30
|
-
create_task_from_hash(
|
30
|
+
create_task_from_hash(name, task_source, EMPTY_HASH)
|
31
31
|
else
|
32
32
|
json_text = loader.get_contents(metadata)
|
33
33
|
begin
|
34
|
-
create_task_from_hash(
|
34
|
+
create_task_from_hash(name, task_source, JSON.parse(json_text) || EMPTY_HASH)
|
35
35
|
rescue JSON::ParserError => ex
|
36
36
|
raise Puppet::ParseError.new(ex.message, metadata)
|
37
37
|
rescue Types::TypeAssertionError => ex
|
@@ -43,7 +43,7 @@ class TaskInstantiator
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
def self.create_task_from_hash(
|
46
|
+
def self.create_task_from_hash(name, task_source, hash)
|
47
47
|
arguments = {
|
48
48
|
'name' => name,
|
49
49
|
'executable' => task_source
|
@@ -54,7 +54,7 @@ class TaskInstantiator
|
|
54
54
|
value.each_pair do |k, v|
|
55
55
|
pd = v.dup
|
56
56
|
t = v['type']
|
57
|
-
pd['type'] = t.nil? ? Types::TypeFactory.data : Types::TypeParser.singleton.parse(t
|
57
|
+
pd['type'] = t.nil? ? Types::TypeFactory.data : Types::TypeParser.singleton.parse(t)
|
58
58
|
ps[k] = pd
|
59
59
|
end
|
60
60
|
value = ps
|
@@ -73,7 +73,9 @@ class TypeDefinitionInstantiator
|
|
73
73
|
case type_name
|
74
74
|
when 'Object'
|
75
75
|
# No need for an alias. The Object type itself will receive the name instead
|
76
|
-
|
76
|
+
unless type_expr.is_a?(Model::LiteralHash)
|
77
|
+
type_expr = type_expr.keys.empty? ? nil : type_expr.keys[0] unless type_expr.is_a?(Hash)
|
78
|
+
end
|
77
79
|
Types::PObjectType.new(name, type_expr)
|
78
80
|
when 'TypeSet'
|
79
81
|
# No need for an alias. The Object type itself will receive the name instead
|
@@ -86,6 +88,7 @@ class TypeDefinitionInstantiator
|
|
86
88
|
|
87
89
|
# @api private
|
88
90
|
def self.named_definition(te)
|
91
|
+
return 'Object' if te.is_a?(Model::LiteralHash)
|
89
92
|
te.is_a?(Model::AccessExpression) && (left = te.left_expr).is_a?(Model::QualifiedReference) ? left.cased_value : nil
|
90
93
|
end
|
91
94
|
|
@@ -15,7 +15,6 @@ class Loaders
|
|
15
15
|
attr_reader :puppet_system_loader
|
16
16
|
attr_reader :public_environment_loader
|
17
17
|
attr_reader :private_environment_loader
|
18
|
-
attr_reader :implementation_registry
|
19
18
|
attr_reader :environment
|
20
19
|
|
21
20
|
def self.new(environment, for_agent = false)
|
@@ -55,12 +54,9 @@ class Loaders
|
|
55
54
|
create_environment_loader(environment)
|
56
55
|
end
|
57
56
|
|
58
|
-
|
59
|
-
# the current environment
|
60
|
-
@implementation_registry = Types::ImplementationRegistry.new(@private_environment_loader)
|
61
|
-
Pcore.init(@puppet_system_loader, @implementation_registry, for_agent)
|
57
|
+
Pcore.init_env(@private_environment_loader)
|
62
58
|
|
63
|
-
#
|
59
|
+
# 3. module loaders are set up from the create_environment_loader, they register themselves
|
64
60
|
end
|
65
61
|
|
66
62
|
# Called after loader has been added to Puppet Context as :loaders so that dynamic types can
|
@@ -91,11 +87,21 @@ class Loaders
|
|
91
87
|
loaders.find_loader(module_name)
|
92
88
|
end
|
93
89
|
|
90
|
+
def self.static_implementation_registry
|
91
|
+
if !class_variable_defined?(:@@static_implementation_registry) || @@static_implementation_registry.nil?
|
92
|
+
ir = Types::ImplementationRegistry.new
|
93
|
+
Types::TypeParser.type_map.values.each { |t| ir.register_implementation(t.simple_name, t.class.name) }
|
94
|
+
@@static_implementation_registry = ir
|
95
|
+
end
|
96
|
+
@@static_implementation_registry
|
97
|
+
end
|
98
|
+
|
94
99
|
def self.static_loader
|
95
100
|
# The static loader can only be changed after a reboot
|
96
101
|
if !class_variable_defined?(:@@static_loader) || @@static_loader.nil?
|
97
102
|
@@static_loader = Loader::StaticLoader.new()
|
98
103
|
@@static_loader.register_aliases
|
104
|
+
Pcore.init(@@static_loader, static_implementation_registry)
|
99
105
|
end
|
100
106
|
@@static_loader
|
101
107
|
end
|
@@ -206,6 +212,11 @@ class Loaders
|
|
206
212
|
end
|
207
213
|
end
|
208
214
|
|
215
|
+
def implementation_registry
|
216
|
+
# Environment specific implementation registry
|
217
|
+
@implementation_registry ||= Types::ImplementationRegistry.new(self.class.static_implementation_registry)
|
218
|
+
end
|
219
|
+
|
209
220
|
def static_loader
|
210
221
|
self.class.static_loader
|
211
222
|
end
|
@@ -337,7 +348,7 @@ class Loaders
|
|
337
348
|
tf = Types::TypeParser.singleton
|
338
349
|
lhs = tf.interpret(type_mapping.type_expr, loader)
|
339
350
|
rhs = tf.interpret_any(type_mapping.mapping_expr, loader)
|
340
|
-
implementation_registry.register_type_mapping(lhs, rhs
|
351
|
+
implementation_registry.register_type_mapping(lhs, rhs)
|
341
352
|
nil
|
342
353
|
end
|
343
354
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'hiera/scope'
|
1
2
|
require_relative 'configured_data_provider'
|
2
3
|
|
3
4
|
module Puppet::Pops
|
@@ -11,7 +12,6 @@ class GlobalDataProvider < ConfiguredDataProvider
|
|
11
12
|
def unchecked_key_lookup(key, lookup_invocation, merge)
|
12
13
|
config = config(lookup_invocation)
|
13
14
|
if(config.version == 3)
|
14
|
-
require 'hiera/scope'
|
15
15
|
# Hiera version 3 needs access to special scope variables
|
16
16
|
scope = lookup_invocation.scope
|
17
17
|
unless scope.is_a?(Hiera::Scope)
|
@@ -179,7 +179,8 @@ class Factory
|
|
179
179
|
end
|
180
180
|
|
181
181
|
def build_ConcatenatedString(o, args)
|
182
|
-
|
182
|
+
# Strip empty segments
|
183
|
+
@init_hash['segments'] = args.reject { |arg| arg.model_class == LiteralString && arg['value'].empty? }
|
183
184
|
end
|
184
185
|
|
185
186
|
def build_HeredocExpression(o, name, expr)
|
@@ -452,10 +453,12 @@ class Factory
|
|
452
453
|
#
|
453
454
|
parent = type_expr['key']
|
454
455
|
hash = type_expr['value']
|
455
|
-
|
456
|
+
pn = parent['cased_value']
|
457
|
+
unless pn == 'Object' || pn == 'TypeSet'
|
456
458
|
hash['entries'] << Factory.KEY_ENTRY(Factory.QNAME('parent'), parent)
|
459
|
+
parent = Factory.QREF('Object')
|
457
460
|
end
|
458
|
-
type_expr =
|
461
|
+
type_expr = parent.access([hash])
|
459
462
|
elsif type_expr.model_class <= LiteralHash
|
460
463
|
# LiteralHash is used for the form:
|
461
464
|
#
|
@@ -28,6 +28,10 @@ class Puppet::Pops::Model::ModelTreeDumper < Puppet::Pops::Model::TreeDumper
|
|
28
28
|
o.value.to_s
|
29
29
|
end
|
30
30
|
|
31
|
+
def dump_QualifiedReference o
|
32
|
+
o.cased_value.to_s
|
33
|
+
end
|
34
|
+
|
31
35
|
def dump_Factory o
|
32
36
|
o['locator'] ||= Puppet::Pops::Parser::Locator.locator("<not from source>", nil)
|
33
37
|
do_dump(o.model)
|
@@ -0,0 +1,400 @@
|
|
1
|
+
module Puppet::Pops
|
2
|
+
module Model
|
3
|
+
|
4
|
+
|
5
|
+
class PNTransformer
|
6
|
+
def self.visitor
|
7
|
+
@visitor ||= Visitor.new(nil, 'transform', 0, 0)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.singleton
|
11
|
+
@singleton ||= new(visitor)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.transform(ast)
|
15
|
+
singleton.transform(ast)
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(visitor)
|
19
|
+
@visitor = visitor
|
20
|
+
end
|
21
|
+
|
22
|
+
def transform(ast)
|
23
|
+
@visitor.visit_this_0(self, ast)
|
24
|
+
end
|
25
|
+
|
26
|
+
def transform_AccessExpression(e)
|
27
|
+
PN::List.new([transform(e.left_expr)] + pn_array(e.keys)).as_call('access')
|
28
|
+
end
|
29
|
+
|
30
|
+
def transform_AndExpression(e)
|
31
|
+
binary_op(e, 'and')
|
32
|
+
end
|
33
|
+
|
34
|
+
def transform_Application(e)
|
35
|
+
definition_to_pn(e, 'application')
|
36
|
+
end
|
37
|
+
|
38
|
+
def transform_ArithmeticExpression(e)
|
39
|
+
binary_op(e, e.operator)
|
40
|
+
end
|
41
|
+
|
42
|
+
def transform_Array(a)
|
43
|
+
PN::List.new(pn_array(a))
|
44
|
+
end
|
45
|
+
|
46
|
+
def transform_AssignmentExpression(e)
|
47
|
+
binary_op(e, e.operator)
|
48
|
+
end
|
49
|
+
|
50
|
+
def transform_AttributeOperation(e)
|
51
|
+
PN::Call.new(e.operator, PN::Literal.new(e.attribute_name), transform(e.value_expr))
|
52
|
+
end
|
53
|
+
|
54
|
+
def transform_AttributesOperation(e)
|
55
|
+
PN::Call.new('splat-hash', transform(e.expr))
|
56
|
+
end
|
57
|
+
|
58
|
+
def transform_BlockExpression(e)
|
59
|
+
transform(e.statements).as_call('block')
|
60
|
+
end
|
61
|
+
|
62
|
+
def transform_CallFunctionExpression(e)
|
63
|
+
call_to_pn(e, 'call-lambda', 'invoke-lambda')
|
64
|
+
end
|
65
|
+
|
66
|
+
def transform_CallMethodExpression(e)
|
67
|
+
call_to_pn(e, 'call-method', 'invoke-method')
|
68
|
+
end
|
69
|
+
|
70
|
+
def transform_CallNamedFunctionExpression(e)
|
71
|
+
call_to_pn(e, 'call', 'invoke')
|
72
|
+
end
|
73
|
+
|
74
|
+
def transform_CapabilityMapping(e)
|
75
|
+
PN::Call.new(e.kind, transform(e.component), PN::List.new([PN::Literal.new(e.capability)] + pn_array(e.mappings)))
|
76
|
+
end
|
77
|
+
|
78
|
+
def transform_CaseExpression(e)
|
79
|
+
PN::Call.new('case', transform(e.test), transform(e.options))
|
80
|
+
end
|
81
|
+
|
82
|
+
def transform_CaseOption(e)
|
83
|
+
PN::Map.new([transform(e.values).with_name('when'), block_as_entry('then', e.then_expr)])
|
84
|
+
end
|
85
|
+
|
86
|
+
def transform_CollectExpression(e)
|
87
|
+
entries = [transform(e.type_expr).with_name('type'), transform(e.query).with_name('query')]
|
88
|
+
entries << transform(e.operations).with_name('ops') unless e.operations.empty?
|
89
|
+
PN::Map.new(entries).as_call('collect')
|
90
|
+
end
|
91
|
+
|
92
|
+
def transform_ComparisonExpression(e)
|
93
|
+
binary_op(e, e.operator)
|
94
|
+
end
|
95
|
+
|
96
|
+
def transform_ConcatenatedString(e)
|
97
|
+
transform(e.segments).as_call('concat')
|
98
|
+
end
|
99
|
+
|
100
|
+
def transform_EppExpression(e)
|
101
|
+
e.body.nil? ? PN::Call.new('epp') : transform(e.body).as_call('epp')
|
102
|
+
end
|
103
|
+
|
104
|
+
def transform_ExportedQuery(e)
|
105
|
+
is_nop?(e.expr) ? PN::Call.new('exported-query') : PN::Call.new('exported-query', transform(e.expr))
|
106
|
+
end
|
107
|
+
|
108
|
+
def transform_Factory(e)
|
109
|
+
transform(e.model)
|
110
|
+
end
|
111
|
+
|
112
|
+
def transform_FunctionDefinition(e)
|
113
|
+
definition_to_pn(e, 'function', nil, e.return_type)
|
114
|
+
end
|
115
|
+
|
116
|
+
def transform_HeredocExpression(e)
|
117
|
+
entries = []
|
118
|
+
entries << PN::Literal.new(e.syntax).with_name('syntax') unless e.syntax == ''
|
119
|
+
entries << transform(e.text_expr).with_name('text')
|
120
|
+
PN::Map.new(entries).as_call('heredoc')
|
121
|
+
end
|
122
|
+
|
123
|
+
def transform_HostClassDefinition(e)
|
124
|
+
definition_to_pn(e, 'class', e.parent_class)
|
125
|
+
end
|
126
|
+
|
127
|
+
def transform_IfExpression(e)
|
128
|
+
if_to_pn(e, 'if')
|
129
|
+
end
|
130
|
+
|
131
|
+
def transform_InExpression(e)
|
132
|
+
binary_op(e, 'in')
|
133
|
+
end
|
134
|
+
|
135
|
+
def transform_KeyedEntry(e)
|
136
|
+
PN::Call.new('=>', transform(e.key), transform(e.value))
|
137
|
+
end
|
138
|
+
|
139
|
+
def transform_LambdaExpression(e)
|
140
|
+
entries = []
|
141
|
+
entries << parameters_entry(e.parameters) unless e.parameters.empty?
|
142
|
+
entries << transform(e.return_type).with_name('returns') unless e.return_type.nil?
|
143
|
+
entries << block_as_entry('body', e.body) unless e.body.nil?
|
144
|
+
PN::Map.new(entries).as_call('lambda')
|
145
|
+
end
|
146
|
+
|
147
|
+
def transform_LiteralBoolean(e)
|
148
|
+
PN::Literal.new(e.value)
|
149
|
+
end
|
150
|
+
|
151
|
+
def transform_LiteralDefault(_)
|
152
|
+
PN::Call.new('default')
|
153
|
+
end
|
154
|
+
|
155
|
+
def transform_LiteralFloat(e)
|
156
|
+
PN::Literal.new(e.value)
|
157
|
+
end
|
158
|
+
|
159
|
+
def transform_LiteralHash(e)
|
160
|
+
transform(e.entries).as_call('hash')
|
161
|
+
end
|
162
|
+
|
163
|
+
def transform_LiteralInteger(e)
|
164
|
+
vl = PN::Literal.new(e.value)
|
165
|
+
e.radix == 10 ? vl : PN::Map.new([PN::Literal.new(e.radix).with_name('radix'), vl.with_name('value')]).as_call('int')
|
166
|
+
end
|
167
|
+
|
168
|
+
def transform_LiteralList(e)
|
169
|
+
transform(e.values).as_call('array')
|
170
|
+
end
|
171
|
+
|
172
|
+
def transform_LiteralRegularExpression(e)
|
173
|
+
PN::Literal.new(Types::PRegexpType.regexp_to_s(e.value)).as_call('regexp')
|
174
|
+
end
|
175
|
+
|
176
|
+
def transform_LiteralString(e)
|
177
|
+
PN::Literal.new(e.value)
|
178
|
+
end
|
179
|
+
|
180
|
+
def transform_LiteralUndef(_)
|
181
|
+
PN::Literal.new(nil)
|
182
|
+
end
|
183
|
+
|
184
|
+
def transform_MatchExpression(e)
|
185
|
+
binary_op(e, e.operator)
|
186
|
+
end
|
187
|
+
|
188
|
+
def transform_NamedAccessExpression(e)
|
189
|
+
binary_op(e, '.')
|
190
|
+
end
|
191
|
+
|
192
|
+
def transform_NodeDefinition(e)
|
193
|
+
entries = [transform(e.host_matches).with_name('matches')]
|
194
|
+
entries << transform(e.parent).with_name('parent') unless e.parent.nil?
|
195
|
+
entries << block_as_entry('body', e.body) unless e.body.nil?
|
196
|
+
PN::Map.new(entries).as_call('node')
|
197
|
+
end
|
198
|
+
|
199
|
+
def transform_Nop(_)
|
200
|
+
PN::Call.new('nop')
|
201
|
+
end
|
202
|
+
|
203
|
+
def transform_NotExpression(e)
|
204
|
+
PN::Call.new('!', transform(e.expr))
|
205
|
+
end
|
206
|
+
|
207
|
+
def transform_OrExpression(e)
|
208
|
+
binary_op(e, 'or')
|
209
|
+
end
|
210
|
+
|
211
|
+
def transform_Parameter(e)
|
212
|
+
entries = [PN::Literal.new(e.name).with_name('name')]
|
213
|
+
entries << transform(e.type_expr).with_name('type') unless e.type_expr.nil?
|
214
|
+
entries << PN::Literal.new(true).with_name('splat') if e.captures_rest
|
215
|
+
entries << transform(e.value).with_name('value') unless e.value.nil?
|
216
|
+
PN::Map.new(entries).with_name('param')
|
217
|
+
end
|
218
|
+
|
219
|
+
def transform_ParenthesizedExpression(e)
|
220
|
+
PN::Call.new('paren', transform(e.expr))
|
221
|
+
end
|
222
|
+
|
223
|
+
def transform_PlanDefinition(e)
|
224
|
+
definition_to_pn(e, 'plan', nil, e.return_type)
|
225
|
+
end
|
226
|
+
|
227
|
+
def transform_Program(e)
|
228
|
+
transform(e.body)
|
229
|
+
end
|
230
|
+
|
231
|
+
def transform_QualifiedName(e)
|
232
|
+
PN::Call.new('qn', PN::Literal.new(e.value))
|
233
|
+
end
|
234
|
+
|
235
|
+
def transform_QualifiedReference(e)
|
236
|
+
PN::Call.new('qr', PN::Literal.new(e.cased_value))
|
237
|
+
end
|
238
|
+
|
239
|
+
def transform_RelationshipExpression(e)
|
240
|
+
binary_op(e, e.operator)
|
241
|
+
end
|
242
|
+
|
243
|
+
def transform_RenderExpression(e)
|
244
|
+
PN::Call.new('render', transform(e.expr))
|
245
|
+
end
|
246
|
+
|
247
|
+
def transform_RenderStringExpression(e)
|
248
|
+
PN::Literal.new(e.value).as_call('render-s')
|
249
|
+
end
|
250
|
+
|
251
|
+
def transform_ReservedWord(e)
|
252
|
+
PN::Literal.new(e.word).as_call('reserved')
|
253
|
+
end
|
254
|
+
|
255
|
+
def transform_ResourceBody(e)
|
256
|
+
PN::Map.new([
|
257
|
+
transform(e.title).with_name('title'),
|
258
|
+
transform(e.operations).with_name('ops')
|
259
|
+
]).as_call('resource_body')
|
260
|
+
end
|
261
|
+
|
262
|
+
def transform_ResourceDefaultsExpression(e)
|
263
|
+
entries = [transform(e.type_ref).with_name('type'), transform(e.operations).with_name('ops')]
|
264
|
+
entries << PN::Literal.new(e.form).with_name('form') unless e.form == 'regular'
|
265
|
+
PN::Map.new(entries).as_call('resource-defaults')
|
266
|
+
end
|
267
|
+
|
268
|
+
def transform_ResourceExpression(e)
|
269
|
+
entries = [
|
270
|
+
transform(e.type_name).with_name('type'),
|
271
|
+
PN::List.new(pn_array(e.bodies).map { |body| body[0] }).with_name('bodies')
|
272
|
+
]
|
273
|
+
entries << PN::Literal.new(e.form).with_name('form') unless e.form == 'regular'
|
274
|
+
PN::Map.new(entries).as_call('resource')
|
275
|
+
end
|
276
|
+
|
277
|
+
def transform_ResourceOverrideExpression(e)
|
278
|
+
entries = [transform(e.resources).with_name('resources'), transform(e.operations).with_name('ops')]
|
279
|
+
entries << PN::Literal.new(e.form).with_name('form') unless e.form == 'regular'
|
280
|
+
PN::Map.new(entries).as_call('resource-override')
|
281
|
+
end
|
282
|
+
|
283
|
+
def transform_ResourceTypeDefinition(e)
|
284
|
+
definition_to_pn(e, 'define')
|
285
|
+
end
|
286
|
+
|
287
|
+
def transform_SelectorEntry(e)
|
288
|
+
PN::Call.new('=>', transform(e.matching_expr), transform(e.value_expr))
|
289
|
+
end
|
290
|
+
|
291
|
+
def transform_SelectorExpression(e)
|
292
|
+
PN::Call.new('?', transform(e.left_expr), transform(e.selectors))
|
293
|
+
end
|
294
|
+
|
295
|
+
def transform_SiteDefinition(e)
|
296
|
+
transform(e.body).as_call('site')
|
297
|
+
end
|
298
|
+
|
299
|
+
def transform_SubLocatedExpression(e)
|
300
|
+
transform(e.expr)
|
301
|
+
end
|
302
|
+
|
303
|
+
def transform_TextExpression(e)
|
304
|
+
PN::Call.new('str', transform(e.expr))
|
305
|
+
end
|
306
|
+
|
307
|
+
def transform_TypeAlias(e)
|
308
|
+
PN::Call.new('type-alias', PN::Literal.new(e.name), transform(e.type_expr))
|
309
|
+
end
|
310
|
+
|
311
|
+
def transform_TypeDefinition(e)
|
312
|
+
PN::Call.new('type-definition', PN::Literal.new(e.name), PN::Literal.new(e.parent), transform(e.body))
|
313
|
+
end
|
314
|
+
|
315
|
+
def transform_TypeMapping(e)
|
316
|
+
PN::Call.new('type-mapping', transform(e.type_expr), transform(e.mapping_expr))
|
317
|
+
end
|
318
|
+
|
319
|
+
def transform_UnaryMinusExpression(e)
|
320
|
+
if e.expr.is_a?(LiteralValue)
|
321
|
+
v = e.expr.value
|
322
|
+
if v.is_a?(Numeric)
|
323
|
+
return PN::Literal.new(-v)
|
324
|
+
end
|
325
|
+
end
|
326
|
+
PN::Call.new('-', transform(e.expr))
|
327
|
+
end
|
328
|
+
|
329
|
+
def transform_UnfoldExpression(e)
|
330
|
+
PN::Call.new('unfold', transform(e.expr))
|
331
|
+
end
|
332
|
+
|
333
|
+
def transform_UnlessExpression(e)
|
334
|
+
if_to_pn(e, 'unless')
|
335
|
+
end
|
336
|
+
|
337
|
+
def transform_VariableExpression(e)
|
338
|
+
ne = e.expr
|
339
|
+
PN::Call.new('var', ne.is_a?(Model::QualifiedName) ? PN::Literal.new(ne.value) : transform(ne))
|
340
|
+
end
|
341
|
+
|
342
|
+
def transform_VirtualQuery(e)
|
343
|
+
is_nop?(e.expr) ? PN::Call.new('virtual-query') : PN::Call.new('virtual-query', transform(e.expr))
|
344
|
+
end
|
345
|
+
|
346
|
+
def is_nop?(e)
|
347
|
+
e.nil? || e.is_a?(Nop)
|
348
|
+
end
|
349
|
+
|
350
|
+
def binary_op(e, op)
|
351
|
+
PN::Call.new(op, transform(e.left_expr), transform(e.right_expr))
|
352
|
+
end
|
353
|
+
|
354
|
+
def definition_to_pn(e, type_name, parent = nil, return_type = nil)
|
355
|
+
entries = [PN::Literal.new(e.name).with_name('name')]
|
356
|
+
entries << PN::Literal.new(parent).with_name('parent') unless parent.nil?
|
357
|
+
entries << parameters_entry(e.parameters) unless e.parameters.empty?
|
358
|
+
entries << block_as_entry('body', e.body) unless e.body.nil?
|
359
|
+
entries << transform(return_type).with_name('returns') unless return_type.nil?
|
360
|
+
PN::Map.new(entries).as_call(type_name)
|
361
|
+
end
|
362
|
+
|
363
|
+
def parameters_entry(parameters)
|
364
|
+
PN::Map.new(parameters.map do |p|
|
365
|
+
entries = []
|
366
|
+
entries << transform(p.type_expr).with_name('type') unless p.type_expr.nil?
|
367
|
+
entries << PN::Literal(true).with_name('splat') if p.captures_rest
|
368
|
+
entries << transform(p.value).with_name('value') unless p.value.nil?
|
369
|
+
PN::Map.new(entries).with_name(p.name)
|
370
|
+
end).with_name('params')
|
371
|
+
end
|
372
|
+
|
373
|
+
def block_as_entry(name, expr)
|
374
|
+
if expr.is_a?(BlockExpression)
|
375
|
+
transform(expr.statements).with_name(name)
|
376
|
+
else
|
377
|
+
transform([expr]).with_name(name)
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
def pn_array(a)
|
382
|
+
a.map { |e| transform(e) }
|
383
|
+
end
|
384
|
+
|
385
|
+
def call_to_pn(e, r, nr)
|
386
|
+
entries = [transform(e.functor_expr).with_name('functor'), transform(e.arguments).with_name('args')]
|
387
|
+
entries << transform(e.lambda).with_name('block') unless e.lambda.nil?
|
388
|
+
PN::Map.new(entries).as_call(e.rval_required ? r : nr)
|
389
|
+
end
|
390
|
+
|
391
|
+
def if_to_pn(e, name)
|
392
|
+
entries = [transform(e.test).with_name('test')]
|
393
|
+
entries << block_as_entry('then', e.then_expr) unless is_nop?(e.then_expr)
|
394
|
+
entries << block_as_entry('else', e.else_expr) unless is_nop?(e.else_expr)
|
395
|
+
PN::Map.new(entries).as_call(name)
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
end
|
400
|
+
end
|