diff --git a/snark-document-builder/src/main/kotlin/Build.kt b/snark-document-builder/src/main/kotlin/Build.kt new file mode 100644 index 0000000..c15b225 --- /dev/null +++ b/snark-document-builder/src/main/kotlin/Build.kt @@ -0,0 +1,17 @@ +package documentBuilder + +internal class GraphManager(private val graph: DependencyGraph) { + fun buildDocument(file: FileName) { + val list = graph.nodes[file] + if (list != null) { + for (element in list.dependencies) { + element.visit(this) + } + } + } + + fun getAstRootDocument(file: FileName): MdAstRoot { + buildDocument(file) + return graph.nodes[file]!!.mdAst + } +} diff --git a/snark-document-builder/src/main/kotlin/DependencyGraph.kt b/snark-document-builder/src/main/kotlin/DependencyGraph.kt index dc0a8bc..864838a 100644 --- a/snark-document-builder/src/main/kotlin/DependencyGraph.kt +++ b/snark-document-builder/src/main/kotlin/DependencyGraph.kt @@ -1,5 +1,7 @@ package documentBuilder +import kotlinx.coroutines.coroutineScope + public typealias FileName = String /** @@ -19,6 +21,7 @@ public data class DependencyGraphNode( * Interface of all dependency edges. */ public sealed interface DependencyGraphEdge { + public fun visit(graphManager: GraphManager) } /** @@ -32,7 +35,16 @@ public data class IncludeDependency( val parentNode: MdAstParent, val dependentNode: MdAstElement, val includeList: List -) : DependencyGraphEdge +) : DependencyGraphEdge { + override fun visit(graphManager: GraphManager) { + val parent = parentNode + for (file in includeList) { + graphManager.buildDocument(file) + parent.children.add(graphManager.graph.nodes[file].mdAst) + } + dependentNode = parent + } +} /** * Whole dependency graph.