Allow to use types as keys in maps
This commit is contained in:
@@ -5,6 +5,7 @@ from smnp.ast.node.iterable import abstractIterableParser
|
|||||||
from smnp.ast.node.none import NoneNode
|
from smnp.ast.node.none import NoneNode
|
||||||
from smnp.ast.node.note import NoteLiteralNode
|
from smnp.ast.node.note import NoteLiteralNode
|
||||||
from smnp.ast.node.string import StringLiteralNode
|
from smnp.ast.node.string import StringLiteralNode
|
||||||
|
from smnp.ast.node.type import TypeNode
|
||||||
from smnp.ast.parser import Parser
|
from smnp.ast.parser import Parser
|
||||||
from smnp.token.type import TokenType
|
from smnp.token.type import TokenType
|
||||||
|
|
||||||
@@ -56,4 +57,5 @@ class MapNode(AccessNode):
|
|||||||
IntegerLiteralNode._literalParser(),
|
IntegerLiteralNode._literalParser(),
|
||||||
StringLiteralNode._literalParser(),
|
StringLiteralNode._literalParser(),
|
||||||
NoteLiteralNode._literalParser(),
|
NoteLiteralNode._literalParser(),
|
||||||
|
TypeNode.parse
|
||||||
)
|
)
|
||||||
@@ -12,7 +12,7 @@ def _function1(env, list, index):
|
|||||||
raise RuntimeException(f"Attempt to access item which is outside the list", None)
|
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))
|
_signature2 = signature(ofType(Type.MAP), ofTypes(Type.INTEGER, Type.STRING, Type.NOTE, Type.TYPE))
|
||||||
def _function2(env, map, key):
|
def _function2(env, map, key):
|
||||||
try:
|
try:
|
||||||
return map.value[key]
|
return map.value[key]
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from smnp.type.model import Type
|
|||||||
from smnp.type.signature.matcher.list import listOfMatchers, listMatches
|
from smnp.type.signature.matcher.list import listOfMatchers, listMatches
|
||||||
from smnp.type.signature.matcher.type import allTypes, ofTypes
|
from smnp.type.signature.matcher.type import allTypes, ofTypes
|
||||||
|
|
||||||
_signature1 = varargSignature(listMatches(ofTypes(Type.INTEGER, Type.STRING, Type.NOTE), allTypes()))
|
_signature1 = varargSignature(listMatches(ofTypes(Type.INTEGER, Type.STRING, Type.NOTE, Type.TYPE), allTypes()))
|
||||||
def _function1(env, vararg):
|
def _function1(env, vararg):
|
||||||
map = {}
|
map = {}
|
||||||
for entry in vararg:
|
for entry in vararg:
|
||||||
@@ -14,7 +14,7 @@ def _function1(env, vararg):
|
|||||||
return Type.map(map)
|
return Type.map(map)
|
||||||
|
|
||||||
|
|
||||||
_signature2 = signature(listOfMatchers(listMatches(ofTypes(Type.INTEGER, Type.STRING, Type.NOTE), allTypes())))
|
_signature2 = signature(listOfMatchers(listMatches(ofTypes(Type.INTEGER, Type.STRING, Type.NOTE, Type.TYPE), allTypes())))
|
||||||
def _function2(env, list):
|
def _function2(env, list):
|
||||||
map = {}
|
map = {}
|
||||||
for entry in list.value:
|
for entry in list.value:
|
||||||
|
|||||||
Reference in New Issue
Block a user