|
|
|
@ -35,6 +35,13 @@ class Parser(private val tokens: List<Token>) {
|
|
|
|
|
|
|
|
|
|
|
|
private fun classDeclaration(): ClassStmt {
|
|
|
|
private fun classDeclaration(): ClassStmt {
|
|
|
|
val name = consume(IDENTIFIER, "Expect class name.")
|
|
|
|
val name = consume(IDENTIFIER, "Expect class name.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var superClass: Variable? = null
|
|
|
|
|
|
|
|
if (match(LESS)) {
|
|
|
|
|
|
|
|
consume(IDENTIFIER, "Expect superclass name.")
|
|
|
|
|
|
|
|
superClass = Variable(previous())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
consume(LEFT_BRACE, "Expect '{' before class body.")
|
|
|
|
consume(LEFT_BRACE, "Expect '{' before class body.")
|
|
|
|
|
|
|
|
|
|
|
|
val methods: MutableList<Function> = ArrayList()
|
|
|
|
val methods: MutableList<Function> = ArrayList()
|
|
|
|
@ -44,7 +51,7 @@ class Parser(private val tokens: List<Token>) {
|
|
|
|
|
|
|
|
|
|
|
|
consume(RIGHT_BRACE, "Expect '}' after class body.")
|
|
|
|
consume(RIGHT_BRACE, "Expect '}' after class body.")
|
|
|
|
|
|
|
|
|
|
|
|
return ClassStmt(name, methods)
|
|
|
|
return ClassStmt(name, superClass, methods)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun function(kind: String): Function {
|
|
|
|
private fun function(kind: String): Function {
|
|
|
|
|