Skip to content

Commit c0625f2

Browse files
committed
Merge remote-tracking branch 'upstream/master' into fix-backtick-handling
2 parents ec1fd0e + 31658f2 commit c0625f2

File tree

6 files changed

+307
-31
lines changed

6 files changed

+307
-31
lines changed

lib/rdoc.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Error < RuntimeError; end
6565
##
6666
# RDoc version you are using
6767

68-
VERSION = '5.1.0'
68+
VERSION = '6.0.0.beta1'
6969

7070
##
7171
# Method visibilities

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

@@ -1542,6 +1548,9 @@ def parse_module container, single, tk, comment
15421548
mod.add_comment comment, @top_level
15431549
parse_statements mod
15441550

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

@@ -1715,7 +1724,6 @@ def parse_statements(container, single = NORMAL, current_method = nil,
17151724
when TkEND then
17161725
nest -= 1
17171726
if nest == 0 then
1718-
read_documentation_modifiers container, RDoc::CLASS_MODIFIERS
17191727
container.ongoing_visibility = save_visibility
17201728

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

lib/rdoc/ruby_lex.rb

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,10 @@ def token
378378
else
379379
tk = tk1
380380
end
381+
elsif (TkPLUS === tk or TkMINUS === tk) and peek(0) =~ /\d/ then
382+
tk1 = token
383+
set_token_position tk.seek, tk.line_no, tk.char_no
384+
tk = Token(tk1.class, tk.text + tk1.text)
381385
end
382386
# Tracer.off
383387
tk
@@ -668,16 +672,16 @@ def lex_init()
668672
end
669673
end
670674

671-
@OP.def_rule(".") do
675+
@OP.def_rules(".", "&.") do
672676
|op, io|
673677
@lex_state = :EXPR_BEG
674678
if peek(0) =~ /[0-9]/
675679
ungetc
676680
identify_number
677681
else
678-
# for "obj.if" etc.
682+
# for "obj.if" or "obj&.if" etc.
679683
@lex_state = :EXPR_DOT
680-
Token(TkDOT)
684+
Token(op)
681685
end
682686
end
683687

@@ -883,7 +887,8 @@ def lex_int2
883887
identify_quotation
884888
elsif peek(0) == '='
885889
getc
886-
Token(TkOPASGN, :%)
890+
@lex_state = :EXPR_BEG
891+
Token(TkOPASGN, '%')
887892
elsif @lex_state == :EXPR_ARG and @space_seen and peek(0) !~ /\s/
888893
identify_quotation
889894
else
@@ -985,7 +990,7 @@ def identify_identifier
985990

986991
ungetc
987992

988-
if (ch == "!" || ch == "?") && token[0,1] =~ /\w/ && peek(0) != "="
993+
if ((ch == "!" && peek(1) != "=") || ch == "?") && token[0,1] =~ /\w/
989994
token.concat getc
990995
end
991996

@@ -1046,12 +1051,7 @@ def identify_identifier
10461051
@indent_stack.push token_c
10471052
end
10481053
else
1049-
if peek(0) == ':' and !peek_match?(/^::/)
1050-
token.concat getc
1051-
token_c = TkSYMBOL
1052-
else
1053-
token_c = TkIDENTIFIER
1054-
end
1054+
token_c = TkIDENTIFIER
10551055
end
10561056

10571057
elsif DEINDENT_CLAUSE.include?(token)
@@ -1063,13 +1063,17 @@ def identify_identifier
10631063
@lex_state = :EXPR_END
10641064
end
10651065
end
1066+
if token_c.ancestors.include?(TkId) and peek(0) == ':' and !peek_match?(/^::/)
1067+
token.concat getc
1068+
token_c = TkSYMBOL
1069+
end
10661070
return Token(token_c, token)
10671071
end
10681072
end
10691073

10701074
if @lex_state == :EXPR_FNAME
10711075
@lex_state = :EXPR_END
1072-
if peek(0) == '='
1076+
if peek(0) == '=' and peek(1) != '>'
10731077
token.concat getc
10741078
end
10751079
elsif @lex_state == :EXPR_BEG || @lex_state == :EXPR_DOT ||
@@ -1081,19 +1085,20 @@ def identify_identifier
10811085

10821086
if token[0, 1] =~ /[A-Z]/
10831087
if token[-1] =~ /[!?]/
1084-
return Token(TkIDENTIFIER, token)
1088+
token_c = TkIDENTIFIER
10851089
else
1086-
return Token(TkCONSTANT, token)
1090+
token_c = TkCONSTANT
10871091
end
10881092
elsif token[token.size - 1, 1] =~ /[!?]/
1089-
return Token(TkFID, token)
1093+
token_c = TkFID
10901094
else
1091-
if peek(0) == ':' and !peek_match?(/^::/)
1092-
token.concat getc
1093-
return Token(TkSYMBOL, token)
1094-
else
1095-
return Token(TkIDENTIFIER, token)
1096-
end
1095+
token_c = TkIDENTIFIER
1096+
end
1097+
if peek(0) == ':' and !peek_match?(/^::/)
1098+
token.concat getc
1099+
return Token(TkSYMBOL, token)
1100+
else
1101+
return Token(token_c, token)
10971102
end
10981103
end
10991104

@@ -1132,7 +1137,7 @@ def identify_here_document(op)
11321137
indent: indent,
11331138
started: false
11341139
}
1135-
@lex_state = :EXPR_BEG
1140+
@lex_state = :EXPR_END
11361141
Token(RDoc::RubyLex::TkHEREDOCBEG, start_token)
11371142
end
11381143

@@ -1331,13 +1336,14 @@ def identify_string(ltype, quoted = ltype, type = nil)
13311336
ungetc
13321337
end
13331338
elsif ch == '\\'
1334-
if %w[' /].include? @ltype then
1339+
case @ltype
1340+
when "'" then
13351341
case ch = getc
1336-
when "\n", "'"
1337-
when @ltype
1342+
when "'", '\\' then
13381343
str << ch
13391344
else
1340-
ungetc
1345+
str << '\\'
1346+
str << ch
13411347
end
13421348
else
13431349
str << read_escape

lib/rdoc/ruby_token.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ def Token(token, value = nil)
303303
[:TkIN, TkKW, "in", :EXPR_BEG],
304304
[:TkDO, TkKW, "do", :EXPR_BEG],
305305
[:TkRETURN, TkKW, "return", :EXPR_MID],
306-
[:TkYIELD, TkKW, "yield", :EXPR_END],
307-
[:TkSUPER, TkKW, "super", :EXPR_END],
306+
[:TkYIELD, TkKW, "yield", :EXPR_ARG],
307+
[:TkSUPER, TkKW, "super", :EXPR_ARG],
308308
[:TkSELF, TkKW, "self", :EXPR_END],
309309
[:TkNIL, TkKW, "nil", :EXPR_END],
310310
[:TkTRUE, TkKW, "true", :EXPR_END],
@@ -317,7 +317,7 @@ def Token(token, value = nil)
317317
[:TkWHILE_MOD, TkKW],
318318
[:TkUNTIL_MOD, TkKW],
319319
[:TkALIAS, TkKW, "alias", :EXPR_FNAME],
320-
[:TkDEFINED, TkKW, "defined?", :EXPR_END],
320+
[:TkDEFINED, TkKW, "defined?", :EXPR_ARG],
321321
[:TklBEGIN, TkKW, "BEGIN", :EXPR_END],
322322
[:TklEND, TkKW, "END", :EXPR_END],
323323
[:Tk__LINE__, TkKW, "__LINE__", :EXPR_END],
@@ -401,6 +401,7 @@ def Token(token, value = nil)
401401

402402
[:TkASSIGN, Token, "="],
403403
[:TkDOT, Token, "."],
404+
[:TkSAFENAV, Token, "&."],
404405
[:TkLPAREN, Token, "("], #(exp)
405406
[:TkLBRACK, Token, "["], #[arry]
406407
[:TkLBRACE, Token, "{"], #{hash}

test/test_rdoc_parser_ruby.rb

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2499,6 +2499,35 @@ def blah()
24992499
assert_equal markup_code, expected
25002500
end
25012501

2502+
def test_parse_statements_postfix_if_after_heredocbeg
2503+
@filename = 'file.rb'
2504+
util_parser <<RUBY
2505+
class Foo
2506+
def blah()
2507+
<<~EOM if true
2508+
EOM
2509+
end
2510+
end
2511+
RUBY
2512+
2513+
expected = <<EXPTECTED
2514+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">blah</span>()
2515+
<span class="ruby-identifier">&lt;&lt;~EOM</span> <span class="ruby-keyword">if</span> <span class="ruby-keyword">true</span>
2516+
<span class="ruby-value"></span><span class="ruby-identifier"> EOM
2517+
</span> <span class="ruby-keyword">end</span>
2518+
EXPTECTED
2519+
expected = expected.rstrip
2520+
2521+
@parser.scan
2522+
2523+
foo = @top_level.classes.first
2524+
assert_equal 'Foo', foo.full_name
2525+
2526+
blah = foo.method_list.first
2527+
markup_code = blah.markup_code.sub(/^.*\n/, '')
2528+
assert_equal markup_code, expected
2529+
end
2530+
25022531
def test_parse_require_dynamic_string
25032532
content = <<-RUBY
25042533
prefix = 'path'
@@ -2513,6 +2542,31 @@ def test_parse_require_dynamic_string
25132542
assert_equal 1, @top_level.requires.length
25142543
end
25152544

2545+
def test_parse_postfix_nodoc
2546+
util_parser <<-RUBY
2547+
class A
2548+
end # :nodoc:
2549+
2550+
class B
2551+
def a
2552+
end # :nodoc:
2553+
2554+
def b
2555+
end
2556+
end
2557+
RUBY
2558+
2559+
@parser.parse_statements @top_level
2560+
2561+
c_a = @top_level.classes.select(&:document_self).first
2562+
assert_equal 'B', c_a.full_name
2563+
2564+
assert_equal 2, @top_level.classes.length
2565+
assert_equal 1, @top_level.classes.count(&:document_self)
2566+
assert_equal 1, c_a.method_list.length
2567+
assert_equal 'B#b', c_a.method_list.first.full_name
2568+
end
2569+
25162570
def test_parse_statements_identifier_require
25172571
content = "require 'bar'"
25182572

0 commit comments

Comments
 (0)