Skip to content

Commit 8dac3fd

Browse files
committed
Merge remote-tracking branch 'upstream/master' into fix-postfix-if-after-escaped-newline
2 parents c7560aa + 6cfcae2 commit 8dac3fd

File tree

5 files changed

+104
-3
lines changed

5 files changed

+104
-3
lines changed

lib/rdoc/ruby_lex.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ def identify_identifier
10881088
token.concat getc
10891089
end
10901090
elsif @lex_state == :EXPR_BEG || @lex_state == :EXPR_DOT ||
1091-
@lex_state == :EXPR_ARG
1091+
@lex_state == :EXPR_ARG || @lex_state == :EXPR_MID
10921092
@lex_state = :EXPR_ARG
10931093
else
10941094
@lex_state = :EXPR_END
@@ -1322,7 +1322,7 @@ def identify_string(ltype, quoted = ltype, type = nil)
13221322
@ltype = ltype
13231323
@quoted = quoted
13241324

1325-
str = if ltype == quoted and %w[" ' /].include? ltype then
1325+
str = if ltype == quoted and %w[" ' / `].include? ltype then
13261326
ltype.dup
13271327
else
13281328
"%#{type}#{PERCENT_PAREN_REV[quoted]||quoted}"

lib/rdoc/token_stream.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def self.to_html token_stream
4040
when RDoc::RubyToken::TkDREGEXP then 'ruby-regexp'
4141
when RDoc::RubyToken::TkNode then 'ruby-node'
4242
when RDoc::RubyToken::TkCOMMENT then 'ruby-comment'
43+
when RDoc::RubyToken::TkXSTRING then 'ruby-string'
4344
when RDoc::RubyToken::TkSTRING then 'ruby-string'
4445
when RDoc::RubyToken::TkVal then 'ruby-value'
4546
end

rdoc.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
2121
RDoc produces HTML and command-line documentation for Ruby projects.
2222
RDoc includes the +rdoc+ and +ri+ tools for generating and displaying documentation from the command-line.
2323
DESCRIPTION
24-
s.homepage = "https://rdoc.github.io/rdoc"
24+
s.homepage = "https://ruby.github.io/rdoc"
2525
s.licenses = ["Ruby"]
2626

2727
s.bindir = "exe"

test/test_rdoc_markup_to_html.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,46 @@ def bar
545545
assert_equal expected, @to.res.join
546546
end
547547

548+
def test_accept_verbatim_escape_in_backtick
549+
code = <<-'RUBY'
550+
def foo
551+
[
552+
`\\`,
553+
`\'\"\``,
554+
`\#`,
555+
`\#{}`,
556+
`#`,
557+
`#{}`
558+
]
559+
end
560+
def bar
561+
end
562+
RUBY
563+
verb = @RM::Verbatim.new(*code.split(/(?<=\n)/))
564+
565+
@to.start_accepting
566+
@to.accept_verbatim verb
567+
568+
expected = <<-'EXPECTED'
569+
570+
<pre class="ruby"><span class="ruby-keyword">def</span> <span class="ruby-identifier">foo</span>
571+
[
572+
<span class="ruby-string">`\\`</span>,
573+
<span class="ruby-string">`\&#39;\&quot;\``</span>,
574+
<span class="ruby-string">`\#`</span>,
575+
<span class="ruby-string">`\#{}`</span>,
576+
<span class="ruby-string">`#`</span>,
577+
<span class="ruby-node">`#{}`</span>
578+
]
579+
<span class="ruby-keyword">end</span>
580+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">bar</span>
581+
<span class="ruby-keyword">end</span>
582+
</pre>
583+
EXPECTED
584+
585+
assert_equal expected, @to.res.join
586+
end
587+
548588
def test_accept_verbatim_ruby
549589
verb = @RM::Verbatim.new("1 + 1\n")
550590
verb.format = :ruby

test/test_rdoc_ruby_lex.rb

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,51 @@ def a
757757
assert_equal expected, tokens
758758
end
759759

760+
def test_class_tokenize_backtick_with_escape
761+
tokens = RDoc::RubyLex.tokenize <<'RUBY', nil
762+
[
763+
`\\`,
764+
`\'\"\``,
765+
`\#`,
766+
`\#{}`,
767+
`#`,
768+
`#{}`
769+
]
770+
RUBY
771+
772+
expected = [
773+
@TK::TkLBRACK .new( 0, 1, 0, "["),
774+
@TK::TkNL .new( 1, 1, 1, "\n"),
775+
@TK::TkSPACE .new( 2, 2, 0, " "),
776+
@TK::TkXSTRING .new( 4, 2, 2, "`\\\\`"),
777+
@TK::TkCOMMA .new( 8, 2, 6, ","),
778+
@TK::TkNL .new( 9, 2, 2, "\n"),
779+
@TK::TkSPACE .new(10, 3, 0, " "),
780+
@TK::TkXSTRING .new(12, 3, 2, "`\\'\\\"\\``"),
781+
@TK::TkCOMMA .new(20, 3, 10, ","),
782+
@TK::TkNL .new(21, 3, 10, "\n"),
783+
@TK::TkSPACE .new(22, 4, 0, " "),
784+
@TK::TkXSTRING .new(24, 4, 2, "`\\#`"),
785+
@TK::TkCOMMA .new(28, 4, 6, ","),
786+
@TK::TkNL .new(29, 4, 22, "\n"),
787+
@TK::TkSPACE .new(30, 5, 0, " "),
788+
@TK::TkXSTRING .new(32, 5, 2, "`\\\#{}`"),
789+
@TK::TkCOMMA .new(38, 5, 8, ","),
790+
@TK::TkNL .new(39, 5, 30, "\n"),
791+
@TK::TkSPACE .new(40, 6, 0, " "),
792+
@TK::TkXSTRING .new(42, 6, 2, "`#`"),
793+
@TK::TkCOMMA .new(45, 6, 5, ","),
794+
@TK::TkNL .new(46, 6, 40, "\n"),
795+
@TK::TkSPACE .new(47, 7, 0, " "),
796+
@TK::TkDXSTRING.new(49, 7, 2, "`\#{}`"),
797+
@TK::TkNL .new(54, 7, 7, "\n"),
798+
@TK::TkRBRACK .new(55, 8, 0, "]"),
799+
@TK::TkNL .new(56, 8, 55, "\n")
800+
]
801+
802+
assert_equal expected, tokens
803+
end
804+
760805
def test_class_tokenize_string_escape
761806
tokens = RDoc::RubyLex.tokenize '"\\n"', nil
762807
assert_equal @TK::TkSTRING.new( 0, 1, 0, "\"\\n\""), tokens.first
@@ -876,6 +921,21 @@ def test_class_tokenize_particular_kind_of_symbols
876921
assert_equal expected, tokens
877922
end
878923

924+
def test_class_tokenize_symbol_for_nested_method
925+
tokens = RDoc::RubyLex.tokenize 'return untrace_var :name', nil
926+
927+
expected = [
928+
@TK::TkRETURN .new( 0, 1, 0, "return"),
929+
@TK::TkSPACE .new( 6, 1, 6, " "),
930+
@TK::TkIDENTIFIER.new( 7, 1, 7, "untrace_var"),
931+
@TK::TkSPACE .new(18, 1, 18, " "),
932+
@TK::TkSYMBOL .new(19, 1, 19, ":name"),
933+
@TK::TkNL .new(24, 1, 24, "\n"),
934+
]
935+
936+
assert_equal expected, tokens
937+
end
938+
879939
def test_class_tokenize_symbol_with_quote
880940
tokens = RDoc::RubyLex.tokenize <<RUBY, nil
881941
a.include?()?"a":"b"

0 commit comments

Comments
 (0)