yard 0.6.8 → 0.7.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.

Files changed (224) hide show
  1. data/.yardopts +1 -0
  2. data/ChangeLog +723 -0
  3. data/README.md +16 -6
  4. data/docs/CodeObjects.md +10 -16
  5. data/docs/GettingStarted.md +232 -32
  6. data/docs/Glossary.md +1 -2
  7. data/docs/Handlers.md +10 -16
  8. data/docs/Overview.md +14 -13
  9. data/docs/Parser.md +13 -22
  10. data/docs/Tags.md +209 -16
  11. data/docs/Templates.md +237 -26
  12. data/docs/WhatsNew.md +178 -2
  13. data/lib/yard.rb +13 -10
  14. data/lib/yard/autoload.rb +22 -18
  15. data/lib/yard/cli/command.rb +13 -12
  16. data/lib/yard/cli/command_parser.rb +20 -19
  17. data/lib/yard/cli/config.rb +19 -19
  18. data/lib/yard/cli/diff.rb +46 -21
  19. data/lib/yard/cli/gems.rb +11 -11
  20. data/lib/yard/cli/graph.rb +13 -13
  21. data/lib/yard/cli/help.rb +1 -1
  22. data/lib/yard/cli/list.rb +22 -0
  23. data/lib/yard/cli/server.rb +17 -17
  24. data/lib/yard/cli/stats.rb +32 -32
  25. data/lib/yard/cli/yardoc.rb +181 -135
  26. data/lib/yard/cli/yri.rb +29 -29
  27. data/lib/yard/code_objects/base.rb +101 -101
  28. data/lib/yard/code_objects/class_object.rb +20 -20
  29. data/lib/yard/code_objects/constant_object.rb +1 -1
  30. data/lib/yard/code_objects/extended_method_object.rb +5 -5
  31. data/lib/yard/code_objects/extra_file_object.rb +89 -0
  32. data/lib/yard/code_objects/macro_object.rb +215 -0
  33. data/lib/yard/code_objects/method_object.rb +30 -30
  34. data/lib/yard/code_objects/module_object.rb +1 -1
  35. data/lib/yard/code_objects/namespace_object.rb +39 -39
  36. data/lib/yard/code_objects/proxy.rb +38 -38
  37. data/lib/yard/code_objects/root_object.rb +1 -1
  38. data/lib/yard/config.rb +40 -40
  39. data/lib/yard/core_ext/array.rb +2 -2
  40. data/lib/yard/core_ext/file.rb +11 -11
  41. data/lib/yard/core_ext/insertion.rb +10 -10
  42. data/lib/yard/core_ext/module.rb +2 -2
  43. data/lib/yard/core_ext/string.rb +2 -2
  44. data/lib/yard/core_ext/symbol_hash.rb +14 -14
  45. data/lib/yard/docstring.rb +122 -54
  46. data/lib/yard/globals.rb +2 -2
  47. data/lib/yard/handlers/base.rb +216 -127
  48. data/lib/yard/handlers/processor.rb +65 -27
  49. data/lib/yard/handlers/ruby/alias_handler.rb +6 -3
  50. data/lib/yard/handlers/ruby/attribute_handler.rb +7 -6
  51. data/lib/yard/handlers/ruby/base.rb +50 -31
  52. data/lib/yard/handlers/ruby/class_condition_handler.rb +11 -11
  53. data/lib/yard/handlers/ruby/class_handler.rb +10 -10
  54. data/lib/yard/handlers/ruby/class_variable_handler.rb +3 -3
  55. data/lib/yard/handlers/ruby/constant_handler.rb +7 -7
  56. data/lib/yard/handlers/ruby/exception_handler.rb +2 -2
  57. data/lib/yard/handlers/ruby/extend_handler.rb +1 -1
  58. data/lib/yard/handlers/ruby/legacy/alias_handler.rb +8 -5
  59. data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +6 -5
  60. data/lib/yard/handlers/ruby/legacy/base.rb +42 -27
  61. data/lib/yard/handlers/ruby/legacy/class_condition_handler.rb +9 -9
  62. data/lib/yard/handlers/ruby/legacy/class_handler.rb +13 -12
  63. data/lib/yard/handlers/ruby/legacy/class_variable_handler.rb +3 -6
  64. data/lib/yard/handlers/ruby/legacy/constant_handler.rb +5 -8
  65. data/lib/yard/handlers/ruby/legacy/exception_handler.rb +1 -1
  66. data/lib/yard/handlers/ruby/legacy/extend_handler.rb +1 -0
  67. data/lib/yard/handlers/ruby/legacy/macro_handler.rb +40 -0
  68. data/lib/yard/handlers/ruby/legacy/method_handler.rb +10 -10
  69. data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +4 -3
  70. data/lib/yard/handlers/ruby/legacy/module_handler.rb +2 -1
  71. data/lib/yard/handlers/ruby/legacy/private_constant_handler.rb +4 -4
  72. data/lib/yard/handlers/ruby/legacy/visibility_handler.rb +2 -1
  73. data/lib/yard/handlers/ruby/legacy/yield_handler.rb +3 -3
  74. data/lib/yard/handlers/ruby/macro_handler.rb +41 -0
  75. data/lib/yard/handlers/ruby/macro_handler_methods.rb +130 -0
  76. data/lib/yard/handlers/ruby/method_condition_handler.rb +1 -1
  77. data/lib/yard/handlers/ruby/method_handler.rb +13 -13
  78. data/lib/yard/handlers/ruby/mixin_handler.rb +4 -4
  79. data/lib/yard/handlers/ruby/module_handler.rb +2 -1
  80. data/lib/yard/handlers/ruby/private_constant_handler.rb +4 -4
  81. data/lib/yard/handlers/ruby/struct_handler_methods.rb +11 -11
  82. data/lib/yard/handlers/ruby/visibility_handler.rb +1 -1
  83. data/lib/yard/handlers/ruby/yield_handler.rb +5 -5
  84. data/lib/yard/logging.rb +11 -11
  85. data/lib/yard/parser/base.rb +8 -8
  86. data/lib/yard/parser/c_parser.rb +42 -33
  87. data/lib/yard/parser/ruby/ast_node.rb +62 -61
  88. data/lib/yard/parser/ruby/legacy/ruby_lex.rb +66 -66
  89. data/lib/yard/parser/ruby/legacy/ruby_parser.rb +4 -4
  90. data/lib/yard/parser/ruby/legacy/statement.rb +11 -11
  91. data/lib/yard/parser/ruby/legacy/statement_list.rb +15 -15
  92. data/lib/yard/parser/ruby/legacy/token_list.rb +9 -9
  93. data/lib/yard/parser/ruby/ruby_parser.rb +51 -37
  94. data/lib/yard/parser/source_parser.rb +271 -46
  95. data/lib/yard/rake/yardoc_task.rb +18 -17
  96. data/lib/yard/registry.rb +64 -64
  97. data/lib/yard/registry_store.rb +34 -34
  98. data/lib/yard/rubygems/backports.rb +8 -0
  99. data/lib/yard/rubygems/backports/LICENSE.txt +57 -0
  100. data/lib/yard/rubygems/backports/MIT.txt +20 -0
  101. data/lib/yard/rubygems/backports/gem.rb +8 -0
  102. data/lib/yard/rubygems/backports/source_index.rb +353 -0
  103. data/lib/yard/rubygems/specification.rb +2 -2
  104. data/lib/yard/serializers/base.rb +20 -20
  105. data/lib/yard/serializers/file_system_serializer.rb +28 -24
  106. data/lib/yard/serializers/process_serializer.rb +3 -3
  107. data/lib/yard/serializers/stdout_serializer.rb +6 -6
  108. data/lib/yard/serializers/yardoc_serializer.rb +17 -17
  109. data/lib/yard/server/adapter.rb +12 -12
  110. data/lib/yard/server/commands/base.rb +26 -26
  111. data/lib/yard/server/commands/display_file_command.rb +3 -2
  112. data/lib/yard/server/commands/display_object_command.rb +5 -5
  113. data/lib/yard/server/commands/frames_command.rb +1 -1
  114. data/lib/yard/server/commands/library_command.rb +7 -7
  115. data/lib/yard/server/commands/library_index_command.rb +2 -2
  116. data/lib/yard/server/commands/list_command.rb +8 -8
  117. data/lib/yard/server/commands/search_command.rb +8 -8
  118. data/lib/yard/server/commands/static_file_command.rb +3 -3
  119. data/lib/yard/server/doc_server_helper.rb +6 -3
  120. data/lib/yard/server/doc_server_serializer.rb +1 -1
  121. data/lib/yard/server/library_version.rb +45 -45
  122. data/lib/yard/server/rack_adapter.rb +10 -10
  123. data/lib/yard/server/router.rb +28 -28
  124. data/lib/yard/server/static_caching.rb +5 -5
  125. data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +3 -3
  126. data/lib/yard/server/templates/default/fulldoc/html/js/live.js +1 -1
  127. data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +2 -2
  128. data/lib/yard/server/templates/default/layout/html/headers.erb +13 -8
  129. data/lib/yard/server/templates/default/layout/html/setup.rb +7 -0
  130. data/lib/yard/server/templates/doc_server/full_list/html/full_list.erb +2 -2
  131. data/lib/yard/server/templates/doc_server/full_list/html/setup.rb +14 -4
  132. data/lib/yard/server/templates/doc_server/library_list/html/contents.erb +2 -2
  133. data/lib/yard/server/templates/doc_server/library_list/html/headers.erb +2 -2
  134. data/lib/yard/server/templates/doc_server/processing/html/processing.erb +1 -1
  135. data/lib/yard/server/templates/doc_server/search/html/search.erb +1 -1
  136. data/lib/yard/server/webrick_adapter.rb +2 -2
  137. data/lib/yard/tags/default_factory.rb +19 -19
  138. data/lib/yard/tags/default_tag.rb +1 -1
  139. data/lib/yard/tags/library.rb +68 -63
  140. data/lib/yard/tags/option_tag.rb +1 -1
  141. data/lib/yard/tags/overload_tag.rb +9 -9
  142. data/lib/yard/tags/ref_tag_list.rb +2 -2
  143. data/lib/yard/tags/tag.rb +7 -7
  144. data/lib/yard/templates/engine.rb +31 -31
  145. data/lib/yard/templates/erb_cache.rb +1 -1
  146. data/lib/yard/templates/helpers/base_helper.rb +46 -32
  147. data/lib/yard/templates/helpers/filter_helper.rb +2 -2
  148. data/lib/yard/templates/helpers/html_helper.rb +120 -81
  149. data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +4 -4
  150. data/lib/yard/templates/helpers/markup/rdoc_markup.rb +9 -9
  151. data/lib/yard/templates/helpers/markup_helper.rb +37 -30
  152. data/lib/yard/templates/helpers/method_helper.rb +7 -7
  153. data/lib/yard/templates/helpers/text_helper.rb +7 -7
  154. data/lib/yard/templates/helpers/uml_helper.rb +3 -3
  155. data/lib/yard/templates/section.rb +14 -14
  156. data/lib/yard/templates/template.rb +54 -54
  157. data/lib/yard/verifier.rb +27 -27
  158. data/spec/cli/list_spec.rb +8 -0
  159. data/spec/cli/yardoc_spec.rb +58 -10
  160. data/spec/code_objects/extra_file_object_spec.rb +132 -0
  161. data/spec/code_objects/macro_object_spec.rb +154 -0
  162. data/spec/docstring_spec.rb +90 -0
  163. data/spec/handlers/base_spec.rb +22 -0
  164. data/spec/handlers/examples/macro_handler_001.rb.txt +73 -0
  165. data/spec/handlers/examples/method_handler_001.rb.txt +17 -0
  166. data/spec/handlers/macro_handler_spec.rb +140 -0
  167. data/spec/handlers/method_handler_spec.rb +28 -0
  168. data/spec/handlers/processor_spec.rb +4 -0
  169. data/spec/handlers/spec_helper.rb +1 -1
  170. data/spec/parser/c_parser_spec.rb +47 -16
  171. data/spec/parser/examples/extrafile.c.txt +8 -0
  172. data/spec/parser/examples/multifile.c.txt +6 -0
  173. data/spec/parser/ruby/ruby_parser_spec.rb +5 -0
  174. data/spec/parser/source_parser_spec.rb +235 -0
  175. data/spec/rake/yardoc_task_spec.rb +22 -17
  176. data/spec/serializers/file_system_serializer_spec.rb +6 -0
  177. data/spec/server/commands/library_command_spec.rb +39 -0
  178. data/spec/spec_helper.rb +14 -0
  179. data/spec/templates/examples/method001.html +6 -6
  180. data/spec/templates/examples/method002.html +4 -4
  181. data/spec/templates/examples/method003.html +10 -10
  182. data/spec/templates/examples/method005.html +2 -2
  183. data/spec/templates/examples/module001.dot +2 -0
  184. data/spec/templates/examples/module001.html +76 -37
  185. data/spec/templates/examples/module001.txt +1 -1
  186. data/spec/templates/helpers/base_helper_spec.rb +7 -2
  187. data/spec/templates/helpers/html_helper_spec.rb +49 -5
  188. data/spec/templates/helpers/markup_helper_spec.rb +9 -8
  189. data/spec/templates/module_spec.rb +7 -0
  190. data/spec/templates/onefile_spec.rb +47 -0
  191. data/templates/default/fulldoc/html/css/style.css +7 -5
  192. data/templates/default/fulldoc/html/full_list.erb +13 -10
  193. data/templates/default/fulldoc/html/full_list_files.erb +1 -1
  194. data/templates/default/fulldoc/html/js/app.js +16 -14
  195. data/templates/default/fulldoc/html/js/full_list.js +7 -6
  196. data/templates/default/fulldoc/html/setup.rb +78 -17
  197. data/templates/default/layout/html/files.erb +1 -1
  198. data/templates/default/layout/html/headers.erb +11 -7
  199. data/templates/default/layout/html/search.erb +4 -4
  200. data/templates/default/layout/html/setup.rb +28 -8
  201. data/templates/default/module/html/inherited_attributes.erb +17 -0
  202. data/templates/default/module/setup.rb +1 -1
  203. data/templates/default/onefile/html/files.erb +2 -2
  204. data/templates/default/onefile/html/layout.erb +1 -1
  205. data/templates/default/onefile/html/setup.rb +7 -5
  206. data/templates/default/tags/html/option.erb +1 -1
  207. data/templates/default/tags/html/tag.erb +3 -3
  208. data/templates/guide/class/html/setup.rb +1 -0
  209. data/templates/guide/docstring/html/setup.rb +1 -0
  210. data/templates/guide/fulldoc/html/css/style.css +91 -0
  211. data/templates/guide/fulldoc/html/js/app.js +33 -0
  212. data/templates/guide/fulldoc/html/setup.rb +54 -0
  213. data/templates/guide/layout/html/layout.erb +81 -0
  214. data/templates/guide/layout/html/setup.rb +24 -0
  215. data/templates/guide/method/html/header.erb +18 -0
  216. data/templates/guide/method/html/setup.rb +21 -0
  217. data/templates/guide/module/html/header.erb +7 -0
  218. data/templates/guide/module/html/method_list.erb +5 -0
  219. data/templates/guide/module/html/setup.rb +26 -0
  220. data/templates/guide/tags/html/setup.rb +8 -0
  221. metadata +40 -7
  222. data/lib/yard/handlers/ruby/legacy/process_handler.rb +0 -13
  223. data/lib/yard/handlers/ruby/process_handler.rb +0 -18
  224. data/spec/handlers/process_handler_spec.rb +0 -17
@@ -3,15 +3,15 @@ module YARD
3
3
  module Ruby
4
4
  # Builds and s-expression by creating {AstNode} objects with
5
5
  # the type provided by the first argument.
6
- #
6
+ #
7
7
  # @example An implicit list of keywords
8
8
  # ast = s(s(:kw, "if"), s(:kw, "else"))
9
9
  # ast.type # => :list
10
10
  # @example A method call
11
11
  # s(:command, s(:var_ref, "mymethod"))
12
- #
12
+ #
13
13
  # @overload s(*nodes, opts = {})
14
- # @param [Array<AstNode>] nodes a list of nodes.
14
+ # @param [Array<AstNode>] nodes a list of nodes.
15
15
  # @param [Hash] opts any extra options (docstring, file, source) to
16
16
  # set on the object
17
17
  # @return [AstNode] an implicit node where node.type == +:list+
@@ -26,16 +26,16 @@ module YARD
26
26
  opts = Hash === args.last ? args.pop : {}
27
27
  AstNode.node_class_for(type).new(type, args, opts)
28
28
  end
29
-
29
+
30
30
  # An AST node is characterized by a type and a list of children. It
31
31
  # is most easily represented by the s-expression {#s} such as:
32
32
  # # AST for "if true; 5 end":
33
33
  # s(s(:if, s(:var_ref, s(:kw, "true")), s(s(:int, "5")), nil))
34
- #
34
+ #
35
35
  # The node type is not considered part of the list, only its children.
36
36
  # So +ast[0]+ does not refer to the type, but rather the first child
37
37
  # (or object). Items that are not +AstNode+ objects can be part of the
38
- # list, like Strings or Symbols representing names. To return only
38
+ # list, like Strings or Symbols representing names. To return only
39
39
  # the AstNode children of the node, use {#children}.
40
40
  class AstNode < Array
41
41
  attr_accessor :docstring_hash_flag
@@ -45,10 +45,10 @@ module YARD
45
45
  alias comments_range docstring_range
46
46
  alias comments_hash_flag docstring_hash_flag
47
47
  alias to_s source
48
-
48
+
49
49
  # @return [Symbol] the node's unique symbolic type
50
50
  attr_accessor :type
51
-
51
+
52
52
  # @return [AstNode, nil] the node's parent or nil if it is a root node.
53
53
  attr_accessor :parent
54
54
 
@@ -58,7 +58,7 @@ module YARD
58
58
  reset_line_info unless @source_range
59
59
  @source_range
60
60
  end
61
-
61
+
62
62
  # @return [Range] the line range in {#full_source} represented
63
63
  # by the node
64
64
  def line_range
@@ -84,9 +84,9 @@ module YARD
84
84
  return parent.full_source[source_range] if parent
