Skip to content

Commit a65ae3c

Browse files
committed
Token: Allow dollar sign in identifiers
1 parent 30354ee commit a65ae3c

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/token.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void Token::update_property_info()
6565
if (!_str.empty()) {
6666
if (_str == "true" || _str == "false")
6767
_tokType = eBoolean;
68-
else if (_str[0] == '_' || std::isalpha((unsigned char)_str[0])) { // Name
68+
else if (std::isalpha((unsigned char)_str[0]) || _str[0] == '_' || _str[0] == '$') { // Name
6969
if (_varId)
7070
_tokType = eVariable;
7171
else if (_tokType != eVariable && _tokType != eFunction && _tokType != eType && _tokType != eKeyword)

test/testtoken.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class TestToken : public TestFixture {
8585
TEST_CASE(isNameGuarantees3)
8686
TEST_CASE(isNameGuarantees4)
8787
TEST_CASE(isNameGuarantees5)
88+
TEST_CASE(isNameGuarantees6)
8889

8990
TEST_CASE(canFindMatchingBracketsNeedsOpen);
9091
TEST_CASE(canFindMatchingBracketsInnerPair);
@@ -888,6 +889,11 @@ class TestToken : public TestFixture {
888889
ASSERT_EQUALS(false, tok.isNumber());
889890
}
890891

892+
void isNameGuarantees6() const {
893+
Token tok(nullptr);
894+
tok.str("$f");
895+
ASSERT_EQUALS(true, tok.isName());
896+
}
891897

892898
void canFindMatchingBracketsNeedsOpen() const {
893899
givenACodeSampleToTokenize var("std::deque<std::set<int> > intsets;");

0 commit comments

Comments
 (0)