From e1528a797cdb155d6ebf8d91c5a55ed7d1713156 Mon Sep 17 00:00:00 2001 From: "R. Timothy Edwards" Date: Mon, 6 Jul 2026 10:22:02 -0400 Subject: [PATCH] Corrected the parsing for assignment left-hand-side to allow for whitespace inside the array declaration, as was (correctly) done for pin connections. Previously, "assign x[ 0] = 1'b1" would fail due to "x[" being parsed as a token by itself. Now, upon reading an array opening bracket delimiter, the verilog parser will continue to read tokens until it finds the closing bracket, as it does for pin connections. --- VERSION | 2 +- base/verilog.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index b8dfb32..c826204 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.5.322 +1.5.323 diff --git a/base/verilog.c b/base/verilog.c index b40f02e..c824324 100644 --- a/base/verilog.c +++ b/base/verilog.c @@ -1914,6 +1914,38 @@ skip_endmodule: else { /* "assign" */ SkipTokComments(VLOG_PIN_CHECK_DELIMITERS); char *aptr = strvchr(nexttok, '['); + + /* This is a repeat of code to handle reading of pins, and + * makes sure that all input has been read to the closing + * bracket. There needs to be a single routine to do this, + * or (better) rewrite the parser with lex instead of trying + * to enumerate all the syntax cases separately. + */ + if ((aptr != NULL) && (strvchr(nexttok, ']') == NULL)) + { + /* If a bus expressions has whitespace, then concatenate + * to the closing ']'. + */ + char *array_expr = (char *)MALLOC(1); + char *new_array_expr = NULL; + *array_expr = '\0'; + /* Read to "]" */ + while (nexttok) { + new_array_expr = (char *)MALLOC(strlen(array_expr) + + strlen(nexttok) + 1); + /* Roundabout way to do realloc() becase there is no REALLOC() */ + strcpy(new_array_expr, array_expr); + strcat(new_array_expr, nexttok); + FREE(array_expr); + array_expr = new_array_expr; + if (strchr(nexttok, ']')) break; + SkipTokComments(VLOG_PIN_CHECK_DELIMITERS); + } + if (!nexttok) { + Printf("Unterminated array in assignment %s\n", array_expr); + } + } + if (((aptr == NULL) && (GetBusTok(&wb) == 0)) || ((aptr != NULL) && (GetBus(aptr, &wb) == 0))) { if (aptr != NULL) {