mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 03:08:13 +00:00
LibSQL: Move Lexer and Parser machinery to AST directory
The SQL engine is expected to be a fairly sizeable piece of software. Therefore we're starting to restructure the codebase for growth.
This commit is contained in:
parent
e0f1c237d2
commit
4198f7e1af
24 changed files with 281 additions and 278 deletions
53
Userland/Libraries/LibSQL/AST/Token.cpp
Normal file
53
Userland/Libraries/LibSQL/AST/Token.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Tim Flynn <trflynn89@pm.me>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "Token.h"
|
||||
#include <AK/Assertions.h>
|
||||
#include <AK/String.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace SQL::AST {
|
||||
|
||||
StringView Token::name(TokenType type)
|
||||
{
|
||||
switch (type) {
|
||||
#define __ENUMERATE_SQL_TOKEN(value, type, category) \
|
||||
case TokenType::type: \
|
||||
return #type;
|
||||
ENUMERATE_SQL_TOKENS
|
||||
#undef __ENUMERATE_SQL_TOKEN
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
TokenCategory Token::category(TokenType type)
|
||||
{
|
||||
switch (type) {
|
||||
#define __ENUMERATE_SQL_TOKEN(value, type, category) \
|
||||
case TokenType::type: \
|
||||
return TokenCategory::category;
|
||||
ENUMERATE_SQL_TOKENS
|
||||
#undef __ENUMERATE_SQL_TOKEN
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
double Token::double_value() const
|
||||
{
|
||||
VERIFY(type() == TokenType::NumericLiteral);
|
||||
String value(m_value);
|
||||
|
||||
if (value[0] == '0' && value.length() >= 2) {
|
||||
if (value[1] == 'x' || value[1] == 'X')
|
||||
return static_cast<double>(strtoul(value.characters() + 2, nullptr, 16));
|
||||
}
|
||||
|
||||
return strtod(value.characters(), nullptr);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue