@@ -12,3 +12,4 @@ void main() {
|
||||
puts("Hello, world!");
|
||||
}
|
||||
```
|
||||
.
|
||||
@@ -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,11 +4,15 @@
|
||||
#ifndef AST_H
|
||||
#define AST_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct {
|
||||
/// @brief The name of the module being imported.
|
||||
char* module_name;
|
||||
|
||||
/// @brief Whether the import is public or not.
|
||||
bool is_public;
|
||||
} ImportDeclaration;
|
||||
|
||||
/**
|
||||
@@ -21,7 +25,7 @@ typedef struct {
|
||||
|
||||
/// @brief The list of imports in the module.
|
||||
ImportDeclaration* imports;
|
||||
|
||||
|
||||
/// @brief The number of imports in the module.
|
||||
size_t import_count;
|
||||
} Module;
|
||||
|
||||
Reference in New Issue
Block a user