diff --git a/smnp/ast/parsers/note.py b/smnp/ast/parsers/note.py index 8933867..e48a89b 100644 --- a/smnp/ast/parsers/note.py +++ b/smnp/ast/parsers/note.py @@ -35,4 +35,5 @@ def parseNote(input, parent): input.ahead() return NoteLiteralNode(Note(notePitch, octave, duration, dot), parent, token.pos) - return None \ No newline at end of file + + return None diff --git a/smnp/error/note.py b/smnp/error/note.py new file mode 100644 index 0000000..b5b0963 --- /dev/null +++ b/smnp/error/note.py @@ -0,0 +1,9 @@ +from smnp.error.base import SmnpException + + +class NoteException(SmnpException): + def __init__(self, msg): + super().__init__(msg) + + def _title(self): + return "Note Error" \ No newline at end of file diff --git a/smnp/note/pitch.py b/smnp/note/pitch.py index 333b5e8..025aec0 100644 --- a/smnp/note/pitch.py +++ b/smnp/note/pitch.py @@ -1,6 +1,6 @@ from enum import Enum -from smnp.error.syntax import SyntaxException +from smnp.error.note import NoteException class NotePitch(Enum): @@ -37,18 +37,14 @@ class NotePitch(Enum): return self.name def __repr__(self): - return self.__str__() - - #@staticmethod - #def checkInterval(a, b): - #return a.value - b.value + return self.__str__() @staticmethod - def toPitch(string): #TODO: token zamiast stringa, żeby można było wziąć pos + def toPitch(string): try: return stringToPitch[string.lower()] except KeyError as e: - raise SyntaxException(f"Note '{string}' does not exist") #TODO jakis inny exception + raise NoteException(f"Note '{string}' does not exist") stringToPitch = { 'c': NotePitch.C, diff --git a/smnp/runtime/evaluators/function.py b/smnp/runtime/evaluators/function.py index 2ff6ab3..1009351 100644 --- a/smnp/runtime/evaluators/function.py +++ b/smnp/runtime/evaluators/function.py @@ -1,5 +1,6 @@ from smnp.ast.node.identifier import IdentifierNode from smnp.ast.node.program import Program +from smnp.error.base import SmnpException from smnp.error.runtime import RuntimeException from smnp.runtime.evaluators.list import evaluateList from smnp.runtime.tools import flatListNode @@ -27,9 +28,13 @@ def evaluateFunctionDefinition(definition, environment): def evaluateFunctionCall(functionCall, environment): - functionName = functionCall.identifier.identifier - arguments = evaluateList(functionCall.arguments, environment).value - return environment.invokeFunction(functionName, arguments) + try: + functionName = functionCall.identifier.identifier + arguments = evaluateList(functionCall.arguments, environment).value + return environment.invokeFunction(functionName, arguments) + except SmnpException as e: + e.pos = functionCall.pos + raise e # def evaluateFunctionCall(functionCall, environment):