Enable stringification on all Values
This commit is contained in:
@@ -41,16 +41,16 @@ object ActualSignatureFormatter {
|
||||
return "list<${output.toSet().joinToString()}>"
|
||||
}
|
||||
|
||||
private fun mapTypes(map: Map<Value, Value>, output: MutableMap<Value, String> = mutableMapOf()): String {
|
||||
private fun mapTypes(map: Map<Value, Value>, output: MutableMap<String, String> = mutableMapOf()): String {
|
||||
for ((k, v) in map) {
|
||||
output[k] = when (v.type) {
|
||||
output[k.type.toString()] = when (v.type) {
|
||||
DataType.LIST -> listTypes(
|
||||
v.value as List<Value>
|
||||
)
|
||||
DataType.MAP -> mapTypes(
|
||||
v.value as Map<Value, Value>
|
||||
)
|
||||
else -> v.type.name.toLowerCase()
|
||||
else -> v.type.toString()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
package io.smnp.type.enumeration
|
||||
|
||||
import io.smnp.data.entity.Note
|
||||
import io.smnp.type.model.Value
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
enum class DataType(val kotlinType: KClass<out Any>?) {
|
||||
INT(Int::class),
|
||||
FLOAT(Float::class),
|
||||
STRING(String::class),
|
||||
LIST(List::class),
|
||||
MAP(Map::class),
|
||||
NOTE(Note::class),
|
||||
BOOL(Boolean::class),
|
||||
TYPE(DataType::class),
|
||||
VOID(null);
|
||||
enum class DataType(val kotlinType: KClass<out Any>?, val stringifier: (Any?) -> String) {
|
||||
INT(Int::class, { it.toString() }),
|
||||
FLOAT(Float::class, { it.toString() }),
|
||||
STRING(String::class, { it.toString() }),
|
||||
LIST(List::class, { "[" + (it as List<Value>).joinToString { v -> v.stringify() } + "]" }),
|
||||
MAP(Map::class, { "{" + (it as Map<Value, Value>).map { (k, v) -> "${k.stringify()} -> ${v.stringify()}" }.joinToString() + "}" }),
|
||||
NOTE(Note::class, { it.toString() }),
|
||||
BOOL(Boolean::class, { it.toString() }),
|
||||
TYPE(DataType::class, { it.toString() }),
|
||||
VOID(null, { "void" });
|
||||
|
||||
fun isInstance(value: Any?): Boolean {
|
||||
if(kotlinType == null) {
|
||||
|
||||
@@ -11,6 +11,10 @@ data class Value(val type: DataType, val value: Any?, val properties: Map<String
|
||||
}
|
||||
}
|
||||
|
||||
fun stringify() = type.stringifier(value)
|
||||
|
||||
fun typeName() = type.toString()
|
||||
|
||||
override fun toString(): String {
|
||||
return "$type($value)"
|
||||
}
|
||||
|
||||
@@ -9,8 +9,7 @@ import io.smnp.type.model.Value
|
||||
class PrintlnFunction : Function("println") {
|
||||
override fun define(new: FunctionDefinitionTool) {
|
||||
new function vararg(allTypes()) body { _, (vararg) ->
|
||||
// TODO: Implement equivalent of "toString()" method
|
||||
println((vararg.value!! as List<Value>).joinToString("") { it.value!!.toString() })
|
||||
println((vararg.value!! as List<Value>).joinToString("") { it.stringify() })
|
||||
Value.void()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user