Add support for comma-separated imports
This commit is contained in:
parent
7497994100
commit
b872410b95
@ -1551,27 +1551,29 @@ static size_t importModule(KrkToken * startOfName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void importStatement() {
|
static void importStatement() {
|
||||||
KrkToken firstName = parser.current;
|
do {
|
||||||
KrkToken startOfName;
|
KrkToken firstName = parser.current;
|
||||||
size_t ind = importModule(&startOfName);
|
KrkToken startOfName;
|
||||||
if (match(TOKEN_AS)) {
|
size_t ind = importModule(&startOfName);
|
||||||
consume(TOKEN_IDENTIFIER, "Expected identifier after `as`");
|
if (match(TOKEN_AS)) {
|
||||||
ind = identifierConstant(&parser.previous);
|
consume(TOKEN_IDENTIFIER, "Expected identifier after `as`");
|
||||||
} else if (startOfName.length != firstName.length) {
|
ind = identifierConstant(&parser.previous);
|
||||||
/**
|
} else if (startOfName.length != firstName.length) {
|
||||||
* We imported foo.bar.baz and 'baz' is now on the stack with no name.
|
/**
|
||||||
* But while doing that, we built a chain so that foo and foo.bar are
|
* We imported foo.bar.baz and 'baz' is now on the stack with no name.
|
||||||
* valid modules that already exist in the module table. We want to
|
* But while doing that, we built a chain so that foo and foo.bar are
|
||||||
* have 'foo.bar.baz' be this new object, so remove 'baz', reimport
|
* valid modules that already exist in the module table. We want to
|
||||||
* 'foo' directly, and put 'foo' into the appropriate namespace.
|
* have 'foo.bar.baz' be this new object, so remove 'baz', reimport
|
||||||
*/
|
* 'foo' directly, and put 'foo' into the appropriate namespace.
|
||||||
emitByte(OP_POP);
|
*/
|
||||||
parser.previous = firstName;
|
emitByte(OP_POP);
|
||||||
ind = identifierConstant(&firstName);
|
parser.previous = firstName;
|
||||||
EMIT_CONSTANT_OP(OP_IMPORT, ind);
|
ind = identifierConstant(&firstName);
|
||||||
}
|
EMIT_CONSTANT_OP(OP_IMPORT, ind);
|
||||||
declareVariable();
|
}
|
||||||
defineVariable(ind);
|
declareVariable();
|
||||||
|
defineVariable(ind);
|
||||||
|
} while (match(TOKEN_COMMA));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fromImportStatement() {
|
static void fromImportStatement() {
|
||||||
|
Loading…
Reference in New Issue
Block a user