extract functions to own file

This commit is contained in:
2021-12-18 13:37:42 +01:00
parent c9c4f0fba3
commit 906df74847
8 changed files with 184 additions and 164 deletions

View File

@@ -23,7 +23,7 @@ namespace usql {
void Lexer::parse(const std::string &code) {
if (code.empty())
throw Exception("empty code");
throw Exception("Lexer.parse empty code");
m_tokens.clear();
m_tokens.reserve(64);
@@ -40,7 +40,9 @@ namespace usql {
std::smatch match = *i;
std::string match_str = match.str();
TokenType token_type = type(match_str);
if (token_type == TokenType::string_literal)
if (token_type == TokenType::undef)
throw Exception("Lexer.parse unknown token type: " + match_str);
if (token_type == TokenType::string_literal)
match_str = stringLiteral(match_str);
if (token_type != TokenType::newline)
@@ -119,7 +121,6 @@ namespace usql {
}
TokenType Lexer::type(const std::string &token) {
// FIXME 'one is evaluated as identifier
if (token == ";") return TokenType::semicolon;
if (token == "+") return TokenType::plus;
if (token == "-") return TokenType::minus;
@@ -177,16 +178,16 @@ namespace usql {
if (token.length() > 1 && token.at(0) == '%' && (token.at(token.length() - 1) == '\n' || token.at(token.length() - 1) == '\r'))
return TokenType::comment;
if (token.length() >= 2 && token.at(0) == '"' && token.at(token.length() - 1) == '"')
return TokenType::string_literal;
if (token.length() >= 2 && token.at(0) == '"')
return (token.at(token.length() - 1) == '"') ? TokenType::string_literal : TokenType::undef;
if (token.length() >= 2 && token.at(0) == '\'' && token.at(token.length() - 1) == '\'')
return TokenType::string_literal;
if (token.length() >= 2 && token.at(0) == '\'')
return (token.at(token.length() - 1) == '\'') ? TokenType::string_literal : TokenType::undef;
if (std::regex_match(token, k_int_regex)) return TokenType::int_number;
if (std::regex_match(token, k_int_underscored_regex)) return TokenType::int_number;
if (std::regex_match(token, k_double_regex)) return TokenType::double_number;
if (std::regex_match(token, k_identifier_regex)) return TokenType::identifier;
if (std::regex_match(token, k_identifier_regex)) return TokenType::identifier;
return TokenType::undef;
}