www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - dfmt - D source code formatter

reply Walter Bright <newshound2 digitalmars.com> writes:
It would be nice to have a D source code formatter. But it needs a champion. 
Who's up for it?
Jul 04 2012
next sibling parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 7/5/12 12:46 AM, Walter Bright wrote:
 It would be nice to have a D source code formatter. But it needs a
 champion. Who's up for it?

Yes please. Andrei
Jul 04 2012
prev sibling next sibling parent reply Jonathan M Davis <jmdavisProg gmx.com> writes:
On Wednesday, July 04, 2012 21:46:29 Walter Bright wrote:
 It would be nice to have a D source code formatter. But it needs a champion.
 Who's up for it?

Doesn't that need a lexer and parser for D first (which I'd _love_ to do but just haven't had time to get around to)? - Jonathan M Davis
Jul 04 2012
parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 7/4/2012 10:22 PM, Jonathan M Davis wrote:
 On Wednesday, July 04, 2012 21:46:29 Walter Bright wrote:
 It would be nice to have a D source code formatter. But it needs a champion.
 Who's up for it?

Doesn't that need a lexer and parser for D first (which I'd _love_ to do but just haven't had time to get around to)?

Yes. Or it could be written based on the .di generation logic, i.e. as part of dmd.
Jul 04 2012
parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Thursday, July 05, 2012 11:11:28 Paulo Pinto wrote:
 This are the type of projects that would benefit from having the
 compiler available as library.

It will be eventually, but someone (or several someones) will have to take the time to do it. Once I find the time, I intend to port the lexer (and later parser) from dmd's frontend to D, and I intended to have it done quite some time ago, but I haven't had the time, so it hasn't happened yet, and no one else has taken the time to do that (or if they have, they haven't finished the job). - Jonathan M Davis
Jul 05 2012
prev sibling next sibling parent "Paulo Pinto" <pjmlp progtools.org> writes:
On Thursday, 5 July 2012 at 06:27:55 UTC, Walter Bright wrote:
 On 7/4/2012 10:22 PM, Jonathan M Davis wrote:
 On Wednesday, July 04, 2012 21:46:29 Walter Bright wrote:
 It would be nice to have a D source code formatter. But it 
 needs a champion.
 Who's up for it?

Doesn't that need a lexer and parser for D first (which I'd _love_ to do but just haven't had time to get around to)?

Yes. Or it could be written based on the .di generation logic, i.e. as part of dmd.

Personally I would rather see it as a separate tool. D already gets a bit of bad publicity for having the compiler do too much stuff that should be relegated to separate tools. This is again another use case that would benefit from the "compiler as library".
Jul 04 2012
prev sibling next sibling parent Jens Mueller <jens.k.mueller gmx.de> writes:
Walter Bright wrote:
 It would be nice to have a D source code formatter. But it needs a
 champion. Who's up for it?

I'm using uncrustify (http://uncrustify.sourceforge.net/). It does most of the time what I want. Jens
Jul 05 2012
prev sibling next sibling parent "Paulo Pinto" <pjmlp progtools.org> writes:
On Thursday, 5 July 2012 at 06:27:55 UTC, Walter Bright wrote:
 On 7/4/2012 10:22 PM, Jonathan M Davis wrote:
 On Wednesday, July 04, 2012 21:46:29 Walter Bright wrote:
 It would be nice to have a D source code formatter. But it 
 needs a champion.
 Who's up for it?

Doesn't that need a lexer and parser for D first (which I'd _love_ to do but just haven't had time to get around to)?

Yes. Or it could be written based on the .di generation logic, i.e. as part of dmd.

Somehow my reply seems to have been lost. I find it nice, but would rather see it as a separate tool. This are the type of projects that would benefit from having the compiler available as library. -- Paulo
Jul 05 2012
prev sibling next sibling parent maarten van damme <maartenvd1994 gmail.com> writes:
2012/7/5 Jens Mueller <jens.k.mueller gmx.de>:
 Walter Bright wrote:
 It would be nice to have a D source code formatter. But it needs a
 champion. Who's up for it?

I'm using uncrustify (http://uncrustify.sourceforge.net/). It does most of the time what I want. Jens

I'm using uncrustify too although it has the annoying habbit of rewriting => to = > causing all functions using the new lambda syntax to break.
Jul 05 2012
prev sibling next sibling parent Jens Mueller <jens.k.mueller gmx.de> writes:
maarten van damme wrote:
 2012/7/5 Jens Mueller <jens.k.mueller gmx.de>:
 Walter Bright wrote:
 It would be nice to have a D source code formatter. But it needs a
 champion. Who's up for it?

I'm using uncrustify (http://uncrustify.sourceforge.net/). It does most of the time what I want. Jens

I'm using uncrustify too although it has the annoying habbit of rewriting => to = > causing all functions using the new lambda syntax to break.

Have you tried adding an issue? I had different problems. Most where fixed. Jens
Jul 05 2012
prev sibling next sibling parent Jacob Carlborg <doob me.com> writes:
On 2012-07-05 06:46, Walter Bright wrote:
 It would be nice to have a D source code formatter. But it needs a
 champion. Who's up for it?

It's a great idea but as others have said, I see no point in creating this until we have a D compiler available as a library. -- /Jacob Carlborg
Jul 05 2012
prev sibling next sibling parent Jacob Carlborg <doob me.com> writes:
On 2012-07-05 06:46, Walter Bright wrote:
 It would be nice to have a D source code formatter. But it needs a
 champion. Who's up for it?

I just tried ddmd-clean and it already does some form of source code formatting. It will format the following file: https://github.com/zachthemystic/ddmd-clean/blob/master/main.d To something like this: http://pastebin.com/JUauQDvb https://github.com/zachthemystic/ddmd-clean -- /Jacob Carlborg
Jul 05 2012
prev sibling next sibling parent "Brian Schott" <briancschott gmail.com> writes:
On Thursday, 5 July 2012 at 04:47:29 UTC, Walter Bright wrote:
 It would be nice to have a D source code formatter. But it 
 needs a champion. Who's up for it?

I'm already working on adding formatting to my general-purpose D tool. https://github.com/Hackerpilot/Dscanner
Jul 05 2012
prev sibling next sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 7/4/2012 9:46 PM, Walter Bright wrote:
 It would be nice to have a D source code formatter. But it needs a champion.
 Who's up for it?

I think that formatting the code is actually rather easy - the hard part will be dealing with the comments in a reasonable way.
Jul 05 2012
next sibling parent reply "Brian Schott" <briancschott gmail.com> writes:
On Thursday, 5 July 2012 at 19:22:56 UTC, Walter Bright wrote:
 I think that formatting the code is actually rather easy - the 
 hard part will be dealing with the comments in a reasonable way.

Eclipse has had a LOT of time and energy put into it, and it still makes my javadoc uglier than it was before formatting. My thought is to properly indent/align comments, but other than that leave them unmodified. There are too many things that can go wrong with re-wrapping them (I'm imagining accidentally ruining somebody's carefully-crafted ASCII art diagram).
Jul 05 2012
parent Walter Bright <newshound2 digitalmars.com> writes:
On 7/5/2012 1:52 PM, Brian Schott wrote:
 On Thursday, 5 July 2012 at 19:22:56 UTC, Walter Bright wrote:
 I think that formatting the code is actually rather easy - the hard part will
 be dealing with the comments in a reasonable way.

Eclipse has had a LOT of time and energy put into it, and it still makes my javadoc uglier than it was before formatting. My thought is to properly indent/align comments, but other than that leave them unmodified. There are too many things that can go wrong with re-wrapping them (I'm imagining accidentally ruining somebody's carefully-crafted ASCII art diagram).

I agree that whatever is inside the comment should be left alone. I was more talking about lining up comment blocks, etc.
Jul 05 2012
prev sibling next sibling parent "Roman D. Boiko" <rb d-coding.com> writes:
On Thursday, 5 July 2012 at 22:25:15 UTC, Walter Bright wrote:
 I agree that whatever is inside the comment should be left 
 alone. I was more talking about lining up comment blocks, etc.

wondering.
Jul 05 2012
prev sibling parent "Brian Schott" <briancschott gmail.com> writes:
On Thursday, 5 July 2012 at 22:27:09 UTC, Roman D. Boiko wrote:
 On Thursday, 5 July 2012 at 22:25:15 UTC, Walter Bright wrote:
 I agree that whatever is inside the comment should be left 
 alone. I was more talking about lining up comment blocks, etc.

I'm wondering.

If the forum interface strips leading whitespace, this message will look pointless. /** * This is easy */ // trivial // multi-line // comment /* This is a list where indenting is significant: * list item * other list item * How do we indent this? */ /* I want this to be fixed * because these lines are off by one space * and should be aligned */ /++ Ddoc is, IIRC, bad at handling leading spaces in code samples --- foo("hello world"); --- +/ void foo(string arg) {
Jul 05 2012
prev sibling parent "Brian Schott" <briancschott gmail.com> writes:
On Thursday, 5 July 2012 at 10:27:41 UTC, maarten van damme wrote:
 I'm using uncrustify too although it has the annoying habbit of
 rewriting => to = > causing all functions using the new lambda 
 syntax
 to break.

Creating a formatter that works *well* is a larger challenge than I first imagined, so I took a small break and fixed that bug in uncrustify. The pull request is here: https://github.com/bengardner/uncrustify/pull/86
Jul 14 2012