3 class RDoc::RI::Error < RuntimeError; end
6 # Break argument into its constituent class or module names, an
7 # optional method type, and a method name
9 class RDoc::RI::NameDescriptor
11 attr_reader :class_names
12 attr_reader :method_name
15 # true and false have the obvious meaning. nil means we don't care
17 attr_reader :is_class_method
22 # 1. A class or module name (optionally qualified with other class or module
23 # names (Kernel, File::Stat etc)
25 # 3. A method name qualified by a optionally fully qualified class or module
28 # We're fairly casual about delimiters: folks can say Kernel::puts,
29 # Kernel.puts, or Kernel\#puts for example. There's one exception: if you
30 # say IO::read, we look for a class method, but if you say IO.read, we look
31 # for an instance method
37 tokens = arg.split(/(\.|::|#)/)
39 # Skip leading '::', '#' or '.', but remember it might
40 # be a method name qualifier
41 separator = tokens.shift if tokens[0] =~ /^(\.|::|#)/
43 # Skip leading '::', but remember we potentially have an inst
45 # leading stuff must be class names
47 while tokens[0] =~ /^[A-Z]/
48 @class_names << tokens.shift
50 separator = tokens.shift
51 break unless separator == "::"
55 # Now must have a single token, the method name, or an empty array
57 @method_name = tokens.shift
58 # We may now have a trailing !, ?, or = to roll into
60 if !tokens.empty? && tokens[0] =~ /^[!?=]$/
61 @method_name << tokens.shift
64 if @method_name =~ /::|\.|#/ or !tokens.empty?
65 raise RDoc::RI::Error.new("Bad argument: #{arg}")
67 if separator && separator != '.'
68 @is_class_method = separator == "::"
73 # Return the full class name (with '::' between the components) or "" if
74 # there's no class name
77 @class_names.join("::")