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*/
|
TODO() /*resolving of dependencies*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public suspend fun buildDependencyGraph(root: Directory): DependencyGraph {
|
public suspend fun buildDependencyGraph(root: Directory): DependencyGraph {
|
||||||
val nodes = HashMap<FileName, DependencyGraphNode>()
|
val nodes = HashMap<FileName, DependencyGraphNode>()
|
||||||
|
|
||||||
buildNodes(root, nodes)
|
buildNodes(root, nodes)
|
||||||
@ -23,11 +23,11 @@ public suspend fun buildDependencyGraph(root: Directory): DependencyGraph {
|
|||||||
|
|
||||||
private suspend fun buildNodes(folder: Directory, nodes: HashMap<FileName, DependencyGraphNode>) {
|
private suspend fun buildNodes(folder: Directory, nodes: HashMap<FileName, DependencyGraphNode>) {
|
||||||
val pathString = folder.path.toString()
|
val pathString = folder.path.toString()
|
||||||
|
|
||||||
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))
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ private suspend fun buildNodes(folder: Directory, nodes: HashMap<FileName, Depen
|
|||||||
|
|
||||||
public suspend fun getDependencies(node: DependencyGraphNode): Set<FileName> {
|
public suspend fun getDependencies(node: DependencyGraphNode): Set<FileName> {
|
||||||
val dependencies = mutableListOf<FileName>()
|
val dependencies = mutableListOf<FileName>()
|
||||||
|
|
||||||
for (dependency in node.dependencies) {
|
for (dependency in node.dependencies) {
|
||||||
when (dependency) {
|
when (dependency) {
|
||||||
is IncludeDependency -> dependencies.addAll(dependency.includeList)
|
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.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()
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user