yard 0.2.2 → 0.2.3

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 (204) hide show
  1. data/LICENSE +1 -1
  2. data/README.markdown +200 -0
  3. data/Rakefile +6 -1
  4. data/benchmarks/format_args.rb +46 -0
  5. data/benchmarks/parsing.rb +13 -1
  6. data/benchmarks/rdoc_vs_yardoc.rb +10 -0
  7. data/benchmarks/ripper_parser.rb +12 -0
  8. data/docs/CODE_OBJECTS.markdown +121 -0
  9. data/docs/FAQ.markdown +34 -0
  10. data/docs/GENERATORS.markdown +211 -0
  11. data/docs/GETTING_STARTED.markdown +263 -0
  12. data/docs/GLOSSARY.markdown +13 -0
  13. data/docs/HANDLERS.markdown +158 -0
  14. data/docs/OVERVIEW.markdown +64 -0
  15. data/docs/PARSER.markdown +180 -0
  16. data/docs/TAGS.markdown +181 -0
  17. data/docs/WHATSNEW.markdown +96 -0
  18. data/docs/images/code-objects-class-diagram.png +0 -0
  19. data/docs/images/handlers-class-diagram.png +0 -0
  20. data/docs/images/overview-class-diagram.png +0 -0
  21. data/docs/images/parser-class-diagram.png +0 -0
  22. data/docs/images/tags-class-diagram.png +0 -0
  23. data/lib/yard.rb +4 -1
  24. data/lib/yard/autoload.rb +79 -31
  25. data/lib/yard/cli/yard_graph.rb +8 -2
  26. data/lib/yard/cli/yardoc.rb +61 -8
  27. data/lib/yard/code_objects/base.rb +78 -135
  28. data/lib/yard/code_objects/class_object.rb +9 -8
  29. data/lib/yard/code_objects/constant_object.rb +1 -0
  30. data/lib/yard/code_objects/extended_method_object.rb +9 -0
  31. data/lib/yard/code_objects/method_object.rb +18 -5
  32. data/lib/yard/code_objects/module_object.rb +8 -1
  33. data/lib/yard/code_objects/namespace_object.rb +25 -16
  34. data/lib/yard/code_objects/proxy.rb +22 -22
  35. data/lib/yard/core_ext/file.rb +1 -1
  36. data/lib/yard/core_ext/string.rb +0 -4
  37. data/lib/yard/core_ext/symbol_hash.rb +3 -2
  38. data/lib/yard/docstring.rb +180 -0
  39. data/lib/yard/generators/base.rb +33 -13
  40. data/lib/yard/generators/class_generator.rb +4 -2
  41. data/lib/yard/generators/constants_generator.rb +3 -2
  42. data/lib/yard/generators/full_doc_generator.rb +76 -9
  43. data/lib/yard/generators/helpers/base_helper.rb +18 -1
  44. data/lib/yard/generators/helpers/filter_helper.rb +2 -2
  45. data/lib/yard/generators/helpers/html_helper.rb +94 -39
  46. data/lib/yard/generators/helpers/html_syntax_highlight_helper.rb +49 -0
  47. data/lib/yard/generators/helpers/markup_helper.rb +86 -0
  48. data/lib/yard/generators/helpers/method_helper.rb +23 -7
  49. data/lib/yard/generators/method_generator.rb +15 -3
  50. data/lib/yard/generators/method_listing_generator.rb +3 -3
  51. data/lib/yard/generators/mixins_generator.rb +8 -2
  52. data/lib/yard/generators/module_generator.rb +3 -2
  53. data/lib/yard/generators/overloads_generator.rb +20 -0
  54. data/lib/yard/generators/quick_doc_generator.rb +3 -9
  55. data/lib/yard/generators/root_generator.rb +32 -0
  56. data/lib/yard/generators/source_generator.rb +2 -17
  57. data/lib/yard/generators/tags_generator.rb +34 -6
  58. data/lib/yard/generators/uml_generator.rb +16 -6
  59. data/lib/yard/handlers/base.rb +88 -253
  60. data/lib/yard/handlers/processor.rb +72 -0
  61. data/lib/yard/handlers/ruby/alias_handler.rb +38 -0
  62. data/lib/yard/handlers/ruby/attribute_handler.rb +69 -0
  63. data/lib/yard/handlers/ruby/base.rb +72 -0
  64. data/lib/yard/handlers/ruby/class_condition_handler.rb +70 -0
  65. data/lib/yard/handlers/ruby/class_handler.rb +74 -0
  66. data/lib/yard/handlers/ruby/class_variable_handler.rb +11 -0
  67. data/lib/yard/handlers/ruby/constant_handler.rb +12 -0
  68. data/lib/yard/handlers/ruby/exception_handler.rb +22 -0
  69. data/lib/yard/handlers/ruby/extend_handler.rb +19 -0
  70. data/lib/yard/handlers/{alias_handler.rb → ruby/legacy/alias_handler.rb} +3 -4
  71. data/lib/yard/handlers/{attribute_handler.rb → ruby/legacy/attribute_handler.rb} +2 -2
  72. data/lib/yard/handlers/ruby/legacy/base.rb +198 -0
  73. data/lib/yard/handlers/{class_handler.rb → ruby/legacy/class_handler.rb} +18 -6
  74. data/lib/yard/handlers/{class_variable_handler.rb → ruby/legacy/class_variable_handler.rb} +1 -1
  75. data/lib/yard/handlers/{constant_handler.rb → ruby/legacy/constant_handler.rb} +2 -2
  76. data/lib/yard/handlers/{exception_handler.rb → ruby/legacy/exception_handler.rb} +3 -3
  77. data/lib/yard/handlers/ruby/legacy/extend_handler.rb +18 -0
  78. data/lib/yard/handlers/ruby/legacy/method_handler.rb +31 -0
  79. data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +28 -0
  80. data/lib/yard/handlers/{module_handler.rb → ruby/legacy/module_handler.rb} +1 -1
  81. data/lib/yard/handlers/{visibility_handler.rb → ruby/legacy/visibility_handler.rb} +1 -1
  82. data/lib/yard/handlers/{yield_handler.rb → ruby/legacy/yield_handler.rb} +4 -4
  83. data/lib/yard/handlers/ruby/method_condition_handler.rb +7 -0
  84. data/lib/yard/handlers/ruby/method_handler.rb +48 -0
  85. data/lib/yard/handlers/ruby/mixin_handler.rb +25 -0
  86. data/lib/yard/handlers/ruby/module_handler.rb +9 -0
  87. data/lib/yard/handlers/ruby/visibility_handler.rb +18 -0
  88. data/lib/yard/handlers/ruby/yield_handler.rb +28 -0
  89. data/lib/yard/parser/ruby/ast_node.rb +263 -0
  90. data/lib/yard/parser/{ruby_lex.rb → ruby/legacy/ruby_lex.rb} +258 -259
  91. data/lib/yard/parser/{statement.rb → ruby/legacy/statement.rb} +8 -4
  92. data/lib/yard/parser/ruby/legacy/statement_list.rb +262 -0
  93. data/lib/yard/parser/{token_list.rb → ruby/legacy/token_list.rb} +1 -1
  94. data/lib/yard/parser/ruby/ruby_parser.rb +307 -0
  95. data/lib/yard/parser/source_parser.rb +76 -45
  96. data/lib/yard/rake/yardoc_task.rb +6 -1
  97. data/lib/yard/registry.rb +45 -19
  98. data/lib/yard/serializers/file_system_serializer.rb +8 -3
  99. data/lib/yard/tags/default_factory.rb +70 -10
  100. data/lib/yard/tags/default_tag.rb +12 -0
  101. data/lib/yard/tags/library.rb +65 -26
  102. data/lib/yard/tags/option_tag.rb +12 -0
  103. data/lib/yard/tags/overload_tag.rb +62 -0
  104. data/lib/yard/tags/ref_tag.rb +7 -0
  105. data/lib/yard/tags/ref_tag_list.rb +27 -0
  106. data/lib/yard/tags/tag.rb +1 -0
  107. data/lib/yard/tags/tag_format_error.rb +6 -0
  108. data/spec/cli/yardoc_spec.rb +43 -0
  109. data/spec/code_objects/base_spec.rb +56 -68
  110. data/spec/code_objects/class_object_spec.rb +18 -6
  111. data/spec/code_objects/constants_spec.rb +2 -0
  112. data/spec/code_objects/method_object_spec.rb +33 -5
  113. data/spec/code_objects/module_object_spec.rb +66 -8
  114. data/spec/code_objects/namespace_object_spec.rb +37 -17
  115. data/spec/code_objects/proxy_spec.rb +13 -2
  116. data/spec/core_ext/string_spec.rb +14 -2
  117. data/spec/core_ext/symbol_hash_spec.rb +9 -3
  118. data/spec/docstring_spec.rb +139 -0
  119. data/spec/generators/full_doc_generator_spec.rb +29 -0
  120. data/spec/generators/helpers/html_helper_spec.rb +74 -0
  121. data/spec/generators/helpers/markup_helper_spec.rb +95 -0
  122. data/spec/handlers/alias_handler_spec.rb +16 -3
  123. data/spec/handlers/attribute_handler_spec.rb +1 -1
  124. data/spec/handlers/base_spec.rb +15 -141
  125. data/spec/handlers/class_condition_handler_spec.rb +49 -0
  126. data/spec/handlers/class_handler_spec.rb +44 -3
  127. data/spec/handlers/class_variable_handler_spec.rb +1 -1
  128. data/spec/handlers/constant_handler_spec.rb +1 -1
  129. data/spec/handlers/examples/alias_handler_001.rb.txt +7 -3
  130. data/spec/handlers/examples/class_condition_handler_001.rb.txt +61 -0
  131. data/spec/handlers/examples/class_handler_001.rb.txt +33 -0
  132. data/spec/handlers/examples/exception_handler_001.rb.txt +1 -1
  133. data/spec/handlers/examples/extend_handler_001.rb.txt +8 -0
  134. data/spec/handlers/examples/method_condition_handler_001.rb.txt +10 -0
  135. data/spec/handlers/examples/method_handler_001.rb.txt +16 -4
  136. data/spec/handlers/examples/mixin_handler_001.rb.txt +10 -2
  137. data/spec/handlers/examples/module_handler_001.rb.txt +4 -0
  138. data/spec/handlers/examples/visibility_handler_001.rb.txt +1 -1
  139. data/spec/handlers/exception_handler_spec.rb +2 -2
  140. data/spec/handlers/extend_handler_spec.rb +15 -0
  141. data/spec/handlers/legacy_base_spec.rb +128 -0
  142. data/spec/handlers/method_condition_handler_spec.rb +14 -0
  143. data/spec/handlers/method_handler_spec.rb +38 -5
  144. data/spec/handlers/mixin_handler_spec.rb +15 -7
  145. data/spec/handlers/module_handler_spec.rb +5 -1
  146. data/spec/handlers/processor_spec.rb +19 -0
  147. data/spec/handlers/ruby/base_spec.rb +90 -0
  148. data/spec/handlers/ruby/legacy/base_spec.rb +53 -0
  149. data/spec/handlers/spec_helper.rb +22 -16
  150. data/spec/handlers/visibility_handler_spec.rb +4 -4
  151. data/spec/handlers/yield_handler_spec.rb +1 -1
  152. data/spec/parser/ruby/ast_node_spec.rb +15 -0
  153. data/spec/parser/ruby/legacy/statement_list_spec.rb +145 -0
  154. data/spec/parser/{token_list_spec.rb → ruby/legacy/token_list_spec.rb} +4 -4
  155. data/spec/parser/source_parser_spec.rb +0 -15
  156. data/spec/rake/yardoc_task_spec.rb +48 -0
  157. data/spec/registry_spec.rb +28 -2
  158. data/spec/serializers/file_system_serializer_spec.rb +7 -1
  159. data/spec/spec_helper.rb +1 -1
  160. data/spec/tags/default_factory_spec.rb +135 -0
  161. data/spec/tags/default_tag_spec.rb +11 -0
  162. data/spec/tags/overload_tag_spec.rb +35 -0
  163. data/spec/tags/ref_tag_list_spec.rb +53 -0
  164. data/templates/default/attributes/html/header.erb +17 -5
  165. data/templates/default/attributes/text/header.erb +1 -1
  166. data/templates/default/fulldoc/html/all_files.erb +19 -0
  167. data/templates/default/fulldoc/html/all_methods.erb +8 -7
  168. data/templates/default/fulldoc/html/all_namespaces.erb +4 -1
  169. data/templates/default/fulldoc/html/app.js +1 -1
  170. data/templates/default/fulldoc/html/{readme.erb → file.erb} +2 -2
  171. data/templates/default/fulldoc/html/header.erb +1 -1
  172. data/templates/default/fulldoc/html/index.erb +4 -3
  173. data/templates/default/fulldoc/html/style.css +13 -3
  174. data/templates/default/fulldoc/html/syntax_highlight.css +8 -5
  175. data/templates/default/method/text/header.erb +1 -0
  176. data/templates/default/method/text/title.erb +1 -0
  177. data/templates/default/methodsignature/html/main.erb +10 -8
  178. data/templates/default/methodsignature/text/main.erb +4 -1
  179. data/templates/default/methodsummary/html/summary.erb +8 -4
  180. data/templates/default/methodsummary/text/summary.erb +4 -1
  181. data/templates/default/mixins/html/header.erb +3 -3
  182. data/templates/default/overloads/html/header.erb +8 -0
  183. data/templates/default/overloads/text/header.erb +8 -0
  184. data/templates/default/root/html/header.erb +4 -0
  185. data/templates/default/tags/html/example.erb +20 -0
  186. data/templates/default/tags/html/option.erb +27 -0
  187. data/templates/default/tags/html/param.erb +21 -0
  188. data/templates/default/tags/html/tags.erb +4 -1
  189. data/templates/default/tags/html/todo.erb +8 -0
  190. data/templates/default/tags/text/example.erb +14 -0
  191. data/templates/default/tags/text/header.erb +3 -3
  192. data/templates/default/tags/text/option.erb +5 -0
  193. data/templates/default/tags/text/param.erb +9 -0
  194. data/templates/default/uml/dot/dependencies.erb +1 -1
  195. data/templates/default/uml/dot/info.erb +1 -1
  196. data/templates/default/uml/dot/superclasses.erb +2 -2
  197. data/templates/javadoc/methodsummary/html/summary.erb +2 -2
  198. data/templates/javadoc/mixins/html/header.erb +3 -3
  199. metadata +108 -139
  200. data/README +0 -211
  201. data/lib/yard/handlers/method_handler.rb +0 -27
  202. data/lib/yard/handlers/mixin_handler.rb +0 -16
  203. data/lib/yard/parser/statement_list.rb +0 -167
  204. data/lib/yard/tags/merbdoc_factory.rb +0 -47
data/README DELETED
@@ -1,211 +0,0 @@
1
- = YARD Release 0.2.2 (June 16th 2008)
2
- Copyright 2007-2008 Loren Segal
3
-
4
- == SYNOPSIS
5
-
6
- YARD is a documentation generation tool for the Ruby programming language
7
- (http://www.ruby-lang.org). It enables the user to generate consistent, usable
8
- documentation that can be exported to a number of formats very easily, and
9
- also supports extending for custom Ruby constructs such as custom class level
10
- definitions. Below is a summary of some of YARD's notable features.
11
-
12
-
13
- == FEATURE LIST
14
-
15
- 1. <b>RDoc/SimpleMarkup Formatting Compatibility</b>: YARD is made to be compatible
16
- with RDoc formatting. In fact, YARD does no processing on RDoc documentation
17
- strings, and leaves this up to the output generation tool to decide how to
18
- render the documentation.
19
-
20
- 2. <b>Yardoc Meta-tag Formatting Like Python, Java, Objective-C and other
21
- languages</b>: YARD uses a '@tag' style definition syntax for meta tags alongside
22
- regular code documentation. These tags should be able to happily sit side by
23
- side RDoc formatted documentation, but provide a much more consistent and
24
- usable way to describe important information about objects, such as what
25
- parameters they take and what types they are expected to be, what type a
26
- method should return, what exceptions it can raise, if it is deprecated, etc..
27
- It also allows information to be better (and more consistently) organized
28
- during the output generation phase. Some of the main tags are listed below:
29
-
30
- <b>Table 1. Meta-tags and their descriptions</b>
31
-
32
- <tt>@param [Types] name description</tt>::
33
- Description Allows for the definition of a method parameter with
34
- optional type information.
35
-
36
- <tt>@yieldparam [Types] name description</tt>::
37
- Description Allows for the definition of a method parameter to a
38
- yield block with optional type information.
39
-
40
- <tt>@yield description</tt>::
41
- Allows the developer to document the purpose of a yield block in
42
- a method.
43
-
44
- @return [Types] description</tt>::
45
- Describes what the method returns with optional type information.
46
-
47
- <tt>@deprecated description</tt>::
48
- Informs the developer that a method is deprecated and should no
49
- longer be used. The description offers the developer an alternative
50
- solution or method for the problem.
51
-
52
- <tt>@raise class description</tt>::
53
- Tells the developer that the method may raise an exception and of
54
- what type.
55
-
56
- <tt>@see name</tt>::
57
- References another object, URL, or other for extra information.
58
-
59
- <tt>@since number</tt>::
60
- Lists the version number in which the object first appeared.
61
-
62
- <tt>@version number</tt>::
63
- Lists the current version of the documentation for the object.
64
-
65
- <tt>@author name</tt>::
66
- The authors responsible for the module
67
-
68
- You might have noticed the optional "types" declarations for certain tags.
69
- This allows the developer to document type signatures for ruby methods and
70
- parameters in a non intrusive but helpful and consistent manner. Instead of
71
- describing this data in the body of the description, a developer may formally
72
- declare the parameter or return type(s) in a single line. Consider the
73
- following Yardoc'd method:
74
-
75
- ##
76
- # Reverses the contents of a String or IO object.
77
- #
78
- # @param [String, #read] contents the contents to reverse
79
- # @return [String] the contents reversed lexically
80
- def reverse(contents)
81
- contents = contents.read if respond_to? :read
82
- contents.reverse
83
- end
84
-
85
- With the above @param tag, we learn that the contents parameter can either be
86
- a String or any object that responds to the 'read' method, which is more
87
- powerful than the textual description, which says it should be an IO object.
88
- This also informs the developer that they should expect to receive a String
89
- object returned by the method, and although this may be obvious for a
90
- 'reverse' method, it becomes very useful when the method name may not be as
91
- descriptive.
92
-
93
- 3. <b>Custom Constructs and Extensibility of YARD</b>: Take for instance the example:
94
-
95
- class A
96
- class << self
97
- def define_name(name, value)
98
- class_eval "def #{name}; #{value.inspect} end"
99
- end
100
- end
101
-
102
- # Documentation string for this name
103
- define_name :publisher, "O'Reilly"
104
- end
105
-
106
- This custom declaration provides dynamically generated code that is hard for a
107
- documentation tool to properly document without help from the developer. To
108
- ease the pains of manually documenting the procedure, YARD can be extended by
109
- the developer to handled the 'define_name' construct and add the required
110
- method to the defined methods of the class with its documentation. This makes
111
- documenting external API's, especially dynamic ones, a lot more consistent for
112
- consumption by the users.
113
-
114
- 4. <b>Raw Data Output</b>: YARD also outputs documented objects as raw data (the
115
- dumped Namespace) which can be reloaded to do generation at a later date, or
116
- even auditing on code. This means that any developer can use the raw data to
117
- perform output generation for any custom format, such as YAML, for instance.
118
- While YARD plans to support XHTML style documentation output as well as
119
- command line (text based) and possibly XML, this may still be useful for those
120
- who would like to reap the benefits of YARD's processing in other forms, such
121
- as throwing all the documentation into a database. Another useful way of
122
- exploiting this raw data format would be to write tools that can auto generate
123
- test cases, for example, or show possible unhandled exceptions in code.
124
-
125
-
126
- == USAGE
127
-
128
- There are a couple of ways to use YARD. The first is via command-line, and the
129
- second is the Rake task. There are also the +yard-graph+ and +yri+ binaries to
130
- look at, if you want to poke around.
131
-
132
- === 1. yardoc Command-line Tool
133
-
134
- The most obvious way to run YARD is to run the +yardoc+ binary file that comes
135
- with YARD. This will, among other things, generate the HTML documentation for
136
- your project code. You can type <tt>yardoc --help</tt> to see the options
137
- that YARD provides, but the easiest way to generate docs for your code is to
138
- simply type +yardoc+ in your project root. This will assume your files are
139
- located in the +lib/+ directory. If they are located elsewhere, you can specify
140
- paths and globs from the commandline via:
141
-
142
- yardoc 'lib/**/*.rb' 'app/**/*.rb' ...etc...
143
-
144
- The tool will generate a +.yardoc+ file which will store the cached database
145
- of your source code and documentation. If you want to re-generate your docs
146
- with another template you can simply use the <tt>--use-cache</tt> (or -c)
147
- option to speed up the generation process by skipping source parsing.
148
-
149
- YARD will by default only document code in your public visibility. You can
150
- document your protected and private code by adding <tt>--protected</tt> or
151
- <tt>--private</tt> to the option switches.
152
-
153
- === 2. Rake Task
154
-
155
- The second most obvious is to generate docs via a Rake task. You can do this by
156
- adding the following to your +Rakefile+:
157
-
158
- YARD::Rake::YardocTask.new do |t|
159
- t.files = ['lib/**/*.rb', OTHER_PATHS] # optional
160
- t.options = ['--any', '--extra', '--opts'] # optional
161
- end
162
-
163
- both the +files+ and +options+ settings are optional. +files+ will default to
164
- <tt>lib/**/*.rb</tt> and +options+ will represents any options you might want
165
- to add. Again, a full list of options is available by typing <tt>yardoc --help</tt>
166
- in a shell. You can also override the options at the Rake command-line with the
167
- OPTS environment variable:
168
-
169
- > rake yardoc OPTS='--any --extra --opts'
170
-
171
- === 3. yri RI Implementation
172
-
173
- The yri binary will use the cached .yardoc database to give you quick ri-style
174
- access to your documentation. It's way faster than ri but currently does not
175
- work with the stdlib or core Ruby libraries, only the active project. Example:
176
-
177
- > yri YARD::Handlers::Base#register
178
- > yri File::relative_path
179
-
180
- === 4. yard-graph Graphviz Generator
181
-
182
- You can use +yard-graph+ to generate dot graphs of your code. This, of course,
183
- requires Graphviz (http://www.graphviz.org) and the +dot+ binary. By default
184
- this will generate a graph of the classes and modules in the best UML2 notation
185
- that Graphviz can support, but without any methods listed. With the <tt>--full</tt>
186
- option, methods and attributes will be listed. There is also a <tt>--dependencies</tt>
187
- option to show mixin inclusions. You can output to stdout or a file, or pipe directly
188
- to +dot+. The same public, protected and private visibility rules apply to yard-graph.
189
- More options can be seen by typing <tt>yard-graph --help</tt>, but here is an example:
190
-
191
- > yard-graph --protected --full --dependencies
192
-
193
-
194
- == CHANGELOG
195
-
196
- - <b>Jun.16.08</b>: 0.2.2 release. This is the largest changset since yard's
197
- conception and involves a complete overhaul of the parser and API to make it
198
- more robust and far easier to extend and use for the developer.
199
-
200
- - <b>Feb.20.08</b>: 0.2.1 release.
201
-
202
- - <b>Feb.24.07</b>: Released 0.1a experimental version for testing. The goal here is
203
- to get people testing YARD on their code because there are too many possible
204
- code styles to fit into a sane amount of test cases. It also demonstrates the
205
- power of YARD and what to expect from the syntax (Yardoc style meta tags).
206
-
207
-
208
- == COPYRIGHT
209
-
210
- YARD was created in 2007-2008 by Loren Segal (lsegal -AT- soen -DOT- ca) and is
211
- licensed under the MIT license. Please see the LICENSE.txt for more information.
@@ -1,27 +0,0 @@
1
- class YARD::Handlers::MethodHandler < YARD::Handlers::Base
2
- handles TkDEF
3
-
4
- def process
5
- nobj = namespace
6
- mscope = scope
7
-
8
- if meth = statement.tokens.to_s[/^def\s+(#{METHODMATCH})/m, 1]
9
- meth.gsub!(/\s+/,'')
10
- else
11
- raise YARD::Handlers::UndocumentableError, "method: invalid name"
12
- end
13
-
14
- # Class method if prefixed by self(::|.) or Module(::|.)
15
- if meth =~ /(?:#{NSEP}|\.)([^#{NSEP}\.]+)$/
16
- mscope, meth = :class, $1
17
- nobj = P(namespace, $`) unless $` == "self"
18
- end
19
-
20
- obj = register MethodObject.new(nobj, meth, mscope) do |o|
21
- o.visibility = visibility
22
- o.source = statement
23
- o.explicit = true
24
- end
25
- parse_block(:owner => obj) # mainly for yield/exceptions
26
- end
27
- end
@@ -1,16 +0,0 @@
1
- class YARD::Handlers::MixinHandler < YARD::Handlers::Base
2
- handles /\Ainclude(\s|\()/
3
-
4
- def process
5
- statement.tokens[1..-1].to_s.split(/\s*,\s*/).each do |mixin|
6
- mixin.strip!
7
- if mixmatch = mixin[/\A(#{NAMESPACEMATCH})\s*/, 1]
8
- obj = Proxy.new(namespace, mixmatch)
9
- obj.type = :module if obj.is_a?(Proxy)
10
- namespace.mixins << obj
11
- else
12
- raise YARD::Handlers::UndocumentableError, "mixin #{mixin} for class #{namespace.path}"
13
- end
14
- end
15
- end
16
- end
@@ -1,167 +0,0 @@
1
- module YARD
2
- module Parser
3
- class StatementList < Array
4
- include RubyToken
5
-
6
- # The following list of tokens will require a block to be opened
7
- # if used at the beginning of a statement.
8
- OPEN_BLOCK_TOKENS = [TkCLASS, TkDEF, TkMODULE, TkUNTIL,
9
- TkIF, TkUNLESS, TkWHILE, TkFOR, TkCASE]
10
- COLON_TOKENS = [TkUNTIL, TkIF, TkUNLESS, TkWHILE, TkCASE, TkWHEN]
11
-
12
- ##
13
- # Creates a new statement list
14
- #
15
- # @param [TokenList, String] content the tokens to create the list from
16
- def initialize(content)
17
- if content.is_a? TokenList
18
- @tokens = content.dup
19
- elsif content.is_a? String
20
- @tokens = TokenList.new(content)
21
- else
22
- raise ArgumentError, "Invalid content for StatementList: #{content.inspect}:#{content.class}"
23
- end
24
-
25
- parse_statements
26
- end
27
-
28
- private
29
-
30
- def parse_statements
31
- while stmt = next_statement do self << stmt end
32
- end
33
-
34
- # MUST REFACTOR THIS CODE
35
- # WARNING WARNING WARNING WARNING
36
- # MUST REFACTOR THIS CODE |
37
- # OR CHILDREN WILL DIE V
38
- # WARNING WARNING WARNING WARNING
39
- # THIS IS MEANT TO BE UGLY.
40
- def next_statement
41
- statement, block, comments = TokenList.new, nil, nil
42
- stmt_number, level = 0, 0
43
- new_statement, open_block = true, false
44
- last_tk, last_ns_tk, before_last_tk = nil, nil, nil
45
- open_parens = 0
46
-
47
- while tk = @tokens.shift
48
- #p tk.class
49
- # !!!!!!!!!!!!!!!!!!!! REMOVED TkfLPAREN, TkfLBRACK
50
- open_parens += 1 if [TkLPAREN, TkLBRACK].include? tk.class
51
- open_parens -= 1 if [TkRPAREN, TkRBRACK].include?(tk.class)
52
-
53
- #if open_parens < 0 || level < 0
54
- # STDERR.puts block.to_s + " TOKEN #{tk.inspect}"
55
- # exit
56
- #end
57
-
58
- # Get the initial comments
59
- if statement.empty?
60
- # Two new-lines in a row will destroy any comment blocks
61
- if [TkCOMMENT].include?(tk.class) && last_tk.class == TkNL &&
62
- (before_last_tk && (before_last_tk.class == TkNL || before_last_tk.class == TkSPACE))
63
- comments = nil
64
- elsif tk.class == TkCOMMENT
65
- # Remove the "#" and up to 1 space before the text
66
- # Since, of course, the convention is to have "# text"
67
- # and not "#text", which I deem ugly (you heard it here first)
68
- comments ||= []
69
- comments << tk.text.gsub(/^#+\s{0,1}/, '')
70
- comments.pop if comments.size == 1 && comments.first =~ /^\s*$/
71
- end
72
- end
73
-
74
- # Ignore any initial comments or whitespace
75
- unless statement.empty? && [TkSPACE, TkNL, TkCOMMENT].include?(tk.class)
76
- # Decrease if end or '}' is seen
77
- level -= 1 if [TkEND, TkRBRACE].include?(tk.class)
78
-
79
- # If the level is greater than 0, add the code to the block text
80
- # otherwise it's part of the statement text
81
- if stmt_number > 0
82
- #puts "Block of #{statement}"
83
- #puts "#{stmt_number} #{tk.line_no} #{level} #{open_parens} #{tk.class.class_name} \t#{tk.text.inspect} #{tk.lex_state} #{open_block.inspect}"
84
- block ||= TokenList.new
85
- block << tk
86
- elsif stmt_number == 0 && tk.class != TkNL && tk.class != TkSEMICOLON && tk.class != TkCOMMENT
87
- statement << tk
88
- end
89
-
90
- #puts "#{tk.line_no} #{level} #{open_parens} #{tk.class.class_name} \t#{tk.text.inspect} #{tk.lex_state} #{open_block.inspect}"
91
-
92
- # Increase level if we have a 'do' or block opening
93
- if tk.class == TkLBRACE #|| tk.class == TkfLBRACE
94
- level += 1
95
- elsif [TkDO, TkBEGIN].include?(tk.class)
96
- #p "#{tk.line_no} #{level} #{tk} \t#{tk.text} #{tk.lex_state}"
97
- level += 1
98
- open_block = false # Cancel our wish to open a block for the if, we're doing it now
99
- end
100
-
101
- # Vouch to open a block when this statement would otherwise end
102
- open_block = [level, tk.class] if (new_statement ||
103
- (last_tk && last_tk.lex_state == EXPR_BEG)) &&
104
- OPEN_BLOCK_TOKENS.include?(tk.class)
105
-
106
- # Check if this token creates a new statement or not
107
- #puts "#{open_parens} open brackets for: #{statement.to_s}"
108
- if open_parens == 0 && ((last_tk && [TkSEMICOLON, TkNL, TkEND_OF_SCRIPT].include?(tk.class)) ||
109
- (open_block && open_block.last == TkDEF && tk.class == TkRPAREN))
110
-
111
- # Make sure we don't have any running expressions
112
- # This includes things like
113
- #
114
- # class <
115
- # Foo
116
- #
117
- # if a ||
118
- # b
119
- if (last_tk && [EXPR_END, EXPR_ARG].include?(last_tk.lex_state)) ||
120
- (open_block && [TkNL, TkSEMICOLON].include?(tk.class) && last_ns_tk.class != open_block.last)
121
- stmt_number += 1
122
- new_statement = true
123
- #p "NEW STATEMENT #{block.to_s}"
124
-
125
- # The statement started with a if/while/begin, so we must go to the next level now
126
- if open_block && open_block.first == level
127
- if tk.class == TkNL && block.nil?
128
- block = TokenList.new
129
- block << tk
130
- end
131
-
132
- open_block = false
133
- level += 1
134
- end
135
- end
136
- elsif tk.class != TkSPACE
137
- new_statement = false
138
- end
139
-
140
- # Else keyword is kind of weird
141
- if tk.is_a? TkELSE
142
- new_statement = true
143
- stmt_number += 1
144
- open_block = false
145
- end
146
-
147
- # We're done if we've ended a statement and we're at level 0
148
- break if new_statement && level == 0
149
-
150
- #raise "Unexpected end" if level < 0
151
- end
152
-
153
- #break if new_statement && level == 0
154
-
155
- before_last_tk = last_tk
156
- last_tk = tk # Save last token
157
- last_ns_tk = tk unless [TkSPACE, TkNL, TkEND_OF_SCRIPT].include? tk.class
158
- end
159
-
160
- # Return the code block with starting token and initial comments
161
- # If there is no code in the block, return nil
162
- comments = comments.compact if comments
163
- statement.empty? ? nil : Statement.new(statement, block, comments)
164
- end
165
- end
166
- end
167
- end
@@ -1,47 +0,0 @@
1
- module YARD
2
- module Tags
3
- class MerbdocFactory < DefaultFactory
4
- ##
5
- # Parses tag text and creates a new tag with formally declared types and
6
- # descriptive text
7
- #
8
- # @param tag_name the name of the tag to parse
9
- # @param text<String> the raw tag text
10
- # @return <Tag> a tag object with the tag_name, types and text values filled
11
- def parse_tag_with_types(tag_name, text)
12
- _, types, text = *extract_types_from_text(text)
13
- # TODO warn if name value ('_') is not nil, because that's invalid syntax
14
- Tag.new(tag_name, text, types)
15
- end
16
-
17
- ##
18
- # Parses tag text and creates a new tag with formally declared types, a key
19
- # name and descriptive text
20
- #
21
- # @param tag_name the name of the tag to parse
22
- # @param text<String> the raw tag text
23
- # @return <Tag> a tag object with the tag_name, name, types and text values filled
24
- def parse_tag_with_types_and_name(tag_name, text)
25
- name, types, text = *extract_types_from_text(text)
26
- name, text = *extract_name_from_text(text) if name.nil?
27
- Tag.new(tag_name, text, types, name)
28
- end
29
-
30
- private
31
-
32
- ##
33
- # Extracts the type signatures with an optional name from the raw tag text
34
- #
35
- # @param text<String> the raw tag text
36
- # @return <Array> an array holding the name as the first element (nil if empty),
37
- # array of types as the second element and the raw text as the last.
38
- def extract_types_from_text(text)
39
- name, types, text = nil, [], text.strip
40
- if text =~ /^\s*(\S*)\s*<(.+?)>\s*(.*)/
41
- name, text, types = $1, $3, $2.split(",").collect {|e| e.strip }
42
- end
43
- [name, types, text]
44
- end
45
- end
46
- end
47
- end