diff --git a/Readme.md b/Readme.md index 211d915..07efefb 100644 --- a/Readme.md +++ b/Readme.md @@ -11,3 +11,11 @@ The library will be provided in 3 forms: * cpp17: Setup ergonoically for usage as a C++ 17 library (both segregated and as a single-header) docs will be updated referencing content procued by Ryan Fleury and content based on studying or resolving this library for this repo. + +## Documentation + +* [docs](./docs/Readme.md) +* [examples](./examples/Readme.md) +* [gen_c11](./gen_c11/Readme.md) +* [gen_cpp17](./gen_cpp17/Readme.md) + diff --git a/bin/Readme.md b/bin/Readme.md new file mode 100644 index 0000000..88bc864 --- /dev/null +++ b/bin/Readme.md @@ -0,0 +1,3 @@ +# bin + + diff --git a/code/mdesk/mdesk.c b/code/mdesk/mdesk.c index fe9b2d0..08db12a 100644 --- a/code/mdesk/mdesk.c +++ b/code/mdesk/mdesk.c @@ -907,7 +907,7 @@ parse_from_text_tokens(Arena* arena, String8 filename, String8 text, TokenArray //- rjf: [main] }s, ]s, and )s -> pop if (work_top->kind == ParseWorkKind_Main && token->flags & TokenFlag_Reserved && (str8_match(token_string, str8_lit("}"), 0) || str8_match(token_string, str8_lit("]"), 0) || str8_match(token_string, str8_lit(")"), 0))) { - Node *parent = work_top->parent; + Node* parent = work_top->parent; parent->flags |= NodeFlag_HasBraceRight *!! str8_match(token_string, str8_lit("}"), 0); parent->flags |= NodeFlag_HasBracketRight *!! str8_match(token_string, str8_lit("]"), 0); parent->flags |= NodeFlag_HasParenRight *!! str8_match(token_string, str8_lit(")"), 0); @@ -945,65 +945,65 @@ parse_from_text_tokens(Arena* arena, String8 filename, String8 text, TokenArray //~ rjf: Bundled Text -> Tree Functions ParseResult -parse_from_text(Arena* arena, String8 filename, String8 text) -{ - TempArena scratch = scratch_begin(&arena, 1); - TokenizeResult tokenize = tokenize_from_text(scratch.arena, text); - ParseResult parse = parse_from_text_tokens(arena, filename, text, tokenize.tokens); - scratch_end(scratch); - return parse; +parse_from_text(Arena* arena, String8 filename, String8 text) { + TempArena scratch = scratch_begin(&arena, 1); + TokenizeResult tokenize = tokenize_from_text(scratch.arena, text); + ParseResult parse = parse_from_text_tokens(arena, filename, text, tokenize.tokens); + scratch_end(scratch); + return parse; } //////////////////////////////// //~ rjf: Tree -> Text Functions -internal String8List -debug_string_list_from_tree(Arena *arena, Node *root) +String8List +debug_string_list_from_tree(Arena* arena, Node* root) { - String8List strings = {0}; - { - char *indentation = " "; - S32 depth = 0; - for(Node *node = root, *next = nil_node(); !node_is_nil(node); node = next) - { - // rjf: get next recursion - NodeRec rec = node_rec_depth_first_pre(node, root); - next = rec.next; - - // rjf: extract node info - String8 kind_string = str8_lit("Unknown"); - switch(node->kind) - { - default:{}break; - case NodeKind_File: {kind_string = str8_lit("File"); }break; - case NodeKind_ErrorMarker:{kind_string = str8_lit("ErrorMarker");}break; - case NodeKind_Main: {kind_string = str8_lit("Main"); }break; - case NodeKind_Tag: {kind_string = str8_lit("Tag"); }break; - case NodeKind_List: {kind_string = str8_lit("List"); }break; - case NodeKind_Reference: {kind_string = str8_lit("Reference"); }break; - } - - // rjf: push node line - str8_list_pushf(arena, &strings, "%.*s\"%S\" : %S", depth, indentation, node->string, kind_string); - - // rjf: children -> open brace - if(rec.push_count != 0) - { - str8_list_pushf(arena, &strings, "%.*s{", depth, indentation); - } - - // rjf: descend - depth += rec.push_count; - - // rjf: popping -> close braces - for(S32 pop_idx = 0; pop_idx < rec.pop_count; pop_idx += 1) - { - str8_list_pushf(arena, &strings, "%.*s}", depth-1-pop_idx, indentation); - } - - // rjf: ascend - depth -= rec.pop_count; - } - } - return strings; + String8List strings = {0}; + { + // Depth-first traversal of tree. + char* indentation = " "; + S32 depth = 0; + for (Node* node = root, *next = nil_node(); !node_is_nil(node); node = next) + { + // rjf: get next recursion + NodeRec + rec = node_rec_depth_first_pre(node, root); + next = rec.next; + + // rjf: extract node info + String8 kind_string = str8_lit("Unknown"); + switch (node->kind) + { + default: {} break; + + case NodeKind_File: { kind_string = str8_lit("File" ); } break; + case NodeKind_ErrorMarker: { kind_string = str8_lit("ErrorMarker"); } break; + case NodeKind_Main: { kind_string = str8_lit("Main" ); } break; + case NodeKind_Tag: { kind_string = str8_lit("Tag" ); } break; + case NodeKind_List: { kind_string = str8_lit("List" ); } break; + case NodeKind_Reference: { kind_string = str8_lit("Reference" ); } break; + } + + // rjf: push node line + str8_list_pushf(arena, &strings, "%.*s\"%S\" : %S", depth, indentation, node->string, kind_string); + + // rjf: children -> open brace + if (rec.push_count != 0) { + str8_list_pushf(arena, &strings, "%.*s\n{", depth, indentation); + } + + // rjf: descend + depth += rec.push_count; + + // rjf: popping -> close braces + for (S32 pop_idx = 0; pop_idx < rec.pop_count; pop_idx += 1) { + str8_list_pushf(arena, &strings, "%.*s\n}", depth - 1 - pop_idx, indentation); + } + + // rjf: ascend + depth -= rec.pop_count; + } + } + return strings; } diff --git a/code/mdesk/mdesk.h b/code/mdesk/mdesk.h index d2acbe6..6a4b141 100644 --- a/code/mdesk/mdesk.h +++ b/code/mdesk/mdesk.h @@ -113,7 +113,8 @@ struct TokenArray //////////////////////////////// //~ rjf: Node Types -typedef enum NodeKind +typedef enum NodeKind NodeKind; +enum NodeKind { NodeKind_Nil, NodeKind_File, @@ -123,37 +124,36 @@ typedef enum NodeKind NodeKind_List, NodeKind_Reference, NodeKind_COUNT -} -NodeKind; +}; typedef U32 NodeFlags; enum { - NodeFlag_MaskSetDelimiters = (0x3F<<0), - NodeFlag_HasParenLeft = (1<<0), - NodeFlag_HasParenRight = (1<<1), - NodeFlag_HasBracketLeft = (1<<2), - NodeFlag_HasBracketRight = (1<<3), - NodeFlag_HasBraceLeft = (1<<4), - NodeFlag_HasBraceRight = (1<<5), + NodeFlag_MaskSetDelimiters = (0x3F << 0), + NodeFlag_HasParenLeft = (1 << 0), + NodeFlag_HasParenRight = (1 << 1), + NodeFlag_HasBracketLeft = (1 << 2), + NodeFlag_HasBracketRight = (1 << 3), + NodeFlag_HasBraceLeft = (1 << 4), + NodeFlag_HasBraceRight = (1 << 5), - NodeFlag_MaskSeparators = (0xF<<6), - NodeFlag_IsBeforeSemicolon = (1<<6), - NodeFlag_IsAfterSemicolon = (1<<7), - NodeFlag_IsBeforeComma = (1<<8), - NodeFlag_IsAfterComma = (1<<9), + NodeFlag_MaskSeparators = (0xF << 6), + NodeFlag_IsBeforeSemicolon = (1 << 6), + NodeFlag_IsAfterSemicolon = (1 << 7), + NodeFlag_IsBeforeComma = (1 << 8), + NodeFlag_IsAfterComma = (1 << 9), - NodeFlag_MaskStringDelimiters = (0xF<<10), - NodeFlag_StringSingleQuote = (1<<10), - NodeFlag_StringDoubleQuote = (1<<11), - NodeFlag_StringTick = (1<<12), - NodeFlag_StringTriplet = (1<<13), + NodeFlag_MaskStringDelimiters = (0xF << 10), + NodeFlag_StringSingleQuote = (1 << 10), + NodeFlag_StringDoubleQuote = (1 << 11), + NodeFlag_StringTick = (1 << 12), + NodeFlag_StringTriplet = (1 << 13), - NodeFlag_MaskLabelKind = (0xF<<14), - NodeFlag_Numeric = (1<<14), - NodeFlag_Identifier = (1<<15), - NodeFlag_StringLiteral = (1<<16), - NodeFlag_Symbol = (1<<17), + NodeFlag_MaskLabelKind = (0xF << 14), + NodeFlag_Numeric = (1 << 14), + NodeFlag_Identifier = (1 << 15), + NodeFlag_StringLiteral = (1 << 16), + NodeFlag_Symbol = (1 << 17), }; #define NodeFlag_AfterFromBefore(f) ((f) << 1) @@ -502,10 +502,10 @@ MD_API ParseResult parse_from_text_tokens(Arena* arena, String8 filename, String //////////////////////////////// //~ rjf: Bundled Text -> Tree Functions -ParseResult parse_from_text(Arena* arena, String8 filename, String8 text); +MD_API ParseResult parse_from_text(Arena* arena, String8 filename, String8 text); #define tree_from_string(arena, string) (parse_from_text((arena), str8_zero(), (string)).root) //////////////////////////////// //~ rjf: Tree -> Text Functions -String8List debug_string_list_from_tree(Arena* arena, Node* root); +MD_API String8List debug_string_list_from_tree(Arena* arena, Node* root); diff --git a/code/metadesk.h b/code/metadesk.h index bbfe615..ca34fff 100644 --- a/code/metadesk.h +++ b/code/metadesk.h @@ -4,6 +4,5 @@ #include "base/base.h" #include "os/os.h" +#include "mdesk/mdesk.h" -// mdesk -// metagen diff --git a/docs/Readme.md b/docs/Readme.md new file mode 100644 index 0000000..f6bd8ff --- /dev/null +++ b/docs/Readme.md @@ -0,0 +1,4 @@ +# docs + +Haven't done yet... + diff --git a/docs/mdesk.pur b/docs/mdesk.pur index 6a79d7c..25efa0e 100644 Binary files a/docs/mdesk.pur and b/docs/mdesk.pur differ diff --git a/examples/Readme.md b/examples/Readme.md new file mode 100644 index 0000000..b18059f --- /dev/null +++ b/examples/Readme.md @@ -0,0 +1,3 @@ +# Examples + + diff --git a/gen_c11/Readme.md b/gen_c11/Readme.md new file mode 100644 index 0000000..9e6d49d --- /dev/null +++ b/gen_c11/Readme.md @@ -0,0 +1,3 @@ +# gen_c11 + + diff --git a/gen_c11/c11.refactor b/gen_c11/c11.refactor index 263226a..d6c5f8e 100644 --- a/gen_c11/c11.refactor +++ b/gen_c11/c11.refactor @@ -1017,9 +1017,9 @@ word Msg, MD_Msg word MsgList, MD_MsgList word TokenFlags, MD_MsgFlags -namespace TokenFlag, MD_TokenFlag +namespace TokenFlag_, MD_TokenFlag_ word TokenGroups, MD_TokenGroups -namespace TokenGroup, MD_TokenGroup +namespace TokenGroup_, MD_TokenGroup_ word Token, MD_Token word TokenChunkNode, MD_TokenChunkNode word TokenChunkList, MD_TokenChunkList diff --git a/gen_cpp17/Readme.md b/gen_cpp17/Readme.md new file mode 100644 index 0000000..4365c8b --- /dev/null +++ b/gen_cpp17/Readme.md @@ -0,0 +1,3 @@ +# gen_cpp17 + + diff --git a/source/md.c b/old_source/md.c similarity index 100% rename from source/md.c rename to old_source/md.c diff --git a/source/md.h b/old_source/md.h similarity index 100% rename from source/md.h rename to old_source/md.h diff --git a/source/md_stb_sprintf.h b/old_source/md_stb_sprintf.h similarity index 100% rename from source/md_stb_sprintf.h rename to old_source/md_stb_sprintf.h diff --git a/third_party/gencpp_c11/Readme.md b/third_party/gencpp_c11/Readme.md new file mode 100644 index 0000000..0854cfc --- /dev/null +++ b/third_party/gencpp_c11/Readme.md @@ -0,0 +1,4 @@ +# gencpp_c11 + +See: [gencpp](https://github.com/Ed94/gencpp) + diff --git a/third_party/stb/Readme.md b/third_party/stb/Readme.md new file mode 100644 index 0000000..6aeb894 --- /dev/null +++ b/third_party/stb/Readme.md @@ -0,0 +1,4 @@ +# stb + +See: [stb](https://github.com/nothings/stb) +