Skip to content

Commit

Permalink
flamingo: Start work on import statement
Browse files Browse the repository at this point in the history
  • Loading branch information
obiwac committed Aug 12, 2024
1 parent 65051a1 commit 55f5d66
Show file tree
Hide file tree
Showing 3 changed files with 5,017 additions and 1,017 deletions.
5 changes: 5 additions & 0 deletions flamingo/flamingo.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "common.h"
#include "scope.c"
#include "val.c"
#include "import.c"

typedef struct {
TSParser* parser;
Expand Down Expand Up @@ -488,6 +489,10 @@ static int parse_statement(flamingo_t* flamingo, TSNode node) {
return parse_expr(flamingo, child, NULL);
}

else if (strcmp(type, "import") == 0) {
return parse_import(flamingo, child);
}

return error(flamingo, "unknown statment type: %s", type);
}

Expand Down
28 changes: 28 additions & 0 deletions flamingo/import.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// This Source Form is subject to the terms of the AQUA Software License,
// v. 1.0. Copyright (c) 2024 Aymeric Wibo

#include "common.h"
#include "flamingo.h"
#include "runtime/tree_sitter/api.h"

#include <assert.h>
#include <string.h>

static int parse_import(flamingo_t* flamingo, TSNode node) {
assert(strcmp(ts_node_type(node), "import") == 0);
assert(ts_node_child_count(node) == 2);

TSNode const relative_node = ts_node_child_by_field_name(node, "relative", 8);
bool const is_relative = !ts_node_is_null(relative_node);

TSNode const path_node = ts_node_child_by_field_name(node, "path", 4);
char const* const path_type = ts_node_type(path_node);

if (strcmp(path_type, "import_path") != 0) {
return error(flamingo, "expected import_path for path, got %s", path_type);
}

// Parse the import path into an actual string path we can use.

return error(flamingo, "TODO");
}
Loading

0 comments on commit 55f5d66

Please sign in to comment.