38 lines
1001 B
C
38 lines
1001 B
C
#ifndef __LEXER_H__
|
|
#define __LEXER_H__
|
|
|
|
#include "token.h"
|
|
#ifndef LEXER_MAX_TOKEN_SIZE
|
|
#define LEXER_MAX_TOKEN_SIZE 63
|
|
#endif
|
|
#ifndef LEXER_BUFFER_SIZE
|
|
#define LEXER_BUFFER_SIZE 4095
|
|
#endif
|
|
|
|
typedef int (*lexer_sread_fn)(void *dst_buf, int dst_size,
|
|
int elem_size, int count, void *stream);
|
|
|
|
typedef struct lexer {
|
|
int line;
|
|
int index;
|
|
// const char current_file_name[LEXER_BUFFER_SIZE+1];
|
|
|
|
unsigned char* cur_ptr; // 当前扫描的字符,但是还没有开始扫描
|
|
unsigned char* end_ptr; // 缓冲区最后一个字符的下一个位置
|
|
char buffer[LEXER_BUFFER_SIZE+1];
|
|
|
|
lexer_sread_fn sread;
|
|
void* stream;
|
|
} lexer_t;
|
|
|
|
void init_lexer(lexer_t* lexer, const char* file_name, void* stream,
|
|
lexer_sread_fn sread);
|
|
|
|
// pure token getter it will included empty token like TOKEN_FLUSH
|
|
void get_token(lexer_t* lexer, tok_t* token);
|
|
|
|
// get_token maybe got invalid (with parser as TOKEN_FLUSH)
|
|
void get_valid_token(lexer_t* lexer, tok_t* token);
|
|
|
|
#endif
|