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