def getValueAccordingToType(value, type): try: if type.value == Type.STRING: return Type.string(value) if type.value == Type.INTEGER: return Type.integer(int(value)) if type.value == Type.BOOL: consumedChars, token = boolTokenizer(value, 0, 0) if consumedChars > 0: return Type.bool(token.value) return ValueError() if type.value == Type.NOTE: consumedChars, token = noteTokenizer(value, 0, 0) if consumedChars > 0: return Type.note(token.value) raise ValueError() raise RuntimeException( f"Type {type.value.name.lower()} is not supported", None) except ValueError: raise RuntimeException( f"Invalid value '{value}' for type {type.value.name.lower()}", None)
def evaluator(cls, node, environment): return Type.note(node.value)
def _function(env, note, octave, duration, dot): return Type.note(Note(note.value, octave.value, duration.value, dot.value))