SNRK-70: MdAstElements and DependencyGraph moved to seperate files, return type of parseMd is changed to DepencyGraphVertex
This commit is contained in:
parent
57df19f1bf
commit
ea4fef95b8
19
snark-document-builder/src/main/kotlin/DependencyGraph.kt
Normal file
19
snark-document-builder/src/main/kotlin/DependencyGraph.kt
Normal file
@ -0,0 +1,19 @@
|
||||
package documentBuilder
|
||||
|
||||
sealed interface DependencyGraphEdge {
|
||||
}
|
||||
|
||||
data class IncludeDependency(
|
||||
val parentNode: MdAstParent,
|
||||
val dependentNode: Iterator<MdAstElement>,
|
||||
val includeList: List<String>
|
||||
) : DependencyGraphEdge
|
||||
|
||||
data class DependencyGraphNode(
|
||||
val mdAst: MdAstRoot,
|
||||
val dependencies: List<DependencyGraphEdge>
|
||||
)
|
||||
|
||||
data class DependencyGraph(
|
||||
val nodes: Map<String, DependencyGraphNode>
|
||||
)
|
84
snark-document-builder/src/main/kotlin/MdAstElements.kt
Normal file
84
snark-document-builder/src/main/kotlin/MdAstElements.kt
Normal file
@ -0,0 +1,84 @@
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.SerialName
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo
|
||||
|
||||
package documentBuilder
|
||||
|
||||
@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,109 +1,5 @@
|
||||
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>
|
||||
)
|
||||
|
||||
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 {
|
||||
public suspend fun parseMd(mdFile: ByteArray): DependencyGraphVertex {
|
||||
TODO()
|
||||
}
|
||||
|
||||
@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
|
Loading…
Reference in New Issue
Block a user