SNRK-66:buildDocument function scratch is added, AstNodes are copied from prototype
This commit is contained in:
parent
a92f9673ac
commit
4465e68408
@ -1,6 +1,7 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id("space.kscience.gradle.jvm")
|
id("space.kscience.gradle.jvm")
|
||||||
`maven-publish`
|
`maven-publish`
|
||||||
|
id("kotlinx-serialization")
|
||||||
}
|
}
|
||||||
|
|
||||||
val coroutinesVersion = space.kscience.gradle.KScienceVersions.coroutinesVersion
|
val coroutinesVersion = space.kscience.gradle.KScienceVersions.coroutinesVersion
|
||||||
@ -12,4 +13,5 @@ dependencies {
|
|||||||
|
|
||||||
implementation(project(":snark-storage-driver"))
|
implementation(project(":snark-storage-driver"))
|
||||||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion")
|
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion")
|
||||||
|
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.3")
|
||||||
}
|
}
|
||||||
|
16
snark-document-builder/src/main/kotlin/DocumentBuilder.kt
Normal file
16
snark-document-builder/src/main/kotlin/DocumentBuilder.kt
Normal file
@ -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())
|
||||||
|
|
||||||
|
}
|
@ -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")
|
|
||||||
}
|
|
112
snark-document-builder/src/main/kotlin/MdParser.kt
Normal file
112
snark-document-builder/src/main/kotlin/MdParser.kt
Normal file
@ -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<MdAstElement>,
|
||||||
|
val includeList: List<String>
|
||||||
|
) : DependencyGraphEdge
|
||||||
|
|
||||||
|
data class DependencyGraphVertex(
|
||||||
|
val mdAst: MdAstRoot,
|
||||||
|
val dependencies: MutableList<DependencyGraphEdge>
|
||||||
|
)
|
||||||
|
|
||||||
|
// data class DependencyGraph(
|
||||||
|
// val root: DependencyGraphVertex
|
||||||
|
// )
|
||||||
|
|
||||||
|
enum class DependenceType {
|
||||||
|
INCLUDE
|
||||||
|
}
|
||||||
|
|
||||||
|
data class ParseResult(val dependencies: Dependencies, val vertex: DependencyGraphVertex)
|
||||||
|
|
||||||
|
typealias Dependencies = HashMap<DependenceType, MutableList<String>>
|
||||||
|
|
||||||
|
// 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<MdAstElement>
|
||||||
|
}
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
@SerialName("root")
|
||||||
|
data class MdAstRoot(
|
||||||
|
override var children: List<MdAstElement>,
|
||||||
|
override var position: Position
|
||||||
|
): MdAstParent
|
||||||
|
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
@SerialName("paragraph")
|
||||||
|
data class MdAstParagraph(
|
||||||
|
override var children: List<MdAstElement>,
|
||||||
|
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<MdAstElement>,
|
||||||
|
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<MdAstElement>,
|
||||||
|
override var position: Position
|
||||||
|
): MdAstParent
|
@ -1,4 +1,4 @@
|
|||||||
package hello
|
package documentBuilder
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
@ -6,6 +6,6 @@ import kotlinx.coroutines.runBlocking
|
|||||||
class SomeTest {
|
class SomeTest {
|
||||||
@Test
|
@Test
|
||||||
fun testEssential() = runBlocking {
|
fun testEssential() = runBlocking {
|
||||||
doSomethingEssential()
|
buildDocument("./example")
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user