From: Brad Phelan Date: 2007-05-22T00:50:03+09:00 Subject: Re: How to adopt "Python Style" indentation for Ruby bbiker wrote: > On May 21, 3:32 am, Brian Candler wrote: >> 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. > > I use Arachono Ruby IDE. Its editor has a feature whereby I can select > a number of lines to comment out or uncomment the lines. This makes > finding the missing end fairly easier. > > I find python indentation much harder to read. For my use, I rather > stick with the "end"s. > I've tried posting several times without success ... here again. http://xtargets.com/snippets/posts/show/68 shows a partial solution to your challenge by overloading require. It is a quick hack but shows you how to write your own pre-processor. The new require checks to find files of type .pyrb and then coverts them to .rb files before loading them. -- Brad Phelan http://xtargets.com