correct end-block token processing (detect more errors)
This commit is contained in:
parent
c398496ee0
commit
e916d9805a
@ -65,9 +65,17 @@ class Compiler(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
parseStatement(braceMeansLambda = true)?.also {
|
val s = parseStatement(braceMeansLambda = true)?.also {
|
||||||
statements += it
|
statements += it
|
||||||
} ?: break
|
}
|
||||||
|
if (s == null) {
|
||||||
|
when( t.type ) {
|
||||||
|
Token.Type.RBRACE, Token.Type.EOF, Token.Type.SEMICOLON -> {}
|
||||||
|
else ->
|
||||||
|
throw ScriptError(t.pos, "unexpeced `${t.value}` here")
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
} while (true)
|
} while (true)
|
||||||
return Script(start, statements)//returnScope.needCatch)
|
return Script(start, statements)//returnScope.needCatch)
|
||||||
@ -833,8 +841,18 @@ class Compiler(
|
|||||||
val isExtern = cc.skipId("extern")
|
val isExtern = cc.skipId("extern")
|
||||||
when {
|
when {
|
||||||
cc.matchQualifiers("fun", "private") -> parseFunctionDeclaration(Visibility.Private, isExtern)
|
cc.matchQualifiers("fun", "private") -> parseFunctionDeclaration(Visibility.Private, isExtern)
|
||||||
cc.matchQualifiers("fun", "private", "static") -> parseFunctionDeclaration(Visibility.Private, isExtern, isStatic = true)
|
cc.matchQualifiers("fun", "private", "static") -> parseFunctionDeclaration(
|
||||||
cc.matchQualifiers("fun", "static") -> parseFunctionDeclaration(Visibility.Public, isExtern, isStatic = true)
|
Visibility.Private,
|
||||||
|
isExtern,
|
||||||
|
isStatic = true
|
||||||
|
)
|
||||||
|
|
||||||
|
cc.matchQualifiers("fun", "static") -> parseFunctionDeclaration(
|
||||||
|
Visibility.Public,
|
||||||
|
isExtern,
|
||||||
|
isStatic = true
|
||||||
|
)
|
||||||
|
|
||||||
cc.matchQualifiers("fn", "private") -> parseFunctionDeclaration(Visibility.Private, isExtern)
|
cc.matchQualifiers("fn", "private") -> parseFunctionDeclaration(Visibility.Private, isExtern)
|
||||||
cc.matchQualifiers("fun", "open") -> parseFunctionDeclaration(isOpen = true, isExtern = isExtern)
|
cc.matchQualifiers("fun", "open") -> parseFunctionDeclaration(isOpen = true, isExtern = isExtern)
|
||||||
cc.matchQualifiers("fn", "open") -> parseFunctionDeclaration(isOpen = true, isExtern = isExtern)
|
cc.matchQualifiers("fn", "open") -> parseFunctionDeclaration(isOpen = true, isExtern = isExtern)
|
||||||
@ -1541,7 +1559,7 @@ class Compiler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun
|
private suspend fun
|
||||||
parseFunctionDeclaration(
|
parseFunctionDeclaration(
|
||||||
visibility: Visibility = Visibility.Public,
|
visibility: Visibility = Visibility.Public,
|
||||||
@Suppress("UNUSED_PARAMETER") isOpen: Boolean = false,
|
@Suppress("UNUSED_PARAMETER") isOpen: Boolean = false,
|
||||||
isExtern: Boolean = false,
|
isExtern: Boolean = false,
|
||||||
@ -1613,7 +1631,7 @@ class Compiler(
|
|||||||
(thisObj as? ObjInstance)?.let { i ->
|
(thisObj as? ObjInstance)?.let { i ->
|
||||||
fnBody.execute(ClosureScope(this, i.instanceScope))
|
fnBody.execute(ClosureScope(this, i.instanceScope))
|
||||||
}
|
}
|
||||||
// other classes can create one-time scope for this rare case:
|
// other classes can create one-time scope for this rare case:
|
||||||
?: fnBody.execute(thisObj.autoInstanceScope(this))
|
?: fnBody.execute(thisObj.autoInstanceScope(this))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,4 +43,21 @@ class OOTest {
|
|||||||
assertEquals( "foo!", Point.getData() )
|
assertEquals( "foo!", Point.getData() )
|
||||||
""".trimIndent())
|
""".trimIndent())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Test
|
||||||
|
fun testDynamic() = runTest {
|
||||||
|
eval("""
|
||||||
|
println("0")
|
||||||
|
class DynamicTest : Dynamic {
|
||||||
|
|
||||||
|
fun getDynamic(name) {
|
||||||
|
if (name == "foo") "bar" else null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println("1")
|
||||||
|
val d = DynamicTest()
|
||||||
|
println(d)
|
||||||
|
println("2")
|
||||||
|
""".trimIndent())
|
||||||
|
}
|
||||||
}
|
}
|
@ -2375,8 +2375,6 @@ class ScriptTest {
|
|||||||
x++; y++
|
x++; y++
|
||||||
}
|
}
|
||||||
assertEquals(p, Point(2,3))
|
assertEquals(p, Point(2,3))
|
||||||
>>> void
|
|
||||||
|
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -2393,8 +2391,6 @@ class ScriptTest {
|
|||||||
y++
|
y++
|
||||||
}
|
}
|
||||||
assertEquals(p, Point(2,3))
|
assertEquals(p, Point(2,3))
|
||||||
>>> void
|
|
||||||
|
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user