On 2022-10-12, Kaz Kylheku <
[email protected]> wrote:
I have a fork of gawk called egawk (enhanced gnu awk) where this
approach could be tried.
I got it working very easily, at the proof of concept stage,
not having validated test cases and such:
Patched:
~/gawk$ ./gawk 'BEGIN {
if (x +
x == 0) { print "blah" } }'
blah
Stock distro gawk:
~/gawk$ gawk 'BEGIN {
if (x +
x == 0) { print "blah" } }'
gawk: cmd. line:3: if (x +
gawk: cmd. line:3: ^ unexpected newline or end of string
gawk: cmd. line:3: x == 0) { print "blah" } }
gawk: cmd. line:3: ^ syntax error
Patched, in --posix mode:
~/gawk$ ./gawk --posix 'BEGIN {
if (x +
x == 0) { print "blah" } }'
gawk: cmd. line:3: if (x +
gawk: cmd. line:3: ^ unexpected newline or end of string
gawk: cmd. line:3: x == 0) { print "blah" } }
gawk: cmd. line:3: ^ syntax error
Patch:
~/gawk$ git diff awkgram.y
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':
sourceline++;
+ /*
+ * 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 */
Very easy; the lexer already counts parentheses, so nothing to do.
All of the above said and patched, note that you can use backslash continuations, which is a bit ugly:
~/gawk$ gawk 'BEGIN {
if (x + \
x == 0) { print "blah" } }'
blah
So before trying to upstreaming, you need a convincing argument why standard-conforming backslash-newline continuations aren't good enough.
--
TXR Programming Language:
http://nongnu.org/txr
Cygnal: C