diff --git a/source/md.c b/source/md.c index 91baa61..2308b05 100644 --- a/source/md.c +++ b/source/md.c @@ -3071,6 +3071,12 @@ MD_ExprBakeOperatorTableFromList(MD_Arena *arena, MD_ExprOperatorList *list) { 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 { @@ -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); result = _MD_ExprParse_Ctx_MinPrecedence(arena, &sub_ctx, 0); } - else if((node->flags & MD_NodeFlag_HasBracketLeft && node->flags & MD_NodeFlag_HasBracketRight) || - (node->flags & MD_NodeFlag_HasBraceLeft && node->flags & MD_NodeFlag_HasBraceRight)) + else if((node->flags & MD_NodeFlag_HasBracketLeft && node->flags & MD_NodeFlag_HasBracketRight && + 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); // 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_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 _MD_CtxAdvance(ctx); result.node = MD_PushArrayZero(arena, MD_ExprNode, 1); diff --git a/source/md.h b/source/md.h index d949bed..6413c74 100644 --- a/source/md.h +++ b/source/md.h @@ -722,6 +722,8 @@ struct MD_ExprOperatorTable MD_MessageList errors; MD_ExprOperator *call_op; // TODO: Move elsewhere MD_ExprOperator *subscript_op; + MD_ExprOperator *bracket_set_op; + MD_ExprOperator *brace_set_op; }; typedef struct MD_ExprNode MD_ExprNode; diff --git a/tests/expression_tests.c b/tests/expression_tests.c index 22733e5..55a77ac 100644 --- a/tests/expression_tests.c +++ b/tests/expression_tests.c @@ -64,7 +64,9 @@ struct OperatorDescription{ X(AssignRightShift, ">>=", BinaryRightAssociative, 4) \ X(AssignBitwiseAnd, "&=", 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(Comma, ",", Binary, 3)