WIP pgindent replacement

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: WIP pgindent replacement
Date: 2011-06-22 00:27:45
Message-ID: 4E013701.2060606@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


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.

Comments welcome.

cheers

andrew

Attachment Content-Type Size
pgindent.pl application/x-perl 9.7 KB
indent.diff text/x-patch 14.8 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2011-06-22 01:50:14 Re: [v9.2] DROP Reworks Part.0 - 'missing_ok' support of get_object_address
Previous Message Dan McGee 2011-06-22 00:11:04 pg_upgrade version check improvements and small fixes