Integrated code formatter

deadalnix deadalnix at gmail.com
Tue Jan 18 02:06:01 UTC 2022


On Tuesday, 18 January 2022 at 01:59:25 UTC, rikki cattermole 
wrote:
> On 18/01/2022 11:46 AM, H. S. Teoh wrote:
>>> clang-format is indeed something I very much miss for D. 
>>> Precisely
>>> this "only reformat this small fragment" functionality is 
>>> extremely
>>> time saving.
>> Does dfmt not do this?
>
> Doesn't appear to.
>
> Keep in mind it uses libdparse to actually ya know, parse the 
> code.
>
> So a small fragment probably wouldn't format properly beyond 
> some basic rules anyway.

This approach is fundamentally flawed, as keeping all the info 
you need through an AST is pretty much impossible.

Modern formatter, such as clang-format, use a parser, but the 
parser generates an IR that as nothing to do with the traditional 
AST you'd get out of a regular parser.

To get an idea of what these IR looks like: 
http://journal.stuffwithstuff.com/2015/09/08/the-hardest-program-ive-ever-written/


More information about the Digitalmars-d mailing list