Skip to content

Commit 8cac561

Browse files
authored
Merge pull request #488 from aycabta/fix-creation-of-symbol-token
Fix creation of symbol token
2 parents f1d5414 + cb4787f commit 8cac561

File tree

2 files changed

+42
-15
lines changed

2 files changed

+42
-15
lines changed

lib/rdoc/ruby_lex.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,12 +1046,7 @@ def identify_identifier
10461046
@indent_stack.push token_c
10471047
end
10481048
else
1049-
if peek(0) == ':' and !peek_match?(/^::/)
1050-
token.concat getc
1051-
token_c = TkSYMBOL
1052-
else
1053-
token_c = TkIDENTIFIER
1054-
end
1049+
token_c = TkIDENTIFIER
10551050
end
10561051

10571052
elsif DEINDENT_CLAUSE.include?(token)
@@ -1063,6 +1058,10 @@ def identify_identifier
10631058
@lex_state = :EXPR_END
10641059
end
10651060
end
1061+
if token_c.ancestors.include?(TkId) and peek(0) == ':' and !peek_match?(/^::/)
1062+
token.concat getc
1063+
token_c = TkSYMBOL
1064+
end
10661065
return Token(token_c, token)
10671066
end
10681067
end
@@ -1081,19 +1080,20 @@ def identify_identifier
10811080

10821081
if token[0, 1] =~ /[A-Z]/
10831082
if token[-1] =~ /[!?]/
1084-
return Token(TkIDENTIFIER, token)
1083+
token_c = TkIDENTIFIER
10851084
else
1086-
return Token(TkCONSTANT, token)
1085+
token_c = TkCONSTANT
10871086
end
10881087
elsif token[token.size - 1, 1] =~ /[!?]/
1089-
return Token(TkFID, token)
1088+
token_c = TkFID
10901089
else
1091-
if peek(0) == ':' and !peek_match?(/^::/)
1092-
token.concat getc
1093-
return Token(TkSYMBOL, token)
1094-
else
1095-
return Token(TkIDENTIFIER, token)
1096-
end
1090+
token_c = TkIDENTIFIER
1091+
end
1092+
if peek(0) == ':' and !peek_match?(/^::/)
1093+
token.concat getc
1094+
return Token(TkSYMBOL, token)
1095+
else
1096+
return Token(token_c, token)
10971097
end
10981098
end
10991099

test/test_rdoc_ruby_lex.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,33 @@ def test_class_tokenize_symbol
671671
assert_equal expected, tokens
672672
end
673673

674+
def test_class_tokenize_particular_kind_of_symbols
675+
tokens = RDoc::RubyLex.tokenize '{ Thomas: :Thomas, Dave!: :Dave!, undef: :undef }', nil
676+
677+
expected = [
678+
@TK::TkLBRACE.new( 0, 1, 0, "{"),
679+
@TK::TkSPACE .new( 1, 1, 1, " "),
680+
@TK::TkSYMBOL.new( 2, 1, 2, "Thomas:"),
681+
@TK::TkSPACE .new( 9, 1, 9, " "),
682+
@TK::TkSYMBOL.new(10, 1, 10, ":Thomas"),
683+
@TK::TkCOMMA .new(17, 1, 17, ","),
684+
@TK::TkSPACE .new(18, 1, 18, " "),
685+
@TK::TkSYMBOL.new(19, 1, 19, "Dave!:"),
686+
@TK::TkSPACE .new(25, 1, 25, " "),
687+
@TK::TkSYMBOL.new(26, 1, 26, ":Dave!"),
688+
@TK::TkCOMMA .new(32, 1, 32, ","),
689+
@TK::TkSPACE .new(33, 1, 33, " "),
690+
@TK::TkSYMBOL.new(34, 1, 34, "undef:"),
691+
@TK::TkSPACE .new(40, 1, 40, " "),
692+
@TK::TkSYMBOL.new(41, 1, 41, ":undef"),
693+
@TK::TkSPACE .new(47, 1, 47, " "),
694+
@TK::TkRBRACE.new(48, 1, 48, "}"),
695+
@TK::TkNL .new(49, 1, 49, "\n"),
696+
]
697+
698+
assert_equal expected, tokens
699+
end
700+
674701
def test_unary_minus
675702
ruby_lex = RDoc::RubyLex.new("-1", nil)
676703
assert_equal("-1", ruby_lex.token.value)

0 commit comments

Comments
 (0)