Use block allocator for lexer.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <string_view>
|
||||
#include "../../Diagnostics/Diagnostics.hpp"
|
||||
#include "../../Utils/MemoryAllocator.hpp"
|
||||
#include "LexToken.hpp"
|
||||
|
||||
namespace ElohimScript::Parser {
|
||||
@@ -10,17 +11,21 @@ namespace ElohimScript::Parser {
|
||||
public:
|
||||
Lexer(const char* script, Diagnostics::Diagnostics* diag)
|
||||
: Lexer(reinterpret_cast<const char8_t*>(script), diag) {}
|
||||
Lexer(const char8_t* script, Diagnostics::Diagnostics* diag) : _script(script), _diagnostics(diag) {}
|
||||
Lexer(std::u8string_view script, Diagnostics::Diagnostics* diag) : _script(script), _diagnostics(diag) {}
|
||||
Lexer(const char8_t* script, Diagnostics::Diagnostics* diag) : Lexer(std::u8string_view(script), diag) {}
|
||||
Lexer(std::u8string_view script, Diagnostics::Diagnostics* diag)
|
||||
: _script(script), _scriptLength(script.size()), _diagnostics(diag) {}
|
||||
const LexToken* Lex();
|
||||
|
||||
private:
|
||||
std::u8string_view _script;
|
||||
size_t _position = -1;
|
||||
size_t _scriptLength;
|
||||
Diagnostics::Diagnostics* _diagnostics;
|
||||
|
||||
Utils::MemoryAllocator<2048, 1024> _allocator;
|
||||
|
||||
inline char8_t Consume() {
|
||||
if (++_position >= _script.size()) {
|
||||
if (++_position >= _scriptLength) {
|
||||
return '\0';
|
||||
}
|
||||
return _script[_position];
|
||||
@@ -30,10 +35,10 @@ namespace ElohimScript::Parser {
|
||||
|
||||
inline char8_t Peek(size_t offset = 1) {
|
||||
auto pos = _position + offset;
|
||||
if (pos >= _script.size()) {
|
||||
if (pos >= _scriptLength) {
|
||||
return '\0';
|
||||
}
|
||||
return _script[pos];
|
||||
return *(_script.data() + pos);
|
||||
}
|
||||
|
||||
LexToken* LexNext();
|
||||
@@ -47,6 +52,10 @@ namespace ElohimScript::Parser {
|
||||
LexToken* LexKeywordOrIdentifier();
|
||||
|
||||
static bool IsAlphaNumericalOrUnderscore(char8_t c);
|
||||
|
||||
template <class T, class... parameters> inline T* Create(parameters... args) {
|
||||
return _allocator.Create<T>(args...);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user