-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/serialization' into 'develop'
Serialization support See merge request pika-lab/tuprolog/2p-in-kotlin!86
- Loading branch information
Showing
68 changed files
with
2,097 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
kotlin { | ||
|
||
sourceSets { | ||
val commonMain by getting { | ||
dependencies { | ||
api(project(":core")) | ||
} | ||
} | ||
|
||
jvm { | ||
compilations["main"].defaultSourceSet { | ||
dependencies { | ||
implementation(Libs.jackson_core) | ||
implementation(Libs.jackson_datatype_jsr310) | ||
implementation(Libs.jackson_dataformat_yaml) | ||
implementation(Libs.jackson_dataformat_xml) | ||
} | ||
} | ||
} | ||
|
||
js { | ||
compilations["main"].defaultSourceSet { | ||
dependencies { | ||
api(npm("yaml", "^1.10.0")) | ||
} | ||
} | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...lize-core/src/commonMain/kotlin/it/unibo/tuprolog/serialize/DeobjectificationException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package it.unibo.tuprolog.serialize | ||
|
||
import it.unibo.tuprolog.core.exception.TuPrologException | ||
|
||
class DeobjectificationException(`object`: Any) : TuPrologException("Error while deobjectifying $`object`") |
11 changes: 11 additions & 0 deletions
11
serialize-core/src/commonMain/kotlin/it/unibo/tuprolog/serialize/Deobjectifier.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package it.unibo.tuprolog.serialize | ||
|
||
import kotlin.js.JsName | ||
|
||
interface Deobjectifier<T> { | ||
@JsName("deobjectify") | ||
fun deobjectify(`object`: Any): T | ||
|
||
@JsName("deobjectifyMany") | ||
fun deobjectifyMany(`object`: Any): Iterable<T> | ||
} |
14 changes: 14 additions & 0 deletions
14
serialize-core/src/commonMain/kotlin/it/unibo/tuprolog/serialize/Deserializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package it.unibo.tuprolog.serialize | ||
|
||
import kotlin.js.JsName | ||
|
||
interface Deserializer<T> { | ||
@JsName("mimeType") | ||
val mimeType: MimeType | ||
|
||
@JsName("deserialize") | ||
fun deserialize(string: String): T | ||
|
||
@JsName("deserializeMany") | ||
fun deserializeMany(string: String): Iterable<T> | ||
} |
18 changes: 18 additions & 0 deletions
18
serialize-core/src/commonMain/kotlin/it/unibo/tuprolog/serialize/MimeType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package it.unibo.tuprolog.serialize | ||
|
||
import kotlin.js.JsName | ||
|
||
sealed class MimeType( | ||
@JsName("type") | ||
val type: String, | ||
@JsName("subType") | ||
val subType: String | ||
) { | ||
|
||
object Json : MimeType("application", "json") | ||
|
||
object Yaml : MimeType("application", "yaml") | ||
|
||
object Xml : MimeType("application", "xml") | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
serialize-core/src/commonMain/kotlin/it/unibo/tuprolog/serialize/Objectifier.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package it.unibo.tuprolog.objectify | ||
|
||
import kotlin.js.JsName | ||
|
||
interface Objectifier<T> { | ||
@JsName("objectify") | ||
fun objectify(value: T): Any | ||
|
||
@JsName("objectifyMany") | ||
fun objectifyMany(vararg values: T): Any = | ||
objectifyMany(listOf(*values)) | ||
|
||
@JsName("objectifyManyIterable") | ||
fun objectifyMany(values: Iterable<T>): Any | ||
|
||
@JsName("objectifyManySequence") | ||
fun objectifyMany(values: Sequence<T>): Any = | ||
objectifyMany(values.asIterable()) | ||
} |
7 changes: 7 additions & 0 deletions
7
serialize-core/src/commonMain/kotlin/it/unibo/tuprolog/serialize/ObjectsUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package it.unibo.tuprolog.serialize | ||
|
||
expect object ObjectsUtils { | ||
fun parseAsObject(string: String, mimeType: MimeType): Any | ||
|
||
fun deeplyEqual(obj1: Any?, obj2: Any?): Boolean | ||
} |
6 changes: 6 additions & 0 deletions
6
serialize-core/src/commonMain/kotlin/it/unibo/tuprolog/serialize/SerializationException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package it.unibo.tuprolog.serialize | ||
|
||
import it.unibo.tuprolog.core.Term | ||
import it.unibo.tuprolog.core.exception.TuPrologException | ||
|
||
class SerializationException(term: Term) : TuPrologException("Error while serialising $term") |
22 changes: 22 additions & 0 deletions
22
serialize-core/src/commonMain/kotlin/it/unibo/tuprolog/serialize/Serializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package it.unibo.tuprolog.serialize | ||
|
||
import kotlin.js.JsName | ||
|
||
interface Serializer<T> { | ||
@JsName("mimeType") | ||
val mimeType: MimeType | ||
|
||
@JsName("serialize") | ||
fun serialize(value: T): String | ||
|
||
@JsName("serializeMany") | ||
fun serializeMany(vararg values: T): String = | ||
serializeMany(listOf(*values)) | ||
|
||
@JsName("serializeManyIterable") | ||
fun serializeMany(values: Iterable<T>): String | ||
|
||
@JsName("serializeManySequence") | ||
fun serializeMany(values: Sequence<T>): String = | ||
serializeMany(values.asIterable()) | ||
} |
14 changes: 14 additions & 0 deletions
14
serialize-core/src/commonMain/kotlin/it/unibo/tuprolog/serialize/TermDeobjectifier.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package it.unibo.tuprolog.serialize | ||
|
||
import it.unibo.tuprolog.core.Term | ||
import kotlin.js.JsName | ||
import kotlin.jvm.JvmStatic | ||
|
||
interface TermDeobjectifier : Deobjectifier<Term> { | ||
companion object { | ||
@JsName("default") | ||
@JvmStatic | ||
val default: TermDeobjectifier | ||
get() = termDeobjectifier() | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
serialize-core/src/commonMain/kotlin/it/unibo/tuprolog/serialize/TermDeserializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package it.unibo.tuprolog.serialize | ||
|
||
import it.unibo.tuprolog.core.Term | ||
import kotlin.js.JsName | ||
import kotlin.jvm.JvmStatic | ||
|
||
interface TermDeserializer : Deserializer<Term> { | ||
companion object { | ||
@JvmStatic | ||
@JsName("of") | ||
fun of(mimeType: MimeType): TermDeserializer { | ||
return termDeserializer(mimeType) | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
serialize-core/src/commonMain/kotlin/it/unibo/tuprolog/serialize/TermObjectifier.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package it.unibo.tuprolog.serialize | ||
|
||
import it.unibo.tuprolog.core.Term | ||
import it.unibo.tuprolog.core.TermVisitor | ||
import it.unibo.tuprolog.objectify.Objectifier | ||
import kotlin.js.JsName | ||
import kotlin.jvm.JvmStatic | ||
|
||
interface TermObjectifier : Objectifier<Term>, TermVisitor<Any> { | ||
override fun objectify(value: Term): Any = visit(value) | ||
|
||
companion object { | ||
@JsName("default") | ||
@JvmStatic | ||
val default: TermObjectifier | ||
get() = termObjectifier() | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
serialize-core/src/commonMain/kotlin/it/unibo/tuprolog/serialize/TermSerialization.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
@file:JvmName("TermSerialization") | ||
|
||
package it.unibo.tuprolog.serialize | ||
|
||
import kotlin.jvm.JvmName | ||
|
||
expect fun termSerializer(mimeType: MimeType): TermSerializer | ||
|
||
expect fun termDeserializer(mimeType: MimeType): TermDeserializer | ||
|
||
expect fun termObjectifier(): TermObjectifier | ||
|
||
expect fun termDeobjectifier(): TermDeobjectifier |
Oops, something went wrong.