mirror of
https://github.com/Ed94/metadesk.git
synced 2026-06-12 23:51:37 -07:00
misc
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
# bin
|
||||
|
||||
|
||||
+56
-56
@@ -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;
|
||||
}
|
||||
|
||||
+27
-27
@@ -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);
|
||||
|
||||
+1
-2
@@ -4,6 +4,5 @@
|
||||
|
||||
#include "base/base.h"
|
||||
#include "os/os.h"
|
||||
#include "mdesk/mdesk.h"
|
||||
|
||||
// mdesk
|
||||
// metagen
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
# docs
|
||||
|
||||
Haven't done yet...
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
# Examples
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
# gen_c11
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
# gen_cpp17
|
||||
|
||||
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
# gencpp_c11
|
||||
|
||||
See: [gencpp](https://github.com/Ed94/gencpp)
|
||||
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
# stb
|
||||
|
||||
See: [stb](https://github.com/nothings/stb)
|
||||
|
||||
Reference in New Issue
Block a user