mirror of
https://github.com/Ed94/metadesk.git
synced 2026-06-24 20:54:59 -07:00
[main] fix initializer of MD_Node
This commit is contained in:
+19
-5
@@ -198,9 +198,12 @@
|
||||
////////////////////////////////
|
||||
//~ Code Location Info.
|
||||
|
||||
@doc("Source code location using file, line, column coordinates")
|
||||
@struct MD_CodeLoc: {
|
||||
filename: MD_String8,
|
||||
@doc("Line numbers are 1 based, the lowest valid location is on line number 1.")
|
||||
line: MD_u32,
|
||||
@doc("Column numbers are 1 based, the lowest valid location is on column number 1.")
|
||||
column: MD_u32,
|
||||
};
|
||||
|
||||
@@ -815,6 +818,22 @@
|
||||
return: MD_ParseResult,
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ Location Conversion
|
||||
|
||||
@func MD_CodeLocFromFileOffset: {
|
||||
filename: MD_String8,
|
||||
base: *MD_u8,
|
||||
off: *MD_u8,
|
||||
return: MD_CodeLoc,
|
||||
};
|
||||
|
||||
@func MD_CodeLocFromNode: {
|
||||
node: *MD_Node,
|
||||
return: MD_CodeLoc,
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////
|
||||
//~ Tree/List Building
|
||||
|
||||
@@ -927,11 +946,6 @@
|
||||
return: MD_b32,
|
||||
};
|
||||
|
||||
@func MD_CodeLocFromNode: {
|
||||
node: *MD_Node,
|
||||
return: MD_CodeLoc,
|
||||
};
|
||||
|
||||
@func MD_ChildCountFromNode: {
|
||||
node: *MD_Node,
|
||||
return: MD_i64,
|
||||
|
||||
+4
-1
@@ -723,6 +723,10 @@ MD_FUNCTION MD_ParseResult MD_ParseOneNode (MD_String8 filename, MD_String8
|
||||
MD_FUNCTION MD_ParseResult MD_ParseWholeString (MD_String8 filename, MD_String8 contents);
|
||||
MD_FUNCTION MD_ParseResult MD_ParseWholeFile (MD_String8 filename);
|
||||
|
||||
//~ Location Conversion
|
||||
MD_FUNCTION MD_CodeLoc MD_CodeLocFromFileOffset(MD_String8 filename, MD_u8 *base, MD_u8 *off);
|
||||
MD_FUNCTION MD_CodeLoc MD_CodeLocFromNode(MD_Node *node);
|
||||
|
||||
//~ Tree/List Building
|
||||
MD_FUNCTION MD_b32 MD_NodeIsNil(MD_Node *node);
|
||||
MD_FUNCTION MD_Node *MD_NilNode(void);
|
||||
@@ -744,7 +748,6 @@ MD_FUNCTION MD_Node * MD_ChildFromIndex(MD_Node *node, int n);
|
||||
MD_FUNCTION MD_Node * MD_TagFromIndex(MD_Node *node, int n);
|
||||
MD_FUNCTION MD_Node * MD_TagArgFromIndex(MD_Node *node, MD_String8 tag_string, int n);
|
||||
MD_FUNCTION MD_b32 MD_NodeHasTag(MD_Node *node, MD_String8 tag_string);
|
||||
MD_FUNCTION MD_CodeLoc MD_CodeLocFromNode(MD_Node *node);
|
||||
MD_FUNCTION MD_i64 MD_ChildCountFromNode(MD_Node *node);
|
||||
MD_FUNCTION MD_i64 MD_TagCountFromNode(MD_Node *node);
|
||||
MD_FUNCTION MD_Node * MD_Deref(MD_Node *node);
|
||||
|
||||
+35
-32
@@ -25,10 +25,12 @@ static MD_Node _md_nil_node =
|
||||
MD_ZERO_STRUCT, // string
|
||||
MD_ZERO_STRUCT, // whole_string
|
||||
0xdeadffffffffffull, // string_hash
|
||||
MD_ZERO_STRUCT, // comment_before
|
||||
MD_ZERO_STRUCT, // comment_after
|
||||
{(MD_u8*)"`NIL DD NODE`", 13}, // filename
|
||||
0, // file_contents
|
||||
0, // at
|
||||
&_md_nil_node, // ref_target
|
||||
{(MD_u8*)"`NIL DD NODE`", 13},
|
||||
0,
|
||||
0,
|
||||
};
|
||||
|
||||
MD_PRIVATE_FUNCTION_IMPL void
|
||||
@@ -1520,28 +1522,6 @@ MD_Parse_RequireKind(MD_ParseCtx *ctx, MD_TokenKind kind, MD_Token *out_token)
|
||||
return result;
|
||||
}
|
||||
|
||||
MD_PRIVATE_FUNCTION_IMPL MD_CodeLoc
|
||||
_MD_CodeLocFromFileOffset(MD_String8 filename, MD_u8 * file_contents, MD_u8 *at)
|
||||
{
|
||||
MD_CodeLoc loc;
|
||||
loc.filename = filename;
|
||||
loc.line = 1;
|
||||
loc.column = 1;
|
||||
for(MD_u64 i = 0; file_contents+i < at && file_contents[i]; i += 1)
|
||||
{
|
||||
if(file_contents[i] == '\n')
|
||||
{
|
||||
loc.line += 1;
|
||||
loc.column = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
loc.column += 1;
|
||||
}
|
||||
}
|
||||
return loc;
|
||||
}
|
||||
|
||||
MD_PRIVATE_FUNCTION_IMPL void
|
||||
_MD_Error(MD_ParseCtx *ctx, MD_Node *node, MD_MessageKind kind, char *fmt, ...)
|
||||
{
|
||||
@@ -2173,6 +2153,36 @@ MD_ParseWholeFile(MD_String8 filename)
|
||||
return parse;
|
||||
}
|
||||
|
||||
MD_PRIVATE_FUNCTION_IMPL MD_CodeLoc
|
||||
MD_CodeLocFromFileOffset(MD_String8 filename, MD_u8 *base, MD_u8 *at)
|
||||
{
|
||||
MD_CodeLoc loc;
|
||||
loc.filename = filename;
|
||||
loc.line = 1;
|
||||
loc.column = 1;
|
||||
for(MD_u64 i = 0; base+i < at && base[i]; i += 1)
|
||||
{
|
||||
if(base[i] == '\n')
|
||||
{
|
||||
loc.line += 1;
|
||||
loc.column = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
loc.column += 1;
|
||||
}
|
||||
}
|
||||
return loc;
|
||||
}
|
||||
|
||||
MD_FUNCTION_IMPL MD_CodeLoc
|
||||
MD_CodeLocFromNode(MD_Node *node)
|
||||
{
|
||||
MD_CodeLoc loc = MD_CodeLocFromFileOffset(node->filename, node->file_contents, node->at);
|
||||
return loc;
|
||||
}
|
||||
|
||||
|
||||
MD_FUNCTION_IMPL MD_b32
|
||||
MD_NodeIsNil(MD_Node *node)
|
||||
{
|
||||
@@ -2374,13 +2384,6 @@ MD_NodeHasTag(MD_Node *node, MD_String8 tag_string)
|
||||
return !MD_NodeIsNil(MD_TagFromString(node, tag_string));
|
||||
}
|
||||
|
||||
MD_FUNCTION_IMPL MD_CodeLoc
|
||||
MD_CodeLocFromNode(MD_Node *node)
|
||||
{
|
||||
MD_CodeLoc loc = _MD_CodeLocFromFileOffset(node->filename, node->file_contents, node->at);
|
||||
return loc;
|
||||
}
|
||||
|
||||
MD_FUNCTION_IMPL MD_i64
|
||||
MD_ChildCountFromNode(MD_Node *node)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user