Add public imports

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-04-25 15:28:33 +02:00
parent 63dd5fa5c9
commit a6bdadac0c
3 changed files with 37 additions and 1 deletions
+1
View File
@@ -12,3 +12,4 @@ void main() {
puts("Hello, world!"); puts("Hello, world!");
} }
``` ```
.
+31
View File
@@ -0,0 +1,31 @@
# Imports
The import statement allows one module access to the public declarations of another module.
## Syntax
The import statement uses the following syntax:
```c2
import module_name;
```
They can optionally be prefixed by the `public` keyword, in which case the module will
export everything in the import transitively.
For instance,
```c2
--- a.c2
module a;
import b;
--- b.c2
module b;
public import c;
--- c.c2
module c;
// Some declarations
```
In this example, both module a and b can access the declarations in module c.
+4
View File
@@ -4,11 +4,15 @@
#ifndef AST_H #ifndef AST_H
#define AST_H #define AST_H
#include <stdbool.h>
#include <stddef.h> #include <stddef.h>
typedef struct { typedef struct {
/// @brief The name of the module being imported. /// @brief The name of the module being imported.
char* module_name; char* module_name;
/// @brief Whether the import is public or not.
bool is_public;
} ImportDeclaration; } ImportDeclaration;
/** /**