Refactor Value and EvaluatorOutput models in order to get rid of optionals(?)
This commit is contained in:
@@ -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"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user