class Puppet::Pops::Types::TypeParser

Public Class Methods

new() click to toggle source

@api public

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

@api private

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

@api private

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

@api private

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

@api private

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

@api private

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

@api private

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

@api private

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

@api private

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

@api private

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

@api private

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

@api private

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

@api private

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

@api private

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

@api private

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

@api private

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

@api private

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

@api private

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

@api private

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

@api private

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

@api private

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

@api private

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

@api private

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

@api private

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

@api private

    # File lib/puppet/pops/types/type_parser.rb
291 def loader_from_context(ast, context)
292   model_loader = Adapters::LoaderAdapter.loader_for_model_object(ast, nil, context)
293   if context.is_a?(PTypeSetType::TypeSetLoader)
294     # Only swap a given TypeSetLoader for another loader when the other loader is different
295     # from the one associated with the TypeSet expression
296     context.model_loader.equal?(model_loader.parent) ? context : model_loader
297   else
298     model_loader
299   end
300 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
36 def parse(string, context = nil)
37   # quick "peephole" optimization of common data types
38   t = self.class.opt_type_map[string]
39   if t
40     return t
41   end
42   model = @parser.parse_string(string)
43   interpret(model.model.body, context)
44 end
parse_literal(string, context = nil) click to toggle source

@api private

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

Private Instance Methods

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