mirror of
https://github.com/irmen/prog8.git
synced 2024-11-26 11:49:22 +00:00
- ModuleImporter: deduplicate code
This commit is contained in:
parent
b8fade23de
commit
f2cb89a128
@ -38,21 +38,7 @@ class ModuleImporter(private val program: Program,
|
|||||||
var logMsg = "importing '${filePath.nameWithoutExtension}' (from $srcPath)"
|
var logMsg = "importing '${filePath.nameWithoutExtension}' (from $srcPath)"
|
||||||
println(logMsg)
|
println(logMsg)
|
||||||
|
|
||||||
val module = Prog8Parser.parseModule(SourceCode.fromPath(srcPath))
|
return importModule(SourceCode.fromPath(srcPath))
|
||||||
|
|
||||||
module.program = program
|
|
||||||
module.linkParents(program.namespace)
|
|
||||||
program.modules.add(module)
|
|
||||||
|
|
||||||
// accept additional imports
|
|
||||||
val lines = module.statements.toMutableList()
|
|
||||||
lines.asSequence()
|
|
||||||
.mapIndexed { i, it -> i to it }
|
|
||||||
.filter { (it.second as? Directive)?.directive == "%import" }
|
|
||||||
.forEach { executeImportDirective(it.second as Directive, module) }
|
|
||||||
|
|
||||||
module.statements = lines
|
|
||||||
return module
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun importLibraryModule(name: String): Module? {
|
fun importLibraryModule(name: String): Module? {
|
||||||
@ -88,7 +74,7 @@ class ModuleImporter(private val program: Program,
|
|||||||
throw SyntaxError("cannot import self", import.position)
|
throw SyntaxError("cannot import self", import.position)
|
||||||
|
|
||||||
val existing = program.modules.singleOrNull { it.name == moduleName }
|
val existing = program.modules.singleOrNull { it.name == moduleName }
|
||||||
if(existing!=null)
|
if (existing!=null)
|
||||||
return null // TODO: why return null instead of Module instance?
|
return null // TODO: why return null instead of Module instance?
|
||||||
|
|
||||||
var srcCode = tryGetModuleFromResource("$moduleName.p8", compilationTargetName)
|
var srcCode = tryGetModuleFromResource("$moduleName.p8", compilationTargetName)
|
||||||
|
Loading…
Reference in New Issue
Block a user