From d117c7fcf5e000dc85436f1c8b5102400cbc9ae3 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Mon, 17 Jul 2017 16:43:01 -0400 Subject: [PATCH] finished site update, switching over to API cleanup --- 4coder_API/app_functions.h | 28 +- 4coder_helper/4coder_helper.h | 2 + 4ed_api_implementation.cpp | 74 +-- site/4ed_abstract_document.cpp | 819 +++++++++++--------------- site/4ed_sitegen.cpp | 18 +- site/source_material/binding_list.txt | 297 +++++----- site/source_material/docs.txt | 44 +- site/source_material/feature_list.txt | 100 ++-- site/source_material/home.txt | 18 +- site/source_material/introduction.txt | 2 +- site/source_material/roadmap.txt | 56 +- site/source_material/site_header.txt | 12 + site/source_material/tutorials.txt | 4 +- 13 files changed, 641 insertions(+), 833 deletions(-) create mode 100644 site/source_material/site_header.txt diff --git a/4coder_API/app_functions.h b/4coder_API/app_functions.h index 7ab8f1c2..89b2f12a 100644 --- a/4coder_API/app_functions.h +++ b/4coder_API/app_functions.h @@ -27,9 +27,7 @@ struct Application_Links; #define BUFFER_READ_TOKENS_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, int32_t start_token, int32_t end_token, Cpp_Token *tokens_out) #define BUFFER_GET_TOKEN_INDEX_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, int32_t pos, Cpp_Get_Token_Result *get_result) #define BUFFER_SEND_END_SIGNAL_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer) -#define BEGIN_BUFFER_CREATION_SIG(n) bool32 n(Application_Links *app, Buffer_Creation_Data *data, Buffer_Create_Flag flags) -#define BUFFER_CREATION_NAME_SIG(n) bool32 n(Application_Links *app, Buffer_Creation_Data *data, char *filename, int32_t filename_len, uint32_t flags) -#define END_BUFFER_CREATION_SIG(n) Buffer_Summary n(Application_Links *app, Buffer_Creation_Data *data) +#define CREATE_BUFFER_SIG(n) Buffer_Summary n(Application_Links *app, char *filename, int32_t filename_len, Buffer_Create_Flag flags) #define SAVE_BUFFER_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, char *filename, int32_t filename_len, uint32_t flags) #define KILL_BUFFER_SIG(n) bool32 n(Application_Links *app, Buffer_Identifier buffer, View_ID view_id, Buffer_Kill_Flag flags) #define GET_VIEW_FIRST_SIG(n) View_Summary n(Application_Links *app, Access_Flag access) @@ -105,9 +103,7 @@ typedef BUFFER_TOKEN_COUNT_SIG(Buffer_Token_Count_Function); typedef BUFFER_READ_TOKENS_SIG(Buffer_Read_Tokens_Function); typedef BUFFER_GET_TOKEN_INDEX_SIG(Buffer_Get_Token_Index_Function); typedef BUFFER_SEND_END_SIGNAL_SIG(Buffer_Send_End_Signal_Function); -typedef BEGIN_BUFFER_CREATION_SIG(Begin_Buffer_Creation_Function); -typedef BUFFER_CREATION_NAME_SIG(Buffer_Creation_Name_Function); -typedef END_BUFFER_CREATION_SIG(End_Buffer_Creation_Function); +typedef CREATE_BUFFER_SIG(Create_Buffer_Function); typedef SAVE_BUFFER_SIG(Save_Buffer_Function); typedef KILL_BUFFER_SIG(Kill_Buffer_Function); typedef GET_VIEW_FIRST_SIG(Get_View_First_Function); @@ -185,9 +181,7 @@ Buffer_Token_Count_Function *buffer_token_count; Buffer_Read_Tokens_Function *buffer_read_tokens; Buffer_Get_Token_Index_Function *buffer_get_token_index; Buffer_Send_End_Signal_Function *buffer_send_end_signal; -Begin_Buffer_Creation_Function *begin_buffer_creation; -Buffer_Creation_Name_Function *buffer_creation_name; -End_Buffer_Creation_Function *end_buffer_creation; +Create_Buffer_Function *create_buffer; Save_Buffer_Function *save_buffer; Kill_Buffer_Function *kill_buffer; Get_View_First_Function *get_view_first; @@ -264,9 +258,7 @@ Buffer_Token_Count_Function *buffer_token_count_; Buffer_Read_Tokens_Function *buffer_read_tokens_; Buffer_Get_Token_Index_Function *buffer_get_token_index_; Buffer_Send_End_Signal_Function *buffer_send_end_signal_; -Begin_Buffer_Creation_Function *begin_buffer_creation_; -Buffer_Creation_Name_Function *buffer_creation_name_; -End_Buffer_Creation_Function *end_buffer_creation_; +Create_Buffer_Function *create_buffer_; Save_Buffer_Function *save_buffer_; Kill_Buffer_Function *kill_buffer_; Get_View_First_Function *get_view_first_; @@ -351,9 +343,7 @@ app_links->buffer_token_count_ = Buffer_Token_Count;\ app_links->buffer_read_tokens_ = Buffer_Read_Tokens;\ app_links->buffer_get_token_index_ = Buffer_Get_Token_Index;\ app_links->buffer_send_end_signal_ = Buffer_Send_End_Signal;\ -app_links->begin_buffer_creation_ = Begin_Buffer_Creation;\ -app_links->buffer_creation_name_ = Buffer_Creation_Name;\ -app_links->end_buffer_creation_ = End_Buffer_Creation;\ +app_links->create_buffer_ = Create_Buffer;\ app_links->save_buffer_ = Save_Buffer;\ app_links->kill_buffer_ = Kill_Buffer;\ app_links->get_view_first_ = Get_View_First;\ @@ -430,9 +420,7 @@ static inline int32_t buffer_token_count(Application_Links *app, Buffer_Summary static inline bool32 buffer_read_tokens(Application_Links *app, Buffer_Summary *buffer, int32_t start_token, int32_t end_token, Cpp_Token *tokens_out){return(app->buffer_read_tokens(app, buffer, start_token, end_token, tokens_out));} static inline bool32 buffer_get_token_index(Application_Links *app, Buffer_Summary *buffer, int32_t pos, Cpp_Get_Token_Result *get_result){return(app->buffer_get_token_index(app, buffer, pos, get_result));} static inline bool32 buffer_send_end_signal(Application_Links *app, Buffer_Summary *buffer){return(app->buffer_send_end_signal(app, buffer));} -static inline bool32 begin_buffer_creation(Application_Links *app, Buffer_Creation_Data *data, Buffer_Create_Flag flags){return(app->begin_buffer_creation(app, data, flags));} -static inline bool32 buffer_creation_name(Application_Links *app, Buffer_Creation_Data *data, char *filename, int32_t filename_len, uint32_t flags){return(app->buffer_creation_name(app, data, filename, filename_len, flags));} -static inline Buffer_Summary end_buffer_creation(Application_Links *app, Buffer_Creation_Data *data){return(app->end_buffer_creation(app, data));} +static inline Buffer_Summary create_buffer(Application_Links *app, char *filename, int32_t filename_len, Buffer_Create_Flag flags){return(app->create_buffer(app, filename, filename_len, flags));} static inline bool32 save_buffer(Application_Links *app, Buffer_Summary *buffer, char *filename, int32_t filename_len, uint32_t flags){return(app->save_buffer(app, buffer, filename, filename_len, flags));} static inline bool32 kill_buffer(Application_Links *app, Buffer_Identifier buffer, View_ID view_id, Buffer_Kill_Flag flags){return(app->kill_buffer(app, buffer, view_id, flags));} static inline View_Summary get_view_first(Application_Links *app, Access_Flag access){return(app->get_view_first(app, access));} @@ -509,9 +497,7 @@ static inline int32_t buffer_token_count(Application_Links *app, Buffer_Summary static inline bool32 buffer_read_tokens(Application_Links *app, Buffer_Summary *buffer, int32_t start_token, int32_t end_token, Cpp_Token *tokens_out){return(app->buffer_read_tokens_(app, buffer, start_token, end_token, tokens_out));} static inline bool32 buffer_get_token_index(Application_Links *app, Buffer_Summary *buffer, int32_t pos, Cpp_Get_Token_Result *get_result){return(app->buffer_get_token_index_(app, buffer, pos, get_result));} static inline bool32 buffer_send_end_signal(Application_Links *app, Buffer_Summary *buffer){return(app->buffer_send_end_signal_(app, buffer));} -static inline bool32 begin_buffer_creation(Application_Links *app, Buffer_Creation_Data *data, Buffer_Create_Flag flags){return(app->begin_buffer_creation_(app, data, flags));} -static inline bool32 buffer_creation_name(Application_Links *app, Buffer_Creation_Data *data, char *filename, int32_t filename_len, uint32_t flags){return(app->buffer_creation_name_(app, data, filename, filename_len, flags));} -static inline Buffer_Summary end_buffer_creation(Application_Links *app, Buffer_Creation_Data *data){return(app->end_buffer_creation_(app, data));} +static inline Buffer_Summary create_buffer(Application_Links *app, char *filename, int32_t filename_len, Buffer_Create_Flag flags){return(app->create_buffer_(app, filename, filename_len, flags));} static inline bool32 save_buffer(Application_Links *app, Buffer_Summary *buffer, char *filename, int32_t filename_len, uint32_t flags){return(app->save_buffer_(app, buffer, filename, filename_len, flags));} static inline bool32 kill_buffer(Application_Links *app, Buffer_Identifier buffer, View_ID view_id, Buffer_Kill_Flag flags){return(app->kill_buffer_(app, buffer, view_id, flags));} static inline View_Summary get_view_first(Application_Links *app, Access_Flag access){return(app->get_view_first_(app, access));} diff --git a/4coder_helper/4coder_helper.h b/4coder_helper/4coder_helper.h index 9f8cf812..0f492a94 100644 --- a/4coder_helper/4coder_helper.h +++ b/4coder_helper/4coder_helper.h @@ -178,6 +178,7 @@ buffer_identifier(Buffer_ID id){ return(identifier); } +#if 0 static Buffer_Summary create_buffer(Application_Links *app, char *filename, int32_t filename_len, Buffer_Create_Flag flags){ Buffer_Summary buffer = {0}; @@ -189,6 +190,7 @@ create_buffer(Application_Links *app, char *filename, int32_t filename_len, Buff return(buffer); } +#endif static Range make_range(int32_t p1, int32_t p2){ diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index cca22b59..d20aaaf7 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -754,7 +754,7 @@ DOC_PARAM(edits, This parameter provides about the source string and destination DOC_PARAM(edit_count, This parameter specifies the number of Buffer_Edit structs in edits.) DOC_PARAM(type, This prameter specifies what type of batch edit to execute.) DOC_RETURN(This call returns non-zero if the batch edit succeeds. This call can fail if the provided buffer summary does not refer to an actual buffer in 4coder.) -DOC(TODO) +DOC(Apply an array of edits all at once. This combines all the edits into one undo operation.) DOC_SEE(Buffer_Edit) DOC_SEE(Buffer_Batch_Edit_Type) */{ @@ -1225,61 +1225,8 @@ DOC(Whenever a buffer is killed an end signal is sent which triggers the end fil return(result); } -// TODO(allen): Buffer_Creation_Flag -API_EXPORT bool32 -Begin_Buffer_Creation(Application_Links *app, Buffer_Creation_Data *data, Buffer_Create_Flag flags) -/* -DOC_PARAM(data, a local user handle for the buffer creation process) -DOC_PARAM(flags, flags defining the buffer creation behavior) - -DOC(Begins a buffer creation by initializing a Buffer_Creation_Data struct. The buffer is not actually created until end_buffer_creation is called.) - -DOC_SEE(buffer_creation_name) -DOC_SEE(end_buffer_creation) - -DOC_SEE(Buffer_Creation_Data) -DOC_SEE(Buffer_Create_Flag) -*/{ - bool32 result = 0; - if (data){ - data->flags = flags; - result = 1; - } - return(result); -} - -API_EXPORT bool32 -Buffer_Creation_Name(Application_Links *app, Buffer_Creation_Data *data, char *filename, int32_t filename_len, uint32_t flags) -/* -DOC_PARAM(data, a local user handle for buffer creation that has already been initialized by begin_buffer_creation) -DOC_PARAM(filename, the name to associate to the buffer; This string need not be null terminated.) -DOC_PARAM(filename_len, the length of the filename string) -DOC_PARAM(flags, not currently used this should be 0) - -DOC(This call sets the name associated to the buffer. If the name is a filename, that filename will be used for loading and saving with the disk, and the buffer name will be extracted from the filename. If the name is not a filename it will be an unassociated buffer and the buffer name will be exactly set to filename.) - -DOC_SEE(begin_buffer_creation) -DOC_SEE(end_buffer_creation) -*/{ - bool32 result = 0; - if (data){ - String fname = make_fixed_width_string(data->fname_space); - copy_ss(&fname, make_string(filename, filename_len)); - data->fname_len = filename_len; - result = 1; - } - return(result); -} - API_EXPORT Buffer_Summary -End_Buffer_Creation(Application_Links *app, Buffer_Creation_Data *data) -/* -DOC_PARAM(data, a local user handle for buffer creation that has already been initialized by begin_buffer_creation and used in subsequent buffer creation flags) - -DOC_RETURN(Returns a summary of the newly created buffer or of the existing buffer that already has the specified name. If there is not enough creation data to make the buffer the returned summary will be null.) - -DOC_SEE(begin_buffer_creation) -*/{ +Create_Buffer(Application_Links *app, char *filename, int32_t filename_len, Buffer_Create_Flag flags){ PRFL_FUNC_GROUP(); Command_Data *cmd = (Command_Data*)app->cmd_context; @@ -1291,8 +1238,8 @@ DOC_SEE(begin_buffer_creation) Buffer_Summary result = {0}; - if (data != 0 && data->fname_len > 0){ - String fname = make_string(data->fname_space, data->fname_len); + if (filename_len > 0){ + String fname = make_string(filename, filename_len); Editing_File *file = 0; b32 do_new_file = false; @@ -1312,8 +1259,6 @@ DOC_SEE(begin_buffer_creation) file = working_set_name_contains(working_set, fname); } - u32 flags = data->flags; - if (file == 0){ if (!do_new_file){ if (flags & BufferCreate_AlwaysNew){ @@ -1914,12 +1859,7 @@ DOC_PARAM(view, The view parameter specifies the view in which to set the cursor DOC_PARAM(seek, The seek parameter specifies the target position for the seek.) DOC_PARAM(set_preferred_x, If this parameter is true the preferred x is updated to match the new cursor x.) DOC_RETURN(This call returns non-zero on success.) -DOC -( -This call sets the the view's cursor position. set_preferred_x should usually be true -unless the change in cursor position is is a vertical motion that tries to keep the -cursor in the same column or x position. -) +DOC(This call sets the the view's cursor position. set_preferred_x should usually be true unless the change in cursor position is is a vertical motion that tries to keep the cursor in the same column or x position.) DOC_SEE(Buffer_Seek) */{ Command_Data *cmd = (Command_Data*)app->cmd_context; @@ -1945,7 +1885,9 @@ DOC_SEE(Buffer_Seek) API_EXPORT bool32 View_Set_Scroll(Application_Links *app, View_Summary *view, GUI_Scroll_Vars scroll) /* -DOC(TODO) +DOC_PARAM(view, The view on which to change the scroll state.) +DOC_PARAM(scroll, The new scroll position for the view.) +DOC(Set the scrolling state of the view.) DOC_SEE(GUI_Scroll_Vars) */{ Command_Data *cmd = (Command_Data*)app->cmd_context; diff --git a/site/4ed_abstract_document.cpp b/site/4ed_abstract_document.cpp index a701836d..8f2401d5 100644 --- a/site/4ed_abstract_document.cpp +++ b/site/4ed_abstract_document.cpp @@ -9,6 +9,25 @@ // TOP +internal char* +get_null_terminated_version(String str){ + char *ptr = 0; + if (str.size > 0){ + if (terminate_with_null(&str)){ + ptr = str.str; + } + else{ + String b = str_alloc(str.size + 1); + copy(&b, str); + terminate_with_null(&b); + ptr = b.str; + } + } + return(ptr); +} + +//////////////////////////////// + struct Enriched_Text{ String fname; String source; @@ -92,19 +111,15 @@ enum{ Doc_TableOfContents, Doc_PlainOldText, Doc_Version, - Doc_BeginStyle, - Doc_EndStyle, + Doc_Style, Doc_DocumentLink, - Doc_BeginLink, - Doc_EndLink, + Doc_Link, Doc_Image, Doc_Video, Doc_BeginParagraph, Doc_EndParagraph, - Doc_BeginList, - Doc_EndList, - Doc_BeginItem, - Doc_EndItem, + Doc_List, + Doc_Item, // Doc_COUNT, }; @@ -113,18 +128,18 @@ struct Document_Item{ Document_Item *next; Document_Item *parent; i32 type; + + struct{ + Document_Item *first_child; + Document_Item *last_child; + String name; + String id; + b32 show_title; + } section; + union{ struct{ - Document_Item *first_child; - Document_Item *last_child; - String name; - String id; - b32 show_title; - } section; - - struct{ - Meta_Unit *unit; - //Alternate_Names_Array *alt_names; + String unit; u32 mangle_rule; } unit_elements; @@ -137,16 +152,22 @@ struct Document_Item{ String name; struct Abstract_Item *document; } include; - - struct{ - Enriched_Text *text; - } enriched_text; }; }; global Document_Item null_document_item = {0}; //////////////////////////////// +internal void +set_item_string(String *out, String text){ + *out = str_alloc(text.size + 1); + fm_align(); + copy(out, text); + terminate_with_null(out); +} + +//////////////////////////////// + struct Basic_Node{ Basic_Node *next; }; @@ -216,6 +237,33 @@ struct Abstract_Item{ }; global Abstract_Item null_abstract_item = {0}; +internal Abstract_Item* +get_item_by_name(Basic_List list, String name){ + Abstract_Item *result = 0; + + for (Basic_Node *node = list.head; + node != 0; + node = node->next){ + Abstract_Item *item = NodeGetData(node, Abstract_Item); + if (match(item->name, name)){ + result = item; + break; + } + } + + return(result); +} + +internal Abstract_Item* +create_abstract_item(Basic_List *list, char *name){ + Abstract_Item *result = 0; + Abstract_Item *lookup = get_item_by_name(*list, make_string_slowly(name)); + if (lookup == 0){ + result = (Abstract_Item*)push_item_on_list(list, sizeof(*result)); + } + return(result); +} + struct Abstract_Item_Array{ Abstract_Item **items; u32 count; @@ -238,16 +286,7 @@ get_abstract_item_array(Basic_List *list){ return(result); } -struct Document_Builder{ - Abstract_Item *doc; - - Document_Item *section_stack[16]; - i32 section_top; -}; - -struct Image_Instantiation{ - i32 w, h; -}; +//////////////////////////////// struct Document_System{ char *code_dir; @@ -277,80 +316,23 @@ create_unresolved_include(Document_System *doc_system, Document_Item *include_it *new_item = include_item; } -internal Abstract_Item* -get_item_by_name(Basic_List list, String name){ - Abstract_Item *result = 0; - - for (Basic_Node *node = list.head; - node != 0; - node = node->next){ - Abstract_Item *item = NodeGetData(node, Abstract_Item); - if (match(item->name, name)){ - result = item; - break; - } - } - - return(result); -} +//////////////////////////////// -internal Image_Instantiation* -get_image_instantiation(Basic_List list, i32 w, i32 h){ - Image_Instantiation *result = 0; - - for (Basic_Node *node = list.head; - node != 0; - node = node->next){ - Image_Instantiation *instantiation = NodeGetData(node, Image_Instantiation); - if (instantiation->w == w && instantiation->h == h){ - result = instantiation; - break; - } - } - - return(result); -} +enum{ + MetaResult_DidParse, + MetaResult_AlreadyExists, + MetaResult_FailedToParse, +}; -internal void -add_image_instantiation(Basic_List *list, i32 w, i32 h){ - Image_Instantiation *instantiation = (Image_Instantiation*)push_item_on_list(list, sizeof(*instantiation)); - instantiation->w = w; - instantiation->h = h; -} - -internal Abstract_Item* -create_abstract_item(Basic_List *list, char *name){ - Abstract_Item *result = 0; - Abstract_Item *lookup = get_item_by_name(*list, make_string_slowly(name)); - if (lookup == 0){ - result = (Abstract_Item*)push_item_on_list(list, sizeof(*result)); - } - return(result); -} - -internal char* -get_null_terminated_version(String str){ - char *ptr = 0; - if (terminate_with_null(&str)){ - ptr = str.str; - } - else{ - String b = str_alloc(str.size + 1); - copy(&b, str); - terminate_with_null(&b); - ptr = b.str; - } - return(ptr); -} - -internal b32 +internal u32 create_meta_unit(Document_System *doc_system, String name_str, String file_str){ + u32 result = MetaResult_DidParse; + char *name = get_null_terminated_version(name_str); char *file = get_null_terminated_version(file_str); Abstract_Item *item = create_abstract_item(&doc_system->meta_list, name); - b32 result = false; if (item != 0){ Meta_Unit *unit = fm_push_array(Meta_Unit, 1); *unit = compile_meta_unit(doc_system->code_dir, file, ExpandArray(meta_keywords)); @@ -361,6 +343,12 @@ create_meta_unit(Document_System *doc_system, String name_str, String file_str){ item->name = name; item->unit = unit; } + else{ + result = MetaResult_FailedToParse; + } + } + else{ + result = MetaResult_AlreadyExists; } return(result); @@ -406,24 +394,43 @@ add_image_description(Document_System *system, char *source_file, char *extensio return(item); } -internal void -set_item_string(String *out, String text){ - *out = str_alloc(text.size + 1); - fm_align(); - copy(out, text); - terminate_with_null(out); +//////////////////////////////// + +struct Image_Instantiation{ + i32 w, h; +}; + +internal Image_Instantiation* +get_image_instantiation(Basic_List list, i32 w, i32 h){ + Image_Instantiation *result = 0; + + for (Basic_Node *node = list.head; + node != 0; + node = node->next){ + Image_Instantiation *instantiation = NodeGetData(node, Image_Instantiation); + if (instantiation->w == w && instantiation->h == h){ + result = instantiation; + break; + } + } + + return(result); } internal void -set_section_name(Document_Item *item, char *name, b32 show_title){ - set_item_string(&item->section.name, make_string_slowly(name)); - item->section.show_title = show_title; +add_image_instantiation(Basic_List *list, i32 w, i32 h){ + Image_Instantiation *instantiation = (Image_Instantiation*)push_item_on_list(list, sizeof(*instantiation)); + instantiation->w = w; + instantiation->h = h; } -internal void -set_section_id(Document_Item *item, char *id){ - set_item_string(&item->section.id, make_lit_string(id)); -} +//////////////////////////////// + +struct Document_Builder{ + Abstract_Item *doc; + Document_Item *item_stack[512]; + i32 item_top; +}; internal Document_Builder begin_document_description(Document_System *system, char *title, char *name, b32 show_title){ @@ -435,25 +442,22 @@ begin_document_description(Document_System *system, char *title, char *name, b32 *doc = null_abstract_item; doc->item_type = ItemType_Document; + doc->name = name; doc->root_item = fm_push_array(Document_Item, 1); *doc->root_item = null_document_item; - set_section_name(doc->root_item, title, show_title); - doc->name = name; - doc->root_item->type = Doc_Root; - builder.section_stack[builder.section_top] = doc->root_item; + Document_Item *item = doc->root_item; + set_item_string(&item->section.name, make_string_slowly(name)); + item->section.show_title = show_title; + item->type = Doc_Root; + + builder.item_stack[builder.item_top] = doc->root_item; } return(builder); } -internal void -end_document_description(Document_Builder *builder){ - Assert(builder->section_top == 0); -} - internal void append_child(Document_Item *parent, Document_Item *item){ - Assert(parent->type == Doc_Root || parent->type == Doc_Section); if (parent->section.last_child == 0){ parent->section.first_child = item; } @@ -464,19 +468,36 @@ append_child(Document_Item *parent, Document_Item *item){ item->parent = parent; } +#define PUSH true + +internal void +doc_push(Document_Builder *builder, Document_Item *item){ + Assert(builder->item_top + 1 < ArrayCount(builder->item_stack)); + builder->item_stack[++builder->item_top] = item; +} + internal Document_Item* -doc_new_item(Document_Builder *builder, u32 type){ - Assert(builder->section_top + 1 < ArrayCount(builder->section_stack)); - Document_Item *parent = builder->section_stack[builder->section_top]; +doc_get_item_top(Document_Builder *builder){ + Assert(builder->item_top < ArrayCount(builder->item_stack)); + Document_Item *parent = builder->item_stack[builder->item_top]; + return(parent); +} + +internal Document_Item* +doc_new_item(Document_Builder *builder, u32 type, b32 push = false){ + Document_Item *parent = doc_get_item_top(builder); Document_Item *item = fm_push_array(Document_Item, 1); *item = null_document_item; item->type = type; append_child(parent, item); + if (push){ + doc_push(builder, item); + } return(item); } internal Document_Item* -doc_new_item_strings(Document_Builder *builder, u32 type, String s1, String s2){ +doc_new_item_strings(Document_Builder *builder, u32 type, String s1, String s2, b32 push = false){ Document_Item *item = doc_new_item(builder, type); if (s1.size > 0){ set_item_string(&item->string.string, s1); @@ -484,29 +505,83 @@ doc_new_item_strings(Document_Builder *builder, u32 type, String s1, String s2){ if (s2.size > 0){ set_item_string(&item->string.string2, s2); } + if (push){ + doc_push(builder, item); + } + return(item); +} + +internal Document_Item* +doc_new_item_documentation(Document_Builder *builder, u32 type, String unit, Mangle_Rule mangle_rule, b32 push = false){ + Document_Item *item = doc_new_item(builder, type); + set_item_string(&item->unit_elements.unit, unit); + item->unit_elements.mangle_rule = mangle_rule; + if (push){ + doc_push(builder, item); + } return(item); } internal void begin_section(Document_Builder *builder, char *title, char *id){ - Document_Item *section = doc_new_item(builder, Doc_Section); - builder->section_stack[++builder->section_top] = section; - set_section_name(section, title, true); + Document_Item *item = doc_new_item(builder, Doc_Section, PUSH); + set_item_string(&item->section.name, make_string_slowly(title)); + item->section.show_title = true; if (id != 0){ - set_section_id(section, id); + set_item_string(&item->section.id, make_lit_string(id)); + } +} + +#define doc_end(b) doc_pop(b) + +#define begin_style(b,t) doc_new_item_strings(b, Doc_Style, t, null_string, PUSH) +#define begin_link(b,t) doc_new_item_strings(b, Doc_Link, t, null_string, PUSH); +#define begin_list(b) doc_new_item(b, Doc_List, PUSH) +#define begin_item(b) doc_new_item(b, Doc_Item, PUSH) + +internal void +add_include(Document_System *doc_system, Document_Builder *builder, String text){ + Document_Item *item = doc_new_item(builder, Doc_Include); + set_item_string(&item->include.name, text); + create_unresolved_include(doc_system, item); +} + +#define add_error(b,t) doc_new_item_strings(b, Doc_Error, t, null_string) +#define add_todo(b) doc_new_item(b, Doc_Todo) +#define add_doc_list(b,u,m) doc_new_item_documentation(b, Doc_DocList, u, m) +#define add_doc_full(b,u,m) doc_new_item_documentation(b, Doc_DocFull, u, m) +#define add_table_of_contents(b) doc_new_item(b, Doc_TableOfContents) +#define add_plain_old_text(b,t) doc_new_item_strings(b, Doc_PlainOldText, t, null_string); +#define add_version(b) doc_new_item(b, Doc_Version) +#define add_document_link(b,t) doc_new_item_strings(b, Doc_DocumentLink, t, null_string) +#define add_image(b,t,e) doc_new_item_strings(b, Doc_Image, t, e) +#define add_video(b,t) doc_new_item_strings(b, Doc_Video, t, null_string) +#define add_begin_paragraph(b) doc_new_item(b, Doc_BeginParagraph) +#define add_end_paragraph(b) doc_new_item(b, Doc_EndParagraph) + +internal void +doc_pop(Document_Builder *builder){ + if (builder->item_top > 0){ + --builder->item_top; + } + else{ + add_error(builder, make_lit_string("unbalanced groups -- extra end")); } } internal void -end_section(Document_Builder *builder){ - Assert(builder->section_top > 0); - --builder->section_top; +end_document_description(Document_Builder *builder){ + b32 closing_error = (builder->item_top != 0); + if (closing_error){ + add_error(builder, make_lit_string("unbalanced groups -- extra begin")); + } + + for (;builder->item_top > 0;){ + doc_end(builder); + } } -internal void -add_error(Document_Builder *builder, String text){ - doc_new_item_strings(builder, Doc_Error, text, null_string); -} +//////////////////////////////// internal void report_error_missing_body(Document_Builder *builder, String command_body){ @@ -517,135 +592,19 @@ report_error_missing_body(Document_Builder *builder, String command_body){ add_error(builder, error_string); } -internal void -add_todo(Document_Builder *builder){ - doc_new_item(builder, Doc_Todo); -} - -internal void -add_include(Document_System *doc_system, Document_Builder *builder, String text){ - Document_Item *item = doc_new_item(builder, Doc_Include); - set_item_string(&item->include.name, text); - create_unresolved_include(doc_system, item); -} - -internal void -add_doc_list(Document_Builder *builder, Meta_Unit *unit, Mangle_Rule mangle_rule){ - Document_Item *item = doc_new_item(builder, Doc_DocList); - item->unit_elements.unit = unit; - item->unit_elements.mangle_rule = mangle_rule; -} - -internal void -add_doc_full(Document_Builder *builder, Meta_Unit *unit, Mangle_Rule mangle_rule){ - Document_Item *item = doc_new_item(builder, Doc_DocFull); - item->unit_elements.unit = unit; - item->unit_elements.mangle_rule = mangle_rule; -} - -internal void -add_table_of_contents(Document_Builder *builder){ - doc_new_item(builder, Doc_TableOfContents); -} - -internal void -add_plain_old_text(Document_Builder *builder, String text){ - doc_new_item_strings(builder, Doc_PlainOldText, text, null_string); -} - -internal void -add_enriched_text(Document_Builder *builder, Enriched_Text *text){ - Document_Item *item = doc_new_item(builder, Doc_PlainOldText); - item->enriched_text.text = text; -} - -internal void -add_version(Document_Builder *builder){ - doc_new_item(builder, Doc_Version); -} - -internal void -add_begin_style(Document_Builder *builder, String text){ - doc_new_item_strings(builder, Doc_BeginStyle, text, null_string); -} - -internal void -add_end_style(Document_Builder *builder){ - doc_new_item(builder, Doc_EndStyle); -} - -internal void -add_document_link(Document_Builder *builder, String text){ - doc_new_item_strings(builder, Doc_DocumentLink, text, null_string); -} - -internal void -add_begin_link(Document_Builder *builder, String text){ - doc_new_item_strings(builder, Doc_BeginLink, text, null_string); -} - -internal void -add_end_link(Document_Builder *builder){ - doc_new_item(builder, Doc_EndLink); -} - -internal void -add_image(Document_Builder *builder, String text, String extra_text){ - doc_new_item_strings(builder, Doc_Image, text, extra_text); -} - -internal void -add_video(Document_Builder *builder, String text){ - doc_new_item_strings(builder, Doc_Video, text, null_string); -} - -internal void -add_begin_paragraph(Document_Builder *builder){ - doc_new_item(builder, Doc_BeginParagraph); -} - -internal void -add_end_paragraph(Document_Builder *builder){ - doc_new_item(builder, Doc_EndParagraph); -} - -internal void -add_begin_list(Document_Builder *builder){ - doc_new_item(builder, Doc_BeginList); -} - -internal void -add_end_list(Document_Builder *builder){ - doc_new_item(builder, Doc_EndList); -} - -internal void -add_begin_item(Document_Builder *builder){ - doc_new_item(builder, Doc_BeginItem); -} - -internal void -add_end_item(Document_Builder *builder){ - doc_new_item(builder, Doc_EndItem); -} - -// Document Generation from Enriched Text +//////////////////////////////// enum Command_Types{ Cmd_BackSlash, - Cmd_BeginStyle, - Cmd_EndStyle, + Cmd_End, + Cmd_Section, + Cmd_Style, + Cmd_List, + Cmd_Item, + Cmd_Link, Cmd_DocumentLink, - Cmd_BeginList, - Cmd_EndList, - Cmd_BeginItem, - Cmd_EndItem, - Cmd_BeginLink, - Cmd_EndLink, Cmd_Image, Cmd_Video, - Cmd_Section, - Cmd_EndSection, Cmd_Version, Cmd_TableOfContents, Cmd_Todo, @@ -665,19 +624,15 @@ get_enriched_commands(){ if (!did_enriched_commands){ did_enriched_commands = true; enriched_commands_global_array[Cmd_BackSlash] = make_lit_string("\\"); - enriched_commands_global_array[Cmd_BeginStyle] = make_lit_string("BEGIN_STYLE"); - enriched_commands_global_array[Cmd_EndStyle] = make_lit_string("END_STYLE"); + enriched_commands_global_array[Cmd_End] = make_lit_string("END"); + enriched_commands_global_array[Cmd_Section] = make_lit_string("SECTION"); + enriched_commands_global_array[Cmd_Style] = make_lit_string("STYLE"); + enriched_commands_global_array[Cmd_List] = make_lit_string("LIST"); + enriched_commands_global_array[Cmd_Item] = make_lit_string("ITEM"); + enriched_commands_global_array[Cmd_Link] = make_lit_string("LINK"); enriched_commands_global_array[Cmd_DocumentLink] = make_lit_string("DOC_LINK"); - enriched_commands_global_array[Cmd_BeginList] = make_lit_string("BEGIN_LIST"); - enriched_commands_global_array[Cmd_EndList] = make_lit_string("END_LIST"); - enriched_commands_global_array[Cmd_BeginItem] = make_lit_string("BEGIN_ITEM"); - enriched_commands_global_array[Cmd_EndItem] = make_lit_string("END_ITEM"); - enriched_commands_global_array[Cmd_BeginLink] = make_lit_string("BEGIN_LINK"); - enriched_commands_global_array[Cmd_EndLink] = make_lit_string("END_LINK"); enriched_commands_global_array[Cmd_Image] = make_lit_string("IMAGE"); enriched_commands_global_array[Cmd_Video] = make_lit_string("VIDEO"); - enriched_commands_global_array[Cmd_Section] = make_lit_string("SECTION"); - enriched_commands_global_array[Cmd_EndSection] = make_lit_string("END_SECTION"); enriched_commands_global_array[Cmd_Version] = make_lit_string("VERSION"); enriched_commands_global_array[Cmd_TableOfContents] = make_lit_string("TABLE_OF_CONTENTS"); enriched_commands_global_array[Cmd_Todo] = make_lit_string("TODO"); @@ -695,47 +650,35 @@ get_enriched_commands_count(){ } internal b32 -extract_command_body(String l, i32 *i_in_out, i32 *body_start_out, i32 *body_end_out){ - b32 result = false; +extract_command_body(String l, i32 *i_in_out, String *body_text_out){ + b32 has_body = false; i32 i = *i_in_out; - for (; i < l.size; ++i){ if (!char_is_whitespace(l.str[i])){ break; } } - i32 body_start = 0, body_end = 0; if (l.str[i] == '{'){ - body_start = i + 1; + i32 body_start = i + 1; + i32 body_end = 0; for (++i; i < l.size; ++i){ if (l.str[i] == '}'){ - result = true; + has_body = true; body_end = i; ++i; break; } } + + if (has_body){ + *i_in_out = i; + + String body_text = substr(l, body_start, body_end - body_start); + *body_text_out = skip_chop_whitespace(body_text); + } } - if (result){ - *i_in_out = i; - *body_start_out = body_start; - *body_end_out = body_end; - } - - return(result); -} - -internal b32 -extract_command_body(String l, i32 *i_in_out, String *body_text_out){ - i32 body_start = 0, body_end = 0; - b32 has_body = extract_command_body(l, i_in_out, &body_start, &body_end); - if (has_body){ - String body_text = substr(l, body_start, body_end - body_start); - body_text = skip_chop_whitespace(body_text); - *body_text_out = body_text; - } return(has_body); } @@ -798,29 +741,74 @@ make_document_from_text(Document_System *doc_system, char *title, char *name, En add_plain_old_text(&builder, make_lit_string("\\")); }break; - case Cmd_BeginStyle: + case Cmd_End: + { + for (Document_Item *top = doc_get_item_top(&builder); + top->type == Doc_Item; + top = doc_get_item_top(&builder)){ + doc_end(&builder); + } + doc_end(&builder); + }break; + + case Cmd_Section: { String body_text = {0}; - b32 has_body = extract_command_body(l, &i, &body_text); - if (has_body){ - add_begin_style(&builder, body_text); + if (extract_command_body(l, &i, &body_text)){ + String extra_text = {0}; + extract_command_body(l, &i, &extra_text); + + char *title = get_null_terminated_version(body_text); + char *id = get_null_terminated_version(extra_text); + + begin_section(&builder, title, id); } else{ report_error_missing_body(&builder, command_string); } }break; - case Cmd_EndStyle: + case Cmd_Style: { - add_end_style(&builder); + String body_text = {0}; + if (extract_command_body(l, &i, &body_text)){ + begin_style(&builder, body_text); + } + else{ + report_error_missing_body(&builder, command_string); + } + }break; + + case Cmd_List: + { + begin_list(&builder); + }break; + + case Cmd_Item: + { + Document_Item *top = doc_get_item_top(&builder); + if (top->type == Doc_Item){ + doc_end(&builder); + } + begin_item(&builder); + }break; + + case Cmd_Link: + { + String body_text = {0}; + if (extract_command_body(l, &i, &body_text)){ + begin_link(&builder, body_text); + } + else{ + report_error_missing_body(&builder, command_string); + } }break; // TODO(allen): upgrade this bs case Cmd_DocumentLink: { String body_text = {0}; - b32 has_body = extract_command_body(l, &i, &body_text); - if (has_body){ + if (extract_command_body(l, &i, &body_text)){ add_document_link(&builder, body_text); } else{ @@ -828,48 +816,10 @@ make_document_from_text(Document_System *doc_system, char *title, char *name, En } }break; - case Cmd_BeginList: - { - add_begin_list(&builder); - }break; - - case Cmd_EndList: - { - add_end_list(&builder); - }break; - - case Cmd_BeginItem: - { - add_begin_item(&builder); - }break; - - case Cmd_EndItem: - { - add_end_item(&builder); - }break; - - case Cmd_BeginLink: - { - String body_text = {0}; - b32 has_body = extract_command_body(l, &i, &body_text); - if (has_body){ - add_begin_link(&builder, body_text); - } - else{ - report_error_missing_body(&builder, command_string); - } - }break; - - case Cmd_EndLink: - { - add_end_link(&builder); - }break; - case Cmd_Image: { String body_text = {0}; - b32 has_body = extract_command_body(l, &i, &body_text); - if (has_body){ + if (extract_command_body(l, &i, &body_text)){ String size_parameter = {0}; extract_command_body(l, &i, &size_parameter); add_image(&builder, body_text, size_parameter); @@ -882,8 +832,7 @@ make_document_from_text(Document_System *doc_system, char *title, char *name, En case Cmd_Video: { String body_text = {0}; - b32 has_body = extract_command_body(l, &i, &body_text); - if (has_body){ + if (extract_command_body(l, &i, &body_text)){ add_video(&builder, body_text); } else{ @@ -891,34 +840,6 @@ make_document_from_text(Document_System *doc_system, char *title, char *name, En } }break; - case Cmd_Section: - { - String body_text = {0}; - b32 has_body = extract_command_body(l, &i, &body_text); - if (has_body){ - String extra_text = {0}; - extract_command_body(l, &i, &extra_text); - - String title = str_alloc(body_text.size + 1); - copy(&title, body_text); - terminate_with_null(&title); - - String id = str_alloc(extra_text.size + 1); - copy(&id, extra_text); - terminate_with_null(&id); - - begin_section(&builder, title.str, id.str); - } - else{ - report_error_missing_body(&builder, command_string); - } - }break; - - case Cmd_EndSection: - { - end_section(&builder); - }break; - case Cmd_Version: { add_version(&builder); @@ -937,8 +858,7 @@ make_document_from_text(Document_System *doc_system, char *title, char *name, En case Cmd_Include: { String body_text = {0}; - b32 has_body = extract_command_body(l, &i, &body_text); - if (has_body){ + if (extract_command_body(l, &i, &body_text)){ add_include(doc_system, &builder, body_text); } else{ @@ -952,7 +872,8 @@ make_document_from_text(Document_System *doc_system, char *title, char *name, En String file = {0}; if (extract_command_body(l, &i, &name)){ if (extract_command_body(l, &i, &file)){ - if (!create_meta_unit(doc_system, name, file)){ + u32 result = create_meta_unit(doc_system, name, file); + if (result == MetaResult_FailedToParse){ char space[512]; String str = make_fixed_width_string(space); append(&str, "parse failed for "); @@ -977,22 +898,20 @@ make_document_from_text(Document_System *doc_system, char *title, char *name, En String mangle = {0}; extract_command_body(l, &i, &mangle); - Abstract_Item *item = get_item_by_name(doc_system->meta_list, name); - if (item != 0){ - u32 mangle_rule = MangleRule_None; - if (match_part(mangle, "mangle:")){ - String mangle_name = substr_tail(mangle, sizeof("mangle:")-1); - mangle_name = skip_chop_whitespace(mangle_name); - mangle_rule = get_mangle_rule(mangle_name); - } - - if (match_index == Cmd_DocList){ - add_doc_list(&builder, item->unit, mangle_rule); - } - else{ - add_doc_full(&builder, item->unit, mangle_rule); - } + u32 mangle_rule = MangleRule_None; + if (match_part(mangle, "mangle:")){ + String mangle_name = substr_tail(mangle, sizeof("mangle:")-1); + mangle_name = skip_chop_whitespace(mangle_name); + mangle_rule = get_mangle_rule(mangle_name); } + + if (match_index == Cmd_DocList){ + add_doc_list(&builder, name, mangle_rule); + } + else{ + add_doc_full(&builder, name, mangle_rule); + } + } else{ report_error_missing_body(&builder, command_string); @@ -1146,8 +1065,8 @@ img_get_link_string(Abstract_Item *img, char *space, i32 capacity, i32 w, i32 h) internal void append_section_number_reduced(String *out, Section_Counter *section_counter, i32 reduce){ - i32 level = section_counter->nest_level-reduce; - for (i32 i = 1; i <= level; ++i){ + i32 level = section_counter->nest_level - reduce; + for (i32 i = 0; i <= level; ++i){ append_int_to_str(out, section_counter->counter[i]); if (i != level){ append(out, "."); @@ -1375,24 +1294,6 @@ output_end_paragraph(String *out){ append(out, "

"); } -internal void -output_begin_section(String *out, Section_Counter *section_counter, String l, String l2){ - html_render_section_header(out, l, l2, section_counter); - ++section_counter->nest_level; - section_counter->list_item_counter = 0; -} - -internal void -output_end_section(String *out, Section_Counter *section_counter){ - if (section_counter->nest_level > 0){ - --section_counter->nest_level; - ++section_counter->counter[section_counter->nest_level]; - } - else{ - output_error(out, make_lit_string("unmatched section end")); - } -} - internal void output_begin_list(String *out){ append(out,"