class Puppet::Pops::Model::Factory

Constants

BUILD_VISITOR
INFER_VISITOR
INTERPOLATION_VISITOR
KEY_BODY
KEY_EXPR
KEY_KEYS
KEY_LEFT_EXPR
KEY_LENGTH

Shared build_visitor, since there are many instances of Factory being used

KEY_LOCATOR
KEY_NAME
KEY_OFFSET
KEY_OPERATOR
KEY_PARAMETERS
KEY_RIGHT_EXPR
KEY_VALUE
MAPOFFSET_VISITOR
STATEMENT_CALLS

Attributes

model_class[R]
unfolded[R]

Public Class Methods

APPLY(arguments, body) click to toggle source
    # File lib/puppet/pops/model/factory.rb
936 def self.APPLY(arguments, body)
937   new(ApplyExpression, arguments, body)
938 end
APPLY_BLOCK(statements) click to toggle source
    # File lib/puppet/pops/model/factory.rb
940 def self.APPLY_BLOCK(statements)
941   new(ApplyBlockExpression, statements)
942 end
ARGUMENTS(args, arg) click to toggle source
    # File lib/puppet/pops/model/factory.rb
845 def self.ARGUMENTS(args, arg)
846   if !args.empty? && arg.model_class <= LiteralHash && arg.unfolded
847     last = args[args.size() - 1]
848     if last.model_class <= LiteralHash && last.unfolded
849       last['entries'].concat(arg['entries'])
850       return args
851     end
852   end
853   args.push(arg)
854 end
ATTRIBUTES_OP(expr) click to toggle source
    # File lib/puppet/pops/model/factory.rb
860 def self.ATTRIBUTES_OP(expr)
861   new(AttributesOperation, expr)
862 end
ATTRIBUTE_OP(name, op, expr) click to toggle source
    # File lib/puppet/pops/model/factory.rb
856 def self.ATTRIBUTE_OP(name, op, expr)
857   new(AttributeOperation, name, op, expr)
858 end
CALL_METHOD(functor, argument_list) click to toggle source
    # File lib/puppet/pops/model/factory.rb
873 def self.CALL_METHOD(functor, argument_list)
874   new(CallMethodExpression, functor, true, nil, argument_list)
875 end
CALL_NAMED(name, rval_required, argument_list) click to toggle source
    # File lib/puppet/pops/model/factory.rb
869 def self.CALL_NAMED(name, rval_required, argument_list)
870   new(CallNamedFunctionExpression, name, rval_required, argument_list)
871 end
CASE(test_e,*options) click to toggle source
    # File lib/puppet/pops/model/factory.rb
704 def self.CASE(test_e,*options);        new(CaseExpression, test_e, options);           end
COLLECT(type_expr, query_expr, attribute_operations) click to toggle source
    # File lib/puppet/pops/model/factory.rb
877 def self.COLLECT(type_expr, query_expr, attribute_operations)
878   new(CollectExpression, type_expr, query_expr, attribute_operations)
879 end
DEFINITION(name, parameters, body) click to toggle source
    # File lib/puppet/pops/model/factory.rb
928 def self.DEFINITION(name, parameters, body)
929   new(ResourceTypeDefinition, name, parameters, body)
930 end
EPP(parameters, body) click to toggle source
    # File lib/puppet/pops/model/factory.rb
778 def self.EPP(parameters, body)
779   if parameters.nil?
780     params = []
781     parameters_specified = false
782   else
783     params = parameters
784     parameters_specified = true
785   end
786   LAMBDA(params, new(EppExpression, parameters_specified, body), nil)
787 end
EXPORTED_QUERY(query_expr) click to toggle source
    # File lib/puppet/pops/model/factory.rb
841 def self.EXPORTED_QUERY(query_expr)
842   new(ExportedQuery, query_expr)
843 end
FUNCTION(name, parameters, body, return_type) click to toggle source
    # File lib/puppet/pops/model/factory.rb
944 def self.FUNCTION(name, parameters, body, return_type)
945   new(FunctionDefinition, name, parameters, body, return_type)
946 end
HASH(entries) click to toggle source
    # File lib/puppet/pops/model/factory.rb
712 def self.HASH(entries);                new(LiteralHash, entries, false);               end
HASH_UNFOLDED(entries) click to toggle source
    # File lib/puppet/pops/model/factory.rb
714 def self.HASH_UNFOLDED(entries);       new(LiteralHash, entries, true);                end
HEREDOC(name, expr) click to toggle source
    # File lib/puppet/pops/model/factory.rb
716 def self.HEREDOC(name, expr);          new(HeredocExpression, name, expr);             end
HOSTCLASS(name, parameters, parent, body) click to toggle source
    # File lib/puppet/pops/model/factory.rb
924 def self.HOSTCLASS(name, parameters, parent, body)
925   new(HostClassDefinition, name, parameters, parent, body)
926 end
IF(test_e,then_e,else_e) click to toggle source
    # File lib/puppet/pops/model/factory.rb
700 def self.IF(test_e,then_e,else_e);     new(IfExpression, test_e, then_e, else_e);      end
KEY_ENTRY(key, val) click to toggle source
    # File lib/puppet/pops/model/factory.rb
710 def self.KEY_ENTRY(key, val);          new(KeyedEntry, key, val);                      end
LAMBDA(parameters, body, return_type) click to toggle source
    # File lib/puppet/pops/model/factory.rb
948 def self.LAMBDA(parameters, body, return_type)
949   new(LambdaExpression, parameters, body, return_type)
950 end
LIST(entries) click to toggle source
    # File lib/puppet/pops/model/factory.rb
720 def self.LIST(entries);                new(LiteralList, entries);                      end
MAP(match, value) click to toggle source
    # File lib/puppet/pops/model/factory.rb
708 def self.MAP(match, value);            new(SelectorEntry, match, value);               end
NAMED_ACCESS(type_name, bodies) click to toggle source
    # File lib/puppet/pops/model/factory.rb
881 def self.NAMED_ACCESS(type_name, bodies)
882   new(NamedAccessExpression, type_name, bodies)
883 end
NODE(hosts, parent, body) click to toggle source
    # File lib/puppet/pops/model/factory.rb
724 def self.NODE(hosts, parent, body);    new(NodeDefinition, hosts, parent, body);       end
NUMBER(name_or_numeric) click to toggle source
    # File lib/puppet/pops/model/factory.rb
800 def self.NUMBER(name_or_numeric)
801   n_radix = Utils.to_n_with_radix(name_or_numeric)
802   if n_radix
803     val, radix = n_radix
804     if val.is_a?(Float)
805       new(LiteralFloat, val)
806     else
807       new(LiteralInteger, val, radix)
808     end
809   else
810     # Bad number should already have been caught by lexer - this should never happen
811     #TRANSLATORS 'NUMBER' refers to a method name and the 'name_or_numeric' was the passed in value and should not be translated
812     raise ArgumentError, _("Internal Error, NUMBER token does not contain a valid number, %{name_or_numeric}") %
813         { name_or_numeric: name_or_numeric }
814   end
815 end
PARAM(name, expr=nil) click to toggle source
    # File lib/puppet/pops/model/factory.rb
