meld
Version:
Meld: A template language for LLM prompts
113 lines (87 loc) • 2.91 kB
Markdown
# @import Directive
The `@import` directive allows you to import variables and commands from other Meld files.
## Syntax
Modern syntax:
```meld
# Import all variables
# Import all variables (equivalent)
# Import specific variables
# Import with aliases
```
Legacy syntax (also supported):
```meld
# Import all variables
# Import specific variables
```
Where:
- `path.meld` is the path to the Meld file to import
- `var1`, `var2` are variable names to import
- `alias1` is an alternative name to use for the imported variable
## Import Behavior
When you import a Meld file:
- All variables and commands defined in the imported file become available
- Text content from the imported file is NOT included
- Imports should be placed at the top of your file
- Imported files can import other files (nesting is supported)
- Circular imports are detected and will generate errors
## Supported Variable Types
The directive can import all types of variables:
- Text variables
- Data variables
- Path variables
- Command variables
## Path Specification
The path can be:
- An absolute path using `$HOMEPATH` or `$PROJECTPATH`
- A path variable: `@import [$utils]`
## Selective Imports and Aliases
Specify selective imports using a comma-separated list:
```meld
```
Import with aliases to avoid name conflicts:
```meld
```
Alternative alias syntax with colon:
```meld
```
## Examples
Basic import:
```meld
```
Import with path variables:
```meld
```
Selective import:
```meld
```
Import with aliases:
```meld
```
Using imported variables:
```meld
```
## Error Handling
The implementation handles various error scenarios:
- File not found errors
- Circular import errors
- Validation errors (syntax, path constraints)
- Variable not found errors
- Parsing errors in imported files
## Notes
- Imported files must be valid Meld files
- Missing import files will generate fatal errors
- Imports should generally be placed at the top of your file
- Imported files can have their own imports (nesting is supported)
- Variables with the same name will be overwritten (last imported wins)
- Circular imports are detected and will generate errors