class Xumlidot::Parsers::KlassDefinition

Parser for the KLASS DEFINITION ONLY

Attributes

definition[R]

Public Class Methods

new(exp, namespace = nil) click to toggle source
Calls superclass method
# File lib/xumlidot/parsers/klass_definition.rb, line 13
def initialize(exp, namespace = nil)
  super()

  @definition = ::Xumlidot::Types::KlassDefinition.new
  @namespace = namespace.dup

  process(exp)
end

Public Instance Methods

process_class(exp) click to toggle source
# File lib/xumlidot/parsers/klass_definition.rb, line 22
def process_class(exp)
  exp.shift # remove :class
  definition = exp.shift

  # Processes the name of the class
  if Sexp === definition
    case definition.sexp_type
    when :colon2 then # Reached in the event that a name is a compound
      name = definition.flatten
      name.delete :const
      name.delete :colon2
      name.each do |v|
        @definition.name << ::Xumlidot::Types::Constant.new(v, @namespace)
      end
    when :colon3 then # Reached in the event that a name begins with ::
      @definition.name << ::Xumlidot::Types::Constant.new(definition.last, '::')
    else
      raise "unknown type #{exp.inspect}"
    end
  else Symbol === definition
    #if we have a symbol we have the actual class name
    # e.g. class Foo; end
    @definition.name << ::Xumlidot::Types::Constant.new(definition, @namespace)
  end

  # Processess inheritance
  process_until_empty(exp)

  s()
end
process_colon2(exp) click to toggle source
# File lib/xumlidot/parsers/klass_definition.rb, line 60
def process_colon2(exp)
  exp.shift # remove :colon2
  @definition.superklass << exp.value
  process_until_empty(exp)
  s()
end
process_colon3(exp) click to toggle source
# File lib/xumlidot/parsers/klass_definition.rb, line 67
def process_colon3(exp)
  exp.shift # remove :colon3
  @definition.superklass << '::'
  @definition.superklass << exp.value
  process_until_empty(exp)
  s()
end
process_const(exp) click to toggle source
# File lib/xumlidot/parsers/klass_definition.rb, line 53
def process_const(exp)
  # TODO: may have removed a shift by mistake
  @definition.superklass << exp.value
  process_until_empty(exp)
  s()
end