|
8 | 8 | # by Keiju ISHITSUKA (Nippon Rational Inc.) |
9 | 9 | # |
10 | 10 |
|
11 | | -if ENV['RDOC_USE_PRISM_PARSER'] |
12 | | - require 'rdoc/parser/prism_ruby' |
13 | | - RDoc::Parser.const_set(:Ruby, RDoc::Parser::PrismRuby) |
14 | | - puts "=========================================================================" |
15 | | - puts "RDoc is using the experimental Prism parser to generate the documentation" |
16 | | - puts "=========================================================================" |
17 | | - return |
18 | | -end |
| 11 | +# This file is based on rtags |
19 | 12 |
|
20 | 13 | require 'ripper' |
21 | 14 | require_relative 'ripper_state_lex' |
22 | 15 |
|
23 | | -## |
24 | | -# Extracts code elements from a source file returning a TopLevel object |
25 | | -# containing the constituent file elements. |
26 | | -# |
27 | | -# This file is based on rtags |
28 | | -# |
29 | | -# RubyParser understands how to document: |
30 | | -# * classes |
31 | | -# * modules |
32 | | -# * methods |
33 | | -# * constants |
34 | | -# * aliases |
35 | | -# * private, public, protected |
36 | | -# * private_class_function, public_class_function |
37 | | -# * private_constant, public_constant |
38 | | -# * module_function |
39 | | -# * attr, attr_reader, attr_writer, attr_accessor |
40 | | -# * extra accessors given on the command line |
41 | | -# * metaprogrammed methods |
42 | | -# * require |
43 | | -# * include |
44 | | -# |
45 | | -# == Method Arguments |
46 | | -# |
47 | | -#-- |
48 | | -# NOTE: I don't think this works, needs tests, remove the paragraph following |
49 | | -# this block when known to work |
50 | | -# |
51 | | -# The parser extracts the arguments from the method definition. You can |
52 | | -# override this with a custom argument definition using the :args: directive: |
53 | | -# |
54 | | -# ## |
55 | | -# # This method tries over and over until it is tired |
56 | | -# |
57 | | -# def go_go_go(thing_to_try, tries = 10) # :args: thing_to_try |
58 | | -# puts thing_to_try |
59 | | -# go_go_go thing_to_try, tries - 1 |
60 | | -# end |
61 | | -# |
62 | | -# If you have a more-complex set of overrides you can use the :call-seq: |
63 | | -# directive: |
64 | | -#++ |
65 | | -# |
66 | | -# The parser extracts the arguments from the method definition. You can |
67 | | -# override this with a custom argument definition using the :call-seq: |
68 | | -# directive: |
69 | | -# |
70 | | -# ## |
71 | | -# # This method can be called with a range or an offset and length |
72 | | -# # |
73 | | -# # :call-seq: |
74 | | -# # my_method(Range) |
75 | | -# # my_method(offset, length) |
76 | | -# |
77 | | -# def my_method(*args) |
78 | | -# end |
79 | | -# |
80 | | -# The parser extracts +yield+ expressions from method bodies to gather the |
81 | | -# yielded argument names. If your method manually calls a block instead of |
82 | | -# yielding or you want to override the discovered argument names use |
83 | | -# the :yields: directive: |
84 | | -# |
85 | | -# ## |
86 | | -# # My method is awesome |
87 | | -# |
88 | | -# def my_method(&block) # :yields: happy, times |
89 | | -# block.call 1, 2 |
90 | | -# end |
91 | | -# |
92 | | -# == Metaprogrammed Methods |
93 | | -# |
94 | | -# To pick up a metaprogrammed method, the parser looks for a comment starting |
95 | | -# with '##' before an identifier: |
96 | | -# |
97 | | -# ## |
98 | | -# # This is a meta-programmed method! |
99 | | -# |
100 | | -# add_my_method :meta_method, :arg1, :arg2 |
101 | | -# |
102 | | -# The parser looks at the token after the identifier to determine the name, in |
103 | | -# this example, :meta_method. If a name cannot be found, a warning is printed |
104 | | -# and 'unknown' is used. |
105 | | -# |
106 | | -# You can force the name of a method using the :method: directive: |
107 | | -# |
108 | | -# ## |
109 | | -# # :method: some_method! |
110 | | -# |
111 | | -# By default, meta-methods are instance methods. To indicate that a method is |
112 | | -# a singleton method instead use the :singleton-method: directive: |
113 | | -# |
114 | | -# ## |
115 | | -# # :singleton-method: |
116 | | -# |
117 | | -# You can also use the :singleton-method: directive with a name: |
118 | | -# |
119 | | -# ## |
120 | | -# # :singleton-method: some_method! |
121 | | -# |
122 | | -# You can define arguments for metaprogrammed methods via either the |
123 | | -# \:call-seq:, :arg: or :args: directives. |
124 | | -# |
125 | | -# Additionally you can mark a method as an attribute by |
126 | | -# using :attr:, :attr_reader:, :attr_writer: or :attr_accessor:. Just like |
127 | | -# for :method:, the name is optional. |
128 | | -# |
129 | | -# ## |
130 | | -# # :attr_reader: my_attr_name |
131 | | -# |
132 | | -# == Hidden methods and attributes |
133 | | -# |
134 | | -# You can provide documentation for methods that don't appear using |
135 | | -# the :method:, :singleton-method: and :attr: directives: |
136 | | -# |
137 | | -# ## |
138 | | -# # :attr_writer: ghost_writer |
139 | | -# # There is an attribute here, but you can't see it! |
140 | | -# |
141 | | -# ## |
142 | | -# # :method: ghost_method |
143 | | -# # There is a method here, but you can't see it! |
144 | | -# |
145 | | -# ## |
146 | | -# # this is a comment for a regular method |
147 | | -# |
148 | | -# def regular_method() end |
149 | | -# |
150 | | -# Note that by default, the :method: directive will be ignored if there is a |
151 | | -# standard rdocable item following it. |
152 | | - |
153 | | -class RDoc::Parser::Ruby < RDoc::Parser |
| 16 | +class RDoc::Parser::RipperRuby < RDoc::Parser |
154 | 17 |
|
155 | | - parse_files_matching(/\.rbw?$/) |
| 18 | + parse_files_matching(/\.rbw?$/) if ENV['RDOC_USE_RIPPER_PARSER'] |
156 | 19 |
|
157 | 20 | include RDoc::TokenStream |
158 | 21 | include RDoc::Parser::RubyTools |
|
0 commit comments