[Top][All Lists]

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

Make awk more friendly to multiline function declaration

From: Peng Yu
Subject: Make awk more friendly to multiline function declaration
Date: Sun, 27 Mar 2022 06:57:46 -0500

I see the following error.

$ awk 'function f(x
, y) {
  return x+y
BEGIN { print f(1, 2) }'
awk: cmd. line:2: function f(x
awk: cmd. line:2:             ^ unexpected newline or end of string

If I move the comma before y to the line of x, the error disappears.

Adding a backslash after x also solves the problem, but it seems that this
requirement is artificial. Because the parentheses enclose the arguments x
and y, there is no way that people should mistake them as being separate
statements. Therefore, I think the grammar of awk should be made more
user-friendly, in this case, by removing the requirement of backslash after
"x" when there is a comma in the next line. Does this suggestion make sense?


reply via email to

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