85
85
  full_source
86
86
  end
87
-
87
+
88
88
  # List of all known keywords
89
- # @return [Hash]
89
+ # @return [Hash]
90
90
  KEYWORDS = { :class => true, :alias => true, :lambda => true, :do_block => true,
91
91
  :def => true, :defs => true, :begin => true, :rescue => true, :rescue_mod => true,
92
92
  :if => true, :if_mod => true, :else => true, :elsif => true, :case => true,
@@ -94,12 +94,12 @@ module YARD
94
94
  :return => true, :throw => true, :catch => true, :until => true, :until_mod => true,
95
95
  :while => true, :while_mod => true, :yield => true, :yield0 => true, :zsuper => true,
96
96
  :unless => true, :unless_mod => true, :for => true, :super => true, :return0 => true }
97
-
97
+
98
98
  # @group Creating an AstNode
99
99
 
100
100
  # Finds the node subclass that should be instantiated for a specific
101
101
  # node type
102
- #
102
+ #
103
103
  # @param [Symbol] type the node type to find a subclass for
104
104
  # @return [Class] a subclass of AstNode to instantiate the node with.
105
105
  def self.node_class_for(type)
@@ -122,9 +122,9 @@ module YARD
122
122
  end
123
123
  end
124
124
  end
125
-
125
+
126
126
  # Creates a new AST node
127
- #
127
+ #
128
128
  # @param [Symbol] type the type of node being created
129
129
  # @param [Array<AstNode>] arr the child nodes
130
130
  # @param [Hash] opts any extra line options
@@ -145,33 +145,33 @@ module YARD
145
145
  @fallback_source = opts[:listchar]
146
146
  @token = true if opts[:token]
147
147
  end
148
-
149
- # @return [Boolean] whether the node is equal to another by checking
148
+
149
+ # @return [Boolean] whether the node is equal to another by checking
150
150
  # the list and type
151
151
  # @private
152
152
  def ==(ast)
153
153
  super && type == ast.type
154
154
  end
155
-
155
+
156
156
  # @group Traversing a Node
157
-
157
+
158
158
  # Searches through the node and all descendants and returns the
159
159
  # first node with a type matching any of +node_types+, otherwise
160
160
  # returns the original node (self).
161
- #
161
+ #
162
162
  # @example Returns the first method definition in a block of code
163
163
  # ast = YARD.parse_string("if true; def x; end end").ast
164
164
  # ast.jump(:def)
165
- # # => s(:def, s(:ident, "x"), s(:params, nil, nil, nil, nil,
165
+ # # => s(:def, s(:ident, "x"), s(:params, nil, nil, nil, nil,
166
166
  # # nil), s(s(:void_stmt, )))
167
167
  # @example Returns first 'def' or 'class' statement
168
168
  # ast = YARD.parse_string("class X; def y; end end")
169
169
  # ast.jump(:def, :class).first
170
- # # =>
170
+ # # =>
171
171
  # @example If the node types are not present in the AST
172
172
  # ast = YARD.parse("def x; end")
173
173
  # ast.jump(:def)
174
- #
174
+ #
175
175
  # @param [Array<Symbol>] node_types a set of node types to match
176
176
  # @return [AstNode] the matching node, if one was found
177
177
  # @return [self] if no node was found
@@ -186,10 +186,10 @@ module YARD
186
186
  end
187
187
 
188
188
  # Traverses the object and yields each node (including descendants) in order.
189
- #
189
+ #
190
190
  # @yield each descendant node in order
191
191
  # @yieldparam [AstNode] self, or a child/descendant node
