ccm/lib/lexer.h

57 lines
1.4 KiB
C

#ifndef CCM_LEXER_H
#define CCM_LEXER_H
#include "commons.h"
#include "node.h"
#include "str.h"
#include "err.h"
typedef struct {
ssize_t cursor;
int line;
} lexer_state_t;
typedef struct {
char const* repr;
NodeKind kind;
} lexer_entry_t;
typedef struct {
err_t err;
str_t separators;
char* source;
ssize_t cursor;
int line;
vec_t texts;
} lexer_t;
void lexer_init(lexer_t* self);
void lexer_free(lexer_t* self);
void lexer_scan(lexer_t* self, char const* source);
void lexer_skip_spaces(lexer_t* self);
int lexer_is_sep(lexer_t* self, ssize_t pos);
void lexer_add_text(lexer_t* self, char const* repr, NodeKind kind);
node_t* lexer_peek(lexer_t* self, int lookahead);
int lexer_peek_kind(lexer_t* self, NodeKind kind, int lookahead);
lexer_state_t lexer_state(lexer_t* self);
void lexer_restore(lexer_t* self, lexer_state_t state);
node_t* lexer_try_new_next(lexer_t* self);
int lexer_consume_next(lexer_t* self, NodeKind kind);
node_t* lexer_try_new_keyword(lexer_t* self,
char const* keyword,
NodeKind kind,
int has_value);
node_t* lexer_try_new_text(lexer_t* self,
char const* text,
NodeKind kind,
int has_value);
node_t* lexer_try_new_num(lexer_t* self);
#endif