2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-06-26 14:21:49 +00:00

Add keywords to header lexer of zcg cpp

This commit is contained in:
Jan
2021-02-12 00:38:38 +01:00
parent 87b7921c73
commit fe1f391bcc
5 changed files with 90 additions and 1 deletions

View File

@ -3,6 +3,20 @@
HeaderLexer::HeaderLexer(IParserLineStream* stream)
: AbstractLexer(stream)
{
PrepareKeywords();
}
void HeaderLexer::PrepareKeywords()
{
m_keywords["__declspec"] = HeaderParserValueType::DECLSPEC;
m_keywords["align"] = HeaderParserValueType::ALIGN;
m_keywords["alignas"] = HeaderParserValueType::ALIGNAS;
m_keywords["const"] = HeaderParserValueType::CONST;
m_keywords["enum"] = HeaderParserValueType::ENUM;
m_keywords["namespace"] = HeaderParserValueType::NAMESPACE;
m_keywords["struct"] = HeaderParserValueType::STRUCT;
m_keywords["typedef"] = HeaderParserValueType::TYPEDEF;
m_keywords["union"] = HeaderParserValueType::UNION;
}
HeaderParserValue HeaderLexer::GetNextToken()
@ -131,7 +145,15 @@ HeaderParserValue HeaderLexer::GetNextToken()
}
if (isalpha(c) || c == '_')
return HeaderParserValue::Identifier(GetPreviousCharacterPos(), new std::string(ReadIdentifier()));
{
auto identifier = ReadIdentifier();
const auto foundKeyword = m_keywords.find(identifier);
if (foundKeyword != m_keywords.end())
return HeaderParserValue::Keyword(GetPreviousCharacterPos(), foundKeyword->second);
return HeaderParserValue::Identifier(GetPreviousCharacterPos(), new std::string(std::move(identifier)));
}
return HeaderParserValue::Character(GetPreviousCharacterPos(), static_cast<char>(c));
}