diff options
author | Steve Bennett <steveb@workware.net.au> | 2023-11-23 08:08:26 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2024-02-02 11:22:30 +1000 |
commit | 172b5c42010d329e84e498e9347c7f09c9b923e2 (patch) | |
tree | e0e81908c5c84ece8ef581e7037114e3ae4fd380 /jim.c | |
parent | a227bf74d2fc5013fed3d3de025086c586bc950c (diff) | |
download | jimtcl-172b5c42010d329e84e498e9347c7f09c9b923e2.zip jimtcl-172b5c42010d329e84e498e9347c7f09c9b923e2.tar.gz jimtcl-172b5c42010d329e84e498e9347c7f09c9b923e2.tar.bz2 |
expr: better error message on nested $()
And explain in the manual that it isn't allowed.
Fixes: #285
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'jim.c')
-rw-r--r-- | jim.c | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -1281,6 +1281,7 @@ struct JimParserCtx int inquote; /* Parsing a quoted string */ int comment; /* Non zero if the next chars may be a comment. */ struct JimParseMissing missing; /* Details of any missing quotes, etc. */ + const char *errmsg; /* Additional error message, or NULL if none */ }; static int JimParseScript(struct JimParserCtx *pc); @@ -9060,6 +9061,8 @@ static const struct Jim_ExprOperator Jim_ExprOperators[] = { static int JimParseExpression(struct JimParserCtx *pc) { + pc->errmsg = NULL; + while (1) { /* Discard spaces and quoted newline */ while (isspace(UCHAR(*pc->p)) || (*(pc->p) == '\\' && *(pc->p + 1) == '\n')) { @@ -9110,6 +9113,7 @@ singlechar: else { /* Don't allow expr sugar in expressions */ if (pc->tt == JIM_TT_EXPRSUGAR) { + pc->errmsg = "nesting expr in expr is not allowed"; return JIM_ERR; } return JIM_OK; @@ -9257,6 +9261,7 @@ static int JimParseExprOperator(struct JimParserCtx *pc) p++; } if (*p != '(') { + pc->errmsg = "function requires parentheses"; return JIM_ERR; } } @@ -9740,6 +9745,9 @@ static int SetExprFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr) if (JimParseExpression(&parser) != JIM_OK) { ScriptTokenListFree(&tokenlist); Jim_SetResultFormatted(interp, "syntax error in expression: \"%#s\"", objPtr); + if (parser.errmsg) { + Jim_AppendStrings(interp, Jim_GetResult(interp), ": ", parser.errmsg, NULL); + } expr = NULL; goto err; } |