From 82da4791606ab95e7b9475f6003a5368221053c4 Mon Sep 17 00:00:00 2001 From: Kyle Lin Date: Sat, 17 Dec 2022 00:33:17 +0800 Subject: [PATCH 1/4] Add scala implementation for Nenggao --- scalaImpl/build.gradle.kts | 14 ++++++++ .../scala/chaos/unity/nenggao/ScLabel.scala | 6 ++++ .../chaos/unity/nenggao/ScPosition.scala | 6 ++++ .../scala/chaos/unity/nenggao/ScSpan.scala | 32 +++++++++++++++++++ settings.gradle.kts | 1 + 5 files changed, 59 insertions(+) create mode 100644 scalaImpl/build.gradle.kts create mode 100644 scalaImpl/src/main/scala/chaos/unity/nenggao/ScLabel.scala create mode 100644 scalaImpl/src/main/scala/chaos/unity/nenggao/ScPosition.scala create mode 100644 scalaImpl/src/main/scala/chaos/unity/nenggao/ScSpan.scala diff --git a/scalaImpl/build.gradle.kts b/scalaImpl/build.gradle.kts new file mode 100644 index 0000000..2979e75 --- /dev/null +++ b/scalaImpl/build.gradle.kts @@ -0,0 +1,14 @@ +plugins { + scala +} + +group = "chaos.unity.nenggao" +version = "1.4.0" + +repositories { + mavenCentral() +} + +dependencies { + implementation(project(":")) +} diff --git a/scalaImpl/src/main/scala/chaos/unity/nenggao/ScLabel.scala b/scalaImpl/src/main/scala/chaos/unity/nenggao/ScLabel.scala new file mode 100644 index 0000000..2ea4fc3 --- /dev/null +++ b/scalaImpl/src/main/scala/chaos/unity/nenggao/ScLabel.scala @@ -0,0 +1,6 @@ +package chaos.unity.nenggao + +import scala.annotation.unused + +@unused +case class ScLabel(span: AbstractSpan, message: String) extends AbstractLabel(span, message) diff --git a/scalaImpl/src/main/scala/chaos/unity/nenggao/ScPosition.scala b/scalaImpl/src/main/scala/chaos/unity/nenggao/ScPosition.scala new file mode 100644 index 0000000..284c598 --- /dev/null +++ b/scalaImpl/src/main/scala/chaos/unity/nenggao/ScPosition.scala @@ -0,0 +1,6 @@ +package chaos.unity.nenggao + +import scala.annotation.unused + +@unused +case class ScPosition(line: Int, pos: Int) extends AbstractPosition(line, pos) diff --git a/scalaImpl/src/main/scala/chaos/unity/nenggao/ScSpan.scala b/scalaImpl/src/main/scala/chaos/unity/nenggao/ScSpan.scala new file mode 100644 index 0000000..e6b04ff --- /dev/null +++ b/scalaImpl/src/main/scala/chaos/unity/nenggao/ScSpan.scala @@ -0,0 +1,32 @@ +package chaos.unity.nenggao + +case class ScSpan(startPosition: AbstractPosition, endPosition: AbstractPosition) extends AbstractSpan(startPosition, endPosition) { + /** + * expand copy current instance of {@link AbstractSpan} and attempt to extend end position to {@code endSpan}. + * If {@code endSpan} is null, returns copy of current instance; if {@code endSpan}'s {@link AbstractSpan# endPosition} + * is in front of the current instance's {@link AbstractSpan# startPosition}, returns copy of current instance, otherwise, + * returns a copy of current instance, which its {@link AbstractSpan# endPosition} is replaced by {@code endSpan}'s + * {@link AbstractSpan# endPosition}. + * + * @param endSpan the span to expand with + * @return a copy of current instance, field data would be different based on {@code endSpan}'s data + */ + override def expand(endSpan: AbstractSpan): AbstractSpan = { + val copied = copy() + + if (endSpan == null) + return copied + + if (endSpan.endPosition.line < startPosition.line) copied + else if (endSpan.endPosition.line == startPosition.line && endSpan.endPosition.pos < startPosition.pos) copied + else { + val startPosition = startPosition + val endPosition = endSpan.endPosition + + ScSpan(startPosition, endPosition) + } + } + + override def copy(): AbstractSpan = + ScSpan(startPosition, endPosition) +} diff --git a/settings.gradle.kts b/settings.gradle.kts index a43a07d..a671f00 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,2 +1,3 @@ rootProject.name = "Nenggao" include("kotlinImpl") +include("scalaImpl") From e69d4321e889787fda815ed34b9053e084705917 Mon Sep 17 00:00:00 2001 From: Kyle Lin Date: Sat, 17 Dec 2022 00:38:16 +0800 Subject: [PATCH 2/4] Minor code cleanup --- .../main/scala/chaos/unity/nenggao/ScSpan.scala | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/scalaImpl/src/main/scala/chaos/unity/nenggao/ScSpan.scala b/scalaImpl/src/main/scala/chaos/unity/nenggao/ScSpan.scala index e6b04ff..9bf929e 100644 --- a/scalaImpl/src/main/scala/chaos/unity/nenggao/ScSpan.scala +++ b/scalaImpl/src/main/scala/chaos/unity/nenggao/ScSpan.scala @@ -1,23 +1,11 @@ package chaos.unity.nenggao case class ScSpan(startPosition: AbstractPosition, endPosition: AbstractPosition) extends AbstractSpan(startPosition, endPosition) { - /** - * expand copy current instance of {@link AbstractSpan} and attempt to extend end position to {@code endSpan}. - * If {@code endSpan} is null, returns copy of current instance; if {@code endSpan}'s {@link AbstractSpan# endPosition} - * is in front of the current instance's {@link AbstractSpan# startPosition}, returns copy of current instance, otherwise, - * returns a copy of current instance, which its {@link AbstractSpan# endPosition} is replaced by {@code endSpan}'s - * {@link AbstractSpan# endPosition}. - * - * @param endSpan the span to expand with - * @return a copy of current instance, field data would be different based on {@code endSpan}'s data - */ override def expand(endSpan: AbstractSpan): AbstractSpan = { val copied = copy() - if (endSpan == null) - return copied - - if (endSpan.endPosition.line < startPosition.line) copied + if (endSpan == null) copied + else if (endSpan.endPosition.line < startPosition.line) copied else if (endSpan.endPosition.line == startPosition.line && endSpan.endPosition.pos < startPosition.pos) copied else { val startPosition = startPosition From 052471360f54d09a933e78a063f91ee0f58a4b92 Mon Sep 17 00:00:00 2001 From: Kyle Lin Date: Sat, 17 Dec 2022 00:38:35 +0800 Subject: [PATCH 3/4] Refactor kotlinImpl --- .../src/main/kotlin/chaos/unity/nengao/KtLabel.kt | 7 +++++++ .../src/main/kotlin/chaos/unity/nengao/KtPosition.kt | 6 ++++++ .../chaos/unity/nengao/{kotlin/Span.kt => KtSpan.kt} | 5 +++-- .../src/main/kotlin/chaos/unity/nengao/kotlin/Label.kt | 6 ------ .../main/kotlin/chaos/unity/nengao/kotlin/Position.kt | 5 ----- src/test/resources/long_line.yk | 10 ---------- 6 files changed, 16 insertions(+), 23 deletions(-) create mode 100644 kotlinImpl/src/main/kotlin/chaos/unity/nengao/KtLabel.kt create mode 100644 kotlinImpl/src/main/kotlin/chaos/unity/nengao/KtPosition.kt rename kotlinImpl/src/main/kotlin/chaos/unity/nengao/{kotlin/Span.kt => KtSpan.kt} (82%) delete mode 100644 kotlinImpl/src/main/kotlin/chaos/unity/nengao/kotlin/Label.kt delete mode 100644 kotlinImpl/src/main/kotlin/chaos/unity/nengao/kotlin/Position.kt diff --git a/kotlinImpl/src/main/kotlin/chaos/unity/nengao/KtLabel.kt b/kotlinImpl/src/main/kotlin/chaos/unity/nengao/KtLabel.kt new file mode 100644 index 0000000..b8ae4ea --- /dev/null +++ b/kotlinImpl/src/main/kotlin/chaos/unity/nengao/KtLabel.kt @@ -0,0 +1,7 @@ +package chaos.unity.nengao + +import chaos.unity.nenggao.AbstractLabel +import chaos.unity.nenggao.AbstractSpan + +@Suppress("unused") +data class KtLabel(val span: AbstractSpan, val message: String) : AbstractLabel(span, message) diff --git a/kotlinImpl/src/main/kotlin/chaos/unity/nengao/KtPosition.kt b/kotlinImpl/src/main/kotlin/chaos/unity/nengao/KtPosition.kt new file mode 100644 index 0000000..94d1859 --- /dev/null +++ b/kotlinImpl/src/main/kotlin/chaos/unity/nengao/KtPosition.kt @@ -0,0 +1,6 @@ +package chaos.unity.nengao + +import chaos.unity.nenggao.AbstractPosition + +@Suppress("unused") +data class KtPosition(val line: Int, val pos: Int) : AbstractPosition(line, pos) diff --git a/kotlinImpl/src/main/kotlin/chaos/unity/nengao/kotlin/Span.kt b/kotlinImpl/src/main/kotlin/chaos/unity/nengao/KtSpan.kt similarity index 82% rename from kotlinImpl/src/main/kotlin/chaos/unity/nengao/kotlin/Span.kt rename to kotlinImpl/src/main/kotlin/chaos/unity/nengao/KtSpan.kt index b8e56d0..8fd7090 100644 --- a/kotlinImpl/src/main/kotlin/chaos/unity/nengao/kotlin/Span.kt +++ b/kotlinImpl/src/main/kotlin/chaos/unity/nengao/KtSpan.kt @@ -1,10 +1,11 @@ -package chaos.unity.nengao.kotlin +package chaos.unity.nengao import chaos.unity.nenggao.AbstractPosition import chaos.unity.nenggao.AbstractSpan import chaos.unity.nenggao.Span -data class Span(val startPosition: AbstractPosition, val endPosition: AbstractPosition) : +@Suppress("unused") +data class KtSpan(val startPosition: AbstractPosition, val endPosition: AbstractPosition) : AbstractSpan(startPosition, endPosition) { override fun expand(endSpan: AbstractSpan?): AbstractSpan = endSpan?.let { diff --git a/kotlinImpl/src/main/kotlin/chaos/unity/nengao/kotlin/Label.kt b/kotlinImpl/src/main/kotlin/chaos/unity/nengao/kotlin/Label.kt deleted file mode 100644 index 3d9a537..0000000 --- a/kotlinImpl/src/main/kotlin/chaos/unity/nengao/kotlin/Label.kt +++ /dev/null @@ -1,6 +0,0 @@ -package chaos.unity.nengao.kotlin - -import chaos.unity.nenggao.AbstractLabel -import chaos.unity.nenggao.AbstractSpan - -data class Label(val span: AbstractSpan, val message: String) : AbstractLabel(span, message) diff --git a/kotlinImpl/src/main/kotlin/chaos/unity/nengao/kotlin/Position.kt b/kotlinImpl/src/main/kotlin/chaos/unity/nengao/kotlin/Position.kt deleted file mode 100644 index 84b91c5..0000000 --- a/kotlinImpl/src/main/kotlin/chaos/unity/nengao/kotlin/Position.kt +++ /dev/null @@ -1,5 +0,0 @@ -package chaos.unity.nengao.kotlin - -import chaos.unity.nenggao.AbstractPosition - -data class Position(val line: Int, val pos: Int) : AbstractPosition(line, pos) diff --git a/src/test/resources/long_line.yk b/src/test/resources/long_line.yk index ca94af1..e69de29 100644 --- a/src/test/resources/long_line.yk +++ b/src/test/resources/long_line.yk @@ -1,10 +0,0 @@ -start -post-start - - - - - - -pre-end -end \ No newline at end of file From 034d7aa69483b7dc86aee81e10af8fb486a2c0f0 Mon Sep 17 00:00:00 2001 From: Kyle Lin Date: Sat, 17 Dec 2022 01:17:32 +0800 Subject: [PATCH 4/4] Release 1.4.1 --- build.gradle.kts | 6 +++--- gradle.properties | 1 + kotlinImpl/build.gradle.kts | 4 +++- scalaImpl/build.gradle.kts | 4 +++- settings.gradle.kts | 1 + 5 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 gradle.properties diff --git a/build.gradle.kts b/build.gradle.kts index dd8e131..c50fab1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,13 +1,13 @@ -import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar - plugins { id("maven-publish") id("java") id("com.github.johnrengelman.shadow") version "7.1.2" } +val commonVersion: String by properties + group = "chaos.unity.nenggao" -version = "1.4.0" +version = commonVersion repositories { mavenCentral() diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..4e295db --- /dev/null +++ b/gradle.properties @@ -0,0 +1 @@ +commonVersion=1.4.1 \ No newline at end of file diff --git a/kotlinImpl/build.gradle.kts b/kotlinImpl/build.gradle.kts index eea44a8..821848e 100644 --- a/kotlinImpl/build.gradle.kts +++ b/kotlinImpl/build.gradle.kts @@ -2,8 +2,10 @@ plugins { kotlin("jvm") version "1.7.20" } +val commonVersion: String by project(":").properties + group = "chaos.unity.nenggao" -version = "1.4.0" +version = commonVersion repositories { mavenCentral() diff --git a/scalaImpl/build.gradle.kts b/scalaImpl/build.gradle.kts index 2979e75..e4f27e1 100644 --- a/scalaImpl/build.gradle.kts +++ b/scalaImpl/build.gradle.kts @@ -2,8 +2,10 @@ plugins { scala } +val commonVersion: String by properties + group = "chaos.unity.nenggao" -version = "1.4.0" +version = commonVersion repositories { mavenCentral() diff --git a/settings.gradle.kts b/settings.gradle.kts index a671f00..1b78f46 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,3 +1,4 @@ rootProject.name = "Nenggao" + include("kotlinImpl") include("scalaImpl")