Create new type: map (dictionary) with all support for it

This commit is contained in:
Bartłomiej Pluta
2019-07-09 00:11:39 +02:00
parent a3dfae73f1
commit d23e7a1276
17 changed files with 150 additions and 29 deletions

View File

@@ -0,0 +1,25 @@
from smnp.error.runtime import RuntimeException
from smnp.library.model import CombinedFunction, Function
from smnp.library.signature import signature, ofType, ofTypes
from smnp.type.model import Type
_signature1 = signature(ofType(Type.LIST), ofType(Type.INTEGER))
def _function1(env, list, index):
try:
return list.value[index]
except KeyError:
raise RuntimeException(f"Attempt to access item which is outside the list", None)
_signature2 = signature(ofType(Type.MAP), ofTypes(Type.INTEGER, Type.STRING, Type.NOTE))
def _function2(env, map, key):
try:
return map.value[key]
except KeyError:
raise RuntimeException(f"Attempt to access unknown key in map", None)
function = CombinedFunction(
'get',
Function(_signature1, _function1),
Function(_signature2, _function2)
)