schema_editor/comdel/parser/comdellexer.h

64 lines
1.2 KiB
C++

#ifndef COMDEL_LEXER_H
#define COMDEL_LEXER_H
#include "parsecontext.h"
#include "presult.h"
#include "sourceerror.h"
#include "token.h"
#include <sstream>
#include <string>
#include <vector>
struct LexerResult {
std::vector<Token> tokens;
std::vector<SourceError> errors;
};
class ComdelLexer
{
enum Radix {
BIN_NUMBER = 2,
DEC_NUMBER = 10,
HEX_NUMBER = 16
};
std::string source;
std::vector<Token> tokens;
std::vector<SourceError> errors;
ParseContext* parseContext;
unsigned fileId;
public:
ComdelLexer(std::string fileName, std::string source, ParseContext* parseContext);
LexerResult tokenize();
private:
void skipWhitespace();
unsigned takeNumberInRadix(Radix radix);
unsigned takeHexColor();
bool digitIsValid(char ch, Radix radix);
Radix takeRadix();
PResult<TokenType> nextTokenType();
Position tokenBegin;
Position position;
char ch;
void skipComment();
bool skipMultilineComment();
PResult<TokenType> takeString();
PResult<TokenType> takeRawString();
void bump(unsigned count = 1);
char peek();
bool eof();
};
#endif // COMDEL_LEXER_H