Making tab-complete.c easier to maintain

From: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Making tab-complete.c easier to maintain
Date: 2015-09-04 13:21:17
Message-ID: CAEepm=2wF0eTXfQUMzvJ71GC47ESQmWQ3Y_fz5CRBask1uA1DA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

--
Thomas Munro
http://www.enterprisedb.com

Attachment Content-Type Size
tab-complete-macrology.patch application/octet-stream 127.4 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Simon Riggs 2015-09-04 13:30:14 Re: Testing WAL replay by comparing before and after images again
Previous Message Heikki Linnakangas 2015-09-04 12:45:56 Testing WAL replay by comparing before and after images again