On 5/21/07, Brad Phelan <phelan / tttech.ttt> wrote:
> 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.

If you change this:

                if l =~ /:\s*$/
                    stack.push indent
                    l.gsub! /:\s*$/,''
                end

to this:

                if l.sub!(/(\|[^\|]*\|)\s*:\s*$/,' do \1') or l.sub!(/:\s*$/,'')
                    stack.push indent
                end

your example won't need the do's:

def foo:
    [1,2,3,4].each |i|:
        puts i
        [1,2,3,4].each |i|:
            puts i

Unfortunately, this isn't too easy to implement in a formal parser
though, since the "|" after each initially looks ambiguous with the
"|" operator.  The ":" to start the indentation style block should
probaly be where the "do" or "{" used to.  You could even get rid of
the || by using ":" to start the args and "\n" to end the args (you'd
need an exlicit * to mean don't care about the args):

def foo :
    [1,2,3,4].each : i
        puts i
        [1,2,3,4].each : i
            puts i

In this example, you get rid of 3 lines and 9 symbols/identifiers (and
add the 3 ":"s) compared to the original ruby.

All of these ":" solutions would have potential incompatibilities with
the ? : operator and :symbol.