Re: Making tab-complete.c easier to maintain

Поиск
Список
Период
Сортировка
От Thomas Munro
Тема Re: Making tab-complete.c easier to maintain
Дата
Msg-id CAEepm=0QKjnVVq9ueBXP5yntNFwtFZhFzLPEOpCA-PPoh0NieQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Making tab-complete.c easier to maintain  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Making tab-complete.c easier to maintain  (Alvaro Herrera <alvherre@2ndquadrant.com>)
Список 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);

--
Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: Is this a bug?
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Fwd: Core dump with nested CREATE TEMP TABLE