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'.freeze
- KEY_OFFSET =
'offset'.freeze
- KEY_LOCATOR =
'locator'.freeze
- KEY_OPERATOR =
'operator'.freeze
- KEY_VALUE =
'value'.freeze
- KEY_KEYS =
'keys'.freeze
- KEY_NAME =
'name'.freeze
- KEY_BODY =
'body'.freeze
- KEY_EXPR =
'expr'.freeze
- KEY_LEFT_EXPR =
'left_expr'.freeze
- KEY_RIGHT_EXPR =
'right_expr'.freeze
- KEY_PARAMETERS =
'parameters'.freeze
- BUILD_VISITOR =
Visitor.new(self, 'build')
- INFER_VISITOR =
Visitor.new(self, 'infer')
- INTERPOLATION_VISITOR =
Visitor.new(self, 'interpolate')
- 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
-
.APPLICATION(name, parameters, body) ⇒ Object
-
.ATTRIBUTE_OP(name, op, expr) ⇒ Object
-
.ATTRIBUTES_OP(expr) ⇒ Object
-
.block(*args) ⇒ Object
-
.block_or_expression(args) ⇒ 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).
-
.CAPABILITY_MAPPING(kind, component, cap_name, mappings) ⇒ Object
-
.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
-
.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
-
.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).
-
.SITE(body) ⇒ Object
-
.STRING(*args) ⇒ Object
-
.string(*args) ⇒ Object
-
.SUBLOCATE(token, expr) ⇒ 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_Application(o, n, ps, body) ⇒ Object
Building of Model classes.
-
#build_ArithmeticExpression(o, op, a, b) ⇒ Object
-
#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_CapabilityMapping(o, kind, component, capability, mappings) ⇒ 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) ⇒ 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_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_SiteDefinition(o, body) ⇒ Object
-
#build_SubLocatedExpression(o, token, expression) ⇒ Object
Builds a SubLocatedExpression - this wraps the expression in a sublocation configured from the given token A SubLocated holds its own locator that is used for subexpressions holding positions relative to what it describes.
-
#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
-
#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
82
83
84
85
86
87
88
89
90
|
# File 'lib/puppet/pops/model/factory.rb', line 82
def initialize(o, *args)
@i12n = {}
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
40
41
42
|
# File 'lib/puppet/pops/model/factory.rb', line 40
def model_class
@model_class
end
|
Class Method Details
.APPLICATION(name, parameters, body) ⇒ Object
864
865
866
|
# File 'lib/puppet/pops/model/factory.rb', line 864
def self.APPLICATION(name, parameters, body)
new(Application, name, parameters, body)
end
|
.ATTRIBUTE_OP(name, op, expr) ⇒ Object
798
799
800
|
# File 'lib/puppet/pops/model/factory.rb', line 798
def self.ATTRIBUTE_OP(name, op, expr)
new(AttributeOperation, name, op, expr)
end
|
.ATTRIBUTES_OP(expr) ⇒ Object
802
803
804
|
# File 'lib/puppet/pops/model/factory.rb', line 802
def self.ATTRIBUTES_OP(expr)
new(AttributesOperation, expr)
end
|
.block(*args) ⇒ Object
662
|
# File 'lib/puppet/pops/model/factory.rb', line 662
def self.block(*args); new(BlockExpression, args.map { |arg| infer(arg) }); end
|
.block_or_expression(args) ⇒ Object
Builds a BlockExpression if args size > 1, else the single expression/value in args
848
849
850
|
# File 'lib/puppet/pops/model/factory.rb', line 848
def self.block_or_expression(args)
args.size > 1 ? new(BlockExpression, args) : args[0]
end
|
.CALL_METHOD(functor, argument_list) ⇒ Object
815
816
817
|
# File 'lib/puppet/pops/model/factory.rb', line 815
def self.CALL_METHOD(functor, argument_list)
new(CallMethodExpression, functor, true, nil, argument_list)
end
|
.CALL_NAMED(name, rval_required, argument_list) ⇒ Object
811
812
813
|
# File 'lib/puppet/pops/model/factory.rb', line 811
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)
807
808
809
|
# File 'lib/puppet/pops/model/factory.rb', line 807
def self.call_named(name, rval_required, *argument_list)
new(CallNamedFunctionExpression, fqn(name), rval_required, argument_list.map { |arg| infer(arg) })
end
|
.CAPABILITY_MAPPING(kind, component, cap_name, mappings) ⇒ Object
860
861
862
|
# File 'lib/puppet/pops/model/factory.rb', line 860
def self.CAPABILITY_MAPPING(kind, component, cap_name, mappings)
new(CapabilityMapping, kind, component, cap_name, mappings)
end
|
.CASE(test_e, *options) ⇒ Object
672
|
# File 'lib/puppet/pops/model/factory.rb', line 672
def self.CASE(test_e,*options); new(CaseExpression, test_e, options); end
|
.COLLECT(type_expr, query_expr, attribute_operations) ⇒ Object
819
820
821
|
# File 'lib/puppet/pops/model/factory.rb', line 819
def self.COLLECT(type_expr, query_expr, attribute_operations)
new(CollectExpression, type_expr, query_expr, attribute_operations)
end
|
.concat(*args) ⇒ Object
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
|
# File 'lib/puppet/pops/model/factory.rb', line 1037
def self.concat(*args)
result = ''
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 #{e.class}"
end
end
infer(result)
end
|
.DEFINITION(name, parameters, body) ⇒ Object
856
857
858
|
# File 'lib/puppet/pops/model/factory.rb', line 856
def self.DEFINITION(name, parameters, body)
new(ResourceTypeDefinition, name, parameters, body)
end
|
.EPP(parameters, body) ⇒ Object
735
736
737
738
739
740
741
742
743
744
|
# File 'lib/puppet/pops/model/factory.rb', line 735
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
794
795
796
|
# File 'lib/puppet/pops/model/factory.rb', line 794
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.
711
712
713
|
# File 'lib/puppet/pops/model/factory.rb', line 711
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
868
869
870
|
# File 'lib/puppet/pops/model/factory.rb', line 868
def self.FUNCTION(name, parameters, body, return_type)
new(FunctionDefinition, name, parameters, body, return_type)
end
|
.HASH(entries) ⇒ Object
680
|
# File 'lib/puppet/pops/model/factory.rb', line 680
def self.HASH(entries); new(LiteralHash, entries); end
|
.HEREDOC(name, expr) ⇒ Object
682
|
# File 'lib/puppet/pops/model/factory.rb', line 682
def self.HEREDOC(name, expr); new(HeredocExpression, name, expr); end
|
.HOSTCLASS(name, parameters, parent, body) ⇒ Object
852
853
854
|
# File 'lib/puppet/pops/model/factory.rb', line 852
def self.HOSTCLASS(name, parameters, parent, body)
new(HostClassDefinition, name, parameters, parent, body)
end
|
.IF(test_e, then_e, else_e) ⇒ Object
668
|
# File 'lib/puppet/pops/model/factory.rb', line 668
def self.IF(test_e,then_e,else_e); new(IfExpression, test_e, then_e, else_e); end
|
32
33
34
35
36
37
38
|
# File 'lib/puppet/pops/model/factory.rb', line 32
def self.infer(o)
if o.instance_of?(Factory)
o
else
new(o)
end
end
|
.KEY_ENTRY(key, val) ⇒ Object
678
|
# File 'lib/puppet/pops/model/factory.rb', line 678
def self.KEY_ENTRY(key, val); new(KeyedEntry, key, val); end
|
.LAMBDA(parameters, body, return_type) ⇒ Object
872
873
874
|
# File 'lib/puppet/pops/model/factory.rb', line 872
def self.LAMBDA(parameters, body, return_type)
new(LambdaExpression, parameters, body, return_type)
end
|
.LIST(entries) ⇒ Object
688
|
# File 'lib/puppet/pops/model/factory.rb', line 688
def self.LIST(entries); new(LiteralList, entries); end
|
.literal(o) ⇒ Object
654
|
# File 'lib/puppet/pops/model/factory.rb', line 654
def self.literal(o); infer(o); end
|
.MAP(match, value) ⇒ Object
676
|
# File 'lib/puppet/pops/model/factory.rb', line 676
def self.MAP(match, value); new(SelectorEntry, match, value); end
|
656
|
# File 'lib/puppet/pops/model/factory.rb', line 656
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
915
916
917
|
# File 'lib/puppet/pops/model/factory.rb', line 915
def self.name_is_statement?(name)
STATEMENT_CALLS.include?(name)
end
|
.NAMED_ACCESS(type_name, bodies) ⇒ Object
823
824
825
|
# File 'lib/puppet/pops/model/factory.rb', line 823
def self.NAMED_ACCESS(type_name, bodies)
new(NamedAccessExpression, type_name, bodies)
end
|
.NODE(hosts, parent, body) ⇒ Object
692
|
# File 'lib/puppet/pops/model/factory.rb', line 692
def self.NODE(hosts, parent, body); new(NodeDefinition, hosts, parent, body); end
|
.nop?(o) ⇒ Boolean
888
889
890
|
# File 'lib/puppet/pops/model/factory.rb', line 888
def self.nop? o
o.nil? || o.instance_of?(Factory) && o.model_class <= Nop
end
|
.NUMBER(name_or_numeric) ⇒ Object
757
758
759
760
761
762
763
764
765
766
767
768
769
|
# File 'lib/puppet/pops/model/factory.rb', line 757
def self.NUMBER(name_or_numeric)
if n_radix = Utils.to_n_with_radix(name_or_numeric)
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}"
end
end
|
.PARAM(name, expr = nil) ⇒ Object
690
|
# File 'lib/puppet/pops/model/factory.rb', line 690
def self.PARAM(name, expr=nil); new(Parameter, name, expr); end
|
.PROGRAM(body, definitions, locator) ⇒ Object
843
844
845
|
# File 'lib/puppet/pops/model/factory.rb', line 843
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.
753
754
755
|
# File 'lib/puppet/pops/model/factory.rb', line 753
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
773
774
775
776
777
778
779
780
781
782
783
784
|
# File 'lib/puppet/pops/model/factory.rb', line 773
def self.QNAME_OR_NUMBER(name)
if n_radix = Utils.to_n_with_radix(name)
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
786
787
788
|
# File 'lib/puppet/pops/model/factory.rb', line 786
def self.QREF(name)
new(QualifiedReference, name)
end
|
.RENDER_EXPR(expr) ⇒ Object
731
732
733
|
# File 'lib/puppet/pops/model/factory.rb', line 731
def self.RENDER_EXPR(expr)
new(RenderExpression, expr)
end
|
.RENDER_STRING(o) ⇒ Object
727
728
729
|
# File 'lib/puppet/pops/model/factory.rb', line 727
def self.RENDER_STRING(o)
new(RenderStringExpression, o)
end
|
.RESERVED(name, future = false) ⇒ Object
746
747
748
|
# File 'lib/puppet/pops/model/factory.rb', line 746
def self.RESERVED(name, future=false)
new(ReservedWord, name, future)
end
|
.RESOURCE(type_name, bodies) ⇒ Object
827
828
829
|
# File 'lib/puppet/pops/model/factory.rb', line 827
def self.RESOURCE(type_name, bodies)
new(ResourceExpression, type_name, bodies)
end
|
.RESOURCE_BODY(resource_title, attribute_operations) ⇒ Object
839
840
841
|
# File 'lib/puppet/pops/model/factory.rb', line 839
def self.RESOURCE_BODY(resource_title, attribute_operations)
new(ResourceBody, resource_title, attribute_operations)
end
|
.RESOURCE_DEFAULTS(type_name, attribute_operations) ⇒ Object
831
832
833
|
# File 'lib/puppet/pops/model/factory.rb', line 831
def self.RESOURCE_DEFAULTS(type_name, attribute_operations)
new(ResourceDefaultsExpression, type_name, attribute_operations)
end
|
.RESOURCE_OVERRIDE(resource_ref, attribute_operations) ⇒ Object
835
836
837
|
# File 'lib/puppet/pops/model/factory.rb', line 835
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
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
|
# File 'lib/puppet/pops/model/factory.rb', line 627
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.
613
614
615
616
617
618
|
# File 'lib/puppet/pops/model/factory.rb', line 613
def self.set_resource_form(expr, form)
return false unless expr.instance_of?(self) && expr.model_class <= AbstractResource
expr['form'] = form
return true
end
|
.SITE(body) ⇒ Object
694
|
# File 'lib/puppet/pops/model/factory.rb', line 694
def self.SITE(body); new(SiteDefinition, body); end
|
.STRING(*args) ⇒ Object
684
|
# File 'lib/puppet/pops/model/factory.rb', line 684
def self.STRING(*args); new(ConcatenatedString, args); end
|
.string(*args) ⇒ Object
664
|
# File 'lib/puppet/pops/model/factory.rb', line 664
def self.string(*args); new(ConcatenatedString, args.map { |arg| infer(arg) }); end
|
.SUBLOCATE(token, expr) ⇒ Object
686
|
# File 'lib/puppet/pops/model/factory.rb', line 686
def self.SUBLOCATE(token, expr) new(SubLocatedExpression, token, expr); end
|
.TEXT(expr) ⇒ Object
722
723
724
|
# File 'lib/puppet/pops/model/factory.rb', line 722
def self.TEXT(expr)
new(TextExpression, infer(expr).interpolate)
end
|
666
|
# File 'lib/puppet/pops/model/factory.rb', line 666
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.
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
|
# File 'lib/puppet/pops/model/factory.rb', line 930
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)
965
966
967
968
969
970
971
972
973
974
975
976
977
|
# File 'lib/puppet/pops/model/factory.rb', line 965
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
876
877
878
879
880
881
882
|
# File 'lib/puppet/pops/model/factory.rb', line 876
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
884
885
886
|
# File 'lib/puppet/pops/model/factory.rb', line 884
def self.TYPE_DEFINITION(name, parent, body)
new(TypeDefinition, name, parent, body)
end
|
.unfold(o) ⇒ Object
658
|
# File 'lib/puppet/pops/model/factory.rb', line 658
def self.unfold(o); infer(o).unfold; end
|
.UNLESS(test_e, then_e, else_e) ⇒ Object
670
|
# File 'lib/puppet/pops/model/factory.rb', line 670
def self.UNLESS(test_e,then_e,else_e); new(UnlessExpression, test_e, then_e, else_e); end
|
660
|
# File 'lib/puppet/pops/model/factory.rb', line 660
def self.var(o); infer(o).var; end
|
.VIRTUAL_QUERY(query_expr) ⇒ Object
790
791
792
|
# File 'lib/puppet/pops/model/factory.rb', line 790
def self.VIRTUAL_QUERY(query_expr)
new(VirtualQuery, query_expr)
end
|
.WHEN(values_list, block) ⇒ Object
674
|
# File 'lib/puppet/pops/model/factory.rb', line 674
def self.WHEN(values_list, block); new(CaseOption, values_list, block); end
|
Instance Method Details
523
|
# File 'lib/puppet/pops/model/factory.rb', line 523
def % r; f_arithmetic('%', r); end
|
521
|
# File 'lib/puppet/pops/model/factory.rb', line 521
def * r; f_arithmetic('*', r); end
|
515
|
# File 'lib/puppet/pops/model/factory.rb', line 515
def + r; f_arithmetic('+', r); end
|
517
|
# File 'lib/puppet/pops/model/factory.rb', line 517
def - r; f_arithmetic('-', r); end
|
519
|
# File 'lib/puppet/pops/model/factory.rb', line 519
def / r; f_arithmetic('/', r); end
|
529
|
# File 'lib/puppet/pops/model/factory.rb', line 529
def < r; f_comparison('<', r); end
|
525
|
# File 'lib/puppet/pops/model/factory.rb', line 525
def << r; f_arithmetic('<<', r); end
|
531
|
# File 'lib/puppet/pops/model/factory.rb', line 531
def <= r; f_comparison('<=', r); end
|
541
|
# File 'lib/puppet/pops/model/factory.rb', line 541
def =~ r; f_match('=~', r); end
|
533
|
# File 'lib/puppet/pops/model/factory.rb', line 533
def > r; f_comparison('>', r); end
|
535
|
# File 'lib/puppet/pops/model/factory.rb', line 535
def >= r; f_comparison('>=', r); end
|
527
|
# File 'lib/puppet/pops/model/factory.rb', line 527
def >> r; f_arithmetic('>>', r); end
|
42
43
44
|
# File 'lib/puppet/pops/model/factory.rb', line 42
def [](key)
@i12n[key]
end
|
#[]=(key, value) ⇒ Object
46
47
48
|
# File 'lib/puppet/pops/model/factory.rb', line 46
def []=(key, value)
@i12n[key] = value
end
|
#access(r) ⇒ Object
511
|
# File 'lib/puppet/pops/model/factory.rb', line 511
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
556
557
558
|
# File 'lib/puppet/pops/model/factory.rb', line 556
def access_at(*r)
f_build_binary(AccessExpression, self, r.map { |arg| Factory.infer(arg) })
end
|
#all_factories(&block) ⇒ Object
50
51
52
53
|
# File 'lib/puppet/pops/model/factory.rb', line 50
def all_factories(&block)
block.call(self)
@i12n.each_value { |value| value.all_factories(&block) if value.instance_of?(Factory) }
end
|
499
|
# File 'lib/puppet/pops/model/factory.rb', line 499
def and(r) f_build_binary(AndExpression, self, r); end
|
#attributes(*args) ⇒ Object
586
587
588
589
|
# File 'lib/puppet/pops/model/factory.rb', line 586
def attributes(*args)
@i12n['attributes'] = args
self
end
|
#build_AccessExpression(o, left, keys) ⇒ Object
126
127
128
129
|
# File 'lib/puppet/pops/model/factory.rb', line 126
def build_AccessExpression(o, left, keys)
@i12n[KEY_LEFT_EXPR] = left
@i12n[KEY_KEYS] = keys
end
|
#build_Application(o, n, ps, body) ⇒ Object
Building of Model classes
99
100
101
102
103
104
|
# File 'lib/puppet/pops/model/factory.rb', line 99
def build_Application(o, n, ps, body)
@i12n[KEY_NAME] = n
@i12n[KEY_PARAMETERS] = ps
b = f_build_body(body)
@i12n[KEY_BODY] = b unless b.nil?
end
|
#build_ArithmeticExpression(o, op, a, b) ⇒ Object
106
107
108
109
|
# File 'lib/puppet/pops/model/factory.rb', line 106
def build_ArithmeticExpression(o, op, a, b)
@i12n[KEY_OPERATOR] = op
build_BinaryExpression(o, a, b)
end
|
#build_AssignmentExpression(o, op, a, b) ⇒ Object
111
112
113
114
|
# File 'lib/puppet/pops/model/factory.rb', line 111
def build_AssignmentExpression(o, op, a, b)
@i12n[KEY_OPERATOR] = op
build_BinaryExpression(o, a, b)
end
|
#build_AttributeOperation(o, name, op, value) ⇒ Object
116
117
118
119
120
|
# File 'lib/puppet/pops/model/factory.rb', line 116
def build_AttributeOperation(o, name, op, value)
@i12n[KEY_OPERATOR] = op
@i12n['attribute_name'] = name.to_s @i12n['value_expr'] = value
end
|
#build_AttributesOperation(o, value) ⇒ Object
122
123
124
|
# File 'lib/puppet/pops/model/factory.rb', line 122
def build_AttributesOperation(o, value)
@i12n[KEY_EXPR] = value
end
|
#build_BinaryExpression(o, left, right) ⇒ Object
131
132
133
134
|
# File 'lib/puppet/pops/model/factory.rb', line 131
def build_BinaryExpression(o, left, right)
@i12n[KEY_LEFT_EXPR] = left
@i12n[KEY_RIGHT_EXPR] = right
end
|
#build_BlockExpression(o, args) ⇒ Object
136
137
138
|
# File 'lib/puppet/pops/model/factory.rb', line 136
def build_BlockExpression(o, args)
@i12n['statements'] = args
end
|
#build_CallExpression(o, functor, rval_required, args) ⇒ Object
147
148
149
150
151
|
# File 'lib/puppet/pops/model/factory.rb', line 147
def build_CallExpression(o, functor, rval_required, args)
@i12n['functor_expr'] = functor
@i12n['rval_required'] = rval_required
@i12n['arguments'] = args
end
|
#build_CallMethodExpression(o, functor, rval_required, lambda, args) ⇒ Object
153
154
155
156
|
# File 'lib/puppet/pops/model/factory.rb', line 153
def build_CallMethodExpression(o, functor, rval_required, lambda, args)
build_CallExpression(o, functor, rval_required, args)
@i12n['lambda'] = lambda
end
|
#build_CapabilityMapping(o, kind, component, capability, mappings) ⇒ Object
350
351
352
353
354
355
|
# File 'lib/puppet/pops/model/factory.rb', line 350
def build_CapabilityMapping(o, kind, component, capability, mappings)
@i12n['kind'] = kind
@i12n['component'] = component
@i12n['capability'] = capability
@i12n['mappings'] = mappings
end
|
#build_CaseExpression(o, test, args) ⇒ Object
158
159
160
161
|
# File 'lib/puppet/pops/model/factory.rb', line 158
def build_CaseExpression(o, test, args)
@i12n['test'] = test
@i12n['options'] = args
end
|
#build_CaseOption(o, value_list, then_expr) ⇒ Object
163
164
165
166
167
168
|
# File 'lib/puppet/pops/model/factory.rb', line 163
def build_CaseOption(o, value_list, then_expr)
value_list = [value_list] unless value_list.is_a?(Array)
@i12n['values'] = value_list
b = f_build_body(then_expr)
@i12n['then_expr'] = b unless b.nil?
end
|
#build_CollectExpression(o, type_expr, query_expr, attribute_operations) ⇒ Object
170
171
172
173
174
|
# File 'lib/puppet/pops/model/factory.rb', line 170
def build_CollectExpression(o, type_expr, query_expr, attribute_operations)
@i12n['type_expr'] = type_expr
@i12n['query'] = query_expr
@i12n['operations'] = attribute_operations
end
|
#build_ComparisonExpression(o, op, a, b) ⇒ Object
176
177
178
179
|
# File 'lib/puppet/pops/model/factory.rb', line 176
def build_ComparisonExpression(o, op, a, b)
@i12n[KEY_OPERATOR] = op
build_BinaryExpression(o, a, b)
end
|
#build_ConcatenatedString(o, args) ⇒ Object
181
182
183
|
# File 'lib/puppet/pops/model/factory.rb', line 181
def build_ConcatenatedString(o, args)
@i12n['segments'] = args
end
|
#build_EppExpression(o, parameters_specified, body) ⇒ Object
140
141
142
143
144
|
# File 'lib/puppet/pops/model/factory.rb', line 140
def build_EppExpression(o, parameters_specified, body)
@i12n['parameters_specified'] = parameters_specified
b = f_build_body(body)
@i12n[KEY_BODY] = b unless b.nil?
end
|
#build_FunctionDefinition(o, name, parameters, body, return_type) ⇒ Object
342
343
344
345
346
347
348
|
# File 'lib/puppet/pops/model/factory.rb', line 342
def build_FunctionDefinition(o, name, parameters, body, return_type)
@i12n[KEY_PARAMETERS] = parameters
b = f_build_body(body)
@i12n[KEY_BODY] = b unless b.nil?
@i12n[KEY_NAME] = name
@i12n['return_type'] = return_type unless return_type.nil?
end
|
#build_HeredocExpression(o, name, expr) ⇒ Object
185
186
187
188
|
# File 'lib/puppet/pops/model/factory.rb', line 185
def build_HeredocExpression(o, name, expr)
@i12n['syntax'] = name
@i12n['text_expr'] = expr
end
|
#build_HostClassDefinition(o, name, parameters, parent_class_name, body) ⇒ HostClassDefinition
Returns configured from the parameters.
196
197
198
199
|
# File 'lib/puppet/pops/model/factory.rb', line 196
def build_HostClassDefinition(o, name, parameters, parent_class_name, body)
build_NamedDefinition(o, name, parameters, body)
@i12n['parent_class'] = parent_class_name unless parent_class_name.nil?
end
|
#build_IfExpression(o, t, ift, els) ⇒ Object
237
238
239
240
241
|
# File 'lib/puppet/pops/model/factory.rb', line 237
def build_IfExpression(o, t, ift, els)
@i12n['test'] = t
@i12n['then_expr'] = ift
@i12n['else_expr'] = els
end
|
#build_KeyedEntry(o, k, v) ⇒ Object
211
212
213
214
|
# File 'lib/puppet/pops/model/factory.rb', line 211
def build_KeyedEntry(o, k, v)
@i12n['key'] = k
@i12n[KEY_VALUE] = v
end
|
#build_LambdaExpression(o, parameters, body, return_type) ⇒ Object
328
329
330
331
332
333
|
# File 'lib/puppet/pops/model/factory.rb', line 328
def build_LambdaExpression(o, parameters, body, return_type)
@i12n[KEY_PARAMETERS] = parameters
b = f_build_body(body)
@i12n[KEY_BODY] = b unless b.nil?
@i12n['return_type'] = return_type unless return_type.nil?
end
|
#build_LiteralFloat(o, val) ⇒ Object
224
225
226
|
# File 'lib/puppet/pops/model/factory.rb', line 224
def build_LiteralFloat(o, val)
@i12n[KEY_VALUE] = val
end
|
#build_LiteralHash(o, keyed_entries) ⇒ Object
216
217
218
|
# File 'lib/puppet/pops/model/factory.rb', line 216
def build_LiteralHash(o, keyed_entries)
@i12n['entries'] = keyed_entries
end
|
#build_LiteralInteger(o, val, radix) ⇒ Object
228
229
230
231
|
# File 'lib/puppet/pops/model/factory.rb', line 228
def build_LiteralInteger(o, val, radix)
@i12n[KEY_VALUE] = val
@i12n['radix'] = radix
end
|
#build_LiteralList(o, values) ⇒ Object
220
221
222
|
# File 'lib/puppet/pops/model/factory.rb', line 220
def build_LiteralList(o, values)
@i12n['values'] = values
end
|
#build_LiteralString(o, value) ⇒ Object
233
234
235
|
# File 'lib/puppet/pops/model/factory.rb', line 233
def build_LiteralString(o, value)
@i12n[KEY_VALUE] = val
end
|
#build_MatchExpression(o, op, a, b) ⇒ Object
243
244
245
246
|
# File 'lib/puppet/pops/model/factory.rb', line 243
def build_MatchExpression(o, op, a, b)
@i12n[KEY_OPERATOR] = op
build_BinaryExpression(o, a, b)
end
|
#build_NamedDefinition(o, name, parameters, body) ⇒ Object
335
336
337
338
339
340
|
# File 'lib/puppet/pops/model/factory.rb', line 335
def build_NamedDefinition(o, name, parameters, body)
@i12n[KEY_PARAMETERS] = parameters
b = f_build_body(body)
@i12n[KEY_BODY] = b unless b.nil?
@i12n[KEY_NAME] = name
end
|
#build_NodeDefinition(o, hosts, parent, body) ⇒ Object
357
358
359
360
361
362
|
# File 'lib/puppet/pops/model/factory.rb', line 357
def build_NodeDefinition(o, hosts, parent, body)
@i12n['host_matches'] = hosts
@i12n['parent'] = parent unless parent.nil? b = f_build_body(body)
@i12n[KEY_BODY] = b unless b.nil?
end
|
#build_Parameter(o, name, expr) ⇒ Object
369
370
371
372
|
# File 'lib/puppet/pops/model/factory.rb', line 369
def build_Parameter(o, name, expr)
@i12n[KEY_NAME] = name
@i12n[KEY_VALUE] = expr
end
|
#build_Program(o, body, definitions, locator) ⇒ Object
454
455
456
457
458
459
|
# File 'lib/puppet/pops/model/factory.rb', line 454
def build_Program(o, body, definitions, locator)
@i12n[KEY_BODY] = body
@i12n['definitions'] = definitions
@i12n[KEY_LOCATOR] = locator
end
|
#build_QualifiedName(o, name) ⇒ Object
461
462
463
|
# File 'lib/puppet/pops/model/factory.rb', line 461
def build_QualifiedName(o, name)
@i12n[KEY_VALUE] = name
end
|
#build_QualifiedReference(o, name) ⇒ Object
374
375
376
|
# File 'lib/puppet/pops/model/factory.rb', line 374
def build_QualifiedReference(o, name)
@i12n['cased_value'] = name.to_s
end
|
#build_QueryExpression(o, expr) ⇒ Object
429
430
431
|
# File 'lib/puppet/pops/model/factory.rb', line 429
def build_QueryExpression(o, expr)
@i12n[KEY_EXPR] = expr unless Factory.nop?(expr)
end
|
#build_RelationshipExpression(o, op, a, b) ⇒ Object
378
379
380
381
|
# File 'lib/puppet/pops/model/factory.rb', line 378
def build_RelationshipExpression(o, op, a, b)
@i12n[KEY_OPERATOR] = op
build_BinaryExpression(o, a, b)
end
|
#build_RenderStringExpression(o, string) ⇒ Object
388
389
390
|
# File 'lib/puppet/pops/model/factory.rb', line 388
def build_RenderStringExpression(o, string)
@i12n[KEY_VALUE] = string;
end
|
#build_ReservedWord(o, name, future) ⇒ Object
206
207
208
209
|
# File 'lib/puppet/pops/model/factory.rb', line 206
def build_ReservedWord(o, name, future)
@i12n['word'] = name
@i12n['future'] = future
end
|
#build_ResourceBody(o, title_expression, attribute_operations) ⇒ Object
392
393
394
395
|
# File 'lib/puppet/pops/model/factory.rb', line 392
def build_ResourceBody(o, title_expression, attribute_operations)
@i12n['title'] = title_expression
@i12n['operations'] = attribute_operations
end
|
#build_ResourceDefaultsExpression(o, type_ref, attribute_operations) ⇒ Object
397
398
399
400
|
# File 'lib/puppet/pops/model/factory.rb', line 397
def build_ResourceDefaultsExpression(o, type_ref, attribute_operations)
@i12n['type_ref'] = type_ref
@i12n['operations'] = attribute_operations
end
|
#build_ResourceExpression(o, type_name, bodies) ⇒ Object
383
384
385
386
|
# File 'lib/puppet/pops/model/factory.rb', line 383
def build_ResourceExpression(o, type_name, bodies)
@i12n['type_name'] = type_name
@i12n['bodies'] = bodies
end
|
#build_ResourceOverrideExpression(o, resources, attribute_operations) ⇒ Object
201
202
203
204
|
# File 'lib/puppet/pops/model/factory.rb', line 201
def build_ResourceOverrideExpression(o, resources, attribute_operations)
@i12n['resources'] = resources
@i12n['operations'] = attribute_operations
end
|
#build_SelectorEntry(o, matching, value) ⇒ Object
424
425
426
427
|
# File 'lib/puppet/pops/model/factory.rb', line 424
def build_SelectorEntry(o, matching, value)
@i12n['matching_expr'] = matching
@i12n['value_expr'] = value
end
|
#build_SelectorExpression(o, left, *selectors) ⇒ Object
402
403
404
405
|
# File 'lib/puppet/pops/model/factory.rb', line 402
def build_SelectorExpression(o, left, *selectors)
@i12n[KEY_LEFT_EXPR] = left
@i12n['selectors'] = selectors
end
|
#build_SiteDefinition(o, body) ⇒ Object
364
365
366
367
|
# File 'lib/puppet/pops/model/factory.rb', line 364
def build_SiteDefinition(o, body)
b = f_build_body(body)
@i12n[KEY_BODY] = b unless b.nil?
end
|
#build_SubLocatedExpression(o, token, expression) ⇒ Object
Builds a SubLocatedExpression - this wraps the expression in a sublocation configured from the given token A SubLocated holds its own locator that is used for subexpressions holding positions relative to what it describes.
412
413
414
415
416
417
418
419
420
421
422
|
# File 'lib/puppet/pops/model/factory.rb', line 412
def build_SubLocatedExpression(o, token, expression)
@i12n[KEY_EXPR] = expression
@i12n[KEY_OFFSET] = token.offset
@i12n[KEY_LENGTH] = token.length
locator = token.locator
@i12n[KEY_LOCATOR] = locator
@i12n['leading_line_count'] = locator.leading_line_count
@i12n['leading_line_offset'] = locator.leading_line_offset
@i12n['line_offsets'] = locator.locator.line_index
end
|
#build_TokenValue(o) ⇒ Object
465
466
467
|
# File 'lib/puppet/pops/model/factory.rb', line 465
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
433
434
435
436
|
# File 'lib/puppet/pops/model/factory.rb', line 433
def build_TypeAlias(o, name, type_expr)
@i12n['type_expr'] = type_expr
@i12n[KEY_NAME] = name
end
|
#build_TypeDefinition(o, name, parent, body) ⇒ Object
443
444
445
446
447
448
|
# File 'lib/puppet/pops/model/factory.rb', line 443
def build_TypeDefinition(o, name, parent, body)
b = f_build_body(body)
@i12n[KEY_BODY] = b unless b.nil?
@i12n['parent'] = parent
@i12n[KEY_NAME] = name
end
|
#build_TypeMapping(o, lhs, rhs) ⇒ Object
438
439
440
441
|
# File 'lib/puppet/pops/model/factory.rb', line 438
def build_TypeMapping(o, lhs, rhs)
@i12n['type_expr'] = lhs
@i12n['mapping_expr'] = rhs
end
|
#build_UnaryExpression(o, expr) ⇒ Object
450
451
452
|
# File 'lib/puppet/pops/model/factory.rb', line 450
def build_UnaryExpression(o, expr)
@i12n[KEY_EXPR] = expr unless Factory.nop?(expr)
end
|
#captures_rest ⇒ Object
Mark parameter as capturing the rest of arguments
699
700
701
|
# File 'lib/puppet/pops/model/factory.rb', line 699
def captures_rest
@i12n['captures_rest'] = true
end
|
#contained_current(container) ⇒ Object
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
|
# File 'lib/puppet/pops/model/factory.rb', line 1065
def contained_current(container)
if @current.nil?
unless @i12n.include?(KEY_LOCATOR)
@i12n[KEY_LOCATOR] = container[KEY_LOCATOR]
@i12n[KEY_OFFSET] = container[KEY_OFFSET] || 0
@i12n[KEY_LENGTH] = 0
end
@current = create_model
end
@current
end
|
#create_model ⇒ Object
74
75
76
77
|
# File 'lib/puppet/pops/model/factory.rb', line 74
def create_model
@i12n.each_pair { |key, elem| @i12n[key] = factory_to_model(elem) }
model_class.from_asserted_hash(@i12n)
end
|
#default(r) ⇒ Object
For CaseExpression, setting the default for an already build CaseExpression
561
562
563
564
|
# File 'lib/puppet/pops/model/factory.rb', line 561
def default(r)
@i12n['options'] << Factory.WHEN(Factory.infer(:default), r)
self
end
|
513
|
# File 'lib/puppet/pops/model/factory.rb', line 513
def dot r; f_build_binary(NamedAccessExpression, self, r); end
|
537
|
# File 'lib/puppet/pops/model/factory.rb', line 537
def eq r; f_comparison('==', r); end
|
#f_arithmetic(op, r) ⇒ Object
482
483
484
|
# File 'lib/puppet/pops/model/factory.rb', line 482
def f_arithmetic(op, r)
f_build_binary_op(ArithmeticExpression, op, self, r)
end
|
#f_build_binary(klazz, left, right) ⇒ Object
478
479
480
|
# File 'lib/puppet/pops/model/factory.rb', line 478
def f_build_binary(klazz, left, right)
Factory.new(klazz, left, right)
end
|
#f_build_binary_op(klazz, op, left, right) ⇒ Object
474
475
476
|
# File 'lib/puppet/pops/model/factory.rb', line 474
def f_build_binary_op(klazz, op, left, right)
Factory.new(klazz, op, left, right)
end
|
#f_build_body(body) ⇒ Object
315
316
317
318
319
320
321
322
323
324
325
326
|
# File 'lib/puppet/pops/model/factory.rb', line 315
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
470
471
472
|
# File 'lib/puppet/pops/model/factory.rb', line 470
def f_build_unary(klazz, expr)
Factory.new(klazz, expr)
end
|
#f_comparison(op, r) ⇒ Object
486
487
488
|
# File 'lib/puppet/pops/model/factory.rb', line 486
def f_comparison(op, r)
f_build_binary_op(ComparisonExpression, op, self, r)
end
|
#f_match(op, r) ⇒ Object
490
491
492
|
# File 'lib/puppet/pops/model/factory.rb', line 490
def f_match(op, r)
f_build_binary_op(MatchExpression, op, self, r)
end
|
#factory_to_model(value) ⇒ Object
1055
1056
1057
1058
1059
1060
1061
1062
1063
|
# File 'lib/puppet/pops/model/factory.rb', line 1055
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
|
495
|
# File 'lib/puppet/pops/model/factory.rb', line 495
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.
302
303
304
305
|
# File 'lib/puppet/pops/model/factory.rb', line 302
def infer_Array(o)
@model_class = LiteralList
@i12n['values'] = o.map { |e| Factory.infer(e) }
end
|
#infer_FalseClass(o) ⇒ Object
266
267
268
269
|
# File 'lib/puppet/pops/model/factory.rb', line 266
def infer_FalseClass(o)
@model_class = LiteralBoolean
@i12n[KEY_VALUE] = o
end
|
#infer_Float(o) ⇒ Object
276
277
278
279
|
# File 'lib/puppet/pops/model/factory.rb', line 276
def infer_Float(o)
@model_class = LiteralFloat
@i12n[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
271
272
273
274
|
# File 'lib/puppet/pops/model/factory.rb', line 271
def infer_Integer(o)
@model_class = LiteralInteger
@i12n[KEY_VALUE] = o
end
|
#infer_NilClass(o) ⇒ Object
257
258
259
|
# File 'lib/puppet/pops/model/factory.rb', line 257
def infer_NilClass(o)
@model_class = Nop
end
|
#infer_Regexp(o) ⇒ Object
281
282
283
284
285
|
# File 'lib/puppet/pops/model/factory.rb', line 281
def infer_Regexp(o)
@model_class = LiteralRegularExpression
@i12n['pattern'] = o.inspect
@i12n[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.
252
253
254
255
|
# File 'lib/puppet/pops/model/factory.rb', line 252
def infer_String(o)
@model_class = LiteralString
@i12n[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.
290
291
292
293
294
295
296
297
298
299
|
# File 'lib/puppet/pops/model/factory.rb', line 290
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
261
262
263
264
|
# File 'lib/puppet/pops/model/factory.rb', line 261
def infer_TrueClass(o)
@model_class = LiteralBoolean
@i12n[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 $
1000
1001
1002
1003
1004
1005
1006
|
# File 'lib/puppet/pops/model/factory.rb', line 1000
def interpolate_AccessExpression(c)
lhs = @i12n[KEY_LEFT_EXPR]
if is_interop_rewriteable?(lhs)
@i12n[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
1017
1018
1019
1020
1021
1022
1023
|
# File 'lib/puppet/pops/model/factory.rb', line 1017
def interpolate_CallMethodExpression(c)
functor_expr = @i12n['functor_expr']
if is_interop_rewriteable?(functor_expr)
@i12n['functor_expr'] = functor_expr.interpolate
end
self
end
|
#interpolate_Factory(c) ⇒ Object
979
980
981
|
# File 'lib/puppet/pops/model/factory.rb', line 979
def interpolate_Factory(c)
self
end
|
#interpolate_LiteralInteger(c) ⇒ Object
983
984
985
986
|
# File 'lib/puppet/pops/model/factory.rb', line 983
def interpolate_LiteralInteger(c)
self.var
end
|
#interpolate_NamedAccessExpression(c) ⇒ Object
1008
1009
1010
1011
1012
1013
1014
|
# File 'lib/puppet/pops/model/factory.rb', line 1008
def interpolate_NamedAccessExpression(c)
lhs = @i12n[KEY_LEFT_EXPR]
if is_interop_rewriteable?(lhs)
@i12n[KEY_LEFT_EXPR] = lhs.interpolate
end
self
end
|
#interpolate_Object(c) ⇒ Object
988
989
990
|
# File 'lib/puppet/pops/model/factory.rb', line 988
def interpolate_Object(c)
self
end
|
#interpolate_QualifiedName(c) ⇒ Object
992
993
994
|
# File 'lib/puppet/pops/model/factory.rb', line 992
def interpolate_QualifiedName(c)
self.var
end
|
#is_interop_rewriteable?(o) ⇒ Boolean
#lambda=(lambda) ⇒ Object
566
567
568
569
|
# File 'lib/puppet/pops/model/factory.rb', line 566
def lambda=(lambda)
@i12n['lambda'] = lambda
self
end
|
595
596
597
|
# File 'lib/puppet/pops/model/factory.rb', line 595
def length
@i12n[KEY_LENGTH]
end
|
503
|
# File 'lib/puppet/pops/model/factory.rb', line 503
def minus(); f_build_unary(UnaryMinusExpression, self); end
|
#minus_set(r) ⇒ Object
582
583
584
|
# File 'lib/puppet/pops/model/factory.rb', line 582
def minus_set(r)
f_build_binary_op(AssignmentExpression, '-=', self, r)
end
|
543
|
# File 'lib/puppet/pops/model/factory.rb', line 543
def mne r; f_match('!~', r); end
|
#model ⇒ Object
Also known as:
current
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/puppet/pops/model/factory.rb', line 55
def model
if @current.nil?
unless @i12n.include?(KEY_LOCATOR)
@i12n[KEY_LOCATOR] = Parser::Locator.locator('<no source>', 'no file')
unless @model_class <= Program
@i12n[KEY_OFFSET] = 0
@i12n[KEY_LENGTH] = 0
end
end
@current = create_model
end
@current
end
|
539
|
# File 'lib/puppet/pops/model/factory.rb', line 539
def ne r; f_comparison('!=', r); end
|
501
|
# File 'lib/puppet/pops/model/factory.rb', line 501
def not(); f_build_unary(NotExpression, self); end
|
591
592
593
|
# File 'lib/puppet/pops/model/factory.rb', line 591
def offset
@i12n[KEY_OFFSET]
end
|
497
|
# File 'lib/puppet/pops/model/factory.rb', line 497
def or(r) f_build_binary(OrExpression, self, r); end
|
545
|
# File 'lib/puppet/pops/model/factory.rb', line 545
def paren; f_build_unary(ParenthesizedExpression, self); end
|
#plus_set(r) ⇒ Object
577
578
579
|
# File 'lib/puppet/pops/model/factory.rb', line 577
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.
601
602
603
604
605
606
607
608
|
# File 'lib/puppet/pops/model/factory.rb', line 601
def record_position(locator, start_locatable, end_locatable)
start_offset = start_locatable.offset
@i12n[KEY_LOCATOR] = locator
@i12n[KEY_OFFSET] = start_offset
@i12n[KEY_LENGTH] = end_locatable.nil? ? start_locatable.length : end_locatable.offset + end_locatable.length - start_offset
self
end
|
#relop(op, r) ⇒ Object
547
548
549
|
# File 'lib/puppet/pops/model/factory.rb', line 547
def relop(op, r)
f_build_binary_op(RelationshipExpression, op, self, r)
end
|
572
573
574
|
# File 'lib/puppet/pops/model/factory.rb', line 572
def set(r)
f_build_binary_op(AssignmentExpression, '=', self, r)
end
|
507
|
# File 'lib/puppet/pops/model/factory.rb', line 507
def text(); f_build_unary(TextExpression, self); end
|
1051
1052
1053
|
# File 'lib/puppet/pops/model/factory.rb', line 1051
def to_s
"Factory for #{@model_class}"
end
|
#type_expr(o) ⇒ Object
Set Expression that should evaluate to the parameter’s type
704
705
706
|
# File 'lib/puppet/pops/model/factory.rb', line 704
def type_expr(o)
@i12n['type_expr'] = o
end
|
505
|
# File 'lib/puppet/pops/model/factory.rb', line 505
def unfold(); f_build_unary(UnfoldExpression, self); end
|
509
|
# File 'lib/puppet/pops/model/factory.rb', line 509
def var(); f_build_unary(VariableExpression, self); end
|