Caleb Clausen <vikkous / gmail.com> wrote in news:347c648b0905251250j61ce408cva469529722fe500c / mail.gmail.com: > On 5/25/09, J Haas <Myrdred / gmail.com> wrote: >> Now, having said all that: I do not _know_ that Tony's claim is >> false. As I said, I was surprised to be told that my proposal >> was impossible and I lack the theoretical background to prove >> otherwise. So if anyone out there agrees with Tony that Pythonic >> indentation in Ruby would not be merely ill-advised but >> _impossible_ I'd appreciate an example. Then I can stop wasting >> my time. > > It's certainly not impossible, as the script you posted shows. > That script is a hack, however, since it doesn't lex its input > properly and it will fail in obscure cases. I've written a proper > implementation, based on my RubyLexer library. > > Basically, it makes the end keyword optional. If you leave off > the end, the preprocessor inserts an end for you at the next line > indented at or below the level of indentation of the line which > started the scope. > > End is optional, so you can still write things like this: > begin > do_something > end until done? > (However, you'd better make damn sure you get the end indented to > the right level!) If I'm reading this right, given x.foreach ... if ... while ... do_something something_else ... would pop an end at the level of the 'while' only. You really need an end there and at each succeeding dedent level up to the level of the next statement ('something_else'). Not saying this is something that should be done, but if it is done, that's what you need to do. > This script uses RubyLexer to extract a stream of tokens and > modify it, then turn those tokens back into ruby code. Since > RubyLexer is a complete stand-alone lexer, this should be a very > thorough solution, free of insoluable little problems due to the > script's inability to follow where comments and strings start and > stop. (That said, I'm sure there will be some problems with it, > as it's pretty raw code.) > > As different programs have a variety of interpretations as to the > width of a tab character, tabs for indentation are absolutely > forbidden by endless.rb. > > If you're interested, please see: > http://gist.github.com/117694 > -- rzed