summaryrefslogtreecommitdiffhomepage
path: root/lib/yard/mruby/handlers/c/header/function_handler.rb
blob: 11f8efcb6e009333ae83148959dec6f22fff2978 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module YARD::MRuby::Handlers::C::Header
  class FunctionHandler < Base
    MATCH = /
      MRB_(API|INLINE)\s+
      ((struct\s+)?\w+(\s*\*)?)\s*
      ((\w+\s+)+)?(\w+)\s*\(
    /mx
      #\(([\w\*,]*)\)

    handles MATCH
    statement_class ToplevelStatement

    process do
      handle_function(statement)
    end

    def handle_function(statement)
      header = self.header(statement.file)

["API", "mrb_value", nil, nil, nil, nil, "sample_api_method"]
      statement.source.scan(MATCH) do |type, retype, _,_,_,_, name, *args|
        puts args.inspect
        register FunctionObject.new(header, name) do |obj|
          if statement.comments
            register_docstring(obj, statement.comments.source, statement)
          end

          if retype != 'void'
            obj.add_tag(YARD::Tags::Tag.new(:return,"", "")) unless obj.has_tag?(:return)
            obj.tag(:return).types = [retype] 
          end

        end
      end
    end
  end
end