jsexportを追加

This commit is contained in:
usbharu 2024-11-15 14:56:40 +09:00
parent 8beae5e426
commit ecff061924
Signed by: usbharu
GPG Key ID: 95CBCF7046307B77
7 changed files with 114 additions and 98 deletions

View File

@ -27,12 +27,11 @@ kotlin {
linuxX64() linuxX64()
mingwX64() mingwX64()
@OptIn(ExperimentalWasmDsl::class) @OptIn(ExperimentalWasmDsl::class)
wasmWasi {
nodejs()
}
js { js {
browser() browser()
nodejs() nodejs()
binaries.library()
generateTypeScriptDefinitions()
} }
sourceSets { sourceSets {

View File

@ -1,12 +1,12 @@
package dev.usbharu.markdown package dev.usbharu.markdown
import kotlin.collections.List import kotlin.js.JsExport
@JsExport
sealed class AstNode { sealed class AstNode {
open fun print(): String { open fun print(): String {
return toString() return toString()
} }
}
data class RootNode(val node: AstNode) : AstNode() { data class RootNode(val node: AstNode) : AstNode() {
override fun print(): String { override fun print(): String {
@ -41,6 +41,7 @@ data object SeparatorNode : BlockNode() {
return "---" return "---"
} }
} }
sealed class ListNode : BlockNode() sealed class ListNode : BlockNode()
data class DiscListNode(val node: InlineNode, val childList: List<ListNode>) : ListNode() data class DiscListNode(val node: InlineNode, val childList: List<ListNode>) : ListNode()
data class DecimalListNode(val node: InlineNode, val childList: List<ListNode>) : ListNode() data class DecimalListNode(val node: InlineNode, val childList: List<ListNode>) : ListNode()
@ -69,3 +70,5 @@ data class PlainText(val text: String) : InlineNode() {
return text return text
} }
} }
}

View File

@ -1,7 +1,10 @@
package dev.usbharu.markdown package dev.usbharu.markdown
import dev.usbharu.markdown.Token.*
import kotlin.collections.List import kotlin.collections.List
import kotlin.js.JsExport
@JsExport
class Lexer { class Lexer {
fun lex(input: String): List<Token> { fun lex(input: String): List<Token> {
val tokens = mutableListOf<Token>() val tokens = mutableListOf<Token>()

View File

@ -1,7 +1,11 @@
package dev.usbharu.markdown package dev.usbharu.markdown
import dev.usbharu.markdown.AstNode.*
import dev.usbharu.markdown.Token.*
import kotlin.collections.List import kotlin.collections.List
import kotlin.js.JsExport
@JsExport
class Parser { class Parser {
fun parse(tokens: List<Token>): AstNode { fun parse(tokens: List<Token>): AstNode {
val iterator = PeekableTokenIterator(tokens) val iterator = PeekableTokenIterator(tokens)
@ -18,7 +22,7 @@ class Parser {
Exclamation -> TODO() Exclamation -> TODO()
is Header -> header(next, iterator) is Header -> header(next, iterator)
is Html -> TODO() is Html -> TODO()
is dev.usbharu.markdown.List -> TODO() is Token.List -> TODO()
ParenthesesEnd -> TODO() ParenthesesEnd -> TODO()
ParenthesesStart -> TODO() ParenthesesStart -> TODO()
is Quote -> TODO() is Quote -> TODO()

View File

@ -1,7 +1,9 @@
package dev.usbharu.markdown package dev.usbharu.markdown
sealed class Token() import kotlin.js.JsExport
@JsExport
sealed class Token {
data class Text(var text: String) : Token() data class Text(var text: String) : Token()
data class Break(var count: Int) : Token() data class Break(var count: Int) : Token()
data class Header(var count: Int) : Token() data class Header(var count: Int) : Token()
@ -38,3 +40,5 @@ data class TagEnd(var tag: String) : Html()
data class AttributeName(val name: String) : Html() data class AttributeName(val name: String) : Html()
data class AttributeValue(val value: String) : Html() data class AttributeValue(val value: String) : Html()
data class HtmlValue(val value: String) : Html() data class HtmlValue(val value: String) : Html()
}

View File

@ -1,5 +1,6 @@
package dev.usbharu.markdown package dev.usbharu.markdown
import dev.usbharu.markdown.Token.*
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertContentEquals import kotlin.test.assertContentEquals
import kotlin.test.assertEquals import kotlin.test.assertEquals

View File

@ -1,5 +1,7 @@
package dev.usbharu.markdown package dev.usbharu.markdown
import dev.usbharu.markdown.AstNode.*
import dev.usbharu.markdown.Token.*
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals