#ifndef COMDEL_LEXER_H #define COMDEL_LEXER_H #include "parse_context.h" #include "presult.h" #include "source_error.h" #include "token.h" #include #include #include /** Contains results of tokenizing, * if errors isn't empty tokenizing has failed */ struct LexerResult { std::vector tokens; std::vector errors; }; /** Used to tokenize input string */ class ComdelLexer { enum Radix { BIN_NUMBER = 2, DEC_NUMBER = 10, HEX_NUMBER = 16 }; /** Source file */ std::string source; std::vector tokens; std::vector errors; /** Source file */ ParseContext *parseContext; unsigned fileId; public: ComdelLexer(std::string fileName, std::string source, ParseContext *parseContext); LexerResult tokenize(); private: /** Current parsing info */ Position tokenBegin; Position position; char ch; /** Methods used to skip unused content */ void skipWhitespace(); void skipComment(); bool skipMultilineComment(); void bump(unsigned count = 1); /** Metods used for number parsing */ unsigned takeNumberInRadix(Radix radix); bool digitIsValid(char ch, Radix radix); Radix takeRadix(); unsigned takeHexColor(); PResult nextTokenType(); PResult takeString(); PResult takeRawString(); char peek(); /** Checks if we reached end of file */ bool eof(); }; #endif // COMDEL_LEXER_H