jsexportを追加
This commit is contained in:
parent
8beae5e426
commit
ecff061924
|
@ -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 {
|
||||||
|
|
|
@ -1,71 +1,74 @@
|
||||||
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 {
|
||||||
return node.print()
|
return node.print()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class BodyNode(val body: List<AstNode>) : AstNode() {
|
data class BodyNode(val body: List<AstNode>) : AstNode() {
|
||||||
override fun print(): String {
|
override fun print(): String {
|
||||||
return body.joinToString("\n") { it.print() }
|
return body.joinToString("\n") { it.print() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class BlockNode : AstNode()
|
sealed class BlockNode : AstNode()
|
||||||
|
|
||||||
data class HeaderNode(val header: Int, val headerTextNode: HeaderTextNode?) : BlockNode() {
|
data class HeaderNode(val header: Int, val headerTextNode: HeaderTextNode?) : BlockNode() {
|
||||||
override fun print(): String {
|
override fun print(): String {
|
||||||
return "#".repeat(header) + " " + headerTextNode?.print().orEmpty()
|
return "#".repeat(header) + " " + headerTextNode?.print().orEmpty()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class HeaderTextNode(val text: String) : BlockNode() {
|
data class HeaderTextNode(val text: String) : BlockNode() {
|
||||||
override fun print(): String {
|
override fun print(): String {
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed interface QuotableNode
|
sealed interface QuotableNode
|
||||||
data class QuoteNode(val nodes: List<QuotableNode>) : AstNode(), QuotableNode
|
data class QuoteNode(val nodes: List<QuotableNode>) : AstNode(), QuotableNode
|
||||||
data object SeparatorNode : BlockNode() {
|
data object SeparatorNode : BlockNode() {
|
||||||
override fun print(): String {
|
override fun print(): String {
|
||||||
return "---"
|
return "---"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sealed class ListNode : BlockNode()
|
|
||||||
data class DiscListNode(val node: InlineNode, val childList: List<ListNode>) : ListNode()
|
sealed class ListNode : BlockNode()
|
||||||
data class DecimalListNode(val node: InlineNode, val childList: List<ListNode>) : ListNode()
|
data class DiscListNode(val node: InlineNode, val childList: List<ListNode>) : ListNode()
|
||||||
data class ParagraphNode(val nodes: List<InlineNode>) : ListNode() {
|
data class DecimalListNode(val node: InlineNode, val childList: List<ListNode>) : ListNode()
|
||||||
|
data class ParagraphNode(val nodes: List<InlineNode>) : ListNode() {
|
||||||
override fun print(): String {
|
override fun print(): String {
|
||||||
return nodes.joinToString("\n") { it.print() }
|
return nodes.joinToString("\n") { it.print() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class InlineNode : AstNode(), QuotableNode
|
sealed class InlineNode : AstNode(), QuotableNode
|
||||||
data class ItalicNode(val nodes: MutableList<InlineNode>) : InlineNode() {
|
data class ItalicNode(val nodes: MutableList<InlineNode>) : InlineNode() {
|
||||||
override fun print(): String {
|
override fun print(): String {
|
||||||
return nodes.joinToString("", prefix = "*", postfix = "*") { it.print() }
|
return nodes.joinToString("", prefix = "*", postfix = "*") { it.print() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class BoldNode(val nodes: MutableList<InlineNode>) : InlineNode() {
|
data class BoldNode(val nodes: MutableList<InlineNode>) : InlineNode() {
|
||||||
override fun print(): String {
|
override fun print(): String {
|
||||||
return nodes.joinToString("", prefix = "**", postfix = "**") { it.print() }
|
return nodes.joinToString("", prefix = "**", postfix = "**") { it.print() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class StrikeThroughNode(val nodes: List<InlineNode>) : InlineNode()
|
data class StrikeThroughNode(val nodes: List<InlineNode>) : InlineNode()
|
||||||
data class PlainText(val text: String) : InlineNode() {
|
data class PlainText(val text: String) : InlineNode() {
|
||||||
override fun print(): String {
|
override fun print(): String {
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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>()
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -1,40 +1,44 @@
|
||||||
package dev.usbharu.markdown
|
package dev.usbharu.markdown
|
||||||
|
|
||||||
sealed class Token()
|
import kotlin.js.JsExport
|
||||||
|
|
||||||
data class Text(var text: String) : Token()
|
@JsExport
|
||||||
data class Break(var count: Int) : Token()
|
sealed class Token {
|
||||||
data class Header(var count: Int) : Token()
|
data class Text(var text: String) : Token()
|
||||||
data class Quote(var count: Int) : Token()
|
data class Break(var count: Int) : Token()
|
||||||
data class Separator(var count: Int, val char: Char) : Token()
|
data class Header(var count: Int) : Token()
|
||||||
data class Whitespace(var count: Int, val whitespace: Char) : Token()
|
data class Quote(var count: Int) : Token()
|
||||||
abstract class List(val type: ListType) : Token() {
|
data class Separator(var count: Int, val char: Char) : Token()
|
||||||
|
data class Whitespace(var count: Int, val whitespace: Char) : Token()
|
||||||
|
abstract class List(val type: ListType) : Token() {
|
||||||
enum class ListType {
|
enum class ListType {
|
||||||
DISC,
|
DISC,
|
||||||
DECIMAL
|
DECIMAL
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data object DiscList : List(ListType.DISC)
|
||||||
|
data class DecimalList(val number: Char) : List(ListType.DECIMAL)
|
||||||
|
data class CheckBox(val checked: Boolean) : Token()
|
||||||
|
data object SquareBracketStart : Token()
|
||||||
|
data object SquareBracketEnd : Token()
|
||||||
|
data object ParenthesesStart : Token()
|
||||||
|
data object ParenthesesEnd : Token()
|
||||||
|
data class Url(var url: String) : Token()
|
||||||
|
data class Asterisk(var count: Int, var char: Char) : Token()
|
||||||
|
data object Exclamation : Token()
|
||||||
|
data class UrlTitle(val title: String) : Token()
|
||||||
|
data class InlineCodeBlock(val text: String) : Token()
|
||||||
|
data class CodeBlock(val text: String) : Token()
|
||||||
|
data class CodeBlockLanguage(val language: String, val filename: String) : Token()
|
||||||
|
data class Strike(val strike: String) : Token()
|
||||||
|
|
||||||
|
abstract class Html() : Token()
|
||||||
|
data class StartTagStart(var tag: String, val void: Boolean) : Html()
|
||||||
|
data class EndTagStart(var tag: String) : Html()
|
||||||
|
data class TagEnd(var tag: String) : Html()
|
||||||
|
data class AttributeName(val name: String) : Html()
|
||||||
|
data class AttributeValue(val value: String) : Html()
|
||||||
|
data class HtmlValue(val value: String) : Html()
|
||||||
}
|
}
|
||||||
|
|
||||||
data object DiscList : List(ListType.DISC)
|
|
||||||
data class DecimalList(val number: Char) : List(ListType.DECIMAL)
|
|
||||||
data class CheckBox(val checked: Boolean) : Token()
|
|
||||||
data object SquareBracketStart : Token()
|
|
||||||
data object SquareBracketEnd : Token()
|
|
||||||
data object ParenthesesStart : Token()
|
|
||||||
data object ParenthesesEnd : Token()
|
|
||||||
data class Url(var url: String) : Token()
|
|
||||||
data class Asterisk(var count: Int, var char: Char) : Token()
|
|
||||||
data object Exclamation : Token()
|
|
||||||
data class UrlTitle(val title: String) : Token()
|
|
||||||
data class InlineCodeBlock(val text: String) : Token()
|
|
||||||
data class CodeBlock(val text: String) : Token()
|
|
||||||
data class CodeBlockLanguage(val language: String, val filename: String) : Token()
|
|
||||||
data class Strike(val strike: String) : Token()
|
|
||||||
|
|
||||||
abstract class Html() : Token()
|
|
||||||
data class StartTagStart(var tag: String, val void: Boolean) : Html()
|
|
||||||
data class EndTagStart(var tag: String) : Html()
|
|
||||||
data class TagEnd(var tag: String) : Html()
|
|
||||||
data class AttributeName(val name: String) : Html()
|
|
||||||
data class AttributeValue(val value: String) : Html()
|
|
||||||
data class HtmlValue(val value: String) : Html()
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue