eval2: macro argument expression tree parsing

This commit is contained in:
Ryan Fleury
2026-06-26 10:07:02 -06:00
parent d7393b2f65
commit bcbc5e4a2a
6 changed files with 38 additions and 5 deletions
+24
View File
@@ -1990,6 +1990,30 @@ e2_parse_from_string(Arena *arena, E2_ParseState *state, B32 identifier_is_type,
}
}
// rjf: try to resolve it as a macro argument
if(!identifier_mapped && state->top_task != 0 && state->top_task->expr_kind == E2_ExprKind_Macro)
{
U64 macro_arg_num = 0;
{
U64 num = 1;
for(String8Node *n = state->top_task->macro_arg_names.first; n != 0; n = n->next, num += 1)
{
if(str8_match(n->string, identifier, 0))
{
macro_arg_num = num;
break;
}
}
}
if(macro_arg_num != 0)
{
identifier_mapped = 1;
expr = e2_expr(arena, E2_ExprKind_MacroArg);
expr->macro_arg_num = (U32)macro_arg_num;
expr->string = identifier;
}
}
// rjf: build this as a leaf identifier expression - ask the caller if it's a type
if(!identifier_mapped)
{
+2 -2
View File
@@ -56,9 +56,8 @@ typedef enum E2_ParseStatus
//- rjf: caller-provided info
E2_ParseStatus_CheckIdentifierIsType,
E2_ParseStatus_NewMacro,
E2_ParseStatus_FirstCallerRequest = E2_ParseStatus_CheckIdentifierIsType,
E2_ParseStatus_LastCallerRequest = E2_ParseStatus_NewMacro,
E2_ParseStatus_LastCallerRequest = E2_ParseStatus_CheckIdentifierIsType,
}
E2_ParseStatus;
@@ -328,6 +327,7 @@ struct E2_Expr
E2_ExprNode *last_child;
U64 child_count;
E2_ExprKind kind;
U32 macro_arg_num;
Rng1U64 src_range;
String8 string;
};
+1
View File
@@ -5,6 +5,7 @@
E2_ExprKindTable:
{
{Identifier Null 0}
{MacroArg Null 0}
{TypeIdentifier Null 0}
{Numeric Null 0}
{StringLiteral Null 0}
+2 -1
View File
@@ -4,7 +4,7 @@
//- GENERATED CODE
C_LINKAGE_BEGIN
E2_ExprKindInfo e2_expr_kind_info_table[41] =
E2_ExprKindInfo e2_expr_kind_info_table[42] =
{
{0},
{E2_ExprParseKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")},
@@ -12,6 +12,7 @@ E2_ExprKindInfo e2_expr_kind_info_table[41] =
{E2_ExprParseKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")},
{E2_ExprParseKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")},
{E2_ExprParseKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")},
{E2_ExprParseKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")},
{E2_ExprParseKind_Null, 0, str8_lit_comp(""), str8_lit_comp("."), str8_lit_comp(""), str8_lit_comp("")},
{E2_ExprParseKind_Binary, 1, str8_lit_comp(""), str8_lit_comp("["), str8_lit_comp("]"), str8_lit_comp("")},
{E2_ExprParseKind_Call, 1, str8_lit_comp(""), str8_lit_comp("("), str8_lit_comp(")"), str8_lit_comp(",")},
+2 -1
View File
@@ -10,6 +10,7 @@ typedef enum E2_ExprKind
{
E2_ExprKind_Null,
E2_ExprKind_Identifier,
E2_ExprKind_MacroArg,
E2_ExprKind_TypeIdentifier,
E2_ExprKind_Numeric,
E2_ExprKind_StringLiteral,
@@ -131,7 +132,7 @@ E2_TypeKind_LastMeta = E2_TypeKind_MetaDescription,
} E2_TypeKind;
C_LINKAGE_BEGIN
extern E2_ExprKindInfo e2_expr_kind_info_table[41];
extern E2_ExprKindInfo e2_expr_kind_info_table[42];
extern U8 e2_type_kind_basic_byte_size_table[61];
extern String8 e2_type_kind_basic_string_table[61];
+7 -1
View File
@@ -43,10 +43,10 @@ entry_point(CmdLine *cmdline)
// (A)
// int & B
// (1 + (int)&B)
s("bar(a, b) = a + b"),
s("123, 456"),
s("int32 == int32"),
s("foo = 123"),
// s("bar(a, b) = a + b"),
s("1 > 2"),
s("1 ? \"Test\" : 888"),
s("'a'"),
@@ -98,6 +98,12 @@ entry_point(CmdLine *cmdline)
{
str8_list_push(scratch.arena, &msgs, n->string);
}
if(parse.status == E2_ParseStatus_CheckIdentifierIsType)
{
identifier_is_type = identifier_is_type || str8_match(parse.identifier, s("int32"), 0);
identifier_is_type = identifier_is_type || str8_match(parse.identifier, s("float32"), 0);
identifier_is_type = identifier_is_type || str8_match(parse.identifier, s("float64"), 0);
}
if(e2_parse_status_is_terminal(parse.status))
{
break;