yard 0.7.5 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of yard might be problematic. Click here for more details.
- data/.yardopts +10 -2
- data/ChangeLog +1263 -38
- data/LEGAL +5 -5
- data/LICENSE +1 -1
- data/README.md +91 -82
- data/Rakefile +6 -6
- data/benchmarks/builtins_vs_eval.rb +1 -1
- data/benchmarks/erb_vs_erubis.rb +4 -4
- data/benchmarks/generation.rb +5 -5
- data/benchmarks/parsing.rb +2 -2
- data/benchmarks/registry_store_types.rb +48 -0
- data/bin/yard +9 -1
- data/bin/yardoc +9 -1
- data/bin/yri +10 -2
- data/docs/CodeObjects.md +10 -10
- data/docs/GettingStarted.md +85 -83
- data/docs/Handlers.md +21 -21
- data/docs/Overview.md +7 -7
- data/docs/Parser.md +30 -30
- data/docs/Tags.md +250 -554
- data/docs/TagsArch.md +123 -0
- data/docs/Templates.md +58 -80
- data/docs/WhatsNew.md +378 -133
- data/docs/templates/default/fulldoc/html/full_list_tag.erb +7 -0
- data/docs/templates/default/fulldoc/html/setup.rb +6 -0
- data/docs/templates/default/layout/html/setup.rb +8 -0
- data/docs/templates/default/layout/html/tag_list.erb +11 -0
- data/docs/templates/default/yard_tags/html/list.erb +18 -0
- data/docs/templates/default/yard_tags/html/setup.rb +27 -0
- data/docs/templates/plugin.rb +65 -0
- data/lib/yard.rb +1 -10
- data/lib/yard/autoload.rb +75 -27
- data/lib/yard/cli/command.rb +5 -2
- data/lib/yard/cli/command_parser.rb +3 -2
- data/lib/yard/cli/diff.rb +1 -1
- data/lib/yard/cli/i18n.rb +69 -0
- data/lib/yard/cli/list.rb +1 -1
- data/lib/yard/cli/server.rb +30 -7
- data/lib/yard/cli/stats.rb +5 -6
- data/lib/yard/cli/yardoc.rb +95 -45
- data/lib/yard/cli/yri.rb +24 -3
- data/lib/yard/code_objects/base.rb +35 -4
- data/lib/yard/code_objects/extra_file_object.rb +1 -1
- data/lib/yard/code_objects/macro_object.rb +56 -99
- data/lib/yard/code_objects/method_object.rb +44 -6
- data/lib/yard/config.rb +18 -8
- data/lib/yard/core_ext/symbol_hash.rb +1 -1
- data/lib/yard/docstring.rb +45 -85
- data/lib/yard/docstring_parser.rb +269 -0
- data/lib/yard/handlers/base.rb +129 -118
- data/lib/yard/handlers/c/alias_handler.rb +15 -0
- data/lib/yard/handlers/c/attribute_handler.rb +13 -0
- data/lib/yard/handlers/c/base.rb +110 -0
- data/lib/yard/handlers/c/class_handler.rb +26 -0
- data/lib/yard/handlers/c/constant_handler.rb +12 -0
- data/lib/yard/handlers/c/handler_methods.rb +165 -0
- data/lib/yard/handlers/c/init_handler.rb +16 -0
- data/lib/yard/handlers/c/method_handler.rb +35 -0
- data/lib/yard/handlers/c/mixin_handler.rb +13 -0
- data/lib/yard/handlers/c/module_handler.rb +16 -0
- data/lib/yard/handlers/c/override_comment_handler.rb +22 -0
- data/lib/yard/handlers/c/path_handler.rb +10 -0
- data/lib/yard/handlers/c/struct_handler.rb +12 -0
- data/lib/yard/handlers/c/symbol_handler.rb +7 -0
- data/lib/yard/handlers/processor.rb +41 -30
- data/lib/yard/handlers/ruby/alias_handler.rb +0 -2
- data/lib/yard/handlers/ruby/attribute_handler.rb +16 -17
- data/lib/yard/handlers/ruby/base.rb +10 -6
- data/lib/yard/handlers/ruby/comment_handler.rb +9 -0
- data/lib/yard/handlers/ruby/dsl_handler.rb +14 -0
- data/lib/yard/handlers/ruby/dsl_handler_methods.rb +71 -0
- data/lib/yard/handlers/ruby/legacy/alias_handler.rb +0 -3
- data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +16 -17
- data/lib/yard/handlers/ruby/legacy/base.rb +28 -6
- data/lib/yard/handlers/ruby/legacy/comment_handler.rb +9 -0
- data/lib/yard/handlers/ruby/legacy/dsl_handler.rb +16 -0
- data/lib/yard/handlers/ruby/legacy/method_handler.rb +0 -2
- data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +1 -1
- data/lib/yard/handlers/ruby/legacy/module_function_handler.rb +18 -0
- data/lib/yard/handlers/ruby/method_handler.rb +10 -15
- data/lib/yard/handlers/ruby/mixin_handler.rb +1 -1
- data/lib/yard/handlers/ruby/module_function_handler.rb +26 -0
- data/lib/yard/handlers/ruby/struct_handler_methods.rb +3 -2
- data/lib/yard/i18n/pot_generator.rb +281 -0
- data/lib/yard/i18n/text.rb +72 -0
- data/lib/yard/logging.rb +3 -7
- data/lib/yard/options.rb +216 -0
- data/lib/yard/parser/c/c_parser.rb +225 -0
- data/lib/yard/parser/c/comment_parser.rb +131 -0
- data/lib/yard/parser/c/statement.rb +63 -0
- data/lib/yard/parser/ruby/ast_node.rb +91 -1
- data/lib/yard/parser/ruby/legacy/ruby_parser.rb +1 -0
- data/lib/yard/parser/ruby/legacy/statement.rb +7 -2
- data/lib/yard/parser/ruby/legacy/statement_list.rb +13 -22
- data/lib/yard/parser/ruby/ruby_parser.rb +87 -26
- data/lib/yard/parser/source_parser.rb +89 -88
- data/lib/yard/rake/yardoc_task.rb +1 -1
- data/lib/yard/registry.rb +21 -10
- data/lib/yard/registry_store.rb +48 -0
- data/lib/yard/serializers/file_system_serializer.rb +18 -20
- data/lib/yard/serializers/yardoc_serializer.rb +1 -0
- data/lib/yard/server/adapter.rb +2 -2
- data/lib/yard/server/commands/base.rb +1 -1
- data/lib/yard/server/commands/display_object_command.rb +13 -6
- data/lib/yard/server/commands/frames_command.rb +4 -21
- data/lib/yard/server/commands/library_command.rb +57 -11
- data/lib/yard/server/commands/list_command.rb +10 -34
- data/lib/yard/server/commands/search_command.rb +8 -2
- data/lib/yard/server/doc_server_helper.rb +34 -0
- data/lib/yard/server/rack_adapter.rb +5 -1
- data/lib/yard/server/router.rb +4 -10
- data/lib/yard/server/static_caching.rb +2 -2
- data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +2 -2
- data/lib/yard/server/templates/default/fulldoc/html/js/live.js +0 -15
- data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +3 -3
- data/lib/yard/server/templates/default/layout/html/script_setup.erb +8 -0
- data/lib/yard/server/templates/doc_server/processing/html/processing.erb +1 -1
- data/lib/yard/server/templates/doc_server/search/html/setup.rb +1 -1
- data/lib/yard/tags/default_factory.rb +31 -4
- data/lib/yard/tags/directives.rb +593 -0
- data/lib/yard/tags/library.rb +437 -35
- data/lib/yard/templates/engine.rb +17 -12
- data/lib/yard/templates/helpers/base_helper.rb +8 -2
- data/lib/yard/templates/helpers/html_helper.rb +57 -14
- data/lib/yard/templates/helpers/markup/rdoc_markup.rb +1 -1
- data/lib/yard/templates/helpers/markup_helper.rb +9 -9
- data/lib/yard/templates/helpers/text_helper.rb +2 -2
- data/lib/yard/templates/template.rb +42 -13
- data/lib/yard/templates/template_options.rb +81 -0
- data/spec/cli/command_parser_spec.rb +4 -4
- data/spec/cli/command_spec.rb +3 -3
- data/spec/cli/config_spec.rb +13 -13
- data/spec/cli/diff_spec.rb +13 -10
- data/spec/cli/gems_spec.rb +12 -12
- data/spec/cli/help_spec.rb +2 -2
- data/spec/cli/i18n_spec.rb +111 -0
- data/spec/cli/server_spec.rb +66 -18
- data/spec/cli/stats_spec.rb +15 -15
- data/spec/cli/yardoc_spec.rb +124 -97
- data/spec/cli/yri_spec.rb +14 -12
- data/spec/code_objects/base_spec.rb +104 -46
- data/spec/code_objects/class_object_spec.rb +33 -33
- data/spec/code_objects/code_object_list_spec.rb +5 -5
- data/spec/code_objects/constants_spec.rb +4 -3
- data/spec/code_objects/extra_file_object_spec.rb +19 -19
- data/spec/code_objects/macro_object_spec.rb +31 -37
- data/spec/code_objects/method_object_spec.rb +46 -23
- data/spec/code_objects/module_object_spec.rb +16 -16
- data/spec/code_objects/namespace_object_spec.rb +6 -6
- data/spec/code_objects/proxy_spec.rb +19 -19
- data/spec/config_spec.rb +33 -24
- data/spec/core_ext/array_spec.rb +1 -1
- data/spec/core_ext/file_spec.rb +8 -8
- data/spec/core_ext/hash_spec.rb +1 -1
- data/spec/core_ext/insertion_spec.rb +3 -3
- data/spec/core_ext/module_spec.rb +1 -1
- data/spec/core_ext/string_spec.rb +6 -6
- data/spec/core_ext/symbol_hash_spec.rb +11 -11
- data/spec/docstring_parser_spec.rb +207 -0
- data/spec/docstring_spec.rb +33 -146
- data/spec/handlers/alias_handler_spec.rb +14 -14
- data/spec/handlers/attribute_handler_spec.rb +20 -20
- data/spec/handlers/base_spec.rb +16 -16
- data/spec/handlers/c/alias_handler_spec.rb +33 -0
- data/spec/handlers/c/attribute_handler_spec.rb +40 -0
- data/spec/handlers/c/class_handler_spec.rb +64 -0
- data/spec/handlers/c/constant_handler_spec.rb +68 -0
- data/spec/handlers/c/init_handler_spec.rb +36 -0
- data/spec/handlers/c/method_handler_spec.rb +228 -0
- data/spec/handlers/c/mixin_handler_spec.rb +27 -0
- data/spec/handlers/c/module_handler_spec.rb +38 -0
- data/spec/handlers/c/override_comment_handler_spec.rb +43 -0
- data/spec/handlers/c/path_handler_spec.rb +35 -0
- data/spec/handlers/c/spec_helper.rb +11 -0
- data/spec/handlers/c/struct_handler_spec.rb +15 -0
- data/spec/handlers/class_condition_handler_spec.rb +10 -10
- data/spec/handlers/class_handler_spec.rb +38 -38
- data/spec/handlers/class_variable_handler_spec.rb +1 -1
- data/spec/handlers/constant_handler_spec.rb +7 -7
- data/spec/handlers/{macro_handler_spec.rb → dsl_handler_spec.rb} +72 -53
- data/spec/handlers/examples/alias_handler_001.rb.txt +5 -5
- data/spec/handlers/examples/class_condition_handler_001.rb.txt +9 -9
- data/spec/handlers/examples/class_handler_001.rb.txt +1 -1
- data/spec/handlers/examples/dsl_handler_001.rb.txt +110 -0
- data/spec/handlers/examples/exception_handler_001.rb.txt +14 -14
- data/spec/handlers/examples/method_condition_handler_001.rb.txt +2 -2
- data/spec/handlers/examples/method_handler_001.rb.txt +16 -16
- data/spec/handlers/examples/mixin_handler_001.rb.txt +8 -4
- data/spec/handlers/examples/private_constant_handler_001.rb.txt +1 -1
- data/spec/handlers/examples/visibility_handler_001.rb.txt +3 -3
- data/spec/handlers/examples/yield_handler_001.rb.txt +13 -14
- data/spec/handlers/exception_handler_spec.rb +9 -9
- data/spec/handlers/extend_handler_spec.rb +2 -2
- data/spec/handlers/legacy_base_spec.rb +34 -34
- data/spec/handlers/method_condition_handler_spec.rb +2 -2
- data/spec/handlers/method_handler_spec.rb +33 -33
- data/spec/handlers/mixin_handler_spec.rb +13 -9
- data/spec/handlers/module_function_handler_spec.rb +82 -0
- data/spec/handlers/module_handler_spec.rb +6 -6
- data/spec/handlers/private_constant_handler_spec.rb +3 -3
- data/spec/handlers/processor_spec.rb +5 -5
- data/spec/handlers/ruby/base_spec.rb +10 -6
- data/spec/handlers/ruby/legacy/base_spec.rb +11 -7
- data/spec/handlers/spec_helper.rb +2 -3
- data/spec/handlers/visibility_handler_spec.rb +6 -6
- data/spec/handlers/yield_handler_spec.rb +8 -8
- data/spec/i18n/pot_generator_spec.rb +244 -0
- data/spec/i18n/text_spec.rb +69 -0
- data/spec/options_spec.rb +160 -0
- data/spec/parser/base_spec.rb +3 -3
- data/spec/parser/c_parser_spec.rb +31 -257
- data/spec/parser/examples/array.c.txt +187 -187
- data/spec/parser/examples/extrafile.c.txt +1 -1
- data/spec/parser/examples/override.c.txt +1 -1
- data/spec/parser/ruby/ast_node_spec.rb +1 -1
- data/spec/parser/ruby/legacy/statement_list_spec.rb +24 -24
- data/spec/parser/ruby/legacy/token_list_spec.rb +7 -7
- data/spec/parser/ruby/ruby_parser_spec.rb +56 -34
- data/spec/parser/source_parser_spec.rb +125 -65
- data/spec/parser/tag_parsing_spec.rb +4 -4
- data/spec/rake/yardoc_task_spec.rb +10 -8
- data/spec/registry_spec.rb +65 -36
- data/spec/registry_store_spec.rb +90 -40
- data/spec/serializers/file_system_serializer_spec.rb +12 -12
- data/spec/serializers/yardoc_serializer_spec.rb +2 -2
- data/spec/server/adapter_spec.rb +3 -3
- data/spec/server/commands/base_spec.rb +8 -8
- data/spec/server/commands/library_command_spec.rb +3 -3
- data/spec/server/commands/static_file_command_spec.rb +7 -7
- data/spec/server/doc_server_helper_spec.rb +1 -1
- data/spec/server/doc_server_serializer_spec.rb +6 -6
- data/spec/server/rack_adapter_spec.rb +3 -3
- data/spec/server/router_spec.rb +19 -19
- data/spec/server/static_caching_spec.rb +4 -4
- data/spec/spec_helper.rb +7 -7
- data/spec/tags/default_factory_spec.rb +24 -16
- data/spec/tags/directives_spec.rb +422 -0
- data/spec/tags/library_spec.rb +15 -4
- data/spec/tags/overload_tag_spec.rb +6 -6
- data/spec/tags/ref_tag_list_spec.rb +8 -8
- data/spec/templates/class_spec.rb +7 -7
- data/spec/templates/constant_spec.rb +7 -7
- data/spec/templates/engine_spec.rb +28 -36
- data/spec/templates/examples/class001.html +108 -108
- data/spec/templates/examples/class002.html +17 -17
- data/spec/templates/examples/constant001.txt +1 -1
- data/spec/templates/examples/method001.html +45 -45
- data/spec/templates/examples/method002.html +25 -25
- data/spec/templates/examples/method003.html +60 -60
- data/spec/templates/examples/method004.html +7 -7
- data/spec/templates/examples/method005.html +28 -28
- data/spec/templates/examples/module001.html +321 -321
- data/spec/templates/examples/module001.txt +1 -1
- data/spec/templates/examples/module002.html +130 -130
- data/spec/templates/examples/module003.html +74 -74
- data/spec/templates/examples/module004.html +388 -0
- data/spec/templates/helpers/base_helper_spec.rb +32 -32
- data/spec/templates/helpers/html_helper_spec.rb +87 -68
- data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +9 -9
- data/spec/templates/helpers/markup/rdoc_markup_spec.rb +16 -16
- data/spec/templates/helpers/markup_helper_spec.rb +31 -28
- data/spec/templates/helpers/method_helper_spec.rb +7 -7
- data/spec/templates/helpers/shared_signature_examples.rb +9 -7
- data/spec/templates/helpers/text_helper_spec.rb +3 -3
- data/spec/templates/method_spec.rb +13 -13
- data/spec/templates/module_spec.rb +70 -24
- data/spec/templates/onefile_spec.rb +32 -15
- data/spec/templates/section_spec.rb +23 -23
- data/spec/templates/spec_helper.rb +31 -1
- data/spec/templates/tag_spec.rb +5 -5
- data/spec/templates/template_spec.rb +54 -46
- data/spec/verifier_spec.rb +5 -5
- data/templates/default/class/setup.rb +2 -2
- data/templates/default/docstring/html/abstract.erb +1 -1
- data/templates/default/docstring/html/note.erb +1 -1
- data/templates/default/docstring/html/private.erb +1 -1
- data/templates/default/docstring/html/todo.erb +1 -1
- data/templates/default/docstring/setup.rb +2 -2
- data/templates/default/fulldoc/html/css/full_list.css +4 -2
- data/templates/default/fulldoc/html/css/style.css +50 -44
- data/templates/default/fulldoc/html/frames.erb +21 -6
- data/templates/default/fulldoc/html/full_list.erb +5 -3
- data/templates/default/fulldoc/html/{full_list_files.erb → full_list_file.erb} +0 -0
- data/templates/default/fulldoc/html/js/app.js +29 -26
- data/templates/default/fulldoc/html/js/full_list.js +9 -9
- data/templates/default/fulldoc/html/js/jquery.js +4 -16
- data/templates/default/fulldoc/html/setup.rb +42 -38
- data/templates/default/layout/dot/header.erb +1 -1
- data/templates/default/layout/html/breadcrumb.erb +6 -6
- data/templates/default/layout/html/files.erb +1 -1
- data/templates/default/layout/html/footer.erb +1 -1
- data/templates/default/layout/html/headers.erb +3 -6
- data/templates/default/layout/html/index.erb +1 -1
- data/templates/default/layout/html/layout.erb +3 -7
- data/templates/default/layout/html/objects.erb +1 -1
- data/templates/default/layout/html/script_setup.erb +5 -0
- data/templates/default/layout/html/search.erb +4 -1
- data/templates/default/layout/html/setup.rb +8 -8
- data/templates/default/method_details/html/method_signature.erb +10 -3
- data/templates/default/method_details/setup.rb +1 -0
- data/templates/default/module/dot/info.erb +1 -1
- data/templates/default/module/dot/setup.rb +2 -2
- data/templates/default/module/html/attribute_details.erb +1 -1
- data/templates/default/module/html/children.erb +1 -1
- data/templates/default/module/html/defines.erb +1 -1
- data/templates/default/module/html/inherited_methods.erb +5 -4
- data/templates/default/module/html/item_summary.erb +15 -5
- data/templates/default/module/html/method_details_list.erb +2 -2
- data/templates/default/module/setup.rb +25 -12
- data/templates/default/module/text/setup.rb +1 -1
- data/templates/default/onefile/html/layout.erb +1 -1
- data/templates/default/onefile/html/setup.rb +2 -2
- data/templates/default/tags/html/example.erb +4 -2
- data/templates/default/tags/html/option.erb +1 -1
- data/templates/default/tags/html/overload.erb +1 -1
- data/templates/default/tags/html/see.erb +1 -1
- data/templates/default/tags/html/tag.erb +1 -1
- data/templates/default/tags/setup.rb +4 -3
- data/templates/guide/fulldoc/html/css/style.css +8 -8
- data/templates/guide/fulldoc/html/js/app.js +6 -6
- data/templates/guide/fulldoc/html/setup.rb +12 -12
- data/templates/guide/layout/html/layout.erb +11 -11
- data/templates/guide/layout/html/setup.rb +9 -9
- data/templates/guide/method/html/header.erb +2 -2
- data/templates/guide/method/html/setup.rb +1 -1
- metadata +68 -18
- data/bin/yard-graph +0 -4
- data/bin/yard-server +0 -4
- data/docs/Glossary.md +0 -12
- data/lib/yard/handlers/ruby/legacy/macro_handler.rb +0 -39
- data/lib/yard/handlers/ruby/macro_handler.rb +0 -40
- data/lib/yard/handlers/ruby/macro_handler_methods.rb +0 -131
- data/lib/yard/parser/c_parser.rb +0 -497
- data/lib/yard/server/templates/default/layout/html/headers.erb +0 -16
- data/lib/yard/server/templates/doc_server/frames/html/frames.erb +0 -13
- data/lib/yard/server/templates/doc_server/frames/html/setup.rb +0 -3
- data/lib/yard/server/templates/doc_server/full_list/html/full_list.erb +0 -34
- data/lib/yard/server/templates/doc_server/full_list/html/setup.rb +0 -20
- data/spec/handlers/examples/macro_handler_001.rb.txt +0 -83
@@ -1,40 +0,0 @@
|
|
1
|
-
module YARD
|
2
|
-
module Handlers
|
3
|
-
module Ruby
|
4
|
-
# Handles a macro (dsl-style method)
|
5
|
-
class MacroHandler < Base
|
6
|
-
include CodeObjects
|
7
|
-
include MacroHandlerMethods
|
8
|
-
handles method_call
|
9
|
-
namespace_only
|
10
|
-
|
11
|
-
IGNORE_METHODS = Hash[*%w(alias alias_method autoload attr attr_accessor
|
12
|
-
attr_reader attr_writer extend include public private protected
|
13
|
-
private_constant).map {|n| [n, true] }.flatten]
|
14
|
-
|
15
|
-
process do
|
16
|
-
globals.__attached_macros ||= {}
|
17
|
-
if !globals.__attached_macros[caller_method]
|
18
|
-
return if IGNORE_METHODS[caller_method]
|
19
|
-
return if !statement.comments || statement.comments.empty?
|
20
|
-
end
|
21
|
-
|
22
|
-
@macro, @docstring = nil, Docstring.new(statement.comments)
|
23
|
-
find_or_create_macro(@docstring)
|
24
|
-
return if !@macro && !statement.comments_hash_flag && @docstring.tags.size == 0
|
25
|
-
@docstring = expanded_macro_or_docstring
|
26
|
-
name = method_name
|
27
|
-
raise UndocumentableError, "method, missing name" if name.nil? || name.empty?
|
28
|
-
tmp_scope = sanitize_scope
|
29
|
-
tmp_vis = sanitize_visibility
|
30
|
-
object = MethodObject.new(namespace, name, tmp_scope)
|
31
|
-
register(object)
|
32
|
-
object.visibility = tmp_vis
|
33
|
-
object.dynamic = true
|
34
|
-
object.signature = method_signature
|
35
|
-
create_attribute_data(object)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,131 +0,0 @@
|
|
1
|
-
module YARD
|
2
|
-
module Handlers
|
3
|
-
module Ruby
|
4
|
-
module MacroHandlerMethods
|
5
|
-
include CodeObjects
|
6
|
-
include Parser
|
7
|
-
|
8
|
-
def find_or_create_macro(docstring)
|
9
|
-
return @macro if @macro
|
10
|
-
return if @macro = super(docstring)
|
11
|
-
|
12
|
-
# Look for implicit macros
|
13
|
-
(globals.__attached_macros[caller_method] || []).each do |macro|
|
14
|
-
(namespace.inheritance_tree + [P('Object')]).each do |obj|
|
15
|
-
break(@macro = macro) if obj == macro.method_object.namespace
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def expanded_macro_or_docstring
|
21
|
-
return @docstring unless @macro
|
22
|
-
all_params = ([caller_method] + call_params).compact
|
23
|
-
data = MacroObject.apply_macro(@macro, @docstring, all_params, statement.source)
|
24
|
-
Docstring.new(data)
|
25
|
-
end
|
26
|
-
|
27
|
-
def expand_macro(object, macro)
|
28
|
-
if @docstring
|
29
|
-
object.docstring = @docstring
|
30
|
-
object.docstring.tags.each do |tag|
|
31
|
-
tag.object = object if tag.respond_to?(:object=)
|
32
|
-
end
|
33
|
-
else
|
34
|
-
super(object, macro)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def sanitize_scope
|
39
|
-
tmp_scope = @docstring.tag(:scope) ? @docstring.tag(:scope).text : ''
|
40
|
-
%w(class instance).include?(tmp_scope) ? tmp_scope.to_sym : scope
|
41
|
-
end
|
42
|
-
|
43
|
-
def sanitize_visibility
|
44
|
-
vis = @docstring.tag(:visibility) ? @docstring.tag(:visibility).text : ''
|
45
|
-
%w(public protected private).include?(vis) ? vis.to_sym : visibility
|
46
|
-
end
|
47
|
-
|
48
|
-
def create_attribute_data(object)
|
49
|
-
return unless object.docstring.tag(:attribute)
|
50
|
-
ensure_loaded!(namespace)
|
51
|
-
clean_name = object.name.to_s.sub(/=$/, '')
|
52
|
-
namespace.attributes[object.scope][clean_name] ||= SymbolHash[:read => nil, :write => nil]
|
53
|
-
if attribute_readable?
|
54
|
-
namespace.attributes[object.scope][clean_name][:read] = object
|
55
|
-
end
|
56
|
-
if attribute_writable?
|
57
|
-
if object.name.to_s[-1,1] == '='
|
58
|
-
writer = object
|
59
|
-
else
|
60
|
-
writer = MethodObject.new(namespace, object.name.to_s + '=', object.scope)
|
61
|
-
register(writer)
|
62
|
-
writer.signature = "def #{object.name}=(value)"
|
63
|
-
writer.visibility = object.visibility
|
64
|
-
writer.dynamic = true
|
65
|
-
end
|
66
|
-
namespace.attributes[object.scope][clean_name][:write] = writer
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def method_name
|
71
|
-
name = nil
|
72
|
-
[:method, :attribute, :overload].each do |tag_name|
|
73
|
-
if tag = @docstring.tag(tag_name)
|
74
|
-
name = tag.send(tag_name == :attribute ? :text : :name).to_s
|
75
|
-
if tag_name == :method && name =~ /\(|\s/
|
76
|
-
overload = Tags::OverloadTag.new(:overload, name)
|
77
|
-
@docstring.add_tag(overload)
|
78
|
-
end
|
79
|
-
break
|
80
|
-
end
|
81
|
-
end
|
82
|
-
name = nil if name =~ /\A\s*\Z/
|
83
|
-
name ||= call_params.first
|
84
|
-
return unless name
|
85
|
-
return unless name =~ /^#{METHODNAMEMATCH}(\s|\(|$)/
|
86
|
-
if name =~ /\A\s*([^\(; \t]+)/
|
87
|
-
name = $1
|
88
|
-
end
|
89
|
-
if @docstring.tag(:attribute) && !attribute_readable?
|
90
|
-
name = name + '='
|
91
|
-
end
|
92
|
-
name
|
93
|
-
end
|
94
|
-
|
95
|
-
def method_signature
|
96
|
-
if @docstring.tag(:method)
|
97
|
-
name = @docstring.tag(:method).name
|
98
|
-
elsif @docstring.tag(:overload)
|
99
|
-
name = @docstring.tag(:overload).signature
|
100
|
-
elsif @docstring.tag(:attribute)
|
101
|
-
name = @docstring.tag(:attribute).text
|
102
|
-
name += '=(value)' if !attribute_readable?
|
103
|
-
else
|
104
|
-
name = method_name
|
105
|
-
end
|
106
|
-
name = nil if name =~ /\A\s*\Z/
|
107
|
-
name ||= call_params.first
|
108
|
-
name =~ /^def\b/ ? name : "def #{name}"
|
109
|
-
end
|
110
|
-
|
111
|
-
private
|
112
|
-
|
113
|
-
def attribute_writable?
|
114
|
-
if @docstring.tag(:attribute)
|
115
|
-
types = @docstring.tag(:attribute).types
|
116
|
-
return types ? types.join.include?('w') : true
|
117
|
-
end
|
118
|
-
false
|
119
|
-
end
|
120
|
-
|
121
|
-
def attribute_readable?
|
122
|
-
if @docstring.tag(:attribute)
|
123
|
-
types = @docstring.tag(:attribute).types
|
124
|
-
return types ? (types.join =~ /(?!w)r/ ? true : false) : true
|
125
|
-
end
|
126
|
-
false
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
data/lib/yard/parser/c_parser.rb
DELETED
@@ -1,497 +0,0 @@
|
|
1
|
-
# Parts of this source were borrowed from `rdoc/parser/c.rb`
|
2
|
-
# RDoc's license is packaged along with Ruby.
|
3
|
-
|
4
|
-
|
5
|
-
module YARD
|
6
|
-
module Parser
|
7
|
-
class CParser < Base
|
8
|
-
def initialize(source, file = '(stdin)')
|
9
|
-
@file = file
|
10
|
-
@namespaces = {}
|
11
|
-
@content = clean_source(source)
|
12
|
-
end
|
13
|
-
|
14
|
-
def parse
|
15
|
-
parse_namespaces
|
16
|
-
parse_methods
|
17
|
-
parse_attributes
|
18
|
-
parse_aliases
|
19
|
-
parse_constants
|
20
|
-
parse_includes
|
21
|
-
end
|
22
|
-
|
23
|
-
# @since 0.5.6
|
24
|
-
def tokenize
|
25
|
-
raise NotImplementedError, "no tokenization support for C/C++ files"
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
# @since 0.5.3
|
31
|
-
def remove_var_prefix(var)
|
32
|
-
var.gsub(/^rb_[mc]|^[a-z_]+/, '')
|
33
|
-
end
|
34
|
-
|
35
|
-
# @since 0.7.5
|
36
|
-
def lookup_var(var)
|
37
|
-
@namespaces[var] || P(remove_var_prefix(var))
|
38
|
-
end
|
39
|
-
|
40
|
-
def ensure_loaded!(object, max_retries = 1)
|
41
|
-
return if object.is_a?(CodeObjects::RootObject)
|
42
|
-
unless CONTINUATIONS_SUPPORTED
|
43
|
-
log.warn_no_continuations
|
44
|
-
raise Handlers::NamespaceMissingError, object
|
45
|
-
end
|
46
|
-
|
47
|
-
retries = 0
|
48
|
-
context = callcc {|c| c }
|
49
|
-
retries += 1
|
50
|
-
|
51
|
-
if object.is_a?(CodeObjects::Proxy)
|
52
|
-
if retries <= max_retries
|
53
|
-
log.debug "Missing object #{object} in file `#{@file}', moving it to the back of the line."
|
54
|
-
raise Parser::LoadOrderError, context
|
55
|
-
end
|
56
|
-
end
|
57
|
-
object
|
58
|
-
end
|
59
|
-
|
60
|
-
# @since 0.7.5
|
61
|
-
def handle_namespace(var_name, ns_type, ns_name, parent, in_module = nil)
|
62
|
-
case ns_type
|
63
|
-
when 'module'; handle_module(var_name, ns_name, in_module)
|
64
|
-
when 'path2class'; handle_class_lookup(var_name, ns_name)
|
65
|
-
else handle_class(var_name, ns_name, parent, in_module)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def handle_module(var_name, mod_name, in_module = nil)
|
70
|
-
namespace = in_module ? lookup_var(in_module) : :root
|
71
|
-
ensure_loaded!(namespace)
|
72
|
-
obj = CodeObjects::ModuleObject.new(namespace, mod_name)
|
73
|
-
obj.add_file(@file)
|
74
|
-
find_namespace_docstring(obj)
|
75
|
-
@namespaces[var_name] = obj
|
76
|
-
end
|
77
|
-
|
78
|
-
def handle_class(var_name, class_name, parent, in_module = nil)
|
79
|
-
parent = nil if parent == "0"
|
80
|
-
namespace = in_module ? lookup_var(in_module) : :root
|
81
|
-
ensure_loaded!(namespace)
|
82
|
-
obj = CodeObjects::ClassObject.new(namespace, class_name)
|
83
|
-
obj.superclass = lookup_var(parent) if parent
|
84
|
-
obj.add_file(@file)
|
85
|
-
find_namespace_docstring(obj)
|
86
|
-
@namespaces[var_name] = obj
|
87
|
-
end
|
88
|
-
|
89
|
-
# @since 0.7.5
|
90
|
-
def handle_class_lookup(var_name, class_name)
|
91
|
-
@namespaces[var_name] = P(class_name)
|
92
|
-
end
|
93
|
-
|
94
|
-
# @return [CodeObjects::Base]
|
95
|
-
def handle_method(scope, var_name, name, func_name, source_file = nil)
|
96
|
-
case scope
|
97
|
-
when "singleton_method", "module_function"; scope = :class
|
98
|
-
else; scope = :instance
|
99
|
-
end
|
100
|
-
|
101
|
-
namespace = lookup_var(var_name)
|
102
|
-
ensure_loaded!(namespace)
|
103
|
-
obj = CodeObjects::MethodObject.new(namespace, name, scope)
|
104
|
-
obj.add_file(@file)
|
105
|
-
obj.parameters = []
|
106
|
-
obj.docstring.add_tag(YARD::Tags::Tag.new(:return, '', 'Boolean')) if name =~ /\?$/
|
107
|
-
obj.source_type = :c
|
108
|
-
|
109
|
-
content = nil
|
110
|
-
begin
|
111
|
-
content = File.read(source_file) if source_file
|
112
|
-
rescue Errno::ENOENT
|
113
|
-
path = "#{namespace}#{scope == :instance ? '#' : '.'}#{name}"
|
114
|
-
log.warn "Missing source file `#{source_file}' when parsing #{path}"
|
115
|
-
ensure
|
116
|
-
content ||= @content
|
117
|
-
end
|
118
|
-
find_method_body(obj, func_name, content)
|
119
|
-
obj
|
120
|
-
end
|
121
|
-
|
122
|
-
def handle_alias(var_name, new_name, old_name)
|
123
|
-
namespace = lookup_var(var_name)
|
124
|
-
ensure_loaded!(namespace)
|
125
|
-
new_meth, old_meth = new_name.to_sym, old_name.to_sym
|
126
|
-
old_obj = namespace.child(:name => old_meth, :scope => :instance)
|
127
|
-
new_obj = YARD::CodeObjects::MethodObject.new(namespace, new_meth, :instance) do |o|
|
128
|
-
o.visibility = :public
|
129
|
-
o.scope = :instance
|
130
|
-
o.add_file(@file)
|
131
|
-
o.source_type = :c
|
132
|
-
end
|
133
|
-
|
134
|
-
if old_obj
|
135
|
-
new_obj.signature = old_obj.signature
|
136
|
-
new_obj.source = old_obj.source
|
137
|
-
new_obj.docstring = old_obj.docstring
|
138
|
-
new_obj.docstring.object = new_obj
|
139
|
-
else
|
140
|
-
new_obj.signature = "def #{new_meth}" # this is all we know.
|
141
|
-
end
|
142
|
-
|
143
|
-
namespace.aliases[new_obj] = old_meth
|
144
|
-
end
|
145
|
-
|
146
|
-
def handle_attribute(var_name, name, read, write, source_file = nil)
|
147
|
-
values = {:read => read.to_i, :write => write.to_i}
|
148
|
-
{:read => name, :write => "#{name}="}.each do |type, meth_name|
|
149
|
-
next unless values[type] > 0
|
150
|
-
obj = handle_method(:instance, var_name, meth_name, nil, source_file)
|
151
|
-
ensure_loaded!(obj.namespace)
|
152
|
-
obj.namespace.attributes[:instance][name] ||= SymbolHash[:read => nil, :write => nil]
|
153
|
-
obj.namespace.attributes[:instance][name][type] = obj
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
def handle_constants(type, var_name, const_name, definition)
|
158
|
-
namespace = lookup_var(var_name)
|
159
|
-
ensure_loaded!(namespace)
|
160
|
-
obj = CodeObjects::ConstantObject.new(namespace, const_name)
|
161
|
-
obj.value = definition
|
162
|
-
obj.add_file(@file)
|
163
|
-
obj.source_type = :c
|
164
|
-
comment = find_constant_docstring(obj, type, const_name)
|
165
|
-
|
166
|
-
# In the case of rb_define_const, the definition and comment are in
|
167
|
-
# "/* definition: comment */" form. The literal ':' and '\' characters
|
168
|
-
# can be escaped with a backslash.
|
169
|
-
if type.downcase == 'const'
|
170
|
-
comment.scan(/\A\s*(.*?[^\s\\]):\s*(.+)/) do |new_value, new_comment|
|
171
|
-
obj.value = new_value.gsub(/\\:/, ':')
|
172
|
-
comment = new_comment
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
obj.docstring = comment
|
177
|
-
end
|
178
|
-
|
179
|
-
def find_namespace_docstring(object)
|
180
|
-
comment = nil
|
181
|
-
if @content =~ %r{((?>/\*.*?\*/\s+))
|
182
|
-
(static\s+)?void\s+Init_#{object.name}\s*(?:_\(\s*)?\(\s*(?:void\s*)\)}xmi then
|
183
|
-
comment = $1
|
184
|
-
elsif @content =~ %r{Document-(?:class|module):\s#{object.path}\s*?(?:<\s+[:,\w]+)?\n((?>.*?\*/))}m
|
185
|
-
comment = $1
|
186
|
-
end
|
187
|
-
object.docstring = parse_comments(object, comment) if comment
|
188
|
-
end
|
189
|
-
|
190
|
-
def find_constant_docstring(object, type, const_name)
|
191
|
-
comment = if @content =~ %r{((?>^\s*/\*.*?\*/\s+))
|
192
|
-
rb_define_#{type}\((?:\s*(\w+),)?\s*"#{const_name}"\s*,.*?\)\s*;}xmi
|
193
|
-
$1
|
194
|
-
elsif @content =~ %r{Document-(?:const|global|variable):\s#{const_name}\s*?\n((?>.*?\*/))}m
|
195
|
-
$1
|
196
|
-
else
|
197
|
-
''
|
198
|
-
end
|
199
|
-
object.docstring = parse_comments(object, comment) if comment
|
200
|
-
end
|
201
|
-
|
202
|
-
def find_method_body(object, func_name, content = @content)
|
203
|
-
case content
|
204
|
-
when %r"((?>/\*.*?\*/\s*))(?:(?:static|SWIGINTERN)\s+)?(?:intern\s+)?VALUE\s+#{func_name}
|
205
|
-
\s*(\([^)]*\))([^;]|$)"xm
|
206
|
-
comment, params = $1, $2
|
207
|
-
body_text = $&
|
208
|
-
|
209
|
-
remove_private_comments(comment) if comment
|
210
|
-
|
211
|
-
# see if we can find the whole body
|
212
|
-
|
213
|
-
re = Regexp.escape(body_text) + '[^(]*\{.*?\}'
|
214
|
-
body_text = $& if /#{re}/m =~ content
|
215
|
-
|
216
|
-
# The comment block may have been overridden with a 'Document-method'
|
217
|
-
# block. This happens in the interpreter when multiple methods are
|
218
|
-
# vectored through to the same C method but those methods are logically
|
219
|
-
# distinct (for example Kernel.hash and Kernel.object_id share the same
|
220
|
-
# implementation
|
221
|
-
|
222
|
-
override_comment = find_override_comment(object)
|
223
|
-
comment = override_comment if override_comment
|
224
|
-
|
225
|
-
object.docstring = parse_comments(object, comment) if comment
|
226
|
-
object.source = body_text.gsub(/\A#{Regexp.quote comment}/, '')
|
227
|
-
when %r{((?>/\*.*?\*/\s*))^\s*\#\s*define\s+#{func_name}\s+(\w+)}m
|
228
|
-
comment = $1
|
229
|
-
find_method_body(object, $2, content)
|
230
|
-
else
|
231
|
-
# No body, but might still have an override comment
|
232
|
-
comment = find_override_comment(object)
|
233
|
-
object.docstring = parse_comments(object, comment) if comment
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
def find_override_comment(object, content = @content)
|
238
|
-
name = Regexp.escape(object.name.to_s)
|
239
|
-
name = "(?:initialize|new)" if name == 'initialize'
|
240
|
-
class_name = object.parent.path
|
241
|
-
if content =~ %r{Document-method:\s+#{class_name}(?:\.|::|#)#{name}\s*?\n((?>.*?\*/))}m then
|
242
|
-
$1
|
243
|
-
elsif content =~ %r{Document-method:\s#{name}\s*?\n((?>.*?\*/))}m then
|
244
|
-
$1
|
245
|
-
else
|
246
|
-
nil
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
def parse_comments(object, comments)
|
251
|
-
spaces = nil
|
252
|
-
comments = remove_private_comments(comments)
|
253
|
-
comments = comments.split(/\r?\n/).map do |line|
|
254
|
-
line.gsub!(/^\s*\/?\*\/?/, '')
|
255
|
-
line.gsub!(/\*\/\s*$/, '')
|
256
|
-
if line =~ /^\s*$/
|
257
|
-
next if spaces.nil?
|
258
|
-
next ""
|
259
|
-
end
|
260
|
-
spaces = (line[/^(\s+)/, 1] || "").size if spaces.nil?
|
261
|
-
line.gsub(/^\s{0,#{spaces}}/, '').rstrip
|
262
|
-
end.compact
|
263
|
-
|
264
|
-
comments.shift if comments.first =~ /^\s*Document-method:/
|
265
|
-
comments = parse_callseq(object, comments)
|
266
|
-
comments.join("\n")
|
267
|
-
end
|
268
|
-
|
269
|
-
def parse_callseq(object, comments)
|
270
|
-
return comments unless comments[0] =~ /\Acall-seq:\s*(\S.+)?/
|
271
|
-
if $1
|
272
|
-
comments[0] = " #{$1}"
|
273
|
-
else
|
274
|
-
comments.shift
|
275
|
-
end
|
276
|
-
overloads = []
|
277
|
-
seen_data = false
|
278
|
-
while comments.first =~ /^\s+(\S.+)/ || comments.first =~ /^\s*$/
|
279
|
-
line = comments.shift.strip
|
280
|
-
break if line.empty? && seen_data
|
281
|
-
next if line.empty?
|
282
|
-
seen_data = true
|
283
|
-
line.sub!(/^\w+[\.#]/, '')
|
284
|
-
signature, types = *line.split(/ [-=]> /)
|
285
|
-
types = parse_types(object, types)
|
286
|
-
if signature.sub!(/\[?\s*(\{(?:\s*\|(.+?)\|)?.*\})\s*\]?\s*$/, '') && $1
|
287
|
-
blk, blkparams = $1, $2
|
288
|
-
else
|
289
|
-
blk, blkparams = nil, nil
|
290
|
-
end
|
291
|
-
case signature
|
292
|
-
when /^(\w+)\s*=\s+(\w+)/
|
293
|
-
signature = "#{$1}=(#{$2})"
|
294
|
-
when /^\w+\s+\S/
|
295
|
-
signature = signature.split(/\s+/)
|
296
|
-
signature = "#{signature[1]}#{signature[2] ? '(' + signature[2..-1].join(' ') + ')' : ''}"
|
297
|
-
when /^\w+\[(.+?)\]\s*(=)?/
|
298
|
-
signature = "[]#{$2}(#{$1})"
|
299
|
-
when /^\w+\s+(#{CodeObjects::METHODMATCH})\s+(\w+)/
|
300
|
-
signature = "#{$1}(#{$2})"
|
301
|
-
end
|
302
|
-
break unless signature =~ /^#{CodeObjects::METHODNAMEMATCH}/
|
303
|
-
signature = signature.rstrip
|
304
|
-
overloads << "@overload #{signature}"
|
305
|
-
overloads << " @yield [#{blkparams}]" if blk
|
306
|
-
overloads << " @return [#{types.join(', ')}]" unless types.empty?
|
307
|
-
end
|
308
|
-
|
309
|
-
comments + [""] + overloads
|
310
|
-
end
|
311
|
-
|
312
|
-
def parse_types(object, types)
|
313
|
-
if types =~ /true or false/
|
314
|
-
["Boolean"]
|
315
|
-
else
|
316
|
-
(types||"").split(/,| or /).map do |t|
|
317
|
-
case t.strip.gsub(/^an?_/, '')
|
318
|
-
when "class"; "Class"
|
319
|
-
when "obj", "object", "anObject"; "Object"
|
320
|
-
when "arr", "array", "anArray", /^\[/; "Array"
|
321
|
-
when /^char\s*\*/, "char", "str", "string", "new_str"; "String"
|
322
|
-
when "enum", "anEnumerator"; "Enumerator"
|
323
|
-
when "exc", "exception"; "Exception"
|
324
|
-
when "proc", "proc_obj", "prc"; "Proc"
|
325
|
-
when "binding"; "Binding"
|
326
|
-
when "hsh", "hash", "aHash"; "Hash"
|
327
|
-
when "ios", "io"; "IO"
|
328
|
-
when "file"; "File"
|
329
|
-
when "float"; "Float"
|
330
|
-
when "time", "new_time"; "Time"
|
331
|
-
when "dir", "aDir"; "Dir"
|
332
|
-
when "regexp", "new_regexp"; "Regexp"
|
333
|
-
when "matchdata"; "MatchData"
|
334
|
-
when "encoding"; "Encoding"
|
335
|
-
when "fixnum", "fix"; "Fixnum"
|
336
|
-
when /^(?:un)?signed$/, /^(?:(?:un)?signed\s*)?(?:short|int|long|long\s+long)$/, "integer", "Integer"; "Integer"
|
337
|
-
when "num", "numeric", "Numeric", "number"; "Numeric"
|
338
|
-
when "aBignum"; "Bignum"
|
339
|
-
when "nil"; "nil"
|
340
|
-
when "true"; "true"
|
341
|
-
when "false"; "false"
|
342
|
-
when "bool", "boolean", "Boolean"; "Boolean"
|
343
|
-
when "self"; object.namespace.name.to_s
|
344
|
-
when /^[-+]?\d/; t
|
345
|
-
when /[A-Z][_a-z0-9]+/; t
|
346
|
-
end
|
347
|
-
end.compact
|
348
|
-
end
|
349
|
-
end
|
350
|
-
|
351
|
-
def parse_namespaces
|
352
|
-
# The '.' lets us handle SWIG-generated files
|
353
|
-
@content.scan(/([\w\.]+)\s* = \s*(?:rb_define_(class|module)|boot_defclass|rb_(path2class))\s*
|
354
|
-
\(
|
355
|
-
\s*"([\w:]+)"(?:,
|
356
|
-
\s*(\w+|0)\s*)?
|
357
|
-
\)/mx) do |var_name, ns_type, path2class, ns_name, parent|
|
358
|
-
handle_namespace(var_name, path2class || ns_type, ns_name, parent)
|
359
|
-
end
|
360
|
-
|
361
|
-
@content.scan(/([\w\.]+)\s* = \s*rb_define_(class|module)_under\s*
|
362
|
-
\(
|
363
|
-
\s*(\w+),
|
364
|
-
\s*"(\w+)"(?:,
|
365
|
-
\s*([\w\*\s\(\)\.\->]+)\s*)? # for SWIG
|
366
|
-
\s*\)/mx) do |var_name, ns_type, in_module, ns_name, parent|
|
367
|
-
handle_namespace(var_name, ns_type, ns_name, parent, in_module)
|
368
|
-
end
|
369
|
-
end
|
370
|
-
|
371
|
-
def parse_methods
|
372
|
-
@content.scan(%r{rb_define_
|
373
|
-
(
|
374
|
-
singleton_method |
|
375
|
-
method |
|
376
|
-
module_function |
|
377
|
-
private_method
|
378
|
-
)
|
379
|
-
\s*\(\s*([\w\.]+),
|
380
|
-
\s*"([^"]+)",
|
381
|
-
\s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\()?(\w+)\)?,
|
382
|
-
\s*(-?\w+)\s*\)
|
383
|
-
(?:;\s*/[*/]\s+in\s+(.+?\.[cy]))?
|
384
|
-
}xm) do |type, var_name, name, func_name, param_count, source_file|
|
385
|
-
|
386
|
-
# Ignore top-object and weird struct.c dynamic stuff
|
387
|
-
next if var_name == "ruby_top_self"
|
388
|
-
next if var_name == "nstr"
|
389
|
-
next if var_name == "envtbl"
|
390
|
-
|
391
|
-
var_name = "rb_cObject" if var_name == "rb_mKernel"
|
392
|
-
handle_method(type, var_name, name, func_name, source_file)
|
393
|
-
end
|
394
|
-
|
395
|
-
@content.scan(%r{rb_define_global_function\s*\(
|
396
|
-
\s*"([^"]+)",
|
397
|
-
\s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\()?(\w+)\)?,
|
398
|
-
\s*(-?\w+)\s*\)
|
399
|
-
(?:;\s*/[*/]\s+in\s+(.+?\.[cy]))?
|
400
|
-
}xm) do |name, func_name, param_count, source_file|
|
401
|
-
handle_method("method", "rb_mKernel", name, func_name, source_file)
|
402
|
-
end
|
403
|
-
end
|
404
|
-
|
405
|
-
def parse_aliases
|
406
|
-
@content.scan(%r{rb_define_alias
|
407
|
-
\s*\(\s*([\w\.]+),
|
408
|
-
\s*"([^"]+)",
|
409
|
-
\s*"([^"]+)"\s*\)
|
410
|
-
}xm) do |var_name, new_name, old_name|
|
411
|
-
|
412
|
-
var_name = "rb_cObject" if var_name == "rb_mKernel"
|
413
|
-
handle_alias(var_name, new_name, old_name)
|
414
|
-
end
|
415
|
-
end
|
416
|
-
|
417
|
-
def parse_attributes
|
418
|
-
@content.scan(%r{rb_define_attr
|
419
|
-
\s*\(\s*([\w\.]+),
|
420
|
-
\s*"([^"]+)",
|
421
|
-
\s*(0|1)\s*,\s*(0|1)\s*\)
|
422
|
-
(?:;\s*/[*/]\s+in\s+(.+?\.[cy]))?
|
423
|
-
}xm) do |var_name, name, read, write, source_file|
|
424
|
-
|
425
|
-
# Ignore top-object and weird struct.c dynamic stuff
|
426
|
-
next if var_name == "ruby_top_self"
|
427
|
-
next if var_name == "nstr"
|
428
|
-
next if var_name == "envtbl"
|
429
|
-
|
430
|
-
var_name = "rb_cObject" if var_name == "rb_mKernel"
|
431
|
-
handle_attribute(var_name, name, read, write, source_file)
|
432
|
-
end
|
433
|
-
end
|
434
|
-
|
435
|
-
def parse_includes
|
436
|
-
@content.scan(/rb_include_module\s*\(\s*(\w+?),\s*(\w+?)\s*\)/) do |klass, mod|
|
437
|
-
if klass = @namespaces[klass]
|
438
|
-
klass.mixins(:instance) << lookup_var(mod)
|
439
|
-
end
|
440
|
-
end
|
441
|
-
end
|
442
|
-
|
443
|
-
def parse_constants
|
444
|
-
@content.scan(%r{\Wrb_define_
|
445
|
-
(
|
446
|
-
variable |
|
447
|
-
readonly_variable |
|
448
|
-
const |
|
449
|
-
global_const |
|
450
|
-
)
|
451
|
-
\s*\(
|
452
|
-
(?:\s*(\w+),)?
|
453
|
-
\s*"(\w+)",
|
454
|
-
\s*(.*?)\s*\)\s*;
|
455
|
-
}xm) do |type, var_name, const_name, definition|
|
456
|
-
var_name = "rb_cObject" if !var_name or var_name == "rb_mKernel"
|
457
|
-
handle_constants(type, var_name, const_name, definition)
|
458
|
-
end
|
459
|
-
end
|
460
|
-
|
461
|
-
private
|
462
|
-
|
463
|
-
def clean_source(source)
|
464
|
-
source = handle_ifdefs_in(source)
|
465
|
-
source = handle_tab_width(source)
|
466
|
-
source = remove_commented_out_lines(source)
|
467
|
-
source
|
468
|
-
end
|
469
|
-
|
470
|
-
def handle_ifdefs_in(body)
|
471
|
-
body.gsub(/^#ifdef HAVE_PROTOTYPES.*?#else.*?\n(.*?)#endif.*?\n/m, '\1')
|
472
|
-
end
|
473
|
-
|
474
|
-
def handle_tab_width(body)
|
475
|
-
if /\t/ =~ body
|
476
|
-
tab_width = 4
|
477
|
-
body.split(/\n/).map do |line|
|
478
|
-
1 while line.gsub!(/\t+/) { ' ' * (tab_width*$&.length - $`.length % tab_width)} && $~ #`
|
479
|
-
line
|
480
|
-
end .join("\n")
|
481
|
-
else
|
482
|
-
body
|
483
|
-
end
|
484
|
-
end
|
485
|
-
|
486
|
-
def remove_commented_out_lines(body)
|
487
|
-
body.gsub(%r{//.*rb_define_}, '//')
|
488
|
-
end
|
489
|
-
|
490
|
-
def remove_private_comments(comment)
|
491
|
-
comment = comment.gsub(/\/?\*--\n(.*?)\/?\*\+\+/m, '')
|
492
|
-
comment = comment.sub(/\/?\*--\n.*/m, '')
|
493
|
-
comment
|
494
|
-
end
|
495
|
-
end
|
496
|
-
end
|
497
|
-
end
|