mirror of
https://github.com/Ed94/metadesk.git
synced 2026-08-06 15:48:47 +00:00
bugfixes and convergence in new parser
This commit is contained in:
+1
-1
@@ -814,7 +814,7 @@ 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);
|
MD_FUNCTION MD_b32 MD_NodeDeepMatch(MD_Node *a, MD_Node *b, MD_MatchFlags node_flags);
|
||||||
|
|
||||||
//~ Generation
|
//~ Generation
|
||||||
MD_FUNCTION void MD_OutputTree(FILE *file, MD_Node *node);
|
MD_FUNCTION void MD_OutputTree(FILE *file, MD_Node *node, int indent_spaces);
|
||||||
|
|
||||||
//~ Command Line Argument Helper
|
//~ Command Line Argument Helper
|
||||||
MD_FUNCTION MD_String8List MD_StringListFromArgCV(int argument_count, char **arguments);
|
MD_FUNCTION MD_String8List MD_StringListFromArgCV(int argument_count, char **arguments);
|
||||||
|
|||||||
+35
-12
@@ -1904,11 +1904,13 @@ MD_ParseOneNode(MD_String8 string, MD_u64 offset)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//- rjf: try to parse children for this node
|
//- rjf: try to parse children for this node
|
||||||
off += MD_BytesFromStringTokenGroupRun(MD_StringSkip(string, off), MD_TokenGroup_Comment|MD_TokenGroup_Whitespace);
|
MD_u64 colon_check_off = off;
|
||||||
MD_Token colon = MD_TokenFromString(MD_StringSkip(string, off));
|
colon_check_off += MD_BytesFromStringTokenGroupRun(MD_StringSkip(string, colon_check_off), MD_TokenGroup_Comment|MD_TokenGroup_Whitespace);
|
||||||
|
MD_Token colon = MD_TokenFromString(MD_StringSkip(string, colon_check_off));
|
||||||
if(MD_StringMatch(colon.string, MD_S8Lit(":"), 0) && colon.kind == MD_TokenKind_Symbol)
|
if(MD_StringMatch(colon.string, MD_S8Lit(":"), 0) && colon.kind == MD_TokenKind_Symbol)
|
||||||
{
|
{
|
||||||
off += colon.outer_string.size;
|
colon_check_off += colon.outer_string.size;
|
||||||
|
off = colon_check_off;
|
||||||
|
|
||||||
//- rjf: prohibit tags here
|
//- rjf: prohibit tags here
|
||||||
for(MD_u64 tag_check_off = off; tag_check_off < string.size;)
|
for(MD_u64 tag_check_off = off; tag_check_off < string.size;)
|
||||||
@@ -1958,7 +1960,6 @@ MD_ParseOneNode(MD_String8 string, MD_u64 offset)
|
|||||||
|
|
||||||
end_parse:;
|
end_parse:;
|
||||||
|
|
||||||
|
|
||||||
//- rjf: parse comments after nodes.
|
//- rjf: parse comments after nodes.
|
||||||
MD_String8 comment_after = MD_ZERO_STRUCT;
|
MD_String8 comment_after = MD_ZERO_STRUCT;
|
||||||
{
|
{
|
||||||
@@ -2003,6 +2004,11 @@ MD_ParseOneNode(MD_String8 string, MD_u64 offset)
|
|||||||
parsed_node->comment_before = comment_before;
|
parsed_node->comment_before = comment_before;
|
||||||
parsed_node->comment_after = comment_after;
|
parsed_node->comment_after = comment_after;
|
||||||
result.node = parsed_node;
|
result.node = parsed_node;
|
||||||
|
if(!MD_NodeIsNil(result.node))
|
||||||
|
{
|
||||||
|
result.node->first_tag = tags_parse.node;
|
||||||
|
result.node->last_tag = tags_parse.last_node;
|
||||||
|
}
|
||||||
result.last_node = parsed_node;
|
result.last_node = parsed_node;
|
||||||
result.bytes_parsed = off - offset;
|
result.bytes_parsed = off - offset;
|
||||||
|
|
||||||
@@ -3341,42 +3347,59 @@ MD_NodeDeepMatch(MD_Node *a, MD_Node *b, MD_MatchFlags flags)
|
|||||||
//~ Generation
|
//~ Generation
|
||||||
|
|
||||||
MD_FUNCTION_IMPL void
|
MD_FUNCTION_IMPL void
|
||||||
MD_OutputTree(FILE *file, MD_Node *node)
|
MD_OutputTree(FILE *file, MD_Node *node, int indent_spaces)
|
||||||
{
|
{
|
||||||
|
#define MD_PrintIndent() do { for(int i = 0; i < indent_spaces; i += 1) fprintf(file, " "); } while(0)
|
||||||
for(MD_Node *tag = node->first_tag; !MD_NodeIsNil(tag); tag = tag->next)
|
for(MD_Node *tag = node->first_tag; !MD_NodeIsNil(tag); tag = tag->next)
|
||||||
{
|
{
|
||||||
|
MD_PrintIndent();
|
||||||
fprintf(file, "@%.*s", MD_StringExpand(tag->string));
|
fprintf(file, "@%.*s", MD_StringExpand(tag->string));
|
||||||
if(!MD_NodeIsNil(tag->first_child))
|
if(!MD_NodeIsNil(tag->first_child))
|
||||||
{
|
{
|
||||||
fprintf(file, "(");
|
fprintf(file, "(");
|
||||||
for(MD_Node *child = tag->first_child; !MD_NodeIsNil(child); child = child->next)
|
for(MD_Node *child = tag->first_child; !MD_NodeIsNil(child); child = child->next)
|
||||||
{
|
{
|
||||||
MD_OutputTree(file, child);
|
MD_OutputTree(file, child, 0);
|
||||||
fprintf(file, ", ");
|
fprintf(file, ", ");
|
||||||
}
|
}
|
||||||
fprintf(file, ")\n");
|
fprintf(file, ")\n");
|
||||||
}
|
}
|
||||||
else
|
else if(!MD_NodeIsNil(tag->next))
|
||||||
{
|
{
|
||||||
fprintf(file, " ");
|
fprintf(file, " ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(!MD_NodeIsNil(node->first_tag))
|
||||||
|
{
|
||||||
|
fprintf(file, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(node->whole_string.size > 0)
|
||||||
|
{
|
||||||
|
MD_PrintIndent();
|
||||||
|
fprintf(file, "%.*s", MD_StringExpand(node->whole_string));
|
||||||
|
}
|
||||||
|
|
||||||
fprintf(file, "%.*s", MD_StringExpand(node->whole_string));
|
|
||||||
if(!MD_NodeIsNil(node->first_child))
|
if(!MD_NodeIsNil(node->first_child))
|
||||||
{
|
{
|
||||||
fprintf(file, ":\n{\n");
|
if(node->whole_string.size > 0)
|
||||||
|
{
|
||||||
|
fprintf(file, ":\n");
|
||||||
|
}
|
||||||
|
MD_PrintIndent();
|
||||||
|
fprintf(file, "{\n");
|
||||||
for(MD_Node *child = node->first_child; !MD_NodeIsNil(child); child = child->next)
|
for(MD_Node *child = node->first_child; !MD_NodeIsNil(child); child = child->next)
|
||||||
{
|
{
|
||||||
MD_OutputTree(file, child);
|
MD_OutputTree(file, child, indent_spaces+2);
|
||||||
fprintf(file, ",\n");
|
|
||||||
}
|
}
|
||||||
|
MD_PrintIndent();
|
||||||
fprintf(file, "}\n");
|
fprintf(file, "}\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(file, " ");
|
fprintf(file, "\n");
|
||||||
}
|
}
|
||||||
|
#undef MD_PrintIndent
|
||||||
}
|
}
|
||||||
|
|
||||||
//~ Command Line Argument Helper
|
//~ Command Line Argument Helper
|
||||||
|
|||||||
Reference in New Issue
Block a user