aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editors/awk.c15
-rwxr-xr-xtestsuite/awk.tests12
2 files changed, 26 insertions, 1 deletions
diff --git a/editors/awk.c b/editors/awk.c
index 90edec82c..d25508e5d 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -1613,12 +1613,25 @@ static void parse_program(char *p)
1613 f = newfunc(t_string); 1613 f = newfunc(t_string);
1614 f->body.first = NULL; 1614 f->body.first = NULL;
1615 f->nargs = 0; 1615 f->nargs = 0;
1616 while (next_token(TC_VARIABLE | TC_SEQTERM) & TC_VARIABLE) { 1616 /* Match func arg list: a comma sep list of >= 0 args, and a close paren */
1617 while (next_token(TC_VARIABLE | TC_SEQTERM | TC_COMMA)) {
1618 /* Either an empty arg list, or trailing comma from prev iter
1619 * must be followed by an arg */
1620 if (f->nargs == 0 && t_tclass == TC_SEQTERM)
1621 break;
1622
1623 /* TC_SEQSTART/TC_COMMA must be followed by TC_VARIABLE */
1624 if (t_tclass != TC_VARIABLE)
1625 syntax_error(EMSG_UNEXP_TOKEN);
1626
1617 v = findvar(ahash, t_string); 1627 v = findvar(ahash, t_string);
1618 v->x.aidx = f->nargs++; 1628 v->x.aidx = f->nargs++;
1619 1629
1630 /* Arg followed either by end of arg list or 1 comma */
1620 if (next_token(TC_COMMA | TC_SEQTERM) & TC_SEQTERM) 1631 if (next_token(TC_COMMA | TC_SEQTERM) & TC_SEQTERM)
1621 break; 1632 break;
1633 if (t_tclass != TC_COMMA)
1634 syntax_error(EMSG_UNEXP_TOKEN);
1622 } 1635 }
1623 seq = &f->body; 1636 seq = &f->body;
1624 chain_group(); 1637 chain_group();
diff --git a/testsuite/awk.tests b/testsuite/awk.tests
index 03fedf771..0db6a26e4 100755
--- a/testsuite/awk.tests
+++ b/testsuite/awk.tests
@@ -280,6 +280,18 @@ testing "awk 'delete a[v--]' evaluates v-- once" \
280" \ 280" \
281 "" "" 281 "" ""
282 282
283testing "awk func arg parsing 1" \
284 "awk 'func f(,) { }' 2>&1" "awk: cmd. line:1: Unexpected token\n" "" ""
285
286testing "awk func arg parsing 2" \
287 "awk 'func f(a,,b) { }' 2>&1" "awk: cmd. line:1: Unexpected token\n" "" ""
288
289testing "awk func arg parsing 3" \
290 "awk 'func f(a,) { }' 2>&1" "awk: cmd. line:1: Unexpected token\n" "" ""
291
292testing "awk func arg parsing 4" \
293 "awk 'func f(a b) { }' 2>&1" "awk: cmd. line:1: Unexpected token\n" "" ""
294
283testing "awk handles empty ()" \ 295testing "awk handles empty ()" \
284 "awk 'BEGIN {print()}' 2>&1" "awk: cmd. line:1: Empty sequence\n" "" "" 296 "awk 'BEGIN {print()}' 2>&1" "awk: cmd. line:1: Empty sequence\n" "" ""
285 297