fix parse error visualization; fix invalid cases in eval expression parser

This commit is contained in:
Ryan Fleury
2024-08-20 14:12:40 -07:00
parent c896d05afc
commit 67a719f2c6
4 changed files with 31 additions and 18 deletions
+10 -4
View File
@@ -2774,7 +2774,6 @@ df_watch_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_WatchViewS
//- rjf: draw start of cache lines in expansions
//
if((row_eval.mode == E_Mode_Offset || row_eval.mode == E_Mode_Null) &&
row_eval.msgs.count == 0 &&
row_eval.value.u64%64 == 0 && row->depth > 0 &&
!row_expanded)
{
@@ -2789,7 +2788,6 @@ df_watch_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_WatchViewS
//- rjf: draw mid-row cache line boundaries in expansions
//
if((row_eval.mode == E_Mode_Offset || row_eval.mode == E_Mode_Null) &&
row_eval.msgs.max_kind == E_MsgKind_Null &&
row_eval.value.u64%64 != 0 &&
row->depth > 0 &&
!row_expanded)
@@ -2850,10 +2848,18 @@ df_watch_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_WatchViewS
}goto value_cell;
value_cell:;
{
if(cell_eval.msgs.max_kind > E_MsgKind_Null)
E_MsgList msgs = cell_eval.msgs;
if(row->depth == 0 && row->string.size != 0)
{
E_TokenArray tokens = e_token_array_from_text(scratch.arena, row->string);
E_Parse parse = e_parse_expr_from_text_tokens(scratch.arena, row->string, &tokens);
e_msg_list_concat_in_place(&parse.msgs, &msgs);
msgs = parse.msgs;
}
if(msgs.max_kind > E_MsgKind_Null)
{
String8List strings = {0};
for(E_Msg *msg = cell_eval.msgs.first; msg != 0; msg = msg->next)
for(E_Msg *msg = msgs.first; msg != 0; msg = msg->next)
{
str8_list_push(scratch.arena, &strings, msg->text);
}
+2 -2
View File
@@ -84,8 +84,8 @@ E_ExprKindTable:
{ Deref UnaryPrefix 2 "*" "*" "" "" }
{ Address UnaryPrefix 2 "&" "&" "" "" }
{ Cast Null 0 "cast" "" "" "" }
{ Sizeof UnaryPrefix 0 "sizeof" "sizeof" "" "" }
{ Cast Null 1 "cast" "" "" "" }
{ Sizeof UnaryPrefix 1 "sizeof" "sizeof" "" "" }
{ Neg UnaryPrefix 2 "-" "-" "" "" }
{ LogNot UnaryPrefix 2 "!" "!" "" "" }
+17 -10
View File
@@ -1191,14 +1191,21 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
it = nested_parse.last_token;
// rjf: build cast-to-U64*, and dereference operators
E_Expr *type = e_push_expr(arena, E_ExprKind_TypeIdent, token_string.str);
type->type_key = e_type_key_cons_ptr(e_type_key_basic(E_TypeKind_U64));
E_Expr *casted = atom;
E_Expr *cast = e_push_expr(arena, E_ExprKind_Cast, token_string.str);
e_expr_push_child(cast, type);
e_expr_push_child(cast, casted);
atom = e_push_expr(arena, E_ExprKind_Deref, token_string.str);
e_expr_push_child(atom, cast);
if(nested_parse.expr == &e_expr_nil)
{
e_msgf(arena, &result.msgs, E_MsgKind_MalformedInput, token_string.str, "Expected expression following `[`.");
}
else
{
E_Expr *type = e_push_expr(arena, E_ExprKind_TypeIdent, token_string.str);
type->type_key = e_type_key_cons_ptr(e_type_key_basic(E_TypeKind_U64));
E_Expr *casted = atom;
E_Expr *cast = e_push_expr(arena, E_ExprKind_Cast, token_string.str);
e_expr_push_child(cast, type);
e_expr_push_child(cast, casted);
atom = e_push_expr(arena, E_ExprKind_Deref, token_string.str);
e_expr_push_child(atom, cast);
}
// rjf: expect ]
E_Token close_paren_maybe = e_token_at_it(it, tokens);
@@ -1814,7 +1821,7 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
}
//- rjf: upgrade atom w/ previously parsed prefix unaries
if(atom == &e_expr_nil && first_prefix_unary != 0 && first_prefix_unary->cast_expr != 0)
if(atom == &e_expr_nil && first_prefix_unary != 0 && first_prefix_unary->cast_expr != &e_expr_nil)
{
atom = first_prefix_unary->cast_expr;
for(PrefixUnaryNode *prefix_unary = first_prefix_unary->next;
@@ -1830,7 +1837,7 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
e_expr_push_child(atom, rhs);
}
}
else if(atom == 0 && first_prefix_unary != 0)
else if(atom == &e_expr_nil && first_prefix_unary != 0)
{
e_msgf(arena, &result.msgs, E_MsgKind_MalformedInput, last_prefix_unary->location, "Missing expression.");
}
+2 -2
View File
@@ -84,8 +84,8 @@ E_OpInfo e_expr_kind_op_info_table[43] =
{ E_OpKind_Null, 0, str8_lit_comp(""), str8_lit_comp("."), str8_lit_comp("MemberAccess") },
{ E_OpKind_UnaryPrefix, 2, str8_lit_comp("*"), str8_lit_comp(""), str8_lit_comp("Deref") },
{ E_OpKind_UnaryPrefix, 2, str8_lit_comp("&"), str8_lit_comp(""), str8_lit_comp("Address") },
{ E_OpKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("Cast") },
{ E_OpKind_UnaryPrefix, 0, str8_lit_comp("sizeof"), str8_lit_comp(""), str8_lit_comp("Sizeof") },
{ E_OpKind_Null, 1, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("Cast") },
{ E_OpKind_UnaryPrefix, 1, str8_lit_comp("sizeof"), str8_lit_comp(""), str8_lit_comp("Sizeof") },
{ E_OpKind_UnaryPrefix, 2, str8_lit_comp("-"), str8_lit_comp(""), str8_lit_comp("Neg") },
{ E_OpKind_UnaryPrefix, 2, str8_lit_comp("!"), str8_lit_comp(""), str8_lit_comp("LogNot") },
{ E_OpKind_UnaryPrefix, 2, str8_lit_comp("~"), str8_lit_comp(""), str8_lit_comp("BitNot") },