diff --git a/snark-document-builder/build.gradle.kts b/snark-document-builder/build.gradle.kts index 4895628..d7d9d05 100644 --- a/snark-document-builder/build.gradle.kts +++ b/snark-document-builder/build.gradle.kts @@ -1,6 +1,7 @@ plugins { id("space.kscience.gradle.jvm") `maven-publish` + id("kotlinx-serialization") } val coroutinesVersion = space.kscience.gradle.KScienceVersions.coroutinesVersion @@ -12,4 +13,5 @@ dependencies { implementation(project(":snark-storage-driver")) implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion") + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.3") } diff --git a/snark-document-builder/src/main/kotlin/DocumentBuilder.kt b/snark-document-builder/src/main/kotlin/DocumentBuilder.kt new file mode 100644 index 0000000..891848c --- /dev/null +++ b/snark-document-builder/src/main/kotlin/DocumentBuilder.kt @@ -0,0 +1,16 @@ +package documentBuilder + +import com.fasterxml.jackson.core.io.BigDecimalParser +import space.kscience.snark.storage.* +import space.kscience.snark.storage.local.LocalDirectory +import java.nio.file.Path + +val DEFAULT_DOCUMENT_ROOT = "main.md" + +public suspend fun buildDocument(documentPath: String) { + val documentDirectory: Directory = LocalDirectory(documentPath) + val documentRoot = documentDirectory.get(DEFAULT_DOCUMENT_ROOT) + + // val (dependencies, vertex) = parseMd(documentRoot.readAll()) + +} \ No newline at end of file diff --git a/snark-document-builder/src/main/kotlin/Hello.kt b/snark-document-builder/src/main/kotlin/Hello.kt deleted file mode 100644 index 027138f..0000000 --- a/snark-document-builder/src/main/kotlin/Hello.kt +++ /dev/null @@ -1,12 +0,0 @@ -package hello - -import com.fasterxml.jackson.core.io.BigDecimalParser -import space.kscience.snark.storage.* -import space.kscience.snark.storage.local.LocalDirectory -import java.nio.file.Path - - -public suspend fun doSomethingEssential() { - val dir: Directory = LocalDirectory(".") - dir.get("notexists") -} \ No newline at end of file diff --git a/snark-document-builder/src/main/kotlin/MdParser.kt b/snark-document-builder/src/main/kotlin/MdParser.kt new file mode 100644 index 0000000..0d40c67 --- /dev/null +++ b/snark-document-builder/src/main/kotlin/MdParser.kt @@ -0,0 +1,112 @@ +package documentBuilder + +import kotlinx.serialization.Serializable +import kotlinx.serialization.SerialName +import com.fasterxml.jackson.annotation.JsonSubTypes +import com.fasterxml.jackson.annotation.JsonTypeInfo + +sealed interface DependencyGraphEdge { +} + +data class IncludeDependency( + val parentNode: MdAstParent, + val dependentNode: Iterator, + val includeList: List +) : DependencyGraphEdge + +data class DependencyGraphVertex( + val mdAst: MdAstRoot, + val dependencies: MutableList +) + +// data class DependencyGraph( +// val root: DependencyGraphVertex +// ) + +enum class DependenceType { + INCLUDE +} + +data class ParseResult(val dependencies: Dependencies, val vertex: DependencyGraphVertex) + +typealias Dependencies = HashMap> + +// public suspend fun parseMd(mdFile: ByteArray): ParseResult { +// } + +@Serializable +data class Point(val line: Int, val column: Int, val offset: Int) + +@Serializable +data class Position(val start: Point, val end: Point) + +@JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.PROPERTY, + property = "type" +) +@JsonSubTypes( + JsonSubTypes.Type(value = MdAstRoot::class, name = "root"), + JsonSubTypes.Type(value = MdAstParagraph::class, name = "paragraph"), + JsonSubTypes.Type(value = MdAstText::class, name = "text"), + JsonSubTypes.Type(value = MdAstHeading::class, name = "heading"), + JsonSubTypes.Type(value = MdAstCode::class, name = "code"), + JsonSubTypes.Type(value = MdAstBlockquote::class, name = "blockquote") +) +@Serializable +sealed interface MdAstElement{ + abstract var position: Position +} + +@Serializable +sealed interface MdAstParent: MdAstElement{ + var children: List +} + +@Serializable +@SerialName("root") +data class MdAstRoot( + override var children: List, + override var position: Position +): MdAstParent + + +@Serializable +@SerialName("paragraph") +data class MdAstParagraph( + override var children: List, + override var position: Position +): MdAstParent + + +@Serializable +@SerialName("text") +data class MdAstText( + val value: String, + override var position: Position +): MdAstElement + + +@Serializable +@SerialName("heading") +data class MdAstHeading( + val depth: Int, + override var children: List, + override var position: Position +): MdAstParent + +@Serializable +@SerialName("code") +data class MdAstCode( + var lang: String? = null, + var meta: String? = null, + var value: String, + override var position: Position, +) : MdAstElement + +@Serializable +@SerialName("blockquote") +data class MdAstBlockquote( + override var children: List, + override var position: Position +): MdAstParent \ No newline at end of file diff --git a/snark-document-builder/src/test/kotlin/Hello.kt b/snark-document-builder/src/test/kotlin/DocumentBuilder.kt similarity index 71% rename from snark-document-builder/src/test/kotlin/Hello.kt rename to snark-document-builder/src/test/kotlin/DocumentBuilder.kt index 4ba4d64..1c4436f 100644 --- a/snark-document-builder/src/test/kotlin/Hello.kt +++ b/snark-document-builder/src/test/kotlin/DocumentBuilder.kt @@ -1,4 +1,4 @@ -package hello +package documentBuilder import org.junit.jupiter.api.Test import kotlinx.coroutines.runBlocking @@ -6,6 +6,6 @@ import kotlinx.coroutines.runBlocking class SomeTest { @Test fun testEssential() = runBlocking { - doSomethingEssential() + buildDocument("./example") } }