# Включение и импорт файлов

## Включение и импорт файлов

Описание **include** импортирует все типы, функции и константы из указанных файлов и их дочерних файлов включенных с помощью **include**.

Описание **import** импортирует только публичные типы, функции и константы из указанных файлов и их дочерних файлов включенных с помощью **include**. Публичные объекты определяются с помощью ключевого слова **pub**.

```
stringConst         = "`" { unicode_char } "`" | stringDoubleConst
stringDoubleConst = `"` { unicode_char | uShort | uLong | escapedChar | byteVal } `"`
importDecl = "import" "{" {stringConst newline} "}"
includeDecl = "include" "{" {stringConst newline} "}"
```

Рассмотрим видимость объектов в виде таблицы. Пусть имеется два файла.

```
// a.g can include or import b.g
func afunc(i int) : return i*2
pub func apubfunc(i int) : return i*3

// b.g 
func bfunc(i int) : return i*4
pub func bpubfunc(i int) : return i*5
```

Пусть файл *c.g* может импортировать или включать файл *a.g*. Вы можете видеть какие функции будут видимы в файле *c.g* в зависимости от различных ситуаций.

|          | include a   a includes b | include a   a imports b | import a   a includes b | import a   a imports b |
| -------- | ------------------------ | ----------------------- | ----------------------- | ---------------------- |
| afunc    | visible                  | visible                 |                         |                        |
| apubfunc | visible                  | visible                 | visible                 | visible                |
| bfunc    | visible                  |                         |                         |                        |
| bpubfunc | visible                  |                         | visible                 |                        |

## Описание pub

Команда **pub** определяет следующую функцию, тип или константы как публичные. Вы можете импортировать их с помощью команды **import**.

```
pubDecl = "pub" [newline]
objects = [pubDecl] (structDecl | FnDecl | ConstDecl | FunctionDecl)
```

Ключевое слово **pub** указывает, что следующая функция, константы или тип будут передаваться в случае импорта файла.

```
pub const IOTA {  // public constants. Visible when include or import
    MY1
    MY2
}

const IOTA*2 {  // private constants. Visible only when include
    MY3
    MY4
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ru.gentee.org/syntax/include-and-import.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
