Re: dfmt 0.1.0
On Sat, 07 Mar 2015 13:03:06 +, Kagamin wrote: In fact, I failed to find good monospace font for source code, it used to be Courier New 9pt, but it works well only on displays no bigger than 1024*768. terminus rocks. signature.asc Description: PGP signature
Re: dfmt 0.1.0
On Friday, 6 March 2015 at 20:22:42 UTC, Ben Boeckel wrote: You're making assumptions about the features of your users' editors. These features are not trivial to implement Implementation of three different word wrapping algorithms in Scintilla took 52 lines of code. For comparison: a rudimentary D lexer is only modest 400 lines. requires things like pygments and other tools used to render code to the web with all kinds of logic to handle dynamic viewports of the shown code. You think too web 2.0, browsers wrap text since the beginning, tools only need to stop fight with them.
Re: dfmt 0.1.0
On Sat, 2015-03-07 at 12:28 +0100, FG via Digitalmars-d-announce wrote: […] If at all, the problem with Phobos' style isn't with horizontal spacing but vertical space. Consider the waste of space below. Too much scrolling and I lose focus. Now, *that* is really irritating. ;) […] This is definitely one of the major reasons I cannot bear to read Phobos formatted code. Others seems to like it, it's a world full of acceptable differences of opinion. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: dfmt 0.1.0
On Sat, 2015-03-07 at 12:57 +, Kagamin via Digitalmars-d-announce wrote: On Friday, 6 March 2015 at 20:22:42 UTC, Ben Boeckel wrote: And I find that monospace fonts tend to make it much easier to tell the difference between 'l', '1', and 'I'. Not so important in English, but it can be all the difference in code. http://abload.de/img/tmpr3uv6.png I see no less difference than in monospace font. That will be because it is a reasonably designed font. I have to admit though, the glyph widths are a bit large in the example font. I guess I prefer something a bit more condensed. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: dfmt 0.1.0
In fact, I failed to find good monospace font for source code, it used to be Courier New 9pt, but it works well only on displays no bigger than 1024*768.
Re: dfmt 0.1.0
On Friday, 6 March 2015 at 20:22:42 UTC, Ben Boeckel wrote: And I find that monospace fonts tend to make it much easier to tell the difference between 'l', '1', and 'I'. Not so important in English, but it can be all the difference in code. http://abload.de/img/tmpr3uv6.png I see no less difference than in monospace font.
Re: dfmt 0.1.0
On 3/6/2015 10:43 PM, Russel Winder via Digitalmars-d-announce wrote: The difficulty here is turning a personal preference into a social orthodoxy. A consistent style is necessary for Phobos. For your own projects, D doesn't dictate any particular style.
Re: dfmt 0.1.0
On 2015-03-07 at 07:51, Russel Winder via Digitalmars-d-announce wrote: Many C++ projects are returning to it, Go enforces it if you let it, many Python projects are starting to use it in spite of PEP-8. Now, that you mentioned Python, it was one of the main reasons why I moved away from tabs. I was used to tab-completion in the shell and Python's interactive interpreter (and didn't want to rebind that feature to some key combination on every system that I worked with). Whenever I copied chunks of tab-indented source code into the interpreter, it got screwed up, because the indentations had vanished, so eventually I switched to using spaces only and had no problems ever since. I can also say from experience that removing tabs from Phobos source has removed a lot of irritation with messed up code rendering and wasted effort arguing about it. We're not going back :-) And I am not going to work on Phobos for exactly the same reasons. My loss, not yours. You must be joking. :) If at all, the problem with Phobos' style isn't with horizontal spacing but vertical space. Consider the waste of space below. Too much scrolling and I lose focus. Now, *that* is really irritating. ;) struct Boo { int a; } struct Foo { int a; auto opAssign(Foo foo) { assert(0); } auto opEquals(Foo foo) { return a == foo.a; } } X calculate(Range)(Range r) { static if (something) { import whatever; auto result = xxx(); size_t i; foreach (e; r) { doSomething(result[i], e); ++i; } return result; } else { auto a = blah(); foreach (e; r) { a.put(e); } return a.data; } }
Re: dfmt 0.1.0
On 3/6/2015 1:48 AM, Brian Schott wrote: The serious answer is that there's a lot of special casing that I'm still trying to figure out. Ah. I had thought that maybe there was an obvious algorithm I didn't think of!
Re: dfmt 0.1.0
On 3/6/2015 2:47 AM, Stefan Koch wrote: I'd like to hear your definition of simple. It's easy to understand, and one could write one from scratch over a weekend. I haven't done any statistics, but I'd bet that that parse.c lexer.c are among the most stable parts of dmd judging by change history.
Re: dfmt 0.1.0
On 3/6/2015 1:54 AM, Brian Schott wrote: On Friday, 6 March 2015 at 09:39:13 UTC, Walter Bright wrote: True, but on the other hand, a D lexer and parser are pretty simple. Did you mean simple compared to C++? It's simple in both absolute terms and relative to C++ terms. It's not as simple as Java's. I remember having to report/fix a LOT of bugs in the language specification and explore the DMD front end source code to get to where I am now. True, but there have been very few bugs in the lexer/parser itself. My laziness in being pedantically correct in writing the specification is an orthogonal issue.
Re: dfmt 0.1.0
On 3/6/2015 11:55 AM, Russel Winder via Digitalmars-d-announce wrote: The core problem here is teletype, monospace font thinking. Using a proper proportional font for you code and you rapidly lose the need for all this alignment stuff. Real point but expressed as a bit of a troll, mostly to expose that this is likely a bikeshed issue. Unlike english prose, code follows patterns. With a monospace font, one can line up those patterns which makes for easier visual checking for errors.
Re: dfmt 0.1.0
On 3/6/2015 2:31 AM, Russel Winder via Digitalmars-d-announce wrote: Remember a tab is not a number of spaces, it is semantic markup. All I can say is good luck with that. ASCII is not a markup language, and trying to reinvent it as one is doomed to failure. I can also say from experience that removing tabs from Phobos source has removed a lot of irritation with messed up code rendering and wasted effort arguing about it. We're not going back :-)
Re: dfmt 0.1.0
On Friday, 6 March 2015 at 09:40:07 UTC, Walter Bright wrote: How are comments handled? The source code makes a DC 15 wisdom save, if it fails then the comments get distributed randomly. The serious answer is that there's a lot of special casing that I'm still trying to figure out.
Re: dfmt 0.1.0
On Fri, 2015-03-06 at 09:48 +, Brian Schott via Digitalmars-d-announce wrote: On Friday, 6 March 2015 at 09:40:07 UTC, Walter Bright wrote: How are comments handled? The source code makes a DC 15 wisdom save, if it fails then the comments get distributed randomly. But with a d4, d6, d8, d10, d12, d20, d100? The serious answer is that there's a lot of special casing that I'm still trying to figure out. I prefer the previous answer :-) -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
Re: dfmt 0.1.0
On Fri, Mar 06, 2015 at 10:31:29 +, Russel Winder via Digitalmars-d-announce wrote: That is the whole point of using tabs for indent, you can chose the indent amount: I tend to use 20ex. Remember a tab is not a number of spaces, it is semantic markup. Using spaces is a low-level hack founded on a lack of separation of concerns and abstraction. The problem with tabs, IMO, are the following: - don't look right in patches (notice the different alignment of indented lines versus lines without any): -int foo(int bar) { - return bar; -} versus (assuming 8 space indents): -int foo(int bar) { -return bar; -} - I have yet to see an editor properly do tab-for-indent with proper space-for-alignment without manual management: int my_long_function_name(int bar, int baz) ^__tab_^^___spaces___^ By the way, this is *wrong* because tabs now have a defined size (8 here) which defeats the only (tangible[1]) advantage they have: int my_long_function_name(int bar, int baz) ^__tab_^ --Ben [1]File size savings are negligible.
Re: dfmt 0.1.0
On Friday, 6 March 2015 at 09:39:13 UTC, Walter Bright wrote: True, but on the other hand, a D lexer and parser are pretty simple. Did you mean simple compared to C++? I remember having to report/fix a LOT of bugs in the language specification and explore the DMD front end source code to get to where I am now.
Re: dfmt 0.1.0
On Friday, 6 March 2015 at 09:39:13 UTC, Walter Bright wrote: On 3/5/2015 1:04 AM, Russel Winder via Digitalmars-d-announce wrote: It would be good if the D implemented D parser were though. Parsing to create an AST is needed for many things. If each tool in the tool chain implements it's own… it just seems wrong. True, but on the other hand, a D lexer and parser are pretty simple. I'd like to hear your definition of simple.
Re: dfmt 0.1.0
On 3/5/2015 7:15 PM, Brian Schott wrote: You probably feel that way because tabs are better. dfmt only defaults to spaces because that's what's in the Phobos style guide. Spaces are used in Phobos because no two tools agree on what the tab size should be.
Re: dfmt 0.1.0
On Fri, 2015-03-06 at 01:37 -0800, Walter Bright via Digitalmars-d-announce wrote: On 3/5/2015 7:15 PM, Brian Schott wrote: You probably feel that way because tabs are better. dfmt only defaults to spaces because that's what's in the Phobos style guide. Spaces are used in Phobos because no two tools agree on what the tab size should be. That is the whole point of using tabs for indent, you can chose the indent amount: I tend to use 20ex. Remember a tab is not a number of spaces, it is semantic markup. Using spaces is a low-level hack founded on a lack of separation of concerns and abstraction. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
Re: dfmt 0.1.0
On 3/3/2015 3:03 PM, Brian Schott wrote: dfmt works by re-using my existing lexer and parser. The parser is run on the code first so that the formatting step knows a few things like the difference between the binary and unary forms of *. Line splitting is figured out using a badly mangled version of A*. How are comments handled?
Re: dfmt 0.1.0
On 3/5/2015 1:04 AM, Russel Winder via Digitalmars-d-announce wrote: It would be good if the D implemented D parser were though. Parsing to create an AST is needed for many things. If each tool in the tool chain implements it's own… it just seems wrong. True, but on the other hand, a D lexer and parser are pretty simple.
Re: dfmt 0.1.0
On Fri, 2015-03-06 at 09:54 -0500, Ben Boeckel via Digitalmars-d-announce wrote: On Fri, Mar 06, 2015 at 10:31:29 +, Russel Winder via Digitalmars-d-announce wrote: That is the whole point of using tabs for indent, you can chose the indent amount: I tend to use 20ex. Remember a tab is not a number of spaces, it is semantic markup. Using spaces is a low-level hack founded on a lack of separation of concerns and abstraction. The problem with tabs, IMO, are the following: - don't look right in patches (notice the different alignment of indented lines versus lines without any): -int foo(int bar) { - return bar; -} versus (assuming 8 space indents): -int foo(int bar) { -return bar; -} Is your point that in this case they have rendered identically? - I have yet to see an editor properly do tab-for-indent with proper space-for-alignment without manual management: int my_long_function_name(int bar, int baz) ^__tab_^^___spaces___^ But, for me anyway, the fundamental flaw here is the idea of alignment. Find a style that eliminates all this alignment malarkey. I really dislike the Go obsession with block style alignment of declarations. The core problem here is teletype, monospace font thinking. Using a proper proportional font for you code and you rapidly lose the need for all this alignment stuff. Real point but expressed as a bit of a troll, mostly to expose that this is likely a bikeshed issue. By the way, this is *wrong* because tabs now have a defined size (8 here) which defeats the only (tangible[1]) advantage they have: int my_long_function_name(int bar, int baz) ^__tab_^ In a real editor there is no hard line break, no need for this form of indentation. Should a line be too long for the rendering area either viewport or syntax directed soft line wrap are used. Having overflow is mixing content with rendering. --Ben [1]File size savings are negligible. Indeed, no argument with that point. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: dfmt 0.1.0
On Fri, Mar 06, 2015 at 19:55:10 +, Russel Winder via Digitalmars-d-announce wrote: On Fri, 2015-03-06 at 09:54 -0500, Ben Boeckel via Digitalmars-d-announce wrote: -int foo(int bar) { - return bar; -} versus (assuming 8 space indents): -int foo(int bar) { -return bar; -} Is your point that in this case they have rendered identically? Well it is now more apparent with more quoting. It now appears that the first block is using 3-space indents while the bottom looks just fine even with the quote markers. - I have yet to see an editor properly do tab-for-indent with proper space-for-alignment without manual management: int my_long_function_name(int bar, int baz) ^__tab_^^___spaces___^ But, for me anyway, the fundamental flaw here is the idea of alignment. Find a style that eliminates all this alignment malarkey. Well, when that means you're going to have absurdly long lines to deal with in anything other than your definition real editors (and I've never seen one which fits your definition). I really dislike the Go obsession with block style alignment of declarations. I won't say I'm a fan of it indiscriminently, but if it's that or 200+-character lines, I'll chop argument lists up a bit to fit something more reasonable. The core problem here is teletype, monospace font thinking. Using a proper proportional font for you code and you rapidly lose the need for all this alignment stuff. Real point but expressed as a bit of a troll, mostly to expose that this is likely a bikeshed issue. And I find that monospace fonts tend to make it much easier to tell the difference between 'l', '1', and 'I'. Not so important in English, but it can be all the difference in code. In a real editor there is no hard line break, no need for this form of indentation. Should a line be too long for the rendering area either viewport or syntax directed soft line wrap are used. Having overflow is mixing content with rendering. You're making assumptions about the features of your users' editors. These features are not trivial to implement and this basically requires things like pygments and other tools used to render code to the web with all kinds of logic to handle dynamic viewports of the shown code. IMO, it is even worse than putting #vim:, #kate:, or emacs formatting directives in your code since it is implicit. Personally, I use Vim because it works similarly for all uses. I don't know what I'd do if I had to work with a different editor for each language I work with. --Ben
Re: dfmt 0.1.0
On Fri, 2015-03-06 at 18:31 -0800, Walter Bright via Digitalmars-d-announce wrote: […] Unlike english prose, code follows patterns. With a monospace font, one can line up those patterns which makes for easier visual checking for errors. That works for you fine, but it doesn't work for me. I find monospace fonts and alignment of code gets in the way of reading and comprehending code. The difficulty here is turning a personal preference into a social orthodoxy. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: dfmt 0.1.0
On Fri, 2015-03-06 at 18:21 -0800, Walter Bright via Digitalmars-d-announce wrote: On 3/6/2015 2:31 AM, Russel Winder via Digitalmars-d-announce wrote: Remember a tab is not a number of spaces, it is semantic markup. All I can say is good luck with that. ASCII is not a markup language, and trying to reinvent it as one is doomed to failure. I try to use Unicode (UTF-8 encoded) languages, restricting to ASCII is very 1970s. The use of tab as the indent character is far from failing. Many C++ projects are returning to it, Go enforces it if you let it, many Python projects are starting to use it in spite of PEP-8. OK so Go enforced format does alignment as well on the assumption of monospace font. I dislike that so just carry on with proportional fonts. ASCII per se is not a markup language, and it retains all the quirks of teletypes, but that should not stop progress. Unicode replacing ASCII is one step forward. Rethinking old established rules is always worthwhile: just because a thing has always been done some way does not make it the right way, nor should it hinder change. I can also say from experience that removing tabs from Phobos source has removed a lot of irritation with messed up code rendering and wasted effort arguing about it. We're not going back :-) And I am not going to work on Phobos for exactly the same reasons. My loss, not yours. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: dfmt 0.1.0
On 2015-03-05 13:10, Daniel Murphy wrote: It isn't, but it's slowly getting better. eg You can now build the lexer as a library without pulling everything else in. Yes, that is absolute fantastic as a first step. It's quite possible that in a couple of years it will be in a state where it's reasonable to build tools on top of it. That would be awesome. You're doing a great job, keep it up. -- /Jacob Carlborg
Re: dfmt 0.1.0
On Thursday, 5 March 2015 at 09:02:25 UTC, Russel Winder wrote: Since using Go and working on a couple of fairly old C++ codebases, all of which use tab for indent, I have come to rather like it. You probably feel that way because tabs are better. dfmt only defaults to spaces because that's what's in the Phobos style guide.
Re: dfmt 0.1.0
On Thu, 2015-03-05 at 08:17 +0100, Jacob Carlborg via Digitalmars-d-announce wrote: On 2015-03-04 16:26, Russel Winder via Digitalmars-d-announce wrote: There ought to be for the compiler/formatter toolchain otherwise there will be problems. And if there is a D parser as library and it works why would anyone want another parser? The DMD front end is not really designed to be used as a library for tooling. It would be good if the D implemented D parser were though. Parsing to create an AST is needed for many things. If each tool in the tool chain implements it's own… it just seems wrong. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: dfmt 0.1.0
On Wed, 2015-03-04 at 21:22 +, Brian Schott via Digitalmars-d-announce wrote: […] That means that the Emacs plugin needs to start it automatically. Is this something on your todo list, or do you need a pull request? Implementing a separate parser based on the language spec has helped to find problems with the language spec. Having One True Implementation can lead to problems as well. https://issues.dlang.org/show_bug.cgi?id=10233 I just wonder if it is wise to have a single two chain with two distinct parsers which have separate lifecycles? (*) The exception is of course Phobos style which I find so annoying I can't read code formatted that way. By default dfmt tries to output Phobos style code. There is an option to use a different brace style and another one to use tabs. Since using Go and working on a couple of fairly old C++ codebases, all of which use tab for indent, I have come to rather like it. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: dfmt 0.1.0
Jacob Carlborg wrote in message news:md8vu6$hc1$1...@digitalmars.com... The DMD front end is not really designed to be used as a library for tooling. It isn't, but it's slowly getting better. eg You can now build the lexer as a library without pulling everything else in. It's quite possible that in a couple of years it will be in a state where it's reasonable to build tools on top of it.
Re: dfmt 0.1.0
On Wed, 2015-03-04 at 15:04 +, Dicebot via Digitalmars-d-announce wrote: […] All Brian tools use the same libdparse. Those include DCD, DScanner, dfix, dfmt and probably some others I am not aware of. It was also proposed for inclusion into Phobos a while ago but review pressure was too high. I try to use DCD when working with Emacs for D code, but I keep forgetting to start the server :-( I would certainly be happy to commit to using dfmt just as I use gofmt in Emacs. As long as the variation from my preferred style is not to much I can live with a One True Style (*). I hope it will eventually replace the legacy lexer/parser converted from DMD C sources - it is much more pleasant to work with. (there is no such thing as one D parser written in D for the compiler) There ought to be for the compiler/formatter toolchain otherwise there will be problems. And if there is a D parser as library and it works why would anyone want another parser? (*) The exception is of course Phobos style which I find so annoying I can't read code formatted that way. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: dfmt 0.1.0
On Wednesday, 4 March 2015 at 15:26:51 UTC, Russel Winder wrote: I try to use DCD when working with Emacs for D code, but I keep forgetting to start the server :-( I would certainly be happy to commit to using dfmt just as I use gofmt in Emacs. As long as the variation from my preferred style is not to much I can live with a One True Style (*). That means that the Emacs plugin needs to start it automatically. There ought to be for the compiler/formatter toolchain otherwise there will be problems. And if there is a D parser as library and it works why would anyone want another parser? Implementing a separate parser based on the language spec has helped to find problems with the language spec. Having One True Implementation can lead to problems as well. https://issues.dlang.org/show_bug.cgi?id=10233 (*) The exception is of course Phobos style which I find so annoying I can't read code formatted that way. By default dfmt tries to output Phobos style code. There is an option to use a different brace style and another one to use tabs.
Re: dfmt 0.1.0
On 2015-03-04 16:26, Russel Winder via Digitalmars-d-announce wrote: There ought to be for the compiler/formatter toolchain otherwise there will be problems. And if there is a D parser as library and it works why would anyone want another parser? The DMD front end is not really designed to be used as a library for tooling. -- /Jacob Carlborg
Re: dfmt 0.1.0
On Wednesday, 4 March 2015 at 07:43:44 UTC, Russel Winder wrote: On Tue, 2015-03-03 at 23:03 +, Brian Schott via Digitalmars-d-announce wrote: […] dfmt works by re-using my existing lexer and parser. The parser is run on the code first so that the formatting step knows a few things like the difference between the binary and unary forms of *. Line splitting is figured out using a badly mangled version of A*. Does this mean dfmt uses the same parser as the D D compiler? No. https://github.com/Hackerpilot/libdparse
Re: dfmt 0.1.0
On Wed, 2015-03-04 at 14:21 +, Dicebot via Digitalmars-d-announce wrote: […] No. https://github.com/Hackerpilot/libdparse Well this a bit not efficient, one D parser written in D for the compiler and a separate D parser written in D for the code formatter. What can go wrong. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: dfmt 0.1.0
On Wednesday, 4 March 2015 at 14:53:22 UTC, Russel Winder wrote: On Wed, 2015-03-04 at 14:21 +, Dicebot via Digitalmars-d-announce wrote: […] No. https://github.com/Hackerpilot/libdparse Well this a bit not efficient, one D parser written in D for the compiler and a separate D parser written in D for the code formatter. What can go wrong. All Brian tools use the same libdparse. Those include DCD, DScanner, dfix, dfmt and probably some others I am not aware of. It was also proposed for inclusion into Phobos a while ago but review pressure was too high. I hope it will eventually replace the legacy lexer/parser converted from DMD C sources - it is much more pleasant to work with. (there is no such thing as one D parser written in D for the compiler)
Re: dfmt 0.1.0
On 2/19/2015 6:21 PM, Brian Schott wrote: dfmt is a D source code formatting tool. https://github.com/Hackerpilot/dfmt/ https://github.com/Hackerpilot/dfmt/releases/tag/v0.1.0 Thanks for doing this. It's an important part of the D toolchain we need to have. At some point I want to merge it into the official release. I noticed it is remarkably small (1400 lines). What is its algorithm? How does it compare with gofmt and clang-format in how it works?
Re: dfmt 0.1.0
On Tue, 2015-03-03 at 23:03 +, Brian Schott via Digitalmars-d-announce wrote: […] dfmt works by re-using my existing lexer and parser. The parser is run on the code first so that the formatting step knows a few things like the difference between the binary and unary forms of *. Line splitting is figured out using a badly mangled version of A*. Does this mean dfmt uses the same parser as the D D compiler? -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: dfmt 0.1.0
On Tuesday, 3 March 2015 at 20:36:20 UTC, Walter Bright wrote: Thanks for doing this. It's an important part of the D toolchain we need to have. At some point I want to merge it into the official release. I noticed it is remarkably small (1400 lines). What is its algorithm? How does it compare with gofmt and clang-format in how it works? I haven't read the source to either of those programs, so I'm not sure how it compares. dfmt works by re-using my existing lexer and parser. The parser is run on the code first so that the formatting step knows a few things like the difference between the binary and unary forms of *. Line splitting is figured out using a badly mangled version of A*.
Re: dfmt 0.1.0
On Tue, 03 Mar 2015 12:35:44 -0800, Walter Bright wrote: On 2/19/2015 6:21 PM, Brian Schott wrote: dfmt is a D source code formatting tool. https://github.com/Hackerpilot/dfmt/ https://github.com/Hackerpilot/dfmt/releases/tag/v0.1.0 Thanks for doing this. It's an important part of the D toolchain we need to have. At some point I want to merge it into the official release. I noticed it is remarkably small (1400 lines). What is its algorithm? How does it compare with gofmt and clang-format in how it works? i bet dfmt parses the source and then regenerates it from scratch using AST it built. with all the work Brian put into his D parsing libraries, the main driver can be relatively small, i think. signature.asc Description: PGP signature
Re: dfmt 0.1.0
Brian Schott wrote in message news:updwbngwrilngxhun...@forum.dlang.org... dfmt is a D source code formatting tool. https://github.com/Hackerpilot/dfmt/ https://github.com/Hackerpilot/dfmt/releases/tag/v0.1.0 Is this on code.dlang.org? I can't find it.
Re: dfmt 0.1.0
On Sunday, 22 February 2015 at 09:07:16 UTC, Brian Schott wrote: On Sunday, 22 February 2015 at 08:48:16 UTC, Brian Schott wrote: On Friday, 20 February 2015 at 02:21:01 UTC, Brian Schott wrote: dfmt is a D source code formatting tool. https://github.com/Hackerpilot/dfmt/ https://github.com/Hackerpilot/dfmt/releases/tag/v0.1.0 I just tagged 0.1.1. The only change is a bug fix for a case where certain long lines with parenthesis wouldn't wrap properly. v0.1.2 is tagged... Move fast: things are broken, or something like that. Just submitted a PR to include pesky braces a la https://twitter.com/thedirtycoder/status/569339014085517312
Re: dfmt 0.1.0
On Sunday, 22 February 2015 at 09:07:16 UTC, Brian Schott wrote: On Sunday, 22 February 2015 at 08:48:16 UTC, Brian Schott wrote: On Friday, 20 February 2015 at 02:21:01 UTC, Brian Schott wrote: dfmt is a D source code formatting tool. https://github.com/Hackerpilot/dfmt/ https://github.com/Hackerpilot/dfmt/releases/tag/v0.1.0 I just tagged 0.1.1. The only change is a bug fix for a case where certain long lines with parenthesis wouldn't wrap properly. v0.1.2 is tagged... Move fast: things are broken, or something like that. 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. 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.
Re: dfmt 0.1.0
On Friday, 20 February 2015 at 02:21:01 UTC, Brian Schott wrote: dfmt is a D source code formatting tool. https://github.com/Hackerpilot/dfmt/ https://github.com/Hackerpilot/dfmt/releases/tag/v0.1.0 I just tagged 0.1.1. The only change is a bug fix for a case where certain long lines with parenthesis wouldn't wrap properly.
Re: dfmt 0.1.0
On Sunday, 22 February 2015 at 08:48:16 UTC, Brian Schott wrote: On Friday, 20 February 2015 at 02:21:01 UTC, Brian Schott wrote: dfmt is a D source code formatting tool. https://github.com/Hackerpilot/dfmt/ https://github.com/Hackerpilot/dfmt/releases/tag/v0.1.0 I just tagged 0.1.1. The only change is a bug fix for a case where certain long lines with parenthesis wouldn't wrap properly. v0.1.2 is tagged... Move fast: things are broken, or something like that.
Re: dfmt 0.1.0
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
Re: dfmt 0.1.0
On Friday, 20 February 2015 at 05:53:32 UTC, Brian Schott wrote: On Friday, 20 February 2015 at 05:23:45 UTC, Joakim wrote: On Friday, 20 February 2015 at 02:21:01 UTC, Brian Schott wrote: dfmt is a D source code formatting tool. https://github.com/Hackerpilot/dfmt/ https://github.com/Hackerpilot/dfmt/releases/tag/v0.1.0 Thanks, you should list some of the formatting changes it makes in the README. It doesn't do formatting changes. It wipes out the formatting during lexing and builds it up from scratch. The only thing that gets preserved is that it will look at line numbers on comments and try to keep them in roughly the same place. (For example, // comments that are on the end of a line instead of on the next line) Several examples in the README would indeed be nice.
Re: dfmt 0.1.0
On Friday, 20 February 2015 at 23:00:25 UTC, Brad Anderson wrote: From what I understand they implemented a LaTeX style weighted line breaker which would explain why it works so much better than a typical code formatter. It's very smart about how it does line breaks. This seems to make all the difference. dfmt uses a weighting system for line breaks as well, though because this is 0.1.0 it doesn't always do what I expect it to do.
Re: dfmt 0.1.0
On Friday, 20 February 2015 at 02:21:01 UTC, Brian Schott wrote: dfmt is a D source code formatting tool. https://github.com/Hackerpilot/dfmt/ https://github.com/Hackerpilot/dfmt/releases/tag/v0.1.0 Great! I've been using clang-format lately for my C++ code and it's really blown me away how good it is. It's not opinionated about how things should be, it just does whatever style you've set it to. The Visual Studio plugin they have just gives me a keyboard shortcut and when I hit it, it formats the current line or selection. I waste almost no time formatting code now. I just type and hit the format key and move on. If it formatted something differently than how I would have done it I just let it be because how it formatted is usually almost as good anyway. I feel like it's been as big of boon to my coding speed as learning vim was. From what I understand they implemented a LaTeX style weighted line breaker which would explain why it works so much better than a typical code formatter. It's very smart about how it does line breaks. This seems to make all the difference. This is all to say I hope dfmt becomes as awesome as clang-format is at some point. Hopefully I can find some time to contribute.
Re: dfmt 0.1.0
On Friday, 20 February 2015 at 02:21:01 UTC, Brian Schott wrote: dfmt is a D source code formatting tool. https://github.com/Hackerpilot/dfmt/ https://github.com/Hackerpilot/dfmt/releases/tag/v0.1.0 Thanks, you should list some of the formatting changes it makes in the README.
Re: dfmt 0.1.0
On Friday, 20 February 2015 at 05:53:32 UTC, Brian Schott wrote: On Friday, 20 February 2015 at 05:23:45 UTC, Joakim wrote: On Friday, 20 February 2015 at 02:21:01 UTC, Brian Schott wrote: dfmt is a D source code formatting tool. https://github.com/Hackerpilot/dfmt/ https://github.com/Hackerpilot/dfmt/releases/tag/v0.1.0 Thanks, you should list some of the formatting changes it makes in the README. It doesn't do formatting changes. It wipes out the formatting during lexing and builds it up from scratch. The only thing that gets preserved is that it will look at line numbers on comments and try to keep them in roughly the same place. (For example, // comments that are on the end of a line instead of on the next line) Well, you should indicate what that new formatting is in the README, so potential users know what to expect without having to run it first.
Re: dfmt 0.1.0
On Friday, 20 February 2015 at 05:23:45 UTC, Joakim wrote: On Friday, 20 February 2015 at 02:21:01 UTC, Brian Schott wrote: dfmt is a D source code formatting tool. https://github.com/Hackerpilot/dfmt/ https://github.com/Hackerpilot/dfmt/releases/tag/v0.1.0 Thanks, you should list some of the formatting changes it makes in the README. It doesn't do formatting changes. It wipes out the formatting during lexing and builds it up from scratch. The only thing that gets preserved is that it will look at line numbers on comments and try to keep them in roughly the same place. (For example, // comments that are on the end of a line instead of on the next line)
Re: dfmt 0.1.0
On Friday, 20 February 2015 at 02:21:01 UTC, Brian Schott wrote: https://github.com/Hackerpilot/dfmt/ https://github.com/Hackerpilot/dfmt/releases/tag/v0.1.0 Congrats, I found the reformatting a bit harsh from time to time, but it's a good opportunity to finally settle style discussions.