def next_token
while @in_part != "rd"
line = @src[@i]
@i += 1
case line
when false
return [false, false]
when /^=begin\s*(?:\bRD\b.*)?\s*$/
if @in_part
@part_content.push(line)
else
@in_part = "rd"
return [:WHITELINE, "=begin\n"]
end
when /^=begin\s+(\w+)/
part = $1
if @in_part
@part_content.push(line)
else
@in_part = part if @tree.filter[part]
end
when /^=end/
if @in_part
part = RDoc::RD::Part.new(@part_content.join(""), @tree, "r")
@part_content.clear
part_out = @tree.filter[@in_part].call(part)
if @tree.filter[@in_part].mode == :rd
subtree = parse_subtree(part_out.to_a)
else
basename = TMPFILE.join('.')
TMPFILE[-1] += 1
tmpfile = open(@tree.tmp_dir + "/" + basename + ".#{@in_part}", "w")
tmpfile.print(part_out)
tmpfile.close
subtree = parse_subtree(["=begin\n", "<<< #{basename}\n", "=end\n"])
end
@in_part = nil
return [:SUBTREE, subtree]
end
else
if @in_part
@part_content.push(line)
end
end
end
@current_indent = @indent_stack.join("")
line = @src[@i]
case line
when false
if_current_indent_equal("") do
[false, false]
end
when /^=end/
if_current_indent_equal("") do
@in_part = nil
[:WHITELINE, "=end"]
end
when /^\s*$/
@i += 1
return [:WHITELINE, ':WHITELINE']
when /^\#/
@i += 1
self.next_token()
when /^(={1,4})(?!=)\s*(?=\S)/, /^(\+{1,2})(?!\+)\s*(?=\S)/
rest = $'
rest.strip!
mark = $1
if_current_indent_equal("") do
return [:HEADLINE, [MARK_TO_LEVEL[mark], rest]]
end
when /^<<<\s*(\S+)/
file = $1
if_current_indent_equal("") do
suffix = file[-3 .. -1]
if suffix == ".rd" or suffix == ".rb"
subtree = parse_subtree(get_included(file))
[:SUBTREE, subtree]
else
[:INCLUDE, file]
end
end
when /^(\s*)\*(\s*)/
rest = $'
newIndent = $2
if_current_indent_equal($1) do
if @in_verbatim
[:STRINGLINE, line]
else
@indent_stack.push("\s" << newIndent)
[:ITEMLISTLINE, rest]
end
end
when /^(\s*)(\(\d+\))(\s*)/
rest = $'
mark = $2
newIndent = $3
if_current_indent_equal($1) do
if @in_verbatim
[:STRINGLINE, line]
else
@indent_stack.push("\s" * mark.size << newIndent)
[:ENUMLISTLINE, rest]
end
end
when /^(\s*):(\s*)/
rest = $'
newIndent = $2
if_current_indent_equal($1) do
if @in_verbatim
[:STRINGLINE, line]
else
@indent_stack.push("\s#{$2}")
[:DESCLISTLINE, rest]
end
end
when /^(\s*)---(?!-|\s*$)/
indent = $1
rest = $'
/\s*/ === rest
term = $'
new_indent = $&
if_current_indent_equal(indent) do
if @in_verbatim
[:STRINGLINE, line]
else
@indent_stack.push("\s\s\s" + new_indent)
[:METHODLISTLINE, term]
end
end
when /^(\s*)/
if_current_indent_equal($1) do
[:STRINGLINE, line]
end
else
raise "[BUG] parsing error may occured."
end
end