722 def self.PARAM(name, expr=nil);        new(Parameter, name, expr);                     end
PLAN(name, parameters, body) click to toggle source
    # File lib/puppet/pops/model/factory.rb
932 def self.PLAN(name, parameters, body)
933   new(PlanDefinition, name, parameters, body, nil)
934 end
PROGRAM(body, definitions, locator) click to toggle source
    # File lib/puppet/pops/model/factory.rb
901 def self.PROGRAM(body, definitions, locator)
902   new(Program, body, definitions, locator)
903 end
QNAME(name) click to toggle source

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.

    # File lib/puppet/pops/model/factory.rb
796 def self.QNAME(name)
797   new(QualifiedName, name)
798 end
QNAME_OR_NUMBER(name) click to toggle source

Convert input string to either a qualified name, a LiteralInteger with radix, or a LiteralFloat

    # File lib/puppet/pops/model/factory.rb
819 def self.QNAME_OR_NUMBER(name)
820   n_radix = Utils.to_n_with_radix(name)
821   if n_radix
822     val, radix = n_radix
823     if val.is_a?(Float)
824       new(LiteralFloat, val)
825     else
826       new(LiteralInteger, val, radix)
827     end
828   else
829     new(QualifiedName, name)
830   end
831 end
QREF(name) click to toggle source
    # File lib/puppet/pops/model/factory.rb
833 def self.QREF(name)
834   new(QualifiedReference, name)
835 end
RENDER_EXPR(expr) click to toggle source
    # File lib/puppet/pops/model/factory.rb
774 def self.RENDER_EXPR(expr)
775   new(RenderExpression, expr)
776 end
RENDER_STRING(o) click to toggle source

TODO_EPP

    # File lib/puppet/pops/model/factory.rb
770 def self.RENDER_STRING(o)
771   new(RenderStringExpression, o)
772 end
RESERVED(name, future=false) click to toggle source
    # File lib/puppet/pops/model/factory.rb
789 def self.RESERVED(name, future=false)
790   new(ReservedWord, name, future)
791 end
RESOURCE(type_name, bodies) click to toggle source
    # File lib/puppet/pops/model/factory.rb
885 def self.RESOURCE(type_name, bodies)
886   new(ResourceExpression, type_name, bodies)
887 end
RESOURCE_BODY(resource_title, attribute_operations) click to toggle source
    # File lib/puppet/pops/model/factory.rb
897 def self.RESOURCE_BODY(resource_title, attribute_operations)
898   new(ResourceBody, resource_title, attribute_operations)
899 end
RESOURCE_DEFAULTS(type_name, attribute_operations) click to toggle source
    # File lib/puppet/pops/model/factory.rb
889 def self.RESOURCE_DEFAULTS(type_name, attribute_operations)
890   new(ResourceDefaultsExpression, type_name, attribute_operations)
891 end
RESOURCE_OVERRIDE(resource_ref, attribute_operations) click to toggle source
    # File lib/puppet/pops/model/factory.rb
893 def self.RESOURCE_OVERRIDE(resource_ref, attribute_operations)
894   new(ResourceOverrideExpression, resource_ref, attribute_operations)
895 end
STRING(*args) click to toggle source
    # File lib/puppet/pops/model/factory.rb
718 def self.STRING(*args);                new(ConcatenatedString, args);                  end
SUBLOCATE(token, expr_factory) click to toggle source
    # File lib/puppet/pops/model/factory.rb
752 def self.SUBLOCATE(token, expr_factory)
753   # expr is a Factory wrapped LiteralString, or ConcatenatedString
754   # The token is SUBLOCATED token which has a SubLocator as the token's locator
755   # Use the SubLocator to recalculate the offsets and lengths.
756   model = expr_factory.model
757   locator = token.locator
758   expr_factory.map_offset(model, locator)
759   model._pcore_all_contents([]) { |element| expr_factory.map_offset(element, locator) }
760 
761   # Returned the factory wrapping the now offset/length transformed expression(s)
762   expr_factory
763 end
TEXT(expr) click to toggle source
    # File lib/puppet/pops/model/factory.rb
765 def self.TEXT(expr)
766   new(TextExpression, infer(expr).interpolate)
767 end
TYPE_ASSIGNMENT(lhs, rhs) click to toggle source
    # File lib/puppet/pops/model/factory.rb
952 def self.TYPE_ASSIGNMENT(lhs, rhs)
953   if lhs.model_class <= AccessExpression
954     new(TypeMapping, lhs, rhs)
955   else
956     new(TypeAlias, lhs['cased_value'], rhs)
957   end
958 end
TYPE_DEFINITION(name, parent, body) click to toggle source
    # File lib/puppet/pops/model/factory.rb
960 def self.TYPE_DEFINITION(name, parent, body)
961   new(TypeDefinition, name, parent, body)
962 end
UNLESS(test_e,then_e,else_e) click to toggle source
    # File lib/puppet/pops/model/factory.rb
702 def self.UNLESS(test_e,then_e,else_e); new(UnlessExpression, test_e, then_e, else_e);  end
VIRTUAL_QUERY(query_expr) click to toggle source
    # File lib/puppet/pops/model/factory.rb
837 def self.VIRTUAL_QUERY(query_expr)
838   new(VirtualQuery, query_expr)
839 end
WHEN(values_list, block) click to toggle source
    # File lib/puppet/pops/model/factory.rb
706 def self.WHEN(values_list, block);     new(CaseOption, values_list, block);            end
block(*args) click to toggle source
    # File lib/puppet/pops/model/factory.rb
694 def self.block(*args);                 new(BlockExpression, args.map { |arg| infer(arg) }); end
block_or_expression(args, left_brace = nil, right_brace = nil) click to toggle source

Builds a BlockExpression if args size > 1, else the single expression/value in args

    # File lib/puppet/pops/model/factory.rb
906 def self.block_or_expression(args, left_brace = nil, right_brace = nil)
907   if args.size > 1
908     block_expr = new(BlockExpression, args)
909 
910     # If given a left and right brace position, use those
911     # otherwise use the first and last element of the block
912     if !left_brace.nil? && !right_brace.nil?
913       block_expr.record_position(args.first[KEY_LOCATOR], left_brace, right_brace)
914     else
915       block_expr.record_position(args.first[KEY_LOCATOR], args.first, args.last)
916     end
917 
918     block_expr
919   else
920     args[0]
921   end
922 end
call_named(name, rval_required, *argument_list) click to toggle source

Same as CALL_NAMED but with inference and varargs (for testing purposes)

    # File lib/puppet/pops/model/factory.rb
