mirror of
https://github.com/Ed94/metadesk.git
synced 2026-07-23 07:57:51 +00:00
[expr parser] Treat all sets as leaves (note 1a).
This commit is contained in:
+8
-11
@@ -3379,6 +3379,9 @@ MD_ExprBakeOperatorTableFromList(MD_Arena *arena, MD_ExprOprList *list)
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO(mal): Allow "[]" and "()" only as unary postfix
|
||||
// TODO(mal): Disallow all other set types ("[)", "(]", "{}") from becoming operators
|
||||
|
||||
for(MD_ExprOpr *op2 = list->first;
|
||||
op2 != op;
|
||||
op2 = op2->next)
|
||||
@@ -3520,8 +3523,6 @@ MD_ExprParse_MakeContext(MD_ExprOprTable *op_table)
|
||||
MD_ExprParseCtx result = MD_ZERO_STRUCT;
|
||||
result.op_table = op_table;
|
||||
|
||||
result.accel.bracket_set_op = MD_ExprOprFromKindString(op_table, MD_ExprOprKind_Prefix, MD_S8Lit("[]"));
|
||||
result.accel.brace_set_op = MD_ExprOprFromKindString(op_table, MD_ExprOprKind_Prefix, MD_S8Lit("{}"));
|
||||
result.accel.call_op = MD_ExprOprFromKindString(op_table, MD_ExprOprKind_Postfix, MD_S8Lit("()"));
|
||||
result.accel.subscript_op = MD_ExprOprFromKindString(op_table, MD_ExprOprKind_Binary, MD_S8Lit("[]"));
|
||||
|
||||
@@ -3604,16 +3605,12 @@ MD_ExprParse_Atom(MD_Arena *arena, MD_ExprParseCtx *ctx, MD_Node **iter,
|
||||
*iter = MD_NodeNextWithLimit(*iter, opl);
|
||||
result = MD_ExprParse_TopLevel(arena, ctx, node->first_child, MD_NilNode());
|
||||
}
|
||||
// TODO(allen): this part seems a bit odd. I think any (delimited) set
|
||||
// should get this treatment, without making these operators to enable them.
|
||||
else if(((node->flags & MD_NodeFlag_HasBracketLeft) && (node->flags & MD_NodeFlag_HasBracketRight) &&
|
||||
ctx->accel.bracket_set_op) ||
|
||||
((node->flags & MD_NodeFlag_HasBraceLeft) &&
|
||||
(node->flags & MD_NodeFlag_HasBraceRight) &&
|
||||
ctx->accel.brace_set_op))
|
||||
{
|
||||
else if(((node->flags & MD_NodeFlag_HasBraceLeft) && (node->flags & MD_NodeFlag_HasBraceRight)) ||
|
||||
((node->flags & MD_NodeFlag_HasBracketLeft) && (node->flags & MD_NodeFlag_HasBracketRight)) ||
|
||||
((node->flags & MD_NodeFlag_HasBracketLeft) && (node->flags & MD_NodeFlag_HasParenRight)) ||
|
||||
((node->flags & MD_NodeFlag_HasParenLeft) && (node->flags & MD_NodeFlag_HasBracketRight)))
|
||||
{ // NOTE(mal): Unparsed leaf sets ({...}, [...], [...), (...])
|
||||
*iter = MD_NodeNextWithLimit(*iter, opl);
|
||||
// NOTE(mal): Unparsed leaf sets ({ ... }, [ ... ])
|
||||
result = MD_Expr_NewLeaf(arena, node);
|
||||
}
|
||||
else if(MD_ExprParse_OprConsume(ctx, iter, opl, MD_ExprOprKind_Prefix, 1, &op))
|
||||
|
||||
@@ -785,8 +785,6 @@ struct MD_ExprParseCtx
|
||||
{
|
||||
MD_ExprOpr *call_op;
|
||||
MD_ExprOpr *subscript_op;
|
||||
MD_ExprOpr *bracket_set_op;
|
||||
MD_ExprOpr *brace_set_op;
|
||||
} accel;
|
||||
|
||||
MD_MessageList errors;
|
||||
|
||||
+21
-11
@@ -75,8 +75,6 @@ X(AssignBitwiseXor, "^=", BinaryRightAssociative, 4) \
|
||||
X(AssignBitwiseOr, "|=", BinaryRightAssociative, 4)
|
||||
|
||||
// TODO(allen): I don't think we want to do this
|
||||
// X(BracketSet, "[]", Prefix, 3)
|
||||
// X(BraceSet, "{}", Prefix, 3)
|
||||
// X(Cast "()", Prefix, 17)
|
||||
// X(Comma, ",", Binary, 3)
|
||||
|
||||
@@ -193,19 +191,30 @@ static void parenthesize_exclude_outer(MD_Arena *arena, OperatorDescription *des
|
||||
}
|
||||
else
|
||||
{
|
||||
if(node->md_node->flags & MD_NodeFlag_HasBracketLeft &&
|
||||
node->md_node->flags & MD_NodeFlag_HasBracketRight)
|
||||
if(node->md_node->flags & MD_NodeFlag_HasParenLeft)
|
||||
{
|
||||
MD_S8ListPush(arena, l, MD_S8Lit("[...]"));
|
||||
MD_S8ListPush(arena, l, MD_S8Lit("("));
|
||||
}
|
||||
else if(node->md_node->flags & MD_NodeFlag_HasBraceLeft &&
|
||||
node->md_node->flags & MD_NodeFlag_HasBraceRight)
|
||||
else if(node->md_node->flags & MD_NodeFlag_HasBraceLeft)
|
||||
{
|
||||
MD_S8ListPush(arena, l, MD_S8Lit("{...}"));
|
||||
MD_S8ListPush(arena, l, MD_S8Lit("{"));
|
||||
}
|
||||
else
|
||||
else if(node->md_node->flags & MD_NodeFlag_HasBracketLeft)
|
||||
{
|
||||
MD_S8ListPush(arena, l, MD_S8Lit("???"));
|
||||
MD_S8ListPush(arena, l, MD_S8Lit("["));
|
||||
}
|
||||
|
||||
MD_S8ListPush(arena, l, MD_S8Lit("..."));
|
||||
|
||||
if(node->md_node->flags & MD_NodeFlag_HasParenRight)
|
||||
{
|
||||
MD_S8ListPush(arena, l, MD_S8Lit(")"));
|
||||
}
|
||||
else if(node->md_node->flags & MD_NodeFlag_HasBraceRight){
|
||||
MD_S8ListPush(arena, l, MD_S8Lit("}"));
|
||||
}
|
||||
else if(node->md_node->flags & MD_NodeFlag_HasBracketRight){
|
||||
MD_S8ListPush(arena, l, MD_S8Lit("]"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -316,7 +325,7 @@ operator_array[Op_##name].op = (MD_ExprOpr){ .op_id = Op_##name, .kind = MD_Expr
|
||||
{ .q = "a(b,c)", .a = "a(...)" },
|
||||
{ .q = "a.b()", .a = "(a . b)(...)" },
|
||||
{ .q = "sizeof a + b", .a = "(sizeof a) + b" },
|
||||
{ .q = "[1, 100] * n", .a = "[...] * n" },
|
||||
{ .q = "[1, 100] * [1)",.a = "[...] * [...)" },
|
||||
{ .q = "a[b+c]", .a = "a[b + c]" },
|
||||
{ .q = "a + b[c[d]+e]", .a = "a + (b[(c[d]) + e])" },
|
||||
{ .q = "a++ + b", .a = "(a++) + b" },
|
||||
@@ -356,6 +365,7 @@ operator_array[Op_##name].op = (MD_ExprOpr){ .op_id = Op_##name, .kind = MD_Expr
|
||||
{ .q = "a+", .a = "", ExpressionErrorKind_Expr, 2},
|
||||
{ .q = "a 1", .a = "", ExpressionErrorKind_Expr, 2},
|
||||
{ .q = "a + (a+)", .a = "", ExpressionErrorKind_Expr, 7},
|
||||
// TODO(mal): This test should not generate an error when [] is postfix and a+ remains unparsed
|
||||
{ .q = "a[a+]", .a = "", ExpressionErrorKind_Expr, 4},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user