Parse char types
This commit is contained in:
@@ -237,6 +237,10 @@ shared_ptr<Token> Lexer::nextToken() {
|
||||
if (token != nullptr)
|
||||
return token;
|
||||
|
||||
token = matchIntegerChar();
|
||||
if (token != nullptr)
|
||||
return token;
|
||||
|
||||
// type
|
||||
token = match(TokenKind::TYPE, "bool", true);
|
||||
if (token != nullptr)
|
||||
@@ -354,6 +358,27 @@ shared_ptr<Token> Lexer::matchIntegerBin() {
|
||||
return token;
|
||||
}
|
||||
|
||||
shared_ptr<Token> Lexer::matchIntegerChar() {
|
||||
int nextIndex = currentIndex;
|
||||
|
||||
if (currentIndex >= source.size() || source.at(nextIndex) != '\'')
|
||||
return nullptr;
|
||||
|
||||
bool isClosing = false;
|
||||
do {
|
||||
nextIndex++;
|
||||
isClosing = source.at(nextIndex) == '\'' && source.at(nextIndex - 1) != '\\';
|
||||
} while (nextIndex < source.length() && !isClosing);
|
||||
|
||||
if (!isClosing)
|
||||
return nullptr;
|
||||
|
||||
string lexme = source.substr(currentIndex, nextIndex - currentIndex + 1);
|
||||
shared_ptr<Token> token = make_shared<Token>(TokenKind::INTEGER_CHAR, lexme, currentLine, currentColumn);
|
||||
advanceWithToken(token);
|
||||
return token;
|
||||
}
|
||||
|
||||
shared_ptr<Token> Lexer::matchReal() {
|
||||
int nextIndex = currentIndex;
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ private:
|
||||
shared_ptr<Token> matchIntegerDec();
|
||||
shared_ptr<Token> matchIntegerHex();
|
||||
shared_ptr<Token> matchIntegerBin();
|
||||
shared_ptr<Token> matchIntegerChar();
|
||||
shared_ptr<Token> matchReal();
|
||||
shared_ptr<Token> matchIdentifier();
|
||||
shared_ptr<Token> matchEnd();
|
||||
|
||||
@@ -40,6 +40,7 @@ vector<TokenKind> Token::tokensLiteral = {
|
||||
TokenKind::INTEGER_DEC,
|
||||
TokenKind::INTEGER_HEX,
|
||||
TokenKind::INTEGER_BIN,
|
||||
TokenKind::INTEGER_CHAR,
|
||||
TokenKind::REAL
|
||||
};
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ enum class TokenKind {
|
||||
INTEGER_DEC,
|
||||
INTEGER_HEX,
|
||||
INTEGER_BIN,
|
||||
INTEGER_CHAR,
|
||||
REAL,
|
||||
IDENTIFIER,
|
||||
TYPE,
|
||||
|
||||
Reference in New Issue
Block a user