awk: skip whitespace between array name and subscript
authorAlexander Shishkin <virtuoso@slind.org>
Thu, 25 Feb 2010 15:55:40 +0000 (17:55 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Fri, 26 Feb 2010 07:48:56 +0000 (08:48 +0100)
It is supported in both mawk and gawk and there are actually scripts
out there that use this "flexibility".

function                                             old     new   delta
next_token                                          1144    1152      +8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 8/0)                 Total: 8 bytes

Signed-off-by: Alexander Shishkin <virtuoso@slind.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
editors/awk.c
testsuite/awk.tests

index bc8b0dad13672ebb0350de0559e31203184dde71..b9bc01f1653dd6ec8b6e1b22465c69ae1b5ff315 100644 (file)
@@ -1046,7 +1046,7 @@ static uint32_t next_token(uint32_t expected)
                                *(p-1) = '\0';
                                tc = TC_VARIABLE;
                                /* also consume whitespace between functionname and bracket */
-                               if (!(expected & TC_VARIABLE))
+                               if (!(expected & TC_VARIABLE) || (expected & TC_ARRAY))
                                        skip_spaces(&p);
                                if (*p == '(') {
                                        tc = TC_FUNCTION;
index 7910c8875e0cd9223d1ad378a7c06703dabab176..03d4649699386de24bd8900bae96dcfbbaefe855 100755 (executable)
@@ -64,4 +64,7 @@ testing "awk string cast (bug 725)" \
        "0\nnumber\n" \
        "" ""
 
+testing "awk handles whitespace before array subscript" \
+       "awk 'BEGIN { arr [3] = 1; print arr [3] }'" "1\n" "" ""
+
 exit $FAILCOUNT