dfmt 0.1.0

Jacob Carlborg via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Sun Feb 22 23:13:50 PST 2015


On 2015-02-22 19:52, qznc wrote:

> Congratulations to releasing. :)
>
> For the record, I think using a D parser in dfmt is a dead end. Surely,
> for certain cases the additional information is necessary. However, it
> restricts dfmt to only format syntactically valid snippets. This means
> you cannot (in general) format parts of a file, e.g. within a diff or
> editor.
>
> Example where parsing helps: "foo : bar" or "foo: bar" depending on the
> context. The former within import statements, the latter within switch
> statements.
>
> Example for a snippet you cannot parse: The body of a switch statement
> without the switch. The 'case' keyword would be an error.

It depends on how the parser is implemented. For example, the Eclipse 
Java parser is very flexible when it comes to this. You can choose to 
either parse a complete file or just a fragment of code.

> Effectively, you want to parse, but not with a normal parser. Great
> formatting seems to require a special (more flexible, less correct)
> parser. This is what clang-format does.

clang-format uses the lexer with the help of the parser. It only changes 
whitespace. At least according to the talk I watched, which is a couple 
of years old.

-- 
/Jacob Carlborg


More information about the Digitalmars-d-announce mailing list