Skip to content

Commit ac9e810

Browse files
committed
Pass the percent string type directly down instead of attempting to guess it from the ending character
1 parent 0f7447e commit ac9e810

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

lib/rdoc/ruby_lex.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,21 +1032,22 @@ def identify_here_document
10321032
end
10331033

10341034
def identify_quotation
1035-
ch = getc
1036-
if lt = PERCENT_LTYPE[ch]
1035+
type = ch = getc
1036+
if lt = PERCENT_LTYPE[type]
10371037
ch = getc
1038-
elsif ch =~ /\W/
1038+
elsif type =~ /\W/
1039+
type = nil
10391040
lt = "\""
10401041
else
1041-
raise Error, "unknown type of %string #{ch.inspect}"
1042+
raise Error, "unknown type of %string #{type.inspect}"
10421043
end
10431044
# if ch !~ /\W/
10441045
# ungetc
10451046
# next
10461047
# end
10471048
#@ltype = lt
10481049
@quoted = ch unless @quoted = PERCENT_PAREN[ch]
1049-
identify_string(lt, @quoted)
1050+
identify_string(lt, @quoted, type)
10501051
end
10511052

10521053
def identify_number(op = "")
@@ -1157,17 +1158,17 @@ def identify_number(op = "")
11571158
Token(type, num)
11581159
end
11591160

1160-
def identify_string(ltype, quoted = ltype)
1161+
def identify_string(ltype, quoted = ltype, type = nil)
11611162
close = PERCENT_PAREN.values.include?(quoted)
11621163
@ltype = ltype
11631164
@quoted = quoted
11641165

11651166
str = if ltype == quoted and %w[" '].include? ltype then
11661167
ltype.dup
11671168
elsif RUBY_VERSION > '1.9' then
1168-
"%#{PERCENT_LTYPE.key ltype}#{PERCENT_PAREN_REV[quoted]}"
1169+
"%#{type or PERCENT_LTYPE.key ltype}#{PERCENT_PAREN_REV[quoted]}"
11691170
else
1170-
"%#{PERCENT_LTYPE.index ltype}#{PERCENT_PAREN_REV[quoted]}"
1171+
"%#{type or PERCENT_LTYPE.index ltype}#{PERCENT_PAREN_REV[quoted]}"
11711172
end
11721173

11731174
subtype = nil

test/test_rdoc_ruby_lex.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ def test_class_tokenize_heredoc_percent_N
9595
end
9696

9797
def test_class_tokenize_percent_w
98-
tokens = RDoc::RubyLex.tokenize "%w[hi]", nil
98+
tokens = RDoc::RubyLex.tokenize '%w[hi]', nil
9999

100100
expected = [
101-
@TK::TkDSTRING.new( 0, 1, 0, "%w[hi]"),
101+
@TK::TkDSTRING.new( 0, 1, 0, '%w[hi]'),
102102
@TK::TkNL .new( 6, 1, 6, "\n"),
103103
]
104104

0 commit comments

Comments
 (0)