Skip to content

Commit 16eda99

Browse files
committed
Merge remote-tracking branch 'upstream/master' into fix-handling-embdoc
2 parents dd2eac5 + 8fc1624 commit 16eda99

File tree

5 files changed

+268
-28
lines changed

5 files changed

+268
-28
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/ruby_lex.rb

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -671,16 +671,16 @@ def lex_init()
671671
end
672672
end
673673

674-
@OP.def_rule(".") do
674+
@OP.def_rules(".", "&.") do
675675
|op, io|
676676
@lex_state = :EXPR_BEG
677677
if peek(0) =~ /[0-9]/
678678
ungetc
679679
identify_number
680680
else
681-
# for "obj.if" etc.
681+
# for "obj.if" or "obj&.if" etc.
682682
@lex_state = :EXPR_DOT
683-
Token(TkDOT)
683+
Token(op)
684684
end
685685
end
686686

@@ -1049,12 +1049,7 @@ def identify_identifier
10491049
@indent_stack.push token_c
10501050
end
10511051
else
1052-
if peek(0) == ':' and !peek_match?(/^::/)
1053-
token.concat getc
1054-
token_c = TkSYMBOL
1055-
else
1056-
token_c = TkIDENTIFIER
1057-
end
1052+
token_c = TkIDENTIFIER
10581053
end
10591054

10601055
elsif DEINDENT_CLAUSE.include?(token)
@@ -1066,13 +1061,17 @@ def identify_identifier
10661061
@lex_state = :EXPR_END
10671062
end
10681063
end
1064+
if token_c.ancestors.include?(TkId) and peek(0) == ':' and !peek_match?(/^::/)
1065+
token.concat getc
1066+
token_c = TkSYMBOL
1067+
end
10691068
return Token(token_c, token)
10701069
end
10711070
end
10721071

10731072
if @lex_state == :EXPR_FNAME
10741073
@lex_state = :EXPR_END
1075-
if peek(0) == '='
1074+
if peek(0) == '=' and peek(1) != '>'
10761075
token.concat getc
10771076
end
10781077
elsif @lex_state == :EXPR_BEG || @lex_state == :EXPR_DOT ||
@@ -1084,19 +1083,20 @@ def identify_identifier
10841083

10851084
if token[0, 1] =~ /[A-Z]/
10861085
if token[-1] =~ /[!?]/
1087-
return Token(TkIDENTIFIER, token)
1086+
token_c = TkIDENTIFIER
10881087
else
1089-
return Token(TkCONSTANT, token)
1088+
token_c = TkCONSTANT
10901089
end
10911090
elsif token[token.size - 1, 1] =~ /[!?]/
1092-
return Token(TkFID, token)
1091+
token_c = TkFID
10931092
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
1093+
token_c = TkIDENTIFIER
1094+
end
1095+
if peek(0) == ':' and !peek_match?(/^::/)
1096+
token.concat getc
1097+
return Token(TkSYMBOL, token)
1098+
else
1099+
return Token(token_c, token)
11001100
end
11011101
end
11021102

@@ -1135,7 +1135,7 @@ def identify_here_document(op)
11351135
indent: indent,
11361136
started: false
11371137
}
1138-
@lex_state = :EXPR_BEG
1138+
@lex_state = :EXPR_END
11391139
Token(RDoc::RubyLex::TkHEREDOCBEG, start_token)
11401140
end
11411141

@@ -1334,13 +1334,14 @@ def identify_string(ltype, quoted = ltype, type = nil)
13341334
ungetc
13351335
end
13361336
elsif ch == '\\'
1337-
if %w[' /].include? @ltype then
1337+
case @ltype
1338+
when "'" then
13381339
case ch = getc
1339-
when "\n", "'"
1340-
when @ltype
1340+
when "'", '\\' then
13411341
str << ch
13421342
else
1343-
ungetc
1343+
str << '\\'
1344+
str << ch
13441345
end
13451346
else
13461347
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_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

0 commit comments

Comments
 (0)