Partial implementation of dump to vars; cleanup some unused config cruft

This commit is contained in:
Allen Webster 2020-11-24 16:58:29 -08:00
parent 7464320e56
commit 8c5e345f66
5 changed files with 203 additions and 152 deletions

View File

@ -231,40 +231,6 @@ def_config_parser_get_boolean(Config_Parser *ctx){
return(string_match(str, string_u8_litexpr("true")));
}
function Config*
def_config_parse(Application_Links *app, Arena *arena, String_Const_u8 file_name,
String_Const_u8 data, Token_Array array){
ProfileScope(app, "config parse");
Temp_Memory restore_point = begin_temp(arena);
Config_Parser ctx = def_config_parser_init(arena, file_name, data, array);
Config *config = def_config_parser_config(&ctx);
if (config == 0){
end_temp(restore_point);
}
return(config);
}
function Config_Error*
def_config_push_error(Arena *arena, Config_Error_List *list, String_Const_u8 file_name, u8 *pos, char *error_text){
Config_Error *error = push_array(arena, Config_Error, 1);
zdll_push_back(list->first, list->last, error);
list->count += 1;
error->file_name = file_name;
error->pos = pos;
error->text = push_string_copy(arena, SCu8(error_text));
return(error);
}
function void
def_config_parser_push_error(Config_Parser *ctx, u8 *pos, char *error_text){
def_config_push_error(ctx->arena, &ctx->errors, ctx->file_name, pos, error_text);
}
function void
def_config_parser_push_error_here(Config_Parser *ctx, char *error_text){
def_config_parser_push_error(ctx, def_config_parser_get_pos(ctx), error_text);
}
function Config*
def_config_parser_config(Config_Parser *ctx){
i32 *version = def_config_parser_version(ctx);
@ -292,32 +258,19 @@ def_config_parser_config(Config_Parser *ctx){
return(config);
}
function void
config_parser__recover_parse(Config_Parser *ctx){
for (;;){
if (def_config_parser_match_cpp_kind(ctx, TokenCppKind_Semicolon)){
break;
}
if (def_config_parser_recognize_cpp_kind(ctx, TokenCppKind_EOF)){
break;
}
def_config_parser_inc(ctx);
}
}
function i32*
def_config_parser_version(Config_Parser *ctx){
require(def_config_parser_match_text(ctx, string_u8_litinit("version")));
if (!def_config_parser_match_cpp_kind(ctx, TokenCppKind_ParenOp)){
def_config_parser_push_error_here(ctx, "expected token '(' for version specifier: 'version(#)'");
config_parser__recover_parse(ctx);
def_config_parser_recover(ctx);
return(0);
}
if (!def_config_parser_recognize_base_kind(ctx, TokenBaseKind_LiteralInteger)){
def_config_parser_push_error_here(ctx, "expected an integer constant for version specifier: 'version(#)'");
config_parser__recover_parse(ctx);
def_config_parser_recover(ctx);
return(0);
}
@ -326,13 +279,13 @@ def_config_parser_version(Config_Parser *ctx){
if (!def_config_parser_match_cpp_kind(ctx, TokenCppKind_ParenCl)){
def_config_parser_push_error_here(ctx, "expected token ')' for version specifier: 'version(#)'");
config_parser__recover_parse(ctx);
def_config_parser_recover(ctx);
return(0);
}
if (!def_config_parser_match_cpp_kind(ctx, TokenCppKind_Semicolon)){
def_config_parser_push_error_here(ctx, "expected token ';' for version specifier: 'version(#)'");
config_parser__recover_parse(ctx);
def_config_parser_recover(ctx);
return(0);
}
@ -348,13 +301,13 @@ def_config_parser_assignment(Config_Parser *ctx){
Config_LValue *l = def_config_parser_lvalue(ctx);
if (l == 0){
def_config_parser_push_error_here(ctx, "expected an l-value; l-value formats: 'identifier', 'identifier[#]'");
config_parser__recover_parse(ctx);
def_config_parser_recover(ctx);
return(0);
}
if (!def_config_parser_match_cpp_kind(ctx, TokenCppKind_Eq)){
def_config_parser_push_error_here(ctx, "expected token '=' for assignment: 'l-value = r-value;'");
config_parser__recover_parse(ctx);
def_config_parser_recover(ctx);
return(0);
}
@ -366,13 +319,13 @@ def_config_parser_assignment(Config_Parser *ctx){
"\tcompound: '{ compound-element, compound-element, compound-element ...}'\n"
"\ta compound-element is an r-value, and can have a layout specifier\n"
"\tcompound-element with layout specifier: .name = r-value, .integer = r-value");
config_parser__recover_parse(ctx);
def_config_parser_recover(ctx);
return(0);
}
if (!def_config_parser_match_cpp_kind(ctx, TokenCppKind_Semicolon)){
def_config_parser_push_error_here(ctx, "expected token ';' for assignment: 'l-value = r-value;'");
config_parser__recover_parse(ctx);
def_config_parser_recover(ctx);
return(0);
}
@ -450,15 +403,6 @@ def_config_parser_rvalue(Config_Parser *ctx){
rvalue->type = ConfigRValueType_String;
rvalue->string = interpreted;
}
else if (def_config_parser_recognize_cpp_kind(ctx, TokenCppKind_LiteralCharacter)){
String_Const_u8 s = def_config_parser_get_lexeme(ctx);
def_config_parser_inc(ctx);
s = string_chop(string_skip(s, 1), 1);
String_Const_u8 interpreted = string_interpret_escapes(ctx->arena, s);
rvalue = push_array_zero(ctx->arena, Config_RValue, 1);
rvalue->type = ConfigRValueType_Character;
rvalue->character = string_get_character(interpreted, 0);
}
return(rvalue);
}
@ -540,15 +484,184 @@ def_config_parser_element(Config_Parser *ctx){
return(element);
}
////////////////////////////////
function Config*
def_config_parse(Application_Links *app, Arena *arena, String_Const_u8 file_name,
String_Const_u8 data, Token_Array array){
ProfileScope(app, "config parse");
Temp_Memory restore_point = begin_temp(arena);
Config_Parser ctx = def_config_parser_init(arena, file_name, data, array);
Config *config = def_config_parser_config(&ctx);
if (config == 0){
end_temp(restore_point);
}
return(config);
}
// TODO(allen): WHAT THE HELL IS THIS SHIT?
function Config_Error*
config_add_error(Arena *arena, Config *config, u8 *pos, char *error_text){
def_config_push_error(Arena *arena, Config_Error_List *list, String_Const_u8 file_name, u8 *pos, char *error_text){
Config_Error *error = push_array(arena, Config_Error, 1);
zdll_push_back(list->first, list->last, error);
list->count += 1;
error->file_name = file_name;
error->pos = pos;
error->text = push_string_copy(arena, SCu8(error_text));
return(error);
}
function Config_Error*
def_config_push_error(Arena *arena, Config *config, u8 *pos, char *error_text){
return(def_config_push_error(arena, &config->errors, config->file_name, pos, error_text));
}
function void
def_config_parser_push_error(Config_Parser *ctx, u8 *pos, char *error_text){
def_config_push_error(ctx->arena, &ctx->errors, ctx->file_name, pos, error_text);
}
function void
def_config_parser_push_error_here(Config_Parser *ctx, char *error_text){
def_config_parser_push_error(ctx, def_config_parser_get_pos(ctx), error_text);
}
function void
def_config_parser_recover(Config_Parser *ctx){
for (;;){
if (def_config_parser_match_cpp_kind(ctx, TokenCppKind_Semicolon)){
break;
}
if (def_config_parser_recognize_cpp_kind(ctx, TokenCppKind_EOF)){
break;
}
def_config_parser_inc(ctx);
}
}
////////////////////////////////
// NOTE(allen): Dump Config to Variables
#if 0
struct Config_Assignment{
Config_Assignment *next;
Config_Assignment *prev;
u8 *pos;
Config_LValue *l;
Config_RValue *r;
b32 visited;
};
struct Config_LValue{
String_Const_u8 identifier;
i32 index;
};
struct Config_RValue{
Config_RValue_Type type;
union{
Config_LValue *lvalue;
b32 boolean;
i32 integer;
u32 uinteger;
String_Const_u8 string;
char character;
Config_Compound *compound;
};
};
struct Config{
i32 *version;
Config_Assignment *first;
Config_Assignment *last;
i32 count;
Config_Error_List errors;
String_Const_u8 file_name;
String_Const_u8 data;
};
#endif
function Variable_Handle
def_var_from_config(Application_Links *app, Variable_Handle parent, String_Const_u8 key, Config *config){
Variable_Handle result = vars_get_nil();
String_ID key_id = vars_save_string(key);
if (key_id != 0){
String_ID file_name_id = vars_save_string(config->file_name);
result = vars_new_variable(parent, key_id, file_name_id);
Variable_Handle var = result;
Scratch_Block scratch(app);
for (Config_Assignment *node = config->first;
node != 0;
node = node->next){
String_ID l_value = 0;
Config_LValue *l = node->l;
if (l != 0){
String_Const_u8 string = l->identifier;
if (string.size == 0){
string = push_stringf(scratch, "%d", l->index);
}
l_value = vars_save_string(string);
}
if (l_value != 0){
Config_RValue *r = node->r;
if (r != 0){
switch (r->type){
case ConfigRValueType_LValue:
{
// TODO(allen):
}break;
case ConfigRValueType_Boolean:
{
String_ID val = 0;
if (r->boolean){
val = vars_save_string(string_litinit("true"));
}
else{
val = vars_save_string(string_litinit("false"));
}
vars_new_variable(var, l_value, val);
}break;
case ConfigRValueType_Integer:
{
// TODO(allen): signed/unsigned problem
String_Const_u8 string = push_stringf(scratch, "%d", r->integer);
String_ID val = vars_save_string(string);
vars_new_variable(var, l_value, val);
}break;
case ConfigRValueType_String:
{
String_ID val = vars_save_string(r->string);
vars_new_variable(var, l_value, val);
}break;
case ConfigRValueType_Compound:
case ConfigRValueType_NoType:
{
}break;
}
}
}
}
}
return(result);
}
////////////////////////////////
// NOTE(allen): Nonsense from the old system
function Config_Assignment*
config_lookup_assignment(Config *config, String_Const_u8 var_name, i32 subscript){
@ -597,11 +710,6 @@ config_evaluate_rvalue(Config *config, Config_Assignment *assignment, Config_RVa
result.string = r->string;
}break;
case ConfigRValueType_Character:
{
result.character = r->character;
}break;
case ConfigRValueType_Compound:
{
result.compound = r->compound;
@ -784,21 +892,6 @@ config_placed_string_var(Config *config, char *var_name, i32 subscript, String_C
return(config_placed_string_var(config, SCu8(var_name), subscript, var_out, space, space_size));
}
function b32
config_char_var(Config *config, String_Const_u8 var_name, i32 subscript, char* var_out){
Config_Get_Result result = config_var(config, var_name, subscript);
b32 success = result.success && result.type == ConfigRValueType_Character;
if (success){
*var_out = result.character;
}
return(success);
}
function b32
config_char_var(Config *config, char *var_name, i32 subscript, char* var_out){
return(config_char_var(config, SCu8(var_name), subscript, var_out));
}
function b32
config_compound_var(Config *config, String_Const_u8 var_name, i32 subscript, Config_Compound** var_out){
Config_Get_Result result = config_var(config, var_name, subscript);
@ -916,23 +1009,6 @@ config_compound_placed_string_member(Config *config, Config_Compound *compound,
return(config_compound_placed_string_member(config, compound, SCu8(var_name), index, var_out, space, space_size));
}
function b32
config_compound_char_member(Config *config, Config_Compound *compound,
String_Const_u8 var_name, i32 index, char* var_out){
Config_Get_Result result = config_compound_member(config, compound, var_name, index);
b32 success = result.success && result.type == ConfigRValueType_Character;
if (success){
*var_out = result.character;
}
return(success);
}
function b32
config_compound_char_member(Config *config, Config_Compound *compound,
char *var_name, i32 index, char* var_out){
return(config_compound_char_member(config, compound, SCu8(var_name), index, var_out));
}
function b32
config_compound_compound_member(Config *config, Config_Compound *compound,
String_Const_u8 var_name, i32 index, Config_Compound** var_out){
@ -1009,16 +1085,6 @@ typed_placed_string_array_iteration_step(Config *config, Config_Compound *compou
return(result.step);
}
function Iteration_Step_Result
typed_char_array_iteration_step(Config *config, Config_Compound *compound, i32 index, char* var_out){
Config_Iteration_Step_Result result = typed_array_iteration_step(config, compound, ConfigRValueType_Character, index);
b32 success = (result.step == Iteration_Good);
if (success){
*var_out = result.get.character;
}
return(result.step);
}
function Iteration_Step_Result
typed_compound_array_iteration_step(Config *config, Config_Compound *compound, i32 index, Config_Compound** var_out){
Config_Iteration_Step_Result result = typed_array_iteration_step(config, compound, ConfigRValueType_Compound, index);
@ -1041,24 +1107,12 @@ typed_int_array_get_count(Config *config, Config_Compound *compound){
return(count);
}
function i32
typed_float_array_get_count(Config *config, Config_Compound *compound){
i32 count = typed_array_get_count(config, compound, ConfigRValueType_Float);
return(count);
}
function i32
typed_string_array_get_count(Config *config, Config_Compound *compound){
i32 count = typed_array_get_count(config, compound, ConfigRValueType_String);
return(count);
}
function i32
typed_character_array_get_count(Config *config, Config_Compound *compound){
i32 count = typed_array_get_count(config, compound, ConfigRValueType_Character);
return(count);
}
function i32
typed_compound_array_get_count(Config *config, Config_Compound *compound){
i32 count = typed_array_get_count(config, compound, ConfigRValueType_Compound);
@ -1083,24 +1137,12 @@ typed_int_array_reference_list(Arena *arena, Config *config, Config_Compound *co
return(list);
}
function Config_Get_Result_List
typed_float_array_reference_list(Arena *arena, Config *config, Config_Compound *compound){
Config_Get_Result_List list = typed_array_reference_list(arena, config, compound, ConfigRValueType_Float);
return(list);
}
function Config_Get_Result_List
typed_string_array_reference_list(Arena *arena, Config *config, Config_Compound *compound){
Config_Get_Result_List list = typed_array_reference_list(arena, config, compound, ConfigRValueType_String);
return(list);
}
function Config_Get_Result_List
typed_character_array_reference_list(Arena *arena, Config *config, Config_Compound *compound){
Config_Get_Result_List list = typed_array_reference_list(arena, config, compound, ConfigRValueType_Character);
return(list);
}
function Config_Get_Result_List
typed_compound_array_reference_list(Arena *arena, Config *config, Config_Compound *compound){
Config_Get_Result_List list = typed_array_reference_list(arena, config, compound, ConfigRValueType_Compound);

View File

@ -53,9 +53,7 @@ enum{
ConfigRValueType_LValue = 0,
ConfigRValueType_Boolean = 1,
ConfigRValueType_Integer = 2,
ConfigRValueType_Float = 3,
ConfigRValueType_String = 4,
ConfigRValueType_Character = 5,
ConfigRValueType_Compound = 6,
ConfigRValueType_NoType = 7,
};
@ -268,6 +266,8 @@ 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);
function void def_config_parser_recover(Config_Parser *ctx);
function Config* def_config_parser_config (Config_Parser *ctx);
function i32* def_config_parser_version (Config_Parser *ctx);
function Config_Assignment* def_config_parser_assignment(Config_Parser *ctx);
@ -279,9 +279,18 @@ function Config_Compound_Element* def_config_parser_element (Config_Parser *ct
function Config* def_config_parse(Application_Links *app, Arena *arena, String_Const_u8 file_name, String_Const_u8 data, Token_Array array);
function Config_Error* def_config_push_error(Arena *arena, Config_Error_List *list, String_Const_u8 file_name, u8 *pos, char *error_text);
function Config_Error* def_config_push_error(Arena *arena, Config *config, u8 *pos, char *error_text);
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);
function void def_config_parser_recover(Config_Parser *ctx);
////////////////////////////////
// NOTE(allen): Dump Config to Variables
function Variable_Handle def_var_from_config(Application_Links *app, Variable_Handle parent, String_Const_u8 key, Config *config);
#endif
// BOTTOM

View File

@ -29,7 +29,7 @@ dynamic_binding_load_from_file(Application_Links *app, Mapping *mapping, String_
Data data = dump_file_handle(scratch, file);
Config *parsed = config_from_text(app, scratch, filename, SCu8(data));
fclose(file);
if (parsed != 0){
result = true;
@ -38,7 +38,7 @@ dynamic_binding_load_from_file(Application_Links *app, Mapping *mapping, String_
mapping_init(tctx, mapping);
MappingScope();
SelectMapping(mapping);
for (Config_Assignment *assignment = parsed->first;
assignment != 0;
assignment = assignment->next){
@ -62,12 +62,12 @@ dynamic_binding_load_from_file(Application_Links *app, Mapping *mapping, String_
String_Const_u8 mod_string[9] = {0};
if (!config_compound_string_member(parsed, src, "cmd", 0, &cmd_string)){
config_add_error(scratch, parsed, node->result.pos, "Command string is required in binding");
def_config_push_error(scratch, parsed, node->result.pos, "Command string is required in binding");
goto finish_map;
}
if (!config_compound_string_member(parsed, src, "key", 1, &key_string)){
config_add_error(scratch, parsed, node->result.pos, "Key string is required in binding");
def_config_push_error(scratch, parsed, node->result.pos, "Key string is required in binding");
goto finish_map;
}
@ -101,10 +101,10 @@ dynamic_binding_load_from_file(Application_Links *app, Mapping *mapping, String_
map_set_binding(mapping, map, command->proc, InputEventKind_KeyStroke, keycode, &mods_set);
}
else{
config_add_error(scratch, parsed, node->result.pos,
(keycode != 0) ? (char*)"Invalid command" :
(command != 0) ? (char*)"Invalid key":
(char*)"Invalid command and key");
def_config_push_error(scratch, parsed, node->result.pos,
(keycode != 0) ? (char*)"Invalid command" :
(command != 0) ? (char*)"Invalid key":
(char*)"Invalid command and key");
}
}

View File

@ -328,7 +328,7 @@ parse_project__config_data__version_1(Application_Links *app, Arena *arena, Stri
if (!config_compound_string_member(parsed, src, "name", 0, &name)){
can_emit_command = false;
config_add_error(arena, parsed, pos, "a command must have a string type name member");
def_config_push_error(arena, parsed, pos, "a command must have a string type name member");
goto finish_command;
}
@ -339,7 +339,7 @@ parse_project__config_data__version_1(Application_Links *app, Arena *arena, Stri
}
else{
can_emit_command = false;
config_add_error(arena, parsed, pos, "a command must have an array type cmd member");
def_config_push_error(arena, parsed, pos, "a command must have an array type cmd member");
goto finish_command;
}
@ -375,7 +375,7 @@ parse_project__config_data__version_1(Application_Links *app, Arena *arena, Stri
}
if (!can_emit_command){
config_add_error(arena, parsed, cmd_pos, "no usable command strings found in cmd");
def_config_push_error(arena, parsed, cmd_pos, "no usable command strings found in cmd");
goto finish_command;
}

View File

@ -372,7 +372,7 @@ static Command_Metadata fcoder_metacmd_table[250] = {
{ PROC_LINKS(list_all_substring_locations, 0), false, "list_all_substring_locations", 28, "Queries the user for a string and lists all case-sensitive substring matches found in all open buffers.", 103, "W:\\4ed\\code\\custom\\4coder_search.cpp", 36, 174 },
{ PROC_LINKS(list_all_substring_locations_case_insensitive, 0), false, "list_all_substring_locations_case_insensitive", 45, "Queries the user for a string and lists all case-insensitive substring matches found in all open buffers.", 105, "W:\\4ed\\code\\custom\\4coder_search.cpp", 36, 186 },
{ PROC_LINKS(load_project, 0), false, "load_project", 12, "Looks for a project.4coder file in the current directory and tries to load it. Looks in parent directories until a project file is found or there are no more parents.", 167, "W:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 867 },
{ PROC_LINKS(load_theme_current_buffer, 0), false, "load_theme_current_buffer", 25, "Parse the current buffer as a theme file and add the theme to the theme list. If the buffer has a .4coder postfix in it's name, it is removed when the name is saved.", 165, "W:\\4ed\\code\\custom\\4coder_config.cpp", 36, 1660 },
{ PROC_LINKS(load_theme_current_buffer, 0), false, "load_theme_current_buffer", 25, "Parse the current buffer as a theme file and add the theme to the theme list. If the buffer has a .4coder postfix in it's name, it is removed when the name is saved.", 165, "W:\\4ed\\code\\custom\\4coder_config.cpp", 36, 1702 },
{ PROC_LINKS(load_themes_default_folder, 0), false, "load_themes_default_folder", 26, "Loads all the theme files in the default theme folder.", 54, "W:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 533 },
{ PROC_LINKS(load_themes_hot_directory, 0), false, "load_themes_hot_directory", 25, "Loads all the theme files in the current hot directory.", 55, "W:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 545 },
{ PROC_LINKS(make_directory_query, 0), false, "make_directory_query", 20, "Queries the user for a name and creates a new directory with the given name.", 76, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1493 },