SNARK-71: buildDependencyGraph is implemented

This commit is contained in:
liubar.pa 2023-05-04 07:55:48 +03:00
parent 088697da78
commit c76ecd592f

View File

@ -7,25 +7,44 @@ import java.nio.file.Path
private val DEFAULT_DOCUMENT_ROOT = "main.md" private val DEFAULT_DOCUMENT_ROOT = "main.md"
public suspend fun buildDocument(documentDirectory: Directory) { public suspend fun buildDocument(documentDirectory: Directory) {
val dependencyGraph = buildDependencyGraph(documentDirectory) val dependencyGraph = buildDependencyGraph(documentDirectory)
TODO() /*resolving of dependencies*/ TODO() /*resolving of dependencies*/
} }
public suspend fun buildDependencyGraph(root: Directory) : DependencyGraph { public suspend fun buildDependencyGraph(root: Directory): DependencyGraph {
// val rootDcoument = root.get(DEFAULT_DOCUMENT_ROOT) val nodes = HashMap<FileName, DependencyGraphNode>()
// val filesToParse: Queue<FileReader> = LinkedList<FileReader>(listOf(root)) // buildNodes(root, nodes)
// var documentName = "."
// val nodes = HashMap<FileName, DependencyGraphNode>() val rootDcoument = root.get(DEFAULT_DOCUMENT_ROOT)
// while (!filesToParse.isEmpty()) nodes.put(".", buildDependencyGraphNode(rootDcoument.readAll()))
// {
// dependencyGraphNode = buildDependencyNode(filesToParse.remove())
// nodes.put() val filesToParse = getDependencies(nodes.getValue("."))
// }
while (!filesToParse.isEmpty())
{
val currentFile = filesToParse.remove()
val currentDocument = Directory(currentFile).get(DEFAULT_DOCUMENT_ROOT)
nodes.put(currentFile, buildDependencyGraphNode(currentDocument.readAll()))
val currentDependencies = getDependencies(nodes.getValue(currentFile))
for (fileName in currentDependencies) {
if (!nodes.containsKey(fileName) && !filesToParse.contains(fileName))
filesToParse.add(fileName)
}
}
return DependencyGraph(nodes)
}
// private suspend fun buildNodes(folder: Directory, nodes: HashMap<FileName, DependencyGraphNode>) {
// assert(!nodes.containsKey(folder.getPath()))
// }
public suspend fun getDependencies(node: DependencyGraphNode): Set<FileName> {
TODO() TODO()
} }