finish the elimination of MD_PushSibling

This commit is contained in:
Allen Webster
2021-06-28 06:44:06 -04:00
parent 9a93a40135
commit 0d57e26ba5
8 changed files with 75 additions and 37 deletions
+4 -6
View File
@@ -5,20 +5,18 @@
int main(int argument_count, char **arguments)
{
// TODO(allen): use list system
// NOTE(rjf): Parse all the files passed in via command line.
MD_Node *first = MD_NilNode();
MD_Node *last = MD_NilNode();
MD_Node *list = MD_MakeList();
for(int i = 1; i < argument_count; i += 1)
{
MD_Node *root = MD_ParseWholeFile(MD_S8CString(arguments[i])).node;
MD_PushSibling(&first, &last, root);
MD_PushReference(list, root);
}
// NOTE(rjf): Print errors on every single node.
for(MD_EachNode(root, first))
for(MD_EachNode(ref, list->first_child))
{
MD_Node *root = MD_Deref(ref);
for(MD_EachNode(node, root->first_child))
{
MD_NodeMessageF(stderr, node, MD_MessageKind_Error, "This node has an error!");
+4 -6
View File
@@ -23,21 +23,19 @@ CleanUp(void)
int main(int argument_count, char **arguments)
{
// TODO(allen): use list system
// NOTE(rjf): Parse all the files passed in via command line.
MD_Node *first = MD_NilNode();
MD_Node *last = MD_NilNode();
MD_Node *list = MD_MakeList();
for(int i = 1; i < argument_count; i += 1)
{
MD_Node *root = MD_ParseWholeFile(MD_S8CString(arguments[i])).node;
MD_PushSibling(&first, &last, root);
MD_PushReference(list, root);
}
// NOTE(rjf): Call "custom layer" back.
Initialize();
for(MD_EachNode(root, first))
for(MD_EachNode(ref, list->first_child))
{
MD_Node *root = MD_Deref(ref);
for(MD_EachNode(node, root->first_child))
{
TopLevel(node);
+4 -6
View File
@@ -58,19 +58,17 @@ static void PrintNode(MD_Node* node, FILE* file, int indent_count) {
int main(int argument_count, char **arguments)
{
// TODO(allen): use list system
// NOTE(pmh): Parse all the files passed in via command line.
MD_Node *first = MD_NilNode();
MD_Node *last = MD_NilNode();
MD_Node *list = MD_MakeList();
for(int i = 1; i < argument_count; i += 1)
{
MD_Node *root = MD_ParseWholeFile(MD_S8CString(arguments[i])).node;
MD_PushSibling(&first, &last, root);
MD_PushReference(list, root);
}
for(MD_EachNode(root, first))
for(MD_EachNode(ref, list->first_child))
{
MD_Node *root = MD_Deref(ref);
MD_String8 code_filename = MD_ChopExtension(MD_SkipFolder(root->string));
MD_String8 info_filename = MD_PushStringF("parsed_%.*s.txt", MD_StringExpand(code_filename));
printf("Parse Input -> Output: %.*s -> %.*s\n", MD_StringExpand(code_filename), MD_StringExpand(info_filename));
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"><meta name="author" content="Ryan Fleury">
<meta property="og:title" content="">
<meta name="twitter:title" content="">
<link rel="canonical" href="https://example.site">
<meta property="og:type" content="website">
<meta property="og:url" content="https://example.site">
<meta property="og:site_name" content="Example Site">
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@ryanjfleury">
<link rel="stylesheet" type="text/css" href="style.css">
<script src="site.js"></script>
<title>Example Site</title>
</head>
<body>
<div class="header">
<h1>Example Site</h1>
<a href="#">Test Link 1</a>
<a href="#">Test Link 2</a>
<a href="#">Test Link 3</a>
</div>
<div class="page_content">
</div>
<div class="footer">
<h4>Example Site Footer</h4>
<a href="#">Test Link 1</a>
<a href="#">Test Link 2</a>
<a href="#">Test Link 3</a>
</div>
</body>
</html>
@@ -55,11 +55,8 @@ int main(int argument_count, char **arguments)
site_info = ParseSiteInfo(site_info_file);
}
// TODO(allen): use list system
//~ NOTE(rjf): Parse pages.
MD_Node *first_root = MD_NilNode();
MD_Node *last_root = MD_NilNode();
MD_Node *root_list = MD_MakeList();
{
printf("Searching for site pages at \"%.*s\"...\n", MD_StringExpand(page_dir_path));
MD_FileInfo file_info = {0};
@@ -76,7 +73,8 @@ int main(int argument_count, char **arguments)
MD_String8 path = MD_PushStringF("%.*s/%.*s",
MD_StringExpand(folder),
MD_StringExpand(file_info.filename));
MD_PushSibling(&first_root, &last_root, MD_ParseWholeFile(path).node);
MD_Node *node = MD_ParseWholeFile(path).node;
MD_PushReference(root_list, node);
}
}
}
@@ -84,8 +82,9 @@ int main(int argument_count, char **arguments)
//~ NOTE(rjf): Generate index table.
MD_Map index_table = {0};
{
for(MD_EachNode(root, first_root))
for(MD_EachNode(ref, root_list->first_child))
{
MD_Node *root = MD_Deref(ref);
for(MD_EachNode(node, root->first_child))
{
if(!MD_NodeIsNil(node->first_child) && MD_StringMatch(node->string, MD_S8Lit("index"), MD_MatchFlag_CaseInsensitive))
@@ -123,8 +122,9 @@ int main(int argument_count, char **arguments)
}
//~ NOTE(rjf): Generate files for all roots.
for(MD_EachNode(root, first_root))
for(MD_EachNode(ref, root_list->first_child))
{
MD_Node *root = MD_Deref(ref);
PageInfo page_info = ParsePageInfo(root);
MD_String8 name_without_extension = MD_SkipFolder(MD_ChopExtension(root->string));
+4 -6
View File
@@ -179,21 +179,19 @@ int main(int argument_count, char **arguments)
//- rjf: parse command line
MD_CommandLine cmdln = MD_CommandLineFromOptions(MD_StringListFromArgCV(argument_count, arguments));
// TODO(allen): use list system
//- rjf: parse all input files
MD_Node *first_file = MD_NilNode();
MD_Node *last_file = MD_NilNode();
MD_Node *file_list = MD_MakeList();
for(MD_String8Node *n = cmdln.inputs.first; n; n = n->next)
{
MD_ParseResult parse = MD_ParseWholeFile(n->string);
MD_PushSibling(&first_file, &last_file, parse.node);
MD_PushReference(file_list, parse.node);
}
//- rjf: gather top-level symbol map
NamespaceNode global_ns_node = {0};
for(MD_EachNode(file, first_file))
for(MD_EachNode(file_ref, file_list->first_child))
{
MD_Node *file = MD_Deref(file_ref);
for(MD_EachNode(top_level, file->first_child))
{
if(MD_NodeHasTag(top_level, MD_S8Lit("proc")))
+8 -6
View File
@@ -26,8 +26,6 @@
// MD_b32 MD_IMPL_FileIterIncrement(MD_FileIter*, MD_String8, MD_FileInfo*) - optional
// void* MD_IMPL_Alloc(MD_u64) - required
//
// TODO(allen): Commentary about this system somewhere easy to discover when
// you go digging.
#ifndef MD_H
#define MD_H
@@ -183,9 +181,6 @@
# define MD_LANG_CPP 0
#endif
#define MD_FUNCTION
#define MD_GLOBAL static
#if MD_LANG_CPP
# define MD_ZERO_STRUCT {}
#else
@@ -200,6 +195,11 @@
# define MD_C_LINKAGE_END }
#endif
//~ Common defines
#define MD_FUNCTION
#define MD_GLOBAL static
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
@@ -222,7 +222,7 @@ typedef float MD_f32;
typedef double MD_f64;
//~ Basic UTF-8 string types.
//~ Basic Unicode string types.
typedef struct MD_String8 MD_String8;
struct MD_String8
@@ -740,6 +740,8 @@ MD_FUNCTION MD_Node *MD_MakeNode(MD_NodeKind kind, MD_String8 string,
MD_String8 whole_string, MD_u8 *at);
MD_FUNCTION void MD_PushChild(MD_Node *parent, MD_Node *new_child);
MD_FUNCTION void MD_PushTag(MD_Node *node, MD_Node *tag);
MD_FUNCTION MD_Node *MD_MakeList(void);
MD_FUNCTION MD_Node *MD_PushReference(MD_Node *list, MD_Node *target);
// TODO(allen): eliminate
+8
View File
@@ -2166,6 +2166,14 @@ MD_PushTag(MD_Node *node, MD_Node *tag)
}
}
MD_FUNCTION_IMPL MD_Node*
MD_MakeList(void)
{
MD_String8 empty = {0};
MD_Node *result = MD_MakeNode(MD_NodeKind_List, empty, empty, 0);
return(result);
}
MD_FUNCTION_IMPL MD_Node*
MD_PushReference(MD_Node *list, MD_Node *target)
{