schema_editor/comdel/parser/comdel_lexer.h

74 lines
1.5 KiB
C
Raw Normal View History

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