Skip to content

Commit

Permalink
Merge pull request #462 from aycabta/move-collecting-up-symbol-to-rub…
Browse files Browse the repository at this point in the history
…y-lex

Move collecting up tokens for a symbol to RubyLex
  • Loading branch information
Zachary Scott committed Jul 18, 2017
2 parents d566ea1 + c957d10 commit 1a68297
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
20 changes: 0 additions & 20 deletions lib/rdoc/parser/ruby_tools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,6 @@ def get_tk

tk = nil if TkEND_OF_SCRIPT === tk

if TkSYMBEG === tk then
set_token_position tk.line_no, tk.char_no

case tk1 = get_tk
when TkId, TkOp, TkSTRING, TkDSTRING, TkSTAR, TkAMPER then
if tk1.respond_to?(:name) then
tk = Token(TkSYMBOL).set_text(":" + tk1.name)
else
tk = Token(TkSYMBOL).set_text(":" + tk1.text)
end

# remove the identifier we just read to replace it with a symbol
@token_listeners.each do |obj|
obj.pop_token
end if @token_listeners
else
tk = tk1
end
end

# inform any listeners of our shiny new token
@token_listeners.each do |obj|
obj.add_token(tk)
Expand Down
16 changes: 16 additions & 0 deletions lib/rdoc/ruby_lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,22 @@ def token
if @readed_auto_clean_up
get_readed
end

if TkSYMBEG === tk then
tk1 = token
set_token_position tk.line_no, tk.char_no

case tk1
when TkId, TkOp, TkSTRING, TkDSTRING, TkSTAR, TkAMPER then
if tk1.respond_to?(:name) then
tk = Token(TkSYMBOL, ":" + tk1.name)
else
tk = Token(TkSYMBOL, ":" + tk1.text)
end
else
tk = tk1
end
end
# Tracer.off
tk
end
Expand Down
6 changes: 2 additions & 4 deletions test/test_rdoc_ruby_lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ def test_class_tokenize_hash_symbol
@TK::TkLBRACE .new( 0, 1, 0, '{'),
@TK::TkSPACE .new( 1, 1, 1, ' '),
@TK::TkIDENTIFIER.new( 2, 1, 2, 'class'),
@TK::TkSYMBEG .new( 7, 1, 7, ':'),
@TK::TkSTRING .new( 8, 1, 8, '"foo"'),
@TK::TkSYMBOL .new( 7, 1, 7, ':"foo"'),
@TK::TkSPACE .new(13, 1, 13, ' '),
@TK::TkRBRACE .new(14, 1, 14, '}'),
@TK::TkNL .new(15, 1, 15, "\n"),
Expand Down Expand Up @@ -393,8 +392,7 @@ def test_class_tokenize_symbol
@TK::TkIDENTIFIER.new( 6, 1, 6, 'module'),
@TK::TkCOLON .new(12, 1, 12, ':'),
@TK::TkSPACE .new(13, 1, 13, ' '),
@TK::TkSYMBEG .new(14, 1, 14, ':'),
@TK::TkIDENTIFIER.new(15, 1, 15, 'v1'),
@TK::TkSYMBOL .new(14, 1, 14, ':v1'),
@TK::TkNL .new(17, 1, 17, "\n"),
]

Expand Down

0 comments on commit 1a68297

Please sign in to comment.