fillDependencies is implemented

This commit is contained in:
liubar.pa 2023-05-05 23:39:51 +03:00
parent cd85fcf329
commit 225b7346a8
2 changed files with 28 additions and 18 deletions

View File

@ -27,7 +27,7 @@ private suspend fun buildNodes(folder: Directory, nodes: HashMap<FileName, Depen
assert(!nodes.containsKey(pathString)) assert(!nodes.containsKey(pathString))
val rootDcoument = folder.get(DEFAULT_DOCUMENT_ROOT) val rootDcoument = folder.get(DEFAULT_DOCUMENT_ROOT)
nodes.put(pathString, buildDependencyGraphNode(rootDcoument.readAll())) nodes.put(pathString, buildDependencyGraphNode(rootDcoument.readAll(), folder.path))
val dependencies = getDependencies(nodes.getValue(pathString)) val dependencies = getDependencies(nodes.getValue(pathString))

View File

@ -2,6 +2,7 @@ package documentBuilder
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue import com.fasterxml.jackson.module.kotlin.readValue
import java.nio.file.Path
private val MARKDOWN_PARSER = "../nodejs/MarkdownParser.js" private val MARKDOWN_PARSER = "../nodejs/MarkdownParser.js"
@ -13,30 +14,39 @@ public suspend fun parseMd(mdFile: ByteArray): MdAstRoot {
.start().inputStream.bufferedReader().readText()) .start().inputStream.bufferedReader().readText())
} }
public suspend fun buildDependencyGraphNode(mdFile: ByteArray): DependencyGraphNode { public suspend fun buildDependencyGraphNode(mdFile: ByteArray, path: Path): DependencyGraphNode {
val treeRoot = parseMd(mdFile) val treeRoot = parseMd(mdFile)
val dependencies = mutableListOf<DependencyGraphEdge>() val dependencies = mutableListOf<DependencyGraphEdge>()
fillDependencies(treeRoot, dependencies) fillDependencies(treeRoot, dependencies, path)
return DependencyGraphNode(treeRoot, dependencies) return DependencyGraphNode(treeRoot, dependencies)
} }
private suspend fun fillDependencies( internal suspend fun fillDependencies(
currentNode: MdAstElement, currentNode: MdAstElement,
dependencies: MutableList<DependencyGraphEdge>) { dependencies: MutableList<DependencyGraphEdge>,
// when (currentNode) { path: Path) {
// is MdAstParent -> { when (currentNode) {
// val iterator = currentNode.children.listIterator() is MdAstParent -> {
for (child in currentNode.children) {
if (child is MdAstText) {
val includeList = getIncludeFiles(child.value).toMutableList()
// while (iterator.hasNext()) { if (includeList.size > 0) {
includeList.replaceAll { path.toString() + "/" + it }
dependencies += IncludeDependency(currentNode, child, includeList)
}
} else {
fillDependencies(child, dependencies, path)
}
}
}
else -> {}
}
}
// iterator.next() public suspend fun getIncludeFiles(string: String): List<FileName> {
// }
// }
// else -> {}
// }
TODO() TODO()
} }