diff --git a/src/expr.c b/src/expr.c index 6db3be45..5e23addc 100644 --- a/src/expr.c +++ b/src/expr.c @@ -199,6 +199,46 @@ static UserFunc *CurrentUserFunc = NULL; /* How many expr_node objects to allocate at a time */ #define ALLOC_CHUNK 64 +static char const * +find_end_of_expr(char const *s) +{ + char const *e = s; + int in_quoted_string = 0; + int escaped = 0; + + while(*e) { + if (in_quoted_string) { + if (escaped) { + escaped = 0; + e++; + continue; + } + if (*e == '\\') { + escaped = 1; + e++; + continue; + } + if (*e == '"') { + in_quoted_string = 0; + e++; + continue; + } + e++; + continue; + } + if (*e == '"') { + in_quoted_string = 1; + e++; + continue; + } + if (*e == ']') { + break; + } + e++; + } + return e; +} + /***************************************************************/ /* */ /* alloc_expr_node - allocate an expr_node object */ @@ -2501,6 +2541,7 @@ expr_node *parse_expression(char const **e, int *r, Var *locals) { char const *orig = *e; char const *o2 = *e; + char const *end_of_expr; if (ExpressionEvaluationDisabled) { *r = E_EXPR_DISABLED; return NULL; @@ -2536,16 +2577,17 @@ expr_node *parse_expression(char const **e, int *r, Var *locals) *r == E_BAD_DATE || *r == E_BAD_TIME || *r == E_ILLEGAL_CHAR) { - orig = o2; - while (*orig) { + end_of_expr = find_end_of_expr(orig); + while (**e && isempty(**e)) { + (*e)++; + } + while (*orig && ((orig < end_of_expr) || (orig <= *e))) { if (*orig == '\n') { fprintf(ErrFp, " "); - orig++; - } else if (*orig == ']' && ! *(orig+1)) { - break; } else { - fprintf(ErrFp, "%c", *orig++); + fprintf(ErrFp, "%c", *orig); } + orig++; } fprintf(ErrFp, "\n"); orig = o2; diff --git a/tests/test-rem b/tests/test-rem index 416257c5..8e8180aa 100644 --- a/tests/test-rem +++ b/tests/test-rem @@ -633,6 +633,14 @@ fi # Torture test #2 ../src/remind ../tests/torture2.rem >> ../tests/test.out 2>&1 +# Expression error-reporting +../src/remind -de - 1 Feb 2024 <<'EOF' >> ../tests/test.out 2>&1 +set a 8 * "]]]" & 6 +msg [8 * "]]]" & 6] is weird +set a 9 * +set a 9 * ] +EOF + # Languages for i in ../include/lang/??.rem ; do ../src/remind -r -q "-ii=\"$i\"" ../tests/tstlang.rem 1 Feb 2024 13:34 >> ../tests/test.out 2>&1 diff --git a/tests/test.cmp b/tests/test.cmp index c499e204..3578e0e3 100644 --- a/tests/test.cmp +++ b/tests/test.cmp @@ -23410,7 +23410,7 @@ max(6, 9, 50) => 50 Parsed expression: max(1, => Error: Illegal character Unparsed: ,1) -max(1,,1) +,1) ^-- here Parsed expression: 5%0 => (% 5 0) @@ -24312,6 +24312,26 @@ Translation hash table statistics: Expression nodes high-water: 300000 Expression nodes leaked: 0 Parse level high-water: 7 +set a 8 * "]]]" & 6 +-stdin-(1): Parse error `&' (did you mean `&&'?) +8 * "]]]" & 6 + ^-- here +msg [8 * "]]]" & 6] is weird +-stdin-(2): Parse error `&' (did you mean `&&'?) +8 * "]]]" & 6 + ^-- here +set a 9 * +-stdin-(3): Unexpected end of line +9 * + ^-- here +set a 9 * ] +-stdin-(4): Illegal character `]' +9 * ] + ^-- here + +Reminders for Thursday, 1st February, 2024: + +No reminders. Agenda pel dijous, 1 de febrer de 2024: Language: ca