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

From Thomas Munro
Subject Re: Making tab-complete.c easier to maintain
Date
Msg-id CAEepm=0QKjnVVq9ueBXP5yntNFwtFZhFzLPEOpCA-PPoh0NieQ@mail.gmail.com
Whole thread Raw
In response to Re: Making tab-complete.c easier to maintain  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Making tab-complete.c easier to maintain
List pgsql-hackers
On Sat, Sep 5, 2015 at 1:40 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Thomas Munro <thomas.munro@enterprisedb.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);

--
Attachment

pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Is this a bug?
Next
From: Tom Lane
Date:
Subject: Re: Fwd: Core dump with nested CREATE TEMP TABLE