More helpful errors when parsing expressions.

This commit is contained in:
Dianne Skoll
2025-10-30 14:30:29 -04:00
parent 35e222967c
commit 05ead8c40d
3 changed files with 24 additions and 6 deletions

View File

@@ -137,6 +137,7 @@
#define E_NO_MB 113 #define E_NO_MB 113
#define E_BAD_MB_SEQ 114 #define E_BAD_MB_SEQ 114
#define E_EXPR_NODES_EXCEEDED 115 #define E_EXPR_NODES_EXCEEDED 115
#define E_EXPECTING_EOXPR 116
#ifdef MK_GLOBALS #ifdef MK_GLOBALS
#undef EXTERN #undef EXTERN
#define EXTERN #define EXTERN
@@ -270,6 +271,7 @@ EXTERN char *ErrMsg[]
/* E_NO_MB */ "C library does not support multibyte characters", /* E_NO_MB */ "C library does not support multibyte characters",
/* E_BAD_MB_SEQ */ "Invalid multibyte sequence", /* E_BAD_MB_SEQ */ "Invalid multibyte sequence",
/* E_EXPR_NODES_EXCEEDED */ "Maximum expression complexity exceeded", /* E_EXPR_NODES_EXCEEDED */ "Maximum expression complexity exceeded",
/* E_EXPECTING_EOXPR */ "Expecting end-of-expression",
} }
#endif /* MK_GLOBALS */ #endif /* MK_GLOBALS */
; ;

View File

@@ -2759,9 +2759,20 @@ expr_node *parse_expression(char const **e, int *r, Var *locals)
print_expr_tree(node, ErrFp); print_expr_tree(node, ErrFp);
fprintf(ErrFp, "\n"); fprintf(ErrFp, "\n");
} }
if (**e && (**e != ']')) { }
if (**e && (**e != ']')) {
if (DebugFlag & DB_PARSE_EXPR) {
fprintf(ErrFp, " Unparsed: %s\n", *e); fprintf(ErrFp, " Unparsed: %s\n", *e);
} }
if (*r == OK) {
*r = E_EXPECTING_EOXPR;
}
}
if (*r != OK) {
if (node) {
free_expr_tree(node);
node = NULL;
}
} }
if (!SuppressErrorOutputInCatch) { if (!SuppressErrorOutputInCatch) {
if (*r == E_EXPECT_COMMA || if (*r == E_EXPECT_COMMA ||
@@ -2771,6 +2782,7 @@ expr_node *parse_expression(char const **e, int *r, Var *locals)
*r == E_2FEW_ARGS || *r == E_2FEW_ARGS ||
*r == E_PARSE_ERR || *r == E_PARSE_ERR ||
*r == E_EOLN || *r == E_EOLN ||
*r == E_EXPECTING_EOXPR ||
*r == E_BAD_NUMBER || *r == E_BAD_NUMBER ||
*r == E_BAD_DATE || *r == E_BAD_DATE ||
*r == E_BAD_TIME || *r == E_BAD_TIME ||

View File

@@ -5040,8 +5040,9 @@ set a 7 * "Cabbage! "
# Should result in errors # Should result in errors
set pqxya 1+2) set pqxya 1+2)
1 + 2 => 3 1+2)
../tests/test.rem(1014): Expecting end-of-line ^-- here
../tests/test.rem(1014): Expecting end-of-expression
# Should result in an error # Should result in an error
REM Tue OMIT 2024-01-01 MSG Wookie REM Tue OMIT 2024-01-01 MSG Wookie
@@ -16669,7 +16670,7 @@ Expression nodes high-water: 302076
Expression nodes leaked: 0 Expression nodes leaked: 0
Parse level high-water: 34 Parse level high-water: 34
Max expr node evaluations per line: 2001 Max expr node evaluations per line: 2001
Total expression node evaluations: 106467 Total expression node evaluations: 106464
Test 2 Test 2
@@ -23905,7 +23906,9 @@ Parsed expression: 1||1
Parsed expression: 2 Parsed expression: 2
=> 2 => 2
Unparsed: , 3 Unparsed: , 3
../tests/expr.rem(15): Expecting end-of-line , 3
^-- here
../tests/expr.rem(15): Expecting end-of-expression
Parsed expression: iif(0, "foo", 0, "bar", 1, "blech", 0, "quux", 1, "borhy", "wacka") Parsed expression: iif(0, "foo", 0, "bar", 1, "blech", 0, "quux", 1, "borhy", "wacka")
=> (Iif 0 "foo" 0 "bar" 1 "blech" 0 "quux" 1 "borhy" "wacka") => (Iif 0 "foo" 0 "bar" 1 "blech" 0 "quux" 1 "borhy" "wacka")
iif(0, ?, 0, ?, 1, "blech", ?, ?, ?, ?, ?) => "blech" iif(0, ?, 0, ?, 1, "blech", ?, ?, ?, ?, ?) => "blech"
@@ -24284,7 +24287,7 @@ Expression nodes high-water: 499
Expression nodes leaked: 0 Expression nodes leaked: 0
Parse level high-water: 2001 Parse level high-water: 2001
Max expr node evaluations per line: 499 Max expr node evaluations per line: 499
Total expression node evaluations: 632 Total expression node evaluations: 631
-stdin-(14): Unmatched PUSH-OMIT-CONTEXT at -stdin-(7) -stdin-(14): Unmatched PUSH-OMIT-CONTEXT at -stdin-(7)
-stdin-(14): Warning: PUSH-OMIT-CONTEXT without matching POP-OMIT-CONTEXT -stdin-(14): Warning: PUSH-OMIT-CONTEXT without matching POP-OMIT-CONTEXT
No reminders. No reminders.
@@ -25063,6 +25066,7 @@ TRANSLATE "TZ specified for non-timed reminder" ""
TRANSLATE "C library does not support multibyte characters" "" TRANSLATE "C library does not support multibyte characters" ""
TRANSLATE "Invalid multibyte sequence" "" TRANSLATE "Invalid multibyte sequence" ""
TRANSLATE "Maximum expression complexity exceeded" "" TRANSLATE "Maximum expression complexity exceeded" ""
TRANSLATE "Expecting end-of-expression" ""
# Other Messages # Other Messages
TRANSLATE "%s function `%s' defined at %s(%s) does not use its argument" "" TRANSLATE "%s function `%s' defined at %s(%s) does not use its argument" ""