Laurent,

Sounds like a good plan.

To answer your questions:

> 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 ?

pprint operates on clojure objects directly and doesn't really
consider where they came from. It has no concept of parsing input at
all.  However, output is very flexible, being driven by user-definable
dispatch functions. The architecture is based on the standard Lisp
pretty print architecture called XP. (This is the pretty printer
that's included in Common Lisp, for instance). You might want to look
at the paper "XP. A Common Lisp Pretty Printing System" which is
available at http://dspace.mit.edu/handle/1721.1/6504. The Clojure
implementation is more "clojure-y" but the algorithms and concepts are
substantially the same.

The pretty printer includes two dispatch functions, simple and code.
These are defined in clojure.contrib.pprint.dispatch.clj. You probably
want to skim over those to see the structure of the Clojure
implementation of this stuff.

I've begun to do more complete documentation of the pretty printer and
how to do dispatch here: 
http://code.google.com/p/clojure-contrib/wiki/PrettyPrinting
but I've gotten distracted with getting all the doc moved from google
code to github. I should be back to fleshing out that documentation
soon.


> 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).

Not clear to me that you would need the "clojure reader parsed code"
in your implementation since you wouldn't be using that directly and
you could extract relevant information from the source code preserving
reader (like func names, etc.), but obviously you know more about how
you're using the results.

But yes, you will want to work in terms of an intermediate form that
you can pprint and work on as well.

Then you would have a modified version of the code-dispatch that
understood the enhanced data structures that were in that version (I
don't think that should be too hard).

One experiment I've been doing is to build an "Object Explorer" based
on pprint. The thing I added (but that's not totally integrated back
into pprint yet), is callbacks to let you map structure to output
location. I use it there for allowing the user to click on parts of
the object displayed to expand and contract its subobjects.

I can imagine that in a IDE this could be used to support structural
motion, paredit type things, etc.

I did a little talk on this here: http://blip.tv/file/2286313 and the
current state of the explorer is on github: 
http://github.com/tomfaulhaber/clj-explorer

>
> 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 :-)
>

Yeah, I use core.clj a lot too. I *do* worry about performance here.
pprint currently renders 300-400 lines per second on my machine. It's
getting faster, but I doubt it will ever exceed 10x where it is now
(though I might surprise myself).

Keep me up to date on how it's going and feel free to bother me about
whatever. (You can often find me in #clojure as replaca, also.)

Tom
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to