From: Brian Candler Date: 2007-05-21T16:32:46+09:00 Subject: Re: How to adopt "Python Style" indentation for Ruby On Mon, May 21, 2007 at 03:53:25PM +0900, Giles Bowkett wrote: > What would it take to write a Ruby pre-processor which parsed Ruby > written in a Pythonic style and turned it into actual valid Ruby? Or > even a Ruby library like Xavier's Perl example, which allows you to > code Ruby as if it were Python after just requiring the library? The > original post's main argument was that indentation is a stable, > consistent shorthand for Ruby's end statements. If all you're looking > to do is use tabs as syntactic sugar, then it should be pretty easy to > just write something which knows how to translate a sequence of tabs > in and tabs out into a series of end statements at the end. Actually, I'd happily settle for something simpler: a pretty-printer which just reads (normal) Ruby and re-outputs it with standard indentation. This would immediately solve the problem of "where did I miss out an 'end' statement?" - you'd just pipe it into this utility and inspect. In the past I've had to resort to binary chops to solve this: copy source.rb to x.rb and remove chunks of method definitions until I find the offending one. This is painful. As an alternative: the existing Ruby parser could be modified to spit out a warning whenever it sees non-standard nesting, e.g. "end at line doesn't align with start of block/method at line ". It only need do this for an 'end' which is at the start of a line. Regards, Brian.