From 583ee06232f35f6c41fa510167908a3c62711598 Mon Sep 17 00:00:00 2001 From: Giles Atkinson <“gatk555@gmail.com”> Date: Fri, 23 Sep 2022 10:13:06 +0100 Subject: [PATCH] Fix bug reported by Anant Devi in user discussion 22/9/22. A function call, vi(v) was misparsed as the special token i(vsource) for the current in a voltage source. --- src/frontend/parse.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/frontend/parse.c b/src/frontend/parse.c index f73a8df1c..c1839e195 100644 --- a/src/frontend/parse.c +++ b/src/frontend/parse.c @@ -885,7 +885,7 @@ int PPlex(YYSTYPE *lvalp, struct PPltype *llocp, char **line) * vthing#branch * i(vthing) */ - for (; *sbuf && !strchr(specials, *sbuf); sbuf++) + for (; *sbuf && !strchr(specials, *sbuf); sbuf++) { if (*sbuf == '@') { atsign = 1; } @@ -897,16 +897,22 @@ int PPlex(YYSTYPE *lvalp, struct PPltype *llocp, char **line) sbuf++; } break; - } - /* keep the identifier i(vss) as a single token, even as dc1.i(vss) */ - else if (prefix("i(v", sbuf)) { + } else if ((sbuf == start || sbuf[-1] == '.') && + prefix("i(v", sbuf)) { + /* Special case for current through voltage source: + * keep the identifier i(vss) as a single token, + * even as dc1.i(vss). + */ + if (get_r_paren(&sbuf) == 1) { - fprintf(stderr, "Error: missing ')' in token\n %s\n", start); + fprintf(stderr, + "Error: missing ')' in token\n %s\n", + start); break; } - sbuf--; + sbuf--; // Point at ')', last accepted char. } - + } lvalp->str = copy_substring(start, sbuf); lexer_return(TOK_STR, 0); }