Method: Puppet::Pops::Types::TypeParser#parse

Defined in:
lib/puppet/pops/types/type_parser.rb

#parse(string, context = nil) ⇒ PAnyType

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

Examples:

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

Parameters:

  • string (String)

    a string with the type expressed in stringified form as produced by the types Puppet::Pops::Types::TypeParser.““#to_s method.

  • context (Loader::Loader) (defaults to: nil)

    optional loader used as no adapted loader is found

Returns:

  • (PAnyType)

    a specialization of the PAnyType representing the type.



37
38
39
40
41
42
43
44
45
46
# File 'lib/puppet/pops/types/type_parser.rb', line 37

def parse(string, context = nil)
  # quick "peephole" optimization of common data types
  t = self.class.opt_type_map[string]
  if t
    return t
  end

  model = @parser.parse_string(string)
  interpret(model.model.body, context)
end