On 11/01/2015 18:48, Walter Bright wrote:
On 1/11/2015 9:45 AM, Stefan Koch wrote:
I'm  powerful writing a parser-generator, that will be able to
transform the
generated parse-tree back into source automatically.
writing a rule-based formatter should be pretty doable.

Formatting the AST into text is straightforward, dmd already does that
for .di file generation.

The main problem is what to do about comments, which don't fit into the
grammar.


It's not that hard to do that once you have a parser that preserves the source range of all AST nodes. With that you can write a formatting algorithm than *modifies* the original source, assisted by AST info, instead of trying to recreate the whole source from the AST info alone. This way you can reformat without losing comment data, even if the AST doesn't have store comments.


--
Bruno Medeiros
https://twitter.com/brunodomedeiros

Reply via email to