Making tab-complete.c easier to maintain - Mailing list pgsql-hackers

From Thomas Munro
Subject Making tab-complete.c easier to maintain
Date
Msg-id CAEepm=2wF0eTXfQUMzvJ71GC47ESQmWQ3Y_fz5CRBask1uA1DA@mail.gmail.com
Whole thread Raw
Responses Re: Making tab-complete.c easier to maintain  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hi hackers,

After spending some time in tab-complete.c responding to a bug report, I had very strong urge to find a way to make it a bit easier to maintain.  Do you think it would be an improvement if we changed all the code that looks a bit like this:

    /* Complete CREATE TRIGGER <name> BEFORE|AFTER with an event */
    else if (pg_strcasecmp(prev4_wd, "CREATE") == 0 &&
              pg_strcasecmp(prev3_wd, "TRIGGER") == 0 &&
              (pg_strcasecmp(prev_wd, "BEFORE") == 0 ||
               pg_strcasecmp(prev_wd, "AFTER") == 0))
    {
        static const char *const list_CREATETRIGGER_EVENTS[] =
        {"INSERT", "DELETE", "UPDATE", "TRUNCATE", NULL};

        COMPLETE_WITH_LIST(list_CREATETRIGGER_EVENTS);
    }

... into code that looks a bit like this?

    /* Complete CREATE TRIGGER <name> BEFORE|AFTER with an event */
    else if (MATCHES4("CREATE", "TRIGGER", "<name>", "BEFORE|AFTER"))
        COMPLETE_WITH_LIST4("INSERT", "DELETE", "UPDATE", "TRUNCATE");

See attached a proof-of-concept patch.  It reduces the size of tab-complete.c by a bit over a thousand lines.  I realise that changing so many lines just to refactor code may may be a difficult sell!  But I think this would make it easier to improve the tab completion code in future, and although it's large it's a superficial and mechanical change.

--
Attachment

pgsql-hackers by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Testing WAL replay by comparing before and after images again
Next
From: Simon Riggs
Date:
Subject: Re: Testing WAL replay by comparing before and after images again