865 def self.call_named(name, rval_required, *argument_list)
866   new(CallNamedFunctionExpression, fqn(name), rval_required, argument_list.map { |arg| infer(arg) })
867 end
concat(*args) click to toggle source
     # File lib/puppet/pops/model/factory.rb
1113 def self.concat(*args)
1114   result = ''
1115   args.each do |e|
1116     if e.instance_of?(Factory) && e.model_class <= LiteralString
1117       result << e[KEY_VALUE]
1118     elsif e.is_a?(String)
1119       result << e
1120     else
1121       raise ArgumentError, _("can only concatenate strings, got %{class_name}") % { class_name: e.class }
1122     end
1123   end
1124   infer(result)
1125 end
fqn(o) click to toggle source

Creates a QualifiedName representation of o, unless o already represents a QualifiedName in which case it is returned.

    # File lib/puppet/pops/model/factory.rb
741 def self.fqn(o)
742   o.instance_of?(Factory) && o.model_class <= QualifiedName ? self : new(QualifiedName, o)
743 end
fqr(o) click to toggle source

Creates a QualifiedName representation of o, unless o already represents a QualifiedName in which case it is returned.

    # File lib/puppet/pops/model/factory.rb
748 def self.fqr(o)
749   o.instance_of?(Factory) && o.model_class <= QualifiedReference ? self : new(QualifiedReference, o)
750 end
infer(o) click to toggle source
   # File lib/puppet/pops/model/factory.rb
33 def self.infer(o)
34   if o.instance_of?(Factory)
35     o
36   else
37     new(o)
38   end
39 end
literal(o) click to toggle source

Factory starting points

    # File lib/puppet/pops/model/factory.rb
686 def self.literal(o);                   infer(o);                                       end
minus(o) click to toggle source
    # File lib/puppet/pops/model/factory.rb
688 def self.minus(o);                     infer(o).minus;                                 end
name_is_statement?(name) click to toggle source

Returns true if the given name is a “statement keyword” (require, include, contain, error, notice, info, debug

    # File lib/puppet/pops/model/factory.rb
991 def self.name_is_statement?(name)
992   STATEMENT_CALLS.include?(name)
993 end
new(o, *args) click to toggle source

Initialize a factory with a single object, or a class with arguments applied to build of created instance

   # File lib/puppet/pops/model/factory.rb
83 def initialize(o, *args)
84   @init_hash = {}
85   if o.instance_of?(Class)
86     @model_class = o
87     BUILD_VISITOR.visit_this_class(self, o, args)
88   else
89     INFER_VISITOR.visit_this(self, o, EMPTY_ARRAY)
90   end
91 end
nop?(o) click to toggle source
    # File lib/puppet/pops/model/factory.rb
964 def self.nop? o
965   o.nil? || o.instance_of?(Factory) && o.model_class <= Nop
966 end
resource_shape(expr) click to toggle source

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

    # File lib/puppet/pops/model/factory.rb
659 def self.resource_shape(expr)
660   if expr == 'class'
661     :class
662   elsif expr.instance_of?(self)
663     mc = expr.model_class
664     if mc <= QualifiedName
665       :resource
666     elsif mc <= QualifiedReference
667       :defaults
668     elsif mc <= AccessExpression
669       # if Resource[e], then it is not resource specific
670       lhs = expr[KEY_LEFT_EXPR]
671       if lhs.model_class <= QualifiedReference && lhs[KEY_VALUE] == 'resource' && expr[KEY_KEYS].size == 1
672         :defaults
673       else
674         :override
675       end
676     else
677       :error
678     end
679   else
680     :error
681   end
682 end
set_resource_form(expr, form) click to toggle source

Sets the form of the resource expression (:regular (the default), :virtual, or :exported). Produces true if the expression was a resource expression, false otherwise.

    # File lib/puppet/pops/model/factory.rb
645 def self.set_resource_form(expr, form)
646   # Note: Validation handles illegal combinations
647   return false unless expr.instance_of?(self) && expr.model_class <= AbstractResource
648   expr['form'] = form
649   return true
650 end
string(*args) click to toggle source
    # File lib/puppet/pops/model/factory.rb
696 def self.string(*args);                new(ConcatenatedString, args.map { |arg| infer(arg) });           end
text(o) click to toggle source
    # File lib/puppet/pops/model/factory.rb
698 def self.text(o);                      infer(o).text;                                  end
transform_calls(expressions) click to toggle source

Transforms an array of expressions containing literal name expressions to calls if followed by an expression, or expression list.

     # File lib/puppet/pops/model/factory.rb
1006 def self.transform_calls(expressions)
1007   expressions.reduce([]) do |memo, expr|
1008     name = memo[-1]
1009     if name.instance_of?(Factory) && name.model_class <= QualifiedName && name_is_statement?(name[KEY_VALUE])
1010       if expr.is_a?(Array)
1011         expr = expr.reject { |e| e.is_a?(Parser::LexerSupport::TokenValue) }
1012       else
1013         expr = [expr]
1014       end
1015       the_call = self.CALL_NAMED(name, false, expr)
1016       # last positioned is last arg if there are several
1017       the_call.record_position(name[KEY_LOCATOR], name, expr[-1])
1018       memo[-1] = the_call
1019       if expr.is_a?(CallNamedFunctionExpression)
1020         # Patch statement function call to expression style
1021         # This is needed because it is first parsed as a "statement" and the requirement changes as it becomes
1022         # an argument to the name to call transform above.
1023         expr.rval_required = true
1024       end
1025     elsif expr.is_a?(Array)
1026       raise ArgsToNonCallError.new(expr, name)
1027     else
1028       memo << expr
1029       if expr.model_class <= CallNamedFunctionExpression
1030         # Patch rvalue expression function call to statement style.
1031         # This is not really required but done to be AST model compliant
1032         expr['rval_required'] = false
1033       end
1034     end
1035     memo
1036   end
1037 end
transform_resource_wo_title(left, attribute_ops, lbrace_token, rbrace_token) click to toggle source

Transforms a left expression followed by an untitled resource (in the form of attribute_operations) @param left [Factory, Expression] the lhs followed what may be a hash

     # File lib/puppet/pops/model/factory.rb
1041 def self.transform_resource_wo_title(left, attribute_ops, lbrace_token, rbrace_token)
1042   # Returning nil means accepting the given as a potential resource expression
1043   return nil unless attribute_ops.is_a? Array
1044   return nil unless left.model_class <= QualifiedName
1045   keyed_entries = attribute_ops.map do |ao|
1046     return nil if ao[KEY_OPERATOR] == '+>'
1047     KEY_ENTRY(infer(ao['attribute_name']), ao['value_expr'])
1048   end
1049   a_hash = HASH(keyed_entries)
1050   a_hash.record_position(left[KEY_LOCATOR], lbrace_token, rbrace_token)
1051   result = block_or_expression(transform_calls([left, a_hash]))
1052   result
1053 end
unfold(o) click to toggle source
    # File lib/puppet/pops/model/factory.rb
690 def self.unfold(o);                    infer(o).unfold;                                end
var(o) click to toggle source
    # File lib/puppet/pops/model/factory.rb
692 def self.var(o);                       infer(o).var;                                   end

Public Instance Methods

%(r;) click to toggle source
    # File lib/puppet/pops/model/factory.rb
555 def % r;      f_arithmetic('%', r);                           end
*(r;) click to toggle source
    # File lib/puppet/pops/model/factory.rb
553 def * r;      f_arithmetic('*', r);                           end
+(r;) click to toggle source
    # File lib/puppet/pops/model/factory.rb
547 def + r;      f_arithmetic('+', r);                           end
-(r;) click to toggle source
    # File lib/puppet/pops/model/factory.rb
549 def - r;      f_arithmetic('-', r);                           end
/(r;) click to toggle source
    # File lib/puppet/pops/model/factory.rb
551 def / r;      f_arithmetic('/', r);                           end
<(r;) click to toggle source
    # File lib/puppet/pops/model/factory.rb
561 def < r;      f_comparison('<', r);                           end
<<(r;) click to toggle source
    # File lib/puppet/pops/model/factory.rb
557 def << r;     f_arithmetic('<<', r);                          end
<=(r;) click to toggle source
    # File lib/puppet/pops/model/factory.rb
563 def <= r;     f_comparison('<=', r);                          end
=~(r;) click to toggle source
    # File lib/puppet/pops/model/factory.rb
573 def =~ r;     f_match('=~', r);                               end
>(r;) click to toggle source
    # File lib/puppet/pops/model/factory.rb
565 def > r;      f_comparison('>', r);                           end
>=(r;) click to toggle source
    # File lib/puppet/pops/model/factory.rb
567 def >= r;     f_comparison('>=', r);                          end
>>(r;) click to toggle source
    # File lib/puppet/pops/model/factory.rb
559 def >> r;     f_arithmetic('>>', r);                          end
[](key) click to toggle source
   # File lib/puppet/pops/model/factory.rb
43 def [](key)
44   @init_hash[key]
45 end
[]=(key, value) click to toggle source
   # File lib/puppet/pops/model/factory.rb
47 def []=(key, value)
48   @init_hash[key] = value
49 end
access(r) click to toggle source
    # File lib/puppet/pops/model/factory.rb
543 def access(r); f_build_binary(AccessExpression, self, r);     end
access_at(*r) click to toggle source

Same as access, but with varargs and arguments that must be inferred. For testing purposes

    # File lib/puppet/pops/model/factory.rb
588 def access_at(*r)
589   f_build_binary(AccessExpression, self, r.map { |arg| Factory.infer(arg) })
590 end
all_factories(&block) click to toggle source
   # File lib/puppet/pops/model/factory.rb
51 def all_factories(&block)
52   block.call(self)
53   @init_hash.each_value { |value| value.all_factories(&block) if value.instance_of?(Factory) }
54 end
and(r) click to toggle source
    # File lib/puppet/pops/model/factory.rb
531 def and(r)    f_build_binary(AndExpression, self, r);         end
attributes(*args) click to toggle source
    # File lib/puppet/pops/model/factory.rb
618 def attributes(*args)
619   @init_hash['attributes'] = args
620   self
621 end
build_AccessExpression(o, left, keys) click to toggle source
    # File lib/puppet/pops/model/factory.rb
143 def build_AccessExpression(o, left, keys)
144   @init_hash[KEY_LEFT_EXPR] = left
145   @init_hash[KEY_KEYS] = keys
146 end
build_ApplyExpression(o, args, body) click to toggle source
    # File lib/puppet/pops/model/factory.rb
262 def build_ApplyExpression(o, args, body)
263   @init_hash['arguments'] = args
264   @init_hash['body'] = body
265 end
build_ArithmeticExpression(o, op, a, b) click to toggle source

Building of Model classes

    # File lib/puppet/pops/model/factory.rb
123 def build_ArithmeticExpression(o, op, a, b)
124   @init_hash[KEY_OPERATOR] = op
125   build_BinaryExpression(o, a, b)
126 end
build_AssignmentExpression(o, op, a, b) click to toggle source
    # File lib/puppet/pops/model/factory.rb
128 def build_AssignmentExpression(o, op, a, b)
129   @init_hash[KEY_OPERATOR] = op
130   build_BinaryExpression(o, a, b)
131 end
build_AttributeOperation(o, name, op, value) click to toggle source
    # File lib/puppet/pops/model/factory.rb
133 def build_AttributeOperation(o, name, op, value)
134   @init_hash[KEY_OPERATOR] = op
135   @init_hash['attribute_name'] = name.to_s # BOOLEAN is allowed in the grammar
136   @init_hash['value_expr'] = value
137 end
build_AttributesOperation(o, value) click to toggle source
    # File lib/puppet/pops/model/factory.rb
139 def build_AttributesOperation(o, value)
140   @init_hash[KEY_EXPR] = value
141 end
build_BinaryExpression(o, left, right) click to toggle source
    # File lib/puppet/pops/model/factory.rb
148 def build_BinaryExpression(o, left, right)
149   @init_hash[KEY_LEFT_EXPR] = left
150   @init_hash[KEY_RIGHT_EXPR] = right
151 end
build_BlockExpression(o, args) click to toggle source
    # File lib/puppet/pops/model/factory.rb
153 def build_BlockExpression(o, args)
154   @init_hash['statements'] = args
155 end
build_CallExpression(o, functor, rval_required, args) click to toggle source

@param rval_required [Boolean] if the call must produce a value

    # File lib/puppet/pops/model/factory.rb
164 def build_CallExpression(o, functor, rval_required, args)
165   @init_hash['functor_expr'] = functor
166   @init_hash['rval_required'] = rval_required
167   @init_hash['arguments'] = args
168 end
build_CallMethodExpression(o, functor, rval_required, lambda, args) click to toggle source
    # File lib/puppet/pops/model/factory.rb
170 def build_CallMethodExpression(o, functor, rval_required, lambda, args)
171   build_CallExpression(o, functor, rval_required, args)
172   @init_hash['lambda'] = lambda
173 end
build_CaseExpression(o, test, args) click to toggle source
    # File lib/puppet/pops/model/factory.rb
175 def build_CaseExpression(o, test, args)
176   @init_hash['test'] = test
177   @init_hash['options'] = args
178 end
build_CaseOption(o, value_list, then_expr) click to toggle source
    # File lib/puppet/pops/model/factory.rb
180 def build_CaseOption(o, value_list, then_expr)
181   value_list = [value_list] unless value_list.is_a?(Array)
182   @init_hash['values'] = value_list
183   b = f_build_body(then_expr)
184   @init_hash['then_expr'] = b unless b.nil?
185 end
build_CollectExpression(o, type_expr, query_expr, attribute_operations) click to toggle source
    # File lib/puppet/pops/model/factory.rb
187 def build_CollectExpression(o, type_expr, query_expr, attribute_operations)
188   @init_hash['type_expr'] = type_expr
189   @init_hash['query'] = query_expr
190   @init_hash['operations'] = attribute_operations
191 end
build_ComparisonExpression(o, op, a, b) click to toggle source
    # File lib/puppet/pops/model/factory.rb
193 def build_ComparisonExpression(o, op, a, b)
194   @init_hash[KEY_OPERATOR] = op
195   build_BinaryExpression(o, a, b)
196 end
build_ConcatenatedString(o, args) click to toggle source
    # File lib/puppet/pops/model/factory.rb
198 def build_ConcatenatedString(o, args)
199   # Strip empty segments
200   @init_hash['segments'] = args.reject { |arg| arg.model_class == LiteralString && arg['value'].empty? }
201 end
build_EppExpression(o, parameters_specified, body) click to toggle source
    # File lib/puppet/pops/model/factory.rb
157 def build_EppExpression(o, parameters_specified, body)
158   @init_hash['parameters_specified'] = parameters_specified
159   b = f_build_body(body)
160   @init_hash[KEY_BODY] = b unless b.nil?
161 end
build_FunctionDefinition(o, name, parameters, body, return_type) click to toggle source
    # File lib/puppet/pops/model/factory.rb
367 def build_FunctionDefinition(o, name, parameters, body, return_type)
368   @init_hash[KEY_PARAMETERS] = parameters
369   b = f_build_body(body)
370   @init_hash[KEY_BODY] = b unless b.nil?
371   @init_hash[KEY_NAME] = name
372   @init_hash['return_type'] = return_type unless return_type.nil?
373 end
build_HeredocExpression(o, name, expr) click to toggle source
    # File lib/puppet/pops/model/factory.rb
203 def build_HeredocExpression(o, name, expr)
204   @init_hash['syntax'] = name
205   @init_hash['text_expr'] = expr
206 end
build_HostClassDefinition(o, name, parameters, parent_class_name, body) click to toggle source

@param name [String] a valid classname @param parameters [Array<Parameter>] may be empty @param parent_class_name [String, nil] a valid classname referencing a parent class, optional. @param body [Array<Expression>, Expression, nil] expression that constitute the body @return [HostClassDefinition] configured from the parameters

    # File lib/puppet/pops/model/factory.rb
214 def build_HostClassDefinition(o, name, parameters, parent_class_name, body)
215   build_NamedDefinition(o, name, parameters, body)
216   @init_hash['parent_class'] = parent_class_name unless parent_class_name.nil?
217 end
build_IfExpression(o, t, ift, els) click to toggle source
    # File lib/puppet/pops/model/factory.rb
256 def build_IfExpression(o, t, ift, els)
257   @init_hash['test'] = t
258   @init_hash['then_expr'] = ift
259   @init_hash['else_expr'] = els
260 end
build_KeyedEntry(o, k, v) click to toggle source
    # File lib/puppet/pops/model/factory.rb
229 def build_KeyedEntry(o, k, v)
230   @init_hash['key'] = k
231   @init_hash[KEY_VALUE] = v
232 end
build_LambdaExpression(o, parameters, body, return_type) click to toggle source
    # File lib/puppet/pops/model/factory.rb
353 def build_LambdaExpression(o, parameters, body, return_type)
354   @init_hash[KEY_PARAMETERS] = parameters
355   b = f_build_body(body)
356   @init_hash[KEY_BODY] = b unless b.nil?
357   @init_hash['return_type'] = return_type unless return_type.nil?
358 end
build_LiteralFloat(o, val) click to toggle source
    # File lib/puppet/pops/model/factory.rb
243 def build_LiteralFloat(o, val)
244   @init_hash[KEY_VALUE] = val
245 end
build_LiteralHash(o, keyed_entries, unfolded) click to toggle source
    # File lib/puppet/pops/model/factory.rb
234 def build_LiteralHash(o, keyed_entries, unfolded)
235   @init_hash['entries'] = keyed_entries
236   @unfolded = unfolded
237 end
build_LiteralInteger(o, val, radix) click to toggle source
    # File lib/puppet/pops/model/factory.rb
247 def build_LiteralInteger(o, val, radix)
248   @init_hash[KEY_VALUE] = val
249   @init_hash['radix'] = radix
250 end
build_LiteralList(o, values) click to toggle source
    # File lib/puppet/pops/model/factory.rb
239 def build_LiteralList(o, values)
240   @init_hash['values'] = values
241 end
build_LiteralString(o, value) click to toggle source
    # File lib/puppet/pops/model/factory.rb
252 def build_LiteralString(o, value)
253   @init_hash[KEY_VALUE] = val
254 end
build_MatchExpression(o, op, a, b) click to toggle source
    # File lib/puppet/pops/model/factory.rb
267 def build_MatchExpression(o, op, a, b)
268   @init_hash[KEY_OPERATOR] = op
269   build_BinaryExpression(o, a, b)
270 end
build_NamedDefinition(o, name, parameters, body) click to toggle source
    # File lib/puppet/pops/model/factory.rb
360 def build_NamedDefinition(o, name, parameters, body)
361   @init_hash[KEY_PARAMETERS] = parameters
362   b = f_build_body(body)
363   @init_hash[KEY_BODY] = b unless b.nil?
364   @init_hash[KEY_NAME] = name
365 end
build_NodeDefinition(o, hosts, parent, body) click to toggle source
    # File lib/puppet/pops/model/factory.rb
383 def build_NodeDefinition(o, hosts, parent, body)
384   @init_hash['host_matches'] = hosts
385   @init_hash['parent'] = parent unless parent.nil? # no nop here
386   b = f_build_body(body)
387   @init_hash[KEY_BODY] = b unless b.nil?
388 end
build_Parameter(o, name, expr) click to toggle source
    # File lib/puppet/pops/model/factory.rb
390 def build_Parameter(o, name, expr)
391   @init_hash[KEY_NAME] = name
392   @init_hash[KEY_VALUE] = expr
393 end
build_PlanDefinition(o, name, parameters, body, return_type=nil) click to toggle source
    # File lib/puppet/pops/model/factory.rb
375 def build_PlanDefinition(o, name, parameters, body, return_type=nil)
376   @init_hash[KEY_PARAMETERS] = parameters
377   b = f_build_body(body)
378   @init_hash[KEY_BODY] = b unless b.nil?
379   @init_hash[KEY_NAME] = name
380   @init_hash['return_type'] = return_type unless return_type.nil?
381 end
build_Program(o, body, definitions, locator) click to toggle source
    # File lib/puppet/pops/model/factory.rb
486 def build_Program(o, body, definitions, locator)
487   @init_hash[KEY_BODY] = body
488   # non containment
489   @init_hash['definitions'] = definitions
490   @init_hash[KEY_LOCATOR] = locator
491 end
build_QualifiedName(o, name) click to toggle source
    # File lib/puppet/pops/model/factory.rb
493 def build_QualifiedName(o, name)
494   @init_hash[KEY_VALUE] = name
495 end
build_QualifiedReference(o, name) click to toggle source
    # File lib/puppet/pops/model/factory.rb
395 def build_QualifiedReference(o, name)
396   @init_hash['cased_value'] = name.to_s
397 end
build_QueryExpression(o, expr) click to toggle source
    # File lib/puppet/pops/model/factory.rb
433 def build_QueryExpression(o, expr)
434   @init_hash[KEY_EXPR] = expr unless Factory.nop?(expr)
435 end
build_RelationshipExpression(o, op, a, b) click to toggle source
    # File lib/puppet/pops/model/factory.rb
399 def build_RelationshipExpression(o, op, a, b)
400   @init_hash[KEY_OPERATOR] = op
401   build_BinaryExpression(o, a, b)
402 end
build_RenderStringExpression(o, string) click to toggle source
    # File lib/puppet/pops/model/factory.rb
409 def build_RenderStringExpression(o, string)
410   @init_hash[KEY_VALUE] = string;
411 end
build_ReservedWord(o, name, future) click to toggle source
    # File lib/puppet/pops/model/factory.rb
224 def build_ReservedWord(o, name, future)
225   @init_hash['word'] = name
226   @init_hash['future'] = future
227 end
build_ResourceBody(o, title_expression, attribute_operations) click to toggle source
    # File lib/puppet/pops/model/factory.rb
413 def build_ResourceBody(o, title_expression, attribute_operations)
414   @init_hash['title'] = title_expression
415   @init_hash['operations'] = attribute_operations
416 end
build_ResourceDefaultsExpression(o, type_ref, attribute_operations) click to toggle source
    # File lib/puppet/pops/model/factory.rb
418 def build_ResourceDefaultsExpression(o, type_ref, attribute_operations)
419   @init_hash['type_ref'] = type_ref
420   @init_hash['operations'] = attribute_operations
421 end
build_ResourceExpression(o, type_name, bodies) click to toggle source
    # File lib/puppet/pops/model/factory.rb
404 def build_ResourceExpression(o, type_name, bodies)
405   @init_hash['type_name'] = type_name
406   @init_hash['bodies'] = bodies
407 end
build_ResourceOverrideExpression(o, resources, attribute_operations) click to toggle source
    # File lib/puppet/pops/model/factory.rb
219 def build_ResourceOverrideExpression(o, resources, attribute_operations)
220   @init_hash['resources'] = resources
221   @init_hash['operations'] = attribute_operations
222 end
build_SelectorEntry(o, matching, value) click to toggle source
    # File lib/puppet/pops/model/factory.rb
428 def build_SelectorEntry(o, matching, value)
429   @init_hash['matching_expr'] = matching
430   @init_hash['value_expr'] = value
431 end
build_SelectorExpression(o, left, *selectors) click to toggle source
    # File lib/puppet/pops/model/factory.rb
423 def build_SelectorExpression(o, left, *selectors)
424   @init_hash[KEY_LEFT_EXPR] = left
425   @init_hash['selectors'] = selectors
426 end
build_TokenValue(o) click to toggle source
    # File lib/puppet/pops/model/factory.rb
497 def build_TokenValue(o)
498   raise "Factory can not deal with a Lexer Token. Got token: #{o}. Probably caused by wrong index in grammar val[n]."
499 end
build_TypeAlias(o, name, type_expr) click to toggle source
    # File lib/puppet/pops/model/factory.rb
437 def build_TypeAlias(o, name, type_expr)
438   if type_expr.model_class <= KeyedEntry
439     # KeyedEntry is used for the form:
440     #
441     #   type Foo = Bar { ... }
442     #
443     # The entry contains Bar => { ... } and must be transformed into:
444     #
445     #   Object[{parent => Bar, ... }]
446     #
447     parent = type_expr['key']
448     hash = type_expr['value']
449     pn = parent['cased_value']
450     unless pn == 'Object' || pn == 'TypeSet'
451       hash['entries'] << Factory.KEY_ENTRY(Factory.QNAME('parent'), parent)
452       parent = Factory.QREF('Object')
453     end
454     type_expr = parent.access([hash])
455   elsif type_expr.model_class <= LiteralHash
456     # LiteralHash is used for the form:
457     #
458     #   type Foo = { ... }
459     #
460     # The hash must be transformed into:
461     #
462     #   Object[{ ... }]
463     #
464     type_expr = Factory.QREF('Object').access([type_expr])
465   end
466   @init_hash['type_expr'] = type_expr
467   @init_hash[KEY_NAME] = name
468 end
build_TypeDefinition(o, name, parent, body) click to toggle source
    # File lib/puppet/pops/model/factory.rb
475 def build_TypeDefinition(o, name, parent, body)
476   b = f_build_body(body)
477   @init_hash[KEY_BODY] = b unless b.nil?
478   @init_hash['parent'] = parent
479   @init_hash[KEY_NAME] = name
480 end
build_TypeMapping(o, lhs, rhs) click to toggle source
    # File lib/puppet/pops/model/factory.rb
470 def build_TypeMapping(o, lhs, rhs)
471   @init_hash['type_expr'] = lhs
472   @init_hash['mapping_expr'] = rhs
473 end
build_UnaryExpression(o, expr) click to toggle source
    # File lib/puppet/pops/model/factory.rb
482 def build_UnaryExpression(o, expr)
483   @init_hash[KEY_EXPR] = expr unless Factory.nop?(expr)
484 end
captures_rest() click to toggle source

Mark parameter as capturing the rest of arguments

    # File lib/puppet/pops/model/factory.rb
729 def captures_rest
730   @init_hash['captures_rest'] = true
731 end
contained_current(container) click to toggle source
     # File lib/puppet/pops/model/factory.rb
1141 def contained_current(container)
1142   if @current.nil?
1143     unless @init_hash.include?(KEY_LOCATOR)
1144       @init_hash[KEY_LOCATOR] = container[KEY_LOCATOR]
1145       @init_hash[KEY_OFFSET] = container[KEY_OFFSET] || 0
1146       @init_hash[KEY_LENGTH] = 0
1147     end
1148     @current = create_model
1149   end
1150   @current
1151 end
create_model() click to toggle source
   # File lib/puppet/pops/model/factory.rb
75 def create_model
76   @init_hash.each_pair { |key, elem| @init_hash[key] = factory_to_model(elem) }
77   model_class.from_asserted_hash(@init_hash)
78 end
current()

Backward API compatibility

Alias for: model
default(r) click to toggle source

For CaseExpression, setting the default for an already build CaseExpression

    # File lib/puppet/pops/model/factory.rb
593 def default(r)
594   @init_hash['options'] << Factory.WHEN(Factory.infer(:default), r)
595   self
596 end
dot(r;) click to toggle source
    # File lib/puppet/pops/model/factory.rb
545 def dot r;    f_build_binary(NamedAccessExpression, self, r); end
eq(r;) click to toggle source
    # File lib/puppet/pops/model/factory.rb
569 def eq r;     f_comparison('==', r);                          end
f_arithmetic(op, r) click to toggle source
    # File lib/puppet/pops/model/factory.rb
514 def f_arithmetic(op, r)
515   f_build_binary_op(ArithmeticExpression, op, self, r)
516 end
f_build_binary(klazz, left, right) click to toggle source
    # File lib/puppet/pops/model/factory.rb
510 def f_build_binary(klazz, left, right)
511   Factory.new(klazz, left, right)
512 end
f_build_binary_op(klazz, op, left, right) click to toggle source
    # File lib/puppet/pops/model/factory.rb
506 def f_build_binary_op(klazz, op, left, right)
507   Factory.new(klazz, op, left, right)
508 end
f_build_body(body) click to toggle source
    # File lib/puppet/pops/model/factory.rb
340 def f_build_body(body)
341   case body
342   when NilClass
343     nil
344   when Array
345     Factory.new(BlockExpression, body)
346   when Factory
347     body
348   else
349     Factory.infer(body)
350   end
351 end
f_build_unary(klazz, expr) click to toggle source

Factory helpers

    # File lib/puppet/pops/model/factory.rb
502 def f_build_unary(klazz, expr)
503   Factory.new(klazz, expr)
504 end
f_comparison(op, r) click to toggle source
    # File lib/puppet/pops/model/factory.rb
518 def f_comparison(op, r)
519   f_build_binary_op(ComparisonExpression, op, self, r)
520 end
f_match(op, r) click to toggle source
    # File lib/puppet/pops/model/factory.rb
522 def f_match(op, r)
523   f_build_binary_op(MatchExpression, op, self, r)
524 end
factory_to_model(value) click to toggle source
     # File lib/puppet/pops/model/factory.rb
1131 def factory_to_model(value)
1132   if value.instance_of?(Factory)
1133     value.contained_current(self)
1134   elsif value.instance_of?(Array)
1135     value.each_with_index { |el, idx| value[idx] = el.contained_current(self) if el.instance_of?(Factory) }
1136   else
1137     value
1138   end
1139 end
in(r) click to toggle source

Operator helpers

    # File lib/puppet/pops/model/factory.rb
527 def in(r)     f_build_binary(InExpression, self, r);          end
infer_Array(o) click to toggle source

Creates a LiteralList instruction from an Array, where the entries are built.

    # File lib/puppet/pops/model/factory.rb
326 def infer_Array(o)
327   @model_class = LiteralList
328   @init_hash['values'] = o.map { |e| Factory.infer(e) }
329 end
infer_FalseClass(o) click to toggle source
    # File lib/puppet/pops/model/factory.rb
290 def infer_FalseClass(o)
291   @model_class = LiteralBoolean
292   @init_hash[KEY_VALUE] = o
293 end
infer_Float(o) click to toggle source
    # File lib/puppet/pops/model/factory.rb
300 def infer_Float(o)
301   @model_class = LiteralFloat
302   @init_hash[KEY_VALUE] = o
303 end
infer_Hash(o) click to toggle source

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

    # File lib/puppet/pops/model/factory.rb
334 def infer_Hash(o)
335   @model_class = LiteralHash
336   @init_hash['entries'] = o.sort_by { |k,_| k.to_s }.map { |k, v| Factory.new(KeyedEntry, Factory.infer(k), Factory.infer(v)) }
337   @unfolded = false
338 end
infer_Integer(o) click to toggle source
    # File lib/puppet/pops/model/factory.rb
295 def infer_Integer(o)
296   @model_class = LiteralInteger
297   @init_hash[KEY_VALUE] = o
298 end
infer_NilClass(o) click to toggle source
    # File lib/puppet/pops/model/factory.rb
281 def infer_NilClass(o)
282   @model_class = Nop
283 end
infer_Regexp(o) click to toggle source
    # File lib/puppet/pops/model/factory.rb
305 def infer_Regexp(o)
306   @model_class = LiteralRegularExpression
307   @init_hash['pattern'] = o.inspect
308   @init_hash[KEY_VALUE] = o
309 end
infer_String(o) click to toggle source

Building model equivalences of Ruby objects Allows passing regular ruby objects to the factory to produce instructions that when evaluated produce the same thing.

    # File lib/puppet/pops/model/factory.rb
276 def infer_String(o)
277   @model_class = LiteralString
278   @init_hash[KEY_VALUE] = o
279 end
infer_Symbol(o) click to toggle source

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.

    # File lib/puppet/pops/model/factory.rb
314 def infer_Symbol(o)
315   case o
316   when :undef
317     @model_class = LiteralUndef
318   when :default
319     @model_class = LiteralDefault
320   else
321     infer_String(o.to_s)
322   end
323 end
infer_TrueClass(o) click to toggle source
    # File lib/puppet/pops/model/factory.rb
285 def infer_TrueClass(o)
286   @model_class = LiteralBoolean
287   @init_hash[KEY_VALUE] = o
288 end
interpolate() click to toggle source

Polymorphic interpolate

    # File lib/puppet/pops/model/factory.rb
117 def interpolate()
118   INTERPOLATION_VISITOR.visit_this_class(self, @model_class, EMPTY_ARRAY)
119 end
interpolate_AccessExpression(c) click to toggle source

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 $

     # File lib/puppet/pops/model/factory.rb
1076 def interpolate_AccessExpression(c)
1077   lhs = @init_hash[KEY_LEFT_EXPR]
1078   if is_interop_rewriteable?(lhs)
1079     @init_hash[KEY_LEFT_EXPR] = lhs.interpolate
1080   end
1081   self
1082 end
interpolate_CallMethodExpression(c) click to toggle source

Rewrite method calls on the form ${x.each …} to ${$x.each}

     # File lib/puppet/pops/model/factory.rb
1093 def interpolate_CallMethodExpression(c)
1094   functor_expr = @init_hash['functor_expr']
1095   if is_interop_rewriteable?(functor_expr)
1096     @init_hash['functor_expr'] = functor_expr.interpolate
1097   end
1098   self
1099 end
interpolate_Factory(c) click to toggle source
     # File lib/puppet/pops/model/factory.rb
1055 def interpolate_Factory(c)
1056   self
1057 end
interpolate_LiteralInteger(c) click to toggle source
     # File lib/puppet/pops/model/factory.rb
1059 def interpolate_LiteralInteger(c)
1060   # convert number to a variable
1061   self.var
1062 end
interpolate_NamedAccessExpression(c) click to toggle source
     # File lib/puppet/pops/model/factory.rb
1084 def interpolate_NamedAccessExpression(c)
1085   lhs = @init_hash[KEY_LEFT_EXPR]
1086   if is_interop_rewriteable?(lhs)
1087     @init_hash[KEY_LEFT_EXPR] = lhs.interpolate
1088   end
1089   self
1090 end
interpolate_Object(c) click to toggle source
     # File lib/puppet/pops/model/factory.rb
1064 def interpolate_Object(c)
1065   self
1066 end
interpolate_QualifiedName(c) click to toggle source
     # File lib/puppet/pops/model/factory.rb
1068 def interpolate_QualifiedName(c)
1069   self.var
1070 end
is_interop_rewriteable?(o) click to toggle source
     # File lib/puppet/pops/model/factory.rb
1101 def is_interop_rewriteable?(o)
1102   mc = o.model_class
1103   if mc <= AccessExpression || mc <= QualifiedName || mc <= NamedAccessExpression || mc <= CallMethodExpression
1104     true
1105   elsif mc <= LiteralInteger
1106     # Only decimal integers can represent variables, else it is a number
1107     o['radix'] == 10
1108   else
1109     false
1110   end
1111 end
lambda=(lambda) click to toggle source
    # File lib/puppet/pops/model/factory.rb
598 def lambda=(lambda)
599   @init_hash['lambda'] = lambda
600   self
601 end
length() click to toggle source
    # File lib/puppet/pops/model/factory.rb
627 def length
628   @init_hash[KEY_LENGTH]
629 end
map_offset(model, locator) click to toggle source
   # File lib/puppet/pops/model/factory.rb
93 def map_offset(model, locator)
94   MAPOFFSET_VISITOR.visit_this_1(self, model, locator)
95 end
map_offset_Factory(o, locator) click to toggle source
    # File lib/puppet/pops/model/factory.rb
101 def map_offset_Factory(o, locator)
102   map_offset(o.model, locator)
103 end
map_offset_Object(o, locator) click to toggle source
   # File lib/puppet/pops/model/factory.rb
97 def map_offset_Object(o, locator)
98   o
99 end
map_offset_Positioned(o, locator) click to toggle source
    # File lib/puppet/pops/model/factory.rb
105 def map_offset_Positioned(o, locator)
106   # Transpose the local offset, length to global "coordinates"
107   global_offset, global_length = locator.to_global(o.offset, o.length)
108 
109   # mutate
110   o.instance_variable_set(:'@offset', global_offset)
111   o.instance_variable_set(:'@length', global_length)
112   # Change locator since the positions were transposed to the global coordinates
113   o.instance_variable_set(:'@locator', locator.locator) if locator.is_a? Puppet::Pops::Parser::Locator::SubLocator
114 end
minus() click to toggle source
    # File lib/puppet/pops/model/factory.rb
535 def minus();  f_build_unary(UnaryMinusExpression, self);      end
minus_set(r) click to toggle source

Assignment -=

    # File lib/puppet/pops/model/factory.rb
614 def minus_set(r)
615   f_build_binary_op(AssignmentExpression, '-=', self, r)
616 end
mne(r;) click to toggle source
    # File lib/puppet/pops/model/factory.rb
575 def mne r;    f_match('!~', r);                               end
model() click to toggle source
   # File lib/puppet/pops/model/factory.rb
56 def model
57   if @current.nil?
58     # Assign a default Locator if it's missing. Should only happen when the factory is used by other
59     # means than from a parser (e.g. unit tests)
60     unless @init_hash.include?(KEY_LOCATOR)
61       @init_hash[KEY_LOCATOR] = Parser::Locator.locator('<no source>', 'no file')
62       unless @model_class <= Program
63         @init_hash[KEY_OFFSET] = 0
64         @init_hash[KEY_LENGTH] = 0
65       end
66     end
67     @current = create_model
68   end
69   @current
70 end
Also aliased as: current
ne(r;) click to toggle source
    # File lib/puppet/pops/model/factory.rb
571 def ne r;     f_comparison('!=', r);                          end
not() click to toggle source
    # File lib/puppet/pops/model/factory.rb
533 def not();    f_build_unary(NotExpression, self);             end
offset() click to toggle source
    # File lib/puppet/pops/model/factory.rb
623 def offset
624   @init_hash[KEY_OFFSET]
625 end
or(r) click to toggle source
    # File lib/puppet/pops/model/factory.rb
529 def or(r)     f_build_binary(OrExpression, self, r);          end
paren() click to toggle source
    # File lib/puppet/pops/model/factory.rb
577 def paren;    f_build_unary(ParenthesizedExpression, self);   end
plus_set(r) click to toggle source

Assignment +=

    # File lib/puppet/pops/model/factory.rb
609 def plus_set(r)
610   f_build_binary_op(AssignmentExpression, '+=', self, r)
611 end
record_position(locator, start_locatable, end_locatable) click to toggle source

Records the position (start -> end) and computes the resulting length.

    # File lib/puppet/pops/model/factory.rb
633 def record_position(locator, start_locatable, end_locatable)
634   # record information directly in the Positioned object
635   start_offset = start_locatable.offset
636   @init_hash[KEY_LOCATOR] = locator
637   @init_hash[KEY_OFFSET] = start_offset
638   @init_hash[KEY_LENGTH] = end_locatable.nil? ? start_locatable.length : end_locatable.offset + end_locatable.length - start_offset
639   self
640 end
relop(op, r) click to toggle source
    # File lib/puppet/pops/model/factory.rb
579 def relop(op, r)
580   f_build_binary_op(RelationshipExpression, op, self, r)
581 end
select(*args) click to toggle source
    # File lib/puppet/pops/model/factory.rb
583 def select(*args)
584   Factory.new(SelectorExpression, self, *args)
585 end
set(r) click to toggle source

Assignment =

    # File lib/puppet/pops/model/factory.rb
604 def set(r)
605   f_build_binary_op(AssignmentExpression, '=', self, r)
606 end
text() click to toggle source
    # File lib/puppet/pops/model/factory.rb
539 def text();   f_build_unary(TextExpression, self);            end
to_s() click to toggle source
     # File lib/puppet/pops/model/factory.rb
1127 def to_s
1128   "Factory for #{@model_class}"
1129 end
type_expr(o) click to toggle source

Set Expression that should evaluate to the parameter's type

    # File lib/puppet/pops/model/factory.rb
734 def type_expr(o)
735   @init_hash['type_expr'] = o
736 end
unfold() click to toggle source
    # File lib/puppet/pops/model/factory.rb
537 def unfold(); f_build_unary(UnfoldExpression, self);          end
var() click to toggle source
    # File lib/puppet/pops/model/factory.rb
541 def var();    f_build_unary(VariableExpression, self);        end