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
+50 -50
View File
@@ -907,7 +907,7 @@ parse_from_text_tokens(Arena* arena, String8 filename, String8 text, TokenArray
//- rjf: [main] }s, ]s, and )s -> pop //- 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))) { 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_HasBraceRight *!! str8_match(token_string, str8_lit("}"), 0);
parent->flags |= NodeFlag_HasBracketRight *!! 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); 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 //~ 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); scratch_end(scratch);
scratch_end(scratch); return parse;
return parse;
} }
//////////////////////////////// ////////////////////////////////
//~ 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};
{ {
char *indentation = " "; // Depth-first traversal of tree.
S32 depth = 0; char* indentation = " ";
for(Node *node = root, *next = nil_node(); !node_is_nil(node); node = next) 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); // rjf: get next recursion
next = rec.next; NodeRec
rec = node_rec_depth_first_pre(node, root);
next = rec.next;
// rjf: extract node info // rjf: extract node info
String8 kind_string = str8_lit("Unknown"); String8 kind_string = str8_lit("Unknown");
switch(node->kind) switch (node->kind)
{ {
default:{}break; 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 case NodeKind_File: { kind_string = str8_lit("File" ); } break;
str8_list_pushf(arena, &strings, "%.*s\"%S\" : %S", depth, indentation, node->string, kind_string); 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: children -> open brace // rjf: push node line
if(rec.push_count != 0) str8_list_pushf(arena, &strings, "%.*s\"%S\" : %S", depth, indentation, node->string, kind_string);
{
str8_list_pushf(arena, &strings, "%.*s{", depth, indentation);
}
// rjf: descend // rjf: children -> open brace
depth += rec.push_count; if (rec.push_count != 0) {
str8_list_pushf(arena, &strings, "%.*s\n{", depth, indentation);
}
// rjf: popping -> close braces // rjf: descend
for(S32 pop_idx = 0; pop_idx < rec.pop_count; pop_idx += 1) depth += rec.push_count;
{
str8_list_pushf(arena, &strings, "%.*s}", depth-1-pop_idx, indentation);
}
// rjf: ascend // rjf: popping -> close braces
depth -= rec.pop_count; 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);
} }
return strings;
// rjf: ascend
depth -= rec.pop_count;
}
}
return strings;
} }
+27 -27
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,37 +124,36 @@ typedef enum NodeKind
NodeKind_List, NodeKind_List,
NodeKind_Reference, NodeKind_Reference,
NodeKind_COUNT NodeKind_COUNT
} };
NodeKind;
typedef U32 NodeFlags; typedef U32 NodeFlags;
enum enum
{ {
NodeFlag_MaskSetDelimiters = (0x3F<<0), NodeFlag_MaskSetDelimiters = (0x3F << 0),
NodeFlag_HasParenLeft = (1<<0), NodeFlag_HasParenLeft = (1 << 0),
NodeFlag_HasParenRight = (1<<1), NodeFlag_HasParenRight = (1 << 1),
NodeFlag_HasBracketLeft = (1<<2), NodeFlag_HasBracketLeft = (1 << 2),
NodeFlag_HasBracketRight = (1<<3), NodeFlag_HasBracketRight = (1 << 3),
NodeFlag_HasBraceLeft = (1<<4), NodeFlag_HasBraceLeft = (1 << 4),
NodeFlag_HasBraceRight = (1<<5), NodeFlag_HasBraceRight = (1 << 5),
NodeFlag_MaskSeparators = (0xF<<6), NodeFlag_MaskSeparators = (0xF << 6),
NodeFlag_IsBeforeSemicolon = (1<<6), NodeFlag_IsBeforeSemicolon = (1 << 6),
NodeFlag_IsAfterSemicolon = (1<<7), NodeFlag_IsAfterSemicolon = (1 << 7),
NodeFlag_IsBeforeComma = (1<<8), NodeFlag_IsBeforeComma = (1 << 8),
NodeFlag_IsAfterComma = (1<<9), NodeFlag_IsAfterComma = (1 << 9),
NodeFlag_MaskStringDelimiters = (0xF<<10), NodeFlag_MaskStringDelimiters = (0xF << 10),
NodeFlag_StringSingleQuote = (1<<10), NodeFlag_StringSingleQuote = (1 << 10),
NodeFlag_StringDoubleQuote = (1<<11), NodeFlag_StringDoubleQuote = (1 << 11),
NodeFlag_StringTick = (1<<12), NodeFlag_StringTick = (1 << 12),
NodeFlag_StringTriplet = (1<<13), NodeFlag_StringTriplet = (1 << 13),
NodeFlag_MaskLabelKind = (0xF<<14), NodeFlag_MaskLabelKind = (0xF << 14),
NodeFlag_Numeric = (1<<14), NodeFlag_Numeric = (1 << 14),
NodeFlag_Identifier = (1<<15), NodeFlag_Identifier = (1 << 15),
NodeFlag_StringLiteral = (1<<16), NodeFlag_StringLiteral = (1 << 16),
NodeFlag_Symbol = (1<<17), NodeFlag_Symbol = (1 << 17),
}; };
#define NodeFlag_AfterFromBefore(f) ((f) << 1) #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 //~ 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)