Writing a source formatter
===

I often find myself reformatting pieces of a scripting language to make them readable. I'd like to automate this task, but hopefully not start from scratch. Is there some good *small* open-source tool I can customize to this purpose?

[AStyle][1] looks nice, but the source is fairly complex. I'm looking for something that's as simple as possible so it's easy to rewrite. That, or an extensible code formatter where I can just define my scripting language and it formats it without changes to the source at all (if such a thing exists).

The target language is 'mostly' functional with some imperative elements, so breaks must be made on parentheses `()` rather than braces `{}`. It writes `func(arg1, arg2, arg3)` rather than a Lisp-like `(func arg1 arg2 arg3)`. So some measure of adaptation is needed, formatters I've seen wouldn't work on it as far as I know.

The language of the formatter can be anything within reason (C++, C, Java, Perl, etc.).

  [1]: http://astyle.sourceforge.net/