2018-05-12 00:53:02 +00:00
|
|
|
/*
|
|
|
|
4coder_config.h - Configuration structs.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
|
|
|
#if !defined(FCODER_CONFIG_H)
|
|
|
|
#define FCODER_CONFIG_H
|
|
|
|
|
2018-05-20 04:44:20 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2020-11-25 00:26:11 +00:00
|
|
|
////////////////////////////////
|
|
|
|
// NOTE(allen): Config Parser Types
|
|
|
|
|
2018-05-20 04:44:20 +00:00
|
|
|
struct Error_Location{
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 line_number;
|
|
|
|
i32 column_number;
|
2018-05-20 04:44:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Config_Error{
|
|
|
|
Config_Error *next;
|
|
|
|
Config_Error *prev;
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 file_name;
|
|
|
|
u8 *pos;
|
|
|
|
String_Const_u8 text;
|
2018-05-20 04:44:20 +00:00
|
|
|
};
|
|
|
|
|
2018-06-02 04:06:13 +00:00
|
|
|
struct Config_Error_List{
|
|
|
|
Config_Error *first;
|
|
|
|
Config_Error *last;
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 count;
|
2018-06-02 04:06:13 +00:00
|
|
|
};
|
|
|
|
|
2018-05-12 00:53:02 +00:00
|
|
|
struct Config_Parser{
|
2019-09-04 05:31:35 +00:00
|
|
|
Token *token;
|
2020-11-25 00:26:11 +00:00
|
|
|
Token *opl;
|
2018-05-12 00:53:02 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 file_name;
|
|
|
|
String_Const_u8 data;
|
2018-05-12 00:53:02 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
Arena *arena;
|
2018-05-20 04:44:20 +00:00
|
|
|
|
2018-06-02 04:06:13 +00:00
|
|
|
Config_Error_List errors;
|
2018-05-26 07:49:37 +00:00
|
|
|
};
|
2018-05-12 00:53:02 +00:00
|
|
|
|
|
|
|
struct Config_LValue{
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 identifier;
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 index;
|
2018-05-12 00:53:02 +00:00
|
|
|
};
|
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
typedef i32 Config_RValue_Type;
|
2018-05-12 00:53:02 +00:00
|
|
|
enum{
|
2020-11-25 01:06:12 +00:00
|
|
|
ConfigRValueType_Null,
|
|
|
|
ConfigRValueType_LValue,
|
|
|
|
ConfigRValueType_Boolean,
|
|
|
|
ConfigRValueType_Integer,
|
|
|
|
ConfigRValueType_String,
|
|
|
|
ConfigRValueType_Compound,
|
|
|
|
ConfigRValueType_COUNT
|
2018-05-12 00:53:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Config_Compound{
|
|
|
|
struct Config_Compound_Element *first;
|
|
|
|
struct Config_Compound_Element *last;
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 count;
|
2018-05-12 00:53:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Config_RValue{
|
|
|
|
Config_RValue_Type type;
|
|
|
|
union{
|
|
|
|
Config_LValue *lvalue;
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 boolean;
|
|
|
|
i32 integer;
|
|
|
|
u32 uinteger;
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 string;
|
2018-05-12 00:53:02 +00:00
|
|
|
char character;
|
|
|
|
Config_Compound *compound;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-05-19 22:05:31 +00:00
|
|
|
struct Config_Integer{
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 is_signed;
|
2018-05-19 22:05:31 +00:00
|
|
|
union{
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 integer;
|
|
|
|
u32 uinteger;
|
2018-05-19 22:05:31 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
typedef i32 Config_Layout_Type;
|
2018-05-12 00:53:02 +00:00
|
|
|
enum{
|
2020-11-25 01:36:43 +00:00
|
|
|
ConfigLayoutType_Unset,
|
|
|
|
ConfigLayoutType_Identifier,
|
|
|
|
ConfigLayoutType_Integer,
|
|
|
|
ConfigLayoutType_COUNT,
|
2018-05-12 00:53:02 +00:00
|
|
|
};
|
|
|
|
struct Config_Layout{
|
|
|
|
Config_Layout_Type type;
|
2019-06-01 23:58:28 +00:00
|
|
|
u8 *pos;
|
2018-05-12 00:53:02 +00:00
|
|
|
union{
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 identifier;
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 integer;
|
2018-05-12 00:53:02 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Config_Compound_Element{
|
|
|
|
Config_Compound_Element *next;
|
|
|
|
Config_Compound_Element *prev;
|
|
|
|
|
|
|
|
Config_Layout l;
|
|
|
|
Config_RValue *r;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Config_Assignment{
|
|
|
|
Config_Assignment *next;
|
|
|
|
Config_Assignment *prev;
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
u8 *pos;
|
2018-05-12 00:53:02 +00:00
|
|
|
Config_LValue *l;
|
|
|
|
Config_RValue *r;
|
2018-05-15 20:19:48 +00:00
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 visited;
|
2018-05-12 00:53:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Config{
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 *version;
|
2018-05-12 00:53:02 +00:00
|
|
|
Config_Assignment *first;
|
|
|
|
Config_Assignment *last;
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 count;
|
2018-05-20 04:44:20 +00:00
|
|
|
|
2018-06-02 04:06:13 +00:00
|
|
|
Config_Error_List errors;
|
2018-05-20 04:44:20 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 file_name;
|
|
|
|
String_Const_u8 data;
|
2018-05-12 00:53:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////
|
2020-11-25 00:26:11 +00:00
|
|
|
// NOTE(allen): Config Iteration
|
2018-05-12 00:53:02 +00:00
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
typedef i32 Iteration_Step_Result;
|
2018-05-30 20:27:47 +00:00
|
|
|
enum{
|
|
|
|
Iteration_Good = 0,
|
|
|
|
Iteration_Skip = 1,
|
|
|
|
Iteration_Quit = 2,
|
|
|
|
};
|
|
|
|
|
2018-05-30 07:58:22 +00:00
|
|
|
struct Config_Get_Result{
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 success;
|
2018-05-30 07:58:22 +00:00
|
|
|
Config_RValue_Type type;
|
2019-06-01 23:58:28 +00:00
|
|
|
u8 *pos;
|
2018-05-30 07:58:22 +00:00
|
|
|
union{
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 boolean;
|
|
|
|
i32 integer;
|
|
|
|
u32 uinteger;
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 string;
|
2018-05-30 07:58:22 +00:00
|
|
|
char character;
|
|
|
|
Config_Compound *compound;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-05-30 20:27:47 +00:00
|
|
|
struct Config_Iteration_Step_Result{
|
|
|
|
Iteration_Step_Result step;
|
|
|
|
Config_Get_Result get;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Config_Get_Result_Node{
|
|
|
|
Config_Get_Result_Node *next;
|
|
|
|
Config_Get_Result_Node *prev;
|
|
|
|
Config_Get_Result result;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Config_Get_Result_List{
|
|
|
|
Config_Get_Result_Node *first;
|
|
|
|
Config_Get_Result_Node *last;
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 count;
|
2018-05-30 20:27:47 +00:00
|
|
|
};
|
|
|
|
|
2018-05-30 07:58:22 +00:00
|
|
|
////////////////////////////////
|
2020-11-25 00:26:11 +00:00
|
|
|
// NOTE(allen): Config Data Type
|
2018-05-30 07:58:22 +00:00
|
|
|
|
2018-05-12 00:53:02 +00:00
|
|
|
struct Config_Data{
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8_Array code_exts;
|
2018-05-28 01:00:13 +00:00
|
|
|
|
2020-05-02 04:21:14 +00:00
|
|
|
f32 cursor_roundness;
|
|
|
|
f32 mark_thickness;
|
|
|
|
f32 lister_roundness;
|
|
|
|
|
2020-02-08 00:50:35 +00:00
|
|
|
i32 virtual_whitespace_regular_indent;
|
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 indent_width;
|
2020-05-02 03:59:36 +00:00
|
|
|
i32 default_tab_width;
|
2018-05-28 05:30:31 +00:00
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 default_font_size;
|
2018-05-26 07:49:37 +00:00
|
|
|
};
|
2018-05-12 00:53:02 +00:00
|
|
|
|
2020-11-25 00:26:11 +00:00
|
|
|
////////////////////////////////
|
|
|
|
// NOTE(allen): Config Parser Functions
|
|
|
|
|
|
|
|
function Config_Parser def_config_parser_init(Arena *arena, String_Const_u8 file_name, String_Const_u8 data, Token_Array array);
|
|
|
|
|
|
|
|
function void def_config_parser_inc(Config_Parser *ctx);
|
|
|
|
function u8* def_config_parser_get_pos(Config_Parser *ctx);
|
|
|
|
|
|
|
|
function b32 def_config_parser_recognize_base_kind(Config_Parser *ctx, Token_Base_Kind kind);
|
|
|
|
function b32 def_config_parser_recognize_cpp_kind(Config_Parser *ctx, Token_Cpp_Kind kind);
|
|
|
|
function b32 def_config_parser_recognize_boolean(Config_Parser *ctx);
|
|
|
|
function b32 def_config_parser_recognize_text(Config_Parser *ctx, String_Const_u8 text);
|
|
|
|
|
|
|
|
function b32 def_config_parser_match_cpp_kind(Config_Parser *ctx, Token_Cpp_Kind kind);
|
|
|
|
function b32 def_config_parser_match_text(Config_Parser *ctx, String_Const_u8 text);
|
|
|
|
|
|
|
|
function String_Const_u8 def_config_parser_get_lexeme(Config_Parser *ctx);
|
|
|
|
function Config_Integer def_config_parser_get_int(Config_Parser *ctx);
|
|
|
|
function b32 def_config_parser_get_boolean(Config_Parser *ctx);
|
|
|
|
|
2020-11-25 00:58:29 +00:00
|
|
|
function void def_config_parser_recover(Config_Parser *ctx);
|
|
|
|
|
2020-11-25 22:35:27 +00:00
|
|
|
function Config* def_config_parser_top (Config_Parser *ctx);
|
2020-11-25 00:26:11 +00:00
|
|
|
function i32* def_config_parser_version (Config_Parser *ctx);
|
|
|
|
function Config_Assignment* def_config_parser_assignment(Config_Parser *ctx);
|
|
|
|
function Config_LValue* def_config_parser_lvalue (Config_Parser *ctx);
|
|
|
|
function Config_RValue* def_config_parser_rvalue (Config_Parser *ctx);
|
|
|
|
function Config_Compound* def_config_parser_compound (Config_Parser *ctx);
|
|
|
|
function Config_Compound_Element* def_config_parser_element (Config_Parser *ctx);
|
|
|
|
|
|
|
|
function Config* def_config_parse(Application_Links *app, Arena *arena, String_Const_u8 file_name, String_Const_u8 data, Token_Array array);
|
2020-11-25 22:35:27 +00:00
|
|
|
function Config* def_config_from_text(Application_Links *app, Arena *arena, String_Const_u8 file_name, String_Const_u8 data);
|
2020-11-25 00:26:11 +00:00
|
|
|
|
|
|
|
function Config_Error* def_config_push_error(Arena *arena, Config_Error_List *list, String_Const_u8 file_name, u8 *pos, char *error_text);
|
2020-11-25 00:58:29 +00:00
|
|
|
function Config_Error* def_config_push_error(Arena *arena, Config *config, u8 *pos, char *error_text);
|
|
|
|
|
2020-11-25 00:26:11 +00:00
|
|
|
function void def_config_parser_push_error(Config_Parser *ctx, u8 *pos, char *error_text);
|
|
|
|
function void def_config_parser_push_error_here(Config_Parser *ctx, char *error_text);
|
|
|
|
|
2020-11-25 00:58:29 +00:00
|
|
|
function void def_config_parser_recover(Config_Parser *ctx);
|
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
// NOTE(allen): Dump Config to Variables
|
|
|
|
|
2020-11-25 22:35:27 +00:00
|
|
|
function Variable_Handle def_fill_var_from_config(Application_Links *app, Variable_Handle parent, String_ID key, Config *config);
|
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
// NOTE(allen): Config Variables Read
|
|
|
|
|
|
|
|
function Variable_Handle def_get_config_var(String_ID key);
|
|
|
|
function void def_set_config_var(String_ID key, String_ID val);
|
|
|
|
|
|
|
|
function b32 def_get_config_b32(String_ID key);
|
|
|
|
function void def_set_config_b32(String_ID key, b32 val);
|
2020-11-25 00:58:29 +00:00
|
|
|
|
2020-11-26 02:29:21 +00:00
|
|
|
function String_Const_u8 def_get_config_string(Arena *arena, String_ID key);
|
|
|
|
function void def_set_config_string(String_ID key, String_Const_u8 val);
|
|
|
|
|
2018-05-12 00:53:02 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// BOTTOM
|
|
|
|
|