71 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			71 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
#ifndef COMDEL_LEXER_H
 | 
						|
#define COMDEL_LEXER_H
 | 
						|
 | 
						|
#include "parse_context.h"
 | 
						|
#include "presult.h"
 | 
						|
#include "source_error.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
 |