Class: Xumlidot::Parsers::Call

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exp, klass) ⇒ Call

Returns a new instance of Call.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/xumlidot/parsers/call.rb', line 11

def initialize(exp, klass)
  super()

  @klass = klass
  @modules = ::Xumlidot::Types::InheritedModule.new(nil)

  process(exp)

  return if klass.definition.nil?
  klass.definition.inherited_modules << @modules
end

Instance Attribute Details

#definitionObject (readonly)

Returns the value of attribute definition.



9
10
11
# File 'lib/xumlidot/parsers/call.rb', line 9

def definition
  @definition
end

Instance Method Details

#add_attributes(name, exp, read: false, write: false) ⇒ Object



61
62
63
64
65
66
# File 'lib/xumlidot/parsers/call.rb', line 61

def add_attributes(name, exp, read: false, write: false)
  @klass.attributes << ::Xumlidot::Types::Attribute.new(name.value, read, write)
  exp.each do |attribute|
    @klass.attributes << ::Xumlidot::Types::Attribute.new(attribute.value, read, write)
  end
end

#process_call(exp) ⇒ Object



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
52
53
54
55
56
57
58
59
# File 'lib/xumlidot/parsers/call.rb', line 23

def process_call(exp)
  exp.shift # remove the :call

  begin
    recv = process(exp.shift)
  rescue => e
    STDERR.puts " ** bug: unable to calculate reciever for #{exp}"
  end

  name = exp.shift
  args = exp.shift

  case name
  when :private, :public, :protected
    ::Xumlidot::Parsers::Scope.set_visibility(name)
  when :include
    @modules.type = :include
    process(args)
  when :extend
    @modules.type = :extend
    process(args)
  when :prepend
    @modules.type = :prepend
    process(args)
  when :module_function
    # TODO: expose as an instance method on the module
  when :attr_reader
    add_attributes(args, exp, read: true)
  when :attr_writer
    add_attributes(args, exp, write: true)
  when :attr_accessor
    add_attributes(args, exp, read: true, write: true)
  # else
    # puts "CALL RECV:#{recv unless recv.nil? || recv.empty?} NAME:#{name} ARGS:#{args unless args.nil? || args.empty?}"
  end
  s()
end

#process_colon2(exp) ⇒ Object



75
76
77
78
79
80
# File 'lib/xumlidot/parsers/call.rb', line 75

def process_colon2(exp)
  exp.shift # remove :colon2
  @modules << exp.value
  process_until_empty(exp)
  s()
end

#process_colon3(exp) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/xumlidot/parsers/call.rb', line 82

def process_colon3(exp)
  exp.shift # remove :colon3
  @modules << '::'
  @modules << exp.value
  process_until_empty(exp)
  s()
end

#process_const(exp) ⇒ Object



68
69
70
71
72
73
# File 'lib/xumlidot/parsers/call.rb', line 68

def process_const(exp)
  # exp.shift # remove :const
  @modules << exp.value
  process_until_empty(exp)
  s()
end