On Wed, May 20, 2009 at 2:30 PM, J Haas <Myrdred / gmail.com> wrote:

> You keep on saying this, yet I have not seen one example of code that
> demonstrates that using dedent couldn't work. Basically, we're looking
> for some code which, if you removed the all ends, a script following
> simple deterministic rules would not be able to unambigiously decide
> where to put them back. I agree that "put an end wherever you see a
> dedent" is naive and wouldn't work... but "put an end wherever you see
> a dedent which isn't followed by a keyword which extends the current
> expression, such as elsif or rescue or ensure" might.
>

Okay, you just want an example I guess.  Code speaks louder than words!

Here is an example Ruby program:

foo = [1,2,3]
x = foo.map do |n|
  n += 1
  n *= 2
end
result = case x
when Array
  x.map! do |n|
    n *= 3
    n += 4
  end
when NilClass
  x
end
result = if result.size > 10
  result[0..2]
else
  result
end
p result

The output of this program is:

[16, 22, 28]

Show me how you would parse the equivalent program in an
indentation-sensitive Ruby, e.g.:

foo = [1,2,3]
x = foo.map do |n|
  n += 1
  n *= 2
result = case x
when Array
  x.map! do |n|
    n *= 3
    n += 4
when NilClass
  x
result = if result.size > 10
  result[0..2]
else
  result
puts result

I'd be particularly interested in solutions which can be parsed with a LALR,
LL*, or PEG parser.  The approach you're describing does not sound like it
could be expressed as a CFG, not that there isn't a CFG solution for this,
just that the one you're proposing is not.

-- 
Tony Arcieri
medioh.com