yard 0.5.8 → 0.6.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 (211) hide show
  1. data/.yardopts +2 -0
  2. data/ChangeLog +1064 -0
  3. data/README.md +103 -42
  4. data/Rakefile +3 -2
  5. data/benchmarks/parsing.rb +2 -1
  6. data/bin/yard +4 -0
  7. data/bin/yard-graph +1 -1
  8. data/bin/yard-server +4 -0
  9. data/docs/GettingStarted.md +8 -8
  10. data/docs/Handlers.md +5 -5
  11. data/docs/Overview.md +5 -5
  12. data/docs/Parser.md +1 -1
  13. data/docs/Tags.md +1 -1
  14. data/docs/Templates.md +27 -6
  15. data/docs/WhatsNew.md +222 -2
  16. data/lib/rubygems_plugin.rb +1 -0
  17. data/lib/yard.rb +7 -1
  18. data/lib/yard/autoload.rb +46 -6
  19. data/lib/yard/cli/{base.rb → command.rb} +20 -6
  20. data/lib/yard/cli/command_parser.rb +87 -0
  21. data/lib/yard/cli/diff.rb +176 -0
  22. data/lib/yard/cli/gems.rb +74 -0
  23. data/lib/yard/cli/{yard_graph.rb → graph.rb} +9 -8
  24. data/lib/yard/cli/help.rb +18 -0
  25. data/lib/yard/cli/server.rb +137 -0
  26. data/lib/yard/cli/stats.rb +210 -0
  27. data/lib/yard/cli/yardoc.rb +315 -116
  28. data/lib/yard/cli/yri.rb +45 -4
  29. data/lib/yard/code_objects/base.rb +73 -30
  30. data/lib/yard/code_objects/class_object.rb +9 -1
  31. data/lib/yard/code_objects/method_object.rb +11 -0
  32. data/lib/yard/code_objects/namespace_object.rb +8 -2
  33. data/lib/yard/code_objects/proxy.rb +2 -2
  34. data/lib/yard/core_ext/array.rb +3 -49
  35. data/lib/yard/core_ext/file.rb +7 -0
  36. data/lib/yard/core_ext/insertion.rb +60 -0
  37. data/lib/yard/docstring.rb +34 -7
  38. data/lib/yard/globals.rb +2 -2
  39. data/lib/yard/handlers/base.rb +101 -20
  40. data/lib/yard/handlers/processor.rb +23 -7
  41. data/lib/yard/handlers/ruby/alias_handler.rb +1 -0
  42. data/lib/yard/handlers/ruby/attribute_handler.rb +8 -0
  43. data/lib/yard/handlers/ruby/base.rb +71 -2
  44. data/lib/yard/handlers/ruby/class_condition_handler.rb +10 -0
  45. data/lib/yard/handlers/ruby/class_handler.rb +7 -4
  46. data/lib/yard/handlers/ruby/class_variable_handler.rb +1 -0
  47. data/lib/yard/handlers/ruby/constant_handler.rb +1 -0
  48. data/lib/yard/handlers/ruby/exception_handler.rb +1 -0
  49. data/lib/yard/handlers/ruby/extend_handler.rb +2 -3
  50. data/lib/yard/handlers/ruby/legacy/alias_handler.rb +1 -0
  51. data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +2 -0
  52. data/lib/yard/handlers/ruby/legacy/base.rb +15 -2
  53. data/lib/yard/handlers/ruby/legacy/class_condition_handler.rb +5 -0
  54. data/lib/yard/handlers/ruby/legacy/class_handler.rb +7 -4
  55. data/lib/yard/handlers/ruby/legacy/class_variable_handler.rb +1 -0
  56. data/lib/yard/handlers/ruby/legacy/constant_handler.rb +1 -0
  57. data/lib/yard/handlers/ruby/legacy/exception_handler.rb +1 -0
  58. data/lib/yard/handlers/ruby/legacy/extend_handler.rb +1 -3
  59. data/lib/yard/handlers/ruby/legacy/method_handler.rb +7 -3
  60. data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +2 -1
  61. data/lib/yard/handlers/ruby/legacy/module_handler.rb +1 -0
  62. data/lib/yard/handlers/ruby/legacy/process_handler.rb +1 -0
  63. data/lib/yard/handlers/ruby/legacy/visibility_handler.rb +1 -0
  64. data/lib/yard/handlers/ruby/legacy/yield_handler.rb +1 -0
  65. data/lib/yard/handlers/ruby/method_condition_handler.rb +1 -0
  66. data/lib/yard/handlers/ruby/method_handler.rb +5 -1
  67. data/lib/yard/handlers/ruby/mixin_handler.rb +2 -1
  68. data/lib/yard/handlers/ruby/module_handler.rb +1 -0
  69. data/lib/yard/handlers/ruby/process_handler.rb +7 -1
  70. data/lib/yard/handlers/ruby/struct_handler_methods.rb +3 -0
  71. data/lib/yard/handlers/ruby/visibility_handler.rb +8 -2
  72. data/lib/yard/handlers/ruby/yield_handler.rb +1 -0
  73. data/lib/yard/logging.rb +7 -1
  74. data/lib/yard/parser/base.rb +1 -0
  75. data/lib/yard/parser/c_parser.rb +2 -0
  76. data/lib/yard/parser/ruby/ast_node.rb +82 -63
  77. data/lib/yard/parser/ruby/legacy/ruby_lex.rb +36 -10
  78. data/lib/yard/parser/ruby/legacy/ruby_parser.rb +1 -0
  79. data/lib/yard/parser/ruby/legacy/statement.rb +9 -5
  80. data/lib/yard/parser/ruby/legacy/statement_list.rb +20 -11
  81. data/lib/yard/parser/ruby/ruby_parser.rb +18 -1
  82. data/lib/yard/parser/source_parser.rb +6 -1
  83. data/lib/yard/registry.rb +284 -278
  84. data/lib/yard/registry_store.rb +4 -2
  85. data/lib/yard/serializers/base.rb +30 -13
  86. data/lib/yard/serializers/file_system_serializer.rb +10 -1
  87. data/lib/yard/server/adapter.rb +51 -0
  88. data/lib/yard/server/commands/base.rb +98 -0
  89. data/lib/yard/server/commands/display_file_command.rb +20 -0
  90. data/lib/yard/server/commands/display_object_command.rb +50 -0
  91. data/lib/yard/server/commands/frames_command.rb +31 -0
  92. data/lib/yard/server/commands/library_command.rb +83 -0
  93. data/lib/yard/server/commands/library_index_command.rb +23 -0
  94. data/lib/yard/server/commands/list_command.rb +44 -0
  95. data/lib/yard/server/commands/search_command.rb +67 -0
  96. data/lib/yard/server/commands/static_file_command.rb +45 -0
  97. data/lib/yard/server/doc_server_helper.rb +22 -0
  98. data/lib/yard/server/doc_server_serializer.rb +29 -0
  99. data/lib/yard/server/library_version.rb +86 -0
  100. data/lib/yard/server/rack_adapter.rb +38 -0
  101. data/lib/yard/server/router.rb +110 -0
  102. data/lib/yard/server/static_caching.rb +16 -0
  103. data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +78 -0
  104. data/lib/yard/server/templates/default/fulldoc/html/images/processing.gif +0 -0
  105. data/lib/yard/server/templates/default/fulldoc/html/js/autocomplete.js +12 -0
  106. data/lib/yard/server/templates/default/fulldoc/html/js/live.js +32 -0
  107. data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +46 -0
  108. data/lib/yard/server/templates/default/layout/html/headers.erb +11 -0
  109. data/lib/yard/server/templates/doc_server/frames/html/frames.erb +13 -0
  110. data/lib/yard/server/templates/doc_server/frames/html/setup.rb +3 -0
  111. data/lib/yard/server/templates/doc_server/full_list/html/full_list.erb +34 -0
  112. data/lib/yard/server/templates/doc_server/full_list/html/setup.rb +10 -0
  113. data/lib/yard/server/templates/doc_server/library_list/html/contents.erb +13 -0
  114. data/lib/yard/server/templates/doc_server/library_list/html/headers.erb +26 -0
  115. data/lib/yard/server/templates/doc_server/library_list/html/library_list.erb +12 -0
  116. data/lib/yard/server/templates/doc_server/library_list/html/setup.rb +3 -0
  117. data/lib/yard/server/templates/doc_server/library_list/html/title.erb +2 -0
  118. data/lib/yard/server/templates/doc_server/processing/html/processing.erb +51 -0
  119. data/lib/yard/server/templates/doc_server/processing/html/setup.rb +3 -0
  120. data/lib/yard/server/templates/doc_server/search/html/search.erb +19 -0
  121. data/lib/yard/server/templates/doc_server/search/html/setup.rb +8 -0
  122. data/lib/yard/server/webrick_adapter.rb +38 -0
  123. data/lib/yard/tags/default_factory.rb +0 -5
  124. data/lib/yard/tags/library.rb +61 -22
  125. data/lib/yard/tags/tag.rb +26 -4
  126. data/lib/yard/templates/engine.rb +12 -1
  127. data/lib/yard/templates/erb_cache.rb +2 -1
  128. data/lib/yard/templates/helpers/base_helper.rb +96 -3
  129. data/lib/yard/templates/helpers/filter_helper.rb +5 -0
  130. data/lib/yard/templates/helpers/html_helper.rb +204 -94
  131. data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +4 -0
  132. data/lib/yard/templates/helpers/markup_helper.rb +58 -3
  133. data/lib/yard/templates/helpers/method_helper.rb +7 -0
  134. data/lib/yard/templates/helpers/module_helper.rb +5 -0
  135. data/lib/yard/templates/helpers/text_helper.rb +10 -1
  136. data/lib/yard/templates/helpers/uml_helper.rb +13 -0
  137. data/lib/yard/templates/section.rb +106 -0
  138. data/lib/yard/templates/template.rb +20 -19
  139. data/lib/yard/verifier.rb +21 -2
  140. data/spec/cli/command_parser_spec.rb +43 -0
  141. data/spec/cli/diff_spec.rb +170 -0
  142. data/spec/cli/help_spec.rb +22 -0
  143. data/spec/cli/server_spec.rb +140 -0
  144. data/spec/cli/stats_spec.rb +75 -0
  145. data/spec/cli/yardoc_spec.rb +438 -182
  146. data/spec/cli/yri_spec.rb +13 -1
  147. data/spec/code_objects/base_spec.rb +51 -6
  148. data/spec/code_objects/class_object_spec.rb +15 -1
  149. data/spec/code_objects/method_object_spec.rb +29 -0
  150. data/spec/code_objects/namespace_object_spec.rb +150 -129
  151. data/spec/core_ext/array_spec.rb +4 -23
  152. data/spec/core_ext/insertion_spec.rb +37 -0
  153. data/spec/docstring_spec.rb +63 -0
  154. data/spec/handlers/attribute_handler_spec.rb +4 -0
  155. data/spec/handlers/base_spec.rb +98 -26
  156. data/spec/handlers/class_handler_spec.rb +5 -1
  157. data/spec/handlers/examples/attribute_handler_001.rb.txt +5 -0
  158. data/spec/handlers/examples/class_handler_001.rb.txt +4 -0
  159. data/spec/handlers/examples/module_handler_001.rb.txt +6 -1
  160. data/spec/handlers/examples/visibility_handler_001.rb.txt +4 -0
  161. data/spec/handlers/method_handler_spec.rb +5 -0
  162. data/spec/handlers/module_handler_spec.rb +4 -0
  163. data/spec/handlers/visibility_handler_spec.rb +6 -0
  164. data/spec/parser/source_parser_spec.rb +24 -0
  165. data/spec/registry_spec.rb +44 -8
  166. data/spec/server/adapter_spec.rb +38 -0
  167. data/spec/server/commands/base_spec.rb +87 -0
  168. data/spec/server/commands/static_file_command_spec.rb +67 -0
  169. data/spec/server/doc_server_serializer_spec.rb +58 -0
  170. data/spec/server/router_spec.rb +115 -0
  171. data/spec/server/spec_helper.rb +17 -0
  172. data/spec/server/static_caching_spec.rb +39 -0
  173. data/spec/server/webrick_servlet_spec.rb +20 -0
  174. data/spec/templates/constant_spec.rb +40 -0
  175. data/spec/templates/engine_spec.rb +9 -5
  176. data/spec/templates/examples/class002.html +1 -3
  177. data/spec/templates/examples/constant001.txt +25 -0
  178. data/spec/templates/examples/constant002.txt +7 -0
  179. data/spec/templates/examples/constant003.txt +11 -0
  180. data/spec/templates/examples/module001.txt +1 -1
  181. data/spec/templates/examples/module002.html +319 -0
  182. data/spec/templates/helpers/base_helper_spec.rb +2 -2
  183. data/spec/templates/helpers/html_helper_spec.rb +93 -3
  184. data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +5 -0
  185. data/spec/templates/helpers/markup_helper_spec.rb +94 -67
  186. data/spec/templates/helpers/shared_signature_examples.rb +9 -0
  187. data/spec/templates/helpers/text_helper_spec.rb +12 -0
  188. data/spec/templates/module_spec.rb +21 -4
  189. data/spec/templates/section_spec.rb +146 -0
  190. data/spec/templates/template_spec.rb +9 -20
  191. data/templates/default/class/setup.rb +5 -5
  192. data/templates/default/constant/text/header.erb +11 -0
  193. data/templates/default/constant/text/setup.rb +3 -0
  194. data/templates/default/fulldoc/html/css/style.css +29 -3
  195. data/templates/default/fulldoc/html/js/app.js +67 -1
  196. data/templates/default/fulldoc/html/js/full_list.js +3 -8
  197. data/templates/default/fulldoc/html/js/jquery.js +150 -15
  198. data/templates/default/fulldoc/html/setup.rb +9 -0
  199. data/templates/default/layout/html/footer.erb +1 -1
  200. data/templates/default/layout/html/setup.rb +7 -25
  201. data/templates/default/method_details/html/source.erb +1 -1
  202. data/templates/default/module/html/attribute_summary.erb +2 -2
  203. data/templates/default/module/html/method_summary.erb +2 -2
  204. data/templates/default/module/setup.rb +27 -4
  205. data/templates/default/onefile/html/files.erb +5 -0
  206. data/templates/default/onefile/html/layout.erb +22 -0
  207. data/templates/default/onefile/html/readme.erb +3 -0
  208. data/templates/default/onefile/html/setup.rb +40 -0
  209. data/templates/default/root/html/setup.rb +1 -0
  210. data/templates/default/tags/setup.rb +26 -33
  211. metadata +80 -10
