1
0
mirror of synced 2024-11-12 02:00:52 +01:00

Added character literals to pattern language

This commit is contained in:
WerWolv 2020-11-27 14:18:28 +01:00
parent 2efe326fdb
commit d55bea7c46
2 changed files with 33 additions and 0 deletions

View File

@ -131,6 +131,37 @@ namespace hex::lang {
} else if (c == '*') {
tokens.push_back({ .type = Token::Type::Operator, .operatorToken = { .op = Token::OperatorToken::Operator::Star } });
offset += 1;
} else if (c == '\'') {
offset += 1;
if (offset >= code.length())
return { ResultLexicalError, { } };
char character = code[offset];
if (character == '\\') {
offset += 1;
if (offset >= code.length())
return { ResultLexicalError, { } };
if (code[offset] != '\\' && code[offset] != '\'')
return { ResultLexicalError, { } };
character = code[offset];
} else {
if (code[offset] == '\\' || code[offset] == '\'')
return { ResultLexicalError, { } };
}
offset += 1;
if (offset >= code.length() || code[offset] != '\'')
return { ResultLexicalError, { } };
tokens.push_back({ .type = Token::Type::Integer, .integerToken = { .integer = character } });
offset += 1;
} else if (std::isalpha(c)) {
std::string identifier = matchTillInvalid(&code[offset], [](char c) -> bool { return std::isalnum(c) || c == '_'; });

View File

@ -48,6 +48,8 @@ namespace hex {
paletteIndex = TextEditor::PaletteIndex::Identifier;
else if (TokenizeCStyleNumber(inBegin, inEnd, outBegin, outEnd))
paletteIndex = TextEditor::PaletteIndex::Number;
else if (TokenizeCStyleCharacterLiteral(inBegin, inEnd, outBegin, outEnd))
paletteIndex = TextEditor::PaletteIndex::CharLiteral;
return paletteIndex != TextEditor::PaletteIndex::Max;
};