Class: Xumlidot::Parsers::KlassDefinition

Inherits:
MethodBasedSexpProcessor
  • Object
show all
Defined in:
lib/xumlidot/parsers/klass_definition.rb

Overview

Parser for the KLASS DEFINITION ONLY

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exp, namespace = nil) ⇒ KlassDefinition

Returns a new instance of KlassDefinition.



13
14
15
16
17
18
19
20
# 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

Instance Attribute Details

#definitionObject (readonly)

Returns the value of attribute definition.



11
12
13
# File 'lib/xumlidot/parsers/klass_definition.rb', line 11

def definition
  @definition
end

Instance Method Details

#process_class(exp) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 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) ⇒ Object



60
61
62
63
64
65
# 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) ⇒ Object



67
68
69
70
71
72
73
# 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) ⇒ Object



53
54
55
56
57
58
# 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