AndreVanDelft / scala

The SubScript extension to the Scala programming language
http://www.subscript-lang.org/
12 stars 1 forks source link

Script lambdas can't handle line break appropriately #24

Open anatoliykmetyuk opened 10 years ago

anatoliykmetyuk commented 10 years ago

Consider following program:

val script = [doSomething]
println(x)

In AST view, it will translate to:

val `script` = subscript.DSL._script(this, scala.Symbol("<lambda>"))(ScriptApply(<empty>, List(doSomething))).println(x);

Apparently, ".println(x)" at the end is not what we want.

There are 2 workarounds, both clumsy though:

val script = [doSomething];

println(x)

(note that both semicolon and extra line break are required, or it will not work)

Or:

val script = ([doSomething])
println(x)
anatoliykmetyuk commented 10 years ago

By the way, construct like:

anchor launch [doSomething]

also doesn't work. To make it work, we need to do it as follows:

anchor launch ([doSomething])
AndreVanDelft commented 10 years ago

Unhappy with the parsing of println(x) I think this should behave as comparable normal Scala code does. If you had instead of [doSomething] a "normal" Scala object, would it be compiled the same?

I understand that in

anchor launch [doSomething]

the open bracket is seen as the start of a type parameter list. We cannot improve this behaviour I am afraid.