class Puppet::Pops::Types::TypeParser

Public Class Methods

new() click to toggle source

@api public

   # File lib/puppet/pops/types/type_parser.rb
16 def initialize
17   @parser = Parser::Parser.new
18   @type_transformer = Visitor.new(nil, 'interpret', 1, 1)
19 end
opt_type_map() click to toggle source

@api private

    # File lib/puppet/pops/types/type_parser.rb
210 def self.opt_type_map
211   # Map of common (and simple to optimize) data types in string form
212   # (Note that some types are the result of evaluation even if they appear to be simple
213   # - for example 'Data' and they cannot be optimized this way since the factory calls
214   # back to the parser for evaluation).
215   #
216   @opt_type_map ||= {
217       'Integer'      => TypeFactory.integer,
218       'Float'        => TypeFactory.float,
219       'Numeric'      => TypeFactory.numeric,
220 
221       'String'       => TypeFactory.string,
222       'String[1]'    => TypeFactory.string(TypeFactory.range(1, :default)),
223 
224       'Binary'       => TypeFactory.binary,
225 
226       'Boolean'      => TypeFactory.boolean,
227       'Boolean[true]'  => TypeFactory.boolean(true),
228       'Boolean[false]' => TypeFactory.boolean(false),
229 
230       'Array'        => TypeFactory.array_of_any,
231       'Array[1]'     => TypeFactory.array_of(TypeFactory.any, TypeFactory.range(1, :default)),
232 
233       'Hash'         => TypeFactory.hash_of_any,
234       'Collection'   => TypeFactory.collection,
235       'Scalar'       => TypeFactory.scalar,
236 
237       'Scalardata'   => TypeFactory.scalar_data,
238       'ScalarData'   => TypeFactory.scalar_data,
239 
240       'Catalogentry' => TypeFactory.catalog_entry,
241       'CatalogEntry' => TypeFactory.catalog_entry,
242 
243       'Undef'        => TypeFactory.undef,
244       'Default'      => TypeFactory.default,
245       'Any'          => TypeFactory.any,
246       'Type'         => TypeFactory.type_type,
247       'Callable'     => TypeFactory.all_callables,
248 
249       'Semver'       => TypeFactory.sem_ver,
250       'SemVer'       => TypeFactory.sem_ver,
251 
252       'Semverrange'  => TypeFactory.sem_ver_range,
253       'SemVerRange'  => TypeFactory.sem_ver_range,
254 
255       'Timestamp'    => TypeFactory.timestamp,
256       'TimeStamp'    => TypeFactory.timestamp,
257 
258       'Timespan'     => TypeFactory.timespan,
259       'TimeSpan'     => TypeFactory.timespan,
260 
261       'Uri'          => TypeFactory.uri,
262       'URI'          => TypeFactory.uri,
263 
264       'Optional[Integer]'      => TypeFactory.optional(TypeFactory.integer),
265       'Optional[String]'       => TypeFactory.optional(TypeFactory.string),
266       'Optional[String[1]]'    => TypeFactory.optional(TypeFactory.string(TypeFactory.range(1, :default))),
267       'Optional[Array]'        => TypeFactory.optional(TypeFactory.array_of_any),
268       'Optional[Hash]'         => TypeFactory.optional(TypeFactory.hash_of_any),
269 
270   }.freeze
271 end
type_map() click to toggle source

@api private

    # File lib/puppet/pops/types/type_parser.rb
