Yerbacon/src/headers/lex.hpp
Username404 04923f03a5
Revert "Remove a useless #include directive in lex.hpp"
This reverts commit 41e33e30ba5faef9bd841777eae8701718bf8f69.
2022-02-14 14:12:00 +01:00

38 lines
1.4 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,
EOF_ = '\0', DEFINE = '=', TAG = '#', DOLLAR_SIGN = '$', DOT = '.',
LPAR = '(', LBRACE = '{', LBRACKET = '[', RPAR = ')',
RBRACE = '}', RBRACKET = ']',
PLUS = '+', HYPHEN = '-', DIVIDE = '/',
LCOMP = '>', RCOMP = '<',
SQUOTE = '\'', ASTERISK = '*', STRING = '"',
};
const type toktype;
const std::string toktext;
const unsigned long line;
tok& operator=(const tok& other) {
if (this != &other) {
const_cast<type&>(toktype) = other.toktype;
const_cast<std::string&>(toktext) = other.toktext;
const_cast<unsigned long&>(line) = other.line;
}
return *this;
}
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