-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updates explanation of modules #369
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Directives | ||
|
||
_Directives_ are system values that modify the encoding context. | ||
|
||
Syntactically, a directive is a top-level s-expression annotated with `$ion`. | ||
Its first child value is an operation name. | ||
The operation determines what changes will be made to the encoding context and which clauses may legally follow. | ||
|
||
```ion | ||
$ion:: | ||
(operation_name | ||
(clause_1 /*...*/) | ||
(clause_2 /*...*/) | ||
/*...more clauses...*/ | ||
(clause_N /*...*/)) | ||
``` | ||
|
||
In Ion 1.1, there are three supported directive operations: | ||
1. [`module`](#module-directives) | ||
2. [`import`](#import-directives) | ||
3. [`encoding`](#encoding-directives) | ||
|
||
## Top-level bindings | ||
|
||
The `module` and `import` directives each create a stream-level binding to a module definition. | ||
Once created, module bindings at this level endure until the file ends or another Ion version marker is encountered. | ||
|
||
Module bindings at the stream-level can be redefined. | ||
|
||
> [!TIP] | ||
> The [`add_macros`](../macros/system_macros.md#add_macros) and [`add_symbols`](../macros/system_macros.md#add_symbols) | ||
> system macros work by redefining the default module (`_`) in terms of itself. | ||
|
||
This behavior differs from module bindings created inside another module; | ||
[attempting to redefine these will raise an error](defining_modules.md#internal-environment). | ||
|
||
### `module` directives | ||
The `module` directive binds a name to a [local module](local_modules.md) definition at the top level of the stream. | ||
|
||
```ion | ||
$ion:: | ||
(module foo | ||
/*...imports, if any...*/ | ||
/*...submodules, if any...*/ | ||
(macro_table /*...*/) | ||
(symbol_table /*...*/) | ||
) | ||
``` | ||
|
||
### `import` directives | ||
|
||
The _import_ directive looks up the module corresponding to the given `(name, version)` pair in the catalog. | ||
Upon success, it creates a new binding to that module at the top level of the stream. | ||
|
||
```ion | ||
$ion:: | ||
(import | ||
bar // Binding | ||
zslayton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"com.example.bar" // Module name | ||
2) // Module version | ||
zslayton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
The `version` can be omitted. When it is not specified, it defaults to `1`. | ||
|
||
If the catalog does contain an exact match, this operation raises an error. | ||
|
||
## `encoding` directives | ||
|
||
An `encoding` directive accepts a sequence of module bindings to use as the following stream segment's | ||
[encoding module sequence](encoding_modules.md). | ||
|
||
```ion | ||
$ion:: | ||
(encoding | ||
mod_a | ||
mod_b | ||
mod_c) | ||
``` | ||
|
||
The new encoding module sequence takes effect immediately after the directive and remains the same until the next `encoding` directive or Ion version marker. | ||
|
||
Note that the [default module](encoding_modules.md#the-default-module) is always implicitly at the head of the encoding module sequence. |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The modules bindings does not contain
$ion
or_
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct. The bindings for
$ion
and_
are at the stream level. Referencing them inside a module will result in recursive lookups through the parent scopes until it reaches the stream. (Optimizations are possible, of course, but this is the behavior that must be achieved.)