From f2cb89a128054c3a0c2816e2d3860b11619ff240 Mon Sep 17 00:00:00 2001 From: meisl Date: Sun, 1 Aug 2021 15:37:57 +0200 Subject: [PATCH] - ModuleImporter: deduplicate code --- compilerAst/src/prog8/parser/ModuleParsing.kt | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/compilerAst/src/prog8/parser/ModuleParsing.kt b/compilerAst/src/prog8/parser/ModuleParsing.kt index c66d95e10..32a2e9646 100644 --- a/compilerAst/src/prog8/parser/ModuleParsing.kt +++ b/compilerAst/src/prog8/parser/ModuleParsing.kt @@ -38,21 +38,7 @@ class ModuleImporter(private val program: Program, var logMsg = "importing '${filePath.nameWithoutExtension}' (from $srcPath)" println(logMsg) - val module = Prog8Parser.parseModule(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 + return importModule(SourceCode.fromPath(srcPath)) } fun importLibraryModule(name: String): Module? { @@ -88,7 +74,7 @@ class ModuleImporter(private val program: Program, throw SyntaxError("cannot import self", import.position) val existing = program.modules.singleOrNull { it.name == moduleName } - if(existing!=null) + if (existing!=null) return null // TODO: why return null instead of Module instance? var srcCode = tryGetModuleFromResource("$moduleName.p8", compilationTargetName)