code_compiler: Use isspace, iscntrl and isprint for tests
This commit is contained in:
@@ -17,11 +17,6 @@
|
|||||||
#include "lexer.hpp"
|
#include "lexer.hpp"
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
|
|
||||||
char g_whitespaceCharacters[] = {
|
|
||||||
' ',
|
|
||||||
'\t',
|
|
||||||
};
|
|
||||||
|
|
||||||
std::pair<char, BlitzLLVM::Lexer::Token> g_symbolCharacters[] = {
|
std::pair<char, BlitzLLVM::Lexer::Token> g_symbolCharacters[] = {
|
||||||
//{ '\"', BlitzLLVM::Lexer::Token::TokenDoubleQuote }, // Has special meaning.
|
//{ '\"', BlitzLLVM::Lexer::Token::TokenDoubleQuote }, // Has special meaning.
|
||||||
{ '+', BlitzLLVM::Lexer::Token::TokenPlus },
|
{ '+', BlitzLLVM::Lexer::Token::TokenPlus },
|
||||||
@@ -82,16 +77,15 @@ std::pair<BlitzLLVM::Lexer::Token, std::string> BlitzLLVM::Lexer::GetNextToken()
|
|||||||
break;
|
break;
|
||||||
} else if (!m_isStringMode && !m_isTextMode && !m_isNumberMode) {
|
} else if (!m_isStringMode && !m_isTextMode && !m_isNumberMode) {
|
||||||
// Whitespace
|
// Whitespace
|
||||||
bool isWhitespace = false;
|
if (isspace(chr))
|
||||||
for (char v : g_whitespaceCharacters) {
|
|
||||||
if (v == chr) {
|
|
||||||
isWhitespace = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isWhitespace)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// Control Code
|
||||||
|
if (iscntrl(chr)) {
|
||||||
|
tkn = Token::TokenUnknown;
|
||||||
|
buf = chr;
|
||||||
|
}
|
||||||
|
|
||||||
// Symbol
|
// Symbol
|
||||||
for (auto v : g_symbolCharacters) {
|
for (auto v : g_symbolCharacters) {
|
||||||
if (v.first == chr) {
|
if (v.first == chr) {
|
||||||
@@ -137,6 +131,10 @@ std::pair<BlitzLLVM::Lexer::Token, std::string> BlitzLLVM::Lexer::GetNextToken()
|
|||||||
m_isStringMode = false;
|
m_isStringMode = false;
|
||||||
tkn = Token::TokenQuotedText;
|
tkn = Token::TokenQuotedText;
|
||||||
break;
|
break;
|
||||||
|
} else if (iscntrl(chr) || !isprint(chr)) {
|
||||||
|
m_fileStream.putback(chr);
|
||||||
|
m_isStringMode = false;
|
||||||
|
break;
|
||||||
} else {
|
} else {
|
||||||
buf += chr;
|
buf += chr;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user