another ugly basic implementation

This commit is contained in:
2021-07-04 15:03:13 +02:00
parent b55115f7c3
commit b4711985b3
12 changed files with 417 additions and 60 deletions

View File

@@ -24,7 +24,7 @@ void Lexer::parse(const std::string &code) {
// TODO make it constant
std::regex words_regex("[0-9]+\\.[0-9]+|[0-9][0-9_]+[0-9]|[0-9]+|[A-Za-z]+[A-Za-z0-9_#]*|[\\(\\)\\[\\]\\{\\}]|[-\\+\\*/"
",;:\?]|==|>=|<=|~=|>|<|=|;|~|\\|\\||&&|\n|\r|\r\n|'([^']|'')*'|\".*?\"|%.*?\n");
",;:\?]|==|>=|<=|~=|>|<|=|;|~|\\||or|and|\n|\r|\r\n|'([^']|'')*'|\".*?\"|%.*?\n");
auto words_begin = std::sregex_iterator(m_code_str.begin(), m_code_str.end(), words_regex);
auto words_end = std::sregex_iterator();
@@ -55,6 +55,12 @@ void Lexer::debugTokens() {
Token Lexer::currentToken() { return m_tokens[m_index]; }
Token Lexer::consumeCurrentToken() {
int i = m_index;
nextToken();
return m_tokens[i];
}
void Lexer::nextToken() {
if (m_index < m_tokens.size()) {
m_index++;
@@ -65,7 +71,7 @@ void Lexer::skipToken(TokenType type) {
if (tokenType() == type) {
nextToken();
} else {
throw Exception("ERROR unexpected token " + currentToken().token_string + ", instead of " + typeToString(type));
throw Exception("ERROR unexpected token " + consumeCurrentToken().token_string + ", instead of " + typeToString(type));
}
}
@@ -177,10 +183,10 @@ TokenType Lexer::type(const std::string &token) {
if (token == "varchar")
return TokenType::keyword_varchar;
if (token == "||")
if (token == "or")
return TokenType::logical_or;
if (token == "&&")
if (token == "and")
return TokenType::logical_and;
if (token == ",")