skopy/lib/include/lexer.h

43 lines
1.2 KiB
C

#ifndef SK_LEXER_H
#define SK_LEXER_H
#include "commons.h"
#include "token.h"
struct context
{
int line;
size_t cursor;
};
struct lexer
{
char* source;
size_t len;
struct context context;
};
void lexer_init(struct lexer* self, char const* source);
void lexer_free(struct lexer* self);
bool lexer_is_at_end(struct lexer* self);
void lexer_skip_spaces(struct lexer* self);
void lexer_skip_comments(struct lexer* self);
bool lexer_is_sep(struct lexer* self, size_t index);
bool lexer_next_is(struct lexer* self, TokenKind kind);
void lexer_consume_next(struct lexer* self);
struct token* lexer_try_new_next(struct lexer* self);
struct token* lexer_try_scan_int(struct lexer* self);
struct token* lexer_try_scan_float(struct lexer* self);
struct token* lexer_try_scan_string(struct lexer* self);
struct token* lexer_try_scan_text(struct lexer* self,
char const* text,
TokenKind kind);
struct token* lexer_try_scan_keyword(struct lexer* self,
char const* keyword,
TokenKind kind,
char const* value);
#endif