Token: Allow dollar sign in identifiers

This commit is contained in:
Daniel Marjamäki 2016-07-29 13:42:11 +02:00
parent 30354ee026
commit a65ae3ce2e
2 changed files with 7 additions and 1 deletions

View File

@ -65,7 +65,7 @@ void Token::update_property_info()
if (!_str.empty()) { if (!_str.empty()) {
if (_str == "true" || _str == "false") if (_str == "true" || _str == "false")
_tokType = eBoolean; _tokType = eBoolean;
else if (_str[0] == '_' || std::isalpha((unsigned char)_str[0])) { // Name else if (std::isalpha((unsigned char)_str[0]) || _str[0] == '_' || _str[0] == '$') { // Name
if (_varId) if (_varId)
_tokType = eVariable; _tokType = eVariable;
else if (_tokType != eVariable && _tokType != eFunction && _tokType != eType && _tokType != eKeyword) else if (_tokType != eVariable && _tokType != eFunction && _tokType != eType && _tokType != eKeyword)

View File

@ -85,6 +85,7 @@ private:
TEST_CASE(isNameGuarantees3) TEST_CASE(isNameGuarantees3)
TEST_CASE(isNameGuarantees4) TEST_CASE(isNameGuarantees4)
TEST_CASE(isNameGuarantees5) TEST_CASE(isNameGuarantees5)
TEST_CASE(isNameGuarantees6)
TEST_CASE(canFindMatchingBracketsNeedsOpen); TEST_CASE(canFindMatchingBracketsNeedsOpen);
TEST_CASE(canFindMatchingBracketsInnerPair); TEST_CASE(canFindMatchingBracketsInnerPair);
@ -888,6 +889,11 @@ private:
ASSERT_EQUALS(false, tok.isNumber()); ASSERT_EQUALS(false, tok.isNumber());
} }
void isNameGuarantees6() const {
Token tok(nullptr);
tok.str("$f");
ASSERT_EQUALS(true, tok.isName());
}
void canFindMatchingBracketsNeedsOpen() const { void canFindMatchingBracketsNeedsOpen() const {
givenACodeSampleToTokenize var("std::deque<std::set<int> > intsets;"); givenACodeSampleToTokenize var("std::deque<std::set<int> > intsets;");