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.

Files changed (223) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +37 -24
  3. data/CHANGELOG.md +18 -3
  4. data/README.md +96 -101
  5. data/Rakefile +2 -0
  6. data/lib/yard/cli/diff.rb +4 -1
  7. data/lib/yard/cli/server.rb +22 -13
  8. data/lib/yard/code_objects/proxy.rb +2 -1
  9. data/lib/yard/globals.rb +1 -1
  10. data/lib/yard/handlers/c/base.rb +164 -129
  11. data/lib/yard/parser/ruby/ruby_parser.rb +6 -4
  12. data/lib/yard/registry_store.rb +1 -1
  13. data/lib/yard/templates/helpers/html_helper.rb +10 -3
  14. data/lib/yard/templates/helpers/markup/rdoc_markup.rb +5 -4
  15. data/lib/yard/version.rb +1 -1
  16. data/tasks/update_error_map.rake +53 -0
  17. data/yard.gemspec +1 -1
  18. metadata +3 -207
  19. data/spec/cli/command_parser_spec.rb +0 -43
  20. data/spec/cli/command_spec.rb +0 -36
  21. data/spec/cli/config_spec.rb +0 -148
  22. data/spec/cli/diff_spec.rb +0 -254
  23. data/spec/cli/display_spec.rb +0 -30
  24. data/spec/cli/gems_spec.rb +0 -81
  25. data/spec/cli/graph_spec.rb +0 -18
  26. data/spec/cli/help_spec.rb +0 -22
  27. data/spec/cli/i18n_spec.rb +0 -107
  28. data/spec/cli/list_spec.rb +0 -8
  29. data/spec/cli/markup_types_spec.rb +0 -22
  30. data/spec/cli/server_spec.rb +0 -324
  31. data/spec/cli/stats_spec.rb +0 -96
  32. data/spec/cli/yard_on_yard_spec.rb +0 -38
  33. data/spec/cli/yardoc_spec.rb +0 -896
  34. data/spec/cli/yri_spec.rb +0 -101
  35. data/spec/code_objects/base_spec.rb +0 -485
  36. data/spec/code_objects/class_object_spec.rb +0 -226
  37. data/spec/code_objects/code_object_list_spec.rb +0 -36
  38. data/spec/code_objects/constants_spec.rb +0 -116
  39. data/spec/code_objects/extra_file_object_spec.rb +0 -161
  40. data/spec/code_objects/macro_object_spec.rb +0 -150
  41. data/spec/code_objects/method_object_spec.rb +0 -184
  42. data/spec/code_objects/module_object_spec.rb +0 -142
  43. data/spec/code_objects/namespace_mapper_spec.rb +0 -32
  44. data/spec/code_objects/namespace_object_spec.rb +0 -171
  45. data/spec/code_objects/proxy_spec.rb +0 -147
  46. data/spec/code_objects/spec_helper.rb +0 -3
  47. data/spec/config_spec.rb +0 -171
  48. data/spec/core_ext/array_spec.rb +0 -13
  49. data/spec/core_ext/file_spec.rb +0 -72
  50. data/spec/core_ext/hash_spec.rb +0 -14
  51. data/spec/core_ext/insertion_spec.rb +0 -37
  52. data/spec/core_ext/module_spec.rb +0 -9
  53. data/spec/core_ext/string_spec.rb +0 -42
  54. data/spec/core_ext/symbol_hash_spec.rb +0 -89
  55. data/spec/docstring_parser_spec.rb +0 -280
  56. data/spec/docstring_spec.rb +0 -373
  57. data/spec/handlers/alias_handler_spec.rb +0 -82
  58. data/spec/handlers/attribute_handler_spec.rb +0 -96
  59. data/spec/handlers/base_spec.rb +0 -216
  60. data/spec/handlers/c/alias_handler_spec.rb +0 -34
  61. data/spec/handlers/c/attribute_handler_spec.rb +0 -41
  62. data/spec/handlers/c/class_handler_spec.rb +0 -78
  63. data/spec/handlers/c/constant_handler_spec.rb +0 -71
  64. data/spec/handlers/c/init_handler_spec.rb +0 -48
  65. data/spec/handlers/c/method_handler_spec.rb +0 -327
  66. data/spec/handlers/c/mixin_handler_spec.rb +0 -44
  67. data/spec/handlers/c/module_handler_spec.rb +0 -71
  68. data/spec/handlers/c/override_comment_handler_spec.rb +0 -47
  69. data/spec/handlers/c/path_handler_spec.rb +0 -36
  70. data/spec/handlers/c/spec_helper.rb +0 -23
  71. data/spec/handlers/c/struct_handler_spec.rb +0 -16
  72. data/spec/handlers/class_condition_handler_spec.rb +0 -87
  73. data/spec/handlers/class_handler_spec.rb +0 -247
  74. data/spec/handlers/class_method_handler_shared_examples.rb +0 -133
  75. data/spec/handlers/class_variable_handler_spec.rb +0 -12
  76. data/spec/handlers/constant_handler_spec.rb +0 -112
  77. data/spec/handlers/decorator_handler_methods_spec.rb +0 -393
  78. data/spec/handlers/dsl_handler_spec.rb +0 -226
  79. data/spec/handlers/examples/alias_handler_001.rb.txt +0 -46
  80. data/spec/handlers/examples/attribute_handler_001.rb.txt +0 -32
  81. data/spec/handlers/examples/class_condition_handler_001.rb.txt +0 -69
  82. data/spec/handlers/examples/class_handler_001.rb.txt +0 -120
  83. data/spec/handlers/examples/class_variable_handler_001.rb.txt +0 -10
  84. data/spec/handlers/examples/constant_handler_001.rb.txt +0 -35
  85. data/spec/handlers/examples/dsl_handler_001.rb.txt +0 -156
  86. data/spec/handlers/examples/exception_handler_001.rb.txt +0 -59
  87. data/spec/handlers/examples/extend_handler_001.rb.txt +0 -19
  88. data/spec/handlers/examples/method_condition_handler_001.rb.txt +0 -10
  89. data/spec/handlers/examples/method_handler_001.rb.txt +0 -128
  90. data/spec/handlers/examples/mixin_handler_001.rb.txt +0 -40
  91. data/spec/handlers/examples/module_handler_001.rb.txt +0 -29
  92. data/spec/handlers/examples/private_constant_handler_001.rb.txt +0 -8
  93. data/spec/handlers/examples/process_handler_001.rb.txt +0 -11
  94. data/spec/handlers/examples/visibility_handler_001.rb.txt +0 -36
  95. data/spec/handlers/examples/yield_handler_001.rb.txt +0 -54
  96. data/spec/handlers/exception_handler_spec.rb +0 -49
  97. data/spec/handlers/extend_handler_spec.rb +0 -28
  98. data/spec/handlers/legacy_base_spec.rb +0 -128
  99. data/spec/handlers/method_condition_handler_spec.rb +0 -15
  100. data/spec/handlers/method_handler_spec.rb +0 -214
  101. data/spec/handlers/mixin_handler_spec.rb +0 -60
  102. data/spec/handlers/module_function_handler_spec.rb +0 -106
  103. data/spec/handlers/module_handler_spec.rb +0 -35
  104. data/spec/handlers/private_class_method_handler_spec.rb +0 -11
  105. data/spec/handlers/private_constant_handler_spec.rb +0 -25
  106. data/spec/handlers/processor_spec.rb +0 -35
  107. data/spec/handlers/public_class_method_handler_spec.rb +0 -11
  108. data/spec/handlers/ruby/base_spec.rb +0 -95
  109. data/spec/handlers/ruby/legacy/base_spec.rb +0 -84
  110. data/spec/handlers/spec_helper.rb +0 -33
  111. data/spec/handlers/visibility_handler_spec.rb +0 -44
  112. data/spec/handlers/yield_handler_spec.rb +0 -52
  113. data/spec/i18n/locale_spec.rb +0 -81
  114. data/spec/i18n/message_spec.rb +0 -52
  115. data/spec/i18n/messages_spec.rb +0 -67
  116. data/spec/i18n/pot_generator_spec.rb +0 -295
  117. data/spec/i18n/text_spec.rb +0 -184
  118. data/spec/logging_spec.rb +0 -44
  119. data/spec/options_spec.rb +0 -171
  120. data/spec/parser/base_spec.rb +0 -24
  121. data/spec/parser/c_parser_spec.rb +0 -236
  122. data/spec/parser/examples/array.c.txt +0 -6267
  123. data/spec/parser/examples/example1.rb.txt +0 -8
  124. data/spec/parser/examples/extrafile.c.txt +0 -8
  125. data/spec/parser/examples/file.c.txt +0 -28
  126. data/spec/parser/examples/multifile.c.txt +0 -22
  127. data/spec/parser/examples/namespace.cpp.txt +0 -68
  128. data/spec/parser/examples/override.c.txt +0 -424
  129. data/spec/parser/examples/parse_in_order_001.rb.txt +0 -2
  130. data/spec/parser/examples/parse_in_order_002.rb.txt +0 -2
  131. data/spec/parser/examples/tag_handler_001.rb.txt +0 -8
  132. data/spec/parser/ruby/ast_node_spec.rb +0 -33
  133. data/spec/parser/ruby/legacy/statement_list_spec.rb +0 -299
  134. data/spec/parser/ruby/legacy/token_list_spec.rb +0 -79
  135. data/spec/parser/ruby/ruby_parser_spec.rb +0 -520
  136. data/spec/parser/ruby/token_resolver_spec.rb +0 -165
  137. data/spec/parser/source_parser_spec.rb +0 -727
  138. data/spec/parser/tag_parsing_spec.rb +0 -17
  139. data/spec/rake/yardoc_task_spec.rb +0 -118
  140. data/spec/registry_resolver_spec.rb +0 -15
  141. data/spec/registry_spec.rb +0 -463
  142. data/spec/registry_store_spec.rb +0 -327
  143. data/spec/rubygems/doc_manager_spec.rb +0 -112
  144. data/spec/serializers/data/serialized_yardoc/checksums +0 -1
  145. data/spec/serializers/data/serialized_yardoc/objects/Foo.dat +0 -0
  146. data/spec/serializers/data/serialized_yardoc/objects/Foo/bar_i.dat +0 -0
  147. data/spec/serializers/data/serialized_yardoc/objects/Foo/baz_i.dat +0 -0
  148. data/spec/serializers/data/serialized_yardoc/objects/root.dat +0 -0
  149. data/spec/serializers/data/serialized_yardoc/proxy_types +0 -2
  150. data/spec/serializers/file_system_serializer_spec.rb +0 -145
  151. data/spec/serializers/spec_helper.rb +0 -2
  152. data/spec/serializers/yardoc_serializer_spec.rb +0 -90
  153. data/spec/server/adapter_spec.rb +0 -39
  154. data/spec/server/commands/base_spec.rb +0 -91
  155. data/spec/server/commands/library_command_spec.rb +0 -39
  156. data/spec/server/doc_server_helper_spec.rb +0 -72
  157. data/spec/server/doc_server_serializer_spec.rb +0 -60
  158. data/spec/server/rack_adapter_spec.rb +0 -21
  159. data/spec/server/router_spec.rb +0 -123
  160. data/spec/server/spec_helper.rb +0 -22
  161. data/spec/server/static_caching_spec.rb +0 -47
  162. data/spec/server/webrick_servlet_spec.rb +0 -20
  163. data/spec/server_spec.rb +0 -19
  164. data/spec/spec_helper.rb +0 -212
  165. data/spec/tags/default_factory_spec.rb +0 -168
  166. data/spec/tags/default_tag_spec.rb +0 -11
  167. data/spec/tags/directives_spec.rb +0 -463
  168. data/spec/tags/library_spec.rb +0 -48
  169. data/spec/tags/overload_tag_spec.rb +0 -53
  170. data/spec/tags/ref_tag_list_spec.rb +0 -53
  171. data/spec/tags/types_explainer_spec.rb +0 -203
  172. data/spec/templates/class_spec.rb +0 -45
  173. data/spec/templates/constant_spec.rb +0 -41
  174. data/spec/templates/engine_spec.rb +0 -131
  175. data/spec/templates/examples/class001.html +0 -308
  176. data/spec/templates/examples/class001.txt +0 -36
  177. data/spec/templates/examples/class002.html +0 -39
  178. data/spec/templates/examples/constant001.txt +0 -25
  179. data/spec/templates/examples/constant002.txt +0 -7
  180. data/spec/templates/examples/constant003.txt +0 -11
  181. data/spec/templates/examples/method001.html +0 -137
  182. data/spec/templates/examples/method001.txt +0 -35
  183. data/spec/templates/examples/method002.html +0 -91
  184. data/spec/templates/examples/method002.txt +0 -20
  185. data/spec/templates/examples/method003.html +0 -165
  186. data/spec/templates/examples/method003.txt +0 -45
  187. data/spec/templates/examples/method004.html +0 -48
  188. data/spec/templates/examples/method004.txt +0 -10
  189. data/spec/templates/examples/method005.html +0 -105
  190. data/spec/templates/examples/method005.txt +0 -33
  191. data/spec/templates/examples/method006.html +0 -108
  192. data/spec/templates/examples/method006.txt +0 -20
  193. data/spec/templates/examples/module001.dot +0 -33
  194. data/spec/templates/examples/module001.html +0 -833
  195. data/spec/templates/examples/module001.txt +0 -33
  196. data/spec/templates/examples/module002.html +0 -341
  197. data/spec/templates/examples/module003.html +0 -202
  198. data/spec/templates/examples/module004.html +0 -394
  199. data/spec/templates/examples/module005.html +0 -82
  200. data/spec/templates/examples/tag001.txt +0 -82
  201. data/spec/templates/helpers/base_helper_spec.rb +0 -171
  202. data/spec/templates/helpers/html_helper_spec.rb +0 -666
  203. data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +0 -65
  204. data/spec/templates/helpers/markup/rdoc_markup_spec.rb +0 -84
  205. data/spec/templates/helpers/markup_helper_spec.rb +0 -136
  206. data/spec/templates/helpers/method_helper_spec.rb +0 -107
  207. data/spec/templates/helpers/module_helper_spec.rb +0 -35
  208. data/spec/templates/helpers/shared_signature_examples.rb +0 -126
  209. data/spec/templates/helpers/text_helper_spec.rb +0 -65
  210. data/spec/templates/markup_processor_integrations/asciidoctor_spec.rb +0 -60
  211. data/spec/templates/markup_processor_integrations/integration_spec_helper.rb +0 -50
  212. data/spec/templates/markup_processor_integrations/rdoc_markdown_spec.rb +0 -48
  213. data/spec/templates/markup_processor_integrations/rdoc_spec.rb +0 -39
  214. data/spec/templates/markup_processor_integrations/redcarpet_spec.rb +0 -64
  215. data/spec/templates/markup_processor_integrations/redcloth_spec.rb +0 -64
  216. data/spec/templates/method_spec.rb +0 -118
  217. data/spec/templates/module_spec.rb +0 -203
  218. data/spec/templates/onefile_spec.rb +0 -66
  219. data/spec/templates/section_spec.rb +0 -144
  220. data/spec/templates/spec_helper.rb +0 -76
  221. data/spec/templates/tag_spec.rb +0 -52
  222. data/spec/templates/template_spec.rb +0 -410
  223. data/spec/verifier_spec.rb +0 -106
data/Rakefile CHANGED
@@ -6,6 +6,8 @@ require 'samus'
6
6
 
7
7
  YARD::VERSION.replace(ENV['YARD_VERSION']) if ENV['YARD_VERSION']
8
8
 
9
+ Dir['tasks/**/*.rake'].each { |task_file| load task_file }
10
+
9
11
  desc "Builds the gem"
10
12
  task :gem do
11
13
  sh "gem build yard.gemspec"
@@ -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
- open(url) {|io| expand_and_parse(gemfile, io) }
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
@@ -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, nil, :gem)]
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, spec.version.to_s, nil, :gem)]
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]', 'Serves documentation for gems from Gemfile') do |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', 'Use the ADAPTER (full Ruby class) for web server') do |adapter|
196
- if adapter.casecmp('webrick') == 0
197
- self.adapter = YARD::Server::WebrickAdapter
198
- elsif adapter.casecmp('rack') == 0
199
- self.adapter = YARD::Server::RackAdapter
200
- else
201
- self.adapter = eval(adapter) # rubocop:disable Lint/Eval
202
- end
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', 'Use a specific server type eg. thin,mongrel,cgi (Rack specific)') do |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', 'A Ruby script to load before the source tree is parsed.') do |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
@@ -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 Style/MethodName
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
@@ -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
- var = remove_var_prefix(var)
67
- var.empty? ? nil : P(var)
68
- end
69
-
70
- def ensure_variable_defined!(var, max_retries = 1)
71
- retries = 0
72
- object = nil
73
-
74
- loop do
75
- object = namespace_for_variable(var)
76
- break unless object.is_a?(Proxy)
77
-
78
- raise NamespaceMissingError, object if retries > max_retries
79
- log.debug "Missing namespace variable #{var} in file `#{parser.file}', moving it to the back of the line."
80
- parser.parse_remaining_files
81
- retries += 1
82
- end
83
-
84
- object
85
- end
86
-
87
- def namespaces
88
- globals.cruby_namespaces ||= {}
89
- end
90
-
91
- def processed_files
92
- globals.cruby_processed_files ||= {}
93
- end
94
-
95
- # @group Parsing an Inner Block
96
-
97
- def parse_block(opts = {})
98
- return if !statement.block || statement.block.empty?
99
- push_state(opts) do
100
- parser.process(statement.block)
101
- end
102
- end
103
-
104
- # @group Processing other files
105
-
106
- def process_file(file, object)
107
- file = File.cleanpath(file)
108
- return if processed_files[file]
109
- processed_files[file] = file
110
- begin
111
- log.debug "Processing embedded call to C source #{file}..."
112
- globals.ordered_parser.files.delete(file) if globals.ordered_parser
113
- parser.process(Parser::C::CParser.new(File.read(file), file).parse)
114
- rescue Errno::ENOENT
115
- log.warn "Missing source file `#{file}' when parsing #{object}"
116
- end
117
- end
118
-
119
- # @endgroup
120
-
121
- private
122
-
123
- def remove_var_prefix(var)
124
- var.gsub(/^rb_[mc]|^[a-z_]+/, '')
125
- end
126
- end
127
- end
128
- end
129
- end
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 %i{comment void_stmt list}.include?(node.type) || node.parent.type != :list
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