Hi,

On 9/29/23 15:37, Julian Hapke wrote:

having gotten used to using clang-format in C and C++ as well as black in Python, I would like to try and write a file formatter for a different language.

There will be a lot of personal preferences involved in this, plus you will need to contend with "inside {} is a different language which has its own formatting rules."

My preferred style these days is

    rule:
        "keyword" IDENTIFIER '{' members '}'
            {
                multi();
                line();
                action();
            }
    |   "keyword" IDENTIFIER ';'
            { short_action(); }

because it gives minimal diffs for adding alternatives and for adding actions after the grammar accepts the example set of inputs, and it also allows code coverage analysis to give sensible results with tools that report on a line-by-line basis.

I am fairly sure that there will be a plethora of different styles out there, all with their own rationale, and there are a few degrees of freedom inside the Bison syntax that a good formatter will need to either replicate or make consistent, such as whether rules need to have a trailing semicolon.

I don't know of any existing tool, but I haven't looked too hard either.

   Simon

Reply via email to