yard 0.6.8 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of yard might be problematic. Click here for more details.
- data/.yardopts +1 -0
- data/ChangeLog +723 -0
- data/README.md +16 -6
- data/docs/CodeObjects.md +10 -16
- data/docs/GettingStarted.md +232 -32
- data/docs/Glossary.md +1 -2
- data/docs/Handlers.md +10 -16
- data/docs/Overview.md +14 -13
- data/docs/Parser.md +13 -22
- data/docs/Tags.md +209 -16
- data/docs/Templates.md +237 -26
- data/docs/WhatsNew.md +178 -2
- data/lib/yard.rb +13 -10
- data/lib/yard/autoload.rb +22 -18
- data/lib/yard/cli/command.rb +13 -12
- data/lib/yard/cli/command_parser.rb +20 -19
- data/lib/yard/cli/config.rb +19 -19
- data/lib/yard/cli/diff.rb +46 -21
- data/lib/yard/cli/gems.rb +11 -11
- data/lib/yard/cli/graph.rb +13 -13
- data/lib/yard/cli/help.rb +1 -1
- data/lib/yard/cli/list.rb +22 -0
- data/lib/yard/cli/server.rb +17 -17
- data/lib/yard/cli/stats.rb +32 -32
- data/lib/yard/cli/yardoc.rb +181 -135
- data/lib/yard/cli/yri.rb +29 -29
- data/lib/yard/code_objects/base.rb +101 -101
- data/lib/yard/code_objects/class_object.rb +20 -20
- data/lib/yard/code_objects/constant_object.rb +1 -1
- data/lib/yard/code_objects/extended_method_object.rb +5 -5
- data/lib/yard/code_objects/extra_file_object.rb +89 -0
- data/lib/yard/code_objects/macro_object.rb +215 -0
- data/lib/yard/code_objects/method_object.rb +30 -30
- data/lib/yard/code_objects/module_object.rb +1 -1
- data/lib/yard/code_objects/namespace_object.rb +39 -39
- data/lib/yard/code_objects/proxy.rb +38 -38
- data/lib/yard/code_objects/root_object.rb +1 -1
- data/lib/yard/config.rb +40 -40
- data/lib/yard/core_ext/array.rb +2 -2
- data/lib/yard/core_ext/file.rb +11 -11
- data/lib/yard/core_ext/insertion.rb +10 -10
- data/lib/yard/core_ext/module.rb +2 -2
- data/lib/yard/core_ext/string.rb +2 -2
- data/lib/yard/core_ext/symbol_hash.rb +14 -14
- data/lib/yard/docstring.rb +122 -54
- data/lib/yard/globals.rb +2 -2
- data/lib/yard/handlers/base.rb +216 -127
- data/lib/yard/handlers/processor.rb +65 -27
- data/lib/yard/handlers/ruby/alias_handler.rb +6 -3
- data/lib/yard/handlers/ruby/attribute_handler.rb +7 -6
- data/lib/yard/handlers/ruby/base.rb +50 -31
- data/lib/yard/handlers/ruby/class_condition_handler.rb +11 -11
- data/lib/yard/handlers/ruby/class_handler.rb +10 -10
- data/lib/yard/handlers/ruby/class_variable_handler.rb +3 -3
- data/lib/yard/handlers/ruby/constant_handler.rb +7 -7
- data/lib/yard/handlers/ruby/exception_handler.rb +2 -2
- data/lib/yard/handlers/ruby/extend_handler.rb +1 -1
- data/lib/yard/handlers/ruby/legacy/alias_handler.rb +8 -5
- data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +6 -5
- data/lib/yard/handlers/ruby/legacy/base.rb +42 -27
- data/lib/yard/handlers/ruby/legacy/class_condition_handler.rb +9 -9
- data/lib/yard/handlers/ruby/legacy/class_handler.rb +13 -12
- data/lib/yard/handlers/ruby/legacy/class_variable_handler.rb +3 -6
- data/lib/yard/handlers/ruby/legacy/constant_handler.rb +5 -8
- data/lib/yard/handlers/ruby/legacy/exception_handler.rb +1 -1
- data/lib/yard/handlers/ruby/legacy/extend_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/macro_handler.rb +40 -0
- data/lib/yard/handlers/ruby/legacy/method_handler.rb +10 -10
- data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +4 -3
- data/lib/yard/handlers/ruby/legacy/module_handler.rb +2 -1
- data/lib/yard/handlers/ruby/legacy/private_constant_handler.rb +4 -4
- data/lib/yard/handlers/ruby/legacy/visibility_handler.rb +2 -1
- data/lib/yard/handlers/ruby/legacy/yield_handler.rb +3 -3
- data/lib/yard/handlers/ruby/macro_handler.rb +41 -0
- data/lib/yard/handlers/ruby/macro_handler_methods.rb +130 -0
- data/lib/yard/handlers/ruby/method_condition_handler.rb +1 -1
- data/lib/yard/handlers/ruby/method_handler.rb +13 -13
- data/lib/yard/handlers/ruby/mixin_handler.rb +4 -4
- data/lib/yard/handlers/ruby/module_handler.rb +2 -1
- data/lib/yard/handlers/ruby/private_constant_handler.rb +4 -4
- data/lib/yard/handlers/ruby/struct_handler_methods.rb +11 -11
- data/lib/yard/handlers/ruby/visibility_handler.rb +1 -1
- data/lib/yard/handlers/ruby/yield_handler.rb +5 -5
- data/lib/yard/logging.rb +11 -11
- data/lib/yard/parser/base.rb +8 -8
- data/lib/yard/parser/c_parser.rb +42 -33
- data/lib/yard/parser/ruby/ast_node.rb +62 -61
- data/lib/yard/parser/ruby/legacy/ruby_lex.rb +66 -66
- data/lib/yard/parser/ruby/legacy/ruby_parser.rb +4 -4
- data/lib/yard/parser/ruby/legacy/statement.rb +11 -11
- data/lib/yard/parser/ruby/legacy/statement_list.rb +15 -15
- data/lib/yard/parser/ruby/legacy/token_list.rb +9 -9
- data/lib/yard/parser/ruby/ruby_parser.rb +51 -37
- data/lib/yard/parser/source_parser.rb +271 -46
- data/lib/yard/rake/yardoc_task.rb +18 -17
- data/lib/yard/registry.rb +64 -64
- data/lib/yard/registry_store.rb +34 -34
- data/lib/yard/rubygems/backports.rb +8 -0
- data/lib/yard/rubygems/backports/LICENSE.txt +57 -0
- data/lib/yard/rubygems/backports/MIT.txt +20 -0
- data/lib/yard/rubygems/backports/gem.rb +8 -0
- data/lib/yard/rubygems/backports/source_index.rb +353 -0
- data/lib/yard/rubygems/specification.rb +2 -2
- data/lib/yard/serializers/base.rb +20 -20
- data/lib/yard/serializers/file_system_serializer.rb +28 -24
- data/lib/yard/serializers/process_serializer.rb +3 -3
- data/lib/yard/serializers/stdout_serializer.rb +6 -6
- data/lib/yard/serializers/yardoc_serializer.rb +17 -17
- data/lib/yard/server/adapter.rb +12 -12
- data/lib/yard/server/commands/base.rb +26 -26
- data/lib/yard/server/commands/display_file_command.rb +3 -2
- data/lib/yard/server/commands/display_object_command.rb +5 -5
- data/lib/yard/server/commands/frames_command.rb +1 -1
- data/lib/yard/server/commands/library_command.rb +7 -7
- data/lib/yard/server/commands/library_index_command.rb +2 -2
- data/lib/yard/server/commands/list_command.rb +8 -8
- data/lib/yard/server/commands/search_command.rb +8 -8
- data/lib/yard/server/commands/static_file_command.rb +3 -3
- data/lib/yard/server/doc_server_helper.rb +6 -3
- data/lib/yard/server/doc_server_serializer.rb +1 -1
- data/lib/yard/server/library_version.rb +45 -45
- data/lib/yard/server/rack_adapter.rb +10 -10
- data/lib/yard/server/router.rb +28 -28
- data/lib/yard/server/static_caching.rb +5 -5
- data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +3 -3
- data/lib/yard/server/templates/default/fulldoc/html/js/live.js +1 -1
- data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +2 -2
- data/lib/yard/server/templates/default/layout/html/headers.erb +13 -8
- data/lib/yard/server/templates/default/layout/html/setup.rb +7 -0
- data/lib/yard/server/templates/doc_server/full_list/html/full_list.erb +2 -2
- data/lib/yard/server/templates/doc_server/full_list/html/setup.rb +14 -4
- data/lib/yard/server/templates/doc_server/library_list/html/contents.erb +2 -2
- data/lib/yard/server/templates/doc_server/library_list/html/headers.erb +2 -2
- data/lib/yard/server/templates/doc_server/processing/html/processing.erb +1 -1
- data/lib/yard/server/templates/doc_server/search/html/search.erb +1 -1
- data/lib/yard/server/webrick_adapter.rb +2 -2
- data/lib/yard/tags/default_factory.rb +19 -19
- data/lib/yard/tags/default_tag.rb +1 -1
- data/lib/yard/tags/library.rb +68 -63
- data/lib/yard/tags/option_tag.rb +1 -1
- data/lib/yard/tags/overload_tag.rb +9 -9
- data/lib/yard/tags/ref_tag_list.rb +2 -2
- data/lib/yard/tags/tag.rb +7 -7
- data/lib/yard/templates/engine.rb +31 -31
- data/lib/yard/templates/erb_cache.rb +1 -1
- data/lib/yard/templates/helpers/base_helper.rb +46 -32
- data/lib/yard/templates/helpers/filter_helper.rb +2 -2
- data/lib/yard/templates/helpers/html_helper.rb +120 -81
- data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +4 -4
- data/lib/yard/templates/helpers/markup/rdoc_markup.rb +9 -9
- data/lib/yard/templates/helpers/markup_helper.rb +37 -30
- data/lib/yard/templates/helpers/method_helper.rb +7 -7
- data/lib/yard/templates/helpers/text_helper.rb +7 -7
- data/lib/yard/templates/helpers/uml_helper.rb +3 -3
- data/lib/yard/templates/section.rb +14 -14
- data/lib/yard/templates/template.rb +54 -54
- data/lib/yard/verifier.rb +27 -27
- data/spec/cli/list_spec.rb +8 -0
- data/spec/cli/yardoc_spec.rb +58 -10
- data/spec/code_objects/extra_file_object_spec.rb +132 -0
- data/spec/code_objects/macro_object_spec.rb +154 -0
- data/spec/docstring_spec.rb +90 -0
- data/spec/handlers/base_spec.rb +22 -0
- data/spec/handlers/examples/macro_handler_001.rb.txt +73 -0
- data/spec/handlers/examples/method_handler_001.rb.txt +17 -0
- data/spec/handlers/macro_handler_spec.rb +140 -0
- data/spec/handlers/method_handler_spec.rb +28 -0
- data/spec/handlers/processor_spec.rb +4 -0
- data/spec/handlers/spec_helper.rb +1 -1
- data/spec/parser/c_parser_spec.rb +47 -16
- data/spec/parser/examples/extrafile.c.txt +8 -0
- data/spec/parser/examples/multifile.c.txt +6 -0
- data/spec/parser/ruby/ruby_parser_spec.rb +5 -0
- data/spec/parser/source_parser_spec.rb +235 -0
- data/spec/rake/yardoc_task_spec.rb +22 -17
- data/spec/serializers/file_system_serializer_spec.rb +6 -0
- data/spec/server/commands/library_command_spec.rb +39 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/templates/examples/method001.html +6 -6
- data/spec/templates/examples/method002.html +4 -4
- data/spec/templates/examples/method003.html +10 -10
- data/spec/templates/examples/method005.html +2 -2
- data/spec/templates/examples/module001.dot +2 -0
- data/spec/templates/examples/module001.html +76 -37
- data/spec/templates/examples/module001.txt +1 -1
- data/spec/templates/helpers/base_helper_spec.rb +7 -2
- data/spec/templates/helpers/html_helper_spec.rb +49 -5
- data/spec/templates/helpers/markup_helper_spec.rb +9 -8
- data/spec/templates/module_spec.rb +7 -0
- data/spec/templates/onefile_spec.rb +47 -0
- data/templates/default/fulldoc/html/css/style.css +7 -5
- data/templates/default/fulldoc/html/full_list.erb +13 -10
- data/templates/default/fulldoc/html/full_list_files.erb +1 -1
- data/templates/default/fulldoc/html/js/app.js +16 -14
- data/templates/default/fulldoc/html/js/full_list.js +7 -6
- data/templates/default/fulldoc/html/setup.rb +78 -17
- data/templates/default/layout/html/files.erb +1 -1
- data/templates/default/layout/html/headers.erb +11 -7
- data/templates/default/layout/html/search.erb +4 -4
- data/templates/default/layout/html/setup.rb +28 -8
- data/templates/default/module/html/inherited_attributes.erb +17 -0
- data/templates/default/module/setup.rb +1 -1
- data/templates/default/onefile/html/files.erb +2 -2
- data/templates/default/onefile/html/layout.erb +1 -1
- data/templates/default/onefile/html/setup.rb +7 -5
- data/templates/default/tags/html/option.erb +1 -1
- data/templates/default/tags/html/tag.erb +3 -3
- data/templates/guide/class/html/setup.rb +1 -0
- data/templates/guide/docstring/html/setup.rb +1 -0
- data/templates/guide/fulldoc/html/css/style.css +91 -0
- data/templates/guide/fulldoc/html/js/app.js +33 -0
- data/templates/guide/fulldoc/html/setup.rb +54 -0
- data/templates/guide/layout/html/layout.erb +81 -0
- data/templates/guide/layout/html/setup.rb +24 -0
- data/templates/guide/method/html/header.erb +18 -0
- data/templates/guide/method/html/setup.rb +21 -0
- data/templates/guide/module/html/header.erb +7 -0
- data/templates/guide/module/html/method_list.erb +5 -0
- data/templates/guide/module/html/setup.rb +26 -0
- data/templates/guide/tags/html/setup.rb +8 -0
- metadata +40 -7
- data/lib/yard/handlers/ruby/legacy/process_handler.rb +0 -13
- data/lib/yard/handlers/ruby/process_handler.rb +0 -18
- data/spec/handlers/process_handler_spec.rb +0 -17
@@ -8,19 +8,19 @@ module YARD
|
|
8
8
|
def initialize(source, filename)
|
9
9
|
@source = source
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def parse
|
13
13
|
@parse ||= StatementList.new(@source)
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def tokenize
|
17
17
|
@tokenize ||= TokenList.new(@source)
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def enumerator
|
21
21
|
@parse
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def encoding_line; @parse.encoding_line end
|
25
25
|
def shebang_line; @parse.shebang_line end
|
26
26
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module YARD
|
2
2
|
module Parser::Ruby::Legacy
|
3
|
-
class Statement
|
3
|
+
class Statement
|
4
4
|
attr_reader :tokens, :comments, :block
|
5
5
|
attr_accessor :comments_range, :group
|
6
6
|
attr_accessor :comments_hash_flag
|
@@ -11,34 +11,34 @@ module YARD
|
|
11
11
|
@comments = comments
|
12
12
|
@comments_hash_flag = false
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def first_line
|
16
16
|
to_s.split(/\n/)[0]
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def to_s(include_block = true)
|
20
20
|
tokens.map do |token|
|
21
21
|
RubyToken::TkBlockContents === token ? (include_block ? block.to_s : '') : token.text
|
22
22
|
end.join
|
23
23
|
end
|
24
24
|
alias source to_s
|
25
|
-
|
25
|
+
|
26
26
|
def inspect
|
27
27
|
l = line - 1
|
28
28
|
to_s(false).split(/\n/).map do |text|
|
29
29
|
"\t#{l += 1}: #{text}"
|
30
30
|
end.join("\n")
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def show
|
34
34
|
"\t #{line}: #{first_line}"
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
# @return [Fixnum] the first line of Ruby source
|
38
38
|
def line
|
39
39
|
tokens.first.line_no
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
# @return [Range<Fixnum>] the first to last lines of Ruby source
|
43
43
|
# @since 0.5.4
|
44
44
|
def line_range
|
@@ -49,10 +49,10 @@ module YARD
|
|
49
49
|
|
50
50
|
def clean_tokens(tokens)
|
51
51
|
last_tk = nil
|
52
|
-
tokens.reject do |tk|
|
53
|
-
tk.is_a?(RubyToken::TkNL) ||
|
54
|
-
(last_tk.is_a?(RubyToken::TkSPACE) &&
|
55
|
-
last_tk.class == tk.class) && last_tk = tk
|
52
|
+
tokens.reject do |tk|
|
53
|
+
tk.is_a?(RubyToken::TkNL) ||
|
54
|
+
(last_tk.is_a?(RubyToken::TkSPACE) &&
|
55
|
+
last_tk.class == tk.class) && last_tk = tk
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
@@ -2,10 +2,10 @@ module YARD
|
|
2
2
|
module Parser::Ruby::Legacy
|
3
3
|
class StatementList < Array
|
4
4
|
include RubyToken
|
5
|
-
|
5
|
+
|
6
6
|
attr_accessor :shebang_line, :encoding_line
|
7
7
|
|
8
|
-
# The following list of tokens will require a block to be opened
|
8
|
+
# The following list of tokens will require a block to be opened
|
9
9
|
# if used at the beginning of a statement.
|
10
10
|
OPEN_BLOCK_TOKENS = [TkCLASS, TkDEF, TkMODULE, TkUNTIL,
|
11
11
|
TkIF, TkELSIF, TkUNLESS, TkWHILE, TkFOR, TkCASE]
|
@@ -21,13 +21,13 @@ module YARD
|
|
21
21
|
@tokens = content.dup
|
22
22
|
elsif content.is_a? String
|
23
23
|
@tokens = TokenList.new(content.gsub("\r", ""))
|
24
|
-
else
|
24
|
+
else
|
25
25
|
raise ArgumentError, "Invalid content for StatementList: #{content.inspect}:#{content.class}"
|
26
26
|
end
|
27
27
|
|
28
28
|
parse_statements
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
private
|
32
32
|
|
33
33
|
def parse_statements
|
@@ -79,7 +79,7 @@ module YARD
|
|
79
79
|
nil
|
80
80
|
end
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
def sanitize_statement_end
|
84
84
|
extra = []
|
85
85
|
(@statement.size - 1).downto(0) do |index|
|
@@ -110,7 +110,7 @@ module YARD
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
def preprocess_token(tk)
|
115
115
|
if tk.is_a?(TkCOMMENT)
|
116
116
|
case tk.text
|
@@ -187,7 +187,7 @@ module YARD
|
|
187
187
|
process_statement_end(tk)
|
188
188
|
@state = :block
|
189
189
|
end
|
190
|
-
|
190
|
+
|
191
191
|
if @first_line == tk.line_no && !@statement.empty? && TkCOMMENT === tk
|
192
192
|
process_initial_comment(tk)
|
193
193
|
end
|
@@ -219,7 +219,7 @@ module YARD
|
|
219
219
|
if @statement.empty? && (@comments_last_line || 0) < tk.line_no - 2
|
220
220
|
@comments = nil
|
221
221
|
end
|
222
|
-
|
222
|
+
|
223
223
|
return unless tk.class == TkCOMMENT
|
224
224
|
|
225
225
|
case tk.text
|
@@ -237,7 +237,7 @@ module YARD
|
|
237
237
|
end
|
238
238
|
return if !@statement.empty? && @comments
|
239
239
|
return if @first_line && tk.line_no > @first_line
|
240
|
-
|
240
|
+
|
241
241
|
@comments = nil if @comments_last_line && @comments_last_line < tk.line_no - 1
|
242
242
|
@comments_line = tk.line_no unless @comments
|
243
243
|
|
@@ -303,8 +303,8 @@ module YARD
|
|
303
303
|
def process_statement_end(tk)
|
304
304
|
# Whitespace means that we keep the same value of @new_statement as last token
|
305
305
|
return if tk.class == TkSPACE
|
306
|
-
|
307
|
-
return unless
|
306
|
+
|
307
|
+
return unless
|
308
308
|
# We might be coming after a statement-ending token...
|
309
309
|
((@last_tk && [TkSEMICOLON, TkNL, TkEND_OF_SCRIPT].include?(tk.class)) ||
|
310
310
|
# Or we might be at the beginning of an argument list
|
@@ -329,13 +329,13 @@ module YARD
|
|
329
329
|
|
330
330
|
# Continue with the statement if we've hit a comma in a def
|
331
331
|
return if @current_block == TkDEF && peek_no_space.class == TkCOMMA
|
332
|
-
|
333
|
-
|
332
|
+
|
333
|
+
|
334
334
|
if [TkEND_OF_SCRIPT, TkNL, TkSEMICOLON].include?(tk.class) && @state == :block_statement &&
|
335
335
|
[TkRBRACE, TkEND].include?(@last_ns_tk.class) && @level == 0
|
336
336
|
@current_block = nil
|
337
337
|
end
|
338
|
-
|
338
|
+
|
339
339
|
unless @current_block
|
340
340
|
@done = true
|
341
341
|
return
|
@@ -365,7 +365,7 @@ module YARD
|
|
365
365
|
@level -= 1
|
366
366
|
end
|
367
367
|
end
|
368
|
-
|
368
|
+
|
369
369
|
@level == 0
|
370
370
|
end
|
371
371
|
|
@@ -2,11 +2,11 @@ module YARD
|
|
2
2
|
module Parser::Ruby::Legacy
|
3
3
|
class TokenList < Array
|
4
4
|
include RubyToken
|
5
|
-
|
5
|
+
|
6
6
|
def initialize(content = nil)
|
7
7
|
self << content if content
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def to_s(full_statement = false, show_block = true)
|
11
11
|
inject([]) do |acc, token|
|
12
12
|
break acc if !full_statement && TkStatementEnd === token
|
@@ -18,7 +18,7 @@ module YARD
|
|
18
18
|
acc
|
19
19
|
end.join
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
# @param [TokenList, Token, String] tokens
|
23
23
|
# A list of tokens. If the token is a string, it
|
24
24
|
# is parsed with {RubyLex}.
|
@@ -37,28 +37,28 @@ module YARD
|
|
37
37
|
self
|
38
38
|
end
|
39
39
|
alias_method :<<, :push
|
40
|
-
|
40
|
+
|
41
41
|
def squeeze(type = TkSPACE)
|
42
42
|
last = nil
|
43
43
|
TokenList.new(map {|t| x = t.is_a?(type) && last.is_a?(type) ? nil : t; last = t; x })
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
private
|
47
|
-
|
47
|
+
|
48
48
|
def parse_content(content)
|
49
49
|
lex = RubyLex.new(content)
|
50
|
-
while tk = lex.token do
|
50
|
+
while tk = lex.token do
|
51
51
|
self << convert_token(lex, tk)
|
52
52
|
end
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
def convert_token(lex, tk)
|
56
56
|
if TkSYMBEG === tk && next_tk = lex.token
|
57
57
|
sym = TkSYMBOL.new(tk.line_no, tk.char_no, nil)
|
58
58
|
sym.lex_state = lex.lex_state
|
59
59
|
sym.set_text(tk.text + next_tk.text)
|
60
60
|
else
|
61
|
-
tk
|
61
|
+
tk
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
@@ -11,14 +11,14 @@ module YARD
|
|
11
11
|
def initialize(source, filename)
|
12
12
|
@parser = RipperParser.new(source, filename)
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def parse; @parser.parse end
|
16
16
|
def tokenize; @parser.tokens end
|
17
17
|
def enumerator; @parser.enumerator end
|
18
18
|
def shebang_line; @parser.shebang_line end
|
19
19
|
def encoding_line; @parser.encoding_line end
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
# Internal parser class
|
23
23
|
# @since 0.5.6
|
24
24
|
class RipperParser < Ripper
|
@@ -52,13 +52,13 @@ module YARD
|
|
52
52
|
insert_comments
|
53
53
|
self
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def enumerator
|
57
57
|
ast.children
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
private
|
61
|
-
|
61
|
+
|
62
62
|
MAPPINGS = {
|
63
63
|
:BEGIN => "BEGIN",
|
64
64
|
:END => "END",
|
@@ -110,7 +110,7 @@ module YARD
|
|
110
110
|
:zsuper => "super"
|
111
111
|
}
|
112
112
|
REV_MAPPINGS = {}
|
113
|
-
|
113
|
+
|
114
114
|
AST_TOKENS = [:CHAR, :backref, :const, :cvar, :gvar, :heredoc_end, :ident,
|
115
115
|
:int, :float, :ivar, :label, :period, :regexp_end, :tstring_content, :backtick]
|
116
116
|
|
@@ -124,7 +124,7 @@ module YARD
|
|
124
124
|
|
125
125
|
PARSER_EVENT_TABLE.each do |event, arity|
|
126
126
|
node_class = AstNode.node_class_for(event)
|
127
|
-
|
127
|
+
|
128
128
|
if /_new\z/ =~ event.to_s and arity == 0
|
129
129
|
module_eval(<<-eof, __FILE__, __LINE__ + 1)
|
130
130
|
def on_#{event}(*args)
|
@@ -165,7 +165,7 @@ module YARD
|
|
165
165
|
end
|
166
166
|
eof
|
167
167
|
end
|
168
|
-
|
168
|
+
|
169
169
|
REV_MAPPINGS.select {|k,v| k.is_a?(Symbol) }.each do |pair|
|
170
170
|
event, value = *pair
|
171
171
|
ast_token = AST_TOKENS.include?(event)
|
@@ -177,7 +177,7 @@ module YARD
|
|
177
177
|
end
|
178
178
|
eof
|
179
179
|
end
|
180
|
-
|
180
|
+
|
181
181
|
[:kw, :op].each do |event|
|
182
182
|
module_eval(<<-eof, __FILE__, __LINE__ + 1)
|
183
183
|
begin; undef on_#{event}; rescue NameError; end
|
@@ -200,7 +200,7 @@ module YARD
|
|
200
200
|
end
|
201
201
|
eof
|
202
202
|
end
|
203
|
-
|
203
|
+
|
204
204
|
def visit_event(node)
|
205
205
|
map = @map[MAPPINGS[node.type]]
|
206
206
|
lstart, sstart = *(map ? map.pop : [lineno, lineno])
|
@@ -208,7 +208,7 @@ module YARD
|
|
208
208
|
node.line_range = Range.new(lstart, lineno)
|
209
209
|
node
|
210
210
|
end
|
211
|
-
|
211
|
+
|
212
212
|
def visit_event_arr(node)
|
213
213
|
mapping = MAPPINGS[node.type].find {|k| @map[k] && !@map[k].empty? }
|
214
214
|
lstart, sstart = *@map[mapping].pop
|
@@ -227,7 +227,7 @@ module YARD
|
|
227
227
|
AstNode.new(token, [data], :line => lineno..lineno, :char => ch..charno-1, :token => true)
|
228
228
|
end
|
229
229
|
end
|
230
|
-
|
230
|
+
|
231
231
|
def add_token(token, data)
|
232
232
|
if @tokens.last && @tokens.last[0] == :symbeg
|
233
233
|
@tokens[-1] = [:symbol, ":" + data]
|
@@ -249,6 +249,7 @@ module YARD
|
|
249
249
|
undef on_aref
|
250
250
|
undef on_rbracket
|
251
251
|
undef on_qwords_new
|
252
|
+
undef on_qwords_add
|
252
253
|
undef on_string_literal
|
253
254
|
undef on_lambda
|
254
255
|
undef on_string_content
|
@@ -270,7 +271,7 @@ module YARD
|
|
270
271
|
args.compact.size == 1 ? args.first : AstNode.new(:list, args)
|
271
272
|
end
|
272
273
|
alias on_bodystmt on_body_stmt
|
273
|
-
|
274
|
+
|
274
275
|
def on_assoc_new(*args)
|
275
276
|
AstNode.new(:assoc, args)
|
276
277
|
end
|
@@ -278,27 +279,27 @@ module YARD
|
|
278
279
|
def on_hash(*args)
|
279
280
|
visit_event AstNode.new(:hash, args.first || [])
|
280
281
|
end
|
281
|
-
|
282
|
+
|
282
283
|
def on_bare_assoc_hash(*args)
|
283
284
|
AstNode.new(:list, args.first)
|
284
285
|
end
|
285
|
-
|
286
|
+
|
286
287
|
def on_assoclist_from_args(*args)
|
287
288
|
args.first
|
288
289
|
end
|
289
|
-
|
290
|
+
|
290
291
|
def on_aref(*args)
|
291
292
|
ll, lc = *@map[:aref].pop
|
292
293
|
sr = args.first.source_range.first..lc
|
293
294
|
lr = args.first.line_range.first..ll
|
294
295
|
AstNode.new(:aref, args, :char => sr, :line => lr)
|
295
296
|
end
|
296
|
-
|
297
|
+
|
297
298
|
def on_rbracket(tok)
|
298
299
|
(@map[:aref] ||= []) << [lineno, charno]
|
299
300
|
visit_ns_token(:rbracket, tok, false)
|
300
301
|
end
|
301
|
-
|
302
|
+
|
302
303
|
def on_top_const_ref(*args)
|
303
304
|
type = :top_const_ref
|
304
305
|
node = AstNode.node_class_for(type).new(type, args)
|
@@ -310,11 +311,11 @@ module YARD
|
|
310
311
|
mapping.push(extra_op) if extra_op
|
311
312
|
node
|
312
313
|
end
|
313
|
-
|
314
|
+
|
314
315
|
def on_const_path_ref(*args)
|
315
316
|
ReferenceNode.new(:const_path_ref, args, :listline => lineno..lineno, :listchar => charno..charno)
|
316
317
|
end
|
317
|
-
|
318
|
+
|
318
319
|
[:if_mod, :unless_mod, :while_mod].each do |kw|
|
319
320
|
node_class = AstNode.node_class_for(kw)
|
320
321
|
module_eval(<<-eof, __FILE__, __LINE__ + 1)
|
@@ -327,10 +328,23 @@ module YARD
|
|
327
328
|
eof
|
328
329
|
end
|
329
330
|
|
330
|
-
def on_qwords_new
|
331
|
-
|
331
|
+
def on_qwords_new(*args)
|
332
|
+
node = LiteralNode.new(:qwords_literal, args)
|
333
|
+
if @map[:qwords_beg]
|
334
|
+
sstart, lstart = *@map[:qwords_beg].pop
|
335
|
+
node.source_range = Range.new(sstart-1, @ns_charno)
|
336
|
+
node.line_range = Range.new(lstart, lineno)
|
337
|
+
end
|
338
|
+
node
|
332
339
|
end
|
333
340
|
|
341
|
+
def on_qwords_add(list, item)
|
342
|
+
list.source_range = (list.source_range.first..@ns_charno)
|
343
|
+
list.line_range = (list.line_range.first..lineno)
|
344
|
+
list.push(item)
|
345
|
+
list
|
346
|
+
end
|
347
|
+
|
334
348
|
def on_string_literal(*args)
|
335
349
|
node = visit_event_arr(LiteralNode.new(:string_literal, args))
|
336
350
|
if args.size == 1
|
@@ -343,15 +357,15 @@ module YARD
|
|
343
357
|
end
|
344
358
|
node
|
345
359
|
end
|
346
|
-
|
360
|
+
|
347
361
|
def on_lambda(*args)
|
348
362
|
visit_event_arr AstNode.new(:lambda, args)
|
349
363
|
end
|
350
|
-
|
364
|
+
|
351
365
|
def on_string_content(*args)
|
352
366
|
AstNode.new(:string_content, args, :listline => lineno..lineno, :listchar => charno..charno)
|
353
367
|
end
|
354
|
-
|
368
|
+
|
355
369
|
def on_rescue(exc, *args)
|
356
370
|
exc = AstNode.new(:list, exc) if exc
|
357
371
|
visit_event AstNode.new(:rescue, [exc, *args])
|
@@ -380,7 +394,7 @@ module YARD
|
|
380
394
|
end
|
381
395
|
ParameterNode.new(:params, args, :listline => lineno..lineno, :listchar => charno..charno)
|
382
396
|
end
|
383
|
-
|
397
|
+
|
384
398
|
def on_label(data)
|
385
399
|
add_token(:label, data)
|
386
400
|
ch = charno
|
@@ -407,15 +421,15 @@ module YARD
|
|
407
421
|
return
|
408
422
|
end
|
409
423
|
case comment
|
410
|
-
when /\A
|
424
|
+
when /\A#+ @group\s+(.+)\s*\Z/
|
411
425
|
@groups.unshift [lineno, $1]
|
412
426
|
return
|
413
|
-
when /\A
|
427
|
+
when /\A#+ @endgroup\s*\Z/
|
414
428
|
@groups.unshift [lineno, nil]
|
415
429
|
return
|
416
430
|
end
|
417
|
-
|
418
|
-
comment = comment.gsub(/^(
|
431
|
+
|
432
|
+
comment = comment.gsub(/^(\#+)\s{0,1}/, '').chomp
|
419
433
|
append_comment = @comments[lineno - 1]
|
420
434
|
hash_flag = $1 == '##' ? true : false
|
421
435
|
|
@@ -425,32 +439,32 @@ module YARD
|
|
425
439
|
@comments_flags.delete(lineno - 1)
|
426
440
|
comment = append_comment + "\n" + comment
|
427
441
|
end
|
428
|
-
|
442
|
+
|
429
443
|
@comments[lineno] = comment
|
430
444
|
@comments_flags[lineno] = hash_flag if !append_comment
|
431
445
|
@comments_last_column = column
|
432
446
|
end
|
433
|
-
|
447
|
+
|
434
448
|
def on_embdoc_beg(text)
|
435
449
|
visit_ns_token(:embdoc_beg, text)
|
436
450
|
@embdoc = ""
|
437
451
|
end
|
438
|
-
|
452
|
+
|
439
453
|
def on_embdoc(text)
|
440
454
|
visit_ns_token(:embdoc, text)
|
441
455
|
@embdoc << text
|
442
456
|
end
|
443
|
-
|
457
|
+
|
444
458
|
def on_embdoc_end(text)
|
445
459
|
visit_ns_token(:embdoc_end, text)
|
446
460
|
@comments[lineno] = @embdoc
|
447
461
|
@embdoc = nil
|
448
462
|
end
|
449
|
-
|
463
|
+
|
450
464
|
def on_parse_error(msg)
|
451
465
|
raise ParserSyntaxError, "syntax error in `#{file}`:(#{lineno},#{column}): #{msg}"
|
452
466
|
end
|
453
|
-
|
467
|
+
|
454
468
|
def insert_comments
|
455
469
|
root.traverse do |node|
|
456
470
|
next if node.type == :list || node.parent.type != :list
|
@@ -474,7 +488,7 @@ module YARD
|
|
474
488
|
end
|
475
489
|
end
|
476
490
|
end
|
477
|
-
|
491
|
+
|
478
492
|
def freeze_tree(node = nil)
|
479
493
|
node ||= root
|
480
494
|
node.children.each do |child|
|