Import and export are working

This commit is contained in:
2022-09-05 06:39:05 +01:00
parent dceb83e618
commit 7fb9ebbce0
10 changed files with 266 additions and 12 deletions

View File

@@ -1175,6 +1175,50 @@ static void returnStmt(Parser* parser, Node** nodeHandle) {
emitNodePath(nodeHandle, NODE_PATH_RETURN, NULL, NULL, NULL, returnValues, NULL);
}
static void importStmt(Parser* parser, Node** nodeHandle) {
//read the identifier
Node* node = NULL;
advance(parser);
identifier(parser, &node);
Literal idn = copyLiteral(node->atomic.literal);
freeNode(node);
Literal alias = TO_NULL_LITERAL;
if (match(parser, TOKEN_AS)) {
advance(parser);
identifier(parser, &node);
alias = copyLiteral(node->atomic.literal);
freeNode(node);
}
emitNodeImport(nodeHandle, NODE_IMPORT, idn, alias);
consume(parser, TOKEN_SEMICOLON, "Expected ';' at end of import statement");
}
static void exportStmt(Parser* parser, Node** nodeHandle) {
//read the identifier
Node* node = NULL;
advance(parser);
identifier(parser, &node);
Literal idn = copyLiteral(node->atomic.literal);
freeNode(node);
Literal alias = TO_NULL_LITERAL;
if (match(parser, TOKEN_AS)) {
advance(parser);
identifier(parser, &node);
alias = copyLiteral(node->atomic.literal);
freeNode(node);
}
emitNodeImport(nodeHandle, NODE_EXPORT, idn, alias);
consume(parser, TOKEN_SEMICOLON, "Expected ';' at end of export statement");
}
//precedence functions
static void expressionStmt(Parser* parser, Node** nodeHandle) {
//BUGFIX: check for empty statements
@@ -1248,6 +1292,18 @@ static void statement(Parser* parser, Node** nodeHandle) {
return;
}
//import
if (match(parser, TOKEN_IMPORT)) {
importStmt(parser, nodeHandle);
return;
}
//export
if (match(parser, TOKEN_EXPORT)) {
exportStmt(parser, nodeHandle);
return;
}
//default
expressionStmt(parser, nodeHandle);
}