192
- # @return [void]
192
+ # @return [void]
193
193
  def traverse
194
194
  nodes = [self]
195
195
  nodes.each.with_index do |node, index|
@@ -197,64 +197,64 @@ module YARD
197
197
  nodes.insert index+1, *node.children
198
198
  end
199
199
  end
200
-
200
+
201
201
  # @group Node Meta Types
202
202
 
203
203
  # @return [Boolean] whether the node is a token
204
204
  def token?
205
205
  @token
206
206
  end
207
-
208
- # @return [Boolean] whether the node is a reference (variable,
207
+
208
+ # @return [Boolean] whether the node is a reference (variable,
209
209
  # constant name)
210
210
  def ref?
211
211
  false
212
212
  end
213
-
213
+
214
214
  # @return [Boolean] whether the node is a literal value
215
215
  def literal?
216
216
  false
217
217
  end
218
-
218
+
219
219
  # @return [Boolean] whether the node is a keyword
220
220
  def kw?
221
221
  false
222
222
  end
223
-
223
+
224
224
  # @return [Boolean] whether the node is a method call
225
225
  def call?
226
226
  false
227
227
  end
228
-
228
+
229
229
  # @return [Boolean] whether the node is a if/elsif/else condition
230
230
  def condition?
231
231
  false
232
232
  end
233
233
 
234
234
  # @group Getting Line Information
235
-
235
+
236
236
  # @return [Boolean] whether the node has a {#line_range} set
237
237
  def has_line?
238
238
  @line_range ? true : false
239
239
  end
240
-
240
+
241
241
  # @return [Fixnum] the starting line number of the node
242
242
  def line
243
243
  line_range && line_range.first
244
244
  end
245
-
245
+
246
246
  # @return [String] the first line of source represented by the node.
247
247
  def first_line
248
248
  full_source.split(/\r?\n/)[line - 1].strip
249
249
  end
250
250
 
251
251
  # @group Printing a Node
252
-
252
+
253
253
  # @return [String] the first line of source the node represents
254
254
  def show
255
255
  "\t#{line}: #{first_line}"
256
256
  end
257
-
257
+
258
258
  # @return [nil] pretty prints the node
259
259
  def pretty_print(q)
260
260
  objs = self.dup + [:__last__]
@@ -271,37 +271,37 @@ module YARD
271
271
  objs.pop if options.size == 0
272
272
 
273
273
  q.group(3, 's(', ')') do
274
- q.seplist(objs, nil, :each) do |v|
274
+ q.seplist(objs, nil, :each) do |v|
275
275
  if v == :__last__
276
276
  q.seplist(options, nil, :each) do |arr|
277
277
  k, v2 = *arr
278
- q.group(3) do
278
+ q.group(3) do
279
279
  q.text k
280
280
  q.group(3) do
281
281
  q.text ': '
282
- q.pp v2
282
+ q.pp v2
283
283
  end
284
284
  end
285
285
  end
286
286
  else
287
- q.pp v
287
+ q.pp v
288
288
  end
289
289
  end
290
290
  end
291
291
  end
292
292
 
293
293
  # @return [String] inspects the object
294
- def inspect
294
+ def inspect
295
295
  typeinfo = type && type != :list ? ':' + type.to_s + ', ' : ''
296
296
  's(' + typeinfo + map(&:inspect).join(", ") + ')'
297
297
  end
298
298
 
299
299
  # @endgroup
300
-
300
+
301
301
  private
302
302
 
303
303
  # Resets line information
304
- # @return [void]
304
+ # @return [void]
305
305
  def reset_line_info
306
306
  if size == 0
307
307
  self.line_range = @fallback_line
@@ -319,27 +319,27 @@ module YARD
319
319
  end
320
320
  end
321
321
  end
322
-
322
+
323
323
  class ReferenceNode < AstNode
324
324
  def ref?; true end
325
-
325
+
326
326
  def path
327
327
  Array.new flatten
328
328
  end
329
-
329
+
330
330
  def namespace
331
331
  Array.new flatten[0...-1]
332
332
  end
333
333
  end
334
-
334
+
335
335
  class LiteralNode < AstNode
336
336
  def literal?; true end
337
337
  end
338
-
338
+
339
339
  class KeywordNode < AstNode
340
340
  def kw?; true end
341
341
  end
342
-
342
+
343
343
  class ParameterNode < AstNode
344
344
  def required_params; self[0] end
345
345
  def required_end_params; self[3] end
@@ -347,7 +347,7 @@ module YARD
347
347
  def splat_param; self[2] ? self[2][0] : nil end
348
348
  def block_param; self[4] ? self[4][0] : nil end
349
349
  end
350
-
350
+
351
351
  class MethodCallNode < AstNode
352
352
  def call?; true end
353
353
  def namespace; first if index_adjust > 0 end
@@ -359,37 +359,38 @@ module YARD
359
359
 
360
360
  def parameters(include_block_param = true)
361
361
  params = self[1 + index_adjust]
362
- return nil unless params
362
+ return [] unless params
363
363
  params = call_has_paren? ? params.first : params
364
+ return [] unless params
364
365
  include_block_param ? params : params[0...-1]
365
366
  end
366
-
367
+
367
368
  def block_param; parameters.last end
368
-
369
+
369
370
  private
370
-
371
+
371
372
  def index_adjust
372
373
  [:call, :command_call].include?(type) ? 2 : 0
373
374
  end
374
-
375
- def call_has_paren?
375
+
376
+ def call_has_paren?
376
377
  [:fcall, :call].include?(type)
377
378
  end
378
379
  end
