moka/lib/lexer.h

63 lines
1.7 KiB
C

#ifndef MK_LEXER_H
#define MK_LEXER_H
#include "token.h"
#include "commons.h"
#include "status.h"
#include "str.h"
struct lex_context
{
size_t cursor;
int line;
};
struct lexer
{
struct status* status;
char* source;
size_t len;
struct lex_context context;
struct str separators;
};
void lexer_init(struct lexer* self,
char const* source,
struct status* status);
void lexer_free(struct lexer* self);
struct token* lexer_try_new_next(struct lexer* self);
void lexer_skip(struct lexer* self, TokenKind kind);
void lexer_skip_spaces(struct lexer* self);
void lexer_skip_comments(struct lexer* self);
struct token* lexer_try_new_int(struct lexer* self);
struct token* lexer_try_new_float(struct lexer* self);
struct token* lexer_try_new_string(struct lexer* self);
struct token* lexer_try_new_symbol(struct lexer* self);
struct token* lexer_try_new_ident(struct lexer* self);
bool lexer_is_sep(struct lexer* self, size_t index);
bool lexer_is_ident(struct lexer* self, size_t index);
struct token* lexer_try_new_text(struct lexer* self,
TokenKind kind,
char const* text);
struct token* lexer_try_new_keyword(struct lexer* self,
TokenKind kind,
char const* keyword,
char const* value);
struct lex_context lexer_state(struct lexer* self);
void lexer_restore(struct lexer* self,
struct lex_context context);
bool lexer_next_is(struct lexer* self,
TokenKind kind,
int lookahead);
bool lexer_end(struct lexer* self);
#endif