fillDependencies is implemented
This commit is contained in:
parent
cd85fcf329
commit
225b7346a8
@ -13,7 +13,7 @@ public suspend fun buildDocument(documentDirectory: Directory) {
|
||||
TODO() /*resolving of dependencies*/
|
||||
}
|
||||
|
||||
public suspend fun buildDependencyGraph(root: Directory): DependencyGraph {
|
||||
public suspend fun buildDependencyGraph(root: Directory): DependencyGraph {
|
||||
val nodes = HashMap<FileName, DependencyGraphNode>()
|
||||
|
||||
buildNodes(root, nodes)
|
||||
@ -23,11 +23,11 @@ public suspend fun buildDependencyGraph(root: Directory): DependencyGraph {
|
||||
|
||||
private suspend fun buildNodes(folder: Directory, nodes: HashMap<FileName, DependencyGraphNode>) {
|
||||
val pathString = folder.path.toString()
|
||||
|
||||
|
||||
assert(!nodes.containsKey(pathString))
|
||||
|
||||
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))
|
||||
|
||||
@ -39,7 +39,7 @@ private suspend fun buildNodes(folder: Directory, nodes: HashMap<FileName, Depen
|
||||
|
||||
public suspend fun getDependencies(node: DependencyGraphNode): Set<FileName> {
|
||||
val dependencies = mutableListOf<FileName>()
|
||||
|
||||
|
||||
for (dependency in node.dependencies) {
|
||||
when (dependency) {
|
||||
is IncludeDependency -> dependencies.addAll(dependency.includeList)
|
||||
|
@ -2,6 +2,7 @@ package documentBuilder
|
||||
|
||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||
import com.fasterxml.jackson.module.kotlin.readValue
|
||||
import java.nio.file.Path
|
||||
|
||||
private val MARKDOWN_PARSER = "../nodejs/MarkdownParser.js"
|
||||
|
||||
@ -13,30 +14,39 @@ public suspend fun parseMd(mdFile: ByteArray): MdAstRoot {
|
||||
.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 dependencies = mutableListOf<DependencyGraphEdge>()
|
||||
|
||||
fillDependencies(treeRoot, dependencies)
|
||||
fillDependencies(treeRoot, dependencies, path)
|
||||
|
||||
return DependencyGraphNode(treeRoot, dependencies)
|
||||
}
|
||||
|
||||
private suspend fun fillDependencies(
|
||||
internal suspend fun fillDependencies(
|
||||
currentNode: MdAstElement,
|
||||
dependencies: MutableList<DependencyGraphEdge>) {
|
||||
// when (currentNode) {
|
||||
// is MdAstParent -> {
|
||||
// val iterator = currentNode.children.listIterator()
|
||||
dependencies: MutableList<DependencyGraphEdge>,
|
||||
path: Path) {
|
||||
when (currentNode) {
|
||||
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()
|
||||
// }
|
||||
|
||||
// }
|
||||
// else -> {}
|
||||
// }
|
||||
public suspend fun getIncludeFiles(string: String): List<FileName> {
|
||||
TODO()
|
||||
}
|
Loading…
Reference in New Issue
Block a user