big naming pass for main API

This commit is contained in:
ryanfleury
2021-07-02 17:15:51 -06:00
parent 33bde8cc2f
commit 9ff0392f04
24 changed files with 1226 additions and 1181 deletions
+2 -2
View File
@@ -5,7 +5,7 @@ int main(void)
{
MD_String8 foo = "foo"_md;
MD_String8 bar = "bar"_md;
MD_String8 str = MD_PushStringF("%S%S", foo, bar);
printf("%.*s", MD_StringExpand(str));
MD_String8 str = MD_S8Fmt("%S%S", foo, bar);
printf("%.*s", MD_S8VArg(str));
return 0;
}
+37 -37
View File
@@ -42,8 +42,8 @@ MD_GLOBAL struct
static void TagSquareBracketSetsAsOptional(MD_Node *node, MD_Node *optional_tag)
{
if(node->kind == MD_NodeKind_Label &&
(node->flags & MD_NodeFlag_BracketLeft) && (node->flags & MD_NodeFlag_BracketRight))
if(node->kind == MD_NodeKind_Main &&
(node->flags & MD_NodeFlag_HasBracketLeft) && (node->flags & MD_NodeFlag_HasBracketRight))
{
if(node->string.size) // NOTE(mal): Production. Tag belongs to the first child
{
@@ -66,7 +66,7 @@ static MD_Node * NewChildLabel(MD_Node *parent, MD_String8 label)
{
MD_Node *result = 0;
result = MD_MakeNode(MD_NodeKind_Label, label, label, 0);
result = MD_MakeNode(MD_NodeKind_Main, label, label, 0);
if(parent)
{
MD_PushChild(parent, result);
@@ -97,9 +97,9 @@ static void PrintRule(MD_Map *depth_map, MD_Node *rule)
for(MD_EachNode(tag, rule->first_tag))
{
if(!MD_StringMatch(tag->string, MD_S8Lit(OPTIONAL_TAG), 0))
if(!MD_S8Match(tag->string, MD_S8Lit(OPTIONAL_TAG), 0))
{
printf("@%.*s ", MD_StringExpand(tag->string));
printf("@%.*s ", MD_S8VArg(tag->string));
}
}
@@ -127,7 +127,7 @@ static void PrintRule(MD_Map *depth_map, MD_Node *rule)
else
{
MD_Assert(rule->string.size > 0);
printf("%.*s", MD_StringExpand(rule->string));
printf("%.*s", MD_S8VArg(rule->string));
}
if(is_literal_char)
@@ -150,7 +150,7 @@ typedef enum OperationFlags
static void Extend(MD_String8 *s, char c)
{
*s = MD_PushStringF("%.*s%c", MD_StringExpand(*s), c);
*s = MD_S8Fmt("%.*s%c", MD_S8VArg(*s), c);
}
static void ExpandProduction(MD_Node *production, MD_String8List *out, MD_Node *cur_node,
@@ -181,31 +181,31 @@ static void ExpandRule(MD_Node *rule, MD_String8List *out_strings, MD_Node *cur_
MD_Node *node_to_tag = 0;
OperationFlags old_op_flags = op_flags;
for(MD_EachNode(tag_node, rule_element->first_tag)){
if(MD_StringMatch(tag_node->string, MD_S8Lit("child"), 0))
if(MD_S8Match(tag_node->string, MD_S8Lit("child"), 0))
{
cur_node = NewChild(cur_node);
op_flags &= ~OperationFlag_Tag; // NOTE(mal): Tag parameters are not tags
}
else if(MD_StringMatch(tag_node->string, MD_S8Lit("sibling"), 0))
else if(MD_S8Match(tag_node->string, MD_S8Lit("sibling"), 0))
{
cur_node = NewChild(cur_node->parent);
}
else if(MD_StringMatch(tag_node->string, MD_S8Lit("fill"), 0))
else if(MD_S8Match(tag_node->string, MD_S8Lit("fill"), 0))
{
op_flags |= OperationFlag_Fill;
}
else if(MD_StringMatch(tag_node->string, MD_S8Lit("tag"), 0))
else if(MD_S8Match(tag_node->string, MD_S8Lit("tag"), 0))
{
op_flags |= OperationFlag_Tag;
node_to_tag = cur_node;
cur_node = NewChild(0);
cur_node->kind = MD_NodeKind_Tag;
}
else if(MD_StringMatch(tag_node->string, MD_S8Lit("markup"), 0))
else if(MD_S8Match(tag_node->string, MD_S8Lit("markup"), 0))
{
op_flags |= OperationFlag_Markup;
}
else if(MD_StringMatch(tag_node->string, MD_S8Lit(OPTIONAL_TAG), 0))
else if(MD_S8Match(tag_node->string, MD_S8Lit(OPTIONAL_TAG), 0))
{
}
else
@@ -238,12 +238,12 @@ static void ExpandRule(MD_Node *rule, MD_String8List *out_strings, MD_Node *cur_
c = rule_element->string.str[0];
}
MD_String8 character = MD_PushStringF("%c", c);
MD_PushStringToList(out_strings, character);
MD_String8 character = MD_S8Fmt("%c", c);
MD_S8ListPush(out_strings, character);
if(op_flags & OperationFlag_Fill)
{
Extend(&cur_node->whole_string, c);
Extend(&cur_node->raw_string, c);
if(!(op_flags & OperationFlag_Markup))
{
Extend(&cur_node->string, c);
@@ -360,11 +360,11 @@ static MD_b32 EqualList(MD_Node *a, MD_Node *b)
static MD_b32 EqualTrees(MD_Node *a, MD_Node *b)
{
MD_b32 result = (a->kind == b->kind &&
MD_StringMatch(a->string, b->string, 0) &&
MD_StringMatch(a->whole_string, b->whole_string, 0));
MD_S8Match(a->string, b->string, 0) &&
MD_S8Match(a->raw_string, b->raw_string, 0));
result &= EqualList(a->first_tag, b->first_tag);
result &= EqualList(a->first_child, b->first_child);
result &= MD_StringMatch(a->comment_before, b->comment_before, 0);
result &= MD_S8Match(a->prev_comment, b->prev_comment, 0);
return result;
}
@@ -475,16 +475,16 @@ FirstBadNodeAtPointer(MD_Node *node)
{
MD_Node *result = 0;
MD_Node *root = MD_RootFromNode(node);
MD_u8 *node_at = root->whole_string.str + node->offset;
MD_u8 *node_at = root->raw_string.str + node->offset;
switch(node->kind){
case MD_NodeKind_File:
{
} break;
case MD_NodeKind_Label:
case MD_NodeKind_Main:
{
if(node_at != node->whole_string.str)
if(node_at != node->raw_string.str)
{
if(node->whole_string.size)
if(node->raw_string.size)
{
result = node;
}
@@ -505,7 +505,7 @@ FirstBadNodeAtPointer(MD_Node *node)
case MD_NodeKind_List:
case MD_NodeKind_Tag:
{
if(node_at != node->whole_string.str)
if(node_at != node->raw_string.str)
{
result = node;
goto end;
@@ -562,7 +562,7 @@ int main(int argument_count, char **arguments)
}
else
{
if(MD_StringMatch(rule_element->string, MD_S8Lit("|"), 0) &&
if(MD_S8Match(rule_element->string, MD_S8Lit("|"), 0) &&
!(rule_element->flags & MD_NodeFlag_StringLiteral))
{
rule = NewChild(production);
@@ -607,7 +607,7 @@ int main(int argument_count, char **arguments)
MD_Node *non_terminal_production = FindNonTerminalProduction(production, &visited_productions);
if(non_terminal_production)
{
fprintf(stderr, "Error: Non-terminal production \"%.*s\"\n", MD_StringExpand(non_terminal_production->string));
fprintf(stderr, "Error: Non-terminal production \"%.*s\"\n", MD_S8VArg(non_terminal_production->string));
goto error;
}
}
@@ -618,7 +618,7 @@ int main(int argument_count, char **arguments)
MD_MapSlot *slot = MD_MapLookup(&visited_productions, MD_MapKeyStr(production->string));
if(!slot)
{
fprintf(stderr, "Warning: Unreachable production \"%.*s\"\n", MD_StringExpand(production->string));
fprintf(stderr, "Warning: Unreachable production \"%.*s\"\n", MD_S8VArg(production->string));
}
}
@@ -702,7 +702,7 @@ int main(int argument_count, char **arguments)
#if DEBUG_RULES_AFTER_TRANSFORMATIONS
for(MD_EachNode(production, productions->first_child))
{
printf("%.*s (min %lu): \n", MD_StringExpand(production->string), GET_DEPTH(production));
printf("%.*s (min %lu): \n", MD_S8VArg(production->string), GET_DEPTH(production));
for(MD_EachNode(rule, production->first_child))
{
printf(" ");
@@ -732,7 +732,7 @@ int main(int argument_count, char **arguments)
MD_String8List string_list = {0};
// NOTE(mal): Generate a random MD file
ExpandProduction(file_production_node, &string_list, test.expected_output, 0, depth_map, max_production_depth, 0);
test.input = MD_JoinStringList(string_list, MD_S8Lit(""));
test.input = MD_S8ListJoin(string_list, MD_S8Lit(""));
Test *prev = 0;
for(Test *cur = first_test; cur; cur = cur->next)
@@ -766,19 +766,19 @@ int main(int argument_count, char **arguments)
for(Test *test = first_test; test; test = test->next)
{
MD_Node *file_node = MD_ParseWholeString(MD_S8Lit(""), test->input).node;
file_node->string = file_node->whole_string = (MD_String8){0};
file_node->string = file_node->raw_string = (MD_String8){0};
#if DEBUG_PRINT_GENERATED_TESTS
printf("> %.*s <\n", MD_StringExpand(EscapeNewlines(test->input)));
printf("> %.*s <\n", MD_S8VArg(EscapeNewlines(test->input)));
#endif
if(!EqualTrees(file_node, test->expected_output))
{
printf("\nFailed test %d\n", i_test);
printf("> %.*s <\n", MD_StringExpand(test->input));
printf("> %.*s <\n", MD_S8VArg(test->input));
printf("MD:\n");
MD_OutputTree(stdout, file_node, 0);
MD_DebugOutputTree(stdout, file_node, 0);
printf("Grammar:\n");
MD_OutputTree(stdout, test->expected_output, 0); printf("\n");
MD_DebugOutputTree(stdout, test->expected_output, 0); printf("\n");
return -1;
}
@@ -786,11 +786,11 @@ int main(int argument_count, char **arguments)
if(bad_at_node)
{
printf("\nBad node->at on test %d\n", i_test);
printf("> %.*s <\n", MD_StringExpand(test->input));
printf("> %.*s <\n", MD_S8VArg(test->input));
printf("MD:\n");
MD_OutputTree(stdout, file_node, 0);
MD_DebugOutputTree(stdout, file_node, 0);
printf("offending_node");
MD_OutputTree(stdout, bad_at_node, 0);
MD_DebugOutputTree(stdout, bad_at_node, 0);
return -1;
}
++i_test;
+8 -8
View File
@@ -95,10 +95,10 @@ unscoped_set_tail : {':' @child unscoped_set | ' ' @sibling unscoped_set | ':'
/* Comments
* Comments around nodes are accessible to the user. Here's how they behave:
* - The text inside a comment immediatly following a node is stored as the
* comment_after member of that node. No newlines can happen between a
* next_comment member of that node. No newlines can happen between a
* node and its after_comment.
* - The text inside a comment preceding a node is stored as the
* comment_before of that node _unless_ it is already the comment_after
* prev_comment of that node _unless_ it is already the next_comment
* of another node. One newline between the comment and the node is
* obviously necessary in the case of C++-style comments and it's also
* allowed for C-style comments.
@@ -108,9 +108,9 @@ unscoped_set_tail : {':' @child unscoped_set | ' ' @sibling unscoped_set | ':'
* The semantically annotated Backus-Naur form that we're using is not a
* good fit to describe the grammar of comments.
* To prevent the comment in "a /* comment */ b" from being interpreted as
* a comment_before of "b", instead of what it is (a comment_after of "a"),
* we would have to complicate the grammar by introducing several extra
* productions with this specific purpose in mind.
* The sensitivity of whitespace in the attachment of comments to nodes is
* also cumbersome to express in BNF.
*/
* a prev_comment of "b", instead of what it is (a next_comment of "a"),
* we would have to complicate the grammar by introducing several extra
* productions with this specific purpose in mind.
* The sensitivity of whitespace in the attachment of comments to nodes is
* also cumbersome to express in BNF.
*/
+150 -150
View File
@@ -71,7 +71,7 @@ MakeTestNode(MD_NodeKind kind, MD_String8 string)
static MD_C_Expr *
AtomExpr(char *str)
{
return MD_C_MakeExpr(MakeTestNode(MD_NodeKind_Label, MD_S8CString(str)),
return MD_C_MakeExpr(MakeTestNode(MD_NodeKind_Main, MD_S8CString(str)),
MD_C_ExprKind_Atom, MD_C_NilExpr(), MD_C_NilExpr());
}
@@ -91,7 +91,7 @@ static MD_b32
MatchParsedWithNode(MD_String8 string, MD_Node *tree)
{
MD_ParseResult parse = MD_ParseOneNode(string, 0);
return MD_NodeDeepMatch(tree, parse.node, MD_MatchFlag_Tags | MD_MatchFlag_TagArguments);
return MD_NodeDeepMatch(tree, parse.node, MD_NodeMatchFlag_Tags | MD_NodeMatchFlag_TagArguments);
}
static MD_b32
@@ -113,7 +113,7 @@ MatchParsedWithType(MD_String8 string, MD_C_Expr *expr)
static MD_b32
TokenMatch(MD_Token token, MD_String8 string, MD_TokenKind kind)
{
return MD_StringMatch(string, token.string, 0) && token.kind == kind;
return MD_S8Match(string, token.string, 0) && token.kind == kind;
}
int main(void)
@@ -123,20 +123,20 @@ int main(void)
MD_String8 string = MD_S8Lit("abc def 123 456 123_456 abc123 123abc");
MD_Token tokens[] =
{
MD_TokenFromString(MD_StringSkip(string, 0)),
MD_TokenFromString(MD_StringSkip(string, 3)),
MD_TokenFromString(MD_StringSkip(string, 4)),
MD_TokenFromString(MD_StringSkip(string, 7)),
MD_TokenFromString(MD_StringSkip(string, 8)),
MD_TokenFromString(MD_StringSkip(string, 11)),
MD_TokenFromString(MD_StringSkip(string, 12)),
MD_TokenFromString(MD_StringSkip(string, 15)),
MD_TokenFromString(MD_StringSkip(string, 16)),
MD_TokenFromString(MD_StringSkip(string, 19)),
MD_TokenFromString(MD_StringSkip(string, 20)),
MD_TokenFromString(MD_StringSkip(string, 23)),
MD_TokenFromString(MD_StringSkip(string, 24)),
MD_TokenFromString(MD_StringSkip(string, 27)),
MD_TokenFromString(MD_S8Skip(string, 0)),
MD_TokenFromString(MD_S8Skip(string, 3)),
MD_TokenFromString(MD_S8Skip(string, 4)),
MD_TokenFromString(MD_S8Skip(string, 7)),
MD_TokenFromString(MD_S8Skip(string, 8)),
MD_TokenFromString(MD_S8Skip(string, 11)),
MD_TokenFromString(MD_S8Skip(string, 12)),
MD_TokenFromString(MD_S8Skip(string, 15)),
MD_TokenFromString(MD_S8Skip(string, 16)),
MD_TokenFromString(MD_S8Skip(string, 19)),
MD_TokenFromString(MD_S8Skip(string, 20)),
MD_TokenFromString(MD_S8Skip(string, 23)),
MD_TokenFromString(MD_S8Skip(string, 24)),
MD_TokenFromString(MD_S8Skip(string, 27)),
};
TestResult(TokenMatch(tokens[0], MD_S8Lit("abc"), MD_TokenKind_Identifier));
@@ -153,37 +153,37 @@ int main(void)
Test("Empty Sets")
{
TestResult(MatchParsedWithNode(MD_S8Lit("{}"), MakeTestNode(MD_NodeKind_Label, MD_S8Lit(""))));
TestResult(MatchParsedWithNode(MD_S8Lit("()"), MakeTestNode(MD_NodeKind_Label, MD_S8Lit(""))));
TestResult(MatchParsedWithNode(MD_S8Lit("[]"), MakeTestNode(MD_NodeKind_Label, MD_S8Lit(""))));
TestResult(MatchParsedWithNode(MD_S8Lit("[)"), MakeTestNode(MD_NodeKind_Label, MD_S8Lit(""))));
TestResult(MatchParsedWithNode(MD_S8Lit("(]"), MakeTestNode(MD_NodeKind_Label, MD_S8Lit(""))));
TestResult(MatchParsedWithNode(MD_S8Lit("{}"), MakeTestNode(MD_NodeKind_Main, MD_S8Lit(""))));
TestResult(MatchParsedWithNode(MD_S8Lit("()"), MakeTestNode(MD_NodeKind_Main, MD_S8Lit(""))));
TestResult(MatchParsedWithNode(MD_S8Lit("[]"), MakeTestNode(MD_NodeKind_Main, MD_S8Lit(""))));
TestResult(MatchParsedWithNode(MD_S8Lit("[)"), MakeTestNode(MD_NodeKind_Main, MD_S8Lit(""))));
TestResult(MatchParsedWithNode(MD_S8Lit("(]"), MakeTestNode(MD_NodeKind_Main, MD_S8Lit(""))));
}
Test("Simple Unnamed Sets")
{
{
MD_String8 string = MD_S8Lit("{a, b, c}");
MD_Node *tree = MakeTestNode(MD_NodeKind_Label, MD_S8Lit(""));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Label, MD_S8Lit("a")));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Label, MD_S8Lit("b")));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Label, MD_S8Lit("c")));
MD_Node *tree = MakeTestNode(MD_NodeKind_Main, MD_S8Lit(""));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Main, MD_S8Lit("a")));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Main, MD_S8Lit("b")));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Main, MD_S8Lit("c")));
TestResult(MatchParsedWithNode(string, tree));
}
{
MD_String8 string = MD_S8Lit("(1 2 3 4 5)");
MD_Node *tree = MakeTestNode(MD_NodeKind_Label, MD_S8Lit(""));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Label, MD_S8Lit("1")));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Label, MD_S8Lit("2")));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Label, MD_S8Lit("3")));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Label, MD_S8Lit("4")));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Label, MD_S8Lit("5")));
MD_Node *tree = MakeTestNode(MD_NodeKind_Main, MD_S8Lit(""));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Main, MD_S8Lit("1")));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Main, MD_S8Lit("2")));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Main, MD_S8Lit("3")));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Main, MD_S8Lit("4")));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Main, MD_S8Lit("5")));
TestResult(MatchParsedWithNode(string, tree));
}
{
MD_String8 string = MD_S8Lit("{a}");
MD_Node *tree = MakeTestNode(MD_NodeKind_Label, MD_S8Lit(""));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Label, MD_S8Lit("a")));
MD_Node *tree = MakeTestNode(MD_NodeKind_Main, MD_S8Lit(""));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Main, MD_S8Lit("a")));
TestResult(MatchParsedWithNode(string, tree));
}
}
@@ -191,10 +191,10 @@ int main(void)
Test("Simple Named Sets")
{
MD_String8 string = MD_S8Lit("simple_set: {a, b, c}");
MD_Node *tree = MakeTestNode(MD_NodeKind_Label, MD_S8Lit("simple_set"));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Label, MD_S8Lit("a")));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Label, MD_S8Lit("b")));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Label, MD_S8Lit("c")));
MD_Node *tree = MakeTestNode(MD_NodeKind_Main, MD_S8Lit("simple_set"));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Main, MD_S8Lit("a")));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Main, MD_S8Lit("b")));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Main, MD_S8Lit("c")));
TestResult(MatchParsedWithNode(string, tree));
}
@@ -202,72 +202,72 @@ int main(void)
{
{
MD_String8 string = MD_S8Lit("{a b:{1 2 3} c}");
MD_Node *tree = MakeTestNode(MD_NodeKind_Label, MD_S8Lit(""));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Label, MD_S8Lit("a")));
MD_Node *tree = MakeTestNode(MD_NodeKind_Main, MD_S8Lit(""));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Main, MD_S8Lit("a")));
{
MD_Node *sub = MakeTestNode(MD_NodeKind_Label, MD_S8Lit("b"));
MD_PushChild(sub, MakeTestNode(MD_NodeKind_Label, MD_S8Lit("1")));
MD_PushChild(sub, MakeTestNode(MD_NodeKind_Label, MD_S8Lit("2")));
MD_PushChild(sub, MakeTestNode(MD_NodeKind_Label, MD_S8Lit("3")));
MD_Node *sub = MakeTestNode(MD_NodeKind_Main, MD_S8Lit("b"));
MD_PushChild(sub, MakeTestNode(MD_NodeKind_Main, MD_S8Lit("1")));
MD_PushChild(sub, MakeTestNode(MD_NodeKind_Main, MD_S8Lit("2")));
MD_PushChild(sub, MakeTestNode(MD_NodeKind_Main, MD_S8Lit("3")));
MD_PushChild(tree, sub);
}
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Label, MD_S8Lit("c")));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Main, MD_S8Lit("c")));
TestResult(MatchParsedWithNode(string, tree));
}
{
MD_String8 string = MD_S8Lit("foo: { (size: u64) -> *void }");
MD_Node *tree = MakeTestNode(MD_NodeKind_Label, MD_S8Lit("foo"));
MD_Node *params = MakeTestNode(MD_NodeKind_Label, MD_S8Lit(""));
MD_Node *size = MakeTestNode(MD_NodeKind_Label, MD_S8Lit("size"));
MD_PushChild(size, MakeTestNode(MD_NodeKind_Label, MD_S8Lit("u64")));
MD_Node *tree = MakeTestNode(MD_NodeKind_Main, MD_S8Lit("foo"));
MD_Node *params = MakeTestNode(MD_NodeKind_Main, MD_S8Lit(""));
MD_Node *size = MakeTestNode(MD_NodeKind_Main, MD_S8Lit("size"));
MD_PushChild(size, MakeTestNode(MD_NodeKind_Main, MD_S8Lit("u64")));
MD_PushChild(params, size);
MD_PushChild(tree, params);
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Label, MD_S8Lit("-")));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Label, MD_S8Lit(">")));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Label, MD_S8Lit("*")));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Label, MD_S8Lit("void")));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Main, MD_S8Lit("-")));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Main, MD_S8Lit(">")));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Main, MD_S8Lit("*")));
MD_PushChild(tree, MakeTestNode(MD_NodeKind_Main, MD_S8Lit("void")));
TestResult(MatchParsedWithNode(string, tree));
}
}
Test("Non-Sets")
{
TestResult(MatchParsedWithNode(MD_S8Lit("foo"), MakeTestNode(MD_NodeKind_Label, MD_S8Lit("foo"))));
TestResult(MatchParsedWithNode(MD_S8Lit("123"), MakeTestNode(MD_NodeKind_Label, MD_S8Lit("123"))));
TestResult(MatchParsedWithNode(MD_S8Lit("+"), MakeTestNode(MD_NodeKind_Label, MD_S8Lit("+"))));
TestResult(MatchParsedWithNode(MD_S8Lit("foo"), MakeTestNode(MD_NodeKind_Main, MD_S8Lit("foo"))));
TestResult(MatchParsedWithNode(MD_S8Lit("123"), MakeTestNode(MD_NodeKind_Main, MD_S8Lit("123"))));
TestResult(MatchParsedWithNode(MD_S8Lit("+"), MakeTestNode(MD_NodeKind_Main, MD_S8Lit("+"))));
}
Test("Set Border Flags")
{
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit("(0, 100)"), 0);
TestResult(parse.node->flags & MD_NodeFlag_ParenLeft &&
parse.node->flags & MD_NodeFlag_ParenRight);
TestResult(parse.node->flags & MD_NodeFlag_HasParenLeft &&
parse.node->flags & MD_NodeFlag_HasParenRight);
}
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit("(0, 100]"), 0);
TestResult(parse.node->flags & MD_NodeFlag_ParenLeft &&
parse.node->flags & MD_NodeFlag_BracketRight);
TestResult(parse.node->flags & MD_NodeFlag_HasParenLeft &&
parse.node->flags & MD_NodeFlag_HasBracketRight);
}
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit("[0, 100)"), 0);
TestResult(parse.node->flags & MD_NodeFlag_BracketLeft &&
parse.node->flags & MD_NodeFlag_ParenRight);
TestResult(parse.node->flags & MD_NodeFlag_HasBracketLeft &&
parse.node->flags & MD_NodeFlag_HasParenRight);
}
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit("[0, 100]"), 0);
TestResult(parse.node->flags & MD_NodeFlag_BracketLeft &&
parse.node->flags & MD_NodeFlag_BracketRight);
TestResult(parse.node->flags & MD_NodeFlag_HasBracketLeft &&
parse.node->flags & MD_NodeFlag_HasBracketRight);
}
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit("{0, 100}"), 0);
TestResult(parse.node->flags & MD_NodeFlag_BraceLeft &&
parse.node->flags & MD_NodeFlag_BraceRight);
TestResult(parse.node->flags & MD_NodeFlag_HasBraceLeft &&
parse.node->flags & MD_NodeFlag_HasBraceRight);
}
}
@@ -275,13 +275,13 @@ int main(void)
{
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit("(a, b)"), 0);
TestResult(parse.node->first_child->flags & MD_NodeFlag_BeforeComma);
TestResult(parse.node->first_child->next->flags & MD_NodeFlag_AfterComma);
TestResult(parse.node->first_child->flags & MD_NodeFlag_IsBeforeComma);
TestResult(parse.node->first_child->next->flags & MD_NodeFlag_IsAfterComma);
}
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit("(a; b)"), 0);
TestResult(parse.node->first_child->flags & MD_NodeFlag_BeforeSemicolon);
TestResult(parse.node->first_child->next->flags & MD_NodeFlag_AfterSemicolon);
TestResult(parse.node->first_child->flags & MD_NodeFlag_IsBeforeSemicolon);
TestResult(parse.node->first_child->next->flags & MD_NodeFlag_IsAfterSemicolon);
}
}
@@ -391,34 +391,34 @@ int main(void)
Test("Style Strings")
{
{
MD_String8 str = MD_StyledStringFromString(MD_S8Lit("THIS_IS_A_TEST"), MD_WordStyle_UpperCamelCase, MD_S8Lit(" "));
TestResult(MD_StringMatch(str, MD_S8Lit("This Is A Test"), 0));
MD_String8 str = MD_S8Stylize(MD_S8Lit("THIS_IS_A_TEST"), MD_IdentifierStyle_UpperCamelCase, MD_S8Lit(" "));
TestResult(MD_S8Match(str, MD_S8Lit("This Is A Test"), 0));
}
{
MD_String8 str = MD_StyledStringFromString(MD_S8Lit("this_is_a_test"), MD_WordStyle_UpperCamelCase, MD_S8Lit(" "));
TestResult(MD_StringMatch(str, MD_S8Lit("This Is A Test"), 0));
MD_String8 str = MD_S8Stylize(MD_S8Lit("this_is_a_test"), MD_IdentifierStyle_UpperCamelCase, MD_S8Lit(" "));
TestResult(MD_S8Match(str, MD_S8Lit("This Is A Test"), 0));
}
{
MD_String8 str = MD_StyledStringFromString(MD_S8Lit("ThisIsATest"), MD_WordStyle_UpperCamelCase, MD_S8Lit(" "));
TestResult(MD_StringMatch(str, MD_S8Lit("This Is A Test"), 0));
MD_String8 str = MD_S8Stylize(MD_S8Lit("ThisIsATest"), MD_IdentifierStyle_UpperCamelCase, MD_S8Lit(" "));
TestResult(MD_S8Match(str, MD_S8Lit("This Is A Test"), 0));
}
{
MD_String8 str = MD_StyledStringFromString(MD_S8Lit("Here is another test."), MD_WordStyle_UpperCamelCase, MD_S8Lit(""));
TestResult(MD_StringMatch(str, MD_S8Lit("HereIsAnotherTest."), 0));
MD_String8 str = MD_S8Stylize(MD_S8Lit("Here is another test."), MD_IdentifierStyle_UpperCamelCase, MD_S8Lit(""));
TestResult(MD_S8Match(str, MD_S8Lit("HereIsAnotherTest."), 0));
}
}
Test("Enum Strings")
{
TestResult(MD_StringMatch(MD_StringFromNodeKind(MD_NodeKind_Label), MD_S8Lit("Label"), 0));
TestResult(MD_StringMatch(MD_StringFromNodeKind(MD_NodeKind_Label), MD_S8Lit("Label"), 0));
MD_String8List list = MD_StringListFromNodeFlags(MD_NodeFlag_StringLiteral | MD_NodeFlag_ParenLeft | MD_NodeFlag_BeforeSemicolon);
TestResult(MD_S8Match(MD_StringFromNodeKind(MD_NodeKind_Main), MD_S8Lit("Main"), 0));
TestResult(MD_S8Match(MD_StringFromNodeKind(MD_NodeKind_Main), MD_S8Lit("Main"), 0));
MD_String8List list = MD_StringListFromNodeFlags(MD_NodeFlag_StringLiteral | MD_NodeFlag_HasParenLeft | MD_NodeFlag_IsBeforeSemicolon);
MD_b32 match = 1;
for(MD_String8Node *node = list.first; node; node = node->next)
{
if(!MD_StringMatch(node->string, MD_S8Lit("StringLiteral"), 0) &&
!MD_StringMatch(node->string, MD_S8Lit("ParenLeft"), 0) &&
!MD_StringMatch(node->string, MD_S8Lit("BeforeSemicolon"), 0))
if(!MD_S8Match(node->string, MD_S8Lit("StringLiteral"), 0) &&
!MD_S8Match(node->string, MD_S8Lit("HasParenLeft"), 0) &&
!MD_S8Match(node->string, MD_S8Lit("IsBeforeSemicolon"), 0))
{
match = 0;
break;
@@ -434,18 +434,18 @@ int main(void)
{
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit("/*foobar*/ (a b c)"), 0);
TestResult(parse.node->kind == MD_NodeKind_Label &&
MD_StringMatch(parse.node->comment_before, MD_S8Lit("foobar"), 0));
TestResult(parse.node->kind == MD_NodeKind_Main &&
MD_S8Match(parse.node->prev_comment, MD_S8Lit("foobar"), 0));
}
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit("// foobar\n(a b c)"), 0);
TestResult(parse.node->kind == MD_NodeKind_Label &&
MD_StringMatch(parse.node->comment_before, MD_S8Lit(" foobar"), 0));
TestResult(parse.node->kind == MD_NodeKind_Main &&
MD_S8Match(parse.node->prev_comment, MD_S8Lit(" foobar"), 0));
}
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit("// foobar\n\n(a b c)"), 0);
TestResult(parse.node->kind == MD_NodeKind_Label &&
MD_StringMatch(parse.node->comment_before, MD_S8Lit(""), 0));
TestResult(parse.node->kind == MD_NodeKind_Main &&
MD_S8Match(parse.node->prev_comment, MD_S8Lit(""), 0));
}
}
@@ -453,23 +453,23 @@ int main(void)
{
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit("(a b c) /*foobar*/"), 0);
TestResult(parse.node->kind == MD_NodeKind_Label &&
MD_StringMatch(parse.node->comment_after, MD_S8Lit("foobar"), 0));
TestResult(parse.node->kind == MD_NodeKind_Main &&
MD_S8Match(parse.node->next_comment, MD_S8Lit("foobar"), 0));
}
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit("(a b c) // foobar"), 0);
TestResult(parse.node->kind == MD_NodeKind_Label &&
MD_StringMatch(parse.node->comment_after, MD_S8Lit(" foobar"), 0));
TestResult(parse.node->kind == MD_NodeKind_Main &&
MD_S8Match(parse.node->next_comment, MD_S8Lit(" foobar"), 0));
}
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit("(a b c)\n// foobar"), 0);
TestResult(parse.node->kind == MD_NodeKind_Label &&
MD_StringMatch(parse.node->comment_after, MD_S8Lit(""), 0));
TestResult(parse.node->kind == MD_NodeKind_Main &&
MD_S8Match(parse.node->next_comment, MD_S8Lit(""), 0));
}
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit("(a b c)\n\n// foobar"), 0);
TestResult(parse.node->kind == MD_NodeKind_Label &&
MD_StringMatch(parse.node->comment_after, MD_S8Lit(""), 0));
TestResult(parse.node->kind == MD_NodeKind_Main &&
MD_S8Match(parse.node->next_comment, MD_S8Lit(""), 0));
}
}
}
@@ -495,7 +495,7 @@ int main(void)
MD_b32 columns_match = 1;
{
MD_Error *e = parse.errors.first;
MD_Message *e = parse.errors.first;
for(int i_error = 0; i_error < max_error_count && tests[i_test].columns[i_error]; ++i_error)
{
if(!e || MD_CodeLocFromNode(e->node).column != tests[i_test].columns[i_error])
@@ -574,60 +574,60 @@ int main(void)
nodes[i] = result.node;
}
TestResult(MD_StringMatch(nodes[0]->string, MD_S8Lit("foo-bar"), 0));
TestResult(MD_StringMatch(nodes[1]->string, MD_S8Lit("foo-bar"), 0));
TestResult(MD_StringMatch(nodes[2]->string, MD_S8Lit("foo-bar"), 0));
TestResult(MD_StringMatch(nodes[3]->string, MD_S8Lit("foo-bar"), 0));
TestResult(MD_StringMatch(nodes[4]->string, MD_S8Lit("foo-bar"), 0));
TestResult(MD_StringMatch(nodes[5]->string, MD_S8Lit("foo-bar"), 0));
TestResult(MD_S8Match(nodes[0]->string, MD_S8Lit("foo-bar"), 0));
TestResult(MD_S8Match(nodes[1]->string, MD_S8Lit("foo-bar"), 0));
TestResult(MD_S8Match(nodes[2]->string, MD_S8Lit("foo-bar"), 0));
TestResult(MD_S8Match(nodes[3]->string, MD_S8Lit("foo-bar"), 0));
TestResult(MD_S8Match(nodes[4]->string, MD_S8Lit("foo-bar"), 0));
TestResult(MD_S8Match(nodes[5]->string, MD_S8Lit("foo-bar"), 0));
TestResult(MD_StringMatch(nodes[0]->whole_string, samples[0], 0));
TestResult(MD_StringMatch(nodes[1]->whole_string, samples[1], 0));
TestResult(MD_StringMatch(nodes[2]->whole_string, samples[2], 0));
TestResult(MD_StringMatch(nodes[3]->whole_string, samples[3], 0));
TestResult(MD_StringMatch(nodes[4]->whole_string, samples[4], 0));
TestResult(MD_StringMatch(nodes[5]->whole_string, samples[5], 0));
TestResult(MD_S8Match(nodes[0]->raw_string, samples[0], 0));
TestResult(MD_S8Match(nodes[1]->raw_string, samples[1], 0));
TestResult(MD_S8Match(nodes[2]->raw_string, samples[2], 0));
TestResult(MD_S8Match(nodes[3]->raw_string, samples[3], 0));
TestResult(MD_S8Match(nodes[4]->raw_string, samples[4], 0));
TestResult(MD_S8Match(nodes[5]->raw_string, samples[5], 0));
}
Test("String escaping")
{
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit("`\\``"), 0);
TestResult(MD_StringMatch(parse.node->string, MD_S8Lit("\\`"), 0));
TestResult(MD_S8Match(parse.node->string, MD_S8Lit("\\`"), 0));
}
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit("``` \\``` ```"), 0);
TestResult(MD_StringMatch(parse.node->string, MD_S8Lit(" \\``` "), 0));
TestResult(MD_S8Match(parse.node->string, MD_S8Lit(" \\``` "), 0));
}
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit("`````\\````"), 0);
TestResult(MD_StringMatch(parse.node->string, MD_S8Lit("``\\`"), 0));
TestResult(MD_S8Match(parse.node->string, MD_S8Lit("``\\`"), 0));
}
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit("`\\'`"), 0);
TestResult(MD_StringMatch(parse.node->string, MD_S8Lit("\\'"), 0));
TestResult(MD_S8Match(parse.node->string, MD_S8Lit("\\'"), 0));
}
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit("''' \\''' '''"), 0);
TestResult(MD_StringMatch(parse.node->string, MD_S8Lit(" \\''' "), 0));
TestResult(MD_S8Match(parse.node->string, MD_S8Lit(" \\''' "), 0));
}
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit("'''''\\''''"), 0);
TestResult(MD_StringMatch(parse.node->string, MD_S8Lit("''\\'"), 0));
TestResult(MD_S8Match(parse.node->string, MD_S8Lit("''\\'"), 0));
}
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit("`\\\"`"), 0);
TestResult(MD_StringMatch(parse.node->string, MD_S8Lit("\\\""), 0));
TestResult(MD_S8Match(parse.node->string, MD_S8Lit("\\\""), 0));
}
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit("\"\"\" \\\"\"\" \"\"\""), 0);
TestResult(MD_StringMatch(parse.node->string, MD_S8Lit(" \\\"\"\" "), 0));
TestResult(MD_S8Match(parse.node->string, MD_S8Lit(" \\\"\"\" "), 0));
}
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit("\"\"\"\"\"\\\"\"\"\""), 0);
TestResult(MD_StringMatch(parse.node->string, MD_S8Lit("\"\"\\\""), 0));
TestResult(MD_S8Match(parse.node->string, MD_S8Lit("\"\"\\\""), 0));
}
}
@@ -638,48 +638,48 @@ int main(void)
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit("foo:{x y z; a b c}"), 0);
MD_Node *node = parse.node;
MD_Node *group_first = node->first_child;
MD_Node *group_last = MD_SeekNodeWithFlags(group_first, MD_NodeFlag_AfterSemicolon);
MD_Node *group_opl = MD_NodeFromFlags(group_first->next, MD_NilNode(), MD_NodeFlag_IsAfterSemicolon);
TestResult(MD_StringMatch(group_first->string, MD_S8Lit("x"), 0));
TestResult(MD_StringMatch(group_first->next->string, MD_S8Lit("y"), 0));
TestResult(MD_StringMatch(group_first->next->next->string, MD_S8Lit("z"), 0));
TestResult(group_last == group_first->next->next->next);
TestResult(MD_S8Match(group_first->string, MD_S8Lit("x"), 0));
TestResult(MD_S8Match(group_first->next->string, MD_S8Lit("y"), 0));
TestResult(MD_S8Match(group_first->next->next->string, MD_S8Lit("z"), 0));
TestResult(group_opl == group_first->next->next->next);
group_first = group_last;
group_last = MD_SeekNodeWithFlags(group_first, MD_NodeFlag_AfterSemicolon);
group_first = group_opl;
group_opl = MD_NodeFromFlags(group_first, MD_NilNode(), MD_NodeFlag_IsAfterSemicolon);
TestResult(MD_StringMatch(group_first->string, MD_S8Lit("a"), 0));
TestResult(MD_StringMatch(group_first->next->string, MD_S8Lit("b"), 0));
TestResult(MD_StringMatch(group_first->next->next->string, MD_S8Lit("c"), 0));
TestResult(group_last == group_first->next->next->next);
TestResult(MD_S8Match(group_first->string, MD_S8Lit("a"), 0));
TestResult(MD_S8Match(group_first->next->string, MD_S8Lit("b"), 0));
TestResult(MD_S8Match(group_first->next->next->string, MD_S8Lit("c"), 0));
TestResult(group_opl == group_first->next->next->next);
}
{
MD_ParseResult parse = MD_ParseOneNode(MD_S8Lit("foo:{a b c , d e f , g h i}"), 0);
MD_Node *node = parse.node;
MD_Node *group_first = 0;
MD_Node *group_last = 0;
MD_Node *group_opl = 0;
group_first = node->first_child;
group_last = MD_SeekNodeWithFlags(group_first, MD_NodeFlag_AfterComma);
TestResult(MD_StringMatch(group_first->string, MD_S8Lit("a"), 0));
TestResult(MD_StringMatch(group_first->next->string, MD_S8Lit("b"), 0));
TestResult(MD_StringMatch(group_first->next->next->string, MD_S8Lit("c"), 0));
TestResult(group_last == group_first->next->next->next);
group_opl = MD_NodeFromFlags(group_first, MD_NilNode(), MD_NodeFlag_IsAfterComma);
TestResult(MD_S8Match(group_first->string, MD_S8Lit("a"), 0));
TestResult(MD_S8Match(group_first->next->string, MD_S8Lit("b"), 0));
TestResult(MD_S8Match(group_first->next->next->string, MD_S8Lit("c"), 0));
TestResult(group_opl == group_first->next->next->next);
group_first = group_last;
group_last = MD_SeekNodeWithFlags(group_first, MD_NodeFlag_AfterComma);
TestResult(MD_StringMatch(group_first->string, MD_S8Lit("d"), 0));
TestResult(MD_StringMatch(group_first->next->string, MD_S8Lit("e"), 0));
TestResult(MD_StringMatch(group_first->next->next->string, MD_S8Lit("f"), 0));
TestResult(group_last == group_first->next->next->next);
group_first = group_opl;
group_opl = MD_NodeFromFlags(group_first, MD_NilNode(), MD_NodeFlag_IsAfterComma);
TestResult(MD_S8Match(group_first->string, MD_S8Lit("d"), 0));
TestResult(MD_S8Match(group_first->next->string, MD_S8Lit("e"), 0));
TestResult(MD_S8Match(group_first->next->next->string, MD_S8Lit("f"), 0));
TestResult(group_opl == group_first->next->next->next);
group_first = group_last;
group_last = MD_SeekNodeWithFlags(group_first, MD_NodeFlag_AfterComma);
TestResult(MD_StringMatch(group_first->string, MD_S8Lit("g"), 0));
TestResult(MD_StringMatch(group_first->next->string, MD_S8Lit("h"), 0));
TestResult(MD_StringMatch(group_first->next->next->string, MD_S8Lit("i"), 0));
TestResult(group_last == group_first->next->next->next);
group_first = group_opl;
group_opl = MD_NodeFromFlags(group_first, MD_NilNode(), MD_NodeFlag_IsAfterComma);
TestResult(MD_S8Match(group_first->string, MD_S8Lit("g"), 0));
TestResult(MD_S8Match(group_first->next->string, MD_S8Lit("h"), 0));
TestResult(MD_S8Match(group_first->next->next->string, MD_S8Lit("i"), 0));
TestResult(group_opl == group_first->next->next->next);
}
}
@@ -867,4 +867,4 @@ int main(void)
}
return 0;
}
}
+2 -2
View File
@@ -5,11 +5,11 @@ void run_test_on_string(MD_String8 string)
{
MD_String16 s16 = MD_S16FromS8(string);
MD_String8 s8_ts16 = MD_S8FromS16(s16);
MD_Assert(MD_StringMatch(s8_ts16, string, 0));
MD_Assert(MD_S8Match(s8_ts16, string, 0));
MD_String32 s32 = MD_S32FromS8(string);
MD_String8 s8_ts32 = MD_S8FromS32(s32);
MD_Assert(MD_StringMatch(s8_ts32, string, 0));
MD_Assert(MD_S8Match(s8_ts32, string, 0));
}
int main(void)