[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Make awk more friendly to multiline function declaration
From: |
Wolfgang Laun |
Subject: |
Re: Make awk more friendly to multiline function declaration |
Date: |
Mon, 28 Mar 2022 15:45:17 +0200 |
The current rule lets you use an unescaped newline after only eight
distinct lexical symbols. You propose to add a rule to "ignore a newline if
it occurs after an *identifier *if this identifier occurs *within the set
of parentheses* used to bracket the parameter list after *function *followed
by an identifier. Thus you extend a simple lexical (regular grammar) rule
by a context-sensitive rule which needs to have the parser (which groups
lexical tokens into sentences of the language) interact with the scanner
that identifies numbers, word symbols and symbols. This is something that
is against all good design rules for a compiler or interpreter.
Moreover, making a "good case" for tolerance of line breaks in a parameter
list will spur others to make similar "good cases" for doing the same
within several other constructs, e.g., within the parentheses of an if or
while statement, a function call, and so on. Ultimately, line end as a
statement terminator is bound to become a rather hazy affair.
Regards
-W
On Sun, 27 Mar 2022 at 13:58, Peng Yu <pengyu.ut@gmail.com> wrote:
> 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?
>
> --
> Regards,
> Peng
>
--
Wolfgang Laun