Re: WIP pgindent replacement

Поиск
Список
Период
Сортировка
От Bruce Momjian
Тема Re: WIP pgindent replacement
Дата
Msg-id 20120803030951.GA5809@momjian.us
обсуждение исходный текст
Ответ на WIP pgindent replacement  (Andrew Dunstan <andrew@dunslane.net>)
Ответы Re: WIP pgindent replacement
Список pgsql-hackers
On Tue, Jun 21, 2011 at 08:27:45PM -0400, Andrew Dunstan wrote:
>
> Attached is a WIP possible replacement for pgindent. Instead of a
> shell script invoking a mishmash of awk and sed, some of which is
> pretty impenetrable, it uses a single engine (perl) to do all the
> pre and post indent processing. Of course, if your regex-fu and
> perl-fu is not up the scratch this too might be impenetrable, but
> all but a couple of the recipes are reduced to single lines, and I'd
> argue that they are all at least as comprehensible as what they
> replace.
>
> Attached also is a diff file showing what it does differently from
> the existing script. I think that these are all things where the new
> script is more correct than the existing script. Most of the changes
> come into two categories:
>
>    * places where the existing script fails to combine the function
>      return type and the function name on a single line in function
>      prototypes.
>    * places where unwanted blank lines are removed by the new script
>      but not by the existing script.
>
> Features include:
>
>    * command line compatibility with the existing script, so you can do:
>      find ../../.. -name '*.[ch]' -type f -print | egrep -v -f
>      exclude_file_patterns | xargs -n100 ./pgindent.pl typedefs.list
>    * a new way of doing the same thing much more nicely:
>      ./pgindent.pl --search-base=../../.. --typedefs=typedefs.list
>      --excludes=exclude_file_patterns
>    * only passes relevant typedefs to indent, not the whole huge list
>    * should in principle be runnable on Windows, unlike existing script
>      (I haven't tested yet)
>    * no semantic tab literals; tabs are only generated using \t and
>      tested for using \t, \h or \s as appropriate. This makes debugging
>      the script much less frustrating. If something looks like a space
>      it should be a space.
>
> In one case I used perl's extended regex mode to comment a fairly
> hairy regex. This should probably be done a bit more, maybe for all
> of them.
>
> If anybody is so inclined, this could be used as a basis for
> removing the use of bsd indent altogether, as has been suggested
> before, as well as external entab/detab.

Thirteen months after Andrew posted this WIP, I have restructured and
tested this code, and it is now ready to replace the pgindent shell
script as pgindent.pl, attached.

I have tested this version by re-running the 9.1 and 9.2 pgindent runs
and comparing the output, and it is just like Andrew said --- it is the
same, except for the two improvements he mentioned.

A Perl version of pgindent has several advantages:

*  more portable;  less dependent on utility command variances
*  able to run on Windows, assuming someone makes entab and
   pg_bsd_indent Windows binaries
*  able to fix more limitations of pgindent

I will add documentation about the arguments.

Many thanks to Andrew for his fine work on this.  Any objections?

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + It's impossible for everything to be true. +

Вложения

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

Предыдущее
От: Marko Kreen
Дата:
Сообщение: Re: [patch] libpq one-row-at-a-time API
Следующее
От: "Etsuro Fujita"
Дата:
Сообщение: Re: WIP Patch: Use sortedness of CSV foreign tables for query planning