Handle multiple variable assignment in a single statement
@@ -1202,6 +1202,7 @@ static void funDeclaration(Compiler *compiler) {
}
static void varDeclaration(Compiler *compiler) {
+ do {
uint8_t global = parseVariable(compiler, "Expect variable name.");
if (match(compiler, TOKEN_EQUAL)) {
@@ -1211,9 +1212,11 @@ static void varDeclaration(Compiler *compiler) {
// Default to nil.
emitByte(compiler, OP_NIL);
}
- consume(compiler, TOKEN_SEMICOLON, "Expect ';' after variable declaration.");
defineVariable(compiler, global);
+ } while (match(compiler, TOKEN_COMMA));
+
+ consume(compiler, TOKEN_SEMICOLON, "Expect ';' after variable declaration.");
}
static void expressionStatement(Compiler *compiler) {
