yard 0.9.24 → 0.9.25
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +37 -24
- data/CHANGELOG.md +18 -3
- data/README.md +96 -101
- data/Rakefile +2 -0
- data/lib/yard/cli/diff.rb +4 -1
- data/lib/yard/cli/server.rb +22 -13
- data/lib/yard/code_objects/proxy.rb +2 -1
- data/lib/yard/globals.rb +1 -1
- data/lib/yard/handlers/c/base.rb +164 -129
- data/lib/yard/parser/ruby/ruby_parser.rb +6 -4
- data/lib/yard/registry_store.rb +1 -1
- data/lib/yard/templates/helpers/html_helper.rb +10 -3
- data/lib/yard/templates/helpers/markup/rdoc_markup.rb +5 -4
- data/lib/yard/version.rb +1 -1
- data/tasks/update_error_map.rake +53 -0
- data/yard.gemspec +1 -1
- metadata +3 -207
- data/spec/cli/command_parser_spec.rb +0 -43
- data/spec/cli/command_spec.rb +0 -36
- data/spec/cli/config_spec.rb +0 -148
- data/spec/cli/diff_spec.rb +0 -254
- data/spec/cli/display_spec.rb +0 -30
- data/spec/cli/gems_spec.rb +0 -81
- data/spec/cli/graph_spec.rb +0 -18
- data/spec/cli/help_spec.rb +0 -22
- data/spec/cli/i18n_spec.rb +0 -107
- data/spec/cli/list_spec.rb +0 -8
- data/spec/cli/markup_types_spec.rb +0 -22
- data/spec/cli/server_spec.rb +0 -324
- data/spec/cli/stats_spec.rb +0 -96
- data/spec/cli/yard_on_yard_spec.rb +0 -38
- data/spec/cli/yardoc_spec.rb +0 -896
- data/spec/cli/yri_spec.rb +0 -101
- data/spec/code_objects/base_spec.rb +0 -485
- data/spec/code_objects/class_object_spec.rb +0 -226
- data/spec/code_objects/code_object_list_spec.rb +0 -36
- data/spec/code_objects/constants_spec.rb +0 -116
- data/spec/code_objects/extra_file_object_spec.rb +0 -161
- data/spec/code_objects/macro_object_spec.rb +0 -150
- data/spec/code_objects/method_object_spec.rb +0 -184
- data/spec/code_objects/module_object_spec.rb +0 -142
- data/spec/code_objects/namespace_mapper_spec.rb +0 -32
- data/spec/code_objects/namespace_object_spec.rb +0 -171
- data/spec/code_objects/proxy_spec.rb +0 -147
- data/spec/code_objects/spec_helper.rb +0 -3
- data/spec/config_spec.rb +0 -171
- data/spec/core_ext/array_spec.rb +0 -13
- data/spec/core_ext/file_spec.rb +0 -72
- data/spec/core_ext/hash_spec.rb +0 -14
- data/spec/core_ext/insertion_spec.rb +0 -37
- data/spec/core_ext/module_spec.rb +0 -9
- data/spec/core_ext/string_spec.rb +0 -42
- data/spec/core_ext/symbol_hash_spec.rb +0 -89
- data/spec/docstring_parser_spec.rb +0 -280
- data/spec/docstring_spec.rb +0 -373
- data/spec/handlers/alias_handler_spec.rb +0 -82
- data/spec/handlers/attribute_handler_spec.rb +0 -96
- data/spec/handlers/base_spec.rb +0 -216
- data/spec/handlers/c/alias_handler_spec.rb +0 -34
- data/spec/handlers/c/attribute_handler_spec.rb +0 -41
- data/spec/handlers/c/class_handler_spec.rb +0 -78
- data/spec/handlers/c/constant_handler_spec.rb +0 -71
- data/spec/handlers/c/init_handler_spec.rb +0 -48
- data/spec/handlers/c/method_handler_spec.rb +0 -327
- data/spec/handlers/c/mixin_handler_spec.rb +0 -44
- data/spec/handlers/c/module_handler_spec.rb +0 -71
- data/spec/handlers/c/override_comment_handler_spec.rb +0 -47
- data/spec/handlers/c/path_handler_spec.rb +0 -36
- data/spec/handlers/c/spec_helper.rb +0 -23
- data/spec/handlers/c/struct_handler_spec.rb +0 -16
- data/spec/handlers/class_condition_handler_spec.rb +0 -87
- data/spec/handlers/class_handler_spec.rb +0 -247
- data/spec/handlers/class_method_handler_shared_examples.rb +0 -133
- data/spec/handlers/class_variable_handler_spec.rb +0 -12
- data/spec/handlers/constant_handler_spec.rb +0 -112
- data/spec/handlers/decorator_handler_methods_spec.rb +0 -393
- data/spec/handlers/dsl_handler_spec.rb +0 -226
- data/spec/handlers/examples/alias_handler_001.rb.txt +0 -46
- data/spec/handlers/examples/attribute_handler_001.rb.txt +0 -32
- data/spec/handlers/examples/class_condition_handler_001.rb.txt +0 -69
- data/spec/handlers/examples/class_handler_001.rb.txt +0 -120
- data/spec/handlers/examples/class_variable_handler_001.rb.txt +0 -10
- data/spec/handlers/examples/constant_handler_001.rb.txt +0 -35
- data/spec/handlers/examples/dsl_handler_001.rb.txt +0 -156
- data/spec/handlers/examples/exception_handler_001.rb.txt +0 -59
- data/spec/handlers/examples/extend_handler_001.rb.txt +0 -19
- data/spec/handlers/examples/method_condition_handler_001.rb.txt +0 -10
- data/spec/handlers/examples/method_handler_001.rb.txt +0 -128
- data/spec/handlers/examples/mixin_handler_001.rb.txt +0 -40
- data/spec/handlers/examples/module_handler_001.rb.txt +0 -29
- data/spec/handlers/examples/private_constant_handler_001.rb.txt +0 -8
- data/spec/handlers/examples/process_handler_001.rb.txt +0 -11
- data/spec/handlers/examples/visibility_handler_001.rb.txt +0 -36
- data/spec/handlers/examples/yield_handler_001.rb.txt +0 -54
- data/spec/handlers/exception_handler_spec.rb +0 -49
- data/spec/handlers/extend_handler_spec.rb +0 -28
- data/spec/handlers/legacy_base_spec.rb +0 -128
- data/spec/handlers/method_condition_handler_spec.rb +0 -15
- data/spec/handlers/method_handler_spec.rb +0 -214
- data/spec/handlers/mixin_handler_spec.rb +0 -60
- data/spec/handlers/module_function_handler_spec.rb +0 -106
- data/spec/handlers/module_handler_spec.rb +0 -35
- data/spec/handlers/private_class_method_handler_spec.rb +0 -11
- data/spec/handlers/private_constant_handler_spec.rb +0 -25
- data/spec/handlers/processor_spec.rb +0 -35
- data/spec/handlers/public_class_method_handler_spec.rb +0 -11
- data/spec/handlers/ruby/base_spec.rb +0 -95
- data/spec/handlers/ruby/legacy/base_spec.rb +0 -84
- data/spec/handlers/spec_helper.rb +0 -33
- data/spec/handlers/visibility_handler_spec.rb +0 -44
- data/spec/handlers/yield_handler_spec.rb +0 -52
- data/spec/i18n/locale_spec.rb +0 -81
- data/spec/i18n/message_spec.rb +0 -52
- data/spec/i18n/messages_spec.rb +0 -67
- data/spec/i18n/pot_generator_spec.rb +0 -295
- data/spec/i18n/text_spec.rb +0 -184
- data/spec/logging_spec.rb +0 -44
- data/spec/options_spec.rb +0 -171
- data/spec/parser/base_spec.rb +0 -24
- data/spec/parser/c_parser_spec.rb +0 -236
- data/spec/parser/examples/array.c.txt +0 -6267
- data/spec/parser/examples/example1.rb.txt +0 -8
- data/spec/parser/examples/extrafile.c.txt +0 -8
- data/spec/parser/examples/file.c.txt +0 -28
- data/spec/parser/examples/multifile.c.txt +0 -22
- data/spec/parser/examples/namespace.cpp.txt +0 -68
- data/spec/parser/examples/override.c.txt +0 -424
- data/spec/parser/examples/parse_in_order_001.rb.txt +0 -2
- data/spec/parser/examples/parse_in_order_002.rb.txt +0 -2
- data/spec/parser/examples/tag_handler_001.rb.txt +0 -8
- data/spec/parser/ruby/ast_node_spec.rb +0 -33
- data/spec/parser/ruby/legacy/statement_list_spec.rb +0 -299
- data/spec/parser/ruby/legacy/token_list_spec.rb +0 -79
- data/spec/parser/ruby/ruby_parser_spec.rb +0 -520
- data/spec/parser/ruby/token_resolver_spec.rb +0 -165
- data/spec/parser/source_parser_spec.rb +0 -727
- data/spec/parser/tag_parsing_spec.rb +0 -17
- data/spec/rake/yardoc_task_spec.rb +0 -118
- data/spec/registry_resolver_spec.rb +0 -15
- data/spec/registry_spec.rb +0 -463
- data/spec/registry_store_spec.rb +0 -327
- data/spec/rubygems/doc_manager_spec.rb +0 -112
- data/spec/serializers/data/serialized_yardoc/checksums +0 -1
- data/spec/serializers/data/serialized_yardoc/objects/Foo.dat +0 -0
- data/spec/serializers/data/serialized_yardoc/objects/Foo/bar_i.dat +0 -0
- data/spec/serializers/data/serialized_yardoc/objects/Foo/baz_i.dat +0 -0
- data/spec/serializers/data/serialized_yardoc/objects/root.dat +0 -0
- data/spec/serializers/data/serialized_yardoc/proxy_types +0 -2
- data/spec/serializers/file_system_serializer_spec.rb +0 -145
- data/spec/serializers/spec_helper.rb +0 -2
- data/spec/serializers/yardoc_serializer_spec.rb +0 -90
- data/spec/server/adapter_spec.rb +0 -39
- data/spec/server/commands/base_spec.rb +0 -91
- data/spec/server/commands/library_command_spec.rb +0 -39
- data/spec/server/doc_server_helper_spec.rb +0 -72
- data/spec/server/doc_server_serializer_spec.rb +0 -60
- data/spec/server/rack_adapter_spec.rb +0 -21
- data/spec/server/router_spec.rb +0 -123
- data/spec/server/spec_helper.rb +0 -22
- data/spec/server/static_caching_spec.rb +0 -47
- data/spec/server/webrick_servlet_spec.rb +0 -20
- data/spec/server_spec.rb +0 -19
- data/spec/spec_helper.rb +0 -212
- data/spec/tags/default_factory_spec.rb +0 -168
- data/spec/tags/default_tag_spec.rb +0 -11
- data/spec/tags/directives_spec.rb +0 -463
- data/spec/tags/library_spec.rb +0 -48
- data/spec/tags/overload_tag_spec.rb +0 -53
- data/spec/tags/ref_tag_list_spec.rb +0 -53
- data/spec/tags/types_explainer_spec.rb +0 -203
- data/spec/templates/class_spec.rb +0 -45
- data/spec/templates/constant_spec.rb +0 -41
- data/spec/templates/engine_spec.rb +0 -131
- data/spec/templates/examples/class001.html +0 -308
- data/spec/templates/examples/class001.txt +0 -36
- data/spec/templates/examples/class002.html +0 -39
- data/spec/templates/examples/constant001.txt +0 -25
- data/spec/templates/examples/constant002.txt +0 -7
- data/spec/templates/examples/constant003.txt +0 -11
- data/spec/templates/examples/method001.html +0 -137
- data/spec/templates/examples/method001.txt +0 -35
- data/spec/templates/examples/method002.html +0 -91
- data/spec/templates/examples/method002.txt +0 -20
- data/spec/templates/examples/method003.html +0 -165
- data/spec/templates/examples/method003.txt +0 -45
- data/spec/templates/examples/method004.html +0 -48
- data/spec/templates/examples/method004.txt +0 -10
- data/spec/templates/examples/method005.html +0 -105
- data/spec/templates/examples/method005.txt +0 -33
- data/spec/templates/examples/method006.html +0 -108
- data/spec/templates/examples/method006.txt +0 -20
- data/spec/templates/examples/module001.dot +0 -33
- data/spec/templates/examples/module001.html +0 -833
- data/spec/templates/examples/module001.txt +0 -33
- data/spec/templates/examples/module002.html +0 -341
- data/spec/templates/examples/module003.html +0 -202
- data/spec/templates/examples/module004.html +0 -394
- data/spec/templates/examples/module005.html +0 -82
- data/spec/templates/examples/tag001.txt +0 -82
- data/spec/templates/helpers/base_helper_spec.rb +0 -171
- data/spec/templates/helpers/html_helper_spec.rb +0 -666
- data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +0 -65
- data/spec/templates/helpers/markup/rdoc_markup_spec.rb +0 -84
- data/spec/templates/helpers/markup_helper_spec.rb +0 -136
- data/spec/templates/helpers/method_helper_spec.rb +0 -107
- data/spec/templates/helpers/module_helper_spec.rb +0 -35
- data/spec/templates/helpers/shared_signature_examples.rb +0 -126
- data/spec/templates/helpers/text_helper_spec.rb +0 -65
- data/spec/templates/markup_processor_integrations/asciidoctor_spec.rb +0 -60
- data/spec/templates/markup_processor_integrations/integration_spec_helper.rb +0 -50
- data/spec/templates/markup_processor_integrations/rdoc_markdown_spec.rb +0 -48
- data/spec/templates/markup_processor_integrations/rdoc_spec.rb +0 -39
- data/spec/templates/markup_processor_integrations/redcarpet_spec.rb +0 -64
- data/spec/templates/markup_processor_integrations/redcloth_spec.rb +0 -64
- data/spec/templates/method_spec.rb +0 -118
- data/spec/templates/module_spec.rb +0 -203
- data/spec/templates/onefile_spec.rb +0 -66
- data/spec/templates/section_spec.rb +0 -144
- data/spec/templates/spec_helper.rb +0 -76
- data/spec/templates/tag_spec.rb +0 -52
- data/spec/templates/template_spec.rb +0 -410
- data/spec/verifier_spec.rb +0 -106
data/Rakefile
CHANGED
data/lib/yard/cli/diff.rb
CHANGED
@@ -161,7 +161,10 @@ module YARD
|
|
161
161
|
url = "http://rubygems.org/downloads/#{gemfile}"
|
162
162
|
log.info "Searching for remote gem file #{url}"
|
163
163
|
begin
|
164
|
-
|
164
|
+
# Note: In Ruby 2.4.x, URI.open is a private method. After
|
165
|
+
# 2.5, URI.open behaves much like Kernel#open once you've
|
166
|
+
# required 'open-uri'
|
167
|
+
OpenURI.open_uri(url) {|io| expand_and_parse(gemfile, io) }
|
165
168
|
return true
|
166
169
|
rescue OpenURI::HTTPError
|
167
170
|
nil # noop
|
data/lib/yard/cli/server.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module YARD
|
3
4
|
module CLI
|
4
5
|
# A local documentation server
|
@@ -58,11 +59,13 @@ module YARD
|
|
58
59
|
|
59
60
|
def load_template_paths
|
60
61
|
return if YARD::Config.options[:safe_mode]
|
62
|
+
|
61
63
|
Templates::Engine.template_paths |= template_paths
|
62
64
|
end
|
63
65
|
|
64
66
|
def select_adapter
|
65
67
|
return adapter if adapter
|
68
|
+
|
66
69
|
require 'rubygems'
|
67
70
|
require 'rack'
|
68
71
|
self.adapter = YARD::Server::RackAdapter
|
@@ -129,7 +132,8 @@ module YARD
|
|
129
132
|
require 'rubygems'
|
130
133
|
YARD::GemIndex.each do |spec|
|
131
134
|
libraries[spec.name] ||= []
|
132
|
-
libraries[spec.name] |= [YARD::Server::LibraryVersion.new(spec.name, spec.version.to_s,
|
135
|
+
libraries[spec.name] |= [YARD::Server::LibraryVersion.new(spec.name, spec.version.to_s,
|
136
|
+
nil, :gem)]
|
133
137
|
end
|
134
138
|
end
|
135
139
|
|
@@ -139,7 +143,8 @@ module YARD
|
|
139
143
|
if File.exist?("#{gemfile}.lock")
|
140
144
|
Bundler::LockfileParser.new(File.read("#{gemfile}.lock")).specs.each do |spec|
|
141
145
|
libraries[spec.name] ||= []
|
142
|
-
libraries[spec.name] |= [YARD::Server::LibraryVersion.new(spec.name,
|
146
|
+
libraries[spec.name] |= [YARD::Server::LibraryVersion.new(spec.name,
|
147
|
+
spec.version.to_s, nil, :gem)]
|
143
148
|
end
|
144
149
|
else
|
145
150
|
log.warn "Cannot find #{gemfile}.lock, ignoring --gemfile option"
|
@@ -171,7 +176,8 @@ module YARD
|
|
171
176
|
opts.on('-g', '--gems', 'Serves documentation for installed gems') do
|
172
177
|
add_gems
|
173
178
|
end
|
174
|
-
opts.on('-G', '--gemfile [GEMFILE]',
|
179
|
+
opts.on('-G', '--gemfile [GEMFILE]',
|
180
|
+
'Serves documentation for gems from Gemfile') do |gemfile|
|
175
181
|
add_gems_from_gemfile(gemfile)
|
176
182
|
end
|
177
183
|
opts.on('-t', '--template-path PATH',
|
@@ -192,23 +198,26 @@ module YARD
|
|
192
198
|
opts.on('--docroot DOCROOT', 'Uses DOCROOT as document root') do |docroot|
|
193
199
|
server_options[:DocumentRoot] = File.expand_path(docroot)
|
194
200
|
end
|
195
|
-
opts.on('-a', '--adapter ADAPTER',
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
201
|
+
opts.on('-a', '--adapter ADAPTER',
|
202
|
+
'Use the ADAPTER (full Ruby class) for web server') do |adapter|
|
203
|
+
self.adapter = if adapter.casecmp('webrick') == 0
|
204
|
+
YARD::Server::WebrickAdapter
|
205
|
+
elsif adapter.casecmp('rack') == 0
|
206
|
+
YARD::Server::RackAdapter
|
207
|
+
else
|
208
|
+
eval(adapter) # rubocop:disable Security/Eval
|
209
|
+
end
|
203
210
|
end
|
204
|
-
opts.on('-s', '--server TYPE',
|
211
|
+
opts.on('-s', '--server TYPE',
|
212
|
+
'Use a specific server type eg. thin,mongrel,cgi (Rack specific)') do |type|
|
205
213
|
server_options[:server] = type
|
206
214
|
end
|
207
215
|
opts.on('--fork', 'Use process forking when serving requests') do
|
208
216
|
options[:use_fork] = true
|
209
217
|
end
|
210
218
|
common_options(opts)
|
211
|
-
opts.on('-e', '--load FILE',
|
219
|
+
opts.on('-e', '--load FILE',
|
220
|
+
'A Ruby script to load before the source tree is parsed.') do |file|
|
212
221
|
scripts << file
|
213
222
|
end
|
214
223
|
parse_options(opts, args)
|
@@ -59,7 +59,8 @@ module YARD
|
|
59
59
|
|
60
60
|
if @namespace.is_a?(ConstantObject)
|
61
61
|
unless @namespace.value =~ /\A#{NAMESPACEMATCH}\Z/
|
62
|
-
raise Parser::UndocumentableError, "constant mapping"
|
62
|
+
raise Parser::UndocumentableError, "constant mapping for " +
|
63
|
+
"#{@origname} (type=#{type.inspect})"
|
63
64
|
end
|
64
65
|
|
65
66
|
@origname = nil # forget these for a constant
|
data/lib/yard/globals.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
#
|
6
6
|
# @see YARD::CodeObjects::Proxy
|
7
7
|
# @see YARD::Registry.resolve
|
8
|
-
def P(namespace, name = nil, type = nil) # rubocop:disable
|
8
|
+
def P(namespace, name = nil, type = nil) # rubocop:disable Naming/MethodName
|
9
9
|
if name.nil?
|
10
10
|
name = namespace
|
11
11
|
namespace = nil
|
data/lib/yard/handlers/c/base.rb
CHANGED
@@ -1,129 +1,164 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module YARD
|
3
|
-
module Handlers
|
4
|
-
module C
|
5
|
-
class Base < Handlers::Base
|
6
|
-
include YARD::Parser::C
|
7
|
-
include HandlerMethods
|
8
|
-
|
9
|
-
# @return [Boolean] whether the handler handles this statement
|
10
|
-
def self.handles?(statement, processor)
|
11
|
-
processor.globals.cruby_processed_files ||= {}
|
12
|
-
processor.globals.cruby_processed_files[processor.file] = true
|
13
|
-
|
14
|
-
src = statement.respond_to?(:declaration) ?
|
15
|
-
statement.declaration : statement.source
|
16
|
-
|
17
|
-
handlers.any? do |a_handler|
|
18
|
-
statement_class >= statement.class &&
|
19
|
-
case a_handler
|
20
|
-
when String
|
21
|
-
src == a_handler
|
22
|
-
when Regexp
|
23
|
-
src =~ a_handler
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.statement_class(type = nil)
|
29
|
-
if type
|
30
|
-
@statement_class = type
|
31
|
-
else
|
32
|
-
(defined?(@statement_class) && @statement_class) || Statement
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# @group Registering objects
|
37
|
-
|
38
|
-
def register_docstring(object, docstring = nil, stmt = nil)
|
39
|
-
super(object, docstring, stmt) if docstring
|
40
|
-
end
|
41
|
-
|
42
|
-
def register_file_info(object, file = nil, line = nil, comments = nil)
|
43
|
-
super(object, file, line, comments) if file
|
44
|
-
end
|
45
|
-
|
46
|
-
def register_source(object, source = nil, type = nil)
|
47
|
-
super(object, source, type) if source
|
48
|
-
end
|
49
|
-
|
50
|
-
def register_visibility(object, visibility = nil)
|
51
|
-
super(object, visibility) if visibility
|
52
|
-
end
|
53
|
-
|
54
|
-
# @group Looking up Symbol and Var Values
|
55
|
-
|
56
|
-
def symbols
|
57
|
-
globals.cruby_symbols ||= {}
|
58
|
-
end
|
59
|
-
|
60
|
-
def override_comments
|
61
|
-
globals.cruby_override_comments ||= []
|
62
|
-
end
|
63
|
-
|
64
|
-
def namespace_for_variable(var)
|
65
|
-
return namespaces[var] if namespaces[var]
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module YARD
|
3
|
+
module Handlers
|
4
|
+
module C
|
5
|
+
class Base < Handlers::Base
|
6
|
+
include YARD::Parser::C
|
7
|
+
include HandlerMethods
|
8
|
+
|
9
|
+
# @return [Boolean] whether the handler handles this statement
|
10
|
+
def self.handles?(statement, processor)
|
11
|
+
processor.globals.cruby_processed_files ||= {}
|
12
|
+
processor.globals.cruby_processed_files[processor.file] = true
|
13
|
+
|
14
|
+
src = statement.respond_to?(:declaration) ?
|
15
|
+
statement.declaration : statement.source
|
16
|
+
|
17
|
+
handlers.any? do |a_handler|
|
18
|
+
statement_class >= statement.class &&
|
19
|
+
case a_handler
|
20
|
+
when String
|
21
|
+
src == a_handler
|
22
|
+
when Regexp
|
23
|
+
src =~ a_handler
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.statement_class(type = nil)
|
29
|
+
if type
|
30
|
+
@statement_class = type
|
31
|
+
else
|
32
|
+
(defined?(@statement_class) && @statement_class) || Statement
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# @group Registering objects
|
37
|
+
|
38
|
+
def register_docstring(object, docstring = nil, stmt = nil)
|
39
|
+
super(object, docstring, stmt) if docstring
|
40
|
+
end
|
41
|
+
|
42
|
+
def register_file_info(object, file = nil, line = nil, comments = nil)
|
43
|
+
super(object, file, line, comments) if file
|
44
|
+
end
|
45
|
+
|
46
|
+
def register_source(object, source = nil, type = nil)
|
47
|
+
super(object, source, type) if source
|
48
|
+
end
|
49
|
+
|
50
|
+
def register_visibility(object, visibility = nil)
|
51
|
+
super(object, visibility) if visibility
|
52
|
+
end
|
53
|
+
|
54
|
+
# @group Looking up Symbol and Var Values
|
55
|
+
|
56
|
+
def symbols
|
57
|
+
globals.cruby_symbols ||= {}
|
58
|
+
end
|
59
|
+
|
60
|
+
def override_comments
|
61
|
+
globals.cruby_override_comments ||= []
|
62
|
+
end
|
63
|
+
|
64
|
+
def namespace_for_variable(var)
|
65
|
+
return namespaces[var] if namespaces[var]
|
66
|
+
|
67
|
+
# The global variables for Ruby's core error classes does not
|
68
|
+
# represent their Ruby name. So we need to look up these names.
|
69
|
+
name = ERROR_CLASS_NAMES[var]
|
70
|
+
return P(name) if name
|
71
|
+
|
72
|
+
# Otherwise the name is inferred from the C variable name.
|
73
|
+
var = remove_var_prefix(var)
|
74
|
+
var.empty? ? nil : P(var)
|
75
|
+
end
|
76
|
+
|
77
|
+
def ensure_variable_defined!(var, max_retries = 1)
|
78
|
+
retries = 0
|
79
|
+
object = nil
|
80
|
+
|
81
|
+
loop do
|
82
|
+
object = namespace_for_variable(var)
|
83
|
+
break unless object.is_a?(Proxy)
|
84
|
+
|
85
|
+
raise NamespaceMissingError, object if retries > max_retries
|
86
|
+
log.debug "Missing namespace variable #{var} in file `#{parser.file}', moving it to the back of the line."
|
87
|
+
parser.parse_remaining_files
|
88
|
+
retries += 1
|
89
|
+
end
|
90
|
+
|
91
|
+
object
|
92
|
+
end
|
93
|
+
|
94
|
+
def namespaces
|
95
|
+
globals.cruby_namespaces ||= {}
|
96
|
+
end
|
97
|
+
|
98
|
+
def processed_files
|
99
|
+
globals.cruby_processed_files ||= {}
|
100
|
+
end
|
101
|
+
|
102
|
+
# @group Parsing an Inner Block
|
103
|
+
|
104
|
+
def parse_block(opts = {})
|
105
|
+
return if !statement.block || statement.block.empty?
|
106
|
+
push_state(opts) do
|
107
|
+
parser.process(statement.block)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# @group Processing other files
|
112
|
+
|
113
|
+
def process_file(file, object)
|
114
|
+
file = File.cleanpath(file)
|
115
|
+
return if processed_files[file]
|
116
|
+
processed_files[file] = file
|
117
|
+
begin
|
118
|
+
log.debug "Processing embedded call to C source #{file}..."
|
119
|
+
globals.ordered_parser.files.delete(file) if globals.ordered_parser
|
120
|
+
parser.process(Parser::C::CParser.new(File.read(file), file).parse)
|
121
|
+
rescue Errno::ENOENT
|
122
|
+
log.warn "Missing source file `#{file}' when parsing #{object}"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# @endgroup
|
127
|
+
|
128
|
+
private
|
129
|
+
|
130
|
+
# Generated by update_error_map.rb (Copy+past results)
|
131
|
+
ERROR_CLASS_NAMES = {
|
132
|
+
'rb_eArgError' => 'ArgumentError',
|
133
|
+
'rb_eEncodingError' => 'EncodingError',
|
134
|
+
'rb_eException' => 'Exception',
|
135
|
+
'rb_eFatal' => 'fatal',
|
136
|
+
'rb_eFrozenError' => 'FrozenError',
|
137
|
+
'rb_eIndexError' => 'IndexError',
|
138
|
+
'rb_eInterrupt' => 'Interrupt',
|
139
|
+
'rb_eKeyError' => 'KeyError',
|
140
|
+
'rb_eLoadError' => 'LoadError',
|
141
|
+
'rb_eNameError' => 'NameError',
|
142
|
+
'rb_eNoMatchingPatternError' => 'NoMatchingPatternError',
|
143
|
+
'rb_eNoMemError' => 'NoMemoryError',
|
144
|
+
'rb_eNoMethodError' => 'NoMethodError',
|
145
|
+
'rb_eNotImpError' => 'NotImplementedError',
|
146
|
+
'rb_eRangeError' => 'RangeError',
|
147
|
+
'rb_eRuntimeError' => 'RuntimeError',
|
148
|
+
'rb_eScriptError' => 'ScriptError',
|
149
|
+
'rb_eSecurityError' => 'SecurityError',
|
150
|
+
'rb_eSignal' => 'SignalException',
|
151
|
+
'rb_eStandardError' => 'StandardError',
|
152
|
+
'rb_eSyntaxError' => 'SyntaxError',
|
153
|
+
'rb_eSystemCallError' => 'SystemCallError',
|
154
|
+
'rb_eSystemExit' => 'SystemExit',
|
155
|
+
'rb_eTypeError' => 'TypeError',
|
156
|
+
}
|
157
|
+
|
158
|
+
def remove_var_prefix(var)
|
159
|
+
var.gsub(/^rb_[mc]|^[a-z_]+/, '')
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
@@ -202,8 +202,7 @@ module YARD
|
|
202
202
|
begin; undef on_#{event}; rescue NameError; end
|
203
203
|
def on_#{event}(tok)
|
204
204
|
unless @last_ns_token == [:kw, "def"] ||
|
205
|
-
(@tokens.last && @tokens.last[0] == :symbeg)
|
206
|
-
(!@newline && %w(if while until unless).include?(tok))
|
205
|
+
(@tokens.last && @tokens.last[0] == :symbeg)
|
207
206
|
(@map[tok] ||= []) << [lineno, charno]
|
208
207
|
end
|
209
208
|
visit_ns_token(:#{event}, tok, true)
|
@@ -412,7 +411,7 @@ module YARD
|
|
412
411
|
end
|
413
412
|
|
414
413
|
def on_dyna_symbol(sym)
|
415
|
-
rng = if sym.source_range.size == 0 # rubocop:disable Style/ZeroLengthPredicate
|
414
|
+
rng = if sym.source_range.to_a.size == 0 # rubocop:disable Style/ZeroLengthPredicate
|
416
415
|
(sym.source_range.begin - 3)...sym.source_range.end
|
417
416
|
else
|
418
417
|
(sym.source_range.begin - 2)..(sym.source_range.end + 1)
|
@@ -442,6 +441,8 @@ module YARD
|
|
442
441
|
module_eval(<<-eof, __FILE__, __LINE__ + 1)
|
443
442
|
begin; undef on_#{kw}; rescue NameError; end
|
444
443
|
def on_#{kw}(*args)
|
444
|
+
mapping = @map[#{kw.to_s.sub(/_mod$/, '').inspect}]
|
445
|
+
mapping.pop if mapping
|
445
446
|
sr = args.last.source_range.first..args.first.source_range.last
|
446
447
|
lr = args.last.line_range.first..args.first.line_range.last
|
447
448
|
#{node_class}.new(:#{kw}, args, :line => lr, :char => sr)
|
@@ -612,7 +613,7 @@ module YARD
|
|
612
613
|
|
613
614
|
def insert_comments
|
614
615
|
root.traverse do |node|
|
615
|
-
next if
|
616
|
+
next if [:comment, :void_stmt, :list].include?(node.type) || node.parent.type != :list
|
616
617
|
|
617
618
|
# never attach comments to if/unless mod nodes
|
618
619
|
if node.type == :if_mod || node.type == :unless_mod
|
@@ -684,6 +685,7 @@ module YARD
|
|
684
685
|
end
|
685
686
|
|
686
687
|
def freeze_tree(node = nil)
|
688
|
+
@tokens = @tokens.sort_by {|t| t.last }
|
687
689
|
nodes = [node || root]
|
688
690
|
until nodes.empty?
|
689
691
|
p_node = nodes.shift
|