2024-11-19 15:22:16 +00:00
|
|
|
#ifndef _LEX_H_
|
|
|
|
|
#define _LEX_H_
|
|
|
|
|
|
|
|
|
|
#include <blue/core/queue.h>
|
2025-11-06 10:38:32 +00:00
|
|
|
#include <blue/ds/dict.h>
|
|
|
|
|
#include <blue/ds/string.h>
|
2024-11-22 22:30:26 +00:00
|
|
|
#include <ivy/lang/lex.h>
|
|
|
|
|
#include <ivy/status.h>
|
2024-11-19 15:22:16 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
2025-11-07 09:49:29 +00:00
|
|
|
enum lex_token_flags {
|
|
|
|
|
LEX_TOK_REQUIRES_WHITESPACE = 0x01u,
|
|
|
|
|
};
|
|
|
|
|
|
2024-11-19 15:22:16 +00:00
|
|
|
struct ivy_lexer {
|
|
|
|
|
struct ivy_lexer_symbol_node *lex_sym_tree;
|
2025-05-08 20:31:55 +01:00
|
|
|
struct ivy_diag_ctx *lex_diag_ctx;
|
2024-11-19 15:22:16 +00:00
|
|
|
struct ivy_line_source *lex_source;
|
|
|
|
|
b_dict *lex_keywords;
|
|
|
|
|
enum ivy_status lex_status;
|
2025-11-07 09:49:29 +00:00
|
|
|
int lex_prev_char, lex_cur_char;
|
2024-11-19 15:22:16 +00:00
|
|
|
|
2024-11-24 16:12:06 +00:00
|
|
|
b_queue lex_queue;
|
2024-11-19 15:22:16 +00:00
|
|
|
enum ivy_token_type lex_prev_token;
|
|
|
|
|
|
|
|
|
|
b_string *lex_temp;
|
|
|
|
|
b_queue lex_state;
|
|
|
|
|
unsigned int lex_brace_depth;
|
|
|
|
|
|
2025-04-28 22:53:21 +01:00
|
|
|
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;
|
|
|
|
|
|
2024-11-19 15:22:16 +00:00
|
|
|
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;
|
|
|
|
|
b_queue_entry s_entry;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ivy_lexer_symbol_node {
|
|
|
|
|
char s_char;
|
2025-11-07 09:49:29 +00:00
|
|
|
struct lex_token_def *s_def;
|
2024-11-19 15:22:16 +00:00
|
|
|
|
|
|
|
|
b_queue_entry s_entry;
|
|
|
|
|
b_queue s_children;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct lex_token_def {
|
|
|
|
|
int id;
|
2025-11-07 09:49:29 +00:00
|
|
|
enum lex_token_flags flags;
|
2024-11-19 15:22:16 +00:00
|
|
|
const char *name;
|
|
|
|
|
uint64_t name_hash;
|
|
|
|
|
};
|
|
|
|
|
|
2024-11-22 22:30:26 +00:00
|
|
|
#endif
|