brownplt / pyret-lang

The Pyret language.
Other
1.07k stars 110 forks source link

Wrong indenting with for and function call in tuple #1174

Closed sorawee closed 6 years ago

sorawee commented 7 years ago
fun x():
  for x(x from {x(x); x}):
    x
end
end

should be indented as:

fun x():
  for x(x from {x(x); x}):
    x
  end
end

But currently it doesn't.

blerner commented 7 years ago

@belph this is really awkward to handle, since we need to determine if something is a tuple or an object...

sorawee commented 6 years ago

I think this is closely related:

fun a():
  {a(a)}
  block:
  a
end
end

should be indented as:

fun a():
  {a(a)}
  block:
    a
  end
end

Weirdly in this case only block would trigger the problem. Other constructs like lam or fun does not cause a problem.

sorawee commented 6 years ago

(We have about 3 Piazza posts complaining this bug today...)

blerner commented 6 years ago

Sorry, this is a fiddly one to figure out. Tuples and shorthand lambdas and objects are easy to mistake for one another. @belph it looks like the problem here is that you're too eager to say "if I see an LPAREN when there's a 'braced-expr on top of the stack, treat it as a lambda" -- it needs to be a LPAREN that immediately follows an LBRACE. I tried adding a check at the end of the indenter that says if I see an identifier when I have 'braced-expr on the top of the stack, turn it into an 'object instead. But that gives weird indentation too. Could you take a look please?

peblair commented 6 years ago

Apologies; this slipped through my inbox. If I can't get to it before then, I'll take a look this weekend.

peblair commented 6 years ago

I had time before then. It should be fixed in brownplt/pyret-codemirror-mode@34f9da9. I'll close this now, despite the inevitable bug @blerner will find with the fixing commit.

blerner commented 6 years ago

pyret.el, too, please?

peblair commented 6 years ago

@blerner: Should I update master or horizon?

sorawee commented 6 years ago

As I understand, the answer is horizon.