Re: [Builder] Interested in auto indentation task



On 02/20/2016 01:29 AM, Megh Parikh wrote:
I am interested in writing a better auto indenter for builder which is
an item on the roadmap. Where should I start?

(I have jhbuild and builder setup and have also fixed a newcomer bug amd
I have good experience in C, Python and C++)

This is going to be a fairly involved task. I have some prototype code
that I need to dig up that uses a new design (that I've not seen
implemented elsewhere) to build indenters.

The design is essentially this:

  Back track from the cursor location and track points of interest. This
might include opening/closing {[('", class definitions, function
prototypes, conditionals (if, else, while, do).

  Indenter builds a set of rules using "selectors", not entirely
different from CSS. The selectors can then associate a rule to apply
when the selector matches. (Selector with highest-rank wins).

  Selector rank is defined by the number of matching attributes, not
entirely different from CSS.

  Subclasses of this indenter (python, C, C++, vala, etc) will define
the points of interest, and the rules to apply.

Some might be asking, why not just use things like "uncrustify",
"gofmt", or "indent" to indent the source code? The answer is that
formatting code with a valid AST and indenting code as you type it are
very different problems. Since while you type it, you almost never have
a valid AST to work with.

There are some ways to work around this by aggressively caching existing
ASTs, but in general, I think that is more effort than it is worth, and
it burns a whole lot of battery to compile with that level of frequency.
Also, if your compilation engine is broken (due to broken build system
settings), you are outta' luck.

An important feature of this is that we can have settings for various
indenters and tweak them in the preferences. We want the C indenter, for
example, to have a few predefined sets of rules. GNU C89, K&R, and Linux
come to mind.

What might be the best course of action for this, would be for me to sit
down and finish the indenter prototype, and then have people work on
indenters for their favorite languages (and the predefined rules).

-- Christian



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]