[SAOC 2023] dfmt rewrite - Weekly update #1
Prajwal S N
snp at lang.org
Fri Sep 22 07:12:02 UTC 2023
Hi everyone,
For SAOC 2023, I'm working on refactoring
[dfmt](https://github.com/dlang-community/dfmt) to use the AST
from DMD-as-a-library instead of libdparse.
The past week has been very interesting. I got up to speed with
the dfmt codebase, and managed to do a 1-to-1 port of the lexer
dependency from libdparse to DMD-as-a-library. Most parts were
pretty straightforward, and the bulk of the work was replacing
every `tok!"<token>"` instance with `TOK.<token>` and making sure
the token coming from DMD was the same as what was previously
being used. So far so good!
You can see the draft PR tracking the work
[here](https://github.com/dlang-community/dfmt/pull/589).
Going forward, my mentor and I have decided that it would be
impractical to try and replace the parser directly, for multiple
reasons:
- It's a lot of work to replace the parser and use the DMD AST
instead of libdparse's, and all of this work will happen without
a working version of dfmt. If, at the end of this, dfmt is broken
or refuses to compile, it could very well mean that all that
effort went down the drain.
- Doing a brute force replacement of the parser will prevent us
from testing the transformation passes in dfmt individually, and
also brings us back to the point above.
Hence, we've decided to do an incremental rewrite of the files
that use the parser, initially with no passes (just to ensure the
AST is being built in the first place), and then adding each pass
along with relevant unit tests.
More information about the Digitalmars-d
mailing list