skopy/lib/include/lexer.h

42 lines
1.1 KiB
C
Raw Normal View History

2024-03-31 21:10:56 +00:00
#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);
2024-04-01 12:13:36 +00:00
bool lexer_is_at_end(struct lexer* self);
2024-03-31 21:10:56 +00:00
void lexer_skip_spaces(struct lexer* self);
2024-04-01 12:13:36 +00:00
void lexer_skip_comments(struct lexer* self);
bool lexer_is_sep(struct lexer* self, size_t index);
2024-03-31 21:10:56 +00:00
bool lexer_next_is(struct lexer* self, TokenKind kind);
2024-03-31 23:32:47 +00:00
void lexer_consume_next(struct lexer* self);
2024-03-31 21:10:56 +00:00
struct token* lexer_try_new_next(struct lexer* self);
struct token* lexer_try_scan_int(struct lexer* self);
2024-04-01 19:08:42 +00:00
struct token* lexer_try_scan_float(struct lexer* self);
2024-03-31 23:32:47 +00:00
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);
2024-03-31 21:10:56 +00:00
#endif