summaryrefslogtreecommitdiffhomepage
path: root/lib/yard/mruby
diff options
context:
space:
mode:
authorSeba Gamboa <[email protected]>2015-09-24 15:27:31 -0300
committerSeba Gamboa <[email protected]>2015-09-24 15:27:31 -0300
commitcc49ade5e7029e4d8d8d62b7c09590042b43d65d (patch)
tree370d836801a48940e41d756171111fd1dcbb22aa /lib/yard/mruby
parent25ce0e81e111915551751dfaa23c4b53ec32afaf (diff)
downloadyard-mruby-cc49ade5e7029e4d8d8d62b7c09590042b43d65d.tar.gz
yard-mruby-cc49ade5e7029e4d8d8d62b7c09590042b43d65d.zip
Registering function objects
Diffstat (limited to 'lib/yard/mruby')
-rw-r--r--lib/yard/mruby/code_objects/function_object.rb8
-rw-r--r--lib/yard/mruby/handlers/c/base.rb1
-rw-r--r--lib/yard/mruby/handlers/header.rb1
-rw-r--r--lib/yard/mruby/handlers/header/base.rb22
-rw-r--r--lib/yard/mruby/handlers/header/function_handler.rb23
5 files changed, 54 insertions, 1 deletions
diff --git a/lib/yard/mruby/code_objects/function_object.rb b/lib/yard/mruby/code_objects/function_object.rb
index 5eb906e..60ff951 100644
--- a/lib/yard/mruby/code_objects/function_object.rb
+++ b/lib/yard/mruby/code_objects/function_object.rb
@@ -2,6 +2,14 @@ module YARD::MRuby::CodeObjects
# A FunctionObject represents a MRuby C API function declaration inside a header inside an include directory
class FunctionObject < YARD::CodeObjects::Base
+ def initialize(header, name, &block)
+ super
+ end
+
+ # Function's shouln't be namespaced
+ def path
+ self.name
+ end
end
end
diff --git a/lib/yard/mruby/handlers/c/base.rb b/lib/yard/mruby/handlers/c/base.rb
index 6f17c37..32a48aa 100644
--- a/lib/yard/mruby/handlers/c/base.rb
+++ b/lib/yard/mruby/handlers/c/base.rb
@@ -45,6 +45,7 @@ module YARD::MRuby::Handlers
end
end
+
end
YARD::Handlers::Processor.register_handler_namespace :C, C
diff --git a/lib/yard/mruby/handlers/header.rb b/lib/yard/mruby/handlers/header.rb
index 5737dd1..590386f 100644
--- a/lib/yard/mruby/handlers/header.rb
+++ b/lib/yard/mruby/handlers/header.rb
@@ -1 +1,2 @@
require_relative 'header/base'
+require_relative 'header/function_handler'
diff --git a/lib/yard/mruby/handlers/header/base.rb b/lib/yard/mruby/handlers/header/base.rb
index d3e5491..58178fe 100644
--- a/lib/yard/mruby/handlers/header/base.rb
+++ b/lib/yard/mruby/handlers/header/base.rb
@@ -1,7 +1,27 @@
module YARD::MRuby::Handlers
module Header
- class Base < YARD::Handlers::Base
+ class Base < YARD::Handlers::C::Base
+ include YARD::MRuby::CodeObjects
+
+ def header(path)
+ # Remove include prefix
+ path = path.gsub(/^.*include\//,'')
+
+ headers[path] ||= begin
+ header = HeaderObject.new(:root, path)
+ register header
+ header
+ end
+
+
+ end
+
+ def headers
+ globals.mruby_headers ||= {}
+ end
+
end
+
end
YARD::Handlers::Processor.register_handler_namespace :header, Header
diff --git a/lib/yard/mruby/handlers/header/function_handler.rb b/lib/yard/mruby/handlers/header/function_handler.rb
index e69de29..9b98258 100644
--- a/lib/yard/mruby/handlers/header/function_handler.rb
+++ b/lib/yard/mruby/handlers/header/function_handler.rb
@@ -0,0 +1,23 @@
+module YARD::MRuby::Handlers::Header
+ class FunctionHandler < Base
+ MATCH = /
+ MRB_(API|INLINE)\s+((\w+\s+)+)(\w+)\s*\(
+ /mx
+
+ handles MATCH
+ statement_class ToplevelStatement
+
+ process do
+ handle_function(statement)
+ end
+
+ def handle_function(statement)
+ header = self.header(statement.file)
+
+ statement.source.scan(MATCH) do |type, prefix, _, name, *args|
+ register FunctionObject.new(header, name) do |obj|
+ end
+ end
+ end
+ end
+end