mirror of
https://github.com/Ed94/metadesk.git
synced 2026-08-03 14:18:45 +00:00
[expr parser] Brace/bracket unary op required for set leaves.
This commit is contained in:
+16
-2
@@ -3071,6 +3071,12 @@ MD_ExprBakeOperatorTableFromList(MD_Arena *arena, MD_ExprOperatorList *list)
|
|||||||
{
|
{
|
||||||
result.subscript_op = &op_node_copy->op;
|
result.subscript_op = &op_node_copy->op;
|
||||||
}
|
}
|
||||||
|
else if(op.kind == MD_ExprOperatorKind_Prefix && MD_S8Match(op_s, MD_S8Lit("[]"), 0)){
|
||||||
|
result.bracket_set_op = &op_node_copy->op;
|
||||||
|
}
|
||||||
|
else if(op.kind == MD_ExprOperatorKind_Prefix && MD_S8Match(op_s, MD_S8Lit("{}"), 0)){
|
||||||
|
result.brace_set_op = &op_node_copy->op;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -3158,8 +3164,10 @@ _MD_ExprParse_Atom(MD_Arena *arena, _MD_ExprParseCtx *ctx)
|
|||||||
_MD_ExprParseCtx sub_ctx = _MD_ExprParse_MakeContext(ctx->op_table, node->first_child, node->last_child->next);
|
_MD_ExprParseCtx sub_ctx = _MD_ExprParse_MakeContext(ctx->op_table, node->first_child, node->last_child->next);
|
||||||
result = _MD_ExprParse_Ctx_MinPrecedence(arena, &sub_ctx, 0);
|
result = _MD_ExprParse_Ctx_MinPrecedence(arena, &sub_ctx, 0);
|
||||||
}
|
}
|
||||||
else if((node->flags & MD_NodeFlag_HasBracketLeft && node->flags & MD_NodeFlag_HasBracketRight) ||
|
else if((node->flags & MD_NodeFlag_HasBracketLeft && node->flags & MD_NodeFlag_HasBracketRight &&
|
||||||
(node->flags & MD_NodeFlag_HasBraceLeft && node->flags & MD_NodeFlag_HasBraceRight))
|
ctx->op_table->bracket_set_op) ||
|
||||||
|
(node->flags & MD_NodeFlag_HasBraceLeft && node->flags & MD_NodeFlag_HasBraceRight &&
|
||||||
|
ctx->op_table->brace_set_op))
|
||||||
{
|
{
|
||||||
_MD_CtxAdvance(ctx);
|
_MD_CtxAdvance(ctx);
|
||||||
// NOTE(mal): Unparsed leaf sets ({ ... }, [ ... ])
|
// NOTE(mal): Unparsed leaf sets ({ ... }, [ ... ])
|
||||||
@@ -3184,6 +3192,12 @@ _MD_ExprParse_Atom(MD_Arena *arena, _MD_ExprParseCtx *ctx)
|
|||||||
MD_Message *error = MD_MakeNodeError(arena, node, MD_MessageKind_Error, error_str);
|
MD_Message *error = MD_MakeNodeError(arena, node, MD_MessageKind_Error, error_str);
|
||||||
MD_MessageListPush(&result.errors, error);
|
MD_MessageListPush(&result.errors, error);
|
||||||
}
|
}
|
||||||
|
else if(node->flags & (MD_NodeFlag_HasParenLeft | MD_NodeFlag_HasParenRight | MD_NodeFlag_HasBracketLeft |
|
||||||
|
MD_NodeFlag_HasBracketRight | MD_NodeFlag_HasBraceLeft | MD_NodeFlag_HasBraceRight)){
|
||||||
|
MD_String8 error_str = MD_S8Fmt(arena, "Unexpected set.", MD_S8VArg(node->string));
|
||||||
|
MD_Message *error = MD_MakeNodeError(arena, node, MD_MessageKind_Error, error_str);
|
||||||
|
MD_MessageListPush(&result.errors, error);
|
||||||
|
}
|
||||||
else{ // NOTE(mal): leaf
|
else{ // NOTE(mal): leaf
|
||||||
_MD_CtxAdvance(ctx);
|
_MD_CtxAdvance(ctx);
|
||||||
result.node = MD_PushArrayZero(arena, MD_ExprNode, 1);
|
result.node = MD_PushArrayZero(arena, MD_ExprNode, 1);
|
||||||
|
|||||||
@@ -722,6 +722,8 @@ struct MD_ExprOperatorTable
|
|||||||
MD_MessageList errors;
|
MD_MessageList errors;
|
||||||
MD_ExprOperator *call_op; // TODO: Move elsewhere
|
MD_ExprOperator *call_op; // TODO: Move elsewhere
|
||||||
MD_ExprOperator *subscript_op;
|
MD_ExprOperator *subscript_op;
|
||||||
|
MD_ExprOperator *bracket_set_op;
|
||||||
|
MD_ExprOperator *brace_set_op;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct MD_ExprNode MD_ExprNode;
|
typedef struct MD_ExprNode MD_ExprNode;
|
||||||
|
|||||||
@@ -64,7 +64,9 @@ struct OperatorDescription{
|
|||||||
X(AssignRightShift, ">>=", BinaryRightAssociative, 4) \
|
X(AssignRightShift, ">>=", BinaryRightAssociative, 4) \
|
||||||
X(AssignBitwiseAnd, "&=", BinaryRightAssociative, 4) \
|
X(AssignBitwiseAnd, "&=", BinaryRightAssociative, 4) \
|
||||||
X(AssignBitwiseXor, "^=", BinaryRightAssociative, 4) \
|
X(AssignBitwiseXor, "^=", BinaryRightAssociative, 4) \
|
||||||
X(AssignBitwiseOr, "|=", BinaryRightAssociative, 4)
|
X(AssignBitwiseOr, "|=", BinaryRightAssociative, 4) \
|
||||||
|
X(BracketSet, "[]", Prefix, 3) \
|
||||||
|
X(BraceSet, "{}", Prefix, 3)
|
||||||
// X(Cast "()", Prefix, 17)
|
// X(Cast "()", Prefix, 17)
|
||||||
// X(Comma, ",", Binary, 3)
|
// X(Comma, ",", Binary, 3)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user