Re: Making tab-complete.c easier to maintain

From: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Making tab-complete.c easier to maintain
Date: 2015-09-05 12:15:26
Message-ID: CAEepm=0QKjnVVq9ueBXP5yntNFwtFZhFzLPEOpCA-PPoh0NieQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, Sep 5, 2015 at 1:40 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com> writes:
> > 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.
>
> I really dislike the magical "<" business. Maybe you could use NULL
> instead of having to reserve a class of real strings as placeholders.
>

Thanks, good point. Here's a version that uses NULL via a macro ANY.
Aside from a few corrections it also now distinguishes between
TAIL_MATCHESn (common) and MATCHESn (rarely used for now), for example:

/* ALTER TABLE,INDEX,MATERIALIZED VIEW xxx ALL IN TABLESPACE xxx */
- else if (pg_strcasecmp(prev4_wd, "ALL") == 0 &&
- pg_strcasecmp(prev3_wd, "IN") == 0 &&
- pg_strcasecmp(prev2_wd, "TABLESPACE") == 0)
- {
- static const char *const list_ALTERALLINTSPC[] =
- {"SET TABLESPACE", "OWNED BY", NULL};
-
- COMPLETE_WITH_LIST(list_ALTERALLINTSPC);
- }
+ else if (TAIL_MATCHES4("ALL", "IN", "TABLESPACE", ANY))
+ COMPLETE_WITH_LIST2("SET TABLESPACE", "OWNED BY");

... versus:

/* EXECUTE, but not EXECUTE embedded in other commands */
- else if (pg_strcasecmp(prev_wd, "EXECUTE") == 0 &&
- prev2_wd[0] == '\0')
+ else if (MATCHES1("EXECUTE"))
COMPLETE_WITH_QUERY(Query_for_list_of_prepared_statements);

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

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2015-09-05 14:07:48 Re: Fwd: Core dump with nested CREATE TEMP TABLE
Previous Message Bruce Momjian 2015-09-05 12:03:20 Re: Is this a bug?