Merge rdoc-6.0.0.beta2 from upstream.

* This version changed lexer used Ripper from lexer based IRB.
    see details: https://github.com/ruby/rdoc/pull/512

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59845 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
hsbt 2017-09-12 03:42:54 +00:00
Родитель 65b11a04f1
Коммит 214a7f8d49
23 изменённых файлов: 1472 добавлений и 3227 удалений

Просмотреть файл

@ -65,7 +65,7 @@ module RDoc
##
# RDoc version you are using
VERSION = '6.0.0.beta1'
VERSION = '6.0.0.beta2'
##
# Method visibilities
@ -148,7 +148,7 @@ module RDoc
autoload :KNOWN_CLASSES, 'rdoc/known_classes'
autoload :RubyLex, 'rdoc/ruby_lex'
autoload :RipperStateLex, 'rdoc/parser/ripper_state_lex'
autoload :RubyToken, 'rdoc/ruby_token'
autoload :TokenStream, 'rdoc/token_stream'

Просмотреть файл

@ -36,7 +36,7 @@ class RDoc::Constant < RDoc::CodeObject
@value = value
@is_alias_for = nil
@visibility = nil
@visibility = :public
self.comment = comment
end
@ -136,7 +136,7 @@ class RDoc::Constant < RDoc::CodeObject
initialize array[1], nil, array[5]
@full_name = array[2]
@visibility = array[3]
@visibility = array[3] || :public
@is_alias_for = array[4]
# 5 handled above
# 6 handled below

Просмотреть файл

@ -1079,6 +1079,7 @@ class RDoc::Context < RDoc::CodeObject
return if [:private, :nodoc].include? min_visibility
remove_invisible_in @method_list, min_visibility
remove_invisible_in @attributes, min_visibility
remove_invisible_in @constants, min_visibility
end
##
@ -1165,6 +1166,17 @@ class RDoc::Context < RDoc::CodeObject
end
end
##
# Given an array +names+ of constants, set the visibility of each constant to
# +visibility+
def set_constant_visibility_for(names, visibility)
names.each do |name|
constant = @constants_hash[name] or next
constant.visibility = visibility
end
end
##
# Sorts sections alphabetically (default) or in TomDoc fashion (none,
# Public, Internal, Deprecated)

Просмотреть файл

@ -15280,7 +15280,7 @@ class RDoc::Markdown
self.pos = _save
break
end
@result = begin;
@result = begin;
ref = [:inline, @note_order.length]
@footnotes[ref] = paragraph a

Просмотреть файл

@ -200,10 +200,12 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
content = if verbatim.ruby? or parseable? text then
begin
tokens = RDoc::RubyLex.tokenize text, @options
tokens = RDoc::RipperStateLex.parse text
klass = ' class="ruby"'
RDoc::TokenStream.to_html tokens
result = RDoc::TokenStream.to_html tokens
result = result + "\n" unless "\n" == result[-1]
result
rescue RDoc::RubyLex::Error
CGI.escapeHTML text
end
@ -212,7 +214,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
end
if @options.pipe then
@res << "\n<pre><code>#{CGI.escapeHTML text}</code></pre>\n"
@res << "\n<pre><code>#{CGI.escapeHTML text}\n</code></pre>\n"
else
@res << "\n<pre#{klass}>#{content}</pre>\n"
end

Просмотреть файл

@ -666,8 +666,7 @@ class RDoc::Parser::C < RDoc::Parser
#meth_obj.params = params
meth_obj.start_collecting_tokens
tk = RDoc::RubyToken::Token.new nil, 1, 1
tk.set_text body
tk = { :line_no => 1, :char_no => 1, :text => body }
meth_obj.add_token tk
meth_obj.comment = comment
meth_obj.line = file_content[0, offset].count("\n") + 1
@ -684,8 +683,7 @@ class RDoc::Parser::C < RDoc::Parser
find_modifiers comment, meth_obj
meth_obj.start_collecting_tokens
tk = RDoc::RubyToken::Token.new nil, 1, 1
tk.set_text body
tk = { :line_no => 1, :char_no => 1, :text => body }
meth_obj.add_token tk
meth_obj.comment = comment
meth_obj.line = file_content[0, offset].count("\n") + 1

Просмотреть файл

@ -0,0 +1,587 @@
require 'ripper'
class RDoc::RipperStateLex
EXPR_NONE = 0
EXPR_BEG = 1
EXPR_END = 2
EXPR_ENDARG = 4
EXPR_ENDFN = 8
EXPR_ARG = 16
EXPR_CMDARG = 32
EXPR_MID = 64
EXPR_FNAME = 128
EXPR_DOT = 256
EXPR_CLASS = 512
EXPR_LABEL = 1024
EXPR_LABELED = 2048
EXPR_FITEM = 4096
EXPR_VALUE = EXPR_BEG
EXPR_BEG_ANY = (EXPR_BEG | EXPR_MID | EXPR_CLASS)
EXPR_ARG_ANY = (EXPR_ARG | EXPR_CMDARG)
EXPR_END_ANY = (EXPR_END | EXPR_ENDARG | EXPR_ENDFN)
class InnerStateLex < Ripper::Filter
attr_accessor :lex_state
def initialize(code)
@lex_state = EXPR_BEG
@in_fname = false
@continue = false
reset
super(code)
end
def reset
@command_start = false
@cmd_state = @command_start
end
def on_nl(tok, data)
case @lex_state
when EXPR_FNAME, EXPR_DOT
@continue = true
else
@continue = false
@lex_state = EXPR_BEG unless (EXPR_LABEL & @lex_state) != 0
end
@callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end
def on_ignored_nl(tok, data)
case @lex_state
when EXPR_FNAME, EXPR_DOT
@continue = true
else
@continue = false
@lex_state = EXPR_BEG unless (EXPR_LABEL & @lex_state) != 0
end
@callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end
def on_op(tok, data)
case tok
when '&', '|', '!', '!=', '!~'
case @lex_state
when EXPR_FNAME, EXPR_DOT
@lex_state = EXPR_ARG
else
@lex_state = EXPR_BEG
end
when '<<'
# TODO next token?
case @lex_state
when EXPR_FNAME, EXPR_DOT
@lex_state = EXPR_ARG
else
@lex_state = EXPR_BEG
end
when '?'
@lex_state = EXPR_BEG
when '&&', '||', '+=', '-=', '*=', '**=',
'&=', '|=', '^=', '<<=', '>>=', '||=', '&&='
@lex_state = EXPR_BEG
else
case @lex_state
when EXPR_FNAME, EXPR_DOT
@lex_state = EXPR_ARG
else
@lex_state = EXPR_BEG
end
end
@callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end
def on_kw(tok, data)
case tok
when 'class'
@lex_state = EXPR_CLASS
@in_fname = true
when 'def'
@lex_state = EXPR_FNAME
@continue = true
@in_fname = true
when 'if', 'unless', 'while', 'until'
if ((EXPR_END | EXPR_ENDARG | EXPR_ENDFN | EXPR_ARG | EXPR_CMDARG) & @lex_state) != 0 # postfix if
@lex_state = EXPR_BEG | EXPR_LABEL
else
@lex_state = EXPR_BEG
end
when 'begin'
@lex_state = EXPR_BEG
else
if @lex_state == EXPR_FNAME
@lex_state = EXPR_END
else
@lex_state = EXPR_END
end
end
@callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end
def on_tstring_beg(tok, data)
@lex_state = EXPR_BEG
@callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end
def on_tstring_end(tok, data)
@lex_state = EXPR_END | EXPR_ENDARG
@callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end
def on_CHAR(tok, data)
@lex_state = EXPR_END
@callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end
def on_period(tok, data)
@lex_state = EXPR_DOT
@callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end
def on_int(tok, data)
@lex_state = EXPR_END | EXPR_ENDARG
@callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end
def on_float(tok, data)
@lex_state = EXPR_END | EXPR_ENDARG
@callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end
def on_rational(tok, data)
@lex_state = EXPR_END | EXPR_ENDARG
@callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end
def on_imaginary(tok, data)
@lex_state = EXPR_END | EXPR_ENDARG
@callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end
def on_symbeg(tok, data)
@lex_state = EXPR_FNAME
@continue = true
@in_fname = true
@callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end
private def on_variables(event, tok, data)
if @in_fname
@lex_state = EXPR_ENDFN
@in_fname = false
@continue = false
elsif @continue
case @lex_state
when EXPR_DOT
@lex_state = EXPR_ARG
else
@lex_state = EXPR_ENDFN
@continue = false
end
else
@lex_state = EXPR_CMDARG
end
@callback.call({ :line_no => lineno, :char_no => column, :kind => event, :text => tok, :state => @lex_state})
end
def on_ident(tok, data)
on_variables(__method__, tok, data)
end
def on_ivar(tok, data)
@lex_state = EXPR_END
on_variables(__method__, tok, data)
end
def on_cvar(tok, data)
@lex_state = EXPR_END
on_variables(__method__, tok, data)
end
def on_gvar(tok, data)
@lex_state = EXPR_END
on_variables(__method__, tok, data)
end
def on_backref(tok, data)
@lex_state = EXPR_END
on_variables(__method__, tok, data)
end
def on_lparen(tok, data)
@lex_state = EXPR_LABEL | EXPR_BEG
@callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end
def on_rparen(tok, data)
@lex_state = EXPR_ENDFN
@callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end
def on_lbrace(tok, data)
@lex_state = EXPR_LABEL | EXPR_BEG
@callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end
def on_rbrace(tok, data)
@lex_state = EXPR_ENDARG
@callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end
def on_lbracket(tok, data)
@lex_state = EXPR_LABEL | EXPR_BEG
@callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end
def on_rbracket(tok, data)
@lex_state = EXPR_ENDARG
@callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end
def on_const(tok, data)
case @lex_state
when EXPR_FNAME
@lex_state = EXPR_ENDFN
when EXPR_CLASS
@lex_state = EXPR_ARG
else
@lex_state = EXPR_CMDARG
end
@callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end
def on_sp(tok, data)
@callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end
def on_comma(tok, data)
@lex_state = EXPR_BEG | EXPR_LABEL if (EXPR_ARG_ANY & @lex_state) != 0
@callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end
def on_comment(tok, data)
@lex_state = EXPR_BEG unless (EXPR_LABEL & @lex_state) != 0
@callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end
def on_ignored_sp(tok, data)
@lex_state = EXPR_BEG unless (EXPR_LABEL & @lex_state) != 0
@callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end
def on_heredoc_end(tok, data)
@callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
@lex_state = EXPR_BEG
end
def on_default(event, tok, data)
reset
@callback.call({ :line_no => lineno, :char_no => column, :kind => event, :text => tok, :state => @lex_state})
end
def each(&block)
@callback = block
parse
end
end
def get_squashed_tk
if @buf.empty?
tk = @inner_lex_enumerator.next
else
tk = @buf.shift
end
case tk[:kind]
when :on_symbeg then
tk = get_symbol_tk(tk)
when :on_tstring_beg then
tk = get_string_tk(tk)
when :on_backtick then
if (EXPR_FNAME & tk[:state]) != 0
@inner_lex.lex_state = EXPR_ARG
tk[:kind] = :on_ident
tk[:state] = @inner_lex.lex_state
else
tk = get_string_tk(tk)
end
when :on_regexp_beg then
tk = get_regexp_tk(tk)
when :on_embdoc_beg then
tk = get_embdoc_tk(tk)
when :on_heredoc_beg then
@heredoc_queue << retrieve_heredoc_info(tk)
@inner_lex.lex_state = EXPR_END
when :on_nl, :on_ignored_nl, :on_comment, :on_heredoc_end then
unless @heredoc_queue.empty?
get_heredoc_tk(*@heredoc_queue.shift)
end
when :on_words_beg then
tk = get_words_tk(tk)
when :on_qwords_beg then
tk = get_words_tk(tk)
when :on_symbols_beg then
tk = get_words_tk(tk)
when :on_qsymbols_beg then
tk = get_words_tk(tk)
when :on_op then
if '&.' == tk[:text]
tk[:kind] = :on_period
else
tk = get_op_tk(tk)
end
end
tk
end
private def get_symbol_tk(tk)
is_symbol = true
symbol_tk = { :line_no => tk[:line_no], :char_no => tk[:char_no], :kind => :on_symbol }
if ":'" == tk[:text] or ':"' == tk[:text]
tk1 = get_string_tk(tk)
symbol_tk[:text] = tk1[:text]
symbol_tk[:state] = tk1[:state]
else
case (tk1 = get_squashed_tk)[:kind]
when :on_ident
symbol_tk[:text] = ":#{tk1[:text]}"
symbol_tk[:state] = tk1[:state]
when :on_tstring_content
symbol_tk[:text] = ":#{tk1[:text]}"
symbol_tk[:state] = get_squashed_tk[:state] # skip :on_tstring_end
when :on_tstring_end
symbol_tk[:text] = ":#{tk1[:text]}"
symbol_tk[:state] = tk1[:state]
when :on_op
symbol_tk[:text] = ":#{tk1[:text]}"
symbol_tk[:state] = tk1[:state]
when :on_ivar
symbol_tk[:text] = ":#{tk1[:text]}"
symbol_tk[:state] = tk1[:state]
when :on_cvar
symbol_tk[:text] = ":#{tk1[:text]}"
symbol_tk[:state] = tk1[:state]
when :on_gvar
symbol_tk[:text] = ":#{tk1[:text]}"
symbol_tk[:state] = tk1[:state]
when :on_const
symbol_tk[:text] = ":#{tk1[:text]}"
symbol_tk[:state] = tk1[:state]
when :on_kw
symbol_tk[:text] = ":#{tk1[:text]}"
symbol_tk[:state] = tk1[:state]
else
is_symbol = false
tk = tk1
end
end
if is_symbol
tk = symbol_tk
end
tk
end
private def get_string_tk(tk)
string = tk[:text]
state = nil
kind = :on_tstring
loop do
inner_str_tk = get_squashed_tk
if inner_str_tk.nil?
break
elsif :on_tstring_end == inner_str_tk[:kind]
string = string + inner_str_tk[:text]
state = inner_str_tk[:state]
break
elsif :on_label_end == inner_str_tk[:kind]
string = string + inner_str_tk[:text]
state = inner_str_tk[:state]
kind = :on_symbol
break
else
string = string + inner_str_tk[:text]
if :on_embexpr_beg == inner_str_tk[:kind] then
kind = :on_dstring if :on_tstring == kind
end
end
end
{
:line_no => tk[:line_no],
:char_no => tk[:char_no],
:kind => kind,
:text => string,
:state => state
}
end
private def get_regexp_tk(tk)
string = tk[:text]
state = nil
loop do
inner_str_tk = get_squashed_tk
if inner_str_tk.nil?
break
elsif :on_regexp_end == inner_str_tk[:kind]
string = string + inner_str_tk[:text]
state = inner_str_tk[:state]
break
else
string = string + inner_str_tk[:text]
end
end
{
:line_no => tk[:line_no],
:char_no => tk[:char_no],
:kind => :on_regexp,
:text => string,
:state => state
}
end
private def get_embdoc_tk(tk)
string = tk[:text]
until :on_embdoc_end == (embdoc_tk = get_squashed_tk)[:kind] do
string = string + embdoc_tk[:text]
end
string = string + embdoc_tk[:text]
{
:line_no => tk[:line_no],
:char_no => tk[:char_no],
:kind => :on_embdoc,
:text => string,
:state => embdoc_tk[:state]
}
end
private def get_heredoc_tk(heredoc_name, indent)
string = ''
start_tk = nil
prev_tk = nil
until heredoc_end?(heredoc_name, indent, tk = @inner_lex_enumerator.next) do
start_tk = tk unless start_tk
if (prev_tk.nil? or "\n" == prev_tk[:text][-1]) and 0 != tk[:char_no]
string = string + (' ' * tk[:char_no])
end
string = string + tk[:text]
prev_tk = tk
end
start_tk = tk unless start_tk
prev_tk = tk unless prev_tk
@buf.unshift tk # closing heredoc
heredoc_tk = {
:line_no => start_tk[:line_no],
:char_no => start_tk[:char_no],
:kind => :on_heredoc,
:text => string,
:state => prev_tk[:state]
}
@buf.unshift heredoc_tk
end
private def retrieve_heredoc_info(tk)
name = tk[:text].gsub(/\A<<[-~]?(['"`]?)(.+)\1\z/, '\2')
indent = tk[:text] =~ /\A<<[-~]/
[name, indent]
end
private def heredoc_end?(name, indent, tk)
result = false
if :on_heredoc_end == tk[:kind] then
tk_name = (indent ? tk[:text].gsub(/^ *(.+)\n?$/, '\1') : tk[:text].gsub(/\n\z/, ''))
if name == tk_name
result = true
end
end
result
end
private def get_words_tk(tk)
string = ''
start_token = tk[:text]
start_quote = tk[:text].rstrip[-1]
line_no = tk[:line_no]
char_no = tk[:char_no]
state = tk[:state]
end_quote =
case start_quote
when ?( then ?)
when ?[ then ?]
when ?{ then ?}
when ?< then ?>
else start_quote
end
end_token = nil
loop do
tk = get_squashed_tk
if tk.nil?
end_token = end_quote
break
elsif :on_tstring_content == tk[:kind] then
string += tk[:text]
elsif :on_words_sep == tk[:kind] or :on_tstring_end == tk[:kind] then
if end_quote == tk[:text].strip then
end_token = tk[:text]
break
else
string += tk[:text]
end
else
string += tk[:text]
end
end
text = "#{start_token}#{string}#{end_token}"
{
:line_no => line_no,
:char_no => char_no,
:kind => :on_dstring,
:text => text,
:state => state
}
end
private def get_op_tk(tk)
redefinable_operators = %w[! != !~ % & * ** + +@ - -@ / < << <= <=> == === =~ > >= >> [] []= ^ ` | ~]
if redefinable_operators.include?(tk[:text]) and EXPR_ARG == tk[:state] then
@inner_lex.lex_state = EXPR_ARG
tk[:kind] = :on_ident
tk[:state] = @inner_lex.lex_state
elsif tk[:text] =~ /^[-+]$/ then
tk_ahead = get_squashed_tk
case tk_ahead[:kind]
when :on_int, :on_float, :on_rational, :on_imaginary then
tk[:text] += tk_ahead[:text]
tk[:kind] = tk_ahead[:kind]
tk[:state] = tk_ahead[:state]
else
@buf.unshift tk_ahead
end
end
tk
end
def initialize(code)
@buf = []
@heredoc_queue = []
@inner_lex = InnerStateLex.new(code)
@inner_lex_enumerator = Enumerator.new do |y|
@inner_lex.each do |tk|
y << tk
end
end
end
def self.parse(code)
lex = self.new(code)
tokens = []
begin
while tk = lex.get_squashed_tk
tokens.push tk
end
rescue StopIteration
end
tokens
end
def self.end?(token)
(token[:state] & EXPR_END)
end
end

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -5,8 +5,6 @@
module RDoc::Parser::RubyTools
include RDoc::RubyToken
##
# Adds a token listener +obj+, but you should probably use token_listener
@ -22,16 +20,25 @@ module RDoc::Parser::RubyTools
tk = nil
if @tokens.empty? then
tk = @scanner.token
@read.push @scanner.get_readed
puts "get_tk1 => #{tk.inspect}" if $TOKEN_DEBUG
if @scanner_point >= @scanner.size
return nil
else
tk = @scanner[@scanner_point]
@scanner_point += 1
@read.push tk[:text]
puts "get_tk1 => #{tk.inspect}" if $TOKEN_DEBUG
end
else
@read.push @unget_read.shift
tk = @tokens.shift
puts "get_tk2 => #{tk.inspect}" if $TOKEN_DEBUG
end
tk = nil if TkEND_OF_SCRIPT === tk
if tk == nil || :on___end__ == tk[:kind]
tk = nil
end
return nil unless tk
# inform any listeners of our shiny new token
@token_listeners.each do |obj|
@ -102,19 +109,24 @@ module RDoc::Parser::RubyTools
@tokens = []
@unget_read = []
@nest = 0
@scanner_point = 0
end
def tk_nl?(tk)
:on_nl == tk[:kind] or :on_ignored_nl == tk[:kind]
end
##
# Skips whitespace tokens including newlines if +skip_nl+ is true
def skip_tkspace(skip_nl = true) # HACK dup
def skip_tkspace(skip_nl = true)
tokens = []
while TkSPACE === (tk = get_tk) or (skip_nl and TkNL === tk) do
tokens.push tk
while (tk = get_tk) and (:on_sp == tk[:kind] or (skip_nl and tk_nl?(tk))) do
tokens.push(tk)
end
unget_tk tk
unget_tk(tk)
tokens
end

Просмотреть файл

@ -677,54 +677,54 @@ Racc_debug_parser = false
# reduce 0 omitted
def _reduce_1(val, _values, result)
result = RDoc::Markup::Document.new(*val[0])
result = RDoc::Markup::Document.new(*val[0])
result
end
def _reduce_2(val, _values, result)
raise ParseError, "file empty"
raise ParseError, "file empty"
result
end
def _reduce_3(val, _values, result)
result = val[0].concat val[1]
result = val[0].concat val[1]
result
end
def _reduce_4(val, _values, result)
result = val[0]
result = val[0]
result
end
def _reduce_5(val, _values, result)
result = val
result = val
result
end
def _reduce_6(val, _values, result)
result = val
result = val
result
end
# reduce 7 omitted
def _reduce_8(val, _values, result)
result = val
result = val
result
end
def _reduce_9(val, _values, result)
result = val
result = val
result
end
def _reduce_10(val, _values, result)
result = [RDoc::Markup::BlankLine.new]
result = [RDoc::Markup::BlankLine.new]
result
end
def _reduce_11(val, _values, result)
result = val[0].parts
result = val[0].parts
result
end
@ -732,30 +732,30 @@ def _reduce_12(val, _values, result)
# val[0] is like [level, title]
title = @inline_parser.parse(val[0][1])
result = RDoc::Markup::Heading.new(val[0][0], title)
result
end
def _reduce_13(val, _values, result)
result = RDoc::Markup::Include.new val[0], @include_path
result
end
def _reduce_14(val, _values, result)
# val[0] is Array of String
result = paragraph val[0]
result
end
def _reduce_15(val, _values, result)
result << val[1].rstrip
result << val[1].rstrip
result
end
def _reduce_16(val, _values, result)
result = [val[0].rstrip]
result = [val[0].rstrip]
result
end
@ -766,7 +766,7 @@ def _reduce_17(val, _values, result)
# imform to lexer.
@in_verbatim = false
result
end
@ -777,25 +777,25 @@ def _reduce_18(val, _values, result)
# imform to lexer.
@in_verbatim = false
result
end
def _reduce_19(val, _values, result)
result << val[1]
result
end
def _reduce_20(val, _values, result)
result.concat val[2]
result
end
def _reduce_21(val, _values, result)
result << "\n"
result
end
@ -803,7 +803,7 @@ def _reduce_22(val, _values, result)
result = val
# inform to lexer.
@in_verbatim = true
result
end
@ -817,89 +817,89 @@ end
def _reduce_27(val, _values, result)
result = val[0]
result
end
def _reduce_28(val, _values, result)
result = val[1]
result
end
def _reduce_29(val, _values, result)
result = val[1].push(val[2])
result
end
def _reduce_30(val, _values, result)
result = val[0] << val[1]
result = val[0] << val[1]
result
end
def _reduce_31(val, _values, result)
result = [val[0]]
result = [val[0]]
result
end
def _reduce_32(val, _values, result)
result = RDoc::Markup::List.new :BULLET, *val[0]
result
end
def _reduce_33(val, _values, result)
result.push(val[1])
result.push(val[1])
result
end
def _reduce_34(val, _values, result)
result = val
result = val
result
end
def _reduce_35(val, _values, result)
result = RDoc::Markup::ListItem.new nil, val[0], *val[1]
result
end
def _reduce_36(val, _values, result)
result = RDoc::Markup::List.new :NUMBER, *val[0]
result
end
def _reduce_37(val, _values, result)
result.push(val[1])
result.push(val[1])
result
end
def _reduce_38(val, _values, result)
result = val
result = val
result
end
def _reduce_39(val, _values, result)
result = RDoc::Markup::ListItem.new nil, val[0], *val[1]
result
end
def _reduce_40(val, _values, result)
result = RDoc::Markup::List.new :NOTE, *val[0]
result
end
def _reduce_41(val, _values, result)
result.push(val[1])
result.push(val[1])
result
end
def _reduce_42(val, _values, result)
result = val
result = val
result
end
@ -907,77 +907,77 @@ def _reduce_43(val, _values, result)
term = @inline_parser.parse val[0].strip
result = RDoc::Markup::ListItem.new term, *val[1]
result
end
def _reduce_44(val, _values, result)
result = RDoc::Markup::List.new :LABEL, *val[0]
result
end
def _reduce_45(val, _values, result)
result.push(val[1])
result.push(val[1])
result
end
def _reduce_46(val, _values, result)
result = val
result = val
result
end
def _reduce_47(val, _values, result)
result = RDoc::Markup::ListItem.new "<tt>#{val[0].strip}</tt>", *val[1]
result
end
def _reduce_48(val, _values, result)
result = [val[1]].concat(val[2])
result
end
def _reduce_49(val, _values, result)
result = [val[1]]
result
end
def _reduce_50(val, _values, result)
result = val[2]
result
end
def _reduce_51(val, _values, result)
result = []
result
end
def _reduce_52(val, _values, result)
result.concat val[1]
result.concat val[1]
result
end
# reduce 53 omitted
def _reduce_54(val, _values, result)
result = val
result = val
result
end
def _reduce_55(val, _values, result)
result = val
result = val
result
end
# reduce 56 omitted
def _reduce_57(val, _values, result)
result = []
result = []
result
end
@ -991,58 +991,58 @@ end
def _reduce_62(val, _values, result)
result = paragraph [val[0]].concat(val[1])
result
end
def _reduce_63(val, _values, result)
result = paragraph [val[0]]
result
end
def _reduce_64(val, _values, result)
result = paragraph [val[0]].concat(val[1])
result
end
def _reduce_65(val, _values, result)
result = paragraph [val[0]]
result
end
def _reduce_66(val, _values, result)
result = [val[0]].concat(val[1])
result
end
def _reduce_67(val, _values, result)
result.concat val[1]
result.concat val[1]
result
end
def _reduce_68(val, _values, result)
result = val[1]
result = val[1]
result
end
def _reduce_69(val, _values, result)
result = val
result = val
result
end
# reduce 70 omitted
def _reduce_71(val, _values, result)
result = []
result = []
result
end
def _reduce_72(val, _values, result)
result = []
result = []
result
end

Просмотреть файл

@ -732,12 +732,12 @@ Racc_debug_parser = false
# reduce 1 omitted
def _reduce_2(val, _values, result)
result.append val[1]
result.append val[1]
result
end
def _reduce_3(val, _values, result)
result = val[0]
result = val[0]
result
end
@ -762,28 +762,28 @@ end
def _reduce_13(val, _values, result)
content = val[1]
result = inline "<em>#{content}</em>", content
result
end
def _reduce_14(val, _values, result)
content = val[1]
result = inline "<code>#{content}</code>", content
result
end
def _reduce_15(val, _values, result)
content = val[1]
result = inline "+#{content}+", content
result
end
def _reduce_16(val, _values, result)
content = val[1]
result = inline "<tt>#{content}</tt>", content
result
end
@ -791,13 +791,13 @@ def _reduce_17(val, _values, result)
label = val[1]
@block_parser.add_label label.reference
result = "<span id=\"label-#{label}\">#{label}</span>"
result
end
def _reduce_18(val, _values, result)
result = "{#{val[1]}}[#{val[2].join}]"
result
end
@ -805,13 +805,13 @@ def _reduce_19(val, _values, result)
scheme, inline = val[1]
result = "{#{inline}}[#{scheme}#{inline.reference}]"
result
end
def _reduce_20(val, _values, result)
result = [nil, inline(val[1])]
result
end
@ -820,25 +820,25 @@ def _reduce_21(val, _values, result)
'rdoc-label:',
inline("#{val[0].reference}/#{val[1].reference}")
]
result
end
def _reduce_22(val, _values, result)
result = ['rdoc-label:', val[0].reference]
result
end
def _reduce_23(val, _values, result)
result = ['rdoc-label:', "#{val[0].reference}/"]
result
end
def _reduce_24(val, _values, result)
result = [nil, inline(val[1])]
result
end
@ -847,92 +847,92 @@ def _reduce_25(val, _values, result)
'rdoc-label:',
inline("#{val[0].reference}/#{val[1].reference}")
]
result
end
def _reduce_26(val, _values, result)
result = ['rdoc-label:', val[0]]
result
end
def _reduce_27(val, _values, result)
ref = val[0].reference
result = ['rdoc-label:', inline(ref, "#{ref}/")]
result
end
# reduce 28 omitted
def _reduce_29(val, _values, result)
result = val[1]
result = val[1]
result
end
def _reduce_30(val, _values, result)
result = val[1]
result = val[1]
result
end
def _reduce_31(val, _values, result)
result = inline val[0]
result
end
def _reduce_32(val, _values, result)
result = inline "\"#{val[1]}\""
result
end
def _reduce_33(val, _values, result)
result = inline val[0]
result
end
def _reduce_34(val, _values, result)
result = inline "\"#{val[1]}\""
result
end
# reduce 35 omitted
def _reduce_36(val, _values, result)
result = val[1]
result = val[1]
result
end
def _reduce_37(val, _values, result)
result = inline val[1]
result = inline val[1]
result
end
def _reduce_38(val, _values, result)
result = val[0].append val[1]
result
end
def _reduce_39(val, _values, result)
result = val[0].append val[1]
result
end
def _reduce_40(val, _values, result)
result = val[0]
result
end
def _reduce_41(val, _values, result)
result = inline val[0]
result
end
@ -940,25 +940,25 @@ end
def _reduce_43(val, _values, result)
result = val[0].append val[1]
result
end
def _reduce_44(val, _values, result)
result = inline val[0]
result
end
def _reduce_45(val, _values, result)
result = val[0].append val[1]
result
end
def _reduce_46(val, _values, result)
result = val[0]
result
end
@ -984,24 +984,24 @@ end
def _reduce_57(val, _values, result)
result = val[0]
result
end
def _reduce_58(val, _values, result)
result = inline val[0]
result
end
def _reduce_59(val, _values, result)
result = inline val[0]
result
end
def _reduce_60(val, _values, result)
result << val[1]
result << val[1]
result
end
@ -1009,7 +1009,7 @@ end
def _reduce_62(val, _values, result)
result << val[1]
result
end
@ -1017,7 +1017,7 @@ end
def _reduce_64(val, _values, result)
result << val[1]
result
end
@ -1048,7 +1048,7 @@ end
# reduce 77 omitted
def _reduce_78(val, _values, result)
result << val[1]
result << val[1]
result
end
@ -1099,13 +1099,13 @@ end
def _reduce_101(val, _values, result)
index = @block_parser.add_footnote val[1].rdoc
result = "{*#{index}}[rdoc-label:foottext-#{index}:footmark-#{index}]"
result
end
def _reduce_102(val, _values, result)
result = inline "<tt>#{val[1]}</tt>", val[1]
result
end
@ -1122,7 +1122,7 @@ end
# reduce 108 omitted
def _reduce_109(val, _values, result)
result << val[1]
result << val[1]
result
end
@ -1130,24 +1130,24 @@ end
def _reduce_111(val, _values, result)
result = inline val[0]
result
end
# reduce 112 omitted
def _reduce_113(val, _values, result)
result = val[1]
result = val[1]
result
end
def _reduce_114(val, _values, result)
result = val[1]
result = val[1]
result
end
def _reduce_115(val, _values, result)
result = val[1]
result = val[1]
result
end
@ -1192,7 +1192,7 @@ end
# reduce 135 omitted
def _reduce_136(val, _values, result)
result << val[1]
result << val[1]
result
end

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,5 +1,5 @@
# frozen_string_literal: false
require 'io/console/size'
require 'io/console'
##
# Stats printer that prints just the files being documented with a progress
@ -23,7 +23,7 @@ class RDoc::Stats::Normal < RDoc::Stats::Quiet
# Print a progress bar, but make sure it fits on a single line. Filename
# will be truncated if necessary.
terminal_width = IO.console_size[1].to_i.nonzero? || 80
terminal_width = IO.console.winsize[1].to_i.nonzero? || 80
max_filename_size = terminal_width - progress_bar.size
if filename.size > max_filename_size then

Просмотреть файл

@ -30,28 +30,41 @@ module RDoc::TokenStream
token_stream.map do |t|
next unless t
style = case t
when RDoc::RubyToken::TkCONSTANT then 'ruby-constant'
when RDoc::RubyToken::TkKW then 'ruby-keyword'
when RDoc::RubyToken::TkIVAR then 'ruby-ivar'
when RDoc::RubyToken::TkOp then 'ruby-operator'
when RDoc::RubyToken::TkId then 'ruby-identifier'
when RDoc::RubyToken::TkREGEXP then 'ruby-regexp'
when RDoc::RubyToken::TkDREGEXP then 'ruby-regexp'
when RDoc::RubyToken::TkNode then 'ruby-node'
when RDoc::RubyToken::TkCOMMENT then 'ruby-comment'
when RDoc::RubyToken::TkXSTRING then 'ruby-string'
when RDoc::RubyToken::TkSTRING then 'ruby-string'
when RDoc::RubyToken::TkVal then 'ruby-value'
style = case t[:kind]
when :on_const then 'ruby-constant'
when :on_kw then 'ruby-keyword'
when :on_ivar then 'ruby-ivar'
when :on_cvar then 'ruby-identifier'
when :on_gvar then 'ruby-identifier'
when '=' != t[:text] && :on_op then
if RDoc::RipperStateLex::EXPR_ARG == t[:state] then
'ruby-identifier'
else
'ruby-operator'
end
when :on_tlambda then 'ruby-operator'
when :on_ident then 'ruby-identifier'
when :on_label then 'ruby-value'
when :on_backref, :on_dstring
then 'ruby-node'
when :on_comment then 'ruby-comment'
when :on_embdoc then 'ruby-comment'
when :on_regexp then 'ruby-regexp'
when :on_tstring then 'ruby-string'
when :on_int, :on_float,
:on_rational, :on_imaginary,
:on_heredoc,
:on_symbol, :on_CHAR then 'ruby-value'
when :on_heredoc_beg, :on_heredoc_end
then 'ruby-identifier'
end
comment_with_nl = false
case t
when RDoc::RubyToken::TkRD_COMMENT, RDoc::RubyToken::TkHEREDOCEND
comment_with_nl = true if t.text =~ /\n$/
text = t.text.rstrip
if :on_comment == t[:kind] or :on_embdoc == t[:kind] or :on_heredoc_end == t[:kind]
comment_with_nl = true if "\n" == t[:text][-1]
text = t[:text].rstrip
else
text = t.text
text = t[:text]
end
text = CGI.escapeHTML text

Просмотреть файл

@ -74,7 +74,7 @@ method(a, b) { |c, d| ... }
def test_markup_code
tokens = [
RDoc::RubyToken::TkCONSTANT. new(0, 0, 0, 'CONSTANT'),
{ :line_no => 0, :char_no => 0, :kind => :on_const, :text => 'CONSTANT' },
]
@c2_a.collect_tokens

Просмотреть файл

@ -86,7 +86,7 @@ class TestRDocConstant < XrefTestCase
assert_equal top_level, loaded.file
assert_equal 'Klass::CONST', loaded.full_name
assert_equal 'CONST', loaded.name
assert_nil loaded.visibility
assert_equal :public, loaded.visibility
assert_equal cm, loaded.parent
assert_equal section, loaded.section
end
@ -114,7 +114,7 @@ class TestRDocConstant < XrefTestCase
assert_equal top_level, loaded.file
assert_equal 'Klass::CONST', loaded.full_name
assert_equal 'CONST', loaded.name
assert_nil loaded.visibility
assert_equal :public, loaded.visibility
assert_equal cm, loaded.parent
assert_equal section, loaded.section
@ -146,7 +146,7 @@ class TestRDocConstant < XrefTestCase
assert_equal top_level, loaded.file
assert_equal 'Klass::CONST', loaded.full_name
assert_equal 'CONST', loaded.name
assert_nil loaded.visibility
assert_equal :public, loaded.visibility
assert_equal cm, loaded.parent
assert_equal section, loaded.section

Просмотреть файл

@ -719,6 +719,7 @@ class TestRDocContext < XrefTestCase
assert_equal [@pub, @prot, @priv], @vis.method_list
assert_equal [@apub, @aprot, @apriv], @vis.attributes
assert_equal [@cpub, @cpriv], @vis.constants
end
def test_remove_invisible_nodoc
@ -728,6 +729,7 @@ class TestRDocContext < XrefTestCase
assert_equal [@pub, @prot, @priv], @vis.method_list
assert_equal [@apub, @aprot, @apriv], @vis.attributes
assert_equal [@cpub, @cpriv], @vis.constants
end
def test_remove_invisible_protected
@ -737,6 +739,7 @@ class TestRDocContext < XrefTestCase
assert_equal [@pub, @prot], @vis.method_list
assert_equal [@apub, @aprot], @vis.attributes
assert_equal [@cpub], @vis.constants
end
def test_remove_invisible_public
@ -746,6 +749,7 @@ class TestRDocContext < XrefTestCase
assert_equal [@pub], @vis.method_list
assert_equal [@apub], @vis.attributes
assert_equal [@cpub], @vis.constants
end
def test_remove_invisible_public_force
@ -755,11 +759,13 @@ class TestRDocContext < XrefTestCase
@prot.force_documentation = true
@apriv.force_documentation = true
@aprot.force_documentation = true
@cpriv.force_documentation = true
@vis.remove_invisible :public
assert_equal [@pub, @prot, @priv], @vis.method_list
assert_equal [@apub, @aprot, @apriv], @vis.attributes
assert_equal [@cpub, @cpriv], @vis.constants
end
def test_remove_invisible_in_protected
@ -922,6 +928,9 @@ class TestRDocContext < XrefTestCase
@aprot = RDoc::Attr.new nil, 'prot', 'RW', nil
@apriv = RDoc::Attr.new nil, 'priv', 'RW', nil
@cpub = RDoc::Constant.new 'CONST_PUBLIC', nil, nil
@cpriv = RDoc::Constant.new 'CONST_PRIVATE', nil, nil
@vis = RDoc::NormalClass.new 'Vis'
@vis.add_method @pub
@vis.add_method @prot
@ -931,11 +940,16 @@ class TestRDocContext < XrefTestCase
@vis.add_attribute @aprot
@vis.add_attribute @apriv
@vis.add_constant @cpub
@vis.add_constant @cpriv
@prot.visibility = :protected
@priv.visibility = :private
@aprot.visibility = :protected
@apriv.visibility = :private
@cpriv.visibility = :private
end
end

Просмотреть файл

@ -452,6 +452,9 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase
end
def test_accept_verbatim_nl_after_backslash
# TODO: Remove "skip" after the issue is resolved: https://github.com/jruby/jruby/issues/4787
# This "skip" is for strange behavior around escaped newline on JRuby
skip if defined? JRUBY_VERSION
verb = @RM::Verbatim.new("a = 1 if first_flag_var and \\\n", " this_is_flag_var\n")
@to.start_accepting

Просмотреть файл

@ -1037,7 +1037,7 @@ Init_Foo(void) {
other_function.comment.text
assert_equal '()', other_function.params
code = other_function.token_stream.first.text
code = other_function.token_stream.first[:text]
assert_equal "VALUE\nother_function() {\n}", code
end
@ -1107,7 +1107,7 @@ Init_Foo(void) {
other_function.comment.text
assert_equal '()', other_function.params
code = other_function.token_stream.first.text
code = other_function.token_stream.first[:text]
assert_equal "VALUE\nother_function() {\n}", code
end
@ -1141,7 +1141,7 @@ Init_Foo(void) {
assert_equal '()', other_function.params
assert_equal 8, other_function.line
code = other_function.token_stream.first.text
code = other_function.token_stream.first[:text]
assert_equal "VALUE\nrb_other_function() {\n}", code
end
@ -1174,7 +1174,7 @@ Init_Foo(void) {
assert_equal '()', other_function.params
assert_equal 4, other_function.line
code = other_function.token_stream.first.text
code = other_function.token_stream.first[:text]
assert_equal "#define other_function rb_other_function", code
end
@ -1314,7 +1314,7 @@ Init_Foo(void) {
other_function.comment.text
assert_equal '()', other_function.params
code = other_function.token_stream.first.text
code = other_function.token_stream.first[:text]
assert_equal "DLL_LOCAL VALUE\nother_function() {\n}", code
end

Просмотреть файл

@ -74,7 +74,7 @@ class C; end
comment = parser.collect_first_comment
assert_equal RDoc::Comment.new("=begin\nfirst\n=end\n\n", @top_level), comment
assert_equal RDoc::Comment.new("=begin\nfirst\n=end\n", @top_level), comment
end
def test_get_class_or_module
@ -84,7 +84,7 @@ class C; end
cont, name_t, given_name = util_parser('A') .get_class_or_module ctxt
assert_equal ctxt, cont
assert_equal 'A', name_t.text
assert_equal 'A', name_t[:text]
assert_equal 'A', given_name
cont, name_t, given_name = util_parser('B::C') .get_class_or_module ctxt
@ -92,16 +92,16 @@ class C; end
b = @store.find_module_named('B')
assert_equal b, cont
assert_equal [@top_level], b.in_files
assert_equal 'C', name_t.text
assert_equal 'C', name_t[:text]
assert_equal 'B::C', given_name
cont, name_t, given_name = util_parser('D:: E').get_class_or_module ctxt
assert_equal @store.find_module_named('D'), cont
assert_equal 'E', name_t.text
assert_equal 'E', name_t[:text]
assert_equal 'D::E', given_name
assert_raises NoMethodError do
assert_raises RDoc::Error do
util_parser("A::\nB").get_class_or_module ctxt
end
end
@ -1194,10 +1194,12 @@ EOF
assert_equal klass.current_section, foo.section
stream = [
tk(:COMMENT, 0, 1, 1, nil,
"# File #{@top_level.relative_name}, line 1"),
RDoc::Parser::Ruby::NEWLINE_TOKEN,
tk(:SPACE, 0, 1, 1, nil, ''),
{
:line_no => 1, :char_no => 1, :kind => :on_comment,
:text => "# File #{@top_level.relative_name}, line 1"
},
{ :line_no => 0, :char_no => 0, :kind => :on_nl, :text => "\n" },
{ :line_no => 1, :char_no => 1, :kind => :on_sp, :text => '' }
]
assert_equal stream, foo.token_stream
@ -1358,6 +1360,33 @@ A::B::C = 1
assert_equal 'comment', c.comment
end
def test_parse_constant_with_bracket
util_parser <<-RUBY
class Klass
end
class Klass2
CONSTANT = Klass
end
class Klass3
CONSTANT_2 = {}
CONSTANT_2[1] = Klass
end
RUBY
@parser.scan
klass = @store.find_class_named 'Klass'
klass2 = @store.find_class_named 'Klass2'
klass3 = @store.find_class_named 'Klass3'
constant = klass2.find_module_named 'CONSTANT'
constant2 = klass3.find_module_named 'CONSTANT_2'
assert_equal klass, klass2.constants.first.is_alias_for
refute_equal klass, klass3.constants.first.is_alias_for
assert_nil klass3.find_module_named 'CONSTANT_2'
end
def test_parse_extend_or_include_extend
klass = RDoc::NormalClass.new 'C'
klass.parent = @top_level
@ -1434,20 +1463,30 @@ A::B::C = 1
assert_equal klass.current_section, foo.section
stream = [
tk(:COMMENT, 0, 1, 1, nil,
"# File #{@top_level.relative_name}, line 1"),
RDoc::Parser::Ruby::NEWLINE_TOKEN,
tk(:SPACE, 0, 1, 1, nil, ''),
tk(:IDENTIFIER, 0, 1, 0, 'add_my_method', 'add_my_method'),
tk(:SPACE, 0, 1, 13, nil, ' '),
tk(:SYMBOL, 0, 1, 14, nil, ':foo'),
tk(:COMMA, 0, 1, 18, nil, ','),
tk(:SPACE, 0, 1, 19, nil, ' '),
tk(:SYMBOL, 0, 1, 20, nil, ':bar'),
tk(:NL, 0, 1, 24, nil, "\n"),
{
:line_no => 1, :char_no => 1, :kind => :on_comment,
:text => "# File #{@top_level.relative_name}, line 1"
},
{ :line_no => 0, :char_no => 0, :kind => :on_nl, :text => "\n" },
{ :line_no => 1, :char_no => 1, :kind => :on_sp, :text => '' },
{ :line_no => 1, :char_no => 0, :kind => :on_ident, :text => 'add_my_method' },
{ :line_no => 1, :char_no => 13, :kind => :on_sp, :text => ' ' },
{ :line_no => 1, :char_no => 14, :kind => :on_symbol, :text => ':foo' },
{ :line_no => 1, :char_no => 18, :kind => :on_comma, :text => ',' },
{ :line_no => 1, :char_no => 19, :kind => :on_sp, :text => ' ' },
{ :line_no => 1, :char_no => 20, :kind => :on_symbol, :text => ':bar' },
{ :line_no => 1, :char_no => 24, :kind => :on_nl, :text => "\n" }
]
parsed_stream = foo.token_stream.map { |t|
{
:line_no => t[:line_no],
:char_no => t[:char_no],
:kind => t[:kind],
:text => t[:text]
}
}
assert_equal stream, foo.token_stream
assert_equal stream, parsed_stream
end
def test_parse_meta_method_block
@ -1468,7 +1507,10 @@ end
@parser.parse_meta_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
assert_equal tk(:NL, 0, 3, 3, 3, "\n"), @parser.get_tk
rest = { :line_no => 3, :char_no => 3, :kind => :on_nl, :text => "\n" }
tk = @parser.get_tk
tk = { :line_no => tk[:line_no], :char_no => tk[:char_no], :kind => tk[:kind], :text => tk[:text] }
assert_equal rest, tk
end
def test_parse_meta_method_define_method
@ -1631,23 +1673,30 @@ end
assert_equal klass.current_section, foo.section
stream = [
tk(:COMMENT, 0, 1, 1, nil,
"# File #{@top_level.relative_name}, line 1"),
RDoc::Parser::Ruby::NEWLINE_TOKEN,
tk(:SPACE, 0, 1, 1, nil, ''),
tk(:DEF, 0, 1, 0, 'def', 'def'),
tk(:SPACE, 3, 1, 3, nil, ' '),
tk(:IDENTIFIER, 4, 1, 4, 'foo', 'foo'),
tk(:LPAREN, 7, 1, 7, nil, '('),
tk(:RPAREN, 8, 1, 8, nil, ')'),
tk(:SPACE, 9, 1, 9, nil, ' '),
tk(:COLON, 10, 1, 10, nil, ':'),
tk(:IDENTIFIER, 11, 1, 11, 'bar', 'bar'),
tk(:SPACE, 14, 1, 14, nil, ' '),
tk(:END, 15, 1, 15, 'end', 'end'),
{
:line_no => 1, :char_no => 1, :kind => :on_comment,
:text => "# File #{@top_level.relative_name}, line 1" },
{ :line_no => 0, :char_no => 0, :kind => :on_nl, :text => "\n" },
{ :line_no => 1, :char_no => 1, :kind => :on_sp, :text => '' },
{ :line_no => 1, :char_no => 0, :kind => :on_kw, :text => 'def' },
{ :line_no => 1, :char_no => 3, :kind => :on_sp, :text => ' ' },
{ :line_no => 1, :char_no => 4, :kind => :on_ident, :text => 'foo' },
{ :line_no => 1, :char_no => 7, :kind => :on_lparen, :text => '(' },
{ :line_no => 1, :char_no => 8, :kind => :on_rparen, :text => ')' },
{ :line_no => 1, :char_no => 9, :kind => :on_sp, :text => ' ' },
{ :line_no => 1, :char_no => 10, :kind => :on_symbol, :text => ':bar' },
{ :line_no => 1, :char_no => 14, :kind => :on_sp, :text => ' ' },
{ :line_no => 1, :char_no => 15, :kind => :on_kw, :text => 'end' }
]
assert_equal stream, foo.token_stream
parsed_stream = foo.token_stream.map { |t|
{
:line_no => t[:line_no],
:char_no => t[:char_no],
:kind => t[:kind],
:text => t[:text]
}
}
assert_equal stream, parsed_stream
end
def test_parse_redefinable_methods
@ -1664,8 +1713,8 @@ end
end
klass.method_list.each do |method|
assert_kind_of RDoc::RubyToken::TkId, method.token_stream[5]
assert_includes redefinable_ops, method.token_stream[5].text
assert_equal :on_ident, method.token_stream[5][:kind]
assert_includes redefinable_ops, method.token_stream[5][:text]
end
end
@ -1909,6 +1958,20 @@ end
assert_equal '(arg1, arg2, arg3)', foo.params
end
def test_parse_method_parameters_with_paren_comment_continue
klass = RDoc::NormalClass.new 'Foo'
klass.parent = @top_level
util_parser "def foo(arg1, arg2, # some useful comment\narg3)\nend"
tk = @parser.get_tk
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, @comment
foo = klass.method_list.first
assert_equal '(arg1, arg2, arg3)', foo.params
end
def test_parse_method_star
klass = RDoc::NormalClass.new 'Foo'
klass.parent = @top_level
@ -2091,22 +2154,34 @@ end
assert_equal 2, x.method_list.length
a = x.method_list.first
expected = [
tk(:COMMENT, 0, 2, 1, nil, "# File #{@filename}, line 2"),
tk(:NL, 0, 0, 0, nil, "\n"),
tk(:SPACE, 0, 1, 1, nil, ''),
tk(:DEF, 8, 2, 0, 'def', 'def'),
tk(:SPACE, 11, 2, 3, nil, ' '),
tk(:IDENTIFIER, 12, 2, 4, 'a', 'a'),
tk(:NL, 13, 2, 5, nil, "\n"),
tk(:REGEXP, 14, 3, 0, nil, '%r{#}'),
tk(:NL, 19, 3, 5, nil, "\n"),
tk(:DREGEXP, 20, 4, 0, nil, '%r{#{}}'),
tk(:NL, 27, 4, 7, nil, "\n"),
tk(:END, 28, 5, 0, 'end', 'end'),
]
assert_equal expected, a.token_stream
expected = [
{
:line_no => 2, :char_no => 1, :kind => :on_comment,
:text => "# File #{@filename}, line 2"
},
{ :line_no => 0, :char_no => 0, :kind => :on_nl, :text => "\n" },
{ :line_no => 1, :char_no => 1, :kind => :on_sp, :text => '' },
{ :line_no => 2, :char_no => 0, :kind => :on_kw, :text => 'def' },
{ :line_no => 2, :char_no => 3, :kind => :on_sp, :text => ' ' },
{ :line_no => 2, :char_no => 4, :kind => :on_ident, :text => 'a' },
{ :line_no => 2, :char_no => 5, :kind => :on_nl, :text => "\n" },
{ :line_no => 3, :char_no => 0, :kind => :on_regexp, :text => '%r{#}' },
{ :line_no => 3, :char_no => 5, :kind => :on_nl, :text => "\n" },
{ :line_no => 4, :char_no => 0, :kind => :on_regexp, :text => '%r{#{}}' },
{ :line_no => 4, :char_no => 7, :kind => :on_nl, :text => "\n" },
{ :line_no => 5, :char_no => 0, :kind => :on_kw, :text => 'end' }
]
parsed_stream = a.token_stream.map { |tk|
{
:line_no => tk[:line_no],
:char_no => tk[:char_no],
:kind => tk[:kind],
:text => tk[:text]
}
}
assert_equal expected, parsed_stream
end
def test_parse_statements_encoding
@ -2286,6 +2361,9 @@ class Foo
SIXTH_CONSTANT = #{sixth_constant}
SEVENTH_CONSTANT = proc { |i| begin i end }
EIGHTH_CONSTANT = "a" \\
"b"
end
EOF
@ -2331,6 +2409,11 @@ EOF
assert_equal 'SEVENTH_CONSTANT', constant.name
assert_equal "proc { |i| begin i end }", constant.value
assert_equal @top_level, constant.file
constant = constants[7]
assert_equal 'EIGHTH_CONSTANT', constant.name
assert_equal "\"a\" \\\n\"b\"", constant.value
assert_equal @top_level, constant.file
end
def test_parse_statements_identifier_attr
@ -2504,7 +2587,7 @@ EXPTECTED
util_parser <<RUBY
class Foo
def blah()
<<~EOM if true
<<-EOM if true
EOM
end
end
@ -2512,7 +2595,7 @@ RUBY
expected = <<EXPTECTED
<span class="ruby-keyword">def</span> <span class="ruby-identifier">blah</span>()
<span class="ruby-identifier">&lt;&lt;~EOM</span> <span class="ruby-keyword">if</span> <span class="ruby-keyword">true</span>
<span class="ruby-identifier">&lt;&lt;-EOM</span> <span class="ruby-keyword">if</span> <span class="ruby-keyword">true</span>
<span class="ruby-value"></span><span class="ruby-identifier"> EOM</span>
<span class="ruby-keyword">end</span>
EXPTECTED
@ -2525,7 +2608,7 @@ EXPTECTED
blah = foo.method_list.first
markup_code = blah.markup_code.sub(/^.*\n/, '')
assert_equal markup_code, expected
assert_equal expected, markup_code
end
def test_parse_statements_method_oneliner_with_regexp
@ -2770,17 +2853,21 @@ RUBY
end
def test_parse_symbol_in_arg
util_parser ':blah "blah" "#{blah}" blah'
util_parser '[:blah, "blah", "#{blah}", blah]'
@parser.get_tk # skip '['
assert_equal 'blah', @parser.parse_symbol_in_arg
@parser.get_tk # skip ','
@parser.skip_tkspace
assert_equal 'blah', @parser.parse_symbol_in_arg
@parser.get_tk # skip ','
@parser.skip_tkspace
assert_equal nil, @parser.parse_symbol_in_arg
@parser.get_tk # skip ','
@parser.skip_tkspace
@ -2888,7 +2975,7 @@ end
assert_equal 'category', directive
assert_equal 'test', value
assert_kind_of RDoc::RubyToken::TkNL, parser.get_tk
assert_equal nil, parser.get_tk
end
def test_read_directive_allow
@ -2898,7 +2985,7 @@ end
assert_nil directive
assert_kind_of RDoc::RubyToken::TkNL, parser.get_tk
assert_equal nil, parser.get_tk
end
def test_read_directive_empty
@ -2908,7 +2995,7 @@ end
assert_nil directive
assert_kind_of RDoc::RubyToken::TkNL, parser.get_tk
assert_equal nil, parser.get_tk
end
def test_read_directive_no_comment
@ -2918,18 +3005,18 @@ end
assert_nil directive
assert_kind_of RDoc::RubyToken::TkNL, parser.get_tk
assert_equal nil, parser.get_tk
end
def test_read_directive_one_liner
parser = util_parser '; end # :category: test'
parser = util_parser 'AAA = 1 # :category: test'
directive, value = parser.read_directive %w[category]
assert_equal 'category', directive
assert_equal 'test', value
assert_kind_of RDoc::RubyToken::TkSEMICOLON, parser.get_tk
assert_equal :on_const, parser.get_tk[:kind]
end
def test_read_documentation_modifiers
@ -2974,10 +3061,10 @@ end
def test_sanity_integer
util_parser '1'
assert_equal '1', @parser.get_tk.text
assert_equal '1', @parser.get_tk[:text]
util_parser '1.0'
assert_equal '1.0', @parser.get_tk.text
assert_equal '1.0', @parser.get_tk[:text]
end
def test_sanity_interpolation
@ -2986,7 +3073,7 @@ end
while tk = @parser.get_tk do last_tk = tk end
assert_equal "\n", last_tk.text
assert_equal 'end', last_tk[:text]
end
# If you're writing code like this you're doing it wrong
@ -2994,15 +3081,15 @@ end
def test_sanity_interpolation_crazy
util_parser '"#{"#{"a")}" if b}"'
assert_equal '"#{"#{"a")}" if b}"', @parser.get_tk.text
assert_equal RDoc::RubyToken::TkNL, @parser.get_tk.class
assert_equal '"#{"#{"a")}" if b}"', @parser.get_tk[:text]
assert_equal nil, @parser.get_tk
end
def test_sanity_interpolation_curly
util_parser '%{ #{} }'
assert_equal '%{ #{} }', @parser.get_tk.text
assert_equal RDoc::RubyToken::TkNL, @parser.get_tk.class
assert_equal '%{ #{} }', @parser.get_tk[:text]
assert_equal nil, @parser.get_tk
end
def test_sanity_interpolation_format
@ -3537,6 +3624,53 @@ end
assert_equal 2, public_method_count
end
def test_scan_constant_visibility
util_parser <<-RUBY
class C
CONST_A = 123
CONST_B = 234
private_constant :CONST_B
CONST_C = 345
public_constant :CONST_C
end
RUBY
@parser.scan
c = @store.find_class_named 'C'
const_a, const_b, const_c, const_d = c.constants.sort_by(&:name)
assert_equal 'CONST_A', const_a.name
assert_equal :public, const_a.visibility
assert_equal 'CONST_B', const_b.name
assert_equal :private, const_b.visibility
assert_equal 'CONST_C', const_c.name
assert_equal :public, const_c.visibility
end
def test_document_after_rescue_inside_paren
util_parser <<-RUBY
class C
attr_accessor :sample if (1.inexistent_method rescue false)
# first
# second
def a
end
end
RUBY
@parser.scan
c = @store.find_class_named 'C'
c_a = c.find_method_named 'a'
assert_equal "first\nsecond", c_a.comment.text
end
def test_singleton_method_via_eigenclass
util_parser <<-RUBY
class C

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -5,17 +5,17 @@ class TestRDocTokenStream < RDoc::TestCase
def test_class_to_html
tokens = [
RDoc::RubyToken::TkCONSTANT. new(0, 0, 0, 'CONSTANT'),
RDoc::RubyToken::TkDEF. new(0, 0, 0, 'KW'),
RDoc::RubyToken::TkIVAR. new(0, 0, 0, 'IVAR'),
RDoc::RubyToken::TkOp. new(0, 0, 0, 'Op'),
RDoc::RubyToken::TkId. new(0, 0, 0, 'Id'),
RDoc::RubyToken::TkNode. new(0, 0, 0, 'Node'),
RDoc::RubyToken::TkCOMMENT. new(0, 0, 0, 'COMMENT'),
RDoc::RubyToken::TkREGEXP. new(0, 0, 0, 'REGEXP'),
RDoc::RubyToken::TkSTRING. new(0, 0, 0, 'STRING'),
RDoc::RubyToken::TkVal. new(0, 0, 0, 'Val'),
RDoc::RubyToken::TkBACKSLASH.new(0, 0, 0, '\\'),
{ :line_no => 0, :char_no => 0, :kind => :on_const, :text => 'CONSTANT' },
{ :line_no => 0, :char_no => 0, :kind => :on_kw, :text => 'KW' },
{ :line_no => 0, :char_no => 0, :kind => :on_ivar, :text => 'IVAR' },
{ :line_no => 0, :char_no => 0, :kind => :on_op, :text => 'Op' },
{ :line_no => 0, :char_no => 0, :kind => :on_ident, :text => 'Id' },
{ :line_no => 0, :char_no => 0, :kind => :on_backref, :text => 'Node' },
{ :line_no => 0, :char_no => 0, :kind => :on_comment, :text => 'COMMENT' },
{ :line_no => 0, :char_no => 0, :kind => :on_regexp, :text => 'REGEXP' },
{ :line_no => 0, :char_no => 0, :kind => :on_tstring, :text => 'STRING' },
{ :line_no => 0, :char_no => 0, :kind => :on_int, :text => 'Val' },
{ :line_no => 0, :char_no => 0, :kind => :on_unknown, :text => '\\' }
]
expected = [