mirror of
https://github.com/Ed94/metadesk.git
synced 2026-06-24 20:54:59 -07:00
Merge branch 'master' of https://github.com/Dion-Systems/metadesk
This commit is contained in:
@@ -18,7 +18,7 @@ static void OutputType_C_LHS_Namespace(FILE *file, MD_Map *user_defined_types, M
|
||||
case MD_ExprKind_Atom:
|
||||
{
|
||||
MD_Node *node = type->node;
|
||||
|
||||
|
||||
if(MD_StringMap_Lookup(user_defined_types, type->node->string))
|
||||
{
|
||||
fprintf(file, "%.*s", MD_StringExpand(prefix));
|
||||
@@ -75,10 +75,10 @@ static void OutputPrefixedType(FILE *f, MD_Map *user_defined_types, MD_String8 p
|
||||
{
|
||||
I(); fprintf(f, "typedef enum\n");
|
||||
I(); fprintf(f, "{\n");
|
||||
|
||||
|
||||
MD_String8 singular_flag_type_name = node->string;
|
||||
if(MD_StringMatch(MD_StringSuffix(singular_flag_type_name, 5), MD_S8Lit("Flags"),
|
||||
MD_StringMatchFlag_CaseInsensitive))
|
||||
MD_MatchFlag_CaseInsensitive))
|
||||
{
|
||||
singular_flag_type_name = MD_StringChop(singular_flag_type_name, 1);
|
||||
}
|
||||
@@ -94,7 +94,7 @@ static void OutputPrefixedType(FILE *f, MD_Map *user_defined_types, MD_String8 p
|
||||
else if(MD_NodeHasTag(node, MD_S8Lit("union")) || MD_NodeHasTag(node, MD_S8Lit("struct")))
|
||||
{
|
||||
MD_String8 aggregate_kind = MD_NodeHasTag(node, MD_S8Lit("union")) ? MD_S8Lit("union") : MD_S8Lit("struct");
|
||||
|
||||
|
||||
if(depth == 0)
|
||||
{
|
||||
fprintf(f, "typedef %.*s %.*s%.*s %.*s%.*s;\n",
|
||||
@@ -102,7 +102,7 @@ static void OutputPrefixedType(FILE *f, MD_Map *user_defined_types, MD_String8 p
|
||||
MD_StringExpand(prefix), MD_StringExpand(node->string),
|
||||
MD_StringExpand(prefix), MD_StringExpand(node->string));
|
||||
}
|
||||
|
||||
|
||||
if(depth == 0)
|
||||
{
|
||||
I(); fprintf(f, "%.*s %.*s%.*s\n", MD_StringExpand(aggregate_kind),
|
||||
@@ -112,7 +112,7 @@ static void OutputPrefixedType(FILE *f, MD_Map *user_defined_types, MD_String8 p
|
||||
{
|
||||
I(); fprintf(f, "%.*s\n", MD_StringExpand(aggregate_kind));
|
||||
}
|
||||
|
||||
|
||||
I(); fprintf(f, "{\n");
|
||||
for(MD_EachNode(member, node->first_child))
|
||||
{
|
||||
@@ -130,12 +130,12 @@ static void OutputPrefixedType(FILE *f, MD_Map *user_defined_types, MD_String8 p
|
||||
else
|
||||
{
|
||||
MD_Expr *type = MD_ParseAsType(node->first_child, node->last_child);
|
||||
|
||||
|
||||
I();
|
||||
OutputType_C_LHS_Namespace(f, user_defined_types, prefix, type);
|
||||
fprintf(f, " %.*s", MD_StringExpand(node->string));
|
||||
MD_OutputType_C_RHS(f, type);
|
||||
|
||||
|
||||
fprintf(f, ";\n");
|
||||
}
|
||||
#undef I
|
||||
@@ -144,12 +144,12 @@ static void OutputPrefixedType(FILE *f, MD_Map *user_defined_types, MD_String8 p
|
||||
static void AppendConversionCode(FILE *f, MD_Map *user_defined_types, MD_Node *new_element, MD_Node *old_element, MD_String8 member_path)
|
||||
{
|
||||
MD_Map new_element_map = MapFromChildren(new_element);
|
||||
|
||||
|
||||
if(MD_NodeHasTag(new_element, MD_S8Lit("struct")))
|
||||
{
|
||||
MD_String8 extended_member_path = MD_PushStringF("%.*s.%.*s", MD_StringExpand(member_path),
|
||||
MD_StringExpand(old_element->string));
|
||||
|
||||
|
||||
for(MD_EachNode(member, old_element->first_child))
|
||||
{
|
||||
MD_MapSlot *slot = MD_StringMap_Lookup(&new_element_map, member->string);
|
||||
@@ -168,11 +168,11 @@ static void AppendConversionCode(FILE *f, MD_Map *user_defined_types, MD_Node *n
|
||||
if(MD_ChildCountFromNode(new_element) == 1)
|
||||
{
|
||||
MD_String8 type_name = new_element->first_child->string;
|
||||
if(MD_NodeDeepMatch(new_element, old_element, 0, 0))
|
||||
if(MD_NodeDeepMatch(new_element, old_element, 0))
|
||||
{
|
||||
MD_String8 extended_member_path = MD_PushStringF("%.*s.%.*s", MD_StringExpand(member_path),
|
||||
MD_StringExpand(old_element->string));
|
||||
|
||||
|
||||
if(MD_StringMap_Lookup(user_defined_types, type_name))
|
||||
{
|
||||
fprintf(f, " result%.*s = %.*sFromV1(v%.*s);\n",
|
||||
@@ -210,7 +210,7 @@ int main(int argument_count, char **arguments)
|
||||
fprintf(stderr, "USAGE: %s spec_file_name.md out_file_name.c\n", arguments[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
MD_ParseResult spec = MD_ParseWholeFile(MD_S8CString(arguments[1]));
|
||||
if(spec.first_error)
|
||||
{
|
||||
@@ -220,16 +220,16 @@ int main(int argument_count, char **arguments)
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
FILE *f = fopen(arguments[2], "wb");
|
||||
if(f == 0)
|
||||
{
|
||||
fprintf(stderr, "Unable to open destination file \"%s\"\n", arguments[2]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
MD_Map ns_map = MapFromChildren(spec.namespaces);
|
||||
|
||||
|
||||
// NOTE(mal): Old types get "v1_" as a prefix
|
||||
fprintf(f, "// V1\n");
|
||||
MD_Node *v1 = MD_StringMap_Lookup(&ns_map, MD_S8Lit("v1"))->value;
|
||||
@@ -238,17 +238,17 @@ int main(int argument_count, char **arguments)
|
||||
{
|
||||
OutputPrefixedType(f, &v1_map, MD_S8Lit("v1_"), node, 0);
|
||||
}
|
||||
|
||||
|
||||
// NOTE(mal): New types don't get a prefix
|
||||
fprintf(f, "// V2\n");
|
||||
MD_Map empty_map = {0};
|
||||
|
||||
|
||||
MD_Node *v2 = MD_StringMap_Lookup(&ns_map, MD_S8Lit("v2"))->value;
|
||||
for(MD_EachNodeRef(node, v2->first_child))
|
||||
{
|
||||
OutputPrefixedType(f, &empty_map, MD_S8Lit(""), node, 0);
|
||||
}
|
||||
|
||||
|
||||
// NOTE(mal): Routines that map old into new
|
||||
fprintf(f, "// V1->V2\n");
|
||||
MD_Map v2_map = MapFromChildren(v2);
|
||||
@@ -257,15 +257,15 @@ int main(int argument_count, char **arguments)
|
||||
MD_MapSlot *slot = MD_StringMap_Lookup(&v2_map, node->string);
|
||||
MD_Node *v2_type = slot->value;
|
||||
MD_Map children_map = MapFromChildren(v2_type);
|
||||
|
||||
|
||||
fprintf(f, "static %.*s %.*sFromV1(v1_%.*s v)\n{\n",
|
||||
MD_StringExpand(node->string), MD_StringExpand(node->string), MD_StringExpand(node->string));
|
||||
|
||||
|
||||
if(MD_NodeHasTag(node, MD_S8Lit("enum")))
|
||||
{
|
||||
fprintf(f, " %.*s result = 0;\n", MD_StringExpand(node->string));
|
||||
fprintf(f, " switch(v)\n {\n");
|
||||
|
||||
|
||||
for(MD_EachNode(enumerand, node->first_child))
|
||||
{
|
||||
fprintf(f, " case v1_%.*s_%.*s: ",
|
||||
@@ -289,14 +289,14 @@ int main(int argument_count, char **arguments)
|
||||
else if(MD_NodeHasTag(node, MD_S8Lit("flags")))
|
||||
{
|
||||
fprintf(f, " %.*s result = 0;\n", MD_StringExpand(node->string));
|
||||
|
||||
|
||||
MD_String8 singular_flag_type_name = node->string;
|
||||
if(MD_StringMatch(MD_StringSuffix(singular_flag_type_name, 5), MD_S8Lit("Flags"),
|
||||
MD_StringMatchFlag_CaseInsensitive))
|
||||
MD_MatchFlag_CaseInsensitive))
|
||||
{
|
||||
singular_flag_type_name = MD_StringChop(singular_flag_type_name, 1);
|
||||
}
|
||||
|
||||
|
||||
for(MD_EachNode(flag, node->first_child))
|
||||
{
|
||||
fprintf(f, " if(v & v1_%.*s_%.*s) ",
|
||||
@@ -316,7 +316,7 @@ int main(int argument_count, char **arguments)
|
||||
else if(MD_NodeHasTag(node, MD_S8Lit("union")))
|
||||
{
|
||||
fprintf(f, " %.*s result = {0};\n", MD_StringExpand(node->string));
|
||||
|
||||
|
||||
MD_Node *authoritative_member = v2_type->first_child;
|
||||
for(MD_EachNode(member, v2_type->first_child))
|
||||
{
|
||||
@@ -326,7 +326,7 @@ int main(int argument_count, char **arguments)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MD_Map v1_children_map = MapFromChildren(node);
|
||||
MD_MapSlot *v1_member_slot = MD_StringMap_Lookup(&v1_children_map, authoritative_member->string);
|
||||
if(v1_member_slot)
|
||||
@@ -364,7 +364,7 @@ int main(int argument_count, char **arguments)
|
||||
fprintf(f, "}\n\n");
|
||||
fflush(f);
|
||||
}
|
||||
|
||||
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -26,18 +26,15 @@
|
||||
<div class="page_content">
|
||||
<div class="standalone_link_container"><a class="link" href="blog_main.html">← Back</a></div><h1 class="title">Test Blog #1</h1><h2 class="subtitle">This is my test blog.</h2><h3 class="date">30 November 2020</h3><h2 class="subtitle">Section 1</h2>
|
||||
<p class="paragraph">
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse ut ornare neque, vitae finibus leo. Praesent pulvinar, urna id lobortis iaculis, velit turpis luctus tortor, quis malesuada neque neque vitae turpis. Phasellus id molestie elit. Sed elementum ipsum a ligula semper, at varius augue rutrum. Pellentesque fringilla, orci nec fringilla finibus, turpis lacus vehicula elit, nec bibendum magna est quis massa. Aliquam efficitur facilisis nibh, ut sodales sapien scelerisque nec. Integer justo sem, pellentesque et ante imperdiet, interdum placerat sem.
|
||||
|
||||
Nunc hendrerit lobortis commodo. Morbi felis quam, fermentum vitae libero vitae, fermentum sodales quam. Nulla bibendum tellus quis lorem sollicitudin pretium. Etiam commodo ex eget aliquet porta. In sit amet dui eleifend, mattis sem nec, tristique erat. Morbi malesuada fringilla bibendum. Integer odio ex, cursus a sodales quis, vehicula non dolor.
|
||||
|
||||
Praesent vitae pharetra felis. Curabitur non ex non nunc pretium feugiat eu sit amet turpis. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aenean blandit ante leo. Vivamus iaculis mi vel sem tincidunt maximus. Aenean elementum ipsum non laoreet semper. Morbi non felis interdum lectus pulvinar mollis id non purus. Nullam eu ipsum ut turpis aliquam feugiat at non tellus. Suspendisse ornare erat quis enim ullamcorper, at rhoncus nulla suscipit.
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse ut ornare neque, vitae finibus leo. Praesent pulvinar, urna id lobortis iaculis, velit turpis luctus tortor, quis malesuada neque neque vitae turpis. Phasellus id molestie elit. Sed elementum ipsum a ligula semper, at varius augue rutrum. Pellentesque fringilla, orci nec fringilla finibus, turpis lacus vehicula elit, nec bibendum magna est quis massa. Aliquam efficitur facilisis nibh, ut sodales sapien scelerisque nec. Integer justo sem, pellentesque et ante imperdiet, interdum placerat sem.</p>
|
||||
<p class="paragraph">Nunc hendrerit lobortis commodo. Morbi felis quam, fermentum vitae libero vitae, fermentum sodales quam. Nulla bibendum tellus quis lorem sollicitudin pretium. Etiam commodo ex eget aliquet porta. In sit amet dui eleifend, mattis sem nec, tristique erat. Morbi malesuada fringilla bibendum. Integer odio ex, cursus a sodales quis, vehicula non dolor.</p>
|
||||
<p class="paragraph">Praesent vitae pharetra felis. Curabitur non ex non nunc pretium feugiat eu sit amet turpis. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aenean blandit ante leo. Vivamus iaculis mi vel sem tincidunt maximus. Aenean elementum ipsum non laoreet semper. Morbi non felis interdum lectus pulvinar mollis id non purus. Nullam eu ipsum ut turpis aliquam feugiat at non tellus. Suspendisse ornare erat quis enim ullamcorper, at rhoncus nulla suscipit.
|
||||
</p>
|
||||
<div class="img_container"><img class="img" src="test.png"></img></div>
|
||||
<h2 class="subtitle">Section 2</h2>
|
||||
<p class="paragraph">
|
||||
Aliquam quis diam at sem interdum imperdiet. Nunc imperdiet ligula tempus nibh semper mattis. Suspendisse fringilla molestie semper. Sed felis dolor, vehicula et tempus sed, porttitor finibus lacus. Pellentesque egestas ex finibus, facilisis tellus suscipit, accumsan turpis. Ut imperdiet vitae nisl eget vestibulum. Donec eu bibendum erat, id maximus magna. Vivamus quis rhoncus justo. Morbi eget commodo lorem, vulputate varius ipsum. Interdum et malesuada fames ac ante ipsum primis in faucibus. Integer accumsan, sem vel rutrum cursus, odio enim sodales leo, sit amet rutrum odio purus at nisi. Fusce iaculis ante id nunc volutpat tincidunt. Duis nec tincidunt ipsum. Fusce vitae odio ac velit sollicitudin maximus. Vestibulum ante dui, varius auctor ante eu, gravida laoreet justo.
|
||||
|
||||
Vivamus dignissim mauris nec turpis convallis, vitae pellentesque sapien faucibus. Phasellus eu euismod elit, sit amet vehicula diam. Curabitur sit amet leo magna. In est erat, congue vel euismod id, venenatis vitae mauris. Vestibulum sit amet leo eget leo ornare feugiat. Interdum et malesuada fames ac ante ipsum primis in faucibus. Vivamus at efficitur ex, a mattis lorem. Maecenas blandit tincidunt tortor vel cursus. In in purus a nisi pretium venenatis in ut lacus. Maecenas venenatis rutrum laoreet. Donec aliquam leo vel risus cursus, placerat pretium lacus fringilla. Suspendisse ut porttitor mauris.
|
||||
Aliquam quis diam at sem interdum imperdiet. Nunc imperdiet ligula tempus nibh semper mattis. Suspendisse fringilla molestie semper. Sed felis dolor, vehicula et tempus sed, porttitor finibus lacus. Pellentesque egestas ex finibus, facilisis tellus suscipit, accumsan turpis. Ut imperdiet vitae nisl eget vestibulum. Donec eu bibendum erat, id maximus magna. Vivamus quis rhoncus justo. Morbi eget commodo lorem, vulputate varius ipsum. Interdum et malesuada fames ac ante ipsum primis in faucibus. Integer accumsan, sem vel rutrum cursus, odio enim sodales leo, sit amet rutrum odio purus at nisi. Fusce iaculis ante id nunc volutpat tincidunt. Duis nec tincidunt ipsum. Fusce vitae odio ac velit sollicitudin maximus. Vestibulum ante dui, varius auctor ante eu, gravida laoreet justo.</p>
|
||||
<p class="paragraph">Vivamus dignissim mauris nec turpis convallis, vitae pellentesque sapien faucibus. Phasellus eu euismod elit, sit amet vehicula diam. Curabitur sit amet leo magna. In est erat, congue vel euismod id, venenatis vitae mauris. Vestibulum sit amet leo eget leo ornare feugiat. Interdum et malesuada fames ac ante ipsum primis in faucibus. Vivamus at efficitur ex, a mattis lorem. Maecenas blandit tincidunt tortor vel cursus. In in purus a nisi pretium venenatis in ut lacus. Maecenas venenatis rutrum laoreet. Donec aliquam leo vel risus cursus, placerat pretium lacus fringilla. Suspendisse ut porttitor mauris.
|
||||
</p>
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/BjdY1eXB6cY" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
|
||||
<h2 class="subtitle">Section 3</h2>
|
||||
|
||||
@@ -26,11 +26,9 @@
|
||||
<div class="page_content">
|
||||
<div class="standalone_link_container"><a class="link" href="blog_main.html">← Back</a></div><h1 class="title">Hello, Again!</h1><h2 class="subtitle">This is another test blog.</h2><h3 class="date">28 November 2020</h3><h2 class="subtitle">Section 1</h2>
|
||||
<p class="paragraph">
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse ut ornare neque, vitae finibus leo. Praesent pulvinar, urna id lobortis iaculis, velit turpis luctus tortor, quis malesuada neque neque vitae turpis. Phasellus id molestie elit. Sed elementum ipsum a ligula semper, at varius augue rutrum. Pellentesque fringilla, orci nec fringilla finibus, turpis lacus vehicula elit, nec bibendum magna est quis massa. Aliquam efficitur facilisis nibh, ut sodales sapien scelerisque nec. Integer justo sem, pellentesque et ante imperdiet, interdum placerat sem.
|
||||
|
||||
Nunc hendrerit lobortis commodo. Morbi felis quam, fermentum vitae libero vitae, fermentum sodales quam. Nulla bibendum tellus quis lorem sollicitudin pretium. Etiam commodo ex eget aliquet porta. In sit amet dui eleifend, mattis sem nec, tristique erat. Morbi malesuada fringilla bibendum. Integer odio ex, cursus a sodales quis, vehicula non dolor.
|
||||
|
||||
Praesent vitae pharetra felis. Curabitur non ex non nunc pretium feugiat eu sit amet turpis. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aenean blandit ante leo. Vivamus iaculis mi vel sem tincidunt maximus. Aenean elementum ipsum non laoreet semper. Morbi non felis interdum lectus pulvinar mollis id non purus. Nullam eu ipsum ut turpis aliquam feugiat at non tellus. Suspendisse ornare erat quis enim ullamcorper, at rhoncus nulla suscipit.
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse ut ornare neque, vitae finibus leo. Praesent pulvinar, urna id lobortis iaculis, velit turpis luctus tortor, quis malesuada neque neque vitae turpis. Phasellus id molestie elit. Sed elementum ipsum a ligula semper, at varius augue rutrum. Pellentesque fringilla, orci nec fringilla finibus, turpis lacus vehicula elit, nec bibendum magna est quis massa. Aliquam efficitur facilisis nibh, ut sodales sapien scelerisque nec. Integer justo sem, pellentesque et ante imperdiet, interdum placerat sem.</p>
|
||||
<p class="paragraph">Nunc hendrerit lobortis commodo. Morbi felis quam, fermentum vitae libero vitae, fermentum sodales quam. Nulla bibendum tellus quis lorem sollicitudin pretium. Etiam commodo ex eget aliquet porta. In sit amet dui eleifend, mattis sem nec, tristique erat. Morbi malesuada fringilla bibendum. Integer odio ex, cursus a sodales quis, vehicula non dolor.</p>
|
||||
<p class="paragraph">Praesent vitae pharetra felis. Curabitur non ex non nunc pretium feugiat eu sit amet turpis. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aenean blandit ante leo. Vivamus iaculis mi vel sem tincidunt maximus. Aenean elementum ipsum non laoreet semper. Morbi non felis interdum lectus pulvinar mollis id non purus. Nullam eu ipsum ut turpis aliquam feugiat at non tellus. Suspendisse ornare erat quis enim ullamcorper, at rhoncus nulla suscipit.
|
||||
</p>
|
||||
<div class="img_container"><img class="img" src="test.png"></img></div>
|
||||
</div>
|
||||
|
||||
@@ -63,11 +63,11 @@ int main(int argument_count, char **arguments)
|
||||
MD_FileInfo file_info = {0};
|
||||
for(MD_FileIter it = {0}; MD_FileIterIncrement(&it, page_dir_path, &file_info);)
|
||||
{
|
||||
if(MD_StringMatch(MD_ExtensionFromPath(file_info.filename), MD_S8Lit("md"), MD_StringMatchFlag_CaseInsensitive) &&
|
||||
if(MD_StringMatch(MD_ExtensionFromPath(file_info.filename), MD_S8Lit("md"), MD_MatchFlag_CaseInsensitive) &&
|
||||
!MD_StringMatch(MD_SkipFolder(MD_ChopExtension(file_info.filename)),
|
||||
MD_SkipFolder(MD_ChopExtension(site_info_path)),
|
||||
MD_StringMatchFlag_CaseInsensitive |
|
||||
MD_StringMatchFlag_SlashInsensitive))
|
||||
MD_MatchFlag_CaseInsensitive |
|
||||
MD_MatchFlag_SlashInsensitive))
|
||||
{
|
||||
printf("Processing site page at \"%.*s\"...\n", MD_StringExpand(file_info.filename));
|
||||
MD_String8 folder = MD_FolderFromPath(page_dir_path);
|
||||
@@ -86,7 +86,7 @@ int main(int argument_count, char **arguments)
|
||||
{
|
||||
for(MD_EachNode(node, root->first_child))
|
||||
{
|
||||
if(!MD_NodeIsNil(node->first_child) && MD_StringMatch(node->string, MD_S8Lit("index"), MD_StringMatchFlag_CaseInsensitive))
|
||||
if(!MD_NodeIsNil(node->first_child) && MD_StringMatch(node->string, MD_S8Lit("index"), MD_MatchFlag_CaseInsensitive))
|
||||
{
|
||||
for(MD_EachNode(index_string, node->first_child))
|
||||
{
|
||||
@@ -252,23 +252,23 @@ ParsePageInfo(MD_Node *page)
|
||||
{
|
||||
if(!MD_NodeIsNil(node->first_child))
|
||||
{
|
||||
if(MD_StringMatch(node->string, MD_S8Lit("title"), MD_StringMatchFlag_CaseInsensitive))
|
||||
if(MD_StringMatch(node->string, MD_S8Lit("title"), MD_MatchFlag_CaseInsensitive))
|
||||
{
|
||||
info.title = node->first_child;
|
||||
}
|
||||
else if(MD_StringMatch(node->string, MD_S8Lit("desc"), MD_StringMatchFlag_CaseInsensitive))
|
||||
else if(MD_StringMatch(node->string, MD_S8Lit("desc"), MD_MatchFlag_CaseInsensitive))
|
||||
{
|
||||
info.desc = node->first_child;
|
||||
}
|
||||
else if(MD_StringMatch(node->string, MD_S8Lit("date"), MD_StringMatchFlag_CaseInsensitive))
|
||||
else if(MD_StringMatch(node->string, MD_S8Lit("date"), MD_MatchFlag_CaseInsensitive))
|
||||
{
|
||||
info.date = node;
|
||||
}
|
||||
else if(MD_StringMatch(node->string, MD_S8Lit("parent"), MD_StringMatchFlag_CaseInsensitive))
|
||||
else if(MD_StringMatch(node->string, MD_S8Lit("parent"), MD_MatchFlag_CaseInsensitive))
|
||||
{
|
||||
info.parent = node->first_child;
|
||||
}
|
||||
else if(MD_StringMatch(node->string, MD_S8Lit("header_image"), MD_StringMatchFlag_CaseInsensitive))
|
||||
else if(MD_StringMatch(node->string, MD_S8Lit("header_image"), MD_MatchFlag_CaseInsensitive))
|
||||
{
|
||||
info.header_image = node->first_child;
|
||||
}
|
||||
@@ -285,39 +285,39 @@ ParseSiteInfo(MD_Node *site)
|
||||
{
|
||||
if(!MD_NodeIsNil(node->first_child))
|
||||
{
|
||||
if(MD_StringMatch(node->string, MD_S8Lit("title"), MD_StringMatchFlag_CaseInsensitive))
|
||||
if(MD_StringMatch(node->string, MD_S8Lit("title"), MD_MatchFlag_CaseInsensitive))
|
||||
{
|
||||
info.title = node->first_child;
|
||||
}
|
||||
else if(MD_StringMatch(node->string, MD_S8Lit("desc"), MD_StringMatchFlag_CaseInsensitive))
|
||||
else if(MD_StringMatch(node->string, MD_S8Lit("desc"), MD_MatchFlag_CaseInsensitive))
|
||||
{
|
||||
info.desc = node->first_child;
|
||||
}
|
||||
else if(MD_StringMatch(node->string, MD_S8Lit("canonical_url"), MD_StringMatchFlag_CaseInsensitive))
|
||||
else if(MD_StringMatch(node->string, MD_S8Lit("canonical_url"), MD_MatchFlag_CaseInsensitive))
|
||||
{
|
||||
info.canonical_url = node->first_child;
|
||||
}
|
||||
else if(MD_StringMatch(node->string, MD_S8Lit("author"), MD_StringMatchFlag_CaseInsensitive))
|
||||
else if(MD_StringMatch(node->string, MD_S8Lit("author"), MD_MatchFlag_CaseInsensitive))
|
||||
{
|
||||
info.author = node->first_child;
|
||||
}
|
||||
else if(MD_StringMatch(node->string, MD_S8Lit("twitter_handle"), MD_StringMatchFlag_CaseInsensitive))
|
||||
else if(MD_StringMatch(node->string, MD_S8Lit("twitter_handle"), MD_MatchFlag_CaseInsensitive))
|
||||
{
|
||||
info.twitter_handle = node->first_child;
|
||||
}
|
||||
else if(MD_StringMatch(node->string, MD_S8Lit("link_dictionary"), MD_StringMatchFlag_CaseInsensitive))
|
||||
else if(MD_StringMatch(node->string, MD_S8Lit("link_dictionary"), MD_MatchFlag_CaseInsensitive))
|
||||
{
|
||||
info.link_dictionary = node;
|
||||
}
|
||||
else if(MD_StringMatch(node->string, MD_S8Lit("header"), MD_StringMatchFlag_CaseInsensitive))
|
||||
else if(MD_StringMatch(node->string, MD_S8Lit("header"), MD_MatchFlag_CaseInsensitive))
|
||||
{
|
||||
info.header = node->first_child;
|
||||
}
|
||||
else if(MD_StringMatch(node->string, MD_S8Lit("footer"), MD_StringMatchFlag_CaseInsensitive))
|
||||
else if(MD_StringMatch(node->string, MD_S8Lit("footer"), MD_MatchFlag_CaseInsensitive))
|
||||
{
|
||||
info.footer = node->first_child;
|
||||
}
|
||||
else if(MD_StringMatch(node->string, MD_S8Lit("style"), MD_StringMatchFlag_CaseInsensitive))
|
||||
else if(MD_StringMatch(node->string, MD_S8Lit("style"), MD_MatchFlag_CaseInsensitive))
|
||||
{
|
||||
info.style = node->first_child;
|
||||
}
|
||||
|
||||
+14
-19
@@ -266,13 +266,15 @@ struct MD_String8List
|
||||
MD_String8Node *last;
|
||||
};
|
||||
|
||||
typedef MD_u32 MD_StringMatchFlags;
|
||||
typedef MD_u32 MD_MatchFlags;
|
||||
enum
|
||||
{
|
||||
MD_StringMatchFlag_CaseInsensitive = (1<<0),
|
||||
MD_StringMatchFlag_RightSideSloppy = (1<<1),
|
||||
MD_StringMatchFlag_FindLast = (1<<2),
|
||||
MD_StringMatchFlag_SlashInsensitive = (1<<3),
|
||||
MD_MatchFlag_CaseInsensitive = (1<<0),
|
||||
MD_MatchFlag_RightSideSloppy = (1<<1),
|
||||
MD_MatchFlag_FindLast = (1<<2),
|
||||
MD_MatchFlag_SlashInsensitive = (1<<3),
|
||||
MD_MatchFlag_Tags = (1<<4),
|
||||
MD_MatchFlag_TagArguments = (1<<5),
|
||||
};
|
||||
|
||||
typedef struct MD_UnicodeConsume MD_UnicodeConsume;
|
||||
@@ -328,13 +330,6 @@ enum
|
||||
MD_NodeFlag_CharLiteral = (1<<13),
|
||||
};
|
||||
|
||||
typedef MD_u32 MD_NodeMatchFlags;
|
||||
enum
|
||||
{
|
||||
MD_NodeMatchFlag_Tags = (1<<0),
|
||||
MD_NodeMatchFlag_TagArguments = (1<<1),
|
||||
};
|
||||
|
||||
typedef struct MD_Node MD_Node;
|
||||
struct MD_Node
|
||||
{
|
||||
@@ -653,9 +648,9 @@ MD_FUNCTION MD_String8 MD_StringChop(MD_String8 str, MD_u64 nmax);
|
||||
MD_FUNCTION MD_String8 MD_StringPrefix(MD_String8 str, MD_u64 size);
|
||||
MD_FUNCTION MD_String8 MD_StringSuffix(MD_String8 str, MD_u64 size);
|
||||
|
||||
MD_FUNCTION MD_b32 MD_StringMatch(MD_String8 a, MD_String8 b, MD_StringMatchFlags flags);
|
||||
MD_FUNCTION MD_b32 MD_StringMatch(MD_String8 a, MD_String8 b, MD_MatchFlags flags);
|
||||
MD_FUNCTION MD_u64 MD_FindSubstring(MD_String8 str, MD_String8 substring,
|
||||
MD_u64 start_pos, MD_StringMatchFlags flags);
|
||||
MD_u64 start_pos, MD_MatchFlags flags);
|
||||
|
||||
MD_FUNCTION MD_String8 MD_ChopExtension(MD_String8 string);
|
||||
MD_FUNCTION MD_String8 MD_SkipFolder(MD_String8 string);
|
||||
@@ -713,7 +708,7 @@ MD_FUNCTION void MD_Parse_Bump(MD_ParseCtx *ctx, MD_Token token);
|
||||
MD_FUNCTION void MD_Parse_BumpNext(MD_ParseCtx *ctx);
|
||||
MD_FUNCTION MD_Token MD_Parse_LexNext(MD_ParseCtx *ctx);
|
||||
MD_FUNCTION MD_Token MD_Parse_PeekSkipSome(MD_ParseCtx *ctx, MD_TokenGroups skip_groups);
|
||||
MD_FUNCTION MD_b32 MD_Parse_TokenMatch(MD_Token token, MD_String8 string, MD_StringMatchFlags flags);
|
||||
MD_FUNCTION MD_b32 MD_Parse_TokenMatch(MD_Token token, MD_String8 string, MD_MatchFlags flags);
|
||||
MD_FUNCTION MD_b32 MD_Parse_Require(MD_ParseCtx *ctx, MD_String8 string, MD_TokenKind kind);
|
||||
MD_FUNCTION MD_b32 MD_Parse_RequireKind(MD_ParseCtx *ctx, MD_TokenKind kind, MD_Token *out_token);
|
||||
MD_FUNCTION MD_ParseResult MD_ParseOneNode (MD_String8 filename, MD_String8 contents);
|
||||
@@ -759,8 +754,8 @@ MD_FUNCTION void MD_NodeMessage(MD_Node *node, MD_MessageKind kind, MD_String8 s
|
||||
MD_FUNCTION void MD_NodeMessageF(MD_Node *node, MD_MessageKind kind, char *fmt, ...);
|
||||
|
||||
//~ Tree Comparison/Verification
|
||||
MD_FUNCTION MD_b32 MD_NodeMatch(MD_Node *a, MD_Node *b, MD_StringMatchFlags str_flags, MD_NodeMatchFlags node_flags);
|
||||
MD_FUNCTION MD_b32 MD_NodeDeepMatch(MD_Node *a, MD_Node *b, MD_StringMatchFlags str_flags, MD_NodeMatchFlags node_flags);
|
||||
MD_FUNCTION MD_b32 MD_NodeMatch(MD_Node *a, MD_Node *b, MD_MatchFlags flags);
|
||||
MD_FUNCTION MD_b32 MD_NodeDeepMatch(MD_Node *a, MD_Node *b, MD_MatchFlags node_flags);
|
||||
|
||||
//~ Expression and Type-Expression Helper
|
||||
MD_FUNCTION MD_Expr * MD_NilExpr(void);
|
||||
@@ -773,8 +768,8 @@ MD_FUNCTION MD_Expr * MD_ParseAsExpr(MD_Node *first, MD_Node *last);
|
||||
MD_FUNCTION MD_Expr * MD_ParseAsType(MD_Node *first, MD_Node *last);
|
||||
MD_FUNCTION MD_i64 MD_EvaluateExpr_I64(MD_Expr *expr);
|
||||
MD_FUNCTION MD_f64 MD_EvaluateExpr_F64(MD_Expr *expr);
|
||||
MD_FUNCTION MD_b32 MD_ExprMatch(MD_Expr *a, MD_Expr *b, MD_StringMatchFlags str_flags);
|
||||
MD_FUNCTION MD_b32 MD_ExprDeepMatch(MD_Expr *a, MD_Expr *b, MD_StringMatchFlags str_flags);
|
||||
MD_FUNCTION MD_b32 MD_ExprMatch(MD_Expr *a, MD_Expr *b, MD_MatchFlags flags);
|
||||
MD_FUNCTION MD_b32 MD_ExprDeepMatch(MD_Expr *a, MD_Expr *b, MD_MatchFlags flags);
|
||||
|
||||
//~ Generation
|
||||
MD_FUNCTION void MD_OutputTree(FILE *file, MD_Node *node);
|
||||
|
||||
+30
-30
@@ -200,20 +200,20 @@ MD_StringSuffix(MD_String8 str, MD_u64 size)
|
||||
}
|
||||
|
||||
MD_FUNCTION_IMPL MD_b32
|
||||
MD_StringMatch(MD_String8 a, MD_String8 b, MD_StringMatchFlags flags)
|
||||
MD_StringMatch(MD_String8 a, MD_String8 b, MD_MatchFlags flags)
|
||||
{
|
||||
int result = 0;
|
||||
if(a.size == b.size || flags & MD_StringMatchFlag_RightSideSloppy)
|
||||
if(a.size == b.size || flags & MD_MatchFlag_RightSideSloppy)
|
||||
{
|
||||
result = 1;
|
||||
for(MD_u64 i = 0; i < a.size; i += 1)
|
||||
{
|
||||
MD_b32 match = (a.str[i] == b.str[i]);
|
||||
if(flags & MD_StringMatchFlag_CaseInsensitive)
|
||||
if(flags & MD_MatchFlag_CaseInsensitive)
|
||||
{
|
||||
match |= (MD_CharToLower(a.str[i]) == MD_CharToLower(b.str[i]));
|
||||
}
|
||||
if(flags & MD_StringMatchFlag_SlashInsensitive)
|
||||
if(flags & MD_MatchFlag_SlashInsensitive)
|
||||
{
|
||||
match |= (MD_CorrectSlash(a.str[i]) == MD_CorrectSlash(b.str[i]));
|
||||
}
|
||||
@@ -228,7 +228,7 @@ MD_StringMatch(MD_String8 a, MD_String8 b, MD_StringMatchFlags flags)
|
||||
}
|
||||
|
||||
MD_FUNCTION_IMPL MD_u64
|
||||
MD_FindSubstring(MD_String8 str, MD_String8 substring, MD_u64 start_pos, MD_StringMatchFlags flags)
|
||||
MD_FindSubstring(MD_String8 str, MD_String8 substring, MD_u64 start_pos, MD_MatchFlags flags)
|
||||
{
|
||||
MD_b32 found = 0;
|
||||
MD_u64 found_idx = str.size;
|
||||
@@ -241,7 +241,7 @@ MD_FindSubstring(MD_String8 str, MD_String8 substring, MD_u64 start_pos, MD_Stri
|
||||
{
|
||||
found_idx = i;
|
||||
found = 1;
|
||||
if(!(flags & MD_StringMatchFlag_FindLast))
|
||||
if(!(flags & MD_MatchFlag_FindLast))
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -254,7 +254,7 @@ MD_FindSubstring(MD_String8 str, MD_String8 substring, MD_u64 start_pos, MD_Stri
|
||||
MD_FUNCTION_IMPL MD_String8
|
||||
MD_ChopExtension(MD_String8 string)
|
||||
{
|
||||
MD_u64 period_pos = MD_FindSubstring(string, MD_S8Lit("."), 0, MD_StringMatchFlag_FindLast);
|
||||
MD_u64 period_pos = MD_FindSubstring(string, MD_S8Lit("."), 0, MD_MatchFlag_FindLast);
|
||||
if(period_pos < string.size)
|
||||
{
|
||||
string.size = period_pos;
|
||||
@@ -266,8 +266,8 @@ MD_FUNCTION_IMPL MD_String8
|
||||
MD_SkipFolder(MD_String8 string)
|
||||
{
|
||||
MD_u64 slash_pos = MD_FindSubstring(string, MD_S8Lit("/"), 0,
|
||||
MD_StringMatchFlag_SlashInsensitive|
|
||||
MD_StringMatchFlag_FindLast);
|
||||
MD_MatchFlag_SlashInsensitive|
|
||||
MD_MatchFlag_FindLast);
|
||||
if(slash_pos < string.size)
|
||||
{
|
||||
string.str += slash_pos+1;
|
||||
@@ -279,7 +279,7 @@ MD_SkipFolder(MD_String8 string)
|
||||
MD_FUNCTION_IMPL MD_String8
|
||||
MD_ExtensionFromPath(MD_String8 string)
|
||||
{
|
||||
MD_u64 period_pos = MD_FindSubstring(string, MD_S8Lit("."), 0, MD_StringMatchFlag_FindLast);
|
||||
MD_u64 period_pos = MD_FindSubstring(string, MD_S8Lit("."), 0, MD_MatchFlag_FindLast);
|
||||
if(period_pos < string.size)
|
||||
{
|
||||
string.str += period_pos+1;
|
||||
@@ -292,8 +292,8 @@ MD_FUNCTION_IMPL MD_String8
|
||||
MD_FolderFromPath(MD_String8 string)
|
||||
{
|
||||
MD_u64 slash_pos = MD_FindSubstring(string, MD_S8Lit("/"), 0,
|
||||
MD_StringMatchFlag_SlashInsensitive|
|
||||
MD_StringMatchFlag_FindLast);
|
||||
MD_MatchFlag_SlashInsensitive|
|
||||
MD_MatchFlag_FindLast);
|
||||
if(slash_pos < string.size)
|
||||
{
|
||||
string.size = slash_pos;
|
||||
@@ -1452,7 +1452,7 @@ MD_Parse_PeekSkipSome(MD_ParseCtx *ctx, MD_TokenGroups skip_groups)
|
||||
}
|
||||
|
||||
MD_FUNCTION_IMPL MD_b32
|
||||
MD_Parse_TokenMatch(MD_Token token, MD_String8 string, MD_StringMatchFlags flags)
|
||||
MD_Parse_TokenMatch(MD_Token token, MD_String8 string, MD_MatchFlags flags)
|
||||
{
|
||||
return MD_StringMatch(token.string, string, flags);
|
||||
}
|
||||
@@ -2212,27 +2212,27 @@ MD_PushTag(MD_Node *node, MD_Node *tag)
|
||||
}
|
||||
|
||||
MD_FUNCTION_IMPL MD_b32
|
||||
MD_NodeMatch(MD_Node *a, MD_Node *b, MD_StringMatchFlags str_flags, MD_NodeMatchFlags match_flags)
|
||||
MD_NodeMatch(MD_Node *a, MD_Node *b, MD_MatchFlags flags)
|
||||
{
|
||||
MD_b32 result = 0;
|
||||
if(a->kind == b->kind && MD_StringMatch(a->string, b->string, str_flags))
|
||||
if(a->kind == b->kind && MD_StringMatch(a->string, b->string, flags))
|
||||
{
|
||||
result = 1;
|
||||
if(a->kind != MD_NodeKind_Tag && (match_flags & MD_NodeMatchFlag_Tags))
|
||||
if(a->kind != MD_NodeKind_Tag && (flags & MD_MatchFlag_Tags))
|
||||
{
|
||||
for(MD_Node *a_tag = a->first_tag, *b_tag = b->first_tag;
|
||||
!MD_NodeIsNil(a_tag) || !MD_NodeIsNil(b_tag);
|
||||
a_tag = a_tag->next, b_tag = b_tag->next)
|
||||
{
|
||||
if(MD_NodeMatch(a_tag, b_tag, str_flags, 0))
|
||||
if(MD_NodeMatch(a_tag, b_tag, flags))
|
||||
{
|
||||
if(match_flags & MD_NodeMatchFlag_TagArguments)
|
||||
if(flags & MD_MatchFlag_TagArguments)
|
||||
{
|
||||
for(MD_Node *a_tag_arg = a_tag->first_child, *b_tag_arg = b_tag->first_child;
|
||||
!MD_NodeIsNil(a_tag_arg) || !MD_NodeIsNil(b_tag_arg);
|
||||
a_tag_arg = a_tag_arg->next, b_tag_arg = b_tag_arg->next)
|
||||
{
|
||||
if(!MD_NodeDeepMatch(a_tag_arg, b_tag_arg, str_flags, match_flags))
|
||||
if(!MD_NodeDeepMatch(a_tag_arg, b_tag_arg, flags))
|
||||
{
|
||||
result = 0;
|
||||
goto end;
|
||||
@@ -2253,16 +2253,16 @@ MD_NodeMatch(MD_Node *a, MD_Node *b, MD_StringMatchFlags str_flags, MD_NodeMatch
|
||||
}
|
||||
|
||||
MD_FUNCTION_IMPL MD_b32
|
||||
MD_NodeDeepMatch(MD_Node *a, MD_Node *b, MD_StringMatchFlags str_flags, MD_NodeMatchFlags match_flags)
|
||||
MD_NodeDeepMatch(MD_Node *a, MD_Node *b, MD_MatchFlags flags)
|
||||
{
|
||||
MD_b32 result = MD_NodeMatch(a, b, str_flags, match_flags);
|
||||
MD_b32 result = MD_NodeMatch(a, b, flags);
|
||||
if(result)
|
||||
{
|
||||
for(MD_Node *a_child = a->first_child, *b_child = b->first_child;
|
||||
!MD_NodeIsNil(a_child) || !MD_NodeIsNil(b_child);
|
||||
a_child = a_child->next, b_child = b_child->next)
|
||||
{
|
||||
if(!MD_NodeDeepMatch(a_child, b_child, str_flags, match_flags))
|
||||
if(!MD_NodeDeepMatch(a_child, b_child, flags))
|
||||
{
|
||||
result = 0;
|
||||
goto end;
|
||||
@@ -2396,7 +2396,7 @@ MD_TagCountFromNode(MD_Node *node)
|
||||
}
|
||||
|
||||
MD_FUNCTION_IMPL MD_i64
|
||||
MD_ChildCountFromNodeAndString(MD_Node *node, MD_String8 string, MD_StringMatchFlags flags)
|
||||
MD_ChildCountFromNodeAndString(MD_Node *node, MD_String8 string, MD_MatchFlags flags)
|
||||
{
|
||||
MD_i64 result = 0;
|
||||
for(MD_EachNode(child, node->first_child))
|
||||
@@ -2410,7 +2410,7 @@ MD_ChildCountFromNodeAndString(MD_Node *node, MD_String8 string, MD_StringMatchF
|
||||
}
|
||||
|
||||
MD_FUNCTION_IMPL MD_i64
|
||||
MD_TagCountFromNodeAndString(MD_Node *node, MD_String8 string, MD_StringMatchFlags flags)
|
||||
MD_TagCountFromNodeAndString(MD_Node *node, MD_String8 string, MD_MatchFlags flags)
|
||||
{
|
||||
MD_i64 result = 0;
|
||||
for(MD_EachNode(tag, node->first_tag))
|
||||
@@ -2941,7 +2941,7 @@ MD_EvaluateExpr_F64(MD_Expr *expr)
|
||||
}
|
||||
|
||||
MD_FUNCTION_IMPL MD_b32
|
||||
MD_ExprMatch(MD_Expr *a, MD_Expr *b, MD_StringMatchFlags str_flags)
|
||||
MD_ExprMatch(MD_Expr *a, MD_Expr *b, MD_MatchFlags flags)
|
||||
{
|
||||
MD_b32 result = 0;
|
||||
if(a->kind == b->kind)
|
||||
@@ -2949,20 +2949,20 @@ MD_ExprMatch(MD_Expr *a, MD_Expr *b, MD_StringMatchFlags str_flags)
|
||||
result = 1;
|
||||
if(a->kind == MD_ExprKind_Atom)
|
||||
{
|
||||
result = MD_StringMatch(a->node->string, b->node->string, str_flags);
|
||||
result = MD_StringMatch(a->node->string, b->node->string, flags);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
MD_FUNCTION_IMPL MD_b32
|
||||
MD_ExprDeepMatch(MD_Expr *a, MD_Expr *b, MD_StringMatchFlags str_flags)
|
||||
MD_ExprDeepMatch(MD_Expr *a, MD_Expr *b, MD_MatchFlags flags)
|
||||
{
|
||||
MD_b32 result = MD_ExprMatch(a, b, str_flags);
|
||||
MD_b32 result = MD_ExprMatch(a, b, flags);
|
||||
if(result && !MD_ExprIsNil(a) && !MD_ExprIsNil(b))
|
||||
{
|
||||
result = (MD_ExprDeepMatch(a->sub[0], b->sub[0], str_flags) &&
|
||||
MD_ExprDeepMatch(a->sub[1], b->sub[1], str_flags));
|
||||
result = (MD_ExprDeepMatch(a->sub[0], b->sub[0], flags) &&
|
||||
MD_ExprDeepMatch(a->sub[1], b->sub[1], flags));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
+20
-20
@@ -80,7 +80,7 @@ static MD_b32
|
||||
MatchParsedWithNode(MD_String8 string, MD_Node *tree)
|
||||
{
|
||||
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit(""), string);
|
||||
return MD_NodeDeepMatch(tree, parse.node, 0, MD_NodeMatchFlag_Tags | MD_NodeMatchFlag_TagArguments);
|
||||
return MD_NodeDeepMatch(tree, parse.node, MD_MatchFlag_Tags | MD_MatchFlag_TagArguments);
|
||||
}
|
||||
|
||||
static MD_b32
|
||||
@@ -445,7 +445,7 @@ int main(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Test("Errors")
|
||||
{
|
||||
struct { char *s; int columns[2]; } tests[] = {
|
||||
@@ -459,13 +459,13 @@ int main(void)
|
||||
{"{a,,#b,}", {4, 5}},
|
||||
{"foo""\x80""bar", {4}},
|
||||
};
|
||||
|
||||
|
||||
int max_error_count = MD_ArrayCount(tests[0].columns);
|
||||
|
||||
|
||||
for(int i_test = 0; i_test < MD_ArrayCount(tests); ++i_test)
|
||||
{
|
||||
MD_ParseResult parse = MD_ParseWholeString(MD_S8Lit("test.md"), MD_S8CString(tests[i_test].s));
|
||||
|
||||
|
||||
MD_b32 columns_match = 1;
|
||||
{
|
||||
MD_Error *e = parse.first_error;
|
||||
@@ -478,7 +478,7 @@ int main(void)
|
||||
}
|
||||
e = e->next;
|
||||
}
|
||||
|
||||
|
||||
if(e && e->next)
|
||||
{
|
||||
columns_match = 0;
|
||||
@@ -486,14 +486,14 @@ int main(void)
|
||||
}
|
||||
TestResult(columns_match);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
MD_ParseResult parse = MD_ParseWholeFile(MD_S8Lit("__does_not_exist.md"));
|
||||
TestResult(parse.node->kind == MD_NodeKind_File && parse.first_error);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Test("Hash maps")
|
||||
{
|
||||
MD_String8 keys[] =
|
||||
@@ -502,12 +502,12 @@ int main(void)
|
||||
MD_S8Lit("\x4c\x80\xb7\x8b\xbf\x65\x5a\x4b\xc1\x2a\xc3\x5f\xe1\x66\xfb\x0d\x72\x83\x1c\x63\xba\xb5\x97\x02\x3f\x6a\xe0\x2a\x1b\x82\x07\x76"),
|
||||
MD_S8Lit("\xd8\xfd\x11\x4b\x04\xdf\xe5\x20\x5b\xd6\x4f\x87\x00\x70\x6a\xc8\xde\xed\xc7\x79\xdb\x87\x24\x36\xa8\x7a\x31\x41\x00\x57\xbd\x8d"),
|
||||
};
|
||||
|
||||
|
||||
// NOTE(mal): True for MD_HashString is djb2
|
||||
{
|
||||
TestResult(MD_HashString(keys[0]) == 1 && MD_HashString(keys[1]) == 1 && MD_HashString(keys[2]) == 3);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
MD_MapCollisionRule rules[] = { MD_MapCollisionRule_Chain, MD_MapCollisionRule_Overwrite };
|
||||
for(int i_rule = 0; i_rule < MD_ArrayCount(rules); ++i_rule)
|
||||
@@ -516,17 +516,17 @@ int main(void)
|
||||
MD_StringMap_Insert(&map, rules[i_rule], keys[0], (void *)0);
|
||||
MD_StringMap_Insert(&map, rules[i_rule], keys[1], (void *)1);
|
||||
MD_StringMap_Insert(&map, rules[i_rule], keys[2], (void *)2);
|
||||
|
||||
|
||||
MD_MapSlot *slot0 = MD_StringMap_Lookup(&map, keys[0]);
|
||||
MD_MapSlot *slot1 = MD_StringMap_Lookup(&map, keys[1]);
|
||||
MD_MapSlot *slot2 = MD_StringMap_Lookup(&map, keys[2]);
|
||||
|
||||
|
||||
TestResult(slot0 && slot0->value == (void *)0 &&
|
||||
slot1 && slot1->value == (void *)1 &&
|
||||
slot2 && slot2->value == (void *)2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
MD_MapCollisionRule rules[] = { MD_MapCollisionRule_Chain, MD_MapCollisionRule_Overwrite };
|
||||
for(int i_rule = 0; i_rule < MD_ArrayCount(rules); ++i_rule)
|
||||
@@ -535,18 +535,18 @@ int main(void)
|
||||
MD_PtrMap_Insert(&map, rules[i_rule], (void *)0, (void *)0);
|
||||
MD_PtrMap_Insert(&map, rules[i_rule], (void *)1, (void *)1);
|
||||
MD_PtrMap_Insert(&map, rules[i_rule], (void *)2, (void *)2);
|
||||
|
||||
|
||||
MD_MapSlot *slot0 = MD_PtrMap_Lookup(&map, (void *)0);
|
||||
MD_MapSlot *slot1 = MD_PtrMap_Lookup(&map, (void *)1);
|
||||
MD_MapSlot *slot2 = MD_PtrMap_Lookup(&map, (void *)2);
|
||||
|
||||
|
||||
TestResult(slot0 && slot0->value == (void *) 0 &&
|
||||
slot1 && slot1->value == (void *) 1 &&
|
||||
slot2 && slot2->value == (void *) 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Test("String escaping")
|
||||
{
|
||||
{
|
||||
@@ -561,7 +561,7 @@ int main(void)
|
||||
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit(""), MD_S8Lit("`````\\````"));
|
||||
TestResult(MD_StringMatch(parse.node->string, MD_S8Lit("``\\`"), 0));
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit(""), MD_S8Lit("`\\'`"));
|
||||
TestResult(MD_StringMatch(parse.node->string, MD_S8Lit("\\'"), 0));
|
||||
@@ -574,7 +574,7 @@ int main(void)
|
||||
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit(""), MD_S8Lit("'''''\\''''"));
|
||||
TestResult(MD_StringMatch(parse.node->string, MD_S8Lit("''\\'"), 0));
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit(""), MD_S8Lit("`\\\"`"));
|
||||
TestResult(MD_StringMatch(parse.node->string, MD_S8Lit("\\\""), 0));
|
||||
@@ -588,6 +588,6 @@ int main(void)
|
||||
TestResult(MD_StringMatch(parse.node->string, MD_S8Lit("\"\"\\\""), 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user