Skip to content

Commit 26fc790

Browse files
committed
Fixed lexing of character syntax like ?z
Character syntax `?z` was lexed as an integer token `"zz"`. This has been fixed to lex as a single character string `"z"`. While this won't round-trip, it is acceptable for syntax highlighting. This was discovered by Xavier Noria (@fxn) in rails/rails#7172. Conflicts: History.rdoc
1 parent 6580451 commit 26fc790

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

History.rdoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Bug fixes
44
* Fixed bug in syntax-highlighting that would corrupt regular expressions.
55
Ruby Bug #6488 by Benny Lyne Amorsen.
6+
* Fixed lexing of character syntax (<code>?x</code>). Reported by Xavier
7+
Noria.
68

79
=== 3.12.1 / 2013-02-05
810

lib/rdoc/ruby_lex.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -536,13 +536,8 @@ def lex_init()
536536
@lex_state = EXPR_BEG;
537537
Token(TkQUESTION)
538538
else
539-
str = ch
540-
if ch == '\\'
541-
str << read_escape
542-
end
543539
@lex_state = EXPR_END
544-
str << (ch.respond_to?(:ord) ? ch.ord : ch[0])
545-
Token(TkINTEGER, str)
540+
Token(TkSTRING, ch)
546541
end
547542
end
548543
end

test/test_rdoc_ruby_lex.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ def test_class_tokenize
3030
assert_equal expected, tokens
3131
end
3232

33+
def test_class_tokenize_character_literal
34+
tokens = RDoc::RubyLex.tokenize "?\\", nil
35+
36+
expected = [
37+
@TK::TkSTRING.new( 0, 1, 0, "\\"),
38+
@TK::TkNL .new( 2, 1, 2, "\n"),
39+
]
40+
41+
assert_equal expected, tokens
42+
end
43+
3344
def test_class_tokenize_def_heredoc
3445
tokens = RDoc::RubyLex.tokenize <<-'RUBY', nil
3546
def x

0 commit comments

Comments
 (0)