Initial commit, support for lexing symbols and numericals.

This commit is contained in:
2020-10-04 16:33:12 +02:00
commit e0c52f4ae7
13 changed files with 6895 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
#ifndef ELOHIMSCRIPT_LEXER_HPP
#define ELOHIMSCRIPT_LEXER_HPP
#include <string_view>
#include "LexToken.hpp"
namespace ElohimScript::Parser {
class Lexer {
public:
Lexer(const char* script) : _script(reinterpret_cast<const char8_t*>(script)) {}
Lexer(std::u8string_view script) : _script(script) {}
const LexToken* Lex();
private:
std::u8string_view _script;
size_t _position = -1;
inline char8_t Consume() {
if (++_position >= _script.size()) {
return '\0';
}
return _script[_position];
}
inline void Progress(size_t steps = 1){
_position += steps;
}
inline char8_t Peek(size_t offset = 1) {
auto pos = _position + offset;
if (pos >= _script.size()) {
return '\0';
}
return _script[pos];
}
LexToken* LexNext();
LexToken* LexNumerical(char8_t);
LexToken* LexDecimal(uint64_t initial);
IntegerToken* LexHexadecimal();
IntegerToken* LexOctal();
IntegerToken* LexBinary();
};
}
#endif // ELOHIMSCRIPT_LEXER_HPP