diff --git a/src/frontend/parse.c b/src/frontend/parse.c index d75005d65..d27b0103e 100644 --- a/src/frontend/parse.c +++ b/src/frontend/parse.c @@ -667,13 +667,23 @@ PPlex(YYSTYPE *lvalp, struct PPltype *llocp, char **line) /* It is bad how we have to recognise '[' -- sometimes * it is part of a word, when it defines a parameter * name, and otherwise it isn't. - * va, ']' too + * + * what is valid here ? + * foo dc1.foo dc1.@m1[vth] + * this too ? + * vthing#branch + * should we convert the pseudo identifier ? + * i(v5) --> v5#branch */ for (; *sbuf && !strchr(specials, *sbuf); sbuf++) if (*sbuf == '@') atsign = 1; - else if (!atsign && (*sbuf == '[' || *sbuf == ']')) + else if (!atsign && *sbuf == '[') break; + else if (atsign && *sbuf == ']') { + sbuf++; + break; + } lvalp->str = copy_substring(start, sbuf); lexer_return(TOK_STR, 0); diff --git a/tests/regression/misc/Makefile.am b/tests/regression/misc/Makefile.am index df99688cc..cabd923d8 100644 --- a/tests/regression/misc/Makefile.am +++ b/tests/regression/misc/Makefile.am @@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in -TESTS = bugs-1.cir dollar-1.cir empty-1.cir resume-1.cir log-functions-1.cir +TESTS = bugs-1.cir bugs-2.cir dollar-1.cir empty-1.cir resume-1.cir log-functions-1.cir TESTS_ENVIRONMENT = ngspice_vpath=$(srcdir) $(SHELL) $(top_srcdir)/tests/bin/check.sh $(top_builddir)/src/ngspice diff --git a/tests/regression/misc/bugs-2.cir b/tests/regression/misc/bugs-2.cir new file mode 100644 index 000000000..1e4014f51 --- /dev/null +++ b/tests/regression/misc/bugs-2.cir @@ -0,0 +1,42 @@ +parser test +* +* test capability to parse @foo[bar][42] +* (exec-spice "ngspice %s" t) + +v1 1 0 dc=0 + +.control + +save @v1[dc] + +dc v1 0 1 250m + +let foo = @v1[dc] + +let gold = 500m +let bar = foo[2] +let baz = @v1[dc][2] + +let fail_count = 0 + +if bar <> 0.5 + echo "ERROR: bar = $&bar should be 0.5" + let fail_count = fail_count + 1 +end + +if baz <> 0.5 + echo "ERROR: baz = $&baz should be 0.5" + let fail_count = fail_count + 1 +end + +if fail_count > 0 + echo "ERROR: $&fail_count tests failed" + quit 1 +else + echo "INFO: $&fail_count tests failed" + quit 0 +end + +.endc + +.end diff --git a/tests/regression/misc/bugs-2.out b/tests/regression/misc/bugs-2.out new file mode 100644 index 000000000..021d13c9e --- /dev/null +++ b/tests/regression/misc/bugs-2.out @@ -0,0 +1,8 @@ + +Circuit: parser test + +Doing analysis at TEMP = 27.000000 and TNOM = 27.000000 + + +No. of Data Rows : 5 +INFO: 0 tests failed