-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
165 additions
and
65 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
23 changes: 23 additions & 0 deletions
23
...s/geary-actions/src/commonMain/kotlin/com/mineinabyss/geary/actions/actions/EvalAction.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,23 @@ | ||
package com.mineinabyss.geary.actions.actions | ||
|
||
import com.mineinabyss.geary.actions.Action | ||
import com.mineinabyss.geary.actions.ActionGroupContext | ||
import com.mineinabyss.geary.actions.expressions.Expression | ||
import com.mineinabyss.geary.actions.expressions.InlineExpressionSerializer | ||
import com.mineinabyss.geary.serialization.serializers.InnerSerializer | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable(with = EvalAction.Serializer::class) | ||
class EvalAction( | ||
val expression: Expression<*>, | ||
) : Action { | ||
override fun ActionGroupContext.execute() = | ||
expression.evaluate(this) | ||
|
||
object Serializer : InnerSerializer<Expression<*>, EvalAction>( | ||
serialName = "geary:eval", | ||
inner = InlineExpressionSerializer, | ||
inverseTransform = { it.expression }, | ||
transform = { EvalAction(it) } | ||
) | ||
} |
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
30 changes: 30 additions & 0 deletions
30
...ons/src/commonMain/kotlin/com/mineinabyss/geary/actions/expressions/FunctionExpression.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,30 @@ | ||
package com.mineinabyss.geary.actions.expressions | ||
|
||
import com.mineinabyss.geary.actions.ActionGroupContext | ||
import com.mineinabyss.geary.serialization.serializableComponents | ||
import com.mineinabyss.geary.serialization.serializers.SerializableComponentId | ||
import kotlinx.serialization.modules.SerializersModule | ||
|
||
interface FunctionExpression<I, O> { | ||
companion object { | ||
fun parse( | ||
ref: Expression<*>, | ||
name: String, | ||
yaml: String, | ||
module: SerializersModule, | ||
): FunctionExpressionWithInput<*, *> { | ||
val compClass = SerializableComponentId.Serializer.getComponent(name, module) | ||
val serializer = serializableComponents.serializers.getSerializerFor(compClass) | ||
?: error("No serializer found for component $name") | ||
val expr = | ||
serializableComponents.formats["yml"]!!.decodeFromString<FunctionExpression<*, *>>(serializer, yaml) | ||
return FunctionExpressionWithInput(ref, expr) | ||
} | ||
} | ||
|
||
fun ActionGroupContext.map(input: I): O | ||
|
||
fun map(input: I, context: ActionGroupContext): O { | ||
return with(context) { map(input) } | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...ommonMain/kotlin/com/mineinabyss/geary/actions/expressions/FunctionExpressionWithInput.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 @@ | ||
package com.mineinabyss.geary.actions.expressions | ||
|
||
import com.mineinabyss.geary.actions.ActionGroupContext | ||
|
||
class FunctionExpressionWithInput<I, O>( | ||
val ref: Expression<*>, | ||
val expr: FunctionExpression<I, O>, | ||
) : Expression<O> { | ||
override fun evaluate(context: ActionGroupContext): O { | ||
val input = ref.evaluate(context) as I | ||
return expr.map(input, context) | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...commonMain/kotlin/com/mineinabyss/geary/actions/expressions/InlineExpressionSerializer.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,23 @@ | ||
package com.mineinabyss.geary.actions.expressions | ||
|
||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.builtins.serializer | ||
import kotlinx.serialization.descriptors.SerialDescriptor | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
|
||
object InlineExpressionSerializer : KSerializer<Expression<*>> { | ||
override val descriptor: SerialDescriptor = String.serializer().descriptor | ||
|
||
override fun deserialize(decoder: Decoder): Expression<*> { | ||
return Expression.parseExpression( | ||
decoder.decodeString(), | ||
decoder.serializersModule | ||
) | ||
} | ||
|
||
override fun serialize(encoder: Encoder, value: Expression<*>) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
} |
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
Oops, something went wrong.