@@ -1,3 +1,4 @@
1
+ # (see Ruby::ModuleHandler)
1
2
  class YARD::Handlers::Ruby::Legacy::ModuleHandler < YARD::Handlers::Ruby::Legacy::Base
2
3
  handles TkMODULE
3
4
 
@@ -1,3 +1,4 @@
1
+ # (see Ruby::ProcessHandler)
1
2
  class YARD::Handlers::Ruby::Legacy::ProcessHandler < YARD::Handlers::Ruby::Legacy::Base
2
3
  handles /\Aprocess(?:\(?|\s)/
3
4
  namespace_only
@@ -1,3 +1,4 @@
1
+ # (see Ruby::VisibilityHandler)
1
2
  class YARD::Handlers::Ruby::Legacy::VisibilityHandler < YARD::Handlers::Ruby::Legacy::Base
2
3
  handles /\A(protected|private|public)(\s|\(|$)/
3
4
 
@@ -1,3 +1,4 @@
1
+ # (see Ruby::YieldHandler)
1
2
  class YARD::Handlers::Ruby::Legacy::YieldHandler < YARD::Handlers::Ruby::Legacy::Base
2
3
  handles TkYIELD
3
4
 
@@ -1,3 +1,4 @@
1
+ # Handles a conditional inside a method
1
2
  class YARD::Handlers::Ruby::MethodConditionHandler < YARD::Handlers::Ruby::Base
2
3
  handles :if_mod, :unless_mod
3
4
 
@@ -1,3 +1,4 @@
1
+ # Handles a method definition
1
2
  class YARD::Handlers::Ruby::MethodHandler < YARD::Handlers::Ruby::Base
2
3
  handles :def, :defs
3
4
 
@@ -5,8 +6,11 @@ class YARD::Handlers::Ruby::MethodHandler < YARD::Handlers::Ruby::Base
5
6
  nobj = namespace
6
7
  mscope = scope
7
8
  if statement.type == :defs
9
+ if statement[0][0].type == :ident
10
+ raise YARD::Parser::UndocumentableError, 'method defined on object instance'
11
+ end
8
12
  meth = statement[2][0]
9
- nobj = P(namespace, statement[0].source) unless statement[0].source == "self"
13
+ nobj = P(namespace, statement[0].source) if statement[0][0].type == :const
10
14
  args = format_args(statement[3])
11
15
  blk = statement[4]
12
16
  mscope = :class
@@ -1,3 +1,4 @@
1
+ # Handles the 'include' statement to mixin a module in the instance scope
1
2
  class YARD::Handlers::Ruby::MixinHandler < YARD::Handlers::Ruby::Base
2
3
  namespace_only
3
4
  handles method_call(:include)
@@ -20,6 +21,6 @@ class YARD::Handlers::Ruby::MixinHandler < YARD::Handlers::Ruby::Base
20
21
  obj = Proxy.new(namespace, obj.value)
21
22
  end
22
23
 
23
- namespace.mixins(scope) << obj
24
+ namespace.mixins(scope).unshift(obj) unless namespace.mixins(scope).include?(obj)
24
25
  end
25
26
  end
@@ -1,3 +1,4 @@
1
+ # Handles the declaration of a module
1
2
  class YARD::Handlers::Ruby::ModuleHandler < YARD::Handlers::Ruby::Base
2
3
  handles :module
3
4
 
@@ -1,10 +1,16 @@
1
+ # This is a YARD-specific handler for handler DSL syntax. It handles the
2
+ # "process do ... end" syntax and translates it into a "def process; end"
3
+ # method declaration.
4
+ #
5
+ # @since 0.5.4
1
6
  class YARD::Handlers::Ruby::ProcessHandler < YARD::Handlers::Ruby::Base
2
7
  handles method_call(:process)
3
8
  namespace_only
4
9
 
5
10
  process do
6
11
  return unless namespace.is_a?(ClassObject) && namespace.superclass.to_s =~ /^YARD::Handlers/
7
- register MethodObject.new(namespace, :process) do |o|
12
+ register MethodObject.new(namespace, :process) do |o|
13
+ o.docstring = "Main processing callback"
8
14
  o.signature = "def process"
9
15
  o.parameters = []
10
16
  end
@@ -1,3 +1,6 @@
1
+ # Helper methods to parse @attr_* tags on a Struct class.
2
+ #
3
+ # @since 0.5.6
1
4
  module YARD::Handlers::Ruby::StructHandlerMethods
2
5
  include YARD::CodeObjects
3
6
 
@@ -1,7 +1,9 @@
1
+ # Handles 'private', 'protected', and 'public' calls.
1
2
  class YARD::Handlers::Ruby::VisibilityHandler < YARD::Handlers::Ruby::Base
2
3
  handles method_call(:private)
3
4
  handles method_call(:protected)
4
5
  handles method_call(:public)
6
+ namespace_only
5
7
 
6
8
  process do
7
9
  return if (ident = statement.jump(:ident)) == statement
@@ -10,8 +12,12 @@ class YARD::Handlers::Ruby::VisibilityHandler < YARD::Handlers::Ruby::Base
10
12
  self.visibility = ident.first
11
13
  when :fcall, :command
12
14
  statement[1].traverse do |node|
13
- next unless node.type == :ident || node.type == :string_content
14
- MethodObject.new(namespace, node.source, scope) {|o| o.visibility = ident.first }
15
+ case node.type
16
+ when :symbol; source = node.jump(:ident).last
17
+ when :string_content; source = node.source
18
+ else next
19
+ end
20
+ MethodObject.new(namespace, source, scope) {|o| o.visibility = ident.first }
15
21
  end
16
22
  end
17
23
  end
@@ -1,3 +1,4 @@
1
+ # Handles 'yield' calls
1
2
  class YARD::Handlers::Ruby::YieldHandler < YARD::Handlers::Ruby::Base
2
3
  handles :yield, :yield0
3
4
 
data/lib/yard/logging.rb CHANGED
@@ -27,6 +27,10 @@ module YARD
27
27
  super
28
28
  end
29
29
 
30
+ # Prints the backtrace +exc+ to the logger as error data.
31
+ #
32
+ # @param [Array<String>] exc the backtrace list
33
+ # @return [void]
30
34
  def backtrace(exc)
31
35
  return unless show_backtraces
32
36
  error "#{exc.class.class_name}: #{exc.message}"
@@ -49,7 +53,9 @@ module YARD
49
53
  self.level = old_level
50
54
  end
51
55
 
52
- # Log format (from Logger implementation)
56
+ private
57
+
58
+ # Log format (from Logger implementation). Used by Logger internally
53
59
  def format_log(sev, time, prog, msg)
54
60
  "[#{sev.downcase}]: #{msg}\n"
55
61
  end
@@ -11,6 +11,7 @@ module YARD
11
11
  # @see #parse
12
12
  # @see #tokenize
13
13
  # @see #enumerator
14
+ # @since 0.5.6
14
15
  class Base
15
16
  # Convenience method to create a new parser and {#parse}
16
17
  def self.parse(source, filename = nil)
@@ -18,12 +18,14 @@ module YARD
18
18
  parse_includes
19
19
  end
20
20
 
21
+ # @since 0.5.6
21
22
  def tokenize
22
23
  raise NotImplementedError, "no tokenization support for C/C++ files"
23
24
  end
24
25
 
25
26
  private
26
27
 
28
+ # @since 0.5.3
27
29
  def remove_var_prefix(var)
28
30
  var.gsub(/^rb_[mc]|^[a-z_]+/, '')
29
31
  end
@@ -38,12 +38,51 @@ module YARD
38
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
- attr_accessor :type, :parent, :docstring, :docstring_range, :source
41
+ attr_accessor :docstring, :docstring_range, :source, :group
42
42
  attr_writer :source_range, :line_range, :file, :full_source
43
43
  alias comments docstring
44
44
  alias comments_range docstring_range
45
45
  alias to_s source
46
46
 
47
+ # @return [Symbol] the node's unique symbolic type
48
+ attr_accessor :type
49
+
50
+ # @return [AstNode, nil] the node's parent or nil if it is a root node.
51
+ attr_accessor :parent
52
+
53
+ # @return [Range] the character range in {#full_source} represented
54
+ # by the node
55
+ def source_range
56
+ reset_line_info unless @source_range
57
+ @source_range
58
+ end
59
+
60
+ # @return [Range] the line range in {#full_source} represented
61
+ # by the node
62
+ def line_range
63
+ reset_line_info unless @line_range
64
+ @line_range
65
+ end
66
+
67
+ # @return [String] the filename the node was parsed from
68
+ def file
69
+ return parent.file if parent
70
+ @file
71
+ end
72
+
73
+ # @return [String] the full source that the node was parsed from
74
+ def full_source
75
+ return parent.full_source if parent
76
+ return @full_source if @full_source
77
+ return IO.read(@file) if file && File.exist?(file)
78
+ end
79
+
80
+ # @return [String] the parse of {#full_source} that the node represents
81
+ def source
82
+ return parent.full_source[source_range] if parent
83
+ full_source
84
+ end
85
+
47
86
  # List of all known keywords
48
87
  # @return [Hash]
49
88
  KEYWORDS = { class: true, alias: true, lambda: true, do_block: true,
@@ -54,6 +93,8 @@ module YARD
54
93
  while: true, while_mod: true, yield: true, yield0: true, zsuper: true,
55
94
  unless: true, unless_mod: true, for: true, super: true, return0: true }
56
95
 
96
+ # @group Creating an AstNode
97
+
57
98
  # Finds the node subclass that should be instantiated for a specific
58
99
  # node type
59
100
  #
@@ -73,7 +114,7 @@ module YARD
73
114
  AstNode
74
115
  end
75
116
  end
76
-
117
+
77
118
  # Creates a new AST node
78
119
  #
79
120
  # @param [Symbol] type the type of node being created
@@ -99,44 +140,13 @@ module YARD
99
140
 
100
141
  # @return [Boolean] whether the node is equal to another by checking
101
142
  # the list and type
143
+ # @private
102
144
  def ==(ast)
103
145
  super && type == ast.type
104
146
  end
105
147
 
106
- # @return [String] the first line of source the node represents
107
- def show
108
- "\t#{line}: #{first_line}"
109
- end
110
-
111
- # @return [Range] the character range in {#full_source} represented
112
- # by the node
113
- def source_range
114
- reset_line_info unless @source_range
115
- @source_range
116
- end
117
-
118
- # @return [Range] the line range in {#full_source} represented
119
- # by the node
120
- def line_range
121
- reset_line_info unless @line_range
122
- @line_range
123
- end
124
-
125
- # @return [Boolean] whether the node has a {#line_range} set
126
- def has_line?
127
- @line_range ? true : false
128
- end
129
-
130
- # @return [Fixnum] the starting line number of the node
131
- def line
132
- line_range && line_range.first
133
- end
134
-
135
- # @return [String] the first line of source represented by the node.
136
- def first_line
137
- full_source.split(/\r?\n/)[line - 1].strip
138
- end
139
-
148
+ # @group Traversing a Node
149
+
140
150
  # Searches through the node and all descendents and returns the
141
151
  # first node with a type matching any of +node_types+, otherwise
142
152
  # returns the original node (self).
@@ -167,6 +177,21 @@ module YARD
167
177
  @children ||= select {|e| AstNode === e }
168
178
  end
169
179
 
180
+ # Traverses the object and yields each node (including descendents) in order.
181
+ #
182
+ # @yield each descendent node in order
183
+ # @yieldparam [AstNode] self, or a child/descendent node
184
+ # @return [void]
185
+ def traverse
186
+ nodes = [self]
187
+ nodes.each.with_index do |node, index|
188
+ yield node
189
+ nodes.insert index+1, *node.children
190
+ end
191
+ end
192
+
193
+ # @group Node Meta Types
194
+
170
195
  # @return [Boolean] whether the node is a token
171
196
  def token?
172
197
  @token
@@ -198,25 +223,30 @@ module YARD
198
223
  false
199
224
  end
200
225
 
201
- # @return [String] the filename the node was parsed from
202
- def file
203
- return parent.file if parent
204
- @file
226
+ # @group Getting Line Information
227
+
228
+ # @return [Boolean] whether the node has a {#line_range} set
229
+ def has_line?
230
+ @line_range ? true : false
205
231
  end
206
-
207
- # @return [String] the full source that the node was parsed from
208
- def full_source
209
- return parent.full_source if parent
210
- return @full_source if @full_source
211
- return IO.read(@file) if file && File.exist?(file)
232
+
233
+ # @return [Fixnum] the starting line number of the node
234
+ def line
235
+ line_range && line_range.first
212
236
  end
213
-
214
- # @return [String] the parse of {#full_source} that the node represents
215
- def source
216
- return parent.full_source[source_range] if parent
217
- full_source
237
+
238
+ # @return [String] the first line of source represented by the node.
239
+ def first_line
240
+ full_source.split(/\r?\n/)[line - 1].strip
218
241
  end
219
242
 
243
+ # @group Printing a Node
244
+
245
+ # @return [String] the first line of source the node represents
246
+ def show
247
+ "\t#{line}: #{first_line}"
248
+ end
249
+
220
250
  # @return [nil] pretty prints the node
221
251
  def pretty_print(q)
222
252
  objs = [*self.dup, :__last__]
@@ -257,18 +287,7 @@ module YARD
257
287
  's(' + typeinfo + map(&:inspect).join(", ") + ')'
258
288
  end
259
289
 
260
- # Traverses the object and yields each node (including descendents) in order.
261
- #
262
- # @yield each descendent node in order
263
- # @yieldparam [AstNode] self, or a child/descendent node
264
- # @return [void]
265
- def traverse
266
- nodes = [self]
267
- nodes.each.with_index do |node, index|
268
- yield node
269
- nodes.insert index+1, *node.children
270
- end
271
- end
290
+ # @endgroup
272
291
 
273
292
  private
274
293
 
@@ -3,6 +3,7 @@ require "irb/slex"
3
3
 
4
4
  module YARD
5
5
  module Parser::Ruby::Legacy
6
+ # Legacy lexical tokenizer module.
6
7
  module RubyToken
7
8
  EXPR_BEG = :EXPR_BEG
8
9
  EXPR_MID = :EXPR_MID
@@ -12,30 +13,50 @@ module YARD
12
13
  EXPR_DOT = :EXPR_DOT
13
14
  EXPR_CLASS = :EXPR_CLASS
14
15
 
16
+ # Represents a token in the Ruby lexer
15
17
  class Token
18
+ # @return [Integer] the line number in the file/stream the token is
19
+ # located.
20
+ attr_reader :line_no
21
+
22
+ # @return [Integer] the character number in the file/stream the token
23
+ # is located.
24
+ attr_reader :char_no
25
+
26
+ # @return [String] the token text value
27
+ attr_reader :text
28
+
29
+ # @return [Symbol] the lexical state at the token
30
+ attr_accessor :lex_state
31
+
32
+ # @private
16
33
  NO_TEXT = "??".freeze
17
34
 
35
+ # Creates a new Token object
36
+ # @param [Integer] line_no the line number to initialize the token to
37
+ # @param [Integer] char_no the char number to initialize the token to
18
38
  def initialize(line_no, char_no)
19
39
  @line_no = line_no
20
40
  @char_no = char_no
21
41
  @text = NO_TEXT
22
42
  end
23
43
 
24
- # Because we're used in contexts that expect to return a token,
25
- # we set the text string and then return ourselves
44
+ # Chainable way to sets the text attribute
45
+ #
46
+ # @param [String] text the new text
47
+ # @return [Token] this token object
26
48
  def set_text(text)
27
49
  @text = text
28
50
  self
29
51
  end
30
-
31
- attr_reader :line_no, :char_no, :text
32
- attr_accessor :lex_state
33
52
  end
34
53
 
54
+ # Represents a block
35
55
  class TkBlockContents < Token
36
56
  def text; '...' end
37
57
  end
38
58
 
59
+ # Represents an end statement
39
60
  class TkStatementEnd < Token
40
61
  def text; '' end
41
62
  end
@@ -44,9 +65,11 @@ module YARD
44
65
  attr :node
45
66
  end
46
67
 
68
+ # Represents whitespace
47
69
  class TkWhitespace < Token
48
70
  end
49
71
 
72
+ # Represents a Ruby identifier
50
73
  class TkId < Token
51
74
  def initialize(line_no, char_no, name)
52
75
  super(line_no, char_no)
@@ -55,9 +78,11 @@ module YARD
55
78
  attr :name
56
79
  end
57
80
 
81
+ # Represents a Ruby keyword
58
82
  class TkKW < TkId
59
83
  end
60
84
 
85
+ # Represents a Ruby value
61
86
  class TkVal < Token
62
87
  def initialize(line_no, char_no, value = nil)
63
88
  super(line_no, char_no)
@@ -91,11 +116,13 @@ module YARD
91
116
  class TkError < Token
92
117
  end
93
118
 
119
+ # @private
94
120
  def set_token_position(line, char)
95
121
  @prev_line_no = line
96
122
  @prev_char_no = char
97
123
  end
98
124
 
125
+ # @private
99
126
  def Token(token, value = nil)
100
127
  tk = nil
101
128
  case token
@@ -117,6 +144,7 @@ module YARD
117
144
  tk
118
145
  end
119
146
 
147
+ # @private
120
148
  TokenDefinitions = [
121
149
  [:TkCLASS, TkKW, "class", EXPR_CLASS],
122
150
  [:TkMODULE, TkKW, "module", EXPR_BEG],
@@ -257,6 +285,7 @@ module YARD
257
285
  TkReading2Token = {}
258
286
  TkSymbol2Token = {}
259
287
 
288
+ # @private
260
289
  def RubyToken.def_token(token_n, super_token = Token, reading = nil, *opts)
261
290
  token_n = token_n.id2name unless token_n.kind_of?(String)
262
291
  if RubyToken.const_defined?(token_n)
@@ -298,11 +327,8 @@ module YARD
298
327
 
299
328
 
300
329
  # Lexical analyzer for Ruby source
301
-
330
+ # @private
302
331
  class RubyLex
303
-
304
- ######################################################################
305
- #
306
332
  # Read an input stream character by character. We allow for unlimited
307
333
  # ungetting of characters just read.
308
334
  #
@@ -330,7 +356,7 @@ module YARD
330
356
  # here document. Once complete, it needs to read the rest of the
331
357
  # original line, but then skip the here document body.
332
358
  #
333
-
359
+ # @private
334
360
  class BufferedReader
335
361
 
336
362
  attr_reader :line_num