379
-
380
+
380
381
  class ConditionalNode < KeywordNode
381
382
  def condition?; true end
382
383
  def condition; first end
383
384
  def then_block; self[1] end
384
-
385
+
385
386
  def else_block
386
387
  if self[2] && !cmod?
387
388
  self[2].type == :elsif ? self[2] : self[2][0]
388
389
  end
389
390
  end
390
-
391
+
391
392
  private
392
-
393
+
393
394
  def cmod?; type =~ /_mod$/ end
394
395
  end
395
396
  end
@@ -12,20 +12,20 @@ module YARD
12
12
  EXPR_FNAME = :EXPR_FNAME
13
13
  EXPR_DOT = :EXPR_DOT
14
14
  EXPR_CLASS = :EXPR_CLASS
15
-
15
+
16
16
  # Represents a token in the Ruby lexer
17
17
  class Token
18
18
  # @return [Integer] the line number in the file/stream the token is
19
19
  # located.
20
20
  attr_reader :line_no
21
-
21
+
22
22
  # @return [Integer] the character number in the file/stream the token
23
23
  # is located.
24
24
  attr_reader :char_no
25
-
25
+
26
26
  # @return [String] the token text value
27
27
  attr_reader :text
28
-
28
+
29
29
  # @return [Symbol] the lexical state at the token
30
30
  attr_accessor :lex_state
31
31
 
@@ -42,7 +42,7 @@ module YARD
42
42
  end
43
43
 
44
44
  # Chainable way to sets the text attribute
45
- #
45
+ #
46
46
  # @param [String] text the new text
47
47
  # @return [Token] this token object
48
48
  def set_text(text)
@@ -50,12 +50,12 @@ module YARD
50
50
  self
51
51
  end
52
52
  end
53
-
53
+
54
54
  # Represents a block
55
55
  class TkBlockContents < Token
56
56
  def text; '...' end
57
57
  end
58
-
58
+
59
59
  # Represents an end statement
60
60
  class TkStatementEnd < Token
61
61
  def text; '' end
@@ -64,7 +64,7 @@ module YARD
64
64
  class TkNode < Token
65
65
  attr :node
66
66
  end
67
-
67
+
68
68
  # Represents whitespace
69
69
  class TkWhitespace < Token
70
70
  end
@@ -131,8 +131,8 @@ module YARD
131
131
  if (tk = source[token]).nil?
132
132
  IRB.fail TkReading2TokenNoKey, token
133
133
  end
134
- tk = Token(tk[0], value)
135
- else
134
+ tk = Token(tk[0], value)
135
+ else
136
136
  if token
137
137
  tk = if (token.ancestors & [TkId, TkVal, TkOPASGN, TkUnknownChar]).empty?
138
138
  token.new(@prev_line_no, @prev_char_no)
@@ -236,14 +236,14 @@ module YARD
236
236
  [:TkASSOC, TkOp, "=>"],
237
237
  [:TkQUESTION, TkOp, "?"], #?
238
238
  [:TkCOLON, TkOp, ":"], #:
239
-
239
+
240
240
  # [:TkfLPAREN], # func( #
241
241
  # [:TkfLBRACK], # func[ #
242
242
  # [:TkfLBRACE], # func{ #
243
243
  [:TkSTAR], # *arg
244
244
  [:TkAMPER], # &arg #
245
245
  # [:TkSYMBOL, TkId], # :SYMBOL
246
- [:TkSYMBEG, TkId],
246
+ [:TkSYMBEG, TkId],
247
247
  [:TkGT, TkOp, ">"],
248
248
  [:TkLT, TkOp, "<"],
249
249
  [:TkPLUS, TkOp, "+"],
@@ -295,7 +295,7 @@ module YARD
295
295
  token_c = Class.new super_token
296
296
  RubyToken.const_set token_n, token_c
297
297
  # token_c.inspect
298
-
298
+
299
299
  if reading
300
300
  if TkReading2Token[reading]
301
301
  IRB.fail TkReading2TokenDuplicateError, token_n, reading
@@ -358,9 +358,9 @@ module YARD
358
358
  #
359
359
  # @private
360
360
  class BufferedReader
361
-
361
+
362
362
  attr_reader :line_num
363
-
363
+
364
364
  def initialize(content)
365
365
  if /\t/ =~ content
366
366
  tab_width = 2
@@ -379,34 +379,34 @@ module YARD
379
379
  @last_newline = 0
380
380
  @newline_pending = false
381
381
  end
382
-
382
+
383
383
  def column
384
384
  @offset - @last_newline
385
385
  end
386
-
386
+
387
387
  def getc
388
388
  return nil if @offset >= @size
389
389
  ch = @content[@offset, 1]
390
-
390
+
391
391
  @offset += 1
392
392
  @hwm = @offset if @hwm < @offset
393
-
393
+
394
394
  if @newline_pending
395
395
  @line_num += 1
396
396
  @last_newline = @offset - 1
397
397
  @newline_pending = false
398
398
  end
399
-
399
+
400
400
  if ch == "\n"
401
401
  @newline_pending = true
402
402
  end
403
403
  ch
404
404
  end
405
-
405
+
406
406
  def getc_already_read
407
407
  getc
408
408
  end
409
-
409
+
410
410
  def ungetc(ch)
411
411
  raise "unget past beginning of file" if @offset <= 0
412
412
  @offset -= 1
@@ -414,13 +414,13 @@ module YARD
414
414
  @newline_pending = false
415
415
  end
416
416
  end
417
-
417
+
418
418
  def get_read
419
419
  res = @content[@read_back_offset...@offset]
420
420
  @read_back_offset = @offset
421
421
  res
422
422
  end
423
-
423
+
424
424
  def peek(at)
425
425
  pos = @offset + at
426
426
  if pos >= @size
@@ -429,11 +429,11 @@ module YARD
429
429
  @content[pos, 1]
430
430
  end
431
431
  end
432
-
432
+
433
433
  def peek_equal(str)
434
434
  @content[@offset, str.length] == str
435
435
  end
436
-
436
+
437
437
  def divert_read_from(reserve)
438
438
  @content[@offset, 0] = reserve
439
439
  @size = @content.size
@@ -446,10 +446,10 @@ module YARD
446
446
  def_exception(:AlreadyDefinedToken, "Already defined token(%s)")
447
447
  def_exception(:TkReading2TokenNoKey, "key nothing(key='%s')")
448
448
  def_exception(:TkSymbol2TokenNoKey, "key nothing(key='%s')")
449
- def_exception(:TkReading2TokenDuplicateError,
449
+ def_exception(:TkReading2TokenDuplicateError,
450
450
  "key duplicate(token_n='%s', key='%s')")
451
451
  def_exception(:SyntaxError, "%s")
452
-
452
+
453
453
  include RubyToken
454
454
  include IRB
455
455
 
@@ -473,7 +473,7 @@ module YARD
473
473
  @quoted = nil
474
474
  @lex_state = EXPR_BEG
475
475
  @space_seen = false
476
-
476
+
477
477
  @continue = false
478
478
  @line = ""
479
479
 
@@ -569,7 +569,7 @@ module YARD
569
569
  tk
570
570
  end
571
571
  end
572
-
572
+
573
573
  ENINDENT_CLAUSE = [
574
574
  "case", "class", "def", "do", "for", "if",
575
575
  "module", "unless", "until", "while", "begin" #, "when"
@@ -586,7 +586,7 @@ module YARD
586
586
  "w" => "]",
587
587
  "W" => "]"
588
588
  }
589
-
589
+
590
590
  PERCENT_PAREN = {
591
591
  "{" => "}",
592
592
  "[" => "]",
@@ -670,10 +670,10 @@ module YARD
670
670
  Token(TkNL).set_text("\n")
671
671
  end
672
672
 
673
- @OP.def_rules("*", "**",
673
+ @OP.def_rules("*", "**",
674
674
  "!", "!=", "!~",
675
- "=", "==", "===",
676
- "=~", "<=>",
675
+ "=", "==", "===",
676
+ "=~", "<=>",
677
677
  "<", "<=",
678
678
  ">", ">=", ">>") do |op, io|
679
679
  @lex_state = EXPR_BEG
@@ -682,7 +682,7 @@ module YARD
682
682
 
683
683
  @OP.def_rules("<<") do |op, io|
684
684
  tk = nil
685
- if @lex_state != EXPR_END && @lex_state != EXPR_CLASS &&
685
+ if @lex_state != EXPR_END && @lex_state != EXPR_CLASS &&
686
686
  (@lex_state != EXPR_ARG || @space_seen)
687
687
  c = peek(0)
688
688
  tk = identify_here_document if /[-\w_\"\'\`]/ =~ c
@@ -732,8 +732,8 @@ module YARD
732
732
  @lex_state = EXPR_BEG
733
733
  Token(op).set_text(op)
734
734
  end
735
-
736
- @OP.def_rules("+=", "-=", "*=", "**=",
735
+
736
+ @OP.def_rules("+=", "-=", "*=", "**=",
737
737
  "&=", "|=", "^=", "<<=", ">>=", "||=", "&&=") do |op, io|
738
738
  @lex_state = EXPR_BEG
739
739
  op =~ /^(.*)=$/
@@ -784,7 +784,7 @@ module YARD
784
784
 
785
785
  lex_int2
786
786
  end
787
-
787
+
788
788
  def lex_int2
789
789
  @OP.def_rules("]", "}", ")") do
790
790
  |op, io|
@@ -793,7 +793,7 @@ module YARD
793
793
  Token(op).set_text(op)
794
794
  end
795
795
 
796
- @OP.def_rule(":") do
796
+ @OP.def_rule(":") do
797
797
  if (@colonblock_seen && @lex_state != EXPR_BEG) || peek(0) =~ /\s/
798
798
  @lex_state = EXPR_BEG
799
799
  tk = Token(TkCOLON)
@@ -825,7 +825,7 @@ module YARD
825
825
  Token(TkOPASGN, :/).set_text("/=") #")
826
826
  elsif @lex_state == EXPR_ARG and @space_seen and peek(0) !~ /\s/
827
827
  identify_string(op)
828
- else
828
+ else
829
829
  @lex_state = EXPR_BEG
830
830
  Token("/").set_text(op)
831
831
  end
@@ -840,7 +840,7 @@ module YARD
840
840
  # @lex_state = EXPR_BEG
841
841
  # Token(TkOPASGN, :^)
842
842
  # end
843
-
843
+
844
844
  @OP.def_rules(",", ";") do |op, io|
845
845
  @colonblock_seen = false
846
846
  @lex_state = EXPR_BEG
@@ -856,7 +856,7 @@ module YARD
856
856
  @lex_state = EXPR_BEG
857
857
  Token("~").set_text("~@")
858
858
  end
859
-
859
+
860
860
  @OP.def_rule("(") do
861
861
  @indent += 1
862
862
  # if @lex_state == EXPR_BEG || @lex_state == EXPR_MID
@@ -907,15 +907,15 @@ module YARD
907
907
  end
908
908
 
909
909
  @OP.def_rule('\\') do #'
910
- if getc == "\n"
910
+ if getc == "\n"
911
911
  @space_seen = true
912
912
  @continue = true
913
913
  Token(TkSPACE).set_text("\\\n")
914
- else
914
+ else
915
915
  ungetc
916
916
  Token("\\").set_text("\\") #"
917
- end
918
- end
917
+ end
918
+ end
919
919
 
920
920
  @OP.def_rule('%') do
921
921
  |op, io|
@@ -945,7 +945,7 @@ module YARD
945
945
  end
946
946
  end
947
947
 
948
- # @OP.def_rule("def", proc{|op, io| /\s/ =~ io.peek(0)}) do
948
+ # @OP.def_rule("def", proc{|op, io| /\s/ =~ io.peek(0)}) do
949
949
  # |op, io|
950
950
  # @indent += 1
951
951
  # @lex_state = EXPR_FNAME
@@ -969,10 +969,10 @@ module YARD
969
969
  printf "MATCH: end %s: %s\n", op, io.inspect if RubyLex.debug?
970
970
  t
971
971
  end
972
-
972
+
973
973
  p @OP if RubyLex.debug?
974
974
  end
975
-
975
+
976
976
  def identify_gvar
977
977
  @lex_state = EXPR_END
978
978
  str = "$"
@@ -981,15 +981,15 @@ module YARD
981
981
  when /[~_*$?!@\/\\;,=:<>".]/ #"
982
982
  str << ch
983
983
  Token(TkGVAR, str)
984
-
984
+
985
985
  when "-"
986
986
  str << "-" << getc
987
987
  Token(TkGVAR, str)
988
-
988
+
989
989
  when "&", "`", "'", "+"
990
990
  str << ch
991
991
  Token(TkBACK_REF, str)
992
-
992
+
993
993
  when /[1-9]/
994
994
  str << ch
995
995
  while (ch = getc) =~ /[0-9]/
@@ -1001,13 +1001,13 @@ module YARD
1001
1001
  ungetc
1002
1002
  ungetc
1003
1003
  return identify_identifier
1004
- else
1004
+ else
1005
1005
  ungetc
1006
- Token("$")
1006
+ Token("$")
1007
1007
  end
1008
1008
  tk.set_text(str)
1009
1009
  end
1010
-
1010
+
1011
1011
  def identify_identifier
1012
1012
  token = ""
1013
1013
  token.concat getc if peek(0) =~ /[$@]/
@@ -1018,7 +1018,7 @@ module YARD
1018
1018
  token.concat ch
1019
1019
  end
1020
1020
  ungetc
1021
-
1021
+
1022
1022
  if ch == "!" or ch == "?"
1023
1023
  token.concat getc
1024
1024
  end
@@ -1033,7 +1033,7 @@ module YARD
1033
1033
  @lex_state = EXPR_END
1034
1034
  return Token(TkIVAR, token).set_text(token)
1035
1035
  end
1036
-
1036
+
1037
1037
  if @lex_state != EXPR_DOT
1038
1038
  print token, "\n" if RubyLex.debug?
1039
1039
 
@@ -1051,8 +1051,8 @@ module YARD
1051
1051
  if @lex_state != EXPR_FNAME
1052
1052
  if ENINDENT_CLAUSE.include?(token)
1053
1053
  @indent += 1
1054
-
1055
- if ACCEPTS_COLON.include?(token)
1054
+
1055
+ if ACCEPTS_COLON.include?(token)
1056
1056
  @colonblock_seen = true
1057
1057
  else
1058
1058
  @colonblock_seen = false
@@ -1138,7 +1138,7 @@ module YARD
1138
1138
  @lex_state = EXPR_END
1139
1139
  Token(Ltype2Token[lt], str).set_text(str.dump)
1140
1140
  end
1141
-
1141
+
1142
1142
  def identify_quotation(initial_char)
1143
1143
  ch = getc
1144
1144
  if lt = PERCENT_LTYPE[ch]
@@ -1219,7 +1219,7 @@ module YARD
1219
1219
  end
1220
1220
  Token(type).set_text(str)
1221
1221
  end
1222
-
1222
+
1223
1223
  def identify_string(ltype, quoted = ltype, opener=nil, initial_char = nil)
1224
1224
  @ltype = ltype
1225
1225
  @quoted = quoted
@@ -1231,9 +1231,9 @@ module YARD
1231
1231
 
1232
1232
  nest = 0
1233
1233
  begin
1234
- while ch = getc
1234
+ while ch = getc
1235
1235
  str << ch
1236
- if @quoted == ch
1236
+ if @quoted == ch
1237
1237
  if nest == 0
1238
1238
  break
1239
1239
  else
@@ -1294,7 +1294,7 @@ module YARD
1294
1294
  if ch == "\n"
1295
1295
  ch = " "
1296
1296
  else
1297
- comment << "\\"
1297
+ comment << "\\"
1298
1298
  end
1299
1299
  else
1300
1300
  if ch == "\n"
@@ -1307,7 +1307,7 @@ module YARD
1307
1307
  end
1308
1308
  return Token(TkCOMMENT).set_text(comment)
1309
1309
  end
1310
-
1310
+
1311
1311
  def read_escape
1312
1312
  res = ""
1313
1313
  case ch = getc
@@ -1324,7 +1324,7 @@ module YARD
1324
1324
  end
1325
1325
  res << ch
1326
1326
  end
1327
-
1327
+
1328
1328
  when "x"
1329
1329
  res << ch
1330
1330
  2.times do