Skip to content

Commit 74e9eee

Browse files
committed
Merge remote-tracking branch 'upstream/master' into fix-regexp-literal-in-oneliner
2 parents 9762de4 + 131d947 commit 74e9eee

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

lib/rdoc/ruby_lex.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def initialize(content, options)
114114
@lex_state = :EXPR_BEG
115115
@space_seen = false
116116
@first_in_method_statement = false
117+
@after_question = false
117118

118119
@continue = false
119120
@line = ""
@@ -386,6 +387,8 @@ def token
386387
set_token_position tk.seek, tk.line_no, tk.char_no
387388
tk = Token(tk1.class, tk.text + tk1.text)
388389
end
390+
@after_question = false if @after_question and !(TkQUESTION === tk)
391+
389392
# Tracer.off
390393
tk
391394
end
@@ -603,6 +606,7 @@ def lex_init()
603606
|op, io|
604607
if @lex_state == :EXPR_END
605608
@lex_state = :EXPR_BEG
609+
@after_question = true
606610
Token(TkQUESTION)
607611
else
608612
ch = getc
@@ -1371,7 +1375,10 @@ def identify_string(ltype, quoted = ltype, type = nil)
13711375
end
13721376
end
13731377

1374-
if subtype
1378+
if peek(0) == ':' and !peek_match?(/^::/) and :EXPR_BEG == @lex_state and !@after_question
1379+
str.concat getc
1380+
return Token(TkSYMBOL, str)
1381+
elsif subtype
13751382
Token(DLtype2Token[ltype], str)
13761383
else
13771384
Token(Ltype2Token[ltype], str)

lib/rdoc/ruby_token.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ def Token(token, value = nil)
322322
[:TklEND, TkKW, "END", :EXPR_END],
323323
[:Tk__LINE__, TkKW, "__LINE__", :EXPR_END],
324324
[:Tk__FILE__, TkKW, "__FILE__", :EXPR_END],
325+
[:Tk__ENCODING__,TkKW, "__ENCODING__", :EXPR_END],
325326

326327
[:TkIDENTIFIER, TkId],
327328
[:TkFID, TkId],

test/test_rdoc_ruby_lex.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ def test_class_tokenize___END__
6262
assert_equal expected, tokens
6363
end
6464

65+
def test_class_tokenize___ENCODING__
66+
tokens = RDoc::RubyLex.tokenize '__ENCODING__', nil
67+
68+
expected = [
69+
@TK::Tk__ENCODING__.new( 0, 1, 0, '__ENCODING__'),
70+
@TK::TkNL .new(12, 1, 12, "\n"),
71+
]
72+
73+
assert_equal expected, tokens
74+
end
75+
6576
def test_class_tokenize_character_literal
6677
tokens = RDoc::RubyLex.tokenize "?c", nil
6778

@@ -827,6 +838,36 @@ def test_class_tokenize_particular_kind_of_symbols
827838
assert_equal expected, tokens
828839
end
829840

841+
def test_class_tokenize_symbol_with_quote
842+
tokens = RDoc::RubyLex.tokenize <<RUBY, nil
843+
a.include?()?"a":"b"
844+
{"t":1,'t2':2}
845+
RUBY
846+
847+
expected = [
848+
@TK::TkIDENTIFIER.new( 0, 1, 0, "a"),
849+
@TK::TkDOT .new( 1, 1, 1, "."),
850+
@TK::TkFID .new( 2, 1, 2, "include?"),
851+
@TK::TkLPAREN .new(10, 1, 10, "("),
852+
@TK::TkRPAREN .new(11, 1, 11, ")"),
853+
@TK::TkQUESTION .new(12, 1, 12, "?"),
854+
@TK::TkSTRING .new(13, 1, 13, "\"a\""),
855+
@TK::TkCOLON .new(16, 1, 16, ":"),
856+
@TK::TkSTRING .new(17, 1, 17, "\"b\""),
857+
@TK::TkNL .new(20, 1, 20, "\n"),
858+
@TK::TkLBRACE .new(21, 2, 0, "{"),
859+
@TK::TkSYMBOL .new(22, 2, 1, "\"t\":"),
860+
@TK::TkINTEGER .new(26, 2, 5, "1"),
861+
@TK::TkCOMMA .new(27, 2, 6, ","),
862+
@TK::TkSYMBOL .new(28, 2, 7, "'t2':"),
863+
@TK::TkINTEGER .new(33, 2, 12, "2"),
864+
@TK::TkRBRACE .new(34, 2, 13, "}"),
865+
@TK::TkNL .new(35, 2, 21, "\n"),
866+
]
867+
868+
assert_equal expected, tokens
869+
end
870+
830871
def test_unary_minus
831872
ruby_lex = RDoc::RubyLex.new("-1", nil)
832873
assert_equal("-1", ruby_lex.token.value)

0 commit comments

Comments
 (0)