Class: Puppet::Pops::Model::Factory
- Inherits:
-
Object
- Object
- Puppet::Pops::Model::Factory
show all
- Defined in:
- lib/puppet/pops/model/factory.rb
Defined Under Namespace
Classes: ArgsToNonCallError
Constant Summary
collapse
- KEY_LENGTH =
Shared build_visitor, since there are many instances of Factory being used
'length'
- KEY_OFFSET =
'offset'
- KEY_LOCATOR =
'locator'
- KEY_OPERATOR =
'operator'
- KEY_VALUE =
'value'
- KEY_KEYS =
'keys'
- KEY_NAME =
'name'
- KEY_BODY =
'body'
- KEY_EXPR =
'expr'
- KEY_LEFT_EXPR =
'left_expr'
- KEY_RIGHT_EXPR =
'right_expr'
- KEY_PARAMETERS =
'parameters'
- BUILD_VISITOR =
Visitor.new(self, 'build')
- INFER_VISITOR =
Visitor.new(self, 'infer')
- INTERPOLATION_VISITOR =
Visitor.new(self, 'interpolate')
- MAPOFFSET_VISITOR =
Visitor.new(self, 'map_offset')
- STATEMENT_CALLS =
{
'require' => true,
'realize' => true,
'include' => true,
'contain' => true,
'tag' => true,
'debug' => true,
'info' => true,
'notice' => true,
'warning' => true,
'err' => true,
'fail' => true,
'import' => true, 'break' => true,
'next' => true,
'return' => true
}.freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
-
.APPLY(arguments, body) ⇒ Object
-
.APPLY_BLOCK(statements) ⇒ Object
-
.ARGUMENTS(args, arg) ⇒ Object
-
.ATTRIBUTE_OP(name, op, expr) ⇒ Object
-
.ATTRIBUTES_OP(expr) ⇒ Object
-
.block(*args) ⇒ Object
-
.block_or_expression(args, left_brace = nil, right_brace = nil) ⇒ Object
Builds a BlockExpression if args size > 1, else the single expression/value in args.
-
.CALL_METHOD(functor, argument_list) ⇒ Object
-
.CALL_NAMED(name, rval_required, argument_list) ⇒ Object
-
.call_named(name, rval_required, *argument_list) ⇒ Object
Same as CALL_NAMED but with inference and varargs (for testing purposes).
-
.CASE(test_e, *options) ⇒ Object
-
.COLLECT(type_expr, query_expr, attribute_operations) ⇒ Object
-
.concat(*args) ⇒ Object
-
.DEFINITION(name, parameters, body) ⇒ Object
-
.EPP(parameters, body) ⇒ Object
-
.EXPORTED_QUERY(query_expr) ⇒ Object
-
.fqn(o) ⇒ Object
Creates a QualifiedName representation of o, unless o already represents a QualifiedName in which case it is returned.
-
.fqr(o) ⇒ Object
Creates a QualifiedName representation of o, unless o already represents a QualifiedName in which case it is returned.
-
.FUNCTION(name, parameters, body, return_type) ⇒ Object
-
.HASH(entries) ⇒ Object
-
.HASH_UNFOLDED(entries) ⇒ Object
-
.HEREDOC(name, expr) ⇒ Object
-
.HOSTCLASS(name, parameters, parent, body) ⇒ Object
-
.IF(test_e, then_e, else_e) ⇒ Object
-
.infer(o) ⇒ Object
-
.KEY_ENTRY(key, val) ⇒ Object
-
.LAMBDA(parameters, body, return_type) ⇒ Object
-
.LIST(entries) ⇒ Object
-
.literal(o) ⇒ Object
-
.MAP(match, value) ⇒ Object
-
.minus(o) ⇒ Object
-
.name_is_statement?(name) ⇒ Boolean
Returns true if the given name is a “statement keyword” (require, include, contain, error, notice, info, debug.
-
.NAMED_ACCESS(type_name, bodies) ⇒ Object
-
.NODE(hosts, parent, body) ⇒ Object
-
.nop?(o) ⇒ Boolean
-
.NUMBER(name_or_numeric) ⇒ Object
-
.PARAM(name, expr = nil) ⇒ Object
-
.PLAN(name, parameters, body) ⇒ Object
-
.PROGRAM(body, definitions, locator) ⇒ Object
-
.QNAME(name) ⇒ Object
TODO: This is the same a fqn factory method, don’t know if callers to fqn and QNAME can live with the same result or not yet - refactor into one method when decided.
-
.QNAME_OR_NUMBER(name) ⇒ Object
Convert input string to either a qualified name, a LiteralInteger with radix, or a LiteralFloat.
-
.QREF(name) ⇒ Object
-
.RENDER_EXPR(expr) ⇒ Object
-
.RENDER_STRING(o) ⇒ Object
-
.RESERVED(name, future = false) ⇒ Object
-
.RESOURCE(type_name, bodies) ⇒ Object
-
.RESOURCE_BODY(resource_title, attribute_operations) ⇒ Object
-
.RESOURCE_DEFAULTS(type_name, attribute_operations) ⇒ Object
-
.RESOURCE_OVERRIDE(resource_ref, attribute_operations) ⇒ Object
-
.resource_shape(expr) ⇒ Object
Returns symbolic information about an expected shape of a resource expression given the LHS of a resource expr.
-
.set_resource_form(expr, form) ⇒ Object
Sets the form of the resource expression (:regular (the default), :virtual, or :exported).
-
.string(*args) ⇒ Object
-
.STRING(*args) ⇒ Object
-
.SUBLOCATE(token, expr_factory) ⇒ Object
-
.TEXT(expr) ⇒ Object
-
.text(o) ⇒ Object
-
.transform_calls(expressions) ⇒ Object
Transforms an array of expressions containing literal name expressions to calls if followed by an expression, or expression list.
-
.transform_resource_wo_title(left, attribute_ops, lbrace_token, rbrace_token) ⇒ Object
Transforms a left expression followed by an untitled resource (in the form of attribute_operations).
-
.TYPE_ASSIGNMENT(lhs, rhs) ⇒ Object
-
.TYPE_DEFINITION(name, parent, body) ⇒ Object
-
.unfold(o) ⇒ Object
-
.UNLESS(test_e, then_e, else_e) ⇒ Object
-
.var(o) ⇒ Object
-
.VIRTUAL_QUERY(query_expr) ⇒ Object
-
.WHEN(values_list, block) ⇒ Object
Instance Method Summary
collapse
-
#%(r) ⇒ Object
-
#*(r) ⇒ Object
-
#+(r) ⇒ Object
-
#-(r) ⇒ Object
-
#/(r) ⇒ Object
-
#<(r) ⇒ Object
-
#<<(r) ⇒ Object
-
#<=(r) ⇒ Object
-
#=~(r) ⇒ Object
-
#>(r) ⇒ Object
-
#>=(r) ⇒ Object
-
#>>(r) ⇒ Object
-
#[](key) ⇒ Object
-
#[]=(key, value) ⇒ Object
-
#access(r) ⇒ Object
-
#access_at(*r) ⇒ Object
Same as access, but with varargs and arguments that must be inferred.
-
#all_factories(&block) ⇒ Object
-
#and(r) ⇒ Object
-
#attributes(*args) ⇒ Object
-
#build_AccessExpression(o, left, keys) ⇒ Object
-
#build_ApplyExpression(o, args, body) ⇒ Object
-
#build_ArithmeticExpression(o, op, a, b) ⇒ Object
Building of Model classes.
-
#build_AssignmentExpression(o, op, a, b) ⇒ Object
-
#build_AttributeOperation(o, name, op, value) ⇒ Object
-
#build_AttributesOperation(o, value) ⇒ Object
-
#build_BinaryExpression(o, left, right) ⇒ Object
-
#build_BlockExpression(o, args) ⇒ Object
-
#build_CallExpression(o, functor, rval_required, args) ⇒ Object
-
#build_CallMethodExpression(o, functor, rval_required, lambda, args) ⇒ Object
-
#build_CaseExpression(o, test, args) ⇒ Object
-
#build_CaseOption(o, value_list, then_expr) ⇒ Object
-
#build_CollectExpression(o, type_expr, query_expr, attribute_operations) ⇒ Object
-
#build_ComparisonExpression(o, op, a, b) ⇒ Object
-
#build_ConcatenatedString(o, args) ⇒ Object
-
#build_EppExpression(o, parameters_specified, body) ⇒ Object
-
#build_FunctionDefinition(o, name, parameters, body, return_type) ⇒ Object
-
#build_HeredocExpression(o, name, expr) ⇒ Object
-
#build_HostClassDefinition(o, name, parameters, parent_class_name, body) ⇒ HostClassDefinition
Configured from the parameters.
-
#build_IfExpression(o, t, ift, els) ⇒ Object
-
#build_KeyedEntry(o, k, v) ⇒ Object
-
#build_LambdaExpression(o, parameters, body, return_type) ⇒ Object
-
#build_LiteralFloat(o, val) ⇒ Object
-
#build_LiteralHash(o, keyed_entries, unfolded) ⇒ Object
-
#build_LiteralInteger(o, val, radix) ⇒ Object
-
#build_LiteralList(o, values) ⇒ Object
-
#build_LiteralString(o, value) ⇒ Object
-
#build_MatchExpression(o, op, a, b) ⇒ Object
-
#build_NamedDefinition(o, name, parameters, body) ⇒ Object
-
#build_NodeDefinition(o, hosts, parent, body) ⇒ Object
-
#build_Parameter(o, name, expr) ⇒ Object
-
#build_PlanDefinition(o, name, parameters, body, return_type = nil) ⇒ Object
-
#build_Program(o, body, definitions, locator) ⇒ Object
-
#build_QualifiedName(o, name) ⇒ Object
-
#build_QualifiedReference(o, name) ⇒ Object
-
#build_QueryExpression(o, expr) ⇒ Object
-
#build_RelationshipExpression(o, op, a, b) ⇒ Object
-
#build_RenderStringExpression(o, string) ⇒ Object
-
#build_ReservedWord(o, name, future) ⇒ Object
-
#build_ResourceBody(o, title_expression, attribute_operations) ⇒ Object
-
#build_ResourceDefaultsExpression(o, type_ref, attribute_operations) ⇒ Object
-
#build_ResourceExpression(o, type_name, bodies) ⇒ Object
-
#build_ResourceOverrideExpression(o, resources, attribute_operations) ⇒ Object
-
#build_SelectorEntry(o, matching, value) ⇒ Object
-
#build_SelectorExpression(o, left, *selectors) ⇒ Object
-
#build_TokenValue(o) ⇒ Object
-
#build_TypeAlias(o, name, type_expr) ⇒ Object
-
#build_TypeDefinition(o, name, parent, body) ⇒ Object
-
#build_TypeMapping(o, lhs, rhs) ⇒ Object
-
#build_UnaryExpression(o, expr) ⇒ Object
-
#captures_rest ⇒ Object
Mark parameter as capturing the rest of arguments.
-
#contained_current(container) ⇒ Object
-
#create_model ⇒ Object
-
#default(r) ⇒ Object
For CaseExpression, setting the default for an already build CaseExpression.
-
#dot(r) ⇒ Object
-
#eq(r) ⇒ Object
-
#f_arithmetic(op, r) ⇒ Object
-
#f_build_binary(klazz, left, right) ⇒ Object
-
#f_build_binary_op(klazz, op, left, right) ⇒ Object
-
#f_build_body(body) ⇒ Object
-
#f_build_unary(klazz, expr) ⇒ Object
-
#f_comparison(op, r) ⇒ Object
-
#f_match(op, r) ⇒ Object
-
#factory_to_model(value) ⇒ Object
-
#in(r) ⇒ Object
-
#infer_Array(o) ⇒ Object
Creates a LiteralList instruction from an Array, where the entries are built.
-
#infer_FalseClass(o) ⇒ Object
-
#infer_Float(o) ⇒ Object
-
#infer_Hash(o) ⇒ Object
Create a LiteralHash instruction from a hash, where keys and values are built The hash entries are added in sorted order based on key.to_s.
-
#infer_Integer(o) ⇒ Object
-
#infer_NilClass(o) ⇒ Object
-
#infer_Regexp(o) ⇒ Object
-
#infer_String(o) ⇒ Object
Building model equivalences of Ruby objects Allows passing regular ruby objects to the factory to produce instructions that when evaluated produce the same thing.
-
#infer_Symbol(o) ⇒ Object
Creates a String literal, unless the symbol is one of the special :undef, or :default which instead creates a LiterlUndef, or a LiteralDefault.
-
#infer_TrueClass(o) ⇒ Object
-
#initialize(o, *args) ⇒ Factory
constructor
Initialize a factory with a single object, or a class with arguments applied to build of created instance.
-
#interpolate ⇒ Object
-
#interpolate_AccessExpression(c) ⇒ Object
rewrite left expression to variable if it is name, number, and recurse if it is an access expression this is for interpolation support in new lexer ($NAME, $NAME[}, $Factory.NUMBER, $NUMBER[] - all other expressions requires variables to be preceded with $.
-
#interpolate_CallMethodExpression(c) ⇒ Object
Rewrite method calls on the form $… to $$x$x.each.
-
#interpolate_Factory(c) ⇒ Object
-
#interpolate_LiteralInteger(c) ⇒ Object
-
#interpolate_NamedAccessExpression(c) ⇒ Object
-
#interpolate_Object(c) ⇒ Object
-
#interpolate_QualifiedName(c) ⇒ Object
-
#is_interop_rewriteable?(o) ⇒ Boolean
-
#lambda=(lambda) ⇒ Object
-
#length ⇒ Object
-
#map_offset(model, locator) ⇒ Object
-
#map_offset_Factory(o, locator) ⇒ Object
-
#map_offset_Object(o, locator) ⇒ Object
-
#map_offset_Positioned(o, locator) ⇒ Object
-
#minus ⇒ Object
-
#minus_set(r) ⇒ Object
-
#mne(r) ⇒ Object
-
#model ⇒ Object
(also: #current)
-
#ne(r) ⇒ Object
-
#not ⇒ Object
-
#offset ⇒ Object
-
#or(r) ⇒ Object
-
#paren ⇒ Object
-
#plus_set(r) ⇒ Object
-
#record_position(locator, start_locatable, end_locatable) ⇒ Object
Records the position (start -> end) and computes the resulting length.
-
#relop(op, r) ⇒ Object
-
#select(*args) ⇒ Object
-
#set(r) ⇒ Object
-
#text ⇒ Object
-
#to_s ⇒ Object
-
#type_expr(o) ⇒ Object
Set Expression that should evaluate to the parameter’s type.
-
#unfold ⇒ Object
-
#var ⇒ Object
Constructor Details
#initialize(o, *args) ⇒ Factory
Initialize a factory with a single object, or a class with arguments applied to build of created instance
84
85
86
87
88
89
90
91
92
|
# File 'lib/puppet/pops/model/factory.rb', line 84
def initialize(o, *args)
@init_hash = {}
if o.instance_of?(Class)
@model_class = o
BUILD_VISITOR.visit_this_class(self, o, args)
else
INFER_VISITOR.visit_this(self, o, EMPTY_ARRAY)
end
end
|
Instance Attribute Details
#model_class ⇒ Object
42
43
44
|
# File 'lib/puppet/pops/model/factory.rb', line 42
def model_class
@model_class
end
|
42
43
44
|
# File 'lib/puppet/pops/model/factory.rb', line 42
def unfolded
@unfolded
end
|
Class Method Details
.APPLY(arguments, body) ⇒ Object
937
938
939
|
# File 'lib/puppet/pops/model/factory.rb', line 937
def self.APPLY(arguments, body)
new(ApplyExpression, arguments, body)
end
|
.APPLY_BLOCK(statements) ⇒ Object
941
942
943
|
# File 'lib/puppet/pops/model/factory.rb', line 941
def self.APPLY_BLOCK(statements)
new(ApplyBlockExpression, statements)
end
|
.ARGUMENTS(args, arg) ⇒ Object
846
847
848
849
850
851
852
853
854
855
|
# File 'lib/puppet/pops/model/factory.rb', line 846
def self.ARGUMENTS(args, arg)
if !args.empty? && arg.model_class <= LiteralHash && arg.unfolded
last = args[args.size() - 1]
if last.model_class <= LiteralHash && last.unfolded
last['entries'].concat(arg['entries'])
return args
end
end
args.push(arg)
end
|
.ATTRIBUTE_OP(name, op, expr) ⇒ Object
857
858
859
|
# File 'lib/puppet/pops/model/factory.rb', line 857
def self.ATTRIBUTE_OP(name, op, expr)
new(AttributeOperation, name, op, expr)
end
|
.ATTRIBUTES_OP(expr) ⇒ Object
861
862
863
|
# File 'lib/puppet/pops/model/factory.rb', line 861
def self.ATTRIBUTES_OP(expr)
new(AttributesOperation, expr)
end
|
.block(*args) ⇒ Object
695
|
# File 'lib/puppet/pops/model/factory.rb', line 695
def self.block(*args); new(BlockExpression, args.map { |arg| infer(arg) }); end
|
.block_or_expression(args, left_brace = nil, right_brace = nil) ⇒ Object
Builds a BlockExpression if args size > 1, else the single expression/value in args
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
|
# File 'lib/puppet/pops/model/factory.rb', line 907
def self.block_or_expression(args, left_brace = nil, right_brace = nil)
if args.size > 1
block_expr = new(BlockExpression, args)
if !left_brace.nil? && !right_brace.nil?
block_expr.record_position(args.first[KEY_LOCATOR], left_brace, right_brace)
else
block_expr.record_position(args.first[KEY_LOCATOR], args.first, args.last)
end
block_expr
else
args[0]
end
end
|
.CALL_METHOD(functor, argument_list) ⇒ Object
874
875
876
|
# File 'lib/puppet/pops/model/factory.rb', line 874
def self.CALL_METHOD(functor, argument_list)
new(CallMethodExpression, functor, true, nil, argument_list)
end
|
.CALL_NAMED(name, rval_required, argument_list) ⇒ Object
870
871
872
|
# File 'lib/puppet/pops/model/factory.rb', line 870
def self.CALL_NAMED(name, rval_required, argument_list)
new(CallNamedFunctionExpression, name, rval_required, argument_list)
end
|
.call_named(name, rval_required, *argument_list) ⇒ Object
Same as CALL_NAMED but with inference and varargs (for testing purposes)
866
867
868
|
# File 'lib/puppet/pops/model/factory.rb', line 866
def self.call_named(name, rval_required, *argument_list)
new(CallNamedFunctionExpression, fqn(name), rval_required, argument_list.map { |arg| infer(arg) })
end
|
.CASE(test_e, *options) ⇒ Object
705
|
# File 'lib/puppet/pops/model/factory.rb', line 705
def self.CASE(test_e,*options); new(CaseExpression, test_e, options); end
|
.COLLECT(type_expr, query_expr, attribute_operations) ⇒ Object
878
879
880
|
# File 'lib/puppet/pops/model/factory.rb', line 878
def self.COLLECT(type_expr, query_expr, attribute_operations)
new(CollectExpression, type_expr, query_expr, attribute_operations)
end
|
.concat(*args) ⇒ Object
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
|
# File 'lib/puppet/pops/model/factory.rb', line 1114
def self.concat(*args)
result = ''.dup
args.each do |e|
if e.instance_of?(Factory) && e.model_class <= LiteralString
result << e[KEY_VALUE]
elsif e.is_a?(String)
result << e
else
raise ArgumentError, _("can only concatenate strings, got %{class_name}") % { class_name: e.class }
end
end
infer(result)
end
|
.DEFINITION(name, parameters, body) ⇒ Object
929
930
931
|
# File 'lib/puppet/pops/model/factory.rb', line 929
def self.DEFINITION(name, parameters, body)
new(ResourceTypeDefinition, name, parameters, body)
end
|
.EPP(parameters, body) ⇒ Object
779
780
781
782
783
784
785
786
787
788
|
# File 'lib/puppet/pops/model/factory.rb', line 779
def self.EPP(parameters, body)
if parameters.nil?
params = []
parameters_specified = false
else
params = parameters
parameters_specified = true
end
LAMBDA(params, new(EppExpression, parameters_specified, body), nil)
end
|
.EXPORTED_QUERY(query_expr) ⇒ Object
842
843
844
|
# File 'lib/puppet/pops/model/factory.rb', line 842
def self.EXPORTED_QUERY(query_expr)
new(ExportedQuery, query_expr)
end
|
Creates a QualifiedName representation of o, unless o already represents a QualifiedName in which case it is returned.
742
743
744
|
# File 'lib/puppet/pops/model/factory.rb', line 742
def self.fqn(o)
o.instance_of?(Factory) && o.model_class <= QualifiedName ? self : new(QualifiedName, o)
end
|
Creates a QualifiedName representation of o, unless o already represents a QualifiedName in which case it is returned.
.FUNCTION(name, parameters, body, return_type) ⇒ Object
945
946
947
|
# File 'lib/puppet/pops/model/factory.rb', line 945
def self.FUNCTION(name, parameters, body, return_type)
new(FunctionDefinition, name, parameters, body, return_type)
end
|
.HASH(entries) ⇒ Object
713
|
# File 'lib/puppet/pops/model/factory.rb', line 713
def self.HASH(entries); new(LiteralHash, entries, false); end
|
.HASH_UNFOLDED(entries) ⇒ Object
715
|
# File 'lib/puppet/pops/model/factory.rb', line 715
def self.HASH_UNFOLDED(entries); new(LiteralHash, entries, true); end
|
.HEREDOC(name, expr) ⇒ Object
717
|
# File 'lib/puppet/pops/model/factory.rb', line 717
def self.HEREDOC(name, expr); new(HeredocExpression, name, expr); end
|
.HOSTCLASS(name, parameters, parent, body) ⇒ Object
925
926
927
|
# File 'lib/puppet/pops/model/factory.rb', line 925
def self.HOSTCLASS(name, parameters, parent, body)
new(HostClassDefinition, name, parameters, parent, body)
end
|
.IF(test_e, then_e, else_e) ⇒ Object
701
|
# File 'lib/puppet/pops/model/factory.rb', line 701
def self.IF(test_e,then_e,else_e); new(IfExpression, test_e, then_e, else_e); end
|
34
35
36
37
38
39
40
|
# File 'lib/puppet/pops/model/factory.rb', line 34
def self.infer(o)
if o.instance_of?(Factory)
o
else
new(o)
end
end
|
.KEY_ENTRY(key, val) ⇒ Object
711
|
# File 'lib/puppet/pops/model/factory.rb', line 711
def self.KEY_ENTRY(key, val); new(KeyedEntry, key, val); end
|
.LAMBDA(parameters, body, return_type) ⇒ Object
949
950
951
|
# File 'lib/puppet/pops/model/factory.rb', line 949
def self.LAMBDA(parameters, body, return_type)
new(LambdaExpression, parameters, body, return_type)
end
|
.LIST(entries) ⇒ Object
721
|
# File 'lib/puppet/pops/model/factory.rb', line 721
def self.LIST(entries); new(LiteralList, entries); end
|
.literal(o) ⇒ Object
687
|
# File 'lib/puppet/pops/model/factory.rb', line 687
def self.literal(o); infer(o); end
|
.MAP(match, value) ⇒ Object
709
|
# File 'lib/puppet/pops/model/factory.rb', line 709
def self.MAP(match, value); new(SelectorEntry, match, value); end
|
689
|
# File 'lib/puppet/pops/model/factory.rb', line 689
def self.minus(o); infer(o).minus; end
|
.name_is_statement?(name) ⇒ Boolean
Returns true if the given name is a “statement keyword” (require, include, contain, error, notice, info, debug
992
993
994
|
# File 'lib/puppet/pops/model/factory.rb', line 992
def self.name_is_statement?(name)
STATEMENT_CALLS.include?(name)
end
|
.NAMED_ACCESS(type_name, bodies) ⇒ Object
882
883
884
|
# File 'lib/puppet/pops/model/factory.rb', line 882
def self.NAMED_ACCESS(type_name, bodies)
new(NamedAccessExpression, type_name, bodies)
end
|
.NODE(hosts, parent, body) ⇒ Object
725
|
# File 'lib/puppet/pops/model/factory.rb', line 725
def self.NODE(hosts, parent, body); new(NodeDefinition, hosts, parent, body); end
|
.nop?(o) ⇒ Boolean
965
966
967
|
# File 'lib/puppet/pops/model/factory.rb', line 965
def self.nop? o
o.nil? || o.instance_of?(Factory) && o.model_class <= Nop
end
|
.NUMBER(name_or_numeric) ⇒ Object
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
|
# File 'lib/puppet/pops/model/factory.rb', line 801
def self.NUMBER(name_or_numeric)
n_radix = Utils.to_n_with_radix(name_or_numeric)
if n_radix
val, radix = n_radix
if val.is_a?(Float)
new(LiteralFloat, val)
else
new(LiteralInteger, val, radix)
end
else
raise ArgumentError, _("Internal Error, NUMBER token does not contain a valid number, %{name_or_numeric}") %
{ name_or_numeric: name_or_numeric }
end
end
|
.PARAM(name, expr = nil) ⇒ Object
723
|
# File 'lib/puppet/pops/model/factory.rb', line 723
def self.PARAM(name, expr=nil); new(Parameter, name, expr); end
|
.PLAN(name, parameters, body) ⇒ Object
933
934
935
|
# File 'lib/puppet/pops/model/factory.rb', line 933
def self.PLAN(name, parameters, body)
new(PlanDefinition, name, parameters, body, nil)
end
|
.PROGRAM(body, definitions, locator) ⇒ Object
902
903
904
|
# File 'lib/puppet/pops/model/factory.rb', line 902
def self.PROGRAM(body, definitions, locator)
new(Program, body, definitions, locator)
end
|
.QNAME(name) ⇒ Object
TODO: This is the same a fqn factory method, don’t know if callers to fqn and QNAME can live with the same result or not yet - refactor into one method when decided.
797
798
799
|
# File 'lib/puppet/pops/model/factory.rb', line 797
def self.QNAME(name)
new(QualifiedName, name)
end
|
.QNAME_OR_NUMBER(name) ⇒ Object
Convert input string to either a qualified name, a LiteralInteger with radix, or a LiteralFloat
820
821
822
823
824
825
826
827
828
829
830
831
832
|
# File 'lib/puppet/pops/model/factory.rb', line 820
def self.QNAME_OR_NUMBER(name)
n_radix = Utils.to_n_with_radix(name)
if n_radix
val, radix = n_radix
if val.is_a?(Float)
new(LiteralFloat, val)
else
new(LiteralInteger, val, radix)
end
else
new(QualifiedName, name)
end
end
|
.QREF(name) ⇒ Object
834
835
836
|
# File 'lib/puppet/pops/model/factory.rb', line 834
def self.QREF(name)
new(QualifiedReference, name)
end
|
.RENDER_EXPR(expr) ⇒ Object
775
776
777
|
# File 'lib/puppet/pops/model/factory.rb', line 775
def self.RENDER_EXPR(expr)
new(RenderExpression, expr)
end
|
.RENDER_STRING(o) ⇒ Object
771
772
773
|
# File 'lib/puppet/pops/model/factory.rb', line 771
def self.RENDER_STRING(o)
new(RenderStringExpression, o)
end
|
.RESERVED(name, future = false) ⇒ Object
790
791
792
|
# File 'lib/puppet/pops/model/factory.rb', line 790
def self.RESERVED(name, future=false)
new(ReservedWord, name, future)
end
|
.RESOURCE(type_name, bodies) ⇒ Object
886
887
888
|
# File 'lib/puppet/pops/model/factory.rb', line 886
def self.RESOURCE(type_name, bodies)
new(ResourceExpression, type_name, bodies)
end
|
.RESOURCE_BODY(resource_title, attribute_operations) ⇒ Object
898
899
900
|
# File 'lib/puppet/pops/model/factory.rb', line 898
def self.RESOURCE_BODY(resource_title, attribute_operations)
new(ResourceBody, resource_title, attribute_operations)
end
|
.RESOURCE_DEFAULTS(type_name, attribute_operations) ⇒ Object
890
891
892
|
# File 'lib/puppet/pops/model/factory.rb', line 890
def self.RESOURCE_DEFAULTS(type_name, attribute_operations)
new(ResourceDefaultsExpression, type_name, attribute_operations)
end
|
.RESOURCE_OVERRIDE(resource_ref, attribute_operations) ⇒ Object
894
895
896
|
# File 'lib/puppet/pops/model/factory.rb', line 894
def self.RESOURCE_OVERRIDE(resource_ref, attribute_operations)
new(ResourceOverrideExpression, resource_ref, attribute_operations)
end
|
.resource_shape(expr) ⇒ Object
Returns symbolic information about an expected shape of a resource expression given the LHS of a resource expr.
-
‘name { }` => `:resource`, create a resource of the given type
-
‘Name { }` => ’:defaults`, set defaults for the referenced type
-
‘Name[] { }` => `:override`, overrides instances referenced by LHS
-
_any other_ => ‘:error’, all other are considered illegal
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
|
# File 'lib/puppet/pops/model/factory.rb', line 660
def self.resource_shape(expr)
if expr == 'class'
:class
elsif expr.instance_of?(self)
mc = expr.model_class
if mc <= QualifiedName
:resource
elsif mc <= QualifiedReference
:defaults
elsif mc <= AccessExpression
lhs = expr[KEY_LEFT_EXPR]
if lhs.model_class <= QualifiedReference && lhs[KEY_VALUE] == 'resource' && expr[KEY_KEYS].size == 1
:defaults
else
:override
end
else
:error
end
else
:error
end
end
|
Sets the form of the resource expression (:regular (the default), :virtual, or :exported). Produces true if the expression was a resource expression, false otherwise.
646
647
648
649
650
651
|
# File 'lib/puppet/pops/model/factory.rb', line 646
def self.set_resource_form(expr, form)
return false unless expr.instance_of?(self) && expr.model_class <= AbstractResource
expr['form'] = form
return true
end
|
.string(*args) ⇒ Object
697
|
# File 'lib/puppet/pops/model/factory.rb', line 697
def self.string(*args); new(ConcatenatedString, args.map { |arg| infer(arg) }); end
|
.STRING(*args) ⇒ Object
719
|
# File 'lib/puppet/pops/model/factory.rb', line 719
def self.STRING(*args); new(ConcatenatedString, args); end
|
.SUBLOCATE(token, expr_factory) ⇒ Object
753
754
755
756
757
758
759
760
761
762
763
764
|
# File 'lib/puppet/pops/model/factory.rb', line 753
def self.SUBLOCATE(token, expr_factory)
model = expr_factory.model
locator = token.locator
expr_factory.map_offset(model, locator)
model._pcore_all_contents([]) { |element| expr_factory.map_offset(element, locator) }
expr_factory
end
|
.TEXT(expr) ⇒ Object
766
767
768
|
# File 'lib/puppet/pops/model/factory.rb', line 766
def self.TEXT(expr)
new(TextExpression, infer(expr).interpolate)
end
|
699
|
# File 'lib/puppet/pops/model/factory.rb', line 699
def self.text(o); infer(o).text; end
|
Transforms an array of expressions containing literal name expressions to calls if followed by an expression, or expression list.
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
|
# File 'lib/puppet/pops/model/factory.rb', line 1007
def self.transform_calls(expressions)
expressions.reduce([]) do |memo, expr|
name = memo[-1]
if name.instance_of?(Factory) && name.model_class <= QualifiedName && name_is_statement?(name[KEY_VALUE])
if expr.is_a?(Array)
expr = expr.reject { |e| e.is_a?(Parser::LexerSupport::TokenValue) }
else
expr = [expr]
end
the_call = self.CALL_NAMED(name, false, expr)
the_call.record_position(name[KEY_LOCATOR], name, expr[-1])
memo[-1] = the_call
if expr.is_a?(CallNamedFunctionExpression)
expr.rval_required = true
end
elsif expr.is_a?(Array)
raise ArgsToNonCallError.new(expr, name)
else
memo << expr
if expr.model_class <= CallNamedFunctionExpression
expr['rval_required'] = false
end
end
memo
end
end
|
Transforms a left expression followed by an untitled resource (in the form of attribute_operations)
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
|
# File 'lib/puppet/pops/model/factory.rb', line 1042
def self.transform_resource_wo_title(left, attribute_ops, lbrace_token, rbrace_token)
return nil unless attribute_ops.is_a? Array
return nil unless left.model_class <= QualifiedName
keyed_entries = attribute_ops.map do |ao|
return nil if ao[KEY_OPERATOR] == '+>'
KEY_ENTRY(infer(ao['attribute_name']), ao['value_expr'])
end
a_hash = HASH(keyed_entries)
a_hash.record_position(left[KEY_LOCATOR], lbrace_token, rbrace_token)
result = block_or_expression(transform_calls([left, a_hash]))
result
end
|
.TYPE_ASSIGNMENT(lhs, rhs) ⇒ Object
953
954
955
956
957
958
959
|
# File 'lib/puppet/pops/model/factory.rb', line 953
def self.TYPE_ASSIGNMENT(lhs, rhs)
if lhs.model_class <= AccessExpression
new(TypeMapping, lhs, rhs)
else
new(TypeAlias, lhs['cased_value'], rhs)
end
end
|
.TYPE_DEFINITION(name, parent, body) ⇒ Object
961
962
963
|
# File 'lib/puppet/pops/model/factory.rb', line 961
def self.TYPE_DEFINITION(name, parent, body)
new(TypeDefinition, name, parent, body)
end
|
.unfold(o) ⇒ Object
691
|
# File 'lib/puppet/pops/model/factory.rb', line 691
def self.unfold(o); infer(o).unfold; end
|
.UNLESS(test_e, then_e, else_e) ⇒ Object
703
|
# File 'lib/puppet/pops/model/factory.rb', line 703
def self.UNLESS(test_e,then_e,else_e); new(UnlessExpression, test_e, then_e, else_e); end
|
693
|
# File 'lib/puppet/pops/model/factory.rb', line 693
def self.var(o); infer(o).var; end
|
.VIRTUAL_QUERY(query_expr) ⇒ Object
838
839
840
|
# File 'lib/puppet/pops/model/factory.rb', line 838
def self.VIRTUAL_QUERY(query_expr)
new(VirtualQuery, query_expr)
end
|
.WHEN(values_list, block) ⇒ Object
707
|
# File 'lib/puppet/pops/model/factory.rb', line 707
def self.WHEN(values_list, block); new(CaseOption, values_list, block); end
|
Instance Method Details
556
|
# File 'lib/puppet/pops/model/factory.rb', line 556
def % r; f_arithmetic('%', r); end
|
554
|
# File 'lib/puppet/pops/model/factory.rb', line 554
def * r; f_arithmetic('*', r); end
|
548
|
# File 'lib/puppet/pops/model/factory.rb', line 548
def + r; f_arithmetic('+', r); end
|
550
|
# File 'lib/puppet/pops/model/factory.rb', line 550
def - r; f_arithmetic('-', r); end
|
552
|
# File 'lib/puppet/pops/model/factory.rb', line 552
def / r; f_arithmetic('/', r); end
|
562
|
# File 'lib/puppet/pops/model/factory.rb', line 562
def < r; f_comparison('<', r); end
|
558
|
# File 'lib/puppet/pops/model/factory.rb', line 558
def << r; f_arithmetic('<<', r); end
|
564
|
# File 'lib/puppet/pops/model/factory.rb', line 564
def <= r; f_comparison('<=', r); end
|
574
|
# File 'lib/puppet/pops/model/factory.rb', line 574
def =~ r; f_match('=~', r); end
|
566
|
# File 'lib/puppet/pops/model/factory.rb', line 566
def > r; f_comparison('>', r); end
|
568
|
# File 'lib/puppet/pops/model/factory.rb', line 568
def >= r; f_comparison('>=', r); end
|
560
|
# File 'lib/puppet/pops/model/factory.rb', line 560
def >> r; f_arithmetic('>>', r); end
|
44
45
46
|
# File 'lib/puppet/pops/model/factory.rb', line 44
def [](key)
@init_hash[key]
end
|
#[]=(key, value) ⇒ Object
48
49
50
|
# File 'lib/puppet/pops/model/factory.rb', line 48
def []=(key, value)
@init_hash[key] = value
end
|
#access(r) ⇒ Object
544
|
# File 'lib/puppet/pops/model/factory.rb', line 544
def access(r); f_build_binary(AccessExpression, self, r); end
|
#access_at(*r) ⇒ Object
Same as access, but with varargs and arguments that must be inferred. For testing purposes
589
590
591
|
# File 'lib/puppet/pops/model/factory.rb', line 589
def access_at(*r)
f_build_binary(AccessExpression, self, r.map { |arg| Factory.infer(arg) })
end
|
#all_factories(&block) ⇒ Object
52
53
54
55
|
# File 'lib/puppet/pops/model/factory.rb', line 52
def all_factories(&block)
block.call(self)
@init_hash.each_value { |value| value.all_factories(&block) if value.instance_of?(Factory) }
end
|
532
|
# File 'lib/puppet/pops/model/factory.rb', line 532
def and(r) f_build_binary(AndExpression, self, r); end
|
#attributes(*args) ⇒ Object
619
620
621
622
|
# File 'lib/puppet/pops/model/factory.rb', line 619
def attributes(*args)
@init_hash['attributes'] = args
self
end
|
#build_AccessExpression(o, left, keys) ⇒ Object
144
145
146
147
|
# File 'lib/puppet/pops/model/factory.rb', line 144
def build_AccessExpression(o, left, keys)
@init_hash[KEY_LEFT_EXPR] = left
@init_hash[KEY_KEYS] = keys
end
|
#build_ApplyExpression(o, args, body) ⇒ Object
263
264
265
266
|
# File 'lib/puppet/pops/model/factory.rb', line 263
def build_ApplyExpression(o, args, body)
@init_hash['arguments'] = args
@init_hash['body'] = body
end
|
#build_ArithmeticExpression(o, op, a, b) ⇒ Object
Building of Model classes
124
125
126
127
|
# File 'lib/puppet/pops/model/factory.rb', line 124
def build_ArithmeticExpression(o, op, a, b)
@init_hash[KEY_OPERATOR] = op
build_BinaryExpression(o, a, b)
end
|
#build_AssignmentExpression(o, op, a, b) ⇒ Object
129
130
131
132
|
# File 'lib/puppet/pops/model/factory.rb', line 129
def build_AssignmentExpression(o, op, a, b)
@init_hash[KEY_OPERATOR] = op
build_BinaryExpression(o, a, b)
end
|
#build_AttributeOperation(o, name, op, value) ⇒ Object
134
135
136
137
138
|
# File 'lib/puppet/pops/model/factory.rb', line 134
def build_AttributeOperation(o, name, op, value)
@init_hash[KEY_OPERATOR] = op
@init_hash['attribute_name'] = name.to_s @init_hash['value_expr'] = value
end
|
#build_AttributesOperation(o, value) ⇒ Object
140
141
142
|
# File 'lib/puppet/pops/model/factory.rb', line 140
def build_AttributesOperation(o, value)
@init_hash[KEY_EXPR] = value
end
|
#build_BinaryExpression(o, left, right) ⇒ Object
149
150
151
152
|
# File 'lib/puppet/pops/model/factory.rb', line 149
def build_BinaryExpression(o, left, right)
@init_hash[KEY_LEFT_EXPR] = left
@init_hash[KEY_RIGHT_EXPR] = right
end
|
#build_BlockExpression(o, args) ⇒ Object
154
155
156
|
# File 'lib/puppet/pops/model/factory.rb', line 154
def build_BlockExpression(o, args)
@init_hash['statements'] = args
end
|
#build_CallExpression(o, functor, rval_required, args) ⇒ Object
165
166
167
168
169
|
# File 'lib/puppet/pops/model/factory.rb', line 165
def build_CallExpression(o, functor, rval_required, args)
@init_hash['functor_expr'] = functor
@init_hash['rval_required'] = rval_required
@init_hash['arguments'] = args
end
|
#build_CallMethodExpression(o, functor, rval_required, lambda, args) ⇒ Object
171
172
173
174
|
# File 'lib/puppet/pops/model/factory.rb', line 171
def build_CallMethodExpression(o, functor, rval_required, lambda, args)
build_CallExpression(o, functor, rval_required, args)
@init_hash['lambda'] = lambda
end
|
#build_CaseExpression(o, test, args) ⇒ Object
176
177
178
179
|
# File 'lib/puppet/pops/model/factory.rb', line 176
def build_CaseExpression(o, test, args)
@init_hash['test'] = test
@init_hash['options'] = args
end
|
#build_CaseOption(o, value_list, then_expr) ⇒ Object
181
182
183
184
185
186
|
# File 'lib/puppet/pops/model/factory.rb', line 181
def build_CaseOption(o, value_list, then_expr)
value_list = [value_list] unless value_list.is_a?(Array)
@init_hash['values'] = value_list
b = f_build_body(then_expr)
@init_hash['then_expr'] = b unless b.nil?
end
|
#build_CollectExpression(o, type_expr, query_expr, attribute_operations) ⇒ Object
188
189
190
191
192
|
# File 'lib/puppet/pops/model/factory.rb', line 188
def build_CollectExpression(o, type_expr, query_expr, attribute_operations)
@init_hash['type_expr'] = type_expr
@init_hash['query'] = query_expr
@init_hash['operations'] = attribute_operations
end
|
#build_ComparisonExpression(o, op, a, b) ⇒ Object
194
195
196
197
|
# File 'lib/puppet/pops/model/factory.rb', line 194
def build_ComparisonExpression(o, op, a, b)
@init_hash[KEY_OPERATOR] = op
build_BinaryExpression(o, a, b)
end
|
#build_ConcatenatedString(o, args) ⇒ Object
199
200
201
202
|
# File 'lib/puppet/pops/model/factory.rb', line 199
def build_ConcatenatedString(o, args)
@init_hash['segments'] = args.reject { |arg| arg.model_class == LiteralString && arg['value'].empty? }
end
|
#build_EppExpression(o, parameters_specified, body) ⇒ Object
158
159
160
161
162
|
# File 'lib/puppet/pops/model/factory.rb', line 158
def build_EppExpression(o, parameters_specified, body)
@init_hash['parameters_specified'] = parameters_specified
b = f_build_body(body)
@init_hash[KEY_BODY] = b unless b.nil?
end
|
#build_FunctionDefinition(o, name, parameters, body, return_type) ⇒ Object
368
369
370
371
372
373
374
|
# File 'lib/puppet/pops/model/factory.rb', line 368
def build_FunctionDefinition(o, name, parameters, body, return_type)
@init_hash[KEY_PARAMETERS] = parameters
b = f_build_body(body)
@init_hash[KEY_BODY] = b unless b.nil?
@init_hash[KEY_NAME] = name
@init_hash['return_type'] = return_type unless return_type.nil?
end
|
#build_HeredocExpression(o, name, expr) ⇒ Object
204
205
206
207
|
# File 'lib/puppet/pops/model/factory.rb', line 204
def build_HeredocExpression(o, name, expr)
@init_hash['syntax'] = name
@init_hash['text_expr'] = expr
end
|
#build_HostClassDefinition(o, name, parameters, parent_class_name, body) ⇒ HostClassDefinition
Returns configured from the parameters.
215
216
217
218
|
# File 'lib/puppet/pops/model/factory.rb', line 215
def build_HostClassDefinition(o, name, parameters, parent_class_name, body)
build_NamedDefinition(o, name, parameters, body)
@init_hash['parent_class'] = parent_class_name unless parent_class_name.nil?
end
|
#build_IfExpression(o, t, ift, els) ⇒ Object
257
258
259
260
261
|
# File 'lib/puppet/pops/model/factory.rb', line 257
def build_IfExpression(o, t, ift, els)
@init_hash['test'] = t
@init_hash['then_expr'] = ift
@init_hash['else_expr'] = els
end
|
#build_KeyedEntry(o, k, v) ⇒ Object
230
231
232
233
|
# File 'lib/puppet/pops/model/factory.rb', line 230
def build_KeyedEntry(o, k, v)
@init_hash['key'] = k
@init_hash[KEY_VALUE] = v
end
|
#build_LambdaExpression(o, parameters, body, return_type) ⇒ Object
354
355
356
357
358
359
|
# File 'lib/puppet/pops/model/factory.rb', line 354
def build_LambdaExpression(o, parameters, body, return_type)
@init_hash[KEY_PARAMETERS] = parameters
b = f_build_body(body)
@init_hash[KEY_BODY] = b unless b.nil?
@init_hash['return_type'] = return_type unless return_type.nil?
end
|
#build_LiteralFloat(o, val) ⇒ Object
244
245
246
|
# File 'lib/puppet/pops/model/factory.rb', line 244
def build_LiteralFloat(o, val)
@init_hash[KEY_VALUE] = val
end
|
#build_LiteralHash(o, keyed_entries, unfolded) ⇒ Object
235
236
237
238
|
# File 'lib/puppet/pops/model/factory.rb', line 235
def build_LiteralHash(o, keyed_entries, unfolded)
@init_hash['entries'] = keyed_entries
@unfolded = unfolded
end
|
#build_LiteralInteger(o, val, radix) ⇒ Object
248
249
250
251
|
# File 'lib/puppet/pops/model/factory.rb', line 248
def build_LiteralInteger(o, val, radix)
@init_hash[KEY_VALUE] = val
@init_hash['radix'] = radix
end
|
#build_LiteralList(o, values) ⇒ Object
240
241
242
|
# File 'lib/puppet/pops/model/factory.rb', line 240
def build_LiteralList(o, values)
@init_hash['values'] = values
end
|
#build_LiteralString(o, value) ⇒ Object
253
254
255
|
# File 'lib/puppet/pops/model/factory.rb', line 253
def build_LiteralString(o, value)
@init_hash[KEY_VALUE] = val
end
|
#build_MatchExpression(o, op, a, b) ⇒ Object
268
269
270
271
|
# File 'lib/puppet/pops/model/factory.rb', line 268
def build_MatchExpression(o, op, a, b)
@init_hash[KEY_OPERATOR] = op
build_BinaryExpression(o, a, b)
end
|
#build_NamedDefinition(o, name, parameters, body) ⇒ Object
361
362
363
364
365
366
|
# File 'lib/puppet/pops/model/factory.rb', line 361
def build_NamedDefinition(o, name, parameters, body)
@init_hash[KEY_PARAMETERS] = parameters
b = f_build_body(body)
@init_hash[KEY_BODY] = b unless b.nil?
@init_hash[KEY_NAME] = name
end
|
#build_NodeDefinition(o, hosts, parent, body) ⇒ Object
384
385
386
387
388
389
|
# File 'lib/puppet/pops/model/factory.rb', line 384
def build_NodeDefinition(o, hosts, parent, body)
@init_hash['host_matches'] = hosts
@init_hash['parent'] = parent unless parent.nil? b = f_build_body(body)
@init_hash[KEY_BODY] = b unless b.nil?
end
|
#build_Parameter(o, name, expr) ⇒ Object
391
392
393
394
|
# File 'lib/puppet/pops/model/factory.rb', line 391
def build_Parameter(o, name, expr)
@init_hash[KEY_NAME] = name
@init_hash[KEY_VALUE] = expr
end
|
#build_PlanDefinition(o, name, parameters, body, return_type = nil) ⇒ Object
376
377
378
379
380
381
382
|
# File 'lib/puppet/pops/model/factory.rb', line 376
def build_PlanDefinition(o, name, parameters, body, return_type=nil)
@init_hash[KEY_PARAMETERS] = parameters
b = f_build_body(body)
@init_hash[KEY_BODY] = b unless b.nil?
@init_hash[KEY_NAME] = name
@init_hash['return_type'] = return_type unless return_type.nil?
end
|
#build_Program(o, body, definitions, locator) ⇒ Object
487
488
489
490
491
492
|
# File 'lib/puppet/pops/model/factory.rb', line 487
def build_Program(o, body, definitions, locator)
@init_hash[KEY_BODY] = body
@init_hash['definitions'] = definitions
@init_hash[KEY_LOCATOR] = locator
end
|
#build_QualifiedName(o, name) ⇒ Object
494
495
496
|
# File 'lib/puppet/pops/model/factory.rb', line 494
def build_QualifiedName(o, name)
@init_hash[KEY_VALUE] = name
end
|
#build_QualifiedReference(o, name) ⇒ Object
396
397
398
|
# File 'lib/puppet/pops/model/factory.rb', line 396
def build_QualifiedReference(o, name)
@init_hash['cased_value'] = name.to_s
end
|
#build_QueryExpression(o, expr) ⇒ Object
434
435
436
|
# File 'lib/puppet/pops/model/factory.rb', line 434
def build_QueryExpression(o, expr)
@init_hash[KEY_EXPR] = expr unless Factory.nop?(expr)
end
|
#build_RelationshipExpression(o, op, a, b) ⇒ Object
400
401
402
403
|
# File 'lib/puppet/pops/model/factory.rb', line 400
def build_RelationshipExpression(o, op, a, b)
@init_hash[KEY_OPERATOR] = op
build_BinaryExpression(o, a, b)
end
|
#build_RenderStringExpression(o, string) ⇒ Object
410
411
412
|
# File 'lib/puppet/pops/model/factory.rb', line 410
def build_RenderStringExpression(o, string)
@init_hash[KEY_VALUE] = string;
end
|
#build_ReservedWord(o, name, future) ⇒ Object
225
226
227
228
|
# File 'lib/puppet/pops/model/factory.rb', line 225
def build_ReservedWord(o, name, future)
@init_hash['word'] = name
@init_hash['future'] = future
end
|
#build_ResourceBody(o, title_expression, attribute_operations) ⇒ Object
414
415
416
417
|
# File 'lib/puppet/pops/model/factory.rb', line 414
def build_ResourceBody(o, title_expression, attribute_operations)
@init_hash['title'] = title_expression
@init_hash['operations'] = attribute_operations
end
|
#build_ResourceDefaultsExpression(o, type_ref, attribute_operations) ⇒ Object
419
420
421
422
|
# File 'lib/puppet/pops/model/factory.rb', line 419
def build_ResourceDefaultsExpression(o, type_ref, attribute_operations)
@init_hash['type_ref'] = type_ref
@init_hash['operations'] = attribute_operations
end
|
#build_ResourceExpression(o, type_name, bodies) ⇒ Object
405
406
407
408
|
# File 'lib/puppet/pops/model/factory.rb', line 405
def build_ResourceExpression(o, type_name, bodies)
@init_hash['type_name'] = type_name
@init_hash['bodies'] = bodies
end
|
#build_ResourceOverrideExpression(o, resources, attribute_operations) ⇒ Object
220
221
222
223
|
# File 'lib/puppet/pops/model/factory.rb', line 220
def build_ResourceOverrideExpression(o, resources, attribute_operations)
@init_hash['resources'] = resources
@init_hash['operations'] = attribute_operations
end
|
#build_SelectorEntry(o, matching, value) ⇒ Object
429
430
431
432
|
# File 'lib/puppet/pops/model/factory.rb', line 429
def build_SelectorEntry(o, matching, value)
@init_hash['matching_expr'] = matching
@init_hash['value_expr'] = value
end
|
#build_SelectorExpression(o, left, *selectors) ⇒ Object
424
425
426
427
|
# File 'lib/puppet/pops/model/factory.rb', line 424
def build_SelectorExpression(o, left, *selectors)
@init_hash[KEY_LEFT_EXPR] = left
@init_hash['selectors'] = selectors
end
|
#build_TokenValue(o) ⇒ Object
498
499
500
|
# File 'lib/puppet/pops/model/factory.rb', line 498
def build_TokenValue(o)
raise "Factory can not deal with a Lexer Token. Got token: #{o}. Probably caused by wrong index in grammar val[n]."
end
|
#build_TypeAlias(o, name, type_expr) ⇒ Object
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
|
# File 'lib/puppet/pops/model/factory.rb', line 438
def build_TypeAlias(o, name, type_expr)
if type_expr.model_class <= KeyedEntry
parent = type_expr['key']
hash = type_expr['value']
pn = parent['cased_value']
unless pn == 'Object' || pn == 'TypeSet'
hash['entries'] << Factory.KEY_ENTRY(Factory.QNAME('parent'), parent)
parent = Factory.QREF('Object')
end
type_expr = parent.access([hash])
elsif type_expr.model_class <= LiteralHash
type_expr = Factory.QREF('Object').access([type_expr])
end
@init_hash['type_expr'] = type_expr
@init_hash[KEY_NAME] = name
end
|
#build_TypeDefinition(o, name, parent, body) ⇒ Object
476
477
478
479
480
481
|
# File 'lib/puppet/pops/model/factory.rb', line 476
def build_TypeDefinition(o, name, parent, body)
b = f_build_body(body)
@init_hash[KEY_BODY] = b unless b.nil?
@init_hash['parent'] = parent
@init_hash[KEY_NAME] = name
end
|
#build_TypeMapping(o, lhs, rhs) ⇒ Object
471
472
473
474
|
# File 'lib/puppet/pops/model/factory.rb', line 471
def build_TypeMapping(o, lhs, rhs)
@init_hash['type_expr'] = lhs
@init_hash['mapping_expr'] = rhs
end
|
#build_UnaryExpression(o, expr) ⇒ Object
483
484
485
|
# File 'lib/puppet/pops/model/factory.rb', line 483
def build_UnaryExpression(o, expr)
@init_hash[KEY_EXPR] = expr unless Factory.nop?(expr)
end
|
#captures_rest ⇒ Object
Mark parameter as capturing the rest of arguments
730
731
732
|
# File 'lib/puppet/pops/model/factory.rb', line 730
def captures_rest
@init_hash['captures_rest'] = true
end
|
#contained_current(container) ⇒ Object
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
|
# File 'lib/puppet/pops/model/factory.rb', line 1142
def contained_current(container)
if @current.nil?
unless @init_hash.include?(KEY_LOCATOR)
@init_hash[KEY_LOCATOR] = container[KEY_LOCATOR]
@init_hash[KEY_OFFSET] = container[KEY_OFFSET] || 0
@init_hash[KEY_LENGTH] = 0
end
@current = create_model
end
@current
end
|
#create_model ⇒ Object
76
77
78
79
|
# File 'lib/puppet/pops/model/factory.rb', line 76
def create_model
@init_hash.each_pair { |key, elem| @init_hash[key] = factory_to_model(elem) }
model_class.from_asserted_hash(@init_hash)
end
|
#default(r) ⇒ Object
For CaseExpression, setting the default for an already build CaseExpression
594
595
596
597
|
# File 'lib/puppet/pops/model/factory.rb', line 594
def default(r)
@init_hash['options'] << Factory.WHEN(Factory.infer(:default), r)
self
end
|
546
|
# File 'lib/puppet/pops/model/factory.rb', line 546
def dot r; f_build_binary(NamedAccessExpression, self, r); end
|
570
|
# File 'lib/puppet/pops/model/factory.rb', line 570
def eq r; f_comparison('==', r); end
|
#f_arithmetic(op, r) ⇒ Object
515
516
517
|
# File 'lib/puppet/pops/model/factory.rb', line 515
def f_arithmetic(op, r)
f_build_binary_op(ArithmeticExpression, op, self, r)
end
|
#f_build_binary(klazz, left, right) ⇒ Object
511
512
513
|
# File 'lib/puppet/pops/model/factory.rb', line 511
def f_build_binary(klazz, left, right)
Factory.new(klazz, left, right)
end
|
#f_build_binary_op(klazz, op, left, right) ⇒ Object
507
508
509
|
# File 'lib/puppet/pops/model/factory.rb', line 507
def f_build_binary_op(klazz, op, left, right)
Factory.new(klazz, op, left, right)
end
|
#f_build_body(body) ⇒ Object
341
342
343
344
345
346
347
348
349
350
351
352
|
# File 'lib/puppet/pops/model/factory.rb', line 341
def f_build_body(body)
case body
when NilClass
nil
when Array
Factory.new(BlockExpression, body)
when Factory
body
else
Factory.infer(body)
end
end
|
#f_build_unary(klazz, expr) ⇒ Object
503
504
505
|
# File 'lib/puppet/pops/model/factory.rb', line 503
def f_build_unary(klazz, expr)
Factory.new(klazz, expr)
end
|
#f_comparison(op, r) ⇒ Object
519
520
521
|
# File 'lib/puppet/pops/model/factory.rb', line 519
def f_comparison(op, r)
f_build_binary_op(ComparisonExpression, op, self, r)
end
|
#f_match(op, r) ⇒ Object
523
524
525
|
# File 'lib/puppet/pops/model/factory.rb', line 523
def f_match(op, r)
f_build_binary_op(MatchExpression, op, self, r)
end
|
#factory_to_model(value) ⇒ Object
1132
1133
1134
1135
1136
1137
1138
1139
1140
|
# File 'lib/puppet/pops/model/factory.rb', line 1132
def factory_to_model(value)
if value.instance_of?(Factory)
value.contained_current(self)
elsif value.instance_of?(Array)
value.each_with_index { |el, idx| value[idx] = el.contained_current(self) if el.instance_of?(Factory) }
else
value
end
end
|
528
|
# File 'lib/puppet/pops/model/factory.rb', line 528
def in(r) f_build_binary(InExpression, self, r); end
|
#infer_Array(o) ⇒ Object
Creates a LiteralList instruction from an Array, where the entries are built.
327
328
329
330
|
# File 'lib/puppet/pops/model/factory.rb', line 327
def infer_Array(o)
@model_class = LiteralList
@init_hash['values'] = o.map { |e| Factory.infer(e) }
end
|
#infer_FalseClass(o) ⇒ Object
291
292
293
294
|
# File 'lib/puppet/pops/model/factory.rb', line 291
def infer_FalseClass(o)
@model_class = LiteralBoolean
@init_hash[KEY_VALUE] = o
end
|
#infer_Float(o) ⇒ Object
301
302
303
304
|
# File 'lib/puppet/pops/model/factory.rb', line 301
def infer_Float(o)
@model_class = LiteralFloat
@init_hash[KEY_VALUE] = o
end
|
#infer_Hash(o) ⇒ Object
Create a LiteralHash instruction from a hash, where keys and values are built The hash entries are added in sorted order based on key.to_s
#infer_Integer(o) ⇒ Object
296
297
298
299
|
# File 'lib/puppet/pops/model/factory.rb', line 296
def infer_Integer(o)
@model_class = LiteralInteger
@init_hash[KEY_VALUE] = o
end
|
#infer_NilClass(o) ⇒ Object
282
283
284
|
# File 'lib/puppet/pops/model/factory.rb', line 282
def infer_NilClass(o)
@model_class = Nop
end
|
#infer_Regexp(o) ⇒ Object
306
307
308
309
310
|
# File 'lib/puppet/pops/model/factory.rb', line 306
def infer_Regexp(o)
@model_class = LiteralRegularExpression
@init_hash['pattern'] = o.inspect
@init_hash[KEY_VALUE] = o
end
|
#infer_String(o) ⇒ Object
Building model equivalences of Ruby objects Allows passing regular ruby objects to the factory to produce instructions that when evaluated produce the same thing.
277
278
279
280
|
# File 'lib/puppet/pops/model/factory.rb', line 277
def infer_String(o)
@model_class = LiteralString
@init_hash[KEY_VALUE] = o
end
|
#infer_Symbol(o) ⇒ Object
Creates a String literal, unless the symbol is one of the special :undef, or :default which instead creates a LiterlUndef, or a LiteralDefault. Supports :undef because nil creates a no-op instruction.
315
316
317
318
319
320
321
322
323
324
|
# File 'lib/puppet/pops/model/factory.rb', line 315
def infer_Symbol(o)
case o
when :undef
@model_class = LiteralUndef
when :default
@model_class = LiteralDefault
else
infer_String(o.to_s)
end
end
|
#infer_TrueClass(o) ⇒ Object
286
287
288
289
|
# File 'lib/puppet/pops/model/factory.rb', line 286
def infer_TrueClass(o)
@model_class = LiteralBoolean
@init_hash[KEY_VALUE] = o
end
|
#interpolate_AccessExpression(c) ⇒ Object
rewrite left expression to variable if it is name, number, and recurse if it is an access expression this is for interpolation support in new lexer ($NAME, $NAME[}, $NUMBER, $NUMBER[] - all other expressions requires variables to be preceded with $
1077
1078
1079
1080
1081
1082
1083
|
# File 'lib/puppet/pops/model/factory.rb', line 1077
def interpolate_AccessExpression(c)
lhs = @init_hash[KEY_LEFT_EXPR]
if is_interop_rewriteable?(lhs)
@init_hash[KEY_LEFT_EXPR] = lhs.interpolate
end
self
end
|
#interpolate_CallMethodExpression(c) ⇒ Object
Rewrite method calls on the form $… to $Puppet::Pops::Model::Factory.$x$x.each
1094
1095
1096
1097
1098
1099
1100
|
# File 'lib/puppet/pops/model/factory.rb', line 1094
def interpolate_CallMethodExpression(c)
functor_expr = @init_hash['functor_expr']
if is_interop_rewriteable?(functor_expr)
@init_hash['functor_expr'] = functor_expr.interpolate
end
self
end
|
#interpolate_Factory(c) ⇒ Object
1056
1057
1058
|
# File 'lib/puppet/pops/model/factory.rb', line 1056
def interpolate_Factory(c)
self
end
|
#interpolate_LiteralInteger(c) ⇒ Object
1060
1061
1062
1063
|
# File 'lib/puppet/pops/model/factory.rb', line 1060
def interpolate_LiteralInteger(c)
self.var
end
|
#interpolate_NamedAccessExpression(c) ⇒ Object
1085
1086
1087
1088
1089
1090
1091
|
# File 'lib/puppet/pops/model/factory.rb', line 1085
def interpolate_NamedAccessExpression(c)
lhs = @init_hash[KEY_LEFT_EXPR]
if is_interop_rewriteable?(lhs)
@init_hash[KEY_LEFT_EXPR] = lhs.interpolate
end
self
end
|
#interpolate_Object(c) ⇒ Object
1065
1066
1067
|
# File 'lib/puppet/pops/model/factory.rb', line 1065
def interpolate_Object(c)
self
end
|
#interpolate_QualifiedName(c) ⇒ Object
1069
1070
1071
|
# File 'lib/puppet/pops/model/factory.rb', line 1069
def interpolate_QualifiedName(c)
self.var
end
|
#is_interop_rewriteable?(o) ⇒ Boolean
#lambda=(lambda) ⇒ Object
599
600
601
602
|
# File 'lib/puppet/pops/model/factory.rb', line 599
def lambda=(lambda)
@init_hash['lambda'] = lambda
self
end
|
628
629
630
|
# File 'lib/puppet/pops/model/factory.rb', line 628
def length
@init_hash[KEY_LENGTH]
end
|
#map_offset(model, locator) ⇒ Object
94
95
96
|
# File 'lib/puppet/pops/model/factory.rb', line 94
def map_offset(model, locator)
MAPOFFSET_VISITOR.visit_this_1(self, model, locator)
end
|
#map_offset_Factory(o, locator) ⇒ Object
102
103
104
|
# File 'lib/puppet/pops/model/factory.rb', line 102
def map_offset_Factory(o, locator)
map_offset(o.model, locator)
end
|
#map_offset_Object(o, locator) ⇒ Object
98
99
100
|
# File 'lib/puppet/pops/model/factory.rb', line 98
def map_offset_Object(o, locator)
o
end
|
#map_offset_Positioned(o, locator) ⇒ Object
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/puppet/pops/model/factory.rb', line 106
def map_offset_Positioned(o, locator)
global_offset, global_length = locator.to_global(o.offset, o.length)
o.instance_variable_set(:'@offset', global_offset)
o.instance_variable_set(:'@length', global_length)
o.instance_variable_set(:'@locator', locator.locator) if locator.is_a? Puppet::Pops::Parser::Locator::SubLocator
end
|
536
|
# File 'lib/puppet/pops/model/factory.rb', line 536
def minus(); f_build_unary(UnaryMinusExpression, self); end
|
#minus_set(r) ⇒ Object
615
616
617
|
# File 'lib/puppet/pops/model/factory.rb', line 615
def minus_set(r)
f_build_binary_op(AssignmentExpression, '-=', self, r)
end
|
576
|
# File 'lib/puppet/pops/model/factory.rb', line 576
def mne r; f_match('!~', r); end
|
#model ⇒ Object
Also known as:
current
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/puppet/pops/model/factory.rb', line 57
def model
if @current.nil?
unless @init_hash.include?(KEY_LOCATOR)
@init_hash[KEY_LOCATOR] = Parser::Locator.locator('<no source>', 'no file')
unless @model_class <= Program
@init_hash[KEY_OFFSET] = 0
@init_hash[KEY_LENGTH] = 0
end
end
@current = create_model
end
@current
end
|
572
|
# File 'lib/puppet/pops/model/factory.rb', line 572
def ne r; f_comparison('!=', r); end
|
534
|
# File 'lib/puppet/pops/model/factory.rb', line 534
def not(); f_build_unary(NotExpression, self); end
|
624
625
626
|
# File 'lib/puppet/pops/model/factory.rb', line 624
def offset
@init_hash[KEY_OFFSET]
end
|
530
|
# File 'lib/puppet/pops/model/factory.rb', line 530
def or(r) f_build_binary(OrExpression, self, r); end
|
578
|
# File 'lib/puppet/pops/model/factory.rb', line 578
def paren; f_build_unary(ParenthesizedExpression, self); end
|
#plus_set(r) ⇒ Object
610
611
612
|
# File 'lib/puppet/pops/model/factory.rb', line 610
def plus_set(r)
f_build_binary_op(AssignmentExpression, '+=', self, r)
end
|
#record_position(locator, start_locatable, end_locatable) ⇒ Object
Records the position (start -> end) and computes the resulting length.
634
635
636
637
638
639
640
641
|
# File 'lib/puppet/pops/model/factory.rb', line 634
def record_position(locator, start_locatable, end_locatable)
start_offset = start_locatable.offset
@init_hash[KEY_LOCATOR] = locator
@init_hash[KEY_OFFSET] = start_offset
@init_hash[KEY_LENGTH] = end_locatable.nil? ? start_locatable.length : end_locatable.offset + end_locatable.length - start_offset
self
end
|
#relop(op, r) ⇒ Object
580
581
582
|
# File 'lib/puppet/pops/model/factory.rb', line 580
def relop(op, r)
f_build_binary_op(RelationshipExpression, op, self, r)
end
|
605
606
607
|
# File 'lib/puppet/pops/model/factory.rb', line 605
def set(r)
f_build_binary_op(AssignmentExpression, '=', self, r)
end
|
540
|
# File 'lib/puppet/pops/model/factory.rb', line 540
def text(); f_build_unary(TextExpression, self); end
|
1128
1129
1130
|
# File 'lib/puppet/pops/model/factory.rb', line 1128
def to_s
"Factory for #{@model_class}"
end
|
#type_expr(o) ⇒ Object
Set Expression that should evaluate to the parameter’s type
735
736
737
|
# File 'lib/puppet/pops/model/factory.rb', line 735
def type_expr(o)
@init_hash['type_expr'] = o
end
|
538
|
# File 'lib/puppet/pops/model/factory.rb', line 538
def unfold(); f_build_unary(UnfoldExpression, self); end
|
542
|
# File 'lib/puppet/pops/model/factory.rb', line 542
def var(); f_build_unary(VariableExpression, self); end
|