schema_editor/comdel/parser/comdellexer.h

71 lines
1.2 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>
struct LexerResult {
std::vector<Token> tokens;
std::vector<SourceError> errors;
};
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
};
std::string source;
std::vector<Token> tokens;
std::vector<SourceError> errors;
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:
void skipWhitespace();
unsigned takeNumberInRadix(Radix radix);
2022-05-27 06:18:17 +00:00
2022-03-29 19:31:45 +00:00
unsigned takeHexColor();
2022-05-27 06:18:17 +00:00
2022-03-29 19:31:45 +00:00
bool digitIsValid(char ch, Radix radix);
2022-05-27 06:18:17 +00:00
2022-03-29 19:31:45 +00:00
Radix takeRadix();
PResult<TokenType> nextTokenType();
Position tokenBegin;
Position position;
char ch;
void skipComment();
2022-05-27 06:18:17 +00:00
2022-03-29 19:31:45 +00:00
bool skipMultilineComment();
PResult<TokenType> takeString();
2022-05-27 06:18:17 +00:00
2022-03-29 19:31:45 +00:00
PResult<TokenType> takeRawString();
void bump(unsigned count = 1);
2022-05-27 06:18:17 +00:00
2022-03-29 19:31:45 +00:00
char peek();
2022-05-27 06:18:17 +00:00
2022-03-29 19:31:45 +00:00
bool eof();
};
2022-04-08 18:17:58 +00:00
#endif // COMDEL_LEXER_H