yard 0.2.1 → 0.2.2

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 (264) hide show
  1. data/{LICENSE.txt → LICENSE} +1 -1
  2. data/README +211 -0
  3. data/Rakefile +31 -0
  4. data/benchmarks/builtins_vs_eval.rb +23 -0
  5. data/benchmarks/erb_vs_erubis.rb +53 -0
  6. data/benchmarks/generation.rb +37 -0
  7. data/benchmarks/parsing.rb +33 -0
  8. data/bin/view_generator +17 -0
  9. data/bin/yard-graph +4 -0
  10. data/bin/yardoc +1 -93
  11. data/bin/yri +12 -3
  12. data/lib/yard.rb +10 -5
  13. data/lib/yard/autoload.rb +116 -0
  14. data/lib/yard/cli/yard_graph.rb +86 -0
  15. data/lib/yard/cli/yardoc.rb +131 -0
  16. data/lib/yard/code_objects/base.rb +321 -0
  17. data/lib/yard/code_objects/class_object.rb +89 -0
  18. data/lib/yard/code_objects/class_variable_object.rb +4 -0
  19. data/lib/yard/code_objects/constant_object.rb +4 -0
  20. data/lib/yard/code_objects/method_object.rb +51 -0
  21. data/lib/yard/code_objects/module_object.rb +4 -0
  22. data/lib/yard/code_objects/namespace_object.rb +88 -0
  23. data/lib/yard/code_objects/proxy.rb +183 -0
  24. data/lib/yard/code_objects/root_object.rb +8 -0
  25. data/lib/yard/core_ext/file.rb +26 -0
  26. data/lib/yard/core_ext/logger.rb +5 -0
  27. data/lib/yard/core_ext/module.rb +9 -0
  28. data/lib/yard/core_ext/string.rb +13 -0
  29. data/lib/yard/core_ext/symbol_hash.rb +24 -0
  30. data/lib/yard/generators/attributes_generator.rb +22 -0
  31. data/lib/yard/generators/base.rb +285 -0
  32. data/lib/yard/generators/class_generator.rb +25 -0
  33. data/lib/yard/generators/constants_generator.rb +73 -0
  34. data/lib/yard/generators/constructor_generator.rb +25 -0
  35. data/lib/yard/generators/deprecated_generator.rb +15 -0
  36. data/lib/yard/generators/docstring_generator.rb +15 -0
  37. data/lib/yard/generators/full_doc_generator.rb +59 -0
  38. data/lib/yard/generators/helpers/base_helper.rb +52 -0
  39. data/lib/yard/generators/helpers/filter_helper.rb +21 -0
  40. data/lib/yard/generators/helpers/html_helper.rb +137 -0
  41. data/lib/yard/generators/helpers/method_helper.rb +27 -0
  42. data/lib/yard/generators/helpers/uml_helper.rb +16 -0
  43. data/lib/yard/generators/inheritance_generator.rb +16 -0
  44. data/lib/yard/generators/method_details_generator.rb +18 -0
  45. data/lib/yard/generators/method_generator.rb +31 -0
  46. data/lib/yard/generators/method_listing_generator.rb +105 -0
  47. data/lib/yard/generators/method_missing_generator.rb +25 -0
  48. data/lib/yard/generators/method_signature_generator.rb +19 -0
  49. data/lib/yard/generators/method_summary_generator.rb +21 -0
  50. data/lib/yard/generators/mixins_generator.rb +15 -0
  51. data/lib/yard/generators/module_generator.rb +22 -0
  52. data/lib/yard/generators/quick_doc_generator.rb +31 -0
  53. data/lib/yard/generators/source_generator.rb +26 -0
  54. data/lib/yard/generators/tags_generator.rb +50 -0
  55. data/lib/yard/generators/uml_generator.rb +92 -0
  56. data/lib/yard/generators/visibility_group_generator.rb +26 -0
  57. data/lib/yard/handlers/alias_handler.rb +32 -0
  58. data/lib/yard/handlers/attribute_handler.rb +54 -0
  59. data/lib/yard/handlers/base.rb +509 -0
  60. data/lib/yard/handlers/class_handler.rb +44 -0
  61. data/lib/yard/handlers/class_variable_handler.rb +13 -0
  62. data/lib/yard/handlers/constant_handler.rb +13 -0
  63. data/lib/yard/handlers/exception_handler.rb +12 -0
  64. data/lib/yard/handlers/method_handler.rb +27 -0
  65. data/lib/yard/handlers/mixin_handler.rb +16 -0
  66. data/lib/yard/handlers/module_handler.rb +9 -0
  67. data/lib/yard/handlers/visibility_handler.rb +14 -0
  68. data/lib/yard/handlers/yield_handler.rb +26 -0
  69. data/lib/yard/logging.rb +27 -0
  70. data/lib/yard/parser/ruby_lex.rb +1344 -0
  71. data/lib/yard/parser/source_parser.rb +109 -0
  72. data/lib/yard/parser/statement.rb +36 -0
  73. data/lib/yard/parser/statement_list.rb +167 -0
  74. data/lib/yard/parser/token_list.rb +58 -0
  75. data/lib/yard/rake/yardoc_task.rb +30 -0
  76. data/lib/yard/registry.rb +136 -0
  77. data/lib/yard/serializers/base.rb +16 -0
  78. data/lib/yard/serializers/file_system_serializer.rb +48 -0
  79. data/lib/yard/serializers/process_serializer.rb +14 -0
  80. data/lib/yard/serializers/stdout_serializer.rb +21 -0
  81. data/lib/yard/tags/default_factory.rb +98 -0
  82. data/lib/yard/tags/library.rb +109 -0
  83. data/lib/yard/tags/merbdoc_factory.rb +47 -0
  84. data/lib/yard/tags/tag.rb +35 -0
  85. data/spec/code_objects/base_spec.rb +219 -0
  86. data/spec/code_objects/class_object_spec.rb +176 -0
  87. data/spec/code_objects/code_object_list_spec.rb +33 -0
  88. data/spec/code_objects/constants_spec.rb +79 -0
  89. data/spec/code_objects/method_object_spec.rb +30 -0
  90. data/spec/code_objects/module_object_spec.rb +73 -0
  91. data/spec/code_objects/namespace_object_spec.rb +129 -0
  92. data/spec/code_objects/proxy_spec.rb +80 -0
  93. data/spec/code_objects/spec_helper.rb +3 -0
  94. data/spec/core_ext/file_spec.rb +20 -0
  95. data/spec/core_ext/string_spec.rb +4 -0
  96. data/spec/core_ext/symbol_hash_spec.rb +80 -0
  97. data/spec/generators/base_spec.rb +64 -0
  98. data/spec/generators/helpers/base_helper_spec.rb +15 -0
  99. data/spec/generators/helpers/html_helper_spec.rb +56 -0
  100. data/spec/generators/quick_doc_generator_spec.rb +13 -0
  101. data/spec/handlers/alias_handler_spec.rb +50 -0
  102. data/spec/handlers/attribute_handler_spec.rb +78 -0
  103. data/spec/handlers/base_spec.rb +165 -0
  104. data/spec/handlers/class_handler_spec.rb +68 -0
  105. data/spec/handlers/class_variable_handler_spec.rb +9 -0
  106. data/spec/handlers/constant_handler_spec.rb +13 -0
  107. data/spec/handlers/examples/alias_handler_001.rb.txt +24 -0
  108. data/spec/handlers/examples/attribute_handler_001.rb.txt +19 -0
  109. data/spec/handlers/examples/class_handler_001.rb.txt +39 -0
  110. data/spec/handlers/examples/class_variable_handler_001.rb.txt +9 -0
  111. data/spec/handlers/examples/constant_handler_001.rb.txt +10 -0
  112. data/spec/handlers/examples/exception_handler_001.rb.txt +42 -0
  113. data/spec/handlers/examples/method_handler_001.rb.txt +35 -0
  114. data/spec/handlers/examples/mixin_handler_001.rb.txt +12 -0
  115. data/spec/handlers/examples/module_handler_001.rb.txt +16 -0
  116. data/spec/handlers/examples/visibility_handler_001.rb.txt +20 -0
  117. data/spec/handlers/examples/yield_handler_001.rb.txt +55 -0
  118. data/spec/handlers/exception_handler_spec.rb +35 -0
  119. data/spec/handlers/method_handler_spec.rb +35 -0
  120. data/spec/handlers/mixin_handler_spec.rb +30 -0
  121. data/spec/handlers/module_handler_spec.rb +25 -0
  122. data/spec/handlers/spec_helper.rb +21 -0
  123. data/spec/handlers/visibility_handler_spec.rb +24 -0
  124. data/spec/handlers/yield_handler_spec.rb +51 -0
  125. data/spec/parser/examples/example1.rb.txt +8 -0
  126. data/spec/parser/examples/tag_handler_001.rb.txt +8 -0
  127. data/spec/parser/source_parser_spec.rb +43 -0
  128. data/spec/parser/tag_parsing_spec.rb +18 -0
  129. data/spec/parser/token_list_spec.rb +35 -0
  130. data/spec/registry_spec.rb +70 -0
  131. data/spec/serializers/file_system_serializer_spec.rb +91 -0
  132. data/spec/serializers/spec_helper.rb +2 -0
  133. data/spec/spec_helper.rb +77 -0
  134. data/templates/default/attributes/html/header.erb +35 -0
  135. data/templates/default/attributes/text/header.erb +10 -0
  136. data/templates/default/class/html/header.erb +4 -0
  137. data/templates/default/constants/html/constants.erb +9 -0
  138. data/templates/default/constants/html/header.erb +3 -0
  139. data/templates/default/constants/html/included.erb +9 -0
  140. data/templates/default/constants/html/inherited.erb +9 -0
  141. data/templates/default/constructor/html/header.erb +10 -0
  142. data/templates/default/deprecated/html/main.erb +4 -0
  143. data/templates/default/deprecated/text/main.erb +3 -0
  144. data/templates/default/docstring/html/main.erb +3 -0
  145. data/templates/default/docstring/text/main.erb +3 -0
  146. data/templates/default/fulldoc/html/all_methods.erb +25 -0
  147. data/templates/default/fulldoc/html/all_namespaces.erb +19 -0
  148. data/templates/default/fulldoc/html/app.js +18 -0
  149. data/templates/default/fulldoc/html/header.erb +15 -0
  150. data/templates/default/fulldoc/html/html_head.erb +3 -0
  151. data/templates/default/fulldoc/html/index.erb +18 -0
  152. data/templates/default/fulldoc/html/jquery.js +11 -0
  153. data/templates/default/fulldoc/html/readme.erb +15 -0
  154. data/templates/default/fulldoc/html/style.css +65 -0
  155. data/templates/default/fulldoc/html/syntax_highlight.css +21 -0
  156. data/templates/default/inheritance/html/header.erb +8 -0
  157. data/templates/default/inheritance/text/header.erb +3 -0
  158. data/templates/default/method/html/aliases.erb +6 -0
  159. data/templates/default/method/html/header.erb +3 -0
  160. data/templates/default/method/html/title.erb +3 -0
  161. data/templates/default/methoddetails/html/header.erb +8 -0
  162. data/templates/default/methoddetails/html/method_header.erb +3 -0
  163. data/templates/default/methodmissing/html/header.erb +12 -0
  164. data/templates/default/methodsignature/html/main.erb +8 -0
  165. data/templates/default/methodsignature/text/main.erb +5 -0
  166. data/templates/default/methodsummary/html/header.erb +5 -0
  167. data/templates/default/methodsummary/html/included.erb +9 -0
  168. data/templates/default/methodsummary/html/inherited.erb +9 -0
  169. data/templates/default/methodsummary/html/summary.erb +25 -0
  170. data/templates/default/methodsummary/text/header.erb +5 -0
  171. data/templates/default/methodsummary/text/included.erb +0 -0
  172. data/templates/default/methodsummary/text/inherited.erb +0 -0
  173. data/templates/default/methodsummary/text/summary.erb +3 -0
  174. data/templates/default/mixins/html/header.erb +4 -0
  175. data/templates/default/module/html/header.erb +4 -0
  176. data/templates/default/quickdoc/html/header.erb +15 -0
  177. data/templates/default/quickdoc/text/header.erb +12 -0
  178. data/templates/default/source/html/main.erb +15 -0
  179. data/templates/default/source/text/main.erb +4 -0
  180. data/templates/default/tags/html/header.erb +4 -0
  181. data/templates/default/tags/html/see.erb +13 -0
  182. data/templates/default/tags/html/tags.erb +20 -0
  183. data/templates/default/tags/text/header.erb +3 -0
  184. data/templates/default/tags/text/see.erb +5 -0
  185. data/templates/default/tags/text/tags.erb +7 -0
  186. data/templates/default/uml/dot/child.erb +1 -0
  187. data/templates/default/uml/dot/dependencies.erb +10 -0
  188. data/templates/default/uml/dot/header.erb +6 -0
  189. data/templates/default/uml/dot/info.erb +14 -0
  190. data/templates/default/uml/dot/subgraph.erb +6 -0
  191. data/templates/default/uml/dot/superclasses.erb +9 -0
  192. data/templates/default/uml/dot/unknown.erb +3 -0
  193. data/templates/default/uml/dot/unknown_child.erb +1 -0
  194. data/templates/default/visibilitygroup/html/header.erb +6 -0
  195. data/templates/javadoc/attributes/html/header.erb +16 -0
  196. data/templates/javadoc/class/html/header.erb +4 -0
  197. data/templates/javadoc/constants/html/constants.erb +9 -0
  198. data/templates/javadoc/constants/html/header.erb +3 -0
  199. data/templates/javadoc/constants/html/included.erb +12 -0
  200. data/templates/javadoc/constants/html/inherited.erb +12 -0
  201. data/templates/javadoc/constructor/html/header.erb +10 -0
  202. data/templates/javadoc/deprecated/html/main.erb +0 -0
  203. data/templates/javadoc/docstring/html/main.erb +6 -0
  204. data/templates/javadoc/fulldoc/html/all_methods.erb +25 -0
  205. data/templates/javadoc/fulldoc/html/all_namespaces.erb +19 -0
  206. data/templates/javadoc/fulldoc/html/app.js +18 -0
  207. data/templates/javadoc/fulldoc/html/header.erb +15 -0
  208. data/templates/javadoc/fulldoc/html/html_head.erb +3 -0
  209. data/templates/javadoc/fulldoc/html/index.erb +18 -0
  210. data/templates/javadoc/fulldoc/html/jquery.js +11 -0
  211. data/templates/javadoc/fulldoc/html/readme.erb +15 -0
  212. data/templates/javadoc/fulldoc/html/style.css +22 -0
  213. data/templates/javadoc/fulldoc/html/syntax_highlight.css +21 -0
  214. data/templates/javadoc/inheritance/html/header.erb +6 -0
  215. data/templates/javadoc/method/html/aliases.erb +6 -0
  216. data/templates/javadoc/method/html/header.erb +4 -0
  217. data/templates/javadoc/method/html/title.erb +4 -0
  218. data/templates/javadoc/methoddetails/html/header.erb +8 -0
  219. data/templates/javadoc/methoddetails/html/method_header.erb +0 -0
  220. data/templates/javadoc/methodmissing/html/header.erb +12 -0
  221. data/templates/javadoc/methodsignature/html/main.erb +8 -0
  222. data/templates/javadoc/methodsummary/html/header.erb +5 -0
  223. data/templates/javadoc/methodsummary/html/included.erb +12 -0
  224. data/templates/javadoc/methodsummary/html/inherited.erb +12 -0
  225. data/templates/javadoc/methodsummary/html/summary.erb +25 -0
  226. data/templates/javadoc/mixins/html/header.erb +5 -0
  227. data/templates/javadoc/module/html/header.erb +4 -0
  228. data/templates/javadoc/source/html/main.erb +15 -0
  229. data/templates/javadoc/tags/html/header.erb +5 -0
  230. data/templates/javadoc/tags/html/see.erb +8 -0
  231. data/templates/javadoc/tags/html/tags.erb +19 -0
  232. data/templates/javadoc/visibilitygroup/html/header.erb +5 -0
  233. metadata +352 -50
  234. data/README.pdf +0 -0
  235. data/lib/code_object.rb +0 -337
  236. data/lib/extra.rb +0 -8
  237. data/lib/formatter.rb +0 -90
  238. data/lib/handlers/all_handlers.rb +0 -2
  239. data/lib/handlers/attribute_handler.rb +0 -51
  240. data/lib/handlers/class_handler.rb +0 -30
  241. data/lib/handlers/class_variable_handler.rb +0 -9
  242. data/lib/handlers/code_object_handler.rb +0 -104
  243. data/lib/handlers/constant_handler.rb +0 -11
  244. data/lib/handlers/exception_handler.rb +0 -20
  245. data/lib/handlers/method_handler.rb +0 -28
  246. data/lib/handlers/mixin_handler.rb +0 -15
  247. data/lib/handlers/module_handler.rb +0 -9
  248. data/lib/handlers/visibility_handler.rb +0 -7
  249. data/lib/handlers/yield_handler.rb +0 -33
  250. data/lib/logger.rb +0 -19
  251. data/lib/namespace.rb +0 -98
  252. data/lib/quick_doc.rb +0 -104
  253. data/lib/ruby_lex.rb +0 -1321
  254. data/lib/source_parser.rb +0 -253
  255. data/lib/tag_library.rb +0 -175
  256. data/lib/tag_type.rb +0 -155
  257. data/templates/default/html/_fulldoc.erb +0 -64
  258. data/templates/default/html/class.erb +0 -226
  259. data/templates/default/html/method.erb +0 -20
  260. data/templates/default/html/module.erb +0 -126
  261. data/test/fixtures/docstring.txt +0 -23
  262. data/test/fixtures/docstring2.txt +0 -4
  263. data/test/test_code_object.rb +0 -66
  264. data/test/test_namespace.rb +0 -10
@@ -1,253 +0,0 @@
1
- require 'stringio'
2
- require File.dirname(__FILE__) + '/ruby_lex'
3
- require File.dirname(__FILE__) + '/namespace'
4
- require File.dirname(__FILE__) + '/code_object'
5
- require File.dirname(__FILE__) + '/handlers/all_handlers'
6
-
7
- module YARD
8
- ##
9
- # Responsible for parsing a source file into the namespace
10
- class SourceParser
11
- attr_reader :file
12
-
13
- def self.parse(content)
14
- new.parse(content)
15
- end
16
-
17
- def self.parse_string(content)
18
- new.parse(StringIO.new(content))
19
- end
20
-
21
- attr_accessor :current_namespace
22
-
23
- def initialize
24
- @current_namespace = NameStruct.new(Namespace.root)
25
- end
26
-
27
- ##
28
- # Creates a new SourceParser that parses a file and returns
29
- # analysis information about it.
30
- #
31
- # @param [String, TokenList, StatementList] content the source file to parse
32
- def parse(content = __FILE__)
33
- case content
34
- when String
35
- @file = content
36
- statements = StatementList.new(IO.read(content))
37
- when TokenList
38
- statements = StatementList.new(content)
39
- when StatementList
40
- statements = content
41
- else
42
- if content.respond_to? :read
43
- statements = StatementList.new(content.read)
44
- else
45
- raise ArgumentError, "Invalid argument for SourceParser::parse: #{content.inspect}:#{content.class}"
46
- end
47
- end
48
-
49
- top_level_parse(statements)
50
- end
51
-
52
- private
53
- def top_level_parse(statements)
54
- statements.each do |stmt|
55
- find_handlers(stmt).each do |handler|
56
- begin
57
- handler.new(self, stmt).process
58
- rescue => e
59
- STDERR.puts "#{handler.to_s} error in `#{file}`:#{stmt.tokens.first.line_no}: #{stmt.tokens.to_s}"
60
- STDERR.puts "Exception message: #{e.message}"
61
- STDERR.puts e.backtrace[0, 5]
62
- STDERR.puts
63
- end
64
- end
65
- end
66
- end
67
-
68
- def find_handlers(stmt)
69
- CodeObjectHandler.subclasses.find_all {|sub| sub.handles? stmt.tokens }
70
- end
71
- end
72
-
73
- class StatementList < Array
74
- include RubyToken
75
-
76
- # The following list of tokens will require a block to be opened
77
- # if used at the beginning of a statement.
78
- @@open_block_tokens = [TkCLASS, TkDEF, TkMODULE, TkUNTIL,
79
- TkIF, TkUNLESS, TkWHILE, TkFOR, TkCASE]
80
-
81
- ##
82
- # Creates a new statement list
83
- #
84
- # @param [TokenList, String] content the tokens to create the list from
85
- def initialize(content)
86
- if content.is_a? TokenList
87
- @tokens = content
88
- elsif content.is_a? String
89
- parse_tokens(content)
90
- else
91
- raise ArgumentError, "Invalid content for StatementList: #{content.inspect}:#{content.class}"
92
- end
93
-
94
- parse_statements
95
- end
96
-
97
- private
98
- def parse_tokens(content)
99
- @tokens = TokenList.new
100
- lex = RubyLex.new(content)
101
- while tk = lex.token do @tokens << tk end
102
- end
103
-
104
- def parse_statements
105
- while stmt = next_statement do self << stmt end
106
- end
107
-
108
- # MUST REFACTOR THIS CODE
109
- # WARNING WARNING WARNING WARNING
110
- # MUST REFACTOR THIS CODE |
111
- # OR CHILDREN WILL DIE V
112
- # WARNING WARNING WARNING WARNING
113
- # THIS IS MEANT TO BE UGLY.
114
- def next_statement
115
- statement, block, comments = TokenList.new, nil, nil
116
- stmt_number, level = 0, 0
117
- new_statement, open_block = true, false
118
- last_tk, before_last_tk = nil, nil
119
- open_parens = 0
120
-
121
- while tk = @tokens.shift
122
- #p tk.class
123
- open_parens += 1 if [TkLPAREN, TkLBRACK].include? tk.class
124
- open_parens -= 1 if [TkRPAREN, TkRBRACK].include?(tk.class) if open_parens > 0
125
-
126
- # raise block.to_s + " TOKEN #{tk.inspect}" if open_parens < 0
127
-
128
- # Get the initial comments
129
- if statement.empty?
130
- # Two new-lines in a row will destroy any comment blocks
131
- if tk.class == TkCOMMENT && last_tk.class == TkNL &&
132
- (before_last_tk && (before_last_tk.class == TkNL || before_last_tk.class == TkSPACE))
133
- comments = nil
134
- elsif tk.class == TkCOMMENT
135
- # Remove the "#" and up to 1 space before the text
136
- # Since, of course, the convention is to have "# text"
137
- # and not "#text", which I deem ugly (you heard it here first)
138
- comments ||= []
139
- comments << (tk.text[/^#+\s{0,1}(\s*[^\s#].+)/, 1] || "")
140
- comments.pop if comments.size == 1 && comments.first =~ /^\s*$/
141
- end
142
- end
143
-
144
- # Ignore any initial comments or whitespace
145
- unless statement.empty? && [TkSPACE, TkNL, TkCOMMENT].include?(tk.class)
146
- # Decrease if end or '}' is seen
147
- level -= 1 if [TkEND, TkRBRACE].include?(tk.class)
148
-
149
- # If the level is greater than 0, add the code to the block text
150
- # otherwise it's part of the statement text
151
- if stmt_number > 0
152
- block ||= TokenList.new
153
- block << tk
154
- elsif stmt_number == 0 && tk.class != TkNL && tk.class != TkCOMMENT
155
- statement << tk
156
- end
157
-
158
- # puts "#{tk.line_no} #{level} #{tk} \t#{tk.text} #{tk.lex_state}"
159
-
160
- # Increase level if we have a 'do' or block opening
161
- if tk.class == TkLBRACE
162
- level += 1
163
- elsif [TkDO, TkfLBRACE, TkBEGIN].include?(tk.class)
164
- #p "#{tk.line_no} #{level} #{tk} \t#{tk.text} #{tk.lex_state}"
165
- level += 1
166
- open_block = false # Cancel our wish to open a block for the if, we're doing it now
167
- end
168
-
169
- # Vouch to open a block when this statement would otherwise end
170
- open_block = true if (new_statement || (last_tk && last_tk.lex_state == EXPR_BEG)) && @@open_block_tokens.include?(tk.class)
171
-
172
- # Check if this token creates a new statement or not
173
- #puts "#{open_parens} open brackets for: #{statement.to_s}"
174
- if open_parens == 0 && ([TkSEMICOLON, TkNL, TkEND_OF_SCRIPT].include?(tk.class) ||
175
- (statement.first.class == TkDEF && tk.class == TkRPAREN))
176
- # Make sure we don't have any running expressions
177
- # This includes things like
178
- #
179
- # class <
180
- # Foo
181
- #
182
- # if a ||
183
- # b
184
- if last_tk && [EXPR_END, EXPR_ARG].include?(last_tk.lex_state)
185
- stmt_number += 1
186
- new_statement = true
187
- #p "NEW STATEMENT #{statement.to_s}"
188
-
189
- # The statement started with a if/while/begin, so we must go to the next level now
190
- if open_block
191
- open_block = false
192
- level += 1
193
- end
194
- end
195
- elsif tk.class != TkSPACE
196
- new_statement = false
197
- end
198
-
199
- # Else keyword is kind of weird
200
- if tk.is_a? RubyToken::TkELSE
201
- new_statement = true
202
- stmt_number += 1
203
- open_block = false
204
- end
205
-
206
- # We're done if we've ended a statement and we're at level 0
207
- break if new_statement && level == 0
208
- end
209
-
210
- before_last_tk = last_tk
211
- last_tk = tk # Save last token
212
- end
213
-
214
- # Return the code block with starting token and initial comments
215
- # If there is no code in the block, return nil
216
- comments = comments.compact if comments
217
- statement.empty? ? nil : Statement.new(statement, block, comments)
218
- end
219
- end
220
-
221
- class TokenList < Array
222
- def to_s
223
- collect {|t| t.text }.join
224
- end
225
- end
226
-
227
- class Statement
228
- attr_reader :tokens, :comments, :block
229
-
230
- def initialize(tokens, block = nil, comments = nil)
231
- @tokens = clean_tokens(tokens)
232
- @block = block
233
- @comments = comments
234
- end
235
-
236
- private
237
- def clean_tokens(tokens)
238
- last_tk = nil
239
- tokens.reject do |tk|
240
- tk.is_a?(RubyToken::TkNL) ||
241
- (last_tk.is_a?(RubyToken::TkSPACE) &&
242
- last_tk.class == tk.class) && last_tk = tk
243
- end
244
- end
245
- end
246
-
247
- class NameStruct
248
- attr_accessor :object, :attributes
249
- def initialize(object)
250
- @object, @attributes = object, { :visibility => :public, :scope => :instance }
251
- end
252
- end
253
- end
@@ -1,175 +0,0 @@
1
- module YARD
2
- ##
3
- # Holds all the registered meta tags. If you want to extend YARD and add
4
- # a new meta tag, you can do it in one of two ways.
5
- #
6
- # == Method #1
7
- # Write your own +tagname_tag+ method that takes the raw text as a parameter.
8
- # Example:
9
- # def mytag_tag(text)
10
- # Tag.parse_tag("mytag", text)
11
- # end
12
- #
13
- # This will allow you to use @mytag TEXT to add meta data to classes through
14
- # the docstring. {Tag} has a few convenience factory methods to create
15
- #
16
- # == Method #2
17
- # Use {TagLibrary::define_tag!} to define a new tag by passing the tag name
18
- # and the factory method to use when creating the tag. These definitions will
19
- # be auto expanded into ruby code similar to what is shown in method #1. If you
20
- # do not provide a factory method to use, it will default to {Tag::parse_tag}
21
- # Example:
22
- # define_tag! :param, :with_types_and_name
23
- # define_tag! :author
24
- #
25
- # The first line will expand to the code:
26
- # def param_tag(text) Tag.parse_tag_with_types_and_name(text) end
27
- #
28
- # The second line will expand to:
29
- # def author_tag(text) Tag.parse_tag(text) end
30
- #
31
- # @see TagLibrary::define_tag!
32
- module TagLibrary
33
- class << self
34
- attr_reader :labels
35
-
36
- ##
37
- # Sorts the labels lexically by their label name, often used when displaying
38
- # the tags.
39
- #
40
- # @return [Array<Symbol,String>] the sorted labels as an array of the tag name and label
41
- def sorted_labels
42
- labels.sort_by {|a| a.last }
43
- end
44
-
45
- ##
46
- # Convenience method to define a new tag using one of {Tag}'s factory methods, or the
47
- # regular {Tag::parse_tag} factory method if none is supplied.
48
- #
49
- # @param tag the tag name to create
50
- # @param meth the {Tag} factory method to call when creating the tag
51
- def self.define_tag!(label, tag, meth = "")
52
- meth = meth.to_s
53
- send_name = meth.empty? ? "" : "_" + meth
54
- class_eval "def #{tag}_tag(text) Tag.parse_tag#{send_name}(#{tag.inspect}, text) end"
55
- @labels ||= {}
56
- @labels.update(tag => label)
57
- end
58
-
59
- define_tag! "Parameters", :param, :with_types_and_name
60
- define_tag! "Block Parameters", :yieldparam, :with_types_and_name
61
- define_tag! "Yields", :yield
62
- define_tag! "Returns", :return, :with_types
63
- define_tag! "Deprecated", :deprecated
64
- define_tag! "Author", :author
65
- define_tag! "Raises", :raise, :with_name
66
- define_tag! "See Also", :see
67
- define_tag! "Since", :since
68
- define_tag! "Version", :version
69
- end
70
- end
71
-
72
- class Tag
73
- attr_reader :tag_name, :text, :types, :name
74
-
75
- class << self
76
- ##
77
- # Parses tag text and creates a new tag with descriptive text
78
- #
79
- # @param tag_name the name of the tag to parse
80
- # @param [String] text the raw tag text
81
- # @return [Tag] a tag object with the tag_name and text values filled
82
- def parse_tag(tag_name, text)
83
- new(tag_name, text)
84
- end
85
-
86
- ##
87
- # Parses tag text and creates a new tag with a key name and descriptive text
88
- #
89
- # @param tag_name the name of the tag to parse
90
- # @param [String] text the raw tag text
91
- # @return [Tag] a tag object with the tag_name, name and text values filled
92
- def parse_tag_with_name(tag_name, text)
93
- name, text = *extract_name_from_text(text)
94
- new(tag_name, text, nil, name)
95
- end
96
-
97
- ##
98
- # Parses tag text and creates a new tag with formally declared types and
99
- # descriptive text
100
- #
101
- # @param tag_name the name of the tag to parse
102
- # @param [String] text the raw tag text
103
- # @return [Tag] a tag object with the tag_name, types and text values filled
104
- def parse_tag_with_types(tag_name, text)
105
- types, text = *extract_types_from_text(text)
106
- new(tag_name, text, types)
107
- end
108
-
109
- ##
110
- # Parses tag text and creates a new tag with formally declared types, a key
111
- # name and descriptive text
112
- #
113
- # @param tag_name the name of the tag to parse
114
- # @param [String] text the raw tag text
115
- # @return [Tag] a tag object with the tag_name, name, types and text values filled
116
- def parse_tag_with_types_and_name(tag_name, text)
117
- types, text = *extract_types_from_text(text)
118
- name, text = *extract_name_from_text(text)
119
- new(tag_name, text, types, name)
120
- end
121
-
122
- ##
123
- # Extracts the name from raw tag text returning the name and remaining value
124
- #
125
- # @param [String] text the raw tag text
126
- # @return [Array] an array holding the name as the first element and the
127
- # value as the second element
128
- def extract_name_from_text(text)
129
- text.strip.split(" ", 2)
130
- end
131
-
132
- ##
133
- # Extracts the type signatures from the raw tag text
134
- #
135
- # @param [String] text the raw tag text
136
- # @return [Array] an array holding the value as the first element and
137
- # the array of types as the second element
138
- def extract_types_from_text(text)
139
- types, text = [], text.strip
140
- if text =~ /^\s*\[(.+?)\]\s*(.*)/
141
- text, types = $2, $1.split(",").collect {|e| e.strip }
142
- end
143
- [types, text]
144
- end
145
- end
146
-
147
- ##
148
- # Creates a new tag object with a tag name and text. Optionally, formally declared types
149
- # and a key name can be specified.
150
- #
151
- # Types are mainly for meta tags that rely on type information, such as +param+, +return+, etc.
152
- #
153
- # Key names are for tags that declare meta data for a specific key or name, such as +param+,
154
- # +raise+, etc.
155
- #
156
- # @param tag_name the tag name to create the tag for
157
- # @param [String] text the descriptive text for this tag
158
- # @param [Array<String>] types optional type list of formally declared types
159
- # for the tag
160
- # @param [String] name optional key name which the tag refers to
161
- def initialize(tag_name, text, types = nil, name = nil)
162
- @tag_name, @text, @types, @name = tag_name.to_s, text, types, name
163
- end
164
-
165
- ##
166
- # Convenience method to access the first type specified. This should mainly
167
- # be used for tags that only specify one type.
168
- #
169
- # @see #types
170
- # @return (String) the first of the list of specified types
171
- def type
172
- types.first
173
- end
174
- end
175
- end
@@ -1,155 +0,0 @@
1
- module YARD
2
- ##
3
- # Represents a tag and its respective tag name and value.
4
- #
5
- # @abstract Override this class to using the class name format of
6
- # 'tagnameTag' to add a new tag to the registered tag library
7
- class BaseTag
8
- class << self
9
- ##
10
- # Returns the tag name that the class responds to. If the class name
11
- # does not accurately represent the tag name, this method should be overrided
12
- # by subclasses to return the correct tag name.
13
- #
14
- # @return [String] the tag name the class represents
15
- def tag_name
16
- @tag_name ||= self.to_s.split("::").last.gsub(/^Base.+|Tag$/, '').downcase
17
- end
18
-
19
- ##
20
- # Return all valid tags in the tag library
21
- #
22
- # @return [Array<String>] a list of valid tags that are registered
23
- # as being handled
24
- def tag_library
25
- @@tag_library || {}
26
- end
27
-
28
- ##
29
- # @override
30
- def inherited(subclass)
31
- @@tag_library ||= {}
32
- @@tag_library[subclass.tag_name] = subclass unless subclass.tag_name.empty?
33
- end
34
-
35
- ##
36
- # Parses tag text from a doc string and returns a new tag
37
- def parse_tag(text)
38
- new(text)
39
- end
40
- end
41
-
42
- ## All tags have an optional field for text data
43
- attr_reader :text
44
-
45
- def initialize(text)
46
- @text = text
47
- end
48
-
49
- ##
50
- # @see BaseTag::tag_name
51
- def tag_name
52
- self.class.tag_name
53
- end
54
- end
55
-
56
- ##
57
- # Similar to the {BaseTag}, this class allows for a tag to
58
- # formally specify type data if it depends on a specific object type.
59
- #
60
- class BaseTypeTag < BaseTag
61
- ##
62
- # Attribute reader for all specified types
63
- #
64
- # @return [String] the object types that the tag formally specifies
65
- attr_reader :types
66
-
67
- ##
68
- # Extracts the type signatures from the raw tag text
69
- #
70
- # @param [String] text the raw tag text
71
- # @return [Array] an array holding the value as the first element and
72
- # the array of types as the second element
73
- def self.extract_types_and_text(text)
74
- types, value = [], text.strip
75
- if text =~ /^\s*\[(.+?)\]\s*(.*)/
76
- value = $2
77
- types = $1.split(",").collect {|e| e.strip }
78
- end
79
- [value, types]
80
- end
81
-
82
- ##
83
- # Extracts the name from raw tag text returning the name and remaining value
84
- #
85
- # @param [String] text the raw tag text
86
- # @return [Array] an array holding the name as the first element and the
87
- # value as the second element
88
- def self.extract_name_and_text(text)
89
- text.strip.split(" ", 2)
90
- end
91
-
92
- ##
93
- # Create a new object with formally specified types
94
- #
95
- # @param [String] text the text data
96
- # @param [Array<String>] types the types that are formally specified
97
- # by the tag.
98
- def initialize(text, types = [])
99
- super(text)
100
- @types = types || []
101
- end
102
-
103
- ##
104
- # Convenience method to access the first type specified. This should mainly
105
- # be used for tags that only specify one type.
106
- #
107
- # @return (String) the first of the list of specified types
108
- def type
109
- types.first
110
- end
111
- end
112
-
113
- class ParamTag < BaseTypeTag
114
- attr_reader :name
115
-
116
- ##
117
- # Parses a typed tag's value section and returns a new {ParamTag} object
118
- #
119
- # @param [String] text the raw tag value to parse type specifications from
120
- # @return [ParamTag] the new typed tag object with the type values
121
- # parsed from raw text
122
- def self.parse_tag(text)
123
- desc, types = *extract_types_and_text(text)
124
- name, desc = *extract_name_and_text(desc)
125
- new(name, desc, types)
126
- end
127
-
128
- ##
129
- # Create a new +param+ tag with a description and declared types
130
- #
131
- # @param [String] name the parameter name specified by the tag
132
- # @param [String] text a description of the parameter
133
- # @param [Array<String>] types the optional types that the parameter accepts
134
- def initialize(name, text, types = [])
135
- super(text, types)
136
- @name = name
137
- end
138
- end
139
-
140
- class ReturnTag < BaseTypeTag
141
- def self.parse_tag(text)
142
- new *extract_types_and_text(text)
143
- end
144
-
145
- def initialize(text, types = []) super end
146
- end
147
-
148
- class DeprecatedTag < BaseTag
149
- def initialize(text) super end
150
- end
151
-
152
- class AuthorTag < BaseTag
153
- def initialize(text) super end
154
- end
155
- end