Yerbacon/src/headers/lex.hpp
2022-03-01 20:14:47 +01:00

33 lines
1.3 KiB
C++

#ifndef YERBACON_LEX_H
#define YERBACON_LEX_H
#include <vector>
#include "Yerbacon.hpp"
#include <limits>
#include <ostream>
struct tok {
typedef Yerbacon::Exception LexerException;
enum type: const unsigned short {
UNEXPECTED = std::numeric_limits<unsigned char>::max() + 1, IDENTIFIER, NUMBER, ALPHACHAR,
DEFINE = '=', TAG = '#', DOLLAR_SIGN = '$', DOT = '.', COMMA = ',',
LPAR = '(', LBRACE = '{', LBRACKET = '[', RPAR = ')',
RBRACE = '}', RBRACKET = ']',
PLUS = '+', HYPHEN = '-', DIVIDE = '/',
LCOMP = '>', RCOMP = '<',
SQUOTE = '\'', ASTERISK = '*', STRING = '"',
};
static auto inverseLCharacter(const unsigned char& character) {
return static_cast<unsigned char>(((character + 2) - (character == tok::LPAR)));
};
type toktype;
std::string toktext;
unsigned long line;
tok(): toktype(UNEXPECTED), toktext(), line(0) {};
tok(const type& Type, std::string_view Text, const decltype(line)& line = 0): toktype(Type), toktext(Text), line(line) {}
explicit tok(const type& Type, const decltype(line)& line = 0): tok(Type, std::string(1, Type), line) {};
friend std::ostream& operator<<(std::ostream& output, const tok& it) { return output << it.toktext; }
};
std::vector<tok> lex(const std::string& in);
#endif //YERBACON_TEST_H