resolveImport

abstract suspend fun resolveImport(path: String, fileGraph: List<SourceFileRef>): TextSourceFile(source)

Resolves a local import from given path and returns a text source file. This function may throw in error cases, in which case a compilation error report will be generated. This will not necessarily abort compilation immediately, but it is guaranteed that the final compilation result is failure.

The k3lp compiler will automatically detect recursive imports and abort compilation based on the returned SourceFileRef handles.

Return

A loaded TextSourceFile with a reference handle that uniquely identifies this file. Must be stable and comparable with other returned references, to allow the k3lp compiler to perform safety checks.

Parameters

path

The requested scoped path to resolve and load. This value is user-controlled and may contain ANY combination of characters, including empty strings. Be aware of possible path expansion attacks and treat this path with care.

fileGraph

The file graph where this import occurs. May be used to guide relative imports. It is guaranteed that the file graph is not empty and that the following holds:

  • fileGraph.first() refers to the root keyboard3 file that is being compiled.

  • fileGraph.last() refers to the current file currently being compiled, which may be the root file, or another imported file.

Throws

in error cases. It is implementation-defined which specific exception is thrown.