From: Robert Feldt Date: 2002-01-14T18:25:07+09:00 Subject: Re: MetaRuby : RubySchema.rb howto? Hi Tobias et al, FYI, I've played with the following way of specifying pretty-printers for RubyAst/RubyTerms/RubySchema in Rockit (its got a similar scheme to Matju's but its not typed; will probably use Matju's scheme in future versions): * You specify PPDoc's by giving a string with slots that can be later filled in. Slots are given as "#" followed by a number starting at 0. Example (for a simple if without else-clause etc): p1 = PPDoc["if (#0)\n #1\nend"] p2 = PPDoc["#0 == #1"] p2[1,2].to_s #=> "1 == 2" p1[p2["a", 1], "puts a\na"].to_s gives: if (a == 1) puts a a end This could be nice since you get a lego set of pretty-printers that you can plug-and-play with. The logical step would be to connect something like that to the RubyTerms/RubySchema so that you can pretty-print them directly. BTW, you can override indentation etc by setting options to a Printer object that you send to PPDoc#format. To make it work you'd probably need optionals that I haven't yet added though (for example the behavior for if should be different depending on if its chained with other ifs etc). Note that there is no real pretty-printing in PPDoc's yet, such as implemented in prettyprinter.rb in Ruby 1.7.2, ie. it won't break lines if more than 79 chars wide. IMHO, the problem with that implementation (and the funcprog combinator libs its based on) is that there is no way to explicitly state that you want a linebreak (or am I wrong here)? For example I rarely want my if's printed as if (condition) statement end even if it fits on a line. But I may be wrong cause I only took a brief look at prettyprint and saw it was based on Wadler's prettyprint libs (which may also give it exponential alg complexity; anyone checked that?). I may have jumped to conclusions... Regards, Robert