shlomo.swidler@stripped wrote:
> It doesn't sound too hard to take any language that adheres to a
> grammar (C, Java, etc.) and write a program that transforms any input
> adhering to that grammar into a custom defined coding style, according
> to a pluggable template. It sounds so obvious - does anyone know of
> any such thing?
>
> Such a utility could be used to solve the "diff against an old file -
> dangit, it's in a different coding style" problem: just run the old
> code through the tool to transform it, then diff.
>
>
I'm not sure if it's as easy as it sounds. One thing is that C
preprocessor is distinct from the compiler
and the styling for #define is usually different from the code, as in
#define FOO do {foo} while (0);
which would be laughed at when used outside #define.
Grammars seem to have hard time defining things like line numbers,
comment style, placement on page,
TABs vs blanks so 'a C program conforming to a style' would be a much
bigger grammar than just a C program,
if at all existing.
Overall it the transformation approach sounds like half the compiler. In
fact anything could be done within the compiler,
someone just needs to advocate it with gcc developers. They have so
many optimization and warning flags, why not
add something for if (foo) bar; vs. if (foo) {bar} vs.
if (foo)
{
bar;
}
Thanks,
Michael Izioumtchenko