Class: Puppet::Pops::Model::Factory
- Inherits:
-
Object
- Object
- Puppet::Pops::Model::Factory
show all
- Defined in:
- lib/puppet/pops/model/factory.rb
Overview
TODO:
All those uppercase methods … they look bad in one way, but stand out nicely in the grammar… decide if they should change into lower case names (some of the are lower case)…
Factory is a helper class that makes construction of a Pops Model much more convenient. It can be viewed as a small internal DSL for model constructions. For usage see tests using the factory.
Defined Under Namespace
Classes: ArgsToNonCallError
Constant Summary
collapse
- Model =
Puppet::Pops::Model
- 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 }
- @@build_visitor =
Shared build_visitor, since there are many instances of Factory being used
Puppet::Pops::Visitor.new(self, "build")
- @@interpolation_visitor =
Puppet::Pops::Visitor.new(self, "interpolate")
Instance Attribute Summary collapse
Class Method Summary
collapse
-
.APPLICATION(name, parameters, body) ⇒ Object
-
.ATTR(name, type_expr = nil) ⇒ 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
-
.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
-
.ENUM(*args) ⇒ 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) ⇒ Object
-
.HASH(entries) ⇒ Object
-
.HEREDOC(name, expr) ⇒ Object
-
.HOSTCLASS(name, parameters, parent, body) ⇒ Object
-
.IF(test_e, then_e, else_e) ⇒ Object
-
.KEY_ENTRY(key, val) ⇒ Object
-
.LAMBDA(parameters, body) ⇒ Object
-
.LIST(entries) ⇒ Object
-
.literal(o) ⇒ Object
-
.MAP(match, value) ⇒ Object
-
.minus(o) ⇒ Object
-
.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
-
.record_position(o, start_locatable, end_locateable) ⇒ 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
-
.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) ⇒ Object
Transforms a left expression followed by an untitled resource (in the form of attribute_operations).
-
.TYPE(name, super_name = nil) ⇒ 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
-
#>>(r) ⇒ Object
-
#[](*r) ⇒ Object
-
#and(r) ⇒ Object
-
#attributes(*args) ⇒ Object
-
#build(o, *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_Array(o) ⇒ Object
Creates a LiteralList instruction from an Array, where the entries are built.
-
#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_Class(o, *args) ⇒ Object
Build a Class by creating an instance of it, and then calling build on the created instance with the given arguments.
-
#build_CollectExpression(o, type_expr, query_expr, attribute_operations) ⇒ Object
-
#build_ComparisonExpression(o, op, a, b) ⇒ Object
-
#build_ConcatenatedString(o, *args) ⇒ Object
-
#build_CreateAttributeExpression(o, name, datatype_expr) ⇒ Object
-
#build_CreateEnumExpression(o, *args) ⇒ Object
-
#build_CreateTypeExpression(o, name, super_name = nil) ⇒ Object
-
#build_EppExpression(o, parameters_specified, body) ⇒ Object
-
#build_Factory(o) ⇒ Object
If building a factory, simply unwrap the model oject contained in the factory.
-
#build_FalseClass(o) ⇒ Object
-
#build_Fixnum(o) ⇒ Object
-
#build_Float(o) ⇒ Object
-
#build_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.
-
#build_HeredocExpression(o, name, expr) ⇒ Object
-
#build_HostClassDefinition(o, name, parameters, parent_class_name, body) ⇒ Model::HostClassDefinition
Configured from the parameters.
-
#build_IfExpression(o, t, ift, els) ⇒ Object
-
#build_KeyedEntry(o, k, v) ⇒ Object
-
#build_LambdaExpression(o, parameters, body) ⇒ Object
-
#build_LiteralFloat(o, val) ⇒ Object
-
#build_LiteralHash(o, *keyed_entries) ⇒ Object
-
#build_LiteralInteger(o, val, radix) ⇒ Object
-
#build_LiteralList(o, *values) ⇒ Object
-
#build_MatchExpression(o, op, a, b) ⇒ Object
-
#build_NamedDefinition(o, name, parameters, body) ⇒ Object
-
#build_NilClass(o) ⇒ 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_Regexp(o) ⇒ 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_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.
-
#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_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.
-
#build_TokenValue(o) ⇒ Object
-
#build_TrueClass(o) ⇒ Object
-
#build_UnaryExpression(o, expr) ⇒ Object
-
#captures_rest ⇒ Object
Mark parameter as capturing the rest of arguments.
-
#default(r) ⇒ Object
For CaseExpression, setting the default for an already build CaseExpression.
-
#dot(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
Builds body :) from different kinds of input.
-
#f_build_unary(klazz, expr) ⇒ Object
Puppet::Pops::Model::Factory helpers.
-
#f_build_vararg(klazz, left, *arg) ⇒ Object
-
#f_comparison(op, r) ⇒ Object
-
#f_match(op, r) ⇒ Object
-
#in(r) ⇒ 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(o) ⇒ 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(o) ⇒ Object
Rewrite method calls on the form $… to $$x$x.each.
-
#interpolate_Factory(o) ⇒ Object
-
#interpolate_LiteralInteger(o) ⇒ Object
-
#interpolate_NamedAccessExpression(o) ⇒ Object
-
#interpolate_Object(o) ⇒ Object
-
#interpolate_QualifiedName(o) ⇒ Object
-
#is_interop_rewriteable?(o) ⇒ Boolean
-
#lambda=(lambda) ⇒ Object
-
#loc ⇒ Puppet::Pops::Adapters::SourcePosAdapter
With location information.
-
#method_missing(meth, *args, &block) ⇒ Object
Catch all delegation to current.
-
#minus ⇒ Object
-
#minus_set(r) ⇒ Object
-
#mne(r) ⇒ Object
-
#name_is_statement(name) ⇒ Object
Returns true if the given name is a “statement keyword” (require, include, contain, error, notice, info, debug.
-
#ne(r) ⇒ Object
-
#not ⇒ Object
-
#or(r) ⇒ Object
-
#paren ⇒ Object
-
#plus_set(r) ⇒ Object
-
#record_position(start_locatable, end_locatable) ⇒ Object
Records the position (start -> end) and computes the resulting length.
-
#relop(op, r) ⇒ Object
-
#respond_to?(meth, include_all = false) ⇒ Boolean
-
#select(*args) ⇒ Object
-
#set(r) ⇒ Object
-
#text ⇒ Object
-
#to_ops(o, *args) ⇒ Object
Checks if the object is already a model object, or build it.
-
#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
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/puppet/pops/model/factory.rb', line 23
def initialize o, *args
@current = case o
when Model::PopsObject
o
when Puppet::Pops::Model::Factory
o.current
else
build(o, *args)
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
Catch all delegation to current
494
495
496
497
498
499
500
|
# File 'lib/puppet/pops/model/factory.rb', line 494
def method_missing(meth, *args, &block)
if current.respond_to?(meth)
current.send(meth, *args, &block)
else
super
end
end
|
Instance Attribute Details
#current ⇒ Object
Also known as:
model
12
13
14
|
# File 'lib/puppet/pops/model/factory.rb', line 12
def current
@current
end
|
Class Method Details
.APPLICATION(name, parameters, body) ⇒ Object
788
789
790
|
# File 'lib/puppet/pops/model/factory.rb', line 788
def self.APPLICATION(name, parameters, body)
new(Model::Application, name, parameters, body)
end
|
.ATTR(name, type_expr = nil) ⇒ Object
594
|
# File 'lib/puppet/pops/model/factory.rb', line 594
def self.ATTR(name, type_expr=nil); new(Model::CreateAttributeExpression, name, type_expr); end
|
.ATTRIBUTE_OP(name, op, expr) ⇒ Object
720
721
722
|
# File 'lib/puppet/pops/model/factory.rb', line 720
def self.ATTRIBUTE_OP(name, op, expr)
new(Model::AttributeOperation, name, op, expr)
end
|
.ATTRIBUTES_OP(expr) ⇒ Object
724
725
726
|
# File 'lib/puppet/pops/model/factory.rb', line 724
def self.ATTRIBUTES_OP(expr)
new(Model::AttributesOperation, expr)
end
|
.block(*args) ⇒ Object
576
|
# File 'lib/puppet/pops/model/factory.rb', line 576
def self.block(*args); new(Model::BlockExpression, *args); end
|
.block_or_expression(*args) ⇒ Object
Builds a BlockExpression if args size > 1, else the single expression/value in args
768
769
770
771
772
773
774
|
# File 'lib/puppet/pops/model/factory.rb', line 768
def self.block_or_expression(*args)
if args.size > 1
new(Model::BlockExpression, *args)
else
new(args[0])
end
end
|
.CALL_METHOD(functor, argument_list) ⇒ Object
735
736
737
|
# File 'lib/puppet/pops/model/factory.rb', line 735
def self.CALL_METHOD(functor, argument_list)
new(Model::CallMethodExpression, functor, true, nil, *argument_list)
end
|
.CALL_NAMED(name, rval_required, argument_list) ⇒ Object
728
729
730
731
732
733
|
# File 'lib/puppet/pops/model/factory.rb', line 728
def self.CALL_NAMED(name, rval_required, argument_list)
unless name.kind_of?(Model::PopsObject)
name = Puppet::Pops::Model::Factory.fqn(name) unless name.is_a?(Puppet::Pops::Model::Factory)
end
new(Model::CallNamedFunctionExpression, name, rval_required, *argument_list)
end
|
.CAPABILITY_MAPPING(kind, component, cap_name, mappings) ⇒ Object
784
785
786
|
# File 'lib/puppet/pops/model/factory.rb', line 784
def self.CAPABILITY_MAPPING(kind, component, cap_name, mappings)
new(Model::CapabilityMapping, kind, component, cap_name, mappings)
end
|
.CASE(test_e, *options) ⇒ Object
586
|
# File 'lib/puppet/pops/model/factory.rb', line 586
def self.CASE(test_e,*options); new(Model::CaseExpression, test_e, *options); end
|
.COLLECT(type_expr, query_expr, attribute_operations) ⇒ Object
739
740
741
|
# File 'lib/puppet/pops/model/factory.rb', line 739
def self.COLLECT(type_expr, query_expr, attribute_operations)
new(Model::CollectExpression, type_expr, query_expr, attribute_operations)
end
|
.concat(*args) ⇒ Object
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
|
# File 'lib/puppet/pops/model/factory.rb', line 1077
def self.concat(*args)
new(args.map do |e|
e = e.current if e.is_a?(self)
case e
when Model::LiteralString
e.value
when String
e
else
raise ArgumentError, "can only concatenate strings, got #{e.class}"
end
end.join(''))
end
|
.DEFINITION(name, parameters, body) ⇒ Object
780
781
782
|
# File 'lib/puppet/pops/model/factory.rb', line 780
def self.DEFINITION(name, parameters, body)
new(Model::ResourceTypeDefinition, name, parameters, body)
end
|
.ENUM(*args) ⇒ Object
596
|
# File 'lib/puppet/pops/model/factory.rb', line 596
def self.ENUM(*args); new(Model::CreateEnumExpression, *args); end
|
.EPP(parameters, body) ⇒ Object
657
658
659
660
661
662
663
664
665
666
|
# File 'lib/puppet/pops/model/factory.rb', line 657
def self.EPP(parameters, body)
if parameters.nil?
params = []
parameters_specified = false
else
params = parameters
parameters_specified = true
end
LAMBDA(params, new(Model::EppExpression, parameters_specified, body))
end
|
.EXPORTED_QUERY(query_expr) ⇒ Object
716
717
718
|
# File 'lib/puppet/pops/model/factory.rb', line 716
def self.EXPORTED_QUERY(query_expr)
new(Model::ExportedQuery, query_expr)
end
|
Creates a QualifiedName representation of o, unless o already represents a QualifiedName in which case it is returned.
629
630
631
632
633
|
# File 'lib/puppet/pops/model/factory.rb', line 629
def self.fqn(o)
o = o.current if o.is_a?(Puppet::Pops::Model::Factory)
o = new(Model::QualifiedName, o) unless o.is_a? Model::QualifiedName
o
end
|
Creates a QualifiedName representation of o, unless o already represents a QualifiedName in which case it is returned.
638
639
640
641
642
|
# File 'lib/puppet/pops/model/factory.rb', line 638
def self.fqr(o)
o = o.current if o.is_a?(Puppet::Pops::Model::Factory)
o = new(Model::QualifiedReference, o) unless o.is_a? Model::QualifiedReference
o
end
|
.FUNCTION(name, parameters, body) ⇒ Object
792
793
794
|
# File 'lib/puppet/pops/model/factory.rb', line 792
def self.FUNCTION(name, parameters, body)
new(Model::FunctionDefinition, name, parameters, body)
end
|
.HASH(entries) ⇒ Object
600
|
# File 'lib/puppet/pops/model/factory.rb', line 600
def self.HASH(entries); new(Model::LiteralHash, *entries); end
|
.HEREDOC(name, expr) ⇒ Object
602
|
# File 'lib/puppet/pops/model/factory.rb', line 602
def self.HEREDOC(name, expr); new(Model::HeredocExpression, name, expr); end
|
.HOSTCLASS(name, parameters, parent, body) ⇒ Object
776
777
778
|
# File 'lib/puppet/pops/model/factory.rb', line 776
def self.HOSTCLASS(name, parameters, parent, body)
new(Model::HostClassDefinition, name, parameters, parent, body)
end
|
.IF(test_e, then_e, else_e) ⇒ Object
582
|
# File 'lib/puppet/pops/model/factory.rb', line 582
def self.IF(test_e,then_e,else_e); new(Model::IfExpression, test_e, then_e, else_e); end
|
.KEY_ENTRY(key, val) ⇒ Object
598
|
# File 'lib/puppet/pops/model/factory.rb', line 598
def self.KEY_ENTRY(key, val); new(Model::KeyedEntry, key, val); end
|
.LAMBDA(parameters, body) ⇒ Object
796
797
798
|
# File 'lib/puppet/pops/model/factory.rb', line 796
def self.LAMBDA(parameters, body)
new(Model::LambdaExpression, parameters, body)
end
|
.LIST(entries) ⇒ Object
606
|
# File 'lib/puppet/pops/model/factory.rb', line 606
def self.LIST(entries); new(Model::LiteralList, *entries); end
|
.literal(o) ⇒ Object
568
|
# File 'lib/puppet/pops/model/factory.rb', line 568
def self.literal(o); new(o); end
|
.MAP(match, value) ⇒ Object
590
|
# File 'lib/puppet/pops/model/factory.rb', line 590
def self.MAP(match, value); new(Model::SelectorEntry, match, value); end
|
570
|
# File 'lib/puppet/pops/model/factory.rb', line 570
def self.minus(o); new(o).minus; end
|
.NAMED_ACCESS(type_name, bodies) ⇒ Object
743
744
745
|
# File 'lib/puppet/pops/model/factory.rb', line 743
def self.NAMED_ACCESS(type_name, bodies)
new(Model::NamedAccessExpression, type_name, bodies)
end
|
.NODE(hosts, parent, body) ⇒ Object
610
|
# File 'lib/puppet/pops/model/factory.rb', line 610
def self.NODE(hosts, parent, body); new(Model::NodeDefinition, hosts, parent, body); end
|
.nop?(o) ⇒ Boolean
800
801
802
|
# File 'lib/puppet/pops/model/factory.rb', line 800
def self.nop? o
o.nil? || o.is_a?(Puppet::Pops::Model::Nop)
end
|
.NUMBER(name_or_numeric) ⇒ Object
679
680
681
682
683
684
685
686
687
688
689
690
691
|
# File 'lib/puppet/pops/model/factory.rb', line 679
def self.NUMBER(name_or_numeric)
if n_radix = Puppet::Pops::Utils.to_n_with_radix(name_or_numeric)
val, radix = n_radix
if val.is_a?(Float)
new(Model::LiteralFloat, val)
else
new(Model::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
608
|
# File 'lib/puppet/pops/model/factory.rb', line 608
def self.PARAM(name, expr=nil); new(Model::Parameter, name, expr); end
|
.PROGRAM(body, definitions, locator) ⇒ Object
763
764
765
|
# File 'lib/puppet/pops/model/factory.rb', line 763
def self.PROGRAM(body, definitions, locator)
new(Model::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.
675
676
677
|
# File 'lib/puppet/pops/model/factory.rb', line 675
def self.QNAME(name)
new(Model::QualifiedName, name)
end
|
.QNAME_OR_NUMBER(name) ⇒ Object
Convert input string to either a qualified name, a LiteralInteger with radix, or a LiteralFloat
695
696
697
698
699
700
701
702
703
704
705
706
|
# File 'lib/puppet/pops/model/factory.rb', line 695
def self.QNAME_OR_NUMBER(name)
if n_radix = Puppet::Pops::Utils.to_n_with_radix(name)
val, radix = n_radix
if val.is_a?(Float)
new(Model::LiteralFloat, val)
else
new(Model::LiteralInteger, val, radix)
end
else
new(Model::QualifiedName, name)
end
end
|
.QREF(name) ⇒ Object
708
709
710
|
# File 'lib/puppet/pops/model/factory.rb', line 708
def self.QREF(name)
new(Model::QualifiedReference, name)
end
|
.record_position(o, start_locatable, end_locateable) ⇒ Object
506
507
508
|
# File 'lib/puppet/pops/model/factory.rb', line 506
def self.record_position(o, start_locatable, end_locateable)
new(o).record_position(start_locatable, end_locateable)
end
|
.RENDER_EXPR(expr) ⇒ Object
653
654
655
|
# File 'lib/puppet/pops/model/factory.rb', line 653
def self.RENDER_EXPR(expr)
new(Model::RenderExpression, expr)
end
|
.RENDER_STRING(o) ⇒ Object
649
650
651
|
# File 'lib/puppet/pops/model/factory.rb', line 649
def self.RENDER_STRING(o)
new(Model::RenderStringExpression, o)
end
|
.RESERVED(name, future = false) ⇒ Object
668
669
670
|
# File 'lib/puppet/pops/model/factory.rb', line 668
def self.RESERVED(name, future=false)
new(Model::ReservedWord, name, future)
end
|
.RESOURCE(type_name, bodies) ⇒ Object
747
748
749
|
# File 'lib/puppet/pops/model/factory.rb', line 747
def self.RESOURCE(type_name, bodies)
new(Model::ResourceExpression, type_name, bodies)
end
|
.RESOURCE_BODY(resource_title, attribute_operations) ⇒ Object
759
760
761
|
# File 'lib/puppet/pops/model/factory.rb', line 759
def self.RESOURCE_BODY(resource_title, attribute_operations)
new(Model::ResourceBody, resource_title, attribute_operations)
end
|
.RESOURCE_DEFAULTS(type_name, attribute_operations) ⇒ Object
751
752
753
|
# File 'lib/puppet/pops/model/factory.rb', line 751
def self.RESOURCE_DEFAULTS(type_name, attribute_operations)
new(Model::ResourceDefaultsExpression, type_name, attribute_operations)
end
|
.RESOURCE_OVERRIDE(resource_ref, attribute_operations) ⇒ Object
755
756
757
|
# File 'lib/puppet/pops/model/factory.rb', line 755
def self.RESOURCE_OVERRIDE(resource_ref, attribute_operations)
new(Model::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
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
|
# File 'lib/puppet/pops/model/factory.rb', line 546
def self.resource_shape(expr)
expr = expr.current if expr.is_a?(Puppet::Pops::Model::Factory)
case expr
when Model::QualifiedName
:resource
when Model::QualifiedReference
:defaults
when Model::AccessExpression
if expr.left_expr.is_a?(Model::QualifiedReference) && expr.left_expr.value == 'resource' && expr.keys.size == 1
:defaults
else
:override
end
when 'class'
:class
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.
531
532
533
534
535
536
537
|
# File 'lib/puppet/pops/model/factory.rb', line 531
def self.set_resource_form(expr, form)
expr = expr.current if expr.is_a?(Puppet::Pops::Model::Factory)
return false unless expr.is_a?(Puppet::Pops::Model::AbstractResource)
expr.form = form
return true
end
|
.SITE(body) ⇒ Object
612
|
# File 'lib/puppet/pops/model/factory.rb', line 612
def self.SITE(body); new(Model::SiteDefinition, body); end
|
.string(*args) ⇒ Object
578
|
# File 'lib/puppet/pops/model/factory.rb', line 578
def self.string(*args); new(Model::ConcatenatedString, *args); end
|
.SUBLOCATE(token, expr) ⇒ Object
604
|
# File 'lib/puppet/pops/model/factory.rb', line 604
def self.SUBLOCATE(token, expr) new(Model::SubLocatedExpression, token, expr); end
|
.TEXT(expr) ⇒ Object
644
645
646
|
# File 'lib/puppet/pops/model/factory.rb', line 644
def self.TEXT(expr)
new(Model::TextExpression, new(expr).interpolate)
end
|
580
|
# File 'lib/puppet/pops/model/factory.rb', line 580
def self.text(o); new(o).text; end
|
Transforms an array of expressions containing literal name expressions to calls if followed by an expression, or expression list.
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
|
# File 'lib/puppet/pops/model/factory.rb', line 838
def self.transform_calls(expressions)
expressions.reduce([]) do |memo, expr|
expr = expr.current if expr.is_a?(Puppet::Pops::Model::Factory)
name = memo[-1]
if name.is_a?(Model::QualifiedName) && STATEMENT_CALLS[name.value]
if expr.is_a?(Array)
expr = expr.reject {|e| e.is_a?(Puppet::Pops::Parser::LexerSupport::TokenValue) }
else
expr = [expr]
end
the_call = Puppet::Pops::Model::Factory.CALL_NAMED(name, false, expr)
record_position(the_call, name, expr.is_a?(Array) ? expr[-1] : expr)
memo[-1] = the_call
if expr.is_a?(Model::CallNamedFunctionExpression)
expr.rval_required = true
end
elsif expr.is_a?(Array)
raise ArgsToNonCallError.new(expr, name)
else
memo << expr
if expr.is_a?(Model::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)
875
876
877
878
879
880
881
882
883
884
885
|
# File 'lib/puppet/pops/model/factory.rb', line 875
def self.transform_resource_wo_title(left, attribute_ops)
return nil unless attribute_ops.is_a? Array
return nil unless left.current.is_a?(Puppet::Pops::Model::QualifiedName)
keyed_entries = attribute_ops.map do |ao|
return nil if ao.operator == :'+>'
KEY_ENTRY(ao.attribute_name, ao.value_expr)
end
result = block_or_expression(*transform_calls([left, HASH(keyed_entries)]))
result
end
|
.TYPE(name, super_name = nil) ⇒ Object
592
|
# File 'lib/puppet/pops/model/factory.rb', line 592
def self.TYPE(name, super_name=nil); new(Model::CreateTypeExpression, name, super_name); end
|
.unfold(o) ⇒ Object
572
|
# File 'lib/puppet/pops/model/factory.rb', line 572
def self.unfold(o); new(o).unfold; end
|
.UNLESS(test_e, then_e, else_e) ⇒ Object
584
|
# File 'lib/puppet/pops/model/factory.rb', line 584
def self.UNLESS(test_e,then_e,else_e); new(Model::UnlessExpression, test_e, then_e, else_e); end
|
574
|
# File 'lib/puppet/pops/model/factory.rb', line 574
def self.var(o); new(o).var; end
|
.VIRTUAL_QUERY(query_expr) ⇒ Object
712
713
714
|
# File 'lib/puppet/pops/model/factory.rb', line 712
def self.VIRTUAL_QUERY(query_expr)
new(Model::VirtualQuery, query_expr)
end
|
.WHEN(values_list, block) ⇒ Object
588
|
# File 'lib/puppet/pops/model/factory.rb', line 588
def self.WHEN(values_list, block); new(Model::CaseOption, values_list, block); end
|
Instance Method Details
430
|
# File 'lib/puppet/pops/model/factory.rb', line 430
def % r; f_arithmetic(:%, r); end
|
428
|
# File 'lib/puppet/pops/model/factory.rb', line 428
def * r; f_arithmetic(:*, r); end
|
422
|
# File 'lib/puppet/pops/model/factory.rb', line 422
def + r; f_arithmetic(:+, r); end
|
424
|
# File 'lib/puppet/pops/model/factory.rb', line 424
def - r; f_arithmetic(:-, r); end
|
426
|
# File 'lib/puppet/pops/model/factory.rb', line 426
def / r; f_arithmetic(:/, r); end
|
436
|
# File 'lib/puppet/pops/model/factory.rb', line 436
def < r; f_comparison(:<, r); end
|
432
|
# File 'lib/puppet/pops/model/factory.rb', line 432
def << r; f_arithmetic(:<<, r); end
|
438
|
# File 'lib/puppet/pops/model/factory.rb', line 438
def <= r; f_comparison(:<=, r); end
|
444
|
# File 'lib/puppet/pops/model/factory.rb', line 444
def == r; f_comparison(:==, r); end
|
448
|
# File 'lib/puppet/pops/model/factory.rb', line 448
def =~ r; f_match(:'=~', r); end
|
440
|
# File 'lib/puppet/pops/model/factory.rb', line 440
def > r; f_comparison(:>, r); end
|
442
|
# File 'lib/puppet/pops/model/factory.rb', line 442
def >= r; f_comparison(:>=, r); end
|
434
|
# File 'lib/puppet/pops/model/factory.rb', line 434
def >> r; f_arithmetic(:>>, r); end
|
418
|
# File 'lib/puppet/pops/model/factory.rb', line 418
def [](*r); f_build_vararg(Model::AccessExpression, current, *r); end
|
406
|
# File 'lib/puppet/pops/model/factory.rb', line 406
def and(r) f_build_binary(Model::AndExpression, current, r); end
|
#attributes(*args) ⇒ Object
488
489
490
491
|
# File 'lib/puppet/pops/model/factory.rb', line 488
def attributes(*args)
args.each {|a| current.addAttributes(build(a)) }
self
end
|
#build(o, *args) ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/puppet/pops/model/factory.rb', line 35
def build(o, *args)
begin
@@build_visitor.visit_this(self, o, args)
rescue =>e
raise e
end
end
|
#build_AccessExpression(o, left, *keys) ⇒ Object
86
87
88
89
90
|
# File 'lib/puppet/pops/model/factory.rb', line 86
def build_AccessExpression(o, left, *keys)
o.left_expr = to_ops(left)
o.keys = keys.map {|expr| to_ops(expr) }
o
end
|
#build_Application(o, n, ps, body) ⇒ Object
Building of Model classes
56
57
58
59
60
61
62
|
# File 'lib/puppet/pops/model/factory.rb', line 56
def build_Application(o, n, ps, body)
o.name = n
ps.each { |p| o.addParameters(build(p)) }
b = f_build_body(body)
o.body = b.current if b
o
end
|
#build_ArithmeticExpression(o, op, a, b) ⇒ Object
64
65
66
67
|
# File 'lib/puppet/pops/model/factory.rb', line 64
def build_ArithmeticExpression(o, op, a, b)
o.operator = op
build_BinaryExpression(o, a, b)
end
|
#build_Array(o) ⇒ Object
Creates a LiteralList instruction from an Array, where the entries are built.
960
961
962
963
964
|
# File 'lib/puppet/pops/model/factory.rb', line 960
def build_Array(o)
x = Model::LiteralList.new
o.each { |v| x.addValues(build(v)) }
x
end
|
#build_AssignmentExpression(o, op, a, b) ⇒ Object
69
70
71
72
|
# File 'lib/puppet/pops/model/factory.rb', line 69
def build_AssignmentExpression(o, op, a, b)
o.operator = op
build_BinaryExpression(o, a, b)
end
|
#build_AttributeOperation(o, name, op, value) ⇒ Object
74
75
76
77
78
79
|
# File 'lib/puppet/pops/model/factory.rb', line 74
def build_AttributeOperation(o, name, op, value)
o.operator = op
o.attribute_name = name.to_s o.value_expr = build(value)
o
end
|
#build_AttributesOperation(o, value) ⇒ Object
81
82
83
84
|
# File 'lib/puppet/pops/model/factory.rb', line 81
def build_AttributesOperation(o, value)
o.expr = build(value)
o
end
|
#build_BinaryExpression(o, left, right) ⇒ Object
92
93
94
95
96
|
# File 'lib/puppet/pops/model/factory.rb', line 92
def build_BinaryExpression(o, left, right)
o.left_expr = to_ops(left)
o.right_expr = to_ops(right)
o
end
|
#build_BlockExpression(o, *args) ⇒ Object
98
99
100
101
|
# File 'lib/puppet/pops/model/factory.rb', line 98
def build_BlockExpression(o, *args)
o.statements = args.map {|expr| to_ops(expr) }
o
end
|
#build_CallExpression(o, functor, rval_required, *args) ⇒ Object
976
977
978
979
980
981
|
# File 'lib/puppet/pops/model/factory.rb', line 976
def build_CallExpression(o, functor, rval_required, *args)
o.functor_expr = to_ops(functor)
o.rval_required = rval_required
args.each {|x| o.addArguments(to_ops(x)) }
o
end
|
#build_CallMethodExpression(o, functor, rval_required, lambda, *args) ⇒ Object
983
984
985
986
987
|
# File 'lib/puppet/pops/model/factory.rb', line 983
def build_CallMethodExpression(o, functor, rval_required, lambda, *args)
build_CallExpression(o, functor, rval_required, *args)
o.lambda = lambda
o
end
|
#build_CapabilityMapping(o, kind, component, capability, mappings) ⇒ Object
242
243
244
245
246
247
248
249
|
# File 'lib/puppet/pops/model/factory.rb', line 242
def build_CapabilityMapping(o, kind, component, capability, mappings)
o.kind = kind
component = component.current if component.is_a?(Puppet::Pops::Model::Factory)
o.component = component
o.capability = capability
o.mappings = mappings.map { |m| build(m) }
o
end
|
#build_CaseExpression(o, test, *args) ⇒ Object
989
990
991
992
993
|
# File 'lib/puppet/pops/model/factory.rb', line 989
def build_CaseExpression(o, test, *args)
o.test = build(test)
args.each {|opt| o.addOptions(build(opt)) }
o
end
|
#build_CaseOption(o, value_list, then_expr) ⇒ Object
995
996
997
998
999
1000
1001
|
# File 'lib/puppet/pops/model/factory.rb', line 995
def build_CaseOption(o, value_list, then_expr)
value_list = [value_list] unless value_list.is_a? Array
value_list.each { |v| o.addValues(build(v)) }
b = f_build_body(then_expr)
o.then_expr = to_ops(b) if b
o
end
|
#build_Class(o, *args) ⇒ Object
Build a Class by creating an instance of it, and then calling build on the created instance with the given arguments
1005
1006
1007
|
# File 'lib/puppet/pops/model/factory.rb', line 1005
def build_Class(o, *args)
build(o.new(), *args)
end
|
#build_CollectExpression(o, type_expr, query_expr, attribute_operations) ⇒ Object
103
104
105
106
107
108
|
# File 'lib/puppet/pops/model/factory.rb', line 103
def build_CollectExpression(o, type_expr, query_expr, attribute_operations)
o.type_expr = to_ops(type_expr)
o.query = build(query_expr)
o.operations = attribute_operations.map {|op| build(op) }
o
end
|
#build_ComparisonExpression(o, op, a, b) ⇒ Object
110
111
112
113
|
# File 'lib/puppet/pops/model/factory.rb', line 110
def build_ComparisonExpression(o, op, a, b)
o.operator = op
build_BinaryExpression(o, a, b)
end
|
#build_ConcatenatedString(o, *args) ⇒ Object
115
116
117
118
|
# File 'lib/puppet/pops/model/factory.rb', line 115
def build_ConcatenatedString(o, *args)
o.segments = args.map {|expr| build(expr) }
o
end
|
#build_CreateAttributeExpression(o, name, datatype_expr) ⇒ Object
132
133
134
135
136
|
# File 'lib/puppet/pops/model/factory.rb', line 132
def build_CreateAttributeExpression(o, name, datatype_expr)
o.name = name
o.type = to_ops(datatype_expr)
o
end
|
#build_CreateEnumExpression(o, *args) ⇒ Object
126
127
128
129
130
|
# File 'lib/puppet/pops/model/factory.rb', line 126
def build_CreateEnumExpression(o, *args)
o.name = args.slice(0) if args.size == 2
o.values = build(args.last)
o
end
|
#build_CreateTypeExpression(o, name, super_name = nil) ⇒ Object
120
121
122
123
124
|
# File 'lib/puppet/pops/model/factory.rb', line 120
def build_CreateTypeExpression(o, name, super_name = nil)
o.name = name
o.super_name = super_name
o
end
|
#build_EppExpression(o, parameters_specified, body) ⇒ Object
933
934
935
936
937
938
|
# File 'lib/puppet/pops/model/factory.rb', line 933
def build_EppExpression(o, parameters_specified, body)
o.parameters_specified = parameters_specified
b = f_build_body(body)
o.body = b.current if b
o
end
|
#build_Factory(o) ⇒ Object
If building a factory, simply unwrap the model oject contained in the factory.
941
942
943
|
# File 'lib/puppet/pops/model/factory.rb', line 941
def build_Factory(o)
o.current
end
|
#build_FalseClass(o) ⇒ Object
909
910
911
912
913
|
# File 'lib/puppet/pops/model/factory.rb', line 909
def build_FalseClass(o)
x = Model::LiteralBoolean.new
x.value = o
x
end
|
#build_Fixnum(o) ⇒ Object
915
916
917
918
919
|
# File 'lib/puppet/pops/model/factory.rb', line 915
def build_Fixnum(o)
x = Model::LiteralInteger.new
x.value = o;
x
end
|
#build_Float(o) ⇒ Object
921
922
923
924
925
|
# File 'lib/puppet/pops/model/factory.rb', line 921
def build_Float(o)
x = Model::LiteralFloat.new
x.value = o;
x
end
|
#build_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
969
970
971
972
973
|
# File 'lib/puppet/pops/model/factory.rb', line 969
def build_Hash(o)
x = Model::LiteralHash.new
(o.sort_by {|k,v| k.to_s}).each {|k,v| x.addEntries(build(Model::KeyedEntry.new, k, v)) }
x
end
|
#build_HeredocExpression(o, name, expr) ⇒ Object
138
139
140
141
142
|
# File 'lib/puppet/pops/model/factory.rb', line 138
def build_HeredocExpression(o, name, expr)
o.syntax = name
o.text_expr = build(expr)
o
end
|
#build_HostClassDefinition(o, name, parameters, parent_class_name, body) ⇒ Model::HostClassDefinition
Returns configured from the parameters.
150
151
152
153
154
|
# File 'lib/puppet/pops/model/factory.rb', line 150
def build_HostClassDefinition(o, name, parameters, parent_class_name, body)
build_NamedDefinition(o, name, parameters, body)
o.parent_class = parent_class_name if parent_class_name
o
end
|
#build_IfExpression(o, t, ift, els) ⇒ Object
195
196
197
198
199
200
|
# File 'lib/puppet/pops/model/factory.rb', line 195
def build_IfExpression(o, t, ift, els)
o.test = build(t)
o.then_expr = build(ift)
o.else_expr= build(els)
o
end
|
#build_KeyedEntry(o, k, v) ⇒ Object
168
169
170
171
172
|
# File 'lib/puppet/pops/model/factory.rb', line 168
def build_KeyedEntry(o, k, v)
o.key = to_ops(k)
o.value = to_ops(v)
o
end
|
#build_LambdaExpression(o, parameters, body) ⇒ Object
227
228
229
230
231
232
|
# File 'lib/puppet/pops/model/factory.rb', line 227
def build_LambdaExpression(o, parameters, body)
o.parameters = parameters.map {|p| build(p) }
b = f_build_body(body)
o.body = to_ops(b) if b
o
end
|
#build_LiteralFloat(o, val) ⇒ Object
184
185
186
187
|
# File 'lib/puppet/pops/model/factory.rb', line 184
def build_LiteralFloat(o, val)
o.value = val
o
end
|
#build_LiteralHash(o, *keyed_entries) ⇒ Object
174
175
176
177
|
# File 'lib/puppet/pops/model/factory.rb', line 174
def build_LiteralHash(o, *keyed_entries)
o.entries = keyed_entries.map {|entry| build(entry) }
o
end
|
#build_LiteralInteger(o, val, radix) ⇒ Object
189
190
191
192
193
|
# File 'lib/puppet/pops/model/factory.rb', line 189
def build_LiteralInteger(o, val, radix)
o.value = val
o.radix = radix
o
end
|
#build_LiteralList(o, *values) ⇒ Object
179
180
181
182
|
# File 'lib/puppet/pops/model/factory.rb', line 179
def build_LiteralList(o, *values)
o.values = values.map {|v| build(v) }
o
end
|
#build_MatchExpression(o, op, a, b) ⇒ Object
202
203
204
205
|
# File 'lib/puppet/pops/model/factory.rb', line 202
def build_MatchExpression(o, op, a, b)
o.operator = op
build_BinaryExpression(o, a, b)
end
|
#build_NamedDefinition(o, name, parameters, body) ⇒ Object
234
235
236
237
238
239
240
|
# File 'lib/puppet/pops/model/factory.rb', line 234
def build_NamedDefinition(o, name, parameters, body)
o.parameters = parameters.map {|p| build(p) }
b = f_build_body(body)
o.body = b.current if b
o.name = name
o
end
|
#build_NilClass(o) ⇒ Object
898
899
900
901
|
# File 'lib/puppet/pops/model/factory.rb', line 898
def build_NilClass(o)
x = Model::Nop.new
x
end
|
#build_NodeDefinition(o, hosts, parent, body) ⇒ Object
255
256
257
258
259
260
261
|
# File 'lib/puppet/pops/model/factory.rb', line 255
def build_NodeDefinition(o, hosts, parent, body)
o.host_matches = hosts.map {|h| build(h) }
o.parent = build(parent) if parent b = f_build_body(body)
o.body = b.current if b
o
end
|
#build_Parameter(o, name, expr) ⇒ Object
271
272
273
274
275
|
# File 'lib/puppet/pops/model/factory.rb', line 271
def build_Parameter(o, name, expr)
o.name = name
o.value = build(expr) if expr o
end
|
#build_Program(o, body, definitions, locator) ⇒ Object
352
353
354
355
356
357
358
359
360
361
|
# File 'lib/puppet/pops/model/factory.rb', line 352
def build_Program(o, body, definitions, locator)
o.body = to_ops(body)
o.definitions = definitions
o.source_ref = locator.file
o.source_text = locator.string
o.line_offsets = locator.line_index
o.locator = locator
o
end
|
#build_QualifiedName(o, name) ⇒ Object
363
364
365
366
|
# File 'lib/puppet/pops/model/factory.rb', line 363
def build_QualifiedName(o, name)
o.value = name.to_s
o
end
|
#build_QualifiedReference(o, name) ⇒ Object
277
278
279
280
|
# File 'lib/puppet/pops/model/factory.rb', line 277
def build_QualifiedReference(o, name)
o.value = name.to_s.downcase
o
end
|
#build_QueryExpression(o, expr) ⇒ Object
340
341
342
343
344
|
# File 'lib/puppet/pops/model/factory.rb', line 340
def build_QueryExpression(o, expr)
ops = to_ops(expr)
o.expr = ops unless Puppet::Pops::Model::Factory.nop? ops
o
end
|
#build_Regexp(o) ⇒ Object
927
928
929
930
931
|
# File 'lib/puppet/pops/model/factory.rb', line 927
def build_Regexp(o)
x = Model::LiteralRegularExpression.new
x.value = o;
x
end
|
#build_RelationshipExpression(o, op, a, b) ⇒ Object
282
283
284
285
|
# File 'lib/puppet/pops/model/factory.rb', line 282
def build_RelationshipExpression(o, op, a, b)
o.operator = op
build_BinaryExpression(o, a, b)
end
|
#build_RenderStringExpression(o, string) ⇒ Object
293
294
295
296
|
# File 'lib/puppet/pops/model/factory.rb', line 293
def build_RenderStringExpression(o, string)
o.value = string;
o
end
|
#build_ReservedWord(o, name, future) ⇒ Object
162
163
164
165
166
|
# File 'lib/puppet/pops/model/factory.rb', line 162
def build_ReservedWord(o, name, future)
o.word = name
o.future = future
o
end
|
#build_ResourceBody(o, title_expression, attribute_operations) ⇒ Object
298
299
300
301
302
|
# File 'lib/puppet/pops/model/factory.rb', line 298
def build_ResourceBody(o, title_expression, attribute_operations)
o.title = build(title_expression)
o.operations = attribute_operations.map {|ao| build(ao) }
o
end
|
#build_ResourceDefaultsExpression(o, type_ref, attribute_operations) ⇒ Object
304
305
306
307
308
|
# File 'lib/puppet/pops/model/factory.rb', line 304
def build_ResourceDefaultsExpression(o, type_ref, attribute_operations)
o.type_ref = build(type_ref)
o.operations = attribute_operations.map {|ao| build(ao) }
o
end
|
#build_ResourceExpression(o, type_name, bodies) ⇒ Object
287
288
289
290
291
|
# File 'lib/puppet/pops/model/factory.rb', line 287
def build_ResourceExpression(o, type_name, bodies)
o.type_name = build(type_name)
o.bodies = bodies.map {|b| build(b) }
o
end
|
#build_ResourceOverrideExpression(o, resources, attribute_operations) ⇒ Object
156
157
158
159
160
|
# File 'lib/puppet/pops/model/factory.rb', line 156
def build_ResourceOverrideExpression(o, resources, attribute_operations)
o.resources = build(resources)
o.operations = attribute_operations.map {|ao| build(ao) }
o
end
|
#build_SelectorEntry(o, matching, value) ⇒ Object
334
335
336
337
338
|
# File 'lib/puppet/pops/model/factory.rb', line 334
def build_SelectorEntry(o, matching, value)
o.matching_expr = build(matching)
o.value_expr = build(value)
o
end
|
#build_SelectorExpression(o, left, *selectors) ⇒ Object
310
311
312
313
314
|
# File 'lib/puppet/pops/model/factory.rb', line 310
def build_SelectorExpression(o, left, *selectors)
o.left_expr = to_ops(left)
o.selectors = selectors.map {|s| build(s) }
o
end
|
#build_SiteDefinition(o, body) ⇒ Object
265
266
267
268
269
|
# File 'lib/puppet/pops/model/factory.rb', line 265
def build_SiteDefinition(o, body)
b = f_build_body(body)
o.body = b.current if b
o
end
|
#build_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.
892
893
894
895
896
|
# File 'lib/puppet/pops/model/factory.rb', line 892
def build_String(o)
x = Model::LiteralString.new
x.value = o;
x
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.
321
322
323
324
325
326
327
328
329
330
331
332
|
# File 'lib/puppet/pops/model/factory.rb', line 321
def build_SubLocatedExpression(o, token, expression)
o.expr = build(expression)
o.offset = token.offset
o.length = token.length
locator = token.locator
o.locator = locator
o.leading_line_count = locator.leading_line_count
o.leading_line_offset = locator.leading_line_offset
o.line_offsets = locator.locator.line_index
o
end
|
#build_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.
948
949
950
951
952
953
954
955
956
957
|
# File 'lib/puppet/pops/model/factory.rb', line 948
def build_Symbol(o)
case o
when :undef
Model::LiteralUndef.new
when :default
Model::LiteralDefault.new
else
build_String(o.to_s)
end
end
|
#build_TokenValue(o) ⇒ Object
368
369
370
|
# File 'lib/puppet/pops/model/factory.rb', line 368
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_TrueClass(o) ⇒ Object
903
904
905
906
907
|
# File 'lib/puppet/pops/model/factory.rb', line 903
def build_TrueClass(o)
x = Model::LiteralBoolean.new
x.value = o
x
end
|
#build_UnaryExpression(o, expr) ⇒ Object
346
347
348
349
350
|
# File 'lib/puppet/pops/model/factory.rb', line 346
def build_UnaryExpression(o, expr)
ops = to_ops(expr)
o.expr = ops unless Puppet::Pops::Model::Factory.nop? ops
o
end
|
#captures_rest ⇒ Object
Mark parameter as capturing the rest of arguments
617
618
619
|
# File 'lib/puppet/pops/model/factory.rb', line 617
def captures_rest()
current.captures_rest = true
end
|
#default(r) ⇒ Object
For CaseExpression, setting the default for an already build CaseExpression
463
464
465
466
|
# File 'lib/puppet/pops/model/factory.rb', line 463
def default r
current.addOptions(Puppet::Pops::Model::Factory.WHEN(:default, r).current)
self
end
|
420
|
# File 'lib/puppet/pops/model/factory.rb', line 420
def dot r; f_build_binary(Model::NamedAccessExpression, current, r); end
|
#f_arithmetic(op, r) ⇒ Object
389
390
391
|
# File 'lib/puppet/pops/model/factory.rb', line 389
def f_arithmetic(op, r)
f_build_binary_op(Model::ArithmeticExpression, op, current, r)
end
|
#f_build_binary(klazz, left, right) ⇒ Object
381
382
383
|
# File 'lib/puppet/pops/model/factory.rb', line 381
def f_build_binary(klazz, left, right)
Puppet::Pops::Model::Factory.new(build(klazz.new, left, right))
end
|
#f_build_binary_op(klazz, op, left, right) ⇒ Object
377
378
379
|
# File 'lib/puppet/pops/model/factory.rb', line 377
def f_build_binary_op(klazz, op, left, right)
Puppet::Pops::Model::Factory.new(build(klazz.new, op, left, right))
end
|
#f_build_body(nothing) ⇒ Object
#f_build_body(array) ⇒ Object
#f_build_body(expr) ⇒ Object
#f_build_body(obj) ⇒ Object
Builds body :) from different kinds of input
216
217
218
219
220
221
222
223
224
225
|
# File 'lib/puppet/pops/model/factory.rb', line 216
def f_build_body(body)
case body
when NilClass
nil
when Array
Puppet::Pops::Model::Factory.new(Model::BlockExpression, *body)
else
build(body)
end
end
|
#f_build_unary(klazz, expr) ⇒ Object
Puppet::Pops::Model::Factory helpers
373
374
375
|
# File 'lib/puppet/pops/model/factory.rb', line 373
def f_build_unary(klazz, expr)
Puppet::Pops::Model::Factory.new(build(klazz.new, expr))
end
|
#f_build_vararg(klazz, left, *arg) ⇒ Object
385
386
387
|
# File 'lib/puppet/pops/model/factory.rb', line 385
def f_build_vararg(klazz, left, *arg)
Puppet::Pops::Model::Factory.new(build(klazz.new, left, *arg))
end
|
#f_comparison(op, r) ⇒ Object
393
394
395
|
# File 'lib/puppet/pops/model/factory.rb', line 393
def f_comparison(op, r)
f_build_binary_op(Model::ComparisonExpression, op, current, r)
end
|
#f_match(op, r) ⇒ Object
397
398
399
|
# File 'lib/puppet/pops/model/factory.rb', line 397
def f_match(op, r)
f_build_binary_op(Model::MatchExpression, op, current, r)
end
|
402
|
# File 'lib/puppet/pops/model/factory.rb', line 402
def in(r) f_build_binary(Model::InExpression, current, r); end
|
#interpolate ⇒ Object
45
46
47
48
49
50
51
52
|
# File 'lib/puppet/pops/model/factory.rb', line 45
def interpolate()
begin
@@interpolation_visitor.visit_this_0(self, current)
rescue =>e
raise e
end
end
|
#interpolate_AccessExpression(o) ⇒ 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 $
1030
1031
1032
1033
1034
1035
|
# File 'lib/puppet/pops/model/factory.rb', line 1030
def interpolate_AccessExpression(o)
if is_interop_rewriteable?(o.left_expr)
o.left_expr = to_ops(self.class.new(o.left_expr).interpolate)
end
o
end
|
#interpolate_CallMethodExpression(o) ⇒ Object
Rewrite method calls on the form $… to $Puppet::Pops::Model::Factory.$x$x.each
1045
1046
1047
1048
1049
1050
|
# File 'lib/puppet/pops/model/factory.rb', line 1045
def interpolate_CallMethodExpression(o)
if is_interop_rewriteable?(o.functor_expr)
o.functor_expr = to_ops(self.class.new(o.functor_expr).interpolate)
end
o
end
|
#interpolate_Factory(o) ⇒ Object
1009
1010
1011
|
# File 'lib/puppet/pops/model/factory.rb', line 1009
def interpolate_Factory(o)
interpolate(o.current)
end
|
#interpolate_LiteralInteger(o) ⇒ Object
1013
1014
1015
1016
|
# File 'lib/puppet/pops/model/factory.rb', line 1013
def interpolate_LiteralInteger(o)
self.class.new(o).var
end
|
#interpolate_NamedAccessExpression(o) ⇒ Object
1037
1038
1039
1040
1041
1042
|
# File 'lib/puppet/pops/model/factory.rb', line 1037
def interpolate_NamedAccessExpression(o)
if is_interop_rewriteable?(o.left_expr)
o.left_expr = to_ops(self.class.new(o.left_expr).interpolate)
end
o
end
|
#interpolate_Object(o) ⇒ Object
1018
1019
1020
|
# File 'lib/puppet/pops/model/factory.rb', line 1018
def interpolate_Object(o)
o
end
|
#interpolate_QualifiedName(o) ⇒ Object
1022
1023
1024
|
# File 'lib/puppet/pops/model/factory.rb', line 1022
def interpolate_QualifiedName(o)
self.class.new(o).var
end
|
#is_interop_rewriteable?(o) ⇒ Boolean
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
|
# File 'lib/puppet/pops/model/factory.rb', line 1052
def is_interop_rewriteable?(o)
case o
when Model::AccessExpression, Model::QualifiedName,
Model::NamedAccessExpression, Model::CallMethodExpression
true
when Model::LiteralInteger
o.radix == 10
else
false
end
end
|
#lambda=(lambda) ⇒ Object
468
469
470
471
|
# File 'lib/puppet/pops/model/factory.rb', line 468
def lambda=(lambda)
current.lambda = lambda.current
self
end
|
Returns with location information.
410
|
# File 'lib/puppet/pops/model/factory.rb', line 410
def minus(); f_build_unary(Model::UnaryMinusExpression, self); end
|
#minus_set(r) ⇒ Object
484
485
486
|
# File 'lib/puppet/pops/model/factory.rb', line 484
def minus_set(r)
f_build_binary_op(Model::AssignmentExpression, :'-=', current, r)
end
|
450
|
# File 'lib/puppet/pops/model/factory.rb', line 450
def mne r; f_match(:'!~', r); end
|
#name_is_statement(name) ⇒ Object
Returns true if the given name is a “statement keyword” (require, include, contain, error, notice, info, debug
823
824
825
|
# File 'lib/puppet/pops/model/factory.rb', line 823
def name_is_statement(name)
STATEMENT_CALLS[name]
end
|
446
|
# File 'lib/puppet/pops/model/factory.rb', line 446
def ne r; f_comparison(:'!=', r); end
|
408
|
# File 'lib/puppet/pops/model/factory.rb', line 408
def not(); f_build_unary(Model::NotExpression, self); end
|
404
|
# File 'lib/puppet/pops/model/factory.rb', line 404
def or(r) f_build_binary(Model::OrExpression, current, r); end
|
452
|
# File 'lib/puppet/pops/model/factory.rb', line 452
def paren(); f_build_unary(Model::ParenthesizedExpression, current); end
|
#plus_set(r) ⇒ Object
479
480
481
|
# File 'lib/puppet/pops/model/factory.rb', line 479
def plus_set(r)
f_build_binary_op(Model::AssignmentExpression, :'+=', current, r)
end
|
#record_position(start_locatable, end_locatable) ⇒ Object
Records the position (start -> end) and computes the resulting length.
512
513
514
515
516
517
518
519
520
521
|
# File 'lib/puppet/pops/model/factory.rb', line 512
def record_position(start_locatable, end_locatable)
from = start_locatable.is_a?(Puppet::Pops::Model::Factory) ? start_locatable.current : start_locatable
to = end_locatable.is_a?(Puppet::Pops::Model::Factory) ? end_locatable.current : end_locatable
to = from if to.nil? || to.offset.nil?
o = current
o.offset = from.offset
o.length ||= to.offset - from.offset + to.length
self
end
|
#relop(op, r) ⇒ Object
454
455
456
|
# File 'lib/puppet/pops/model/factory.rb', line 454
def relop op, r
f_build_binary_op(Model::RelationshipExpression, op.to_sym, current, r)
end
|
#respond_to?(meth, include_all = false) ⇒ Boolean
502
503
504
|
# File 'lib/puppet/pops/model/factory.rb', line 502
def respond_to?(meth, include_all=false)
current.respond_to?(meth, include_all) || super
end
|
#select(*args) ⇒ Object
458
459
460
|
# File 'lib/puppet/pops/model/factory.rb', line 458
def select *args
Puppet::Pops::Model::Factory.new(build(Model::SelectorExpression, current, *args))
end
|
474
475
476
|
# File 'lib/puppet/pops/model/factory.rb', line 474
def set(r)
f_build_binary_op(Model::AssignmentExpression, :'=', current, r)
end
|
414
|
# File 'lib/puppet/pops/model/factory.rb', line 414
def text(); f_build_unary(Model::TextExpression, self); end
|
#to_ops(o, *args) ⇒ Object
Checks if the object is already a model object, or build it
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
|
# File 'lib/puppet/pops/model/factory.rb', line 1066
def to_ops(o, *args)
case o
when Model::PopsObject
o
when Puppet::Pops::Model::Factory
o.current
else
build(o, *args)
end
end
|
#type_expr(o) ⇒ Object
Set Expression that should evaluate to the parameter’s type
622
623
624
|
# File 'lib/puppet/pops/model/factory.rb', line 622
def type_expr(o)
current.type_expr = to_ops(o)
end
|
412
|
# File 'lib/puppet/pops/model/factory.rb', line 412
def unfold(); f_build_unary(Model::UnfoldExpression, self); end
|
416
|
# File 'lib/puppet/pops/model/factory.rb', line 416
def var(); f_build_unary(Model::VariableExpression, self); end
|