28 lines
1.1 KiB
C++
28 lines
1.1 KiB
C++
#ifndef YERBACON_LEX_H
|
|
#define YERBACON_LEX_H
|
|
|
|
#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(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
|