summaryrefslogtreecommitdiffhomepage
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
parent25ce0e81e111915551751dfaa23c4b53ec32afaf (diff)
downloadyard-mruby-cc49ade5e7029e4d8d8d62b7c09590042b43d65d.tar.gz
yard-mruby-cc49ade5e7029e4d8d8d62b7c09590042b43d65d.zip
Registering function objects
-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
-rw-r--r--spec/handlers/header/function_handler_spec.rb10
-rw-r--r--spec/handlers/header/spec_helper.rb21
7 files changed, 85 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
diff --git a/spec/handlers/header/function_handler_spec.rb b/spec/handlers/header/function_handler_spec.rb
new file mode 100644
index 0000000..8ad5334
--- /dev/null
+++ b/spec/handlers/header/function_handler_spec.rb
@@ -0,0 +1,10 @@
+require_relative 'spec_helper'
+
+describe YARD::MRuby::Handlers::Header::FunctionHandler do
+ it "should register functions" do
+ header_line <<-eof
+ MRB_API void mrb_foo( void );
+ eof
+ expect(Registry.at('mrb_foo')).not_to be_nil
+ end
+end
diff --git a/spec/handlers/header/spec_helper.rb b/spec/handlers/header/spec_helper.rb
new file mode 100644
index 0000000..da2b74f
--- /dev/null
+++ b/spec/handlers/header/spec_helper.rb
@@ -0,0 +1,21 @@
+
+require_relative '../spec_helper'
+
+def header(src, file = 'stdin.h')
+ YARD::Registry.clear
+ parser = YARD::Parser::SourceParser.new(:header)
+ parser.file = file
+ parser.parse(StringIO.new(src))
+end
+
+def header_line(src)
+ header <<-EOF
+ #include "mruby.h"
+ #ifndef HEADER_H
+ #define HEADER_H
+ MRB_BEGIN_DECL
+ #{src}
+ MRB_END_DECL
+ #endif
+ EOF
+end