Refactor Value and EvaluatorOutput models in order to get rid of optionals(?)

This commit is contained in:
2020-03-14 13:25:42 +01:00
parent d8744670ed
commit 5b03f55cd4
30 changed files with 60 additions and 78 deletions

View File

@@ -12,7 +12,7 @@ import io.smnp.type.model.Value
class CharAtMethod : Method(ofType(STRING),"charAt") {
override fun define(new: MethodDefinitionTool) {
new method simple(ofType(INT)) body { _, obj, (index) ->
Value.string((obj.value!! as String).getOrNull(index.value!! as Int)?.toString() ?: throw EvaluationException("Index '${index.value!!}' runs out of string bounds"))
Value.string((obj.value as String).getOrNull(index.value as Int)?.toString() ?: throw EvaluationException("Index '${index.value}' runs out of string bounds"))
}
}
}

View File

@@ -12,8 +12,8 @@ import io.smnp.type.model.Value
class ListAccessMethod : Method(ofType(LIST), "get") {
override fun define(new: MethodDefinitionTool) {
new method simple(ofType(INT)) body { _, value, (index) ->
val list = value.value!! as List<Value>
val i = index.value!! as Int
val list = value.value as List<Value>
val i = index.value as Int
if(i >= list.size) {
throw EvaluationException("Index '$i' runs out of array bounds")

View File

@@ -12,8 +12,8 @@ import io.smnp.type.model.Value
class MapAccessMethod : Method(ofType(MAP), "get") {
override fun define(new: MethodDefinitionTool) {
new method simple(allTypes()) body { _, obj, (key) ->
val map = (obj.value!! as Map<Value, Value>)
map[key] ?: throw EvaluationException("Key '${key.value!!}' not found")
val map = (obj.value as Map<Value, Value>)
map[key] ?: throw EvaluationException("Key '${key.value}' not found")
}
}
}