Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy_maven_central.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
branches:
- main
pull_request:
types: [opened, synchronize]
types: [opened, synchronize, edited]
branches:
- main
workflow_dispatch:
Expand Down
9 changes: 1 addition & 8 deletions generate/src/jvmMain/kotlin/_Tag_generate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,35 @@ import generator.DslGenerator
import generator.IntegrationGenerator
import generator.NativeGenerator
import generator.TagGenerator
import generator.UnionGenerator
import java.io.File

fun main() {
// 出力先ディレクトリ
val outputDir = "../renlin/src/commonMain/kotlin/net/kigawa/renlin/tag"
val categoryOutputDir = "../renlin/src/commonMain/kotlin/net/kigawa/renlin/w3c/category"
val categoryUnionOutputDir = "$categoryOutputDir/native"
val categoryIntegrationOutputDir = "$categoryOutputDir/integration"
val categoryDslOutputDir = "$categoryOutputDir/dsl"
val categoryNativeOutputDir = "$categoryOutputDir/native"
File(outputDir).mkdirs()
File(categoryOutputDir).mkdirs()
File(categoryUnionOutputDir).mkdirs()
File(categoryIntegrationOutputDir).mkdirs()
File(categoryDslOutputDir).mkdirs()
File(categoryNativeOutputDir).mkdirs()

val tagGenerator = TagGenerator(outputDir).also {
it.generate()
}
val unionGenerator = UnionGenerator(categoryUnionOutputDir).also {
it.generate()
}
val integrationGenerator = IntegrationGenerator(categoryIntegrationOutputDir).also {
it.generate()
}
val dslGenerator = DslGenerator(categoryDslOutputDir).also {
it.generate()
}
val nativeGenerator = NativeGenerator(categoryNativeOutputDir).also {
it.generate(unionGenerator.nativeCategories)
it.generate(integrationGenerator.nativeCategories)
}

println("タグのコード生成が完了しました。")
println("生成されたUnionクラス: ${unionGenerator.processedUnions.size}")
println("生成されたIntegrationクラス: ${integrationGenerator.processedIntegrations.size}")
println("生成されたDSLクラス: ${dslGenerator.processedDsls.size}")
}
62 changes: 46 additions & 16 deletions generate/src/jvmMain/kotlin/generator/IntegrationGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,66 @@ class IntegrationGenerator(
val categoryIntegrationOutputDir: String,
) {
val processedIntegrations = mutableSetOf<String>()
val nativeCategories = mutableMapOf<String, MutableSet<String>>()
fun generate() {
// Integrationクラスの生成
// First collect all possible integrations
val allIntegrations = mutableMapOf<String, Set<String>>()

tagCategories
.map { it.allowedCategories }
.map { it.tagCategories }
.filter { it.categories.size > 1 }
.forEach { allowedCategories ->
val integrationName = allowedCategories.connectedStr("Integration")
.toSet()
.forEach { tagCategories ->
val integrationName = tagCategories.connectedStr("Integration")
if (!processedIntegrations.contains(integrationName)) {
processedIntegrations.add(integrationName)
val categories = allowedCategories.categories
allIntegrations[integrationName] = tagCategories.categories.toSet()

val fileContent = """
tagCategories.categories.forEach {
nativeCategories.getOrPut(it) { mutableSetOf() }.add(integrationName)
}
}
}

// Generate each integration with inheritance from subset integrations
allIntegrations.forEach { (integrationName, categories) ->
// Find other integrations that are subsets of this integration
val subsetIntegrations = allIntegrations.filter { (otherName, otherCategories) ->
otherName != integrationName &&
otherCategories.isNotEmpty() &&
otherCategories.all { it in categories } &&
otherCategories.size < categories.size
}.keys

// Generate imports for categories and subset integrations
val categoryImports = categories.map { category ->
"import net.kigawa.renlin.w3c.category.native.$category"
}

val integrationImports = subsetIntegrations.map { subsetIntegration ->
"import net.kigawa.renlin.w3c.category.integration.$subsetIntegration"
}

val allImports = (categoryImports + integrationImports).joinToString("\n ")

// Generate inheritance list including categories and subset integrations
val inheritance = (categories + subsetIntegrations + "ContentCategory").joinToString(", ")

val fileContent = """
package net.kigawa.renlin.w3c.category.integration

import net.kigawa.renlin.w3c.category.ContentCategory
${
categories.joinToString("\n ")
{ "import net.kigawa.renlin.w3c.category.native.$it" }
}
$allImports

/**
* Integration of ${categories.joinToString(", ")}
*/
interface $integrationName : ${(categories + "ContentCategory").joinToString(", ")}
interface $integrationName: $inheritance
""".trimIndent()

val file = File("$categoryIntegrationOutputDir/${integrationName}.kt")
file.writeText(fileContent)
println("Generated integration: ${integrationName}.kt")
}
}
val file = File("$categoryIntegrationOutputDir/${integrationName}.kt")
file.writeText(fileContent)
println("Generated integration: ${integrationName}.kt")
}
}
}
4 changes: 2 additions & 2 deletions generate/src/jvmMain/kotlin/generator/NativeGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class NativeGenerator(val categoryNativeOutputDir: String) {
allParentCategories.putAll(tagInfo.allowedCategories.parentCategories)
}

// Unionクラスの生成
// Integrationクラスの生成
categories.forEach { (name, deps) ->
val categoryName = name

Expand All @@ -33,7 +33,7 @@ class NativeGenerator(val categoryNativeOutputDir: String) {
import net.kigawa.renlin.w3c.category.ContentCategory

/**
* Union to ${deps.joinToString(", ")}
* Integration to ${deps.joinToString(", ")}
* ${if (parentCategory != null) "Parent: $parentCategory" else ""}
*/
interface $categoryName : $interfaces
Expand Down
42 changes: 27 additions & 15 deletions generate/src/jvmMain/kotlin/generator/TagGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,36 @@ class TagGenerator(
// 各タグのクラスを生成
tagCategories.forEach { tagInfo ->

val fileContent = """
package net.kigawa.renlin.tag
val imports = mutableSetOf<String>()

import net.kigawa.renlin.w3c.category.native.${tagInfo.tagCategories.connectedStr("Union")}
${
if (tagInfo.allowedCategories.categories.size > 1)
if (tagInfo.tagCategories.categories.size > 1)
imports.add(
"import net.kigawa.renlin.w3c.category.integration.${
tagInfo.tagCategories.connectedStr(
"Integration"
)
}"
)
else imports.add("import net.kigawa.renlin.w3c.category.native.${tagInfo.tagCategories.connectedStr()}")
if (tagInfo.allowedCategories.categories.size > 1)
imports.add(
"import net.kigawa.renlin.w3c.category.integration.${
tagInfo.allowedCategories.connectedStr("Integration")
}"
else if (
tagInfo.allowedCategories.categories.isNotEmpty() &&
tagInfo.tagCategories.connectedStr("Union") !=
tagInfo.allowedCategories.connectedStr("Integration")
) "import net.kigawa.renlin.w3c.category.native.${
tagInfo.allowedCategories.connectedStr("Integration")
)
else if (
tagInfo.allowedCategories.categories.isNotEmpty() &&
tagInfo.tagCategories.connectedStr("Integration") !=
tagInfo.allowedCategories.connectedStr("Integration")
) imports.add(
"import net.kigawa.renlin.w3c.category.native.${
tagInfo.allowedCategories.connectedStr()
}"
else ""
}
)
val fileContent = """
package net.kigawa.renlin.tag

${imports.distinct().joinToString("\n ")}
import net.kigawa.renlin.dsl.DslBase
import net.kigawa.renlin.dsl.StatedDsl
import net.kigawa.renlin.component.TagComponent1
Expand All @@ -49,7 +61,7 @@ class TagGenerator(
StatedDsl<${tagInfo.allowedCategories.connectedStr("Integration")}>${
if (tagInfo.allowedCategories.categories.isEmpty()) ""
else ",\n ${tagInfo.allowedCategories.connectedStr()}" +
"Dsl<${tagInfo.allowedCategories.connectedStr("Integration")}>"
"Dsl<${tagInfo.allowedCategories.connectedStr("Integration")}>"
} {
override fun applyElement(element: TagNode): ()->Unit {
return {}
Expand All @@ -58,7 +70,7 @@ class TagGenerator(

val ${tagInfo.escapement} = TagComponent1(${tagInfo.className}, ::${tagInfo.className}Dsl)

object ${tagInfo.className} : Tag<${tagInfo.tagCategories.connectedStr("Union")}> {
object ${tagInfo.className} : Tag<${tagInfo.tagCategories.connectedStr("Integration")}> {
override val name: String
get() = "${tagInfo.name}"
}
Expand Down
45 changes: 0 additions & 45 deletions generate/src/jvmMain/kotlin/generator/UnionGenerator.kt

This file was deleted.

3 changes: 1 addition & 2 deletions renlin/src/commonMain/kotlin/net/kigawa/renlin/tag/A.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.kigawa.renlin.tag

import net.kigawa.renlin.w3c.category.native.FlowInteractivePalpablePhrasingUnion
import net.kigawa.renlin.w3c.category.integration.FlowInteractivePalpablePhrasingIntegration
import net.kigawa.renlin.dsl.DslBase
import net.kigawa.renlin.dsl.StatedDsl
Expand All @@ -26,7 +25,7 @@ class ADsl(dslState: DslState):

val a = TagComponent1(A, ::ADsl)

object A : Tag<FlowInteractivePalpablePhrasingUnion> {
object A : Tag<FlowInteractivePalpablePhrasingIntegration> {
override val name: String
get() = "a"
}
5 changes: 2 additions & 3 deletions renlin/src/commonMain/kotlin/net/kigawa/renlin/tag/Abbr.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.kigawa.renlin.tag

import net.kigawa.renlin.w3c.category.native.FlowPalpablePhrasingUnion

import net.kigawa.renlin.w3c.category.integration.FlowPalpablePhrasingIntegration
import net.kigawa.renlin.dsl.DslBase
import net.kigawa.renlin.dsl.StatedDsl
import net.kigawa.renlin.component.TagComponent1
Expand All @@ -24,7 +23,7 @@ class AbbrDsl(dslState: DslState):

val abbr = TagComponent1(Abbr, ::AbbrDsl)

object Abbr : Tag<FlowPalpablePhrasingUnion> {
object Abbr : Tag<FlowPalpablePhrasingIntegration> {
override val name: String
get() = "abbr"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.kigawa.renlin.tag

import net.kigawa.renlin.w3c.category.native.FlowPalpableUnion
import net.kigawa.renlin.w3c.category.integration.FlowPalpableIntegration
import net.kigawa.renlin.dsl.DslBase
import net.kigawa.renlin.dsl.StatedDsl
Expand All @@ -26,7 +25,7 @@ class AddressDsl(dslState: DslState):

val address = TagComponent1(Address, ::AddressDsl)

object Address : Tag<FlowPalpableUnion> {
object Address : Tag<FlowPalpableIntegration> {
override val name: String
get() = "address"
}
5 changes: 2 additions & 3 deletions renlin/src/commonMain/kotlin/net/kigawa/renlin/tag/Area.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.kigawa.renlin.tag

import net.kigawa.renlin.w3c.category.native.FlowPhrasingUnion

import net.kigawa.renlin.w3c.category.integration.FlowPhrasingIntegration
import net.kigawa.renlin.dsl.DslBase
import net.kigawa.renlin.dsl.StatedDsl
import net.kigawa.renlin.component.TagComponent1
Expand All @@ -24,7 +23,7 @@ class AreaDsl(dslState: DslState):

val area = TagComponent1(Area, ::AreaDsl)

object Area : Tag<FlowPhrasingUnion> {
object Area : Tag<FlowPhrasingIntegration> {
override val name: String
get() = "area"
}
5 changes: 2 additions & 3 deletions renlin/src/commonMain/kotlin/net/kigawa/renlin/tag/Article.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.kigawa.renlin.tag

import net.kigawa.renlin.w3c.category.native.FlowPalpableSectioningUnion

import net.kigawa.renlin.w3c.category.integration.FlowPalpableSectioningIntegration
import net.kigawa.renlin.dsl.DslBase
import net.kigawa.renlin.dsl.StatedDsl
import net.kigawa.renlin.component.TagComponent1
Expand All @@ -24,7 +23,7 @@ class ArticleDsl(dslState: DslState):

val article = TagComponent1(Article, ::ArticleDsl)

object Article : Tag<FlowPalpableSectioningUnion> {
object Article : Tag<FlowPalpableSectioningIntegration> {
override val name: String
get() = "article"
}
5 changes: 2 additions & 3 deletions renlin/src/commonMain/kotlin/net/kigawa/renlin/tag/Aside.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.kigawa.renlin.tag

import net.kigawa.renlin.w3c.category.native.FlowPalpableSectioningUnion

import net.kigawa.renlin.w3c.category.integration.FlowPalpableSectioningIntegration
import net.kigawa.renlin.dsl.DslBase
import net.kigawa.renlin.dsl.StatedDsl
import net.kigawa.renlin.component.TagComponent1
Expand All @@ -24,7 +23,7 @@ class AsideDsl(dslState: DslState):

val aside = TagComponent1(Aside, ::AsideDsl)

object Aside : Tag<FlowPalpableSectioningUnion> {
object Aside : Tag<FlowPalpableSectioningIntegration> {
override val name: String
get() = "aside"
}
5 changes: 2 additions & 3 deletions renlin/src/commonMain/kotlin/net/kigawa/renlin/tag/Audio.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.kigawa.renlin.tag

import net.kigawa.renlin.w3c.category.native.EmbeddedFlowInteractivePalpablePhrasingUnion

import net.kigawa.renlin.w3c.category.integration.EmbeddedFlowInteractivePalpablePhrasingIntegration
import net.kigawa.renlin.dsl.DslBase
import net.kigawa.renlin.dsl.StatedDsl
import net.kigawa.renlin.component.TagComponent1
Expand All @@ -24,7 +23,7 @@ class AudioDsl(dslState: DslState):

val audio = TagComponent1(Audio, ::AudioDsl)

object Audio : Tag<EmbeddedFlowInteractivePalpablePhrasingUnion> {
object Audio : Tag<EmbeddedFlowInteractivePalpablePhrasingIntegration> {
override val name: String
get() = "audio"
}
Loading
Loading