162 def self.type_map
163   @type_map ||= {
164       'integer'      => TypeFactory.integer,
165       'float'        => TypeFactory.float,
166       'numeric'      => TypeFactory.numeric,
167       'init'         => TypeFactory.init,
168       'iterable'     => TypeFactory.iterable,
169       'iterator'     => TypeFactory.iterator,
170       'string'       => TypeFactory.string,
171       'binary'       => TypeFactory.binary,
172       'sensitive'    => TypeFactory.sensitive,
173       'enum'         => TypeFactory.enum,
174       'boolean'      => TypeFactory.boolean,
175       'pattern'      => TypeFactory.pattern,
176       'regexp'       => TypeFactory.regexp,
177       'array'        => TypeFactory.array_of_any,
178       'hash'         => TypeFactory.hash_of_any,
179       'class'        => TypeFactory.host_class,
180       'resource'     => TypeFactory.resource,
181       'collection'   => TypeFactory.collection,
182       'scalar'       => TypeFactory.scalar,
183       'scalardata'   => TypeFactory.scalar_data,
184       'catalogentry' => TypeFactory.catalog_entry,
185       'undef'        => TypeFactory.undef,
186       'notundef'     => TypeFactory.not_undef,
187       'default'      => TypeFactory.default,
188       'any'          => TypeFactory.any,
189       'variant'      => TypeFactory.variant,
190       'optional'     => TypeFactory.optional,
191       'runtime'      => TypeFactory.runtime,
192       'type'         => TypeFactory.type_type,
193       'tuple'        => TypeFactory.tuple,
194       'struct'       => TypeFactory.struct,
195       'object'       => TypeFactory.object,
196       'typealias'    => TypeFactory.type_alias,
197       'typereference' => TypeFactory.type_reference,
198       'typeset'      => TypeFactory.type_set,
199        # A generic callable as opposed to one that does not accept arguments
200       'callable'     => TypeFactory.all_callables,
201       'semver'       => TypeFactory.sem_ver,
202       'semverrange'  => TypeFactory.sem_ver_range,
203       'timestamp'    => TypeFactory.timestamp,
204       'timespan'     => TypeFactory.timespan,
205       'uri'          => TypeFactory.uri,
206   }.freeze
207 end

Public Instance Methods

interpret(ast, context = nil) click to toggle source

@param ast [Puppet::Pops::Model::PopsObject] the ast to interpret @param context [Loader::Loader] optional loader used when no adapted loader is found @return [PAnyType] a specialization of the PAnyType representing the type.

@api public

   # File lib/puppet/pops/types/type_parser.rb
56 def interpret(ast, context = nil)
57   result = @type_transformer.visit_this_1(self, ast, context)
58   raise_invalid_type_specification_error(ast) unless result.is_a?(PAnyType)
59   result
60 end
interpret_AccessExpression(ast, context) click to toggle source

@api private

    # File lib/puppet/pops/types/type_parser.rb
302 def interpret_AccessExpression(ast, context)
303   parameters = ast.keys.collect { |param| interpret_any(param, context) }
304 
305   qref = ast.left_expr
306   raise_invalid_type_specification_error(ast) unless qref.is_a?(Model::QualifiedReference)
307 
308   type_name = qref.value
309   case type_name
310   when 'array'
311     case parameters.size
312     when 1
313       type = assert_type(ast, parameters[0])
314     when 2
315       if parameters[0].is_a?(PAnyType)
316         type = parameters[0]
317         size_type =
318           if parameters[1].is_a?(PIntegerType)
319             size_type = parameters[1]
320           else
321             assert_range_parameter(ast, parameters[1])
322             TypeFactory.range(parameters[1], :default)
323           end
324       else
325         type = :default
326         assert_range_parameter(ast, parameters[0])
327         assert_range_parameter(ast, parameters[1])
328         size_type = TypeFactory.range(parameters[0], parameters[1])
329       end
330     when 3
331       type = assert_type(ast, parameters[0])
332       assert_range_parameter(ast, parameters[1])
333       assert_range_parameter(ast, parameters[2])
334       size_type = TypeFactory.range(parameters[1], parameters[2])
335     else
336       raise_invalid_parameters_error('Array', '1 to 3', parameters.size)
337     end
338     TypeFactory.array_of(type, size_type)
339 
340   when 'hash'
341     case parameters.size
342     when 2
343       if parameters[0].is_a?(PAnyType) && parameters[1].is_a?(PAnyType)
344         TypeFactory.hash_of(parameters[1], parameters[0])
345       else
346         assert_range_parameter(ast, parameters[0])
347         assert_range_parameter(ast, parameters[1])
348         TypeFactory.hash_of(:default, :default, TypeFactory.range(parameters[0], parameters[1]))
349       end
350     when 3
351       size_type =
352         if parameters[2].is_a?(PIntegerType)
353           parameters[2]
354         else
355           assert_range_parameter(ast, parameters[2])
356           TypeFactory.range(parameters[2], :default)
357         end
358       assert_type(ast, parameters[0])
359       assert_type(ast, parameters[1])
360       TypeFactory.hash_of(parameters[1], parameters[0], size_type)
361     when 4
362       assert_range_parameter(ast, parameters[2])
363       assert_range_parameter(ast, parameters[3])
364       assert_type(ast, parameters[0])
365       assert_type(ast, parameters[1])
366       TypeFactory.hash_of(parameters[1], parameters[0], TypeFactory.range(parameters[2], parameters[3]))
367     else
368       raise_invalid_parameters_error('Hash', '2 to 4', parameters.size)
369     end
370 
371   when 'collection'
372     size_type = case parameters.size
373       when 1
374         if parameters[0].is_a?(PIntegerType)
375           parameters[0]
376         else
377           assert_range_parameter(ast, parameters[0])
378           TypeFactory.range(parameters[0], :default)
379         end
380       when 2
381         assert_range_parameter(ast, parameters[0])
382         assert_range_parameter(ast, parameters[1])
383         TypeFactory.range(parameters[0], parameters[1])
384       else
385         raise_invalid_parameters_error('Collection', '1 to 2', parameters.size)
386       end
387     TypeFactory.collection(size_type)
388 
389   when 'class'
390     if parameters.size != 1
391       raise_invalid_parameters_error('Class', 1, parameters.size)
392     end
393     TypeFactory.host_class(parameters[0])
394 
395   when 'resource'
396     type = parameters[0]
397     if type.is_a?(PTypeReferenceType)
398       type_str = type.type_string
399       param_start = type_str.index('[')
400       if param_start.nil?
401         type = type_str
402       else
403         tps = interpret_any(@parser.parse_string(type_str[param_start..-1]).model, context)
404         raise_invalid_parameters_error(type.to_s, '1', tps.size) unless tps.size == 1
405         type = type_str[0..param_start-1]
406         parameters = [type] + tps
407       end
408     end
409     create_resource(type, parameters)
410 
411   when 'regexp'
412     # 1 parameter being a string, or regular expression
413     raise_invalid_parameters_error('Regexp', '1', parameters.size) unless parameters.size == 1
414     TypeFactory.regexp(parameters[0])
415 
416   when 'enum'
417     # 1..m parameters being string
418     last = parameters.last
419     case_insensitive = false
420     if last == true || last == false
421       parameters = parameters[0...-1]
422       case_insensitive = last
423     end
424     raise_invalid_parameters_error('Enum', '1 or more', parameters.size) unless parameters.size >= 1
425     parameters.each { |p| raise Puppet::ParseError, _('Enum parameters must be identifiers or strings') unless p.is_a?(String) }
426     PEnumType.new(parameters, case_insensitive)
427 
428   when 'pattern'
429     # 1..m parameters being strings or regular expressions
430     raise_invalid_parameters_error('Pattern', '1 or more', parameters.size) unless parameters.size >= 1
431     TypeFactory.pattern(*parameters)
432 
433   when 'uri'
434     # 1 parameter which is a string or a URI
435     raise_invalid_parameters_error('URI', '1', parameters.size) unless parameters.size == 1
436     TypeFactory.uri(parameters[0])
437 
438   when 'variant'
439     # 1..m parameters being strings or regular expressions
440     raise_invalid_parameters_error('Variant', '1 or more', parameters.size) unless parameters.size >= 1
441     parameters.each { |p| assert_type(ast, p) }
442     TypeFactory.variant(*parameters)
443 
444   when 'tuple'
445     # 1..m parameters being types (last two optionally integer or literal default
446     raise_invalid_parameters_error('Tuple', '1 or more', parameters.size) unless parameters.size >= 1
447     length = parameters.size
448     size_type = nil
449     if TypeFactory.is_range_parameter?(parameters[-2])
450       # min, max specification
451       min = parameters[-2]
452       min = (min == :default || min == 'default') ? 0 : min
453       assert_range_parameter(ast, parameters[-1])
454       max = parameters[-1]
455       max = max == :default ? nil : max
456       parameters = parameters[0, length-2]
457       size_type = TypeFactory.range(min, max)
458     elsif TypeFactory.is_range_parameter?(parameters[-1])
459       min = parameters[-1]
460       min = (min == :default || min == 'default') ? 0 : min
461       max = nil
462       parameters = parameters[0, length-1]
463       size_type = TypeFactory.range(min, max)
464     end
465     TypeFactory.tuple(parameters, size_type)
466 
467   when 'callable'
468     # 1..m parameters being types (last three optionally integer or literal default, and a callable)
469     if parameters.size > 1 && parameters[0].is_a?(Array)
470       raise_invalid_parameters_error('callable', '2 when first parameter is an array', parameters.size) unless parameters.size == 2
471     end
472     TypeFactory.callable(*parameters)
473 
474   when 'struct'
475     # 1..m parameters being types (last two optionally integer or literal default
476     raise_invalid_parameters_error('Struct', '1', parameters.size) unless parameters.size == 1
477     h = parameters[0]
478     raise_invalid_type_specification_error(ast) unless h.is_a?(Hash)
479     TypeFactory.struct(h)
480 
481   when 'boolean'
482     raise_invalid_parameters_error('Boolean', '1', parameters.size) unless parameters.size == 1
483     p = parameters[0]
484     raise Puppet::ParseError, 'Boolean parameter must be true or false' unless p == true || p == false
485     TypeFactory.boolean(p)
486 
487   when 'integer'
488     if parameters.size == 1
489       case parameters[0]
490       when Integer
491         TypeFactory.range(parameters[0], :default)
492       when :default
493         TypeFactory.integer # unbound
494       end
495     elsif parameters.size != 2
496       raise_invalid_parameters_error('Integer', '1 or 2', parameters.size)
497     else
498       TypeFactory.range(parameters[0] == :default ? nil : parameters[0], parameters[1] == :default ? nil : parameters[1])
499     end
500 
501   when 'object'
502     raise_invalid_parameters_error('Object', 1, parameters.size) unless parameters.size == 1
503     TypeFactory.object(parameters[0])
504 
505   when 'typeset'
506     raise_invalid_parameters_error('Object', 1, parameters.size) unless parameters.size == 1
507     TypeFactory.type_set(parameters[0])
508 
509   when 'init'
510     assert_type(ast, parameters[0])
511     TypeFactory.init(*parameters)
512 
513   when 'iterable'
514     if parameters.size != 1
515       raise_invalid_parameters_error('Iterable', 1, parameters.size)
516     end
517     assert_type(ast, parameters[0])
518     TypeFactory.iterable(parameters[0])
519 
520   when 'iterator'
521     if parameters.size != 1
522       raise_invalid_parameters_error('Iterator', 1, parameters.size)
523     end
524     assert_type(ast, parameters[0])
525     TypeFactory.iterator(parameters[0])
526 
527   when 'float'
528     if parameters.size == 1
529       case parameters[0]
530       when Integer, Float
531         TypeFactory.float_range(parameters[0], :default)
532       when :default
533         TypeFactory.float # unbound
534       end
535     elsif parameters.size != 2
536       raise_invalid_parameters_error('Float', '1 or 2', parameters.size)
537     else
538       TypeFactory.float_range(parameters[0] == :default ? nil : parameters[0], parameters[1] == :default ? nil : parameters[1])
539     end
540 
541   when 'string'
542     size_type =
543     case parameters.size
544     when 1
545       if parameters[0].is_a?(PIntegerType)
546         parameters[0]
547       else
548         assert_range_parameter(ast, parameters[0])
549         TypeFactory.range(parameters[0], :default)
550       end
551     when 2
552       assert_range_parameter(ast, parameters[0])
553       assert_range_parameter(ast, parameters[1])
554       TypeFactory.range(parameters[0], parameters[1])
555     else
556       raise_invalid_parameters_error('String', '1 to 2', parameters.size)
557     end
558     TypeFactory.string(size_type)
559 
560   when 'sensitive'
561     if parameters.size == 0
562       TypeFactory.sensitive
563     elsif parameters.size == 1
564       param = parameters[0]
565       assert_type(ast, param)
566       TypeFactory.sensitive(param)
567     else
568       raise_invalid_parameters_error('Sensitive', '0 to 1', parameters.size)
569     end
570 
571   when 'optional'
572     if parameters.size != 1
573       raise_invalid_parameters_error('Optional', 1, parameters.size)
574     end
575     param = parameters[0]
576     assert_type(ast, param) unless param.is_a?(String)
577     TypeFactory.optional(param)
578 
579   when 'any', 'data', 'catalogentry', 'scalar', 'undef', 'numeric', 'default', 'semverrange'
580     raise_unparameterized_type_error(qref)
581 
582   when 'notundef'
583     case parameters.size
584     when 0
585       TypeFactory.not_undef
586     when 1
587       param = parameters[0]
588       assert_type(ast, param) unless param.is_a?(String)
589       TypeFactory.not_undef(param)
590     else
591       raise_invalid_parameters_error("NotUndef", "0 to 1", parameters.size)
592     end
593 
594   when 'type'
595     if parameters.size != 1
596       raise_invalid_parameters_error('Type', 1, parameters.size)
597     end
598     assert_type(ast, parameters[0])
599     TypeFactory.type_type(parameters[0])
600 
601   when 'runtime'
602     raise_invalid_parameters_error('Runtime', '2', parameters.size) unless parameters.size == 2
603     TypeFactory.runtime(*parameters)
604 
605   when 'timespan'
606     raise_invalid_parameters_error('Timespan', '0 to 2', parameters.size) unless parameters.size <= 2
607     TypeFactory.timespan(*parameters)
608 
609   when 'timestamp'
610     raise_invalid_parameters_error('Timestamp', '0 to 2', parameters.size) unless parameters.size <= 2
611     TypeFactory.timestamp(*parameters)
612 
613   when 'semver'
614     raise_invalid_parameters_error('SemVer', '1 or more', parameters.size) unless parameters.size >= 1
615     TypeFactory.sem_ver(*parameters)
616 
617   else
618     loader = loader_from_context(qref, context)
619     type = nil
620     unless loader.nil?
621       type = loader.load(:type, type_name)
622       type = type.resolve(loader) unless type.nil?
623     end
624 
625     if type.nil?
626       TypeFactory.type_reference(original_text_of(ast))
627     elsif type.is_a?(PResourceType)
628       raise_invalid_parameters_error(qref.cased_value, 1, parameters.size) unless parameters.size == 1
629       TypeFactory.resource(type.type_name, parameters[0])
630     elsif type.is_a?(PObjectType)
631       PObjectTypeExtension.create(type, parameters)
632     else
633       # Must be a type alias. They can't use parameters (yet)
634       raise_unparameterized_type_error(qref)
635     end
636   end
637 end
interpret_HeredocExpression(o, context) click to toggle source

@api private

   # File lib/puppet/pops/types/type_parser.rb
93 def interpret_HeredocExpression(o, context)
94   interpret_any(o.text_expr, context)
95 end
interpret_LambdaExpression(o, context) click to toggle source

@api private

   # File lib/puppet/pops/types/type_parser.rb
88 def interpret_LambdaExpression(o, context)
89   o
90 end
interpret_LiteralBoolean(o, context) click to toggle source

@api private

    # File lib/puppet/pops/types/type_parser.rb
103 def interpret_LiteralBoolean(o, context)
104   o.value
105 end
interpret_LiteralDefault(o, context) click to toggle source

@api private

    # File lib/puppet/pops/types/type_parser.rb
108 def interpret_LiteralDefault(o, context)
109   :default
110 end
interpret_LiteralFloat(o, context) click to toggle source

@api private

    # File lib/puppet/pops/types/type_parser.rb
113 def interpret_LiteralFloat(o, context)
114   o.value
115 end
interpret_LiteralHash(o, context) click to toggle source

@api private

    # File lib/puppet/pops/types/type_parser.rb
118 def interpret_LiteralHash(o, context)
119   result = {}
120   o.entries.each do |entry|
121     result[@type_transformer.visit_this_1(self, entry.key, context)] = @type_transformer.visit_this_1(self, entry.value, context)
122   end
123   result
124 end
interpret_LiteralInteger(o, context) click to toggle source

@api private

    # File lib/puppet/pops/types/type_parser.rb
127 def interpret_LiteralInteger(o, context)
128   o.value
129 end
interpret_LiteralList(o, context) click to toggle source

@api private

    # File lib/puppet/pops/types/type_parser.rb
132 def interpret_LiteralList(o, context)
133   o.values.map { |value| @type_transformer.visit_this_1(self, value, context) }
134 end
interpret_LiteralRegularExpression(o, context) click to toggle source

@api private

    # File lib/puppet/pops/types/type_parser.rb
137 def interpret_LiteralRegularExpression(o, context)
138   o.value
139 end
interpret_LiteralString(o, context) click to toggle source

@api private

    # File lib/puppet/pops/types/type_parser.rb
142 def interpret_LiteralString(o, context)
143   o.value
144 end
interpret_LiteralUndef(o, context) click to toggle source

@api private

    # File lib/puppet/pops/types/type_parser.rb
147 def interpret_LiteralUndef(o, context)
148   nil
149 end
interpret_Object(o, context) click to toggle source

@api private

   # File lib/puppet/pops/types/type_parser.rb
68 def interpret_Object(o, context)
69   raise_invalid_type_specification_error(o)
70 end
interpret_Program(o, context) click to toggle source

@api private

   # File lib/puppet/pops/types/type_parser.rb
73 def interpret_Program(o, context)
74   interpret_any(o.body, context)
75 end
interpret_QualifiedName(o, context) click to toggle source

@api private

    # File lib/puppet/pops/types/type_parser.rb
 98 def interpret_QualifiedName(o, context)
 99   o.value
100 end
interpret_QualifiedReference(name_ast, context) click to toggle source

@api private

    # File lib/puppet/pops/types/type_parser.rb
274 def interpret_QualifiedReference(name_ast, context)
275   name = name_ast.value
276   found = self.class.type_map[name]
277   if found
278     found
279   else
280     loader = loader_from_context(name_ast, context)
281     unless loader.nil?
282       type = loader.load(:type, name)
283       type = type.resolve(loader) unless type.nil?
284     end
285     type || TypeFactory.type_reference(name_ast.cased_value)
286   end
287 end
interpret_String(o, context) click to toggle source

@api private

    # File lib/puppet/pops/types/type_parser.rb
152 def interpret_String(o, context)
153   o
154 end
interpret_TypeAlias(o, context) click to toggle source

@api private

   # File lib/puppet/pops/types/type_parser.rb
78 def interpret_TypeAlias(o, context)
79   Loader::TypeDefinitionInstantiator.create_type(o.name, o.type_expr, Pcore::RUNTIME_NAME_AUTHORITY).resolve(loader_from_context(o, context))
80 end
interpret_TypeDefinition(o, context) click to toggle source

@api private

   # File lib/puppet/pops/types/type_parser.rb
83 def interpret_TypeDefinition(o, context)
84   Loader::TypeDefinitionInstantiator.create_runtime_type(o)
85 end
interpret_UnaryMinusExpression(o, context) click to toggle source

@api private

    # File lib/puppet/pops/types/type_parser.rb
157 def interpret_UnaryMinusExpression(o, context)
158   -@type_transformer.visit_this_1(self, o.expr, context)
159 end
interpret_any(ast, context) click to toggle source

@api private

   # File lib/puppet/pops/types/type_parser.rb
63 def interpret_any(ast, context)
64   @type_transformer.visit_this_1(self, ast, context)
65 end
loader_from_context(ast, context) click to toggle source

@api private

    # File lib/puppet/pops/types/type_parser.rb
290 def loader_from_context(ast, context)
291   model_loader = Adapters::LoaderAdapter.loader_for_model_object(ast, nil, context)
292   if context.is_a?(PTypeSetType::TypeSetLoader)
293     # Only swap a given TypeSetLoader for another loader when the other loader is different
294     # from the one associated with the TypeSet expression
295     context.model_loader.equal?(model_loader.parent) ? context : model_loader
296   else
297     model_loader
298   end
299 end
parse(string, context = nil) click to toggle source

Produces a *puppet type* based on the given string.

@example

parser.parse('Integer')
parser.parse('Array[String]')
parser.parse('Hash[Integer, Array[String]]')

@param string [String] a string with the type expressed in stringified form as produced by the

types {"#to_s} method.

@param context [Loader::Loader] optional loader used as no adapted loader is found @return [PAnyType] a specialization of the PAnyType representing the type.

@api public

   # File lib/puppet/pops/types/type_parser.rb
35 def parse(string, context = nil)
36   # quick "peephole" optimization of common data types
37   t = self.class.opt_type_map[string]
38   if t
39     return t
40   end
41   model = @parser.parse_string(string)
42   interpret(model.model.body, context)
43 end
parse_literal(string, context = nil) click to toggle source

@api private

   # File lib/puppet/pops/types/type_parser.rb
46 def parse_literal(string, context = nil)
47   factory = @parser.parse_string(string)
48   interpret_any(factory.model.body, context)
49 end

Private Instance Methods

assert_range_parameter(ast, t) click to toggle source
    # File lib/puppet/pops/types/type_parser.rb
656 def assert_range_parameter(ast, t)
657   raise_invalid_type_specification_error(ast) unless TypeFactory.is_range_parameter?(t)
658 end
assert_type(ast, t) click to toggle source
    # File lib/puppet/pops/types/type_parser.rb
651 def assert_type(ast, t)
652   raise_invalid_type_specification_error(ast) unless t.is_a?(PAnyType)
653   t
654 end
create_resource(name, parameters) click to toggle source
    # File lib/puppet/pops/types/type_parser.rb
641 def create_resource(name, parameters)
642   if parameters.size == 1
643     TypeFactory.resource(name)
644   elsif parameters.size == 2
645     TypeFactory.resource(name, parameters[1])
646   else
647     raise_invalid_parameters_error('Resource', '1 or 2', parameters.size)
648   end
649 end
original_text_of(ast) click to toggle source
    # File lib/puppet/pops/types/type_parser.rb
678 def original_text_of(ast)
679   ast.locator.extract_tree_text(ast)
680 end
raise_invalid_parameters_error(type, required, given) click to toggle source
    # File lib/puppet/pops/types/type_parser.rb
665 def raise_invalid_parameters_error(type, required, given)
666   raise Puppet::ParseError, _("Invalid number of type parameters specified: %{type} requires %{required}, %{given} provided") %
667       { type: type, required: required, given: given }
668 end
raise_invalid_type_specification_error(ast) click to toggle source
    # File lib/puppet/pops/types/type_parser.rb
660 def raise_invalid_type_specification_error(ast)
661   raise Puppet::ParseError, _("The expression <%{expression}> is not a valid type specification.") %
662       { expression: original_text_of(ast) }
663 end
raise_unknown_type_error(ast) click to toggle source
    # File lib/puppet/pops/types/type_parser.rb
674 def raise_unknown_type_error(ast)
675   raise Puppet::ParseError, _("Unknown type <%{type}>") % { type: original_text_of(ast) }
676 end
raise_unparameterized_type_error(ast) click to toggle source
    # File lib/puppet/pops/types/type_parser.rb
670 def raise_unparameterized_type_error(ast)
671   raise Puppet::ParseError, _("Not a parameterized type <%{type}>") % { type: original_text_of(ast) }
672 end