1
# type.rb: named types, based on metabuilder
2
# copyright (c) 2009 by Vincent Fourmond
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details (in the COPYING file).
14
require 'ctioga2/utils'
15
require 'ctioga2/metabuilder/types'
19
Version::register_svn_info('$Revision: 173 $', '$Date: 2010-10-22 21:41:39 +0200 (Fri, 22 Oct 2010) $')
23
# A named type, based on CTioga2::MetaBuilder::Type
25
# @todo *Structural* in real, I don't think it is necessary
26
# anymore to rely on MetaBuilder, as most types in CTioga2 already
27
# provide a from_text class function that does a nice job. I
28
# should convert as many things as possible to using that.
31
# The underlying CTioga2::MetaBuilder::Type object.
34
# The unique identification of this type.
37
# The description of this type
38
attr_accessor :description
40
# The context of definition [file, line]
41
attr_accessor :context
44
# Makes sure the return value is a CommandType. Will fail
46
def self.get_type(obj)
47
if obj.is_a? CommandType
52
"Converting type specification #{obj.inspect} to string at #{caller[1]}"
56
type = Interpreter::type(obj)
60
raise InvalidType, "Type #{obj.inspect} unknown"
65
# _type_ is the type of the argument in a descriptive fashion,
66
# as could be fed to CTioga2::MetaBuilder::Type.get_type, or
67
# directly a MetaBuilder::Type object.
68
def initialize(name, type, desc = nil)
69
if type.is_a? MetaBuilder::Type
72
@type = CTioga2::MetaBuilder::Type.get_type(type)
76
caller[1].gsub(/.*\/ctioga2\//, 'lib/ctioga2/') =~ /(.*):(\d+)/
77
@context = [$1, $2.to_i]
79
Interpreter::register_type(self)
82
# Now, a series of redirection from/to the underlying
83
# MetaBuilder::Type object.
85
# Whether this is a boolean type or not.
90
# Does the actual conversion from string to the real type
91
def string_to_type(str)
92
return @type.string_to_type(str)
95
# Returns the long option for the option parser.
97
# \todo maybe this should be rethought a bit ?
98
def option_parser_long_option(name, param = nil)
99
return @type.option_parser_long_option(name, param)