Skip to content

Commit 90f73be

Browse files
committed
Merge remote-tracking branch 'upstream/master' into fix-regexp-literal-in-oneliner
2 parents bf49394 + 9789e6f commit 90f73be

File tree

5 files changed

+411
-26
lines changed

5 files changed

+411
-26
lines changed

lib/rdoc/parser/ruby.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,9 @@ def parse_class container, single, tk, comment
752752

753753
cls.line = line_no
754754

755+
# after end modifiers
756+
read_documentation_modifiers cls, RDoc::CLASS_MODIFIERS
757+
755758
cls
756759
end
757760

@@ -1311,6 +1314,9 @@ def parse_method(container, single, tk, comment)
13111314

13121315
meth.comment = comment
13131316

1317+
# after end modifiers
1318+
read_documentation_modifiers meth, RDoc::METHOD_MODIFIERS
1319+
13141320
@stats.add_method meth
13151321
end
13161322

@@ -1543,6 +1549,9 @@ def parse_module container, single, tk, comment
15431549
mod.add_comment comment, @top_level
15441550
parse_statements mod
15451551

1552+
# after end modifiers
1553+
read_documentation_modifiers mod, RDoc::CLASS_MODIFIERS
1554+
15461555
@stats.add_module mod
15471556
end
15481557

@@ -1716,7 +1725,6 @@ def parse_statements(container, single = NORMAL, current_method = nil,
17161725
when TkEND then
17171726
nest -= 1
17181727
if nest == 0 then
1719-
read_documentation_modifiers container, RDoc::CLASS_MODIFIERS
17201728
container.ongoing_visibility = save_visibility
17211729

17221730
parse_comment container, tk, comment unless comment.empty?

lib/rdoc/ruby_lex.rb

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ def token
381381
else
382382
tk = tk1
383383
end
384+
elsif (TkPLUS === tk or TkMINUS === tk) and peek(0) =~ /\d/ then
385+
tk1 = token
386+
set_token_position tk.seek, tk.line_no, tk.char_no
387+
tk = Token(tk1.class, tk.text + tk1.text)
384388
end
385389
# Tracer.off
386390
tk
@@ -605,6 +609,7 @@ def lex_init()
605609
Token(TkQUESTION)
606610
else
607611
@lex_state = :EXPR_END
612+
ch << getc if "\\" == ch
608613
Token(TkCHAR, "?#{ch}")
609614
end
610615
end
@@ -886,7 +891,8 @@ def lex_int2
886891
identify_quotation
887892
elsif peek(0) == '='
888893
getc
889-
Token(TkOPASGN, :%)
894+
@lex_state = :EXPR_BEG
895+
Token(TkOPASGN, '%')
890896
elsif @lex_state == :EXPR_ARG and @space_seen and peek(0) !~ /\s/
891897
identify_quotation
892898
else
@@ -988,7 +994,7 @@ def identify_identifier
988994

989995
ungetc
990996

991-
if (ch == "!" || ch == "?") && token[0,1] =~ /\w/ && peek(0) != "="
997+
if ((ch == "!" && peek(1) != "=") || ch == "?") && token[0,1] =~ /\w/
992998
token.concat getc
993999
end
9941000

@@ -1049,12 +1055,7 @@ def identify_identifier
10491055
@indent_stack.push token_c
10501056
end
10511057
else
1052-
if peek(0) == ':' and !peek_match?(/^::/)
1053-
token.concat getc
1054-
token_c = TkSYMBOL
1055-
else
1056-
token_c = TkIDENTIFIER
1057-
end
1058+
token_c = TkIDENTIFIER
10581059
end
10591060

10601061
elsif DEINDENT_CLAUSE.include?(token)
@@ -1066,13 +1067,17 @@ def identify_identifier
10661067
@lex_state = :EXPR_END
10671068
end
10681069
end
1070+
if token_c.ancestors.include?(TkId) and peek(0) == ':' and !peek_match?(/^::/)
1071+
token.concat getc
1072+
token_c = TkSYMBOL
1073+
end
10691074
return Token(token_c, token)
10701075
end
10711076
end
10721077

10731078
if @lex_state == :EXPR_FNAME
10741079
@lex_state = :EXPR_END
1075-
if peek(0) == '='
1080+
if peek(0) == '=' and peek(1) != '>'
10761081
token.concat getc
10771082
end
10781083
elsif @lex_state == :EXPR_BEG || @lex_state == :EXPR_DOT ||
@@ -1084,19 +1089,20 @@ def identify_identifier
10841089

10851090
if token[0, 1] =~ /[A-Z]/
10861091
if token[-1] =~ /[!?]/
1087-
return Token(TkIDENTIFIER, token)
1092+
token_c = TkIDENTIFIER
10881093
else
1089-
return Token(TkCONSTANT, token)
1094+
token_c = TkCONSTANT
10901095
end
10911096
elsif token[token.size - 1, 1] =~ /[!?]/
1092-
return Token(TkFID, token)
1097+
token_c = TkFID
10931098
else
1094-
if peek(0) == ':' and !peek_match?(/^::/)
1095-
token.concat getc
1096-
return Token(TkSYMBOL, token)
1097-
else
1098-
return Token(TkIDENTIFIER, token)
1099-
end
1099+
token_c = TkIDENTIFIER
1100+
end
1101+
if peek(0) == ':' and !peek_match?(/^::/)
1102+
token.concat getc
1103+
return Token(TkSYMBOL, token)
1104+
else
1105+
return Token(token_c, token)
11001106
end
11011107
end
11021108

@@ -1135,7 +1141,7 @@ def identify_here_document(op)
11351141
indent: indent,
11361142
started: false
11371143
}
1138-
@lex_state = :EXPR_BEG
1144+
@lex_state = :EXPR_END
11391145
Token(RDoc::RubyLex::TkHEREDOCBEG, start_token)
11401146
end
11411147

