Eric Mahurin
5/21/2007 7:59:00 PM
On 5/21/07, Brad Phelan <bradphelan@xtargets.com> wrote:
> though I do like the economy of
>
> > def foo :
> > [1,2,3,4].each : i
> > puts i
> > [1,2,3,4].each : i
> > puts i
>
> Perhaps another symbol other than :
:: could work. As long as it is not followed by an identifier
character it shouldn't collide. You could use this code for starting
the block:
if l.sub!(/::\s*$/,'') or l.sub!(/::\s+(.*)$/,' do |\1|')
stack.push indent
end
and then this should work:
def foo ::
[1,2,3,4].each :: i
puts i
[1,2,3,4].each :: i
puts i
With this code, to do the equivalent of do...end w/o args you'd need
an explicit do before the :: . This could be fixed in a real parser
since it would know whether the block is for a builtin
def/while/if/class statement versus a standard lambda block. In the
lambda block context maybe you'd want "::\n" to mean "do ||" and use
":: *\n" to mean "do |*|" (which is equivalent to a block without
args). Otherwise you couldn't get the equivalent of "do ||".