Source-File-Based Import Analysis #
This module provides functions for analyzing imports by parsing source files directly,
as an alternative to Environment-based analysis (e.g. in ImportGraph.Imports). Specifically:
parseImports?,System.FilePath.parseImports': Parse direct imports from a single string or fileLean.ModuleHeader.filterInit: RemoveInitimports from a parsed headerparseCurrentHeader: parse the imports of the current file from theFileMapmodToRelFilePath: likemodToFilePath, but does not insert a leading file separatorfindTransitiveImportsFromSource: Compute a nameset of the transitive closure of imports from source files. Note, however, that this does not respect the module system.
Like parseImports', but pure. Instead of returning the fileName:pos <msg> error of
parseImports' of parseImports', returns (fileMap, pos, <msg>).
Instances For
Parse the header of the source file at path, returning its ModuleHeader.
This is a thin wrapper around Lean.parseImports' which:
- Reads the file from disk
- Parses the import statements
Note that it does not filter out Init modules. See ModuleHeader.filterInit.
Instances For
Parses the header of the current file via the source string present in the ambient FileMap.
Instances For
Parse all imports in a source file at path and return their module names.
This is a thin wrapper around Lean.parseImports' that:
- Reads the file from disk
- Parses the import statements
- Filters out
Init(part of the prelude)
Note: This only sees syntactic imports in the source file. It does not account for what declarations are actually used.
Instances For
Like modToFilePath, but does not demand base. Example: modToRelFilePath A.B.C "lean"
results in A/B/C.lean. (Note that modToFilePath "" mod ext inserts a leading file separator,
and would result in /A/B/C.lean.)
Instances For
Compute the transitive closure of imports starting from a source file.
Returns a NameSet of all modules that are transitively imported by the given file,
by recursively parsing source files.
Example:
-- Get all transitive Mathlib imports
let imports ← findTransitiveImportsFromSource "Mathlib/Algebra/Ring/Basic.lean" (some `Mathlib)
-- Get all transitive imports regardless of namespace
let allImports ← findTransitiveImportsFromSource "MyFile.lean"