@@ -1334,13 +1340,13 @@ def identify_string(ltype, quoted = ltype, type = nil)
13341340
ungetc
13351341
end
13361342
elsif ch == '\\'
1337-
if %w[' /].include? @ltype then
1343+
case @ltype
1344+
when "'" then
13381345
case ch = getc
1339-
when "\n", "'"
1340-
when @ltype
1346+
when "'", '\\' then
13411347
str << ch
13421348
else
1343-
ungetc
1349+
str << ch
13441350
end
13451351
else
13461352
str << read_escape

test/test_rdoc_markup_to_html.rb

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,66 @@ def test_accept_verbatim_pipe
485485
assert_equal expected, @to.res.join
486486
end
487487

488+
def test_accept_verbatim_escape_in_string
489+
code = <<-'RUBY'
490+
def foo
491+
[
492+
'\\',
493+
'\'',
494+
"'",
495+
"\'\"\`",
496+
"\#",
497+
"\#{}",
498+
"#",
499+
"#{}",
500+
/'"/,
501+
/\'\"/,
502+
/\//,
503+
/\\/,
504+
/\#/,
505+
/\#{}/,
506+
/#/,
507+
/#{}/
508+
]
509+
end
510+
def bar
511+
end
512+
RUBY
513+
verb = @RM::Verbatim.new(*code.split(/(?<=\n)/))
514+
515+
@to.start_accepting
516+
@to.accept_verbatim verb
517+
518+
expected = <<-'EXPECTED'
519+
520+
<pre class="ruby"><span class="ruby-keyword">def</span> <span class="ruby-identifier">foo</span>
521+
[
522+
<span class="ruby-string">&#39;\\&#39;</span>,
523+
<span class="ruby-string">&#39;\&#39;&#39;</span>,
524+
<span class="ruby-string">&quot;&#39;&quot;</span>,
525+
<span class="ruby-string">&quot;\&#39;\&quot;\`&quot;</span>,
526+
<span class="ruby-string">&quot;\#&quot;</span>,
527+
<span class="ruby-string">&quot;\#{}&quot;</span>,
528+
<span class="ruby-string">&quot;#&quot;</span>,
529+
<span class="ruby-node">&quot;#{}&quot;</span>,
530+
<span class="ruby-regexp">/&#39;&quot;/</span>,
531+
<span class="ruby-regexp">/\&#39;\&quot;/</span>,
532+
<span class="ruby-regexp">/\//</span>,
533+
<span class="ruby-regexp">/\\/</span>,
534+
<span class="ruby-regexp">/\#/</span>,
535+
<span class="ruby-regexp">/\#{}/</span>,
536+
<span class="ruby-regexp">/#/</span>,
537+
<span class="ruby-regexp">/#{}/</span>
538+
]
539+
<span class="ruby-keyword">end</span>
540+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">bar</span>
541+
<span class="ruby-keyword">end</span>
542+
</pre>
543+
EXPECTED
544+
545+
assert_equal expected, @to.res.join
546+
end
547+
488548
def test_accept_verbatim_ruby
489549
verb = @RM::Verbatim.new("1 + 1\n")
490550
verb.format = :ruby

test/test_rdoc_parser_ruby.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,6 +2535,31 @@ def test_parse_require_dynamic_string
25352535
assert_equal 1, @top_level.requires.length
25362536
end
25372537

2538+
def test_parse_postfix_nodoc
2539+
util_parser <<-RUBY
2540+
class A
2541+
end # :nodoc:
2542+
2543+
class B
2544+
def a
2545+
end # :nodoc:
2546+
2547+
def b
2548+
end
2549+
end
2550+
RUBY
2551+
2552+
@parser.parse_statements @top_level
2553+
2554+
c_a = @top_level.classes.select(&:document_self).first
2555+
assert_equal 'B', c_a.full_name
2556+
2557+
assert_equal 2, @top_level.classes.length
2558+
assert_equal 1, @top_level.classes.count(&:document_self)
2559+
assert_equal 1, c_a.method_list.length
2560+
assert_equal 'B#b', c_a.method_list.first.full_name
2561+
end
2562+
25382563
def test_parse_statements_identifier_require
25392564
content = "require 'bar'"
25402565

0 commit comments

Comments
 (0)