Thread overview | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
January 15, 2013 D source code formatting utility (dformat) | ||||
---|---|---|---|---|
| ||||
Continuing in the vein of the Exceptional coding style thread, D needs (and has needed for a long time) a utility that will reformat source code. One use of it would be to run as a filter on all of the Druntime and Phobos source code before checkin. This could make great use of the current projects to implement a D lexer and parser in D. It'd make for a nice boon to the D community. Any champions for this? |
January 16, 2013 Re: D source code formatting utility (dformat) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Tuesday, 15 January 2013 at 23:50:12 UTC, Walter Bright wrote: > Continuing in the vein of the Exceptional coding style thread, D needs (and has needed for a long time) a utility that will reformat source code. > > One use of it would be to run as a filter on all of the Druntime and Phobos source code before checkin. > > This could make great use of the current projects to implement a D lexer and parser in D. > > It'd make for a nice boon to the D community. > > Any champions for this? Uncrustify[1] had a release on the first of this month which I'm sure includes the fix I made to the parser to recognize the => lamba syntax. It may be easier to just use that instead of making our own. (I haven't tested to see what it does with user-defined attributes yet) On the other hand, if we need a utility written in D, I'd like to finish work on my lexer so that it can be phobos-quality first. [1] http://sourceforge.net/projects/uncrustify/ |
January 16, 2013 Re: D source code formatting utility (dformat) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Tuesday, January 15, 2013 15:50:10 Walter Bright wrote: > Continuing in the vein of the Exceptional coding style thread, D needs (and has needed for a long time) a utility that will reformat source code. > > One use of it would be to run as a filter on all of the Druntime and Phobos source code before checkin. Honestly, I would hate to have anything like this run on druntime or Phobos. We've specifically avoided enforcing exact formatting rules in the style guide and instead have focused on the API. In addition, code formatters always end up mangling code. Sure, some of the code looks fine, but other parts of it inevitably look hideous, because the formatter can never deal with special cases well enough. You just can't make the formatting rules flexible enough, and sometimes, you just plain have to break formatting guidelines in order to make code legible. I have no problem with anyone writing a code formatter, but I sure don't want to deal with a code base that uses one. > This could make great use of the current projects to implement a D lexer and parser in D. I really need to get back to this, but life is so hectic... - Jonathan M Davis |
January 16, 2013 Re: D source code formatting utility (dformat) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On 1/15/13 6:50 PM, Walter Bright wrote:
> Continuing in the vein of the Exceptional coding style thread, D needs
> (and has needed for a long time) a utility that will reformat source code.
>
> One use of it would be to run as a filter on all of the Druntime and
> Phobos source code before checkin.
>
> This could make great use of the current projects to implement a D lexer
> and parser in D.
>
> It'd make for a nice boon to the D community.
>
> Any champions for this?
What about just using the json output?
Andrei
|
January 16, 2013 Re: D source code formatting utility (dformat) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On 1/15/2013 4:45 PM, Andrei Alexandrescu wrote:
> What about just using the json output?
It'd lose all the comments.
|
January 16, 2013 Re: D source code formatting utility (dformat) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On 1/16/13, Walter Bright <newshound2@digitalmars.com> wrote:
> On 1/15/2013 4:45 PM, Andrei Alexandrescu wrote:
>> What about just using the json output?
>
> It'd lose all the comments.
Json could output comments if we wanted to.
This isn't such a bad idea considering the amount of work necessary to actually parse D code in the first place.
|
January 16, 2013 Re: D source code formatting utility (dformat) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Wednesday, 16 January 2013 at 00:49:21 UTC, Walter Bright wrote:
> On 1/15/2013 4:45 PM, Andrei Alexandrescu wrote:
>> What about just using the json output?
>
> It'd lose all the comments.
And the code itself, unless I'm missing some new enhancement to the json... the best you can make from that is prototypes (and even that is incomplete right now!)
It seems to me that the easiest way to do this might be to do something similar to .di generation, inside the compiler. All the code is there, but we'd have to be sure to do do it before any of the lowerings done in semantic; if the user writes "foreach", we don't want the code formatter spitting out "for".
|
January 16, 2013 Re: D source code formatting utility (dformat) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On 1/16/13, Adam D. Ruppe <destructionator@gmail.com> wrote: > And the code itself, unless I'm missing some new enhancement to the json... Good point. On 1/16/13, Adam D. Ruppe <destructionator@gmail.com> wrote: > It seems to me that the easiest way to do this might be to do something similar to .di generation, inside the compiler. Note the title! I'm pretty sure Walter specifically wants this written in D. C/C++ solutions already exist, but a D implementation could be a good way to show how much work is required to write a code formatter in D and could e.g. be presented in DConf. String processing should be D's powerful side, after all. |
January 16, 2013 Re: D source code formatting utility (dformat) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On 01/16/2013 12:50 AM, Walter Bright wrote:
> Continuing in the vein of the Exceptional coding style thread, D needs
> (and has needed for a long time) a utility that will reformat source code.
>
> One use of it would be to run as a filter on all of the Druntime and
> Phobos source code before checkin.
>
> This could make great use of the current projects to implement a D lexer
> and parser in D.
>
> It'd make for a nice boon to the D community.
>
> Any champions for this?
It is on my TODO list.
|
January 16, 2013 Re: D source code formatting utility (dformat) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On 1/15/13 7:56 PM, Andrej Mitrovic wrote:
> On 1/16/13, Walter Bright<newshound2@digitalmars.com> wrote:
>> On 1/15/2013 4:45 PM, Andrei Alexandrescu wrote:
>>> What about just using the json output?
>>
>> It'd lose all the comments.
>
> Json could output comments if we wanted to.
>
> This isn't such a bad idea considering the amount of work necessary to
> actually parse D code in the first place.
Agreed. Generally we should standardize tooling on json, regardless of the notion that indeed a parser is good in the library. Walter?
Andrei
|
Copyright © 1999-2021 by the D Language Foundation