Hi Tom, Thanks for the answer. I already have some embryonic antlr grammar for clojure, but I'm willing to give pprint a thourough try.
I'll play with your code. Do you have a first pass over the clojure reader to attach other meta information as you go, or do you directly consume the clojure data structures the reader passes to you ? If so, then certainly there would be the need to have an intermediate structure that would be the output of both "clojure reader parsed code" and "source code preserving reader parsed code" ? So that the rest of the formatting code is decoupled from that ? (But that will certainly be lots of changes, and in all parts I guess). As far as IDE integration is concerned, i would not bother (at first) about incremental thing. I rather intend to always parse the entire edited file content (of course if this causes a performance problem, I might rethink about it). For performance testing, I've found that clojure/core.clj is a good candidate :-) Regards, -- Laurent 2009/6/30 Tom Faulhaber <tomfaulha...@gmail.com>: > > Hi Laurent, > > I think that pprint might be a good foundation for what you are doing, > but there are a couple of issues that need to be dealt with first. > > First, pprint works directly on Clojure objects and not strings, so > the code will need to be read first. > > Second, the Clojure reader is lossy - it strips comments, metadata > tags (#^{}) and expands forms like backquote and reader time > evaluation before passing you the result. > > The first thing I would do is look at making a modified reader that > could read chunks of s-expression and pass back raw data. In a perfect > world, this reader would be much more resistant to syntax problems > (for example by "assuming" extra opening or closing brackets of > various types). > > Then I would look at how I was going to attach the pprint to the > editor. In practice, I think you want the reformatting to be very > incremental, working on small chunks of code at a time, but you know > better than I. > > Using the code dispatch in pretty printing should be pretty easy once > you have this infrastructure. You'll probably want to customize it a > little, but that's fairly straightforward. You'll also probably want > to "clean up" any syntax corrections you made. I might think about > adding metadata to the read structure and then using that in the > dispatch to skip writing open parens that weren't really there, for > instance. > > I've been thinking about doing all this, but it's not at the top of my > list right now (working on a new contrib autodoc tool and making > pprint cleaner and faster plus my real job!). But I'm happy to discuss/ > help in the short term. > > HTH, > > Tom > > On Jun 30, 7:08 am, Laurent PETIT <laurent.pe...@gmail.com> wrote: >> Hi all, >> >> I want to add source code formatting / auto-indenting to the clojure >> plugin for eclipse. >> >> I had asked other IDE plugin creators, and it seems that they >> leveraged the specifics of their respective platforms to do so. So I >> have nothing substantial to "steal from them" not requiring a fair >> amount of rework :-) >> >> I'm now facing the following two paths : >> >> * try to leverage Eclipse's way of doing clojure source code >> formatting / auto-indenting and create yet another lib for doing that >> very specifically >> >> * try to do it in clojure so that it can also be used as a standalone >> command-line / whatever utility for mass source code reformatting ... >> >> So what is my question ? :-) >> >> Do you know if pprint lib now is (or will in a near future) be able to >> handle this use case : that is not only formatting clojure code >> returned by the reader, but also clojure code as string, and >> potentially broken code (and so it would have to preserve comments, >> literal metadata in the exact form they were written, etc.) >> >> Do you know whether there is another existing effort to do this in >> plain clojure, or at least sufficiently independtly from an existing >> IDE framework so that I can painlessly reuse it ? >> >> Thanks in advance, >> >> -- >> Laurent > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---