fix: top level block, even isolated, is treated as a lambda too
This commit is contained in:
parent
c0cf190452
commit
4dc73b91c2
@ -47,7 +47,7 @@ One interesting way of using closure isolation is to keep state of the functions
|
|||||||
>>> 0
|
>>> 0
|
||||||
>>> 1
|
>>> 1
|
||||||
>>> 2
|
>>> 2
|
||||||
>> void
|
>>> void
|
||||||
|
|
||||||
Inner `counter` is not accessible from outside, no way; still it is kept
|
Inner `counter` is not accessible from outside, no way; still it is kept
|
||||||
between calls in the closure, as inner function `doit`, returned from the
|
between calls in the closure, as inner function `doit`, returned from the
|
||||||
|
@ -16,14 +16,14 @@ class Compiler(
|
|||||||
|
|
||||||
private fun parseScript(start: Pos, tokens: CompilerContext): Script {
|
private fun parseScript(start: Pos, tokens: CompilerContext): Script {
|
||||||
val statements = mutableListOf<Statement>()
|
val statements = mutableListOf<Statement>()
|
||||||
while (parseStatement(tokens)?.also {
|
while (parseStatement(tokens,braceMeansLambda = true)?.also {
|
||||||
statements += it
|
statements += it
|
||||||
} != null) {/**/
|
} != null) {/**/
|
||||||
}
|
}
|
||||||
return Script(start, statements)
|
return Script(start, statements)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseStatement(cc: CompilerContext): Statement? {
|
private fun parseStatement(cc: CompilerContext,braceMeansLambda: Boolean = false): Statement? {
|
||||||
while (true) {
|
while (true) {
|
||||||
val t = cc.next()
|
val t = cc.next()
|
||||||
return when (t.type) {
|
return when (t.type) {
|
||||||
@ -49,6 +49,9 @@ class Compiler(
|
|||||||
|
|
||||||
Token.Type.LBRACE -> {
|
Token.Type.LBRACE -> {
|
||||||
cc.previous()
|
cc.previous()
|
||||||
|
if( braceMeansLambda )
|
||||||
|
parseExpression(cc)
|
||||||
|
else
|
||||||
parseBlock(cc)
|
parseBlock(cc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user