Import Statements
The CKSP compiler supports modular programming by allowing code from other *.cksp files to be included using the import statement.
These statements are placed in the global scope of a *.cksp file and specify the path to the file to be imported.
Syntax
Import Path Resolution
Import paths always use forward slashes (/), regardless of the operating system. To move up a directory, use ../. To specify a path relative to the project root, use ./.
Import paths can be specified in two ways:
-
Relative to the current file The path is resolved based on the location of the file containing the
importstatement. This is especially useful when using independent modules or libraries that might be shared across different projects. -
Relative to the project root The project root is always the file initially passed to the compiler. By prefixing the path with
./, you can reference paths relative to this root, regardless of the location of the importing file. However, (to maintain compatibility with SublimeKSP) you can also use paths relative to the project root without the./prefix. In this case, you would simply specify the path as if it were imported from the root.
Example project structure:
In main.cksp (imports from a subdirectory):
In component.cksp (importing utility functions)
Key Features of Import Paths
-
Flexible Resolution Paths can be based on the current file location or fixed to the project root.
-
Navigation with
../Use../to move up one directory; can be chained for multiple levels. -
Root-based Imports with
./Start a path with./to resolve from the project root, which is always the file first passed to the compiler.