This commit is contained in:
ed
2025-02-08 16:26:54 -05:00
parent c8490143a4
commit 2ef486b7a0
16 changed files with 118 additions and 87 deletions
+8
View File
@@ -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) * 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. 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)
+3
View File
@@ -0,0 +1,3 @@
# bin
+10 -10
View File
@@ -945,8 +945,7 @@ parse_from_text_tokens(Arena* arena, String8 filename, String8 text, TokenArray
//~ rjf: Bundled Text -> Tree Functions //~ rjf: Bundled Text -> Tree Functions
ParseResult ParseResult
parse_from_text(Arena* arena, String8 filename, String8 text) parse_from_text(Arena* arena, String8 filename, String8 text) {
{
TempArena scratch = scratch_begin(&arena, 1); TempArena scratch = scratch_begin(&arena, 1);
TokenizeResult tokenize = tokenize_from_text(scratch.arena, text); TokenizeResult tokenize = tokenize_from_text(scratch.arena, text);
ParseResult parse = parse_from_text_tokens(arena, filename, text, tokenize.tokens); ParseResult parse = parse_from_text_tokens(arena, filename, text, tokenize.tokens);
@@ -957,17 +956,19 @@ parse_from_text(Arena* arena, String8 filename, String8 text)
//////////////////////////////// ////////////////////////////////
//~ rjf: Tree -> Text Functions //~ rjf: Tree -> Text Functions
internal String8List String8List
debug_string_list_from_tree(Arena* arena, Node* root) debug_string_list_from_tree(Arena* arena, Node* root)
{ {
String8List strings = {0}; String8List strings = {0};
{ {
// Depth-first traversal of tree.
char* indentation = " "; char* indentation = " ";
S32 depth = 0; S32 depth = 0;
for (Node* node = root, *next = nil_node(); !node_is_nil(node); node = next) for (Node* node = root, *next = nil_node(); !node_is_nil(node); node = next)
{ {
// rjf: get next recursion // rjf: get next recursion
NodeRec rec = node_rec_depth_first_pre(node, root); NodeRec
rec = node_rec_depth_first_pre(node, root);
next = rec.next; next = rec.next;
// rjf: extract node info // rjf: extract node info
@@ -975,6 +976,7 @@ debug_string_list_from_tree(Arena *arena, Node *root)
switch (node->kind) switch (node->kind)
{ {
default: {} break; default: {} break;
case NodeKind_File: { kind_string = str8_lit("File" ); } break; case NodeKind_File: { kind_string = str8_lit("File" ); } break;
case NodeKind_ErrorMarker: { kind_string = str8_lit("ErrorMarker"); } break; case NodeKind_ErrorMarker: { kind_string = str8_lit("ErrorMarker"); } break;
case NodeKind_Main: { kind_string = str8_lit("Main" ); } break; case NodeKind_Main: { kind_string = str8_lit("Main" ); } break;
@@ -987,18 +989,16 @@ debug_string_list_from_tree(Arena *arena, Node *root)
str8_list_pushf(arena, &strings, "%.*s\"%S\" : %S", depth, indentation, node->string, kind_string); str8_list_pushf(arena, &strings, "%.*s\"%S\" : %S", depth, indentation, node->string, kind_string);
// rjf: children -> open brace // rjf: children -> open brace
if(rec.push_count != 0) if (rec.push_count != 0) {
{ str8_list_pushf(arena, &strings, "%.*s\n{", depth, indentation);
str8_list_pushf(arena, &strings, "%.*s{", depth, indentation);
} }
// rjf: descend // rjf: descend
depth += rec.push_count; depth += rec.push_count;
// rjf: popping -> close braces // rjf: popping -> close braces
for(S32 pop_idx = 0; pop_idx < rec.pop_count; pop_idx += 1) 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);
str8_list_pushf(arena, &strings, "%.*s}", depth-1-pop_idx, indentation);
} }
// rjf: ascend // rjf: ascend
+5 -5
View File
@@ -113,7 +113,8 @@ struct TokenArray
//////////////////////////////// ////////////////////////////////
//~ rjf: Node Types //~ rjf: Node Types
typedef enum NodeKind typedef enum NodeKind NodeKind;
enum NodeKind
{ {
NodeKind_Nil, NodeKind_Nil,
NodeKind_File, NodeKind_File,
@@ -123,8 +124,7 @@ typedef enum NodeKind
NodeKind_List, NodeKind_List,
NodeKind_Reference, NodeKind_Reference,
NodeKind_COUNT NodeKind_COUNT
} };
NodeKind;
typedef U32 NodeFlags; typedef U32 NodeFlags;
enum enum
@@ -502,10 +502,10 @@ MD_API ParseResult parse_from_text_tokens(Arena* arena, String8 filename, String
//////////////////////////////// ////////////////////////////////
//~ rjf: Bundled Text -> Tree Functions //~ 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) #define tree_from_string(arena, string) (parse_from_text((arena), str8_zero(), (string)).root)
//////////////////////////////// ////////////////////////////////
//~ rjf: Tree -> Text Functions //~ 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);
+1 -2
View File
@@ -4,6 +4,5 @@
#include "base/base.h" #include "base/base.h"
#include "os/os.h" #include "os/os.h"
#include "mdesk/mdesk.h"
// mdesk
// metagen
+4
View File
@@ -0,0 +1,4 @@
# docs
Haven't done yet...
BIN
View File
Binary file not shown.
+3
View File
@@ -0,0 +1,3 @@
# Examples
+3
View File
@@ -0,0 +1,3 @@
# gen_c11
+2 -2
View File
@@ -1017,9 +1017,9 @@ word Msg, MD_Msg
word MsgList, MD_MsgList word MsgList, MD_MsgList
word TokenFlags, MD_MsgFlags word TokenFlags, MD_MsgFlags
namespace TokenFlag, MD_TokenFlag namespace TokenFlag_, MD_TokenFlag_
word TokenGroups, MD_TokenGroups word TokenGroups, MD_TokenGroups
namespace TokenGroup, MD_TokenGroup namespace TokenGroup_, MD_TokenGroup_
word Token, MD_Token word Token, MD_Token
word TokenChunkNode, MD_TokenChunkNode word TokenChunkNode, MD_TokenChunkNode
word TokenChunkList, MD_TokenChunkList word TokenChunkList, MD_TokenChunkList
+3
View File
@@ -0,0 +1,3 @@
# gen_cpp17
View File
View File
+4
View File
@@ -0,0 +1,4 @@
# gencpp_c11
See: [gencpp](https://github.com/Ed94/gencpp)
+4
View File
@@ -0,0 +1,4 @@
# stb
See: [stb](https://github.com/nothings/stb)