Files
ivy/lang/lex.h

69 lines
1.3 KiB
C

#ifndef _LEX_H_
#define _LEX_H_
#include <fx/core/queue.h>
#include <fx/ds/dict.h>
#include <fx/ds/string.h>
#include <ivy/lang/lex.h>
#include <ivy/status.h>
#include <stdint.h>
enum lex_token_flags {
LEX_TOK_REQUIRES_WHITESPACE = 0x01u,
};
struct ivy_lexer {
struct ivy_lexer_symbol_node *lex_sym_tree;
struct ivy_diag_ctx *lex_diag_ctx;
struct ivy_line_source *lex_source;
fx_dict *lex_keywords;
enum ivy_status lex_status;
int lex_prev_char, lex_cur_char;
fx_queue lex_queue;
enum ivy_token_type lex_prev_token;
fx_string *lex_temp;
fx_queue lex_state;
unsigned int lex_brace_depth;
unsigned long lex_token_start_row, lex_token_start_col;
unsigned long lex_token_end_row, lex_token_end_col;
unsigned long lex_cursor_row, lex_cursor_col;
char *lex_linebuf;
size_t lex_linebuf_len;
size_t lex_linebuf_cap;
size_t lex_linebuf_ptr;
};
enum lexer_state_type {
STATE_NORMAL,
STATE_STRING,
STATE_FSTRING,
STATE_INTERPOLATION,
};
struct lexer_state {
enum lexer_state_type s_type;
unsigned int s_brace_depth;
fx_queue_entry s_entry;
};
struct ivy_lexer_symbol_node {
char s_char;
struct lex_token_def *s_def;
fx_queue_entry s_entry;
fx_queue s_children;
};
struct lex_token_def {
int id;
enum lex_token_flags flags;
const char *name;
uint64_t name_hash;
};
#endif