Skip to content

Commit 1a68297

Browse files
author
Zachary Scott
authored
Merge pull request #462 from aycabta/move-collecting-up-symbol-to-ruby-lex
Move collecting up tokens for a symbol to RubyLex
2 parents d566ea1 + c957d10 commit 1a68297

File tree

3 files changed

+18
-24
lines changed

3 files changed

+18
-24
lines changed

lib/rdoc/parser/ruby_tools.rb

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,6 @@ def get_tk
3333

3434
tk = nil if TkEND_OF_SCRIPT === tk
3535

36-
if TkSYMBEG === tk then
37-
set_token_position tk.line_no, tk.char_no
38-
39-
case tk1 = get_tk
40-
when TkId, TkOp, TkSTRING, TkDSTRING, TkSTAR, TkAMPER then
41-
if tk1.respond_to?(:name) then
42-
tk = Token(TkSYMBOL).set_text(":" + tk1.name)
43-
else
44-
tk = Token(TkSYMBOL).set_text(":" + tk1.text)
45-
end
46-
47-
# remove the identifier we just read to replace it with a symbol
48-
@token_listeners.each do |obj|
49-
obj.pop_token
50-
end if @token_listeners
51-
else
52-
tk = tk1
53-
end
54-
end
55-
5636
# inform any listeners of our shiny new token
5737
@token_listeners.each do |obj|
5838
obj.add_token(tk)

lib/rdoc/ruby_lex.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,22 @@ def token
361361
if @readed_auto_clean_up
362362
get_readed
363363
end
364+
365+
if TkSYMBEG === tk then
366+
tk1 = token
367+
set_token_position tk.line_no, tk.char_no
368+
369+
case tk1
370+
when TkId, TkOp, TkSTRING, TkDSTRING, TkSTAR, TkAMPER then
371+
if tk1.respond_to?(:name) then
372+
tk = Token(TkSYMBOL, ":" + tk1.name)
373+
else
374+
tk = Token(TkSYMBOL, ":" + tk1.text)
375+
end
376+
else
377+
tk = tk1
378+
end
379+
end
364380
# Tracer.off
365381
tk
366382
end

test/test_rdoc_ruby_lex.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ def test_class_tokenize_hash_symbol
8181
@TK::TkLBRACE .new( 0, 1, 0, '{'),
8282
@TK::TkSPACE .new( 1, 1, 1, ' '),
8383
@TK::TkIDENTIFIER.new( 2, 1, 2, 'class'),
84-
@TK::TkSYMBEG .new( 7, 1, 7, ':'),
85-
@TK::TkSTRING .new( 8, 1, 8, '"foo"'),
84+
@TK::TkSYMBOL .new( 7, 1, 7, ':"foo"'),
8685
@TK::TkSPACE .new(13, 1, 13, ' '),
8786
@TK::TkRBRACE .new(14, 1, 14, '}'),
8887
@TK::TkNL .new(15, 1, 15, "\n"),
@@ -393,8 +392,7 @@ def test_class_tokenize_symbol
393392
@TK::TkIDENTIFIER.new( 6, 1, 6, 'module'),
394393
@TK::TkCOLON .new(12, 1, 12, ':'),
395394
@TK::TkSPACE .new(13, 1, 13, ' '),
396-
@TK::TkSYMBEG .new(14, 1, 14, ':'),
397-
@TK::TkIDENTIFIER.new(15, 1, 15, 'v1'),
395+
@TK::TkSYMBOL .new(14, 1, 14, ':v1'),
398396
@TK::TkNL .new(17, 1, 17, "\n"),
399397
]
400398

0 commit comments

Comments
 (0)