mirror of
https://github.com/Ed94/metadesk.git
synced 2026-07-10 11:51:37 -07:00
Remove catastrophic from MD_Error and add MD_MessageKind to it.
This commit is contained in:
+4
-2
@@ -380,8 +380,9 @@ struct MD_CodeLoc
|
||||
|
||||
typedef enum MD_MessageKind
|
||||
{
|
||||
MD_MessageKind_Error,
|
||||
MD_MessageKind_None,
|
||||
MD_MessageKind_Warning,
|
||||
MD_MessageKind_Error,
|
||||
}
|
||||
MD_MessageKind;
|
||||
|
||||
@@ -487,7 +488,7 @@ struct MD_Error
|
||||
MD_String8 string;
|
||||
MD_String8 filename;
|
||||
MD_Node *node;
|
||||
MD_b32 catastrophic;
|
||||
MD_MessageKind kind;
|
||||
};
|
||||
|
||||
typedef struct MD_ParseCtx MD_ParseCtx;
|
||||
@@ -502,6 +503,7 @@ struct MD_ParseCtx
|
||||
MD_String8 file_contents;
|
||||
MD_Map namespace_table;
|
||||
MD_Node *selected_namespace;
|
||||
MD_MessageKind error_level;
|
||||
MD_b32 catastrophic_error;
|
||||
};
|
||||
|
||||
|
||||
+19
-15
@@ -1546,7 +1546,7 @@ _MD_CodeLocFromFileOffset(MD_String8 filename, MD_u8 * file_contents, MD_u8 *at)
|
||||
}
|
||||
|
||||
MD_PRIVATE_FUNCTION_IMPL void
|
||||
_MD_Error(MD_ParseCtx *ctx, MD_Node *node, MD_b32 catastrophic, char *fmt, ...)
|
||||
_MD_Error(MD_ParseCtx *ctx, MD_Node *node, MD_MessageKind kind, MD_b32 catastrophic, char *fmt, ...)
|
||||
{
|
||||
// NOTE(mal): Sort errors. Traverse the whole list assuming it will be short.
|
||||
// The alternative is to drop a prev pointer into MD_Error and traverse it backwards
|
||||
@@ -1564,11 +1564,10 @@ _MD_Error(MD_ParseCtx *ctx, MD_Node *node, MD_b32 catastrophic, char *fmt, ...)
|
||||
}
|
||||
|
||||
// NOTE(mal): Ignore errors after first catastrophic error
|
||||
if(!ctx->catastrophic_error || !prev_error || prev_error->catastrophic == 0)
|
||||
if(!ctx->catastrophic_error || !prev_error || prev_error->next)
|
||||
{
|
||||
MD_Error *error = _MD_PushArray(_MD_GetCtx(), MD_Error, 1);
|
||||
error->node = node ? node : MD_NilNode();
|
||||
error->catastrophic = catastrophic;
|
||||
error->filename = ctx->filename;
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
@@ -1595,10 +1594,15 @@ _MD_Error(MD_ParseCtx *ctx, MD_Node *node, MD_b32 catastrophic, char *fmt, ...)
|
||||
{
|
||||
ctx->catastrophic_error = 1;
|
||||
}
|
||||
|
||||
if(kind > ctx->error_level)
|
||||
{
|
||||
ctx->error_level = kind;
|
||||
}
|
||||
}
|
||||
}
|
||||
#define _MD_TokenError(ctx, token, catastrophic, fmt, ...) \
|
||||
_MD_Error(ctx, _MD_MakeNodeFromToken_Ctx(ctx, MD_NodeKind_ErrorMarker, token), catastrophic, fmt, __VA_ARGS__)
|
||||
#define _MD_TokenError(ctx, token, kind, catastrophic, fmt, ...) \
|
||||
_MD_Error(ctx, _MD_MakeNodeFromToken_Ctx(ctx, MD_NodeKind_ErrorMarker, token), kind, catastrophic, fmt, __VA_ARGS__)
|
||||
|
||||
MD_PRIVATE_FUNCTION_IMPL MD_Node *
|
||||
_MD_MakeNode(MD_NodeKind kind, MD_String8 string, MD_String8 whole_string, MD_String8 filename,
|
||||
@@ -1736,7 +1740,7 @@ _MD_ParseOneNode(MD_ParseCtx *ctx)
|
||||
comment_before = comment_token.string;
|
||||
if(!_MD_CommentIsSyntacticallyCorrect(comment_token))
|
||||
{
|
||||
_MD_TokenError(ctx, comment_token, 1, "Unterminated comment \"%.*s\"",
|
||||
_MD_TokenError(ctx, comment_token, MD_MessageKind_Error, 1, "Unterminated comment \"%.*s\"",
|
||||
MD_StringExpand(MD_StringPrefix(comment_token.outer_string, _MD_MAX_UNTERMINATED_TOKEN_ERROR_LEN)));
|
||||
}
|
||||
}
|
||||
@@ -1778,7 +1782,7 @@ _MD_ParseOneNode(MD_ParseCtx *ctx)
|
||||
{
|
||||
if(!_MD_StringLiteralIsBalanced(token))
|
||||
{
|
||||
_MD_Error(ctx, result.node, 1, "Unterminated text literal \"%.*s\"",
|
||||
_MD_Error(ctx, result.node, MD_MessageKind_Error, 1, "Unterminated text literal \"%.*s\"",
|
||||
MD_StringExpand(MD_StringPrefix(token.outer_string, _MD_MAX_UNTERMINATED_TOKEN_ERROR_LEN)));
|
||||
}
|
||||
}
|
||||
@@ -1787,11 +1791,11 @@ _MD_ParseOneNode(MD_ParseCtx *ctx)
|
||||
MD_u8 c = token.string.str[0];
|
||||
if(c == '}' || c == ']' || c == ')')
|
||||
{
|
||||
_MD_TokenError(ctx, token, 1, "Unbalanced \"%c\"", c);
|
||||
_MD_TokenError(ctx, token, MD_MessageKind_Error, 1, "Unbalanced \"%c\"", c);
|
||||
}
|
||||
else
|
||||
{
|
||||
_MD_TokenError(ctx, token, 0, "Unexpected reserved symbol \"%c\"", c);
|
||||
_MD_TokenError(ctx, token, MD_MessageKind_Error, 0, "Unexpected reserved symbol \"%c\"", c);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1813,7 +1817,7 @@ _MD_ParseOneNode(MD_ParseCtx *ctx)
|
||||
{
|
||||
for(MD_EachNode(tag, fc->first_tag))
|
||||
{
|
||||
_MD_Error(ctx, tag, 0, "Invalid position for tag \"%.*s\"", MD_StringExpand(tag->string));
|
||||
_MD_Error(ctx, tag, MD_MessageKind_Warning, 0, "Invalid position for tag \"%.*s\"", MD_StringExpand(tag->string));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1828,7 +1832,7 @@ _MD_ParseOneNode(MD_ParseCtx *ctx)
|
||||
MD_PushStringToList(&bytes, MD_PushStringF("0x%02X", token.outer_string.str[i_byte]));
|
||||
}
|
||||
MD_String8 byte_string = MD_JoinStringListWithSeparator(bytes, MD_S8Lit(" "));
|
||||
_MD_TokenError(ctx, token, 0, "Non-ASCII character \"%.*s\"", MD_StringExpand(byte_string));
|
||||
_MD_TokenError(ctx, token, MD_MessageKind_Error, 0, "Non-ASCII character \"%.*s\"", MD_StringExpand(byte_string));
|
||||
goto retry;
|
||||
}
|
||||
|
||||
@@ -1863,7 +1867,7 @@ _MD_ParseOneNode(MD_ParseCtx *ctx)
|
||||
comment_after = comment_token.string;
|
||||
if(!_MD_CommentIsSyntacticallyCorrect(comment_token))
|
||||
{
|
||||
_MD_TokenError(ctx, comment_token, 1, "Unterminated comment \"%.*s\"",
|
||||
_MD_TokenError(ctx, comment_token, MD_MessageKind_Error, 1, "Unterminated comment \"%.*s\"",
|
||||
MD_StringExpand(MD_StringPrefix(comment_token.outer_string, _MD_MAX_UNTERMINATED_TOKEN_ERROR_LEN)));
|
||||
}
|
||||
}
|
||||
@@ -1967,7 +1971,7 @@ _MD_ParseSet(MD_ParseCtx *ctx, MD_Node *parent, _MD_ParseSetFlags flags,
|
||||
if(brace) delimiter_char = '{';
|
||||
else if(paren) delimiter_char = '(';
|
||||
else if(bracket) delimiter_char = '[';
|
||||
_MD_Error(ctx, parent, 1, "Unbalanced \"%c\"", delimiter_char);
|
||||
_MD_Error(ctx, parent, MD_MessageKind_Error, 1, "Unbalanced \"%c\"", delimiter_char);
|
||||
}
|
||||
goto end_parse;
|
||||
}
|
||||
@@ -2042,7 +2046,7 @@ _MD_ParseTagList(MD_ParseCtx *ctx, MD_Node **first_out, MD_Node **last_out)
|
||||
else
|
||||
{
|
||||
MD_Token token = MD_Parse_PeekSkipSome(ctx, 0);
|
||||
_MD_TokenError(ctx, token, 0, "\"%.*s\" is not a proper tag identifier",
|
||||
_MD_TokenError(ctx, token, MD_MessageKind_Error, 0, "\"%.*s\" is not a proper tag identifier",
|
||||
MD_StringExpand(token.outer_string));
|
||||
// NOTE(mal): There are reasons to consume the non-tag token, but also to leave it.
|
||||
break;
|
||||
@@ -2112,7 +2116,7 @@ MD_ParseWholeString(MD_String8 filename, MD_String8 contents)
|
||||
else
|
||||
{
|
||||
MD_Token token = MD_Parse_PeekSkipSome(&ctx, 0);
|
||||
_MD_TokenError(&ctx, token, 0, "Invalid hash directive \"%.*s\"",
|
||||
_MD_TokenError(&ctx, token, MD_MessageKind_Error, 0, "Invalid hash directive \"%.*s\"",
|
||||
MD_StringExpand(token.outer_string));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user