Skip to content

Commit

Permalink
Fix parse bug with toplevel methods. Allow RDoc in =begin rdoc/=end c…
Browse files Browse the repository at this point in the history
…omments (experimental)

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6066 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
dave committed Apr 2, 2004
1 parent 64ec09d commit ef38efc
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 26 deletions.
12 changes: 12 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ Fri Apr 2 07:31:38 2004 Yukihiro Matsumoto <[email protected]>
* ext/socket/socket.c (make_hostent): fix memory leak, based on
the patch from HORIKAWA Hisashi <[email protected]>.

Thu Apr 1 22:55:33 2004 Dave Thomas <[email protected]>

* lib/rdoc/parsers/parse_rb.rb: Allow rdoc comments in
=begin rdoc/=end

* lib/rdoc/parsers/parse_rb.rb: Fix problem with comment in
top-level method being taken as file comment.

Thu Apr 1 22:55:04 2004 Dave Thomas <[email protected]>

* lib/rdoc/ri/ri_options.rb: Fix undefined variable warning.

Thu Apr 1 19:58:37 2004 NAKAMURA, Hiroshi <[email protected]>

* lib/soap/mapping/{factory.rb,registry.rb}: fixed illegal mapped URI
Expand Down
10 changes: 9 additions & 1 deletion lib/rdoc/README
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,15 @@ can see the formatted result in EXAMPLE.rb and Anagram.

= Markup

Comment blocks can be written fairly naturally.
Comment blocks can be written fairly naturally, either using '#' on
successive lines of the comment, or by including the comment in
an =begin/=end block. If you use the latter form, the =begin line
must be flagged with an RDoc tag:

=begin rdoc
Documentation to
be processed by RDoc.
=end

Paragraphs are lines that share the left margin. Text indented past
this margin are formatted verbatim.
Expand Down
9 changes: 9 additions & 0 deletions lib/rdoc/code_objects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,15 @@ class TopLevel < Context
@@all_classes = {}
@@all_modules = {}

def comment=(t)
if @c
fail t
else
@c = true
end
super
end

def TopLevel::reset
@@all_classes = {}
@@all_modules = {}
Expand Down
55 changes: 33 additions & 22 deletions lib/rdoc/parsers/parse_rb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,14 @@ def lex_init()
ungetc

@ltype = nil
Token(TkRD_COMMENT).set_text(str)

if str =~ /\A=begin\s+rdoc/i
str.sub!(/\A=begin.*\n/, '')
str.sub!(/^=end.*/m, '')
Token(TkCOMMENT).set_text(str)
else
Token(TkRD_COMMENT)#.set_text(str)
end
end

@OP.def_rule("\n") do
Expand Down Expand Up @@ -1394,7 +1401,7 @@ def scan
@read = []
catch(:eof) do
begin
parse_statements(@top_level)
parse_toplevel_statements(@top_level)
rescue Exception => e
$stderr.puts "\n\n"
$stderr.puts "RDoc failure in #@input_file_name at or around " +
Expand Down Expand Up @@ -1546,26 +1553,30 @@ def collect_first_comment
res
end

def parse_statements(container, single=NORMAL, current_method = nil)
def parse_toplevel_statements(container)
comment = collect_first_comment
look_for_directives_in(container, comment)
container.comment = comment unless comment.empty?
parse_statements(container, NORMAL, nil, comment)
end

def parse_statements(container, single=NORMAL, current_method=nil, comment='')
nest = 1
save_visibility = container.visibility

if container.kind_of?(TopLevel)
comment = collect_first_comment
look_for_directives_in(container, comment)
container.comment = comment unless comment.empty?
else
comment = ''
end

# if container.kind_of?(TopLevel)
# else
# comment = ''
# end

non_comment_seen = true

while tk = get_tk

keep_comment = false

non_comment_seen = true unless tk.kind_of?(TkCOMMENT)

# $stderr.puts "===== #{tk.inspect}"
# blank_line_seen = true
# while tk.kind_of?(TkNL)
Expand Down Expand Up @@ -1713,7 +1724,7 @@ def parse_statements(container, single=NORMAL, current_method = nil)

end
end

def parse_class(container, single, tk, comment, &block)
progress("c")

Expand Down Expand Up @@ -1867,7 +1878,7 @@ def parse_method(container, single, tk, comment)
@stats.num_methods += 1
line_no = tk.line_no
column = tk.char_no

start_collecting_tokens
add_token(tk)
add_token_listener(self)
Expand Down Expand Up @@ -1949,20 +1960,20 @@ def parse_method(container, single, tk, comment)
meth.visibility = :public
end
end

parse_statements(container, single, meth)

remove_token_listener(meth)

meth.comment = comment
end

def skip_method(container)
meth = AnyMethod.new("", "anon")
parse_method_parameters(meth)
parse_statements(container, false, meth)
end

# Capture the method's parameters. Along the way,
# look for a comment containing
#
Expand Down
6 changes: 3 additions & 3 deletions lib/rdoc/ri/ri_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module RI

require 'rdoc/ri/ri_display'

VERSION_STRING = "beta1"
VERSION_STRING = "ri: beta1"
CVS_ID = "$Id$";

class Options
Expand Down Expand Up @@ -171,7 +171,7 @@ def OptionList.usage(short_form=false)
# Show the version and exit
def show_version
cvs_info = CVS_ID.split
puts "ri #{VERSION_STRING} (#{cvs_info[2]} #{cvs_info[3]})"
puts "#{VERSION_STRING} (#{cvs_info[2]} #{cvs_info[3]})"
exit(0)
end

Expand Down Expand Up @@ -230,7 +230,7 @@ def parse

# Return the doc_dir as an array, or nil if no overriding doc dir was given
def paths
@doc_dir ? [ @doc_dir ] : nil
defined?(@doc_dir) ? [ @doc_dir ] : nil
end

# Return an instance of the displayer (the thing that actually writes
Expand Down

0 comments on commit ef38efc

Please sign in to comment.