From f00e74ffc73f6ba6fe74fb7a26319770b8c3792c Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 14 Apr 2022 07:00:15 -0700 Subject: @let: allow trailing comma. We allow forms like @let(x,) and @let(x, y=1,) with the trailing comma. This is helpful for code generators and macros, which can then treat temporary variables as comma-terminated items. * awkgram.y (let_var_list_opt): Add a production which matches a trailing comma after let_var_list. * test/let1.awk, test/let1.ok: Test cases. * doc/gawkt.texi, doc/gawktexi.in: Trailing comma documented. * awkgram.c: Regenerated with Bison 3.8. --- doc/gawk.texi | 7 ++++++- doc/gawktexi.in | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'doc') diff --git a/doc/gawk.texi b/doc/gawk.texi index dea485c6..2535e45a 100644 --- a/doc/gawk.texi +++ b/doc/gawk.texi @@ -21658,7 +21658,7 @@ statement. The @code{@@let} statement is introduced by the @code{@@} symbol followed by the special keyword @code{let}. These tokens are -then followed by a comma-separated list of variable declarators, +then followed by a comma-separated or comma-terminated list of variable declarators, enclosed in parentheses. After the parentheses comes a required statement, The list of variables may be empty. @@ -21809,6 +21809,11 @@ The @code{print} statement is then executed in the scope of the rightmost @code{x}. The initializing expressions @code{x + 1} have the previous @code{x} still in scope. +The @code{@@let} statement allows a trailing comma after the last +variable declarator. Effectively, the declarators can be regarded +as either comma-separated or comma-terminated. Comma termination is +easier to deal with in macro preprocessing and code generation. + @node Pass By Value/Reference @subsubsection Passing Function Arguments by Value Or by Reference diff --git a/doc/gawktexi.in b/doc/gawktexi.in index 651bd8d2..0bb4f4dc 100644 --- a/doc/gawktexi.in +++ b/doc/gawktexi.in @@ -20570,7 +20570,7 @@ statement. The @code{@@let} statement is introduced by the @code{@@} symbol followed by the special keyword @code{let}. These tokens are -then followed by a comma-separated list of variable declarators, +then followed by a comma-separated or comma-terminated list of variable declarators, enclosed in parentheses. After the parentheses comes a required statement, The list of variables may be empty. @@ -20721,6 +20721,11 @@ The @code{print} statement is then executed in the scope of the rightmost @code{x}. The initializing expressions @code{x + 1} have the previous @code{x} still in scope. +The @code{@@let} statement allows a trailing comma after the last +variable declarator. Effectively, the declarators can be regarded +as either comma-separated or comma-terminated. Comma termination is +easier to deal with in macro preprocessing and code generation. + @node Pass By Value/Reference @subsubsection Passing Function Arguments by Value Or by Reference -- cgit v1.2.3