mirror of
https://github.com/Ed94/metadesk.git
synced 2026-08-06 23:58:48 +00:00
[expr parser] fix test fails; refactoring error reporting
This commit is contained in:
@@ -3,7 +3,12 @@ I don't get what's going on with error messages:
|
|||||||
Why is it rebased by "original_first"?
|
Why is it rebased by "original_first"?
|
||||||
Why is it the same for 3 locations but different here?
|
Why is it the same for 3 locations but different here?
|
||||||
`MD_u64 error_offset = ctx.first->offset - first->offset;`
|
`MD_u64 error_offset = ctx.first->offset - first->offset;`
|
||||||
Why is it named `MD_MakeExprParseError` it doesn't seem to have any\
|
Why is it named `MD_MakeExprParseError`?
|
||||||
details tied expression parsing.
|
|
||||||
|
Some changes I made to `MD_MakeExprParseError` (I'm not obsessed I swear):
|
||||||
|
Attach user pointer to keep the testing features working as originally written
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+22
-11
@@ -3387,7 +3387,8 @@ MD_ExprBakeOperatorTableFromList(MD_Arena *arena, MD_ExprOprList *list)
|
|||||||
{
|
{
|
||||||
// TODO(allen): review: does it make sense to use these kinds of errors
|
// TODO(allen): review: does it make sense to use these kinds of errors
|
||||||
// for *this* which isn't derived from metadesk at all?
|
// for *this* which isn't derived from metadesk at all?
|
||||||
MD_Message *error = MD_MakeExprParseError(arena, error_str, 0);
|
MD_Message *error = MD_MakeExprParseError(arena, MD_MessageKind_Warning, error_str, 0,
|
||||||
|
op->op_ptr);
|
||||||
MD_MessageListPush(&result.errors, error);
|
MD_MessageListPush(&result.errors, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3427,13 +3428,15 @@ _MD_Expr_Make(MD_Arena *arena, MD_ExprOpr *op, MD_Node *op_node,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
MD_FUNCTION void _MD_CtxAdvance(MD_ExprParseCtx *ctx)
|
MD_FUNCTION void
|
||||||
|
_MD_CtxAdvance(MD_ExprParseCtx *ctx)
|
||||||
{
|
{
|
||||||
ctx->first = ctx->first->next;
|
ctx->first = ctx->first->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
MD_FUNCTION MD_b32 _MD_ExprOprConsumed(MD_ExprParseCtx *ctx, MD_ExprOprKind kind, MD_u32 min_precedence,
|
MD_FUNCTION MD_b32
|
||||||
MD_ExprOpr **op_out)
|
_MD_ExprOprConsumed(MD_ExprParseCtx *ctx, MD_ExprOprKind kind, MD_u32 min_precedence,
|
||||||
|
MD_ExprOpr **op_out)
|
||||||
{
|
{
|
||||||
MD_b32 result = 0;
|
MD_b32 result = 0;
|
||||||
if(!MD_NodeIsNil(ctx->first))
|
if(!MD_NodeIsNil(ctx->first))
|
||||||
@@ -3494,7 +3497,8 @@ _MD_ExprParse_Atom(MD_Arena *arena, MD_ExprParseCtx *ctx)
|
|||||||
|
|
||||||
MD_String8 error_str = MD_S8Lit("Unexpected end of expression.");
|
MD_String8 error_str = MD_S8Lit("Unexpected end of expression.");
|
||||||
MD_u64 error_offset = last_non_null->offset + last_non_null->raw_string.size - ctx->original_first->offset;
|
MD_u64 error_offset = last_non_null->offset + last_non_null->raw_string.size - ctx->original_first->offset;
|
||||||
MD_Message *error = MD_MakeExprParseError(arena, error_str, error_offset);
|
MD_Message *error = MD_MakeExprParseError(arena, MD_MessageKind_FatalError,
|
||||||
|
error_str, error_offset, last_non_null);
|
||||||
MD_MessageListPush(&result.errors, error);
|
MD_MessageListPush(&result.errors, error);
|
||||||
}
|
}
|
||||||
else if(node->flags & MD_NodeFlag_HasParenLeft && node->flags & MD_NodeFlag_HasParenRight)
|
else if(node->flags & MD_NodeFlag_HasParenLeft && node->flags & MD_NodeFlag_HasParenRight)
|
||||||
@@ -3529,7 +3533,8 @@ _MD_ExprParse_Atom(MD_Arena *arena, MD_ExprParseCtx *ctx)
|
|||||||
{
|
{
|
||||||
MD_String8 error_str = MD_S8Fmt(arena, "Expected leaf. Got operator \"%.*s\".", MD_S8VArg(node->string));
|
MD_String8 error_str = MD_S8Fmt(arena, "Expected leaf. Got operator \"%.*s\".", MD_S8VArg(node->string));
|
||||||
MD_u64 error_offset = node->offset - ctx->original_first->offset;
|
MD_u64 error_offset = node->offset - ctx->original_first->offset;
|
||||||
MD_Message *error = MD_MakeExprParseError(arena, error_str, error_offset);
|
MD_Message *error = MD_MakeExprParseError(arena, MD_MessageKind_FatalError,
|
||||||
|
error_str, error_offset, node);
|
||||||
MD_MessageListPush(&result.errors, error);
|
MD_MessageListPush(&result.errors, error);
|
||||||
}
|
}
|
||||||
else if(node->flags & (MD_NodeFlag_HasParenLeft | MD_NodeFlag_HasParenRight | MD_NodeFlag_HasBracketLeft |
|
else if(node->flags & (MD_NodeFlag_HasParenLeft | MD_NodeFlag_HasParenRight | MD_NodeFlag_HasBracketLeft |
|
||||||
@@ -3537,7 +3542,8 @@ _MD_ExprParse_Atom(MD_Arena *arena, MD_ExprParseCtx *ctx)
|
|||||||
{
|
{
|
||||||
MD_String8 error_str = MD_S8Fmt(arena, "Unexpected set.", MD_S8VArg(node->string));
|
MD_String8 error_str = MD_S8Fmt(arena, "Unexpected set.", MD_S8VArg(node->string));
|
||||||
MD_u64 error_offset = node->offset - ctx->original_first->offset;
|
MD_u64 error_offset = node->offset - ctx->original_first->offset;
|
||||||
MD_Message *error = MD_MakeExprParseError(arena, error_str, error_offset);
|
MD_Message *error = MD_MakeExprParseError(arena, MD_MessageKind_FatalError,
|
||||||
|
error_str, error_offset, node);
|
||||||
MD_MessageListPush(&result.errors, error);
|
MD_MessageListPush(&result.errors, error);
|
||||||
}
|
}
|
||||||
else{ // NOTE(mal): leaf
|
else{ // NOTE(mal): leaf
|
||||||
@@ -3629,7 +3635,8 @@ MD_ExprParse(MD_Arena *arena, MD_ExprOprTable *op_table,
|
|||||||
MD_String8 error_str =
|
MD_String8 error_str =
|
||||||
MD_S8Lit("Partial parse. Expected binary or unary postfix operator.");
|
MD_S8Lit("Partial parse. Expected binary or unary postfix operator.");
|
||||||
MD_u64 error_offset = ctx.first->offset - first->offset;
|
MD_u64 error_offset = ctx.first->offset - first->offset;
|
||||||
MD_Message *error = MD_MakeExprParseError(arena, error_str, error_offset);
|
MD_Message *error = MD_MakeExprParseError(arena, MD_MessageKind_FatalError,
|
||||||
|
error_str, error_offset, ctx.first);
|
||||||
MD_MessageListPush(&result.errors, error);
|
MD_MessageListPush(&result.errors, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3666,10 +3673,14 @@ MD_ExprOprFromKindString(MD_ExprOprTable *table, MD_ExprOprKind kind, MD_String8
|
|||||||
}
|
}
|
||||||
|
|
||||||
MD_FUNCTION MD_Message*
|
MD_FUNCTION MD_Message*
|
||||||
MD_MakeExprParseError(MD_Arena *arena, MD_String8 str, MD_u64 offset)
|
MD_MakeExprParseError(MD_Arena *arena, MD_MessageKind kind, MD_String8 str, MD_u64 offset,
|
||||||
|
void *user_ptr)
|
||||||
{
|
{
|
||||||
MD_Node *err_node = MD_MakeNode(arena, MD_NodeKind_ErrorMarker, MD_S8Lit(""), MD_S8Lit(""), offset);
|
MD_Node *err_node = MD_MakeNode(arena, MD_NodeKind_ErrorMarker,
|
||||||
return MD_MakeNodeError(arena, err_node, MD_MessageKind_FatalError, str);
|
MD_S8Lit(""), MD_S8Lit(""), offset);
|
||||||
|
MD_Message *result = MD_MakeNodeError(arena, err_node, kind, str);
|
||||||
|
result->user_ptr = user_ptr;
|
||||||
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+5
-2
@@ -691,6 +691,7 @@ struct MD_Message
|
|||||||
MD_Node *node;
|
MD_Node *node;
|
||||||
MD_MessageKind kind;
|
MD_MessageKind kind;
|
||||||
MD_String8 string;
|
MD_String8 string;
|
||||||
|
void *user_ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct MD_MessageList MD_MessageList;
|
typedef struct MD_MessageList MD_MessageList;
|
||||||
@@ -783,7 +784,8 @@ struct MD_ExprParseCtx
|
|||||||
MD_Node *first;
|
MD_Node *first;
|
||||||
MD_Node *one_past_last;
|
MD_Node *one_past_last;
|
||||||
|
|
||||||
struct{
|
struct
|
||||||
|
{
|
||||||
MD_ExprOpr *call_op;
|
MD_ExprOpr *call_op;
|
||||||
MD_ExprOpr *subscript_op;
|
MD_ExprOpr *subscript_op;
|
||||||
MD_ExprOpr *bracket_set_op;
|
MD_ExprOpr *bracket_set_op;
|
||||||
@@ -1112,7 +1114,8 @@ MD_FUNCTION MD_ExprParseResult MD_ExprParse(MD_Arena *arena, MD_ExprOprTable *op
|
|||||||
|
|
||||||
MD_FUNCTION MD_ExprOpr* MD_ExprOprFromKindString(MD_ExprOprTable *table,
|
MD_FUNCTION MD_ExprOpr* MD_ExprOprFromKindString(MD_ExprOprTable *table,
|
||||||
MD_ExprOprKind kind, MD_String8 s);
|
MD_ExprOprKind kind, MD_String8 s);
|
||||||
MD_FUNCTION MD_Message* MD_MakeExprParseError(MD_Arena *arena, MD_String8 str, MD_u64 offset);
|
MD_FUNCTION MD_Message* MD_MakeExprParseError(MD_Arena *arena, MD_MessageKind kind,
|
||||||
|
MD_String8 str, MD_u64 offset, void *ptr);
|
||||||
|
|
||||||
//~ String Generation
|
//~ String Generation
|
||||||
|
|
||||||
|
|||||||
@@ -245,8 +245,9 @@ operator_array[Op_##name].op = (MD_ExprOpr){ .op_id = Op_##name, .kind = MD_Expr
|
|||||||
MD_ExprOprPush(arena, &operator_list, MD_ExprOprKind_Null, 1, MD_S8Lit("+"),
|
MD_ExprOprPush(arena, &operator_list, MD_ExprOprKind_Null, 1, MD_S8Lit("+"),
|
||||||
Op_Addition, plus_node);
|
Op_Addition, plus_node);
|
||||||
op_table = MD_ExprBakeOperatorTableFromList(arena, &operator_list);
|
op_table = MD_ExprBakeOperatorTableFromList(arena, &operator_list);
|
||||||
MD_Assert(op_table.errors.max_message_kind = MD_MessageKind_Warning && op_table.errors.node_count == 1 &&
|
MD_Assert(op_table.errors.max_message_kind == MD_MessageKind_Warning &&
|
||||||
op_table.errors.first->node == plus_node);
|
op_table.errors.node_count == 1 &&
|
||||||
|
op_table.errors.first->user_ptr == plus_node);
|
||||||
|
|
||||||
// NOTE: Repeat operator
|
// NOTE: Repeat operator
|
||||||
operator_list = (MD_ExprOprList){0};
|
operator_list = (MD_ExprOprList){0};
|
||||||
@@ -255,8 +256,9 @@ operator_array[Op_##name].op = (MD_ExprOpr){ .op_id = Op_##name, .kind = MD_Expr
|
|||||||
MD_ExprOprPush(arena, &operator_list, MD_ExprOprKind_Binary, 1, MD_S8Lit("+"),
|
MD_ExprOprPush(arena, &operator_list, MD_ExprOprKind_Binary, 1, MD_S8Lit("+"),
|
||||||
Op_Addition, plus_node_bis);
|
Op_Addition, plus_node_bis);
|
||||||
op_table = MD_ExprBakeOperatorTableFromList(arena, &operator_list);
|
op_table = MD_ExprBakeOperatorTableFromList(arena, &operator_list);
|
||||||
MD_Assert(op_table.errors.max_message_kind = MD_MessageKind_Warning && op_table.errors.node_count == 1 &&
|
MD_Assert(op_table.errors.max_message_kind == MD_MessageKind_Warning &&
|
||||||
op_table.errors.first->node == plus_node_bis);
|
op_table.errors.node_count == 1 &&
|
||||||
|
op_table.errors.first->user_ptr == plus_node_bis);
|
||||||
|
|
||||||
operator_list = (MD_ExprOprList){0};
|
operator_list = (MD_ExprOprList){0};
|
||||||
// NOTE: Binary-postfix operator conflict
|
// NOTE: Binary-postfix operator conflict
|
||||||
@@ -265,8 +267,9 @@ operator_array[Op_##name].op = (MD_ExprOpr){ .op_id = Op_##name, .kind = MD_Expr
|
|||||||
MD_ExprOprPush(arena, &operator_list, MD_ExprOprKind_Postfix, 1, MD_S8Lit("+"),
|
MD_ExprOprPush(arena, &operator_list, MD_ExprOprKind_Postfix, 1, MD_S8Lit("+"),
|
||||||
Op_Addition, plus_node_bis);
|
Op_Addition, plus_node_bis);
|
||||||
op_table = MD_ExprBakeOperatorTableFromList(arena, &operator_list);
|
op_table = MD_ExprBakeOperatorTableFromList(arena, &operator_list);
|
||||||
MD_Assert(op_table.errors.max_message_kind = MD_MessageKind_Warning && op_table.errors.node_count == 1 &&
|
MD_Assert(op_table.errors.max_message_kind == MD_MessageKind_Warning
|
||||||
op_table.errors.first->node == plus_node_bis);
|
&& op_table.errors.node_count == 1 &&
|
||||||
|
op_table.errors.first->user_ptr == plus_node_bis);
|
||||||
|
|
||||||
operator_list = (MD_ExprOprList){0};
|
operator_list = (MD_ExprOprList){0};
|
||||||
// NOTE: Same precedence difference associativity conflict
|
// NOTE: Same precedence difference associativity conflict
|
||||||
@@ -275,8 +278,9 @@ operator_array[Op_##name].op = (MD_ExprOpr){ .op_id = Op_##name, .kind = MD_Expr
|
|||||||
MD_ExprOprPush(arena, &operator_list, MD_ExprOprKind_BinaryRightAssociative, 1, MD_S8Lit("-"),
|
MD_ExprOprPush(arena, &operator_list, MD_ExprOprKind_BinaryRightAssociative, 1, MD_S8Lit("-"),
|
||||||
Op_Addition, minus_node);
|
Op_Addition, minus_node);
|
||||||
op_table = MD_ExprBakeOperatorTableFromList(arena, &operator_list);
|
op_table = MD_ExprBakeOperatorTableFromList(arena, &operator_list);
|
||||||
MD_Assert(op_table.errors.max_message_kind = MD_MessageKind_Warning && op_table.errors.node_count == 1 &&
|
MD_Assert(op_table.errors.max_message_kind == MD_MessageKind_Warning &&
|
||||||
op_table.errors.first->node == minus_node);
|
op_table.errors.node_count == 1 &&
|
||||||
|
op_table.errors.first->user_ptr == minus_node);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user