[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Allow newlines within parentheses.

From: Kaz Kylheku
Subject: [PATCH] Allow newlines within parentheses.
Date: Wed, 12 Oct 2022 16:47:03 -0700
User-agent: Roundcube Webmail/1.4.13

* awkgram.y (yylex): If we are not in --posix mode,
and a newline character occurs between parentheses,
indicated by a nonzero count in the in_parens
variable, then we eat the newline instead of generating
a NEWLINE token.
* doc/gawk.texi: Mention together with Gawk extension that
allows newline after certain operators like &&.

diff --git a/awkgram.y b/awkgram.y
index fc35100d..c24e35c5 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -3911,6 +3911,13 @@ yylex(void)
        case '\n':
+               /*
+                * If not in POSIX mode, allow free-form newline in bracketed
+                * and parenthesized expressions, by swallowing '\n' rather than
+                * turning it into a NEWLINE token.
+                */
+               if (! do_posix && in_parens)
+                       goto retry;
                return lasttok = NEWLINE;
        case '#':               /* it's a comment */
diff --git a/doc/gawk.texi b/doc/gawk.texi
index 2535e45a..38ab01e6 100644
--- a/doc/gawk.texi
+++ b/doc/gawk.texi
@@ -3534,6 +3534,19 @@ However, @command{gawk} ignores newlines after any of 
the following
 ,    @{    ?    :    ||    &&    do    else
 @end example
+Also, @command{gawk} ignores newline tokens which occur anywhere
+within parentheses, at any nesting level.  This is regardless of
+the semantics of the parentheses; expression grouping parentheses
+count, as do the parentheses surrounding a funcction call
+argument list, and the delimiting parentheses around the
+controlling expressions of statements
+like @command{if} and @command{while}.
+ printf("%s\n",  # line break allowed here
+        "not standard Awk!");
+@end example
 A newline at any other point is considered the end of the
 statement.@footnote{The @samp{?} and @samp{:} referred to here is the
@@ -3541,7 +3554,7 @@ three-operand conditional expression described in
 @ref{Conditional Exp}.
 Splitting lines after @samp{?} and @samp{:} is a minor @command{gawk}
 extension; if @option{--posix} is specified
-(@pxref{Options}), then this extension is disabled.}
+(@pxref{Options}), then these extensions are disabled.}
 @cindex @code{\} (backslash) @subentry continuing lines and
 @cindex backslash (@code{\}) @subentry continuing lines and

reply via email to

[Prev in Thread] Current Thread [Next in Thread]