Skip to content

Commit 3a6bb1f

Browse files
committed
Fix creation of symbol token
Symbol tokens are created form TkIDENTIFIER with ":", but there are several other cases. Subclasses of TkId can become symbol token with ":", for example reserved keywords can become symbol, "{ undef: undef }". This commit fixes it.
1 parent e752c73 commit 3a6bb1f

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-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

0 commit comments

Comments
 (0)