Fixed auto-indent crash bug; also progress on whatever

master
Allen Webster 2019-10-03 16:06:42 -07:00
parent 7a507ee6e4
commit 7af92c4b56
5 changed files with 46 additions and 49 deletions

View File

@ -73,11 +73,11 @@ api_get_api(Arena *arena, API_Definition_List *list, String_Const_u8 name){
function void
generate_api_master_list(Arena *scratch, API_Definition *api, FILE *out){
fprintf(out, "// %.*s\n", string_expand(api->name));
for (API_Call *call = api->first;
call != 0;
call = call->next){
fprintf(out, "%.*s %.*s(",
fprintf(out, "api(%.*s) function %.*s %.*s(",
string_expand(api->name),
string_expand(call->return_type),
string_expand(call->name));
if (call->params.count == 0){

View File

@ -212,13 +212,6 @@ int
main(int argc, char **argv){
Arena arena = make_arena_malloc();
char *hack[] = {
"nothing",
"../code/4ed_api_implementation.cpp"
};
argv = hack;
argc = 2;
if (argc < 2){
printf("usage: <script> <source> {<source>}\n"
" source : file to load and parse into the output list\n");

View File

@ -63,42 +63,46 @@ set_line_indents(Application_Links *app, Arena *arena, Buffer_ID buffer, Range_i
internal Token*
find_anchor_token(Application_Links *app, Buffer_ID buffer, Token_Array *tokens, i64 invalid_line){
Token *result = tokens->tokens;
i64 invalid_pos = get_line_start_pos(app, buffer, invalid_line);
Token *result = 0;
i32 scope_counter = 0;
i32 paren_counter = 0;
Token *token = tokens->tokens;
for (;;token += 1){
if (token->pos + token->size > invalid_pos){
break;
}
if (!HasFlag(token->flags, TokenBaseFlag_PreprocessorBody)){
if (scope_counter == 0 && paren_counter == 0){
result = token;
if (tokens != 0 && tokens->tokens != 0){
result = tokens->tokens;
i64 invalid_pos = get_line_start_pos(app, buffer, invalid_line);
i32 scope_counter = 0;
i32 paren_counter = 0;
Token *token = tokens->tokens;
for (;;token += 1){
if (token->pos + token->size > invalid_pos){
break;
}
switch (token->kind){
case TokenBaseKind_ScopeOpen:
{
scope_counter += 1;
}break;
case TokenBaseKind_ScopeClose:
{
paren_counter = 0;
if (scope_counter > 0){
scope_counter -= 1;
}
}break;
case TokenBaseKind_ParentheticalOpen:
{
paren_counter += 1;
}break;
case TokenBaseKind_ParentheticalClose:
{
if (paren_counter > 0){
paren_counter -= 1;
}
}break;
if (!HasFlag(token->flags, TokenBaseFlag_PreprocessorBody)){
if (scope_counter == 0 && paren_counter == 0){
result = token;
}
switch (token->kind){
case TokenBaseKind_ScopeOpen:
{
scope_counter += 1;
}break;
case TokenBaseKind_ScopeClose:
{
paren_counter = 0;
if (scope_counter > 0){
scope_counter -= 1;
}
}break;
case TokenBaseKind_ParentheticalOpen:
{
paren_counter += 1;
}break;
case TokenBaseKind_ParentheticalClose:
{
if (paren_counter > 0){
paren_counter -= 1;
}
}break;
}
}
}
}
@ -257,7 +261,7 @@ auto_indent_buffer(Application_Links *app, Buffer_ID buffer, Range_i64 pos, Inde
Token_Array *tokens = scope_attachment(app, scope, attachment_tokens, Token_Array);
b32 result = false;
if (tokens != 0){
if (tokens != 0 && tokens->tokens != 0){
result = true;
Scratch_Block scratch(app);

View File

@ -387,10 +387,10 @@ static Command_Metadata fcoder_metacmd_table[226] = {
{ PROC_LINKS(interactive_new, 0), "interactive_new", 15, "Interactively creates a new file.", 33, "w:\\4ed\\code\\custom\\4coder_lists.cpp", 35, 847 },
{ PROC_LINKS(interactive_open, 0), "interactive_open", 16, "Interactively opens a file.", 27, "w:\\4ed\\code\\custom\\4coder_lists.cpp", 35, 880 },
{ PROC_LINKS(command_lister, 0), "command_lister", 14, "Opens an interactive list of all registered commands.", 53, "w:\\4ed\\code\\custom\\4coder_lists.cpp", 35, 960 },
{ PROC_LINKS(auto_tab_whole_file, 0), "auto_tab_whole_file", 19, "Audo-indents the entire current buffer.", 39, "w:\\4ed\\code\\custom\\4coder_auto_indent.cpp", 41, 309 },
{ PROC_LINKS(auto_tab_line_at_cursor, 0), "auto_tab_line_at_cursor", 23, "Auto-indents the line on which the cursor sits.", 47, "w:\\4ed\\code\\custom\\4coder_auto_indent.cpp", 41, 318 },
{ PROC_LINKS(auto_tab_range, 0), "auto_tab_range", 14, "Auto-indents the range between the cursor and the mark.", 55, "w:\\4ed\\code\\custom\\4coder_auto_indent.cpp", 41, 328 },
{ PROC_LINKS(write_and_auto_tab, 0), "write_and_auto_tab", 18, "Inserts a character and auto-indents the line on which the cursor sits.", 71, "w:\\4ed\\code\\custom\\4coder_auto_indent.cpp", 41, 338 },
{ PROC_LINKS(auto_tab_whole_file, 0), "auto_tab_whole_file", 19, "Audo-indents the entire current buffer.", 39, "w:\\4ed\\code\\custom\\4coder_auto_indent.cpp", 41, 313 },
{ PROC_LINKS(auto_tab_line_at_cursor, 0), "auto_tab_line_at_cursor", 23, "Auto-indents the line on which the cursor sits.", 47, "w:\\4ed\\code\\custom\\4coder_auto_indent.cpp", 41, 322 },
{ PROC_LINKS(auto_tab_range, 0), "auto_tab_range", 14, "Auto-indents the range between the cursor and the mark.", 55, "w:\\4ed\\code\\custom\\4coder_auto_indent.cpp", 41, 332 },
{ PROC_LINKS(write_and_auto_tab, 0), "write_and_auto_tab", 18, "Inserts a character and auto-indents the line on which the cursor sits.", 71, "w:\\4ed\\code\\custom\\4coder_auto_indent.cpp", 41, 342 },
{ PROC_LINKS(list_all_locations, 0), "list_all_locations", 18, "Queries the user for a string and lists all exact case-sensitive matches found in all open buffers.", 99, "w:\\4ed\\code\\custom\\4coder_search.cpp", 36, 166 },
{ PROC_LINKS(list_all_substring_locations, 0), "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, 172 },
{ PROC_LINKS(list_all_locations_case_insensitive, 0), "list_all_locations_case_insensitive", 35, "Queries the user for a string and lists all exact case-insensitive matches found in all open buffers.", 101, "w:\\4ed\\code\\custom\\4coder_search.cpp", 36, 178 },

View File

@ -59,7 +59,7 @@ command_list = {
{ .name = "build api parser",
.out = "*compilation*", .footer_panel = true, .save_dirty_files = true,
.cmd = { { "custom\\bin\\build_one_time 4ed_api_parser.cpp ..\\build", .os = "win" }, }, },
.cmd = { { "custom\\bin\\build_one_time 4ed_api_parser.cpp ..\\build & copy /B one_time.exe api_parser.exe", .os = "win" }, }, },
};
fkey_command[1] = "build x64";