Reformat evaluator #2 (exceptions)
This commit is contained in:
@@ -35,4 +35,5 @@ def parseNote(input, parent):
|
|||||||
|
|
||||||
input.ahead()
|
input.ahead()
|
||||||
return NoteLiteralNode(Note(notePitch, octave, duration, dot), parent, token.pos)
|
return NoteLiteralNode(Note(notePitch, octave, duration, dot), parent, token.pos)
|
||||||
return None
|
|
||||||
|
return None
|
||||||
|
|||||||
9
smnp/error/note.py
Normal file
9
smnp/error/note.py
Normal file
@@ -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"
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
from smnp.error.syntax import SyntaxException
|
from smnp.error.note import NoteException
|
||||||
|
|
||||||
|
|
||||||
class NotePitch(Enum):
|
class NotePitch(Enum):
|
||||||
@@ -37,18 +37,14 @@ class NotePitch(Enum):
|
|||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.__str__()
|
return self.__str__()
|
||||||
|
|
||||||
#@staticmethod
|
|
||||||
#def checkInterval(a, b):
|
|
||||||
#return a.value - b.value
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def toPitch(string): #TODO: token zamiast stringa, żeby można było wziąć pos
|
def toPitch(string):
|
||||||
try:
|
try:
|
||||||
return stringToPitch[string.lower()]
|
return stringToPitch[string.lower()]
|
||||||
except KeyError as e:
|
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 = {
|
stringToPitch = {
|
||||||
'c': NotePitch.C,
|
'c': NotePitch.C,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from smnp.ast.node.identifier import IdentifierNode
|
from smnp.ast.node.identifier import IdentifierNode
|
||||||
from smnp.ast.node.program import Program
|
from smnp.ast.node.program import Program
|
||||||
|
from smnp.error.base import SmnpException
|
||||||
from smnp.error.runtime import RuntimeException
|
from smnp.error.runtime import RuntimeException
|
||||||
from smnp.runtime.evaluators.list import evaluateList
|
from smnp.runtime.evaluators.list import evaluateList
|
||||||
from smnp.runtime.tools import flatListNode
|
from smnp.runtime.tools import flatListNode
|
||||||
@@ -27,9 +28,13 @@ def evaluateFunctionDefinition(definition, environment):
|
|||||||
|
|
||||||
|
|
||||||
def evaluateFunctionCall(functionCall, environment):
|
def evaluateFunctionCall(functionCall, environment):
|
||||||
functionName = functionCall.identifier.identifier
|
try:
|
||||||
arguments = evaluateList(functionCall.arguments, environment).value
|
functionName = functionCall.identifier.identifier
|
||||||
return environment.invokeFunction(functionName, arguments)
|
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):
|
# def evaluateFunctionCall(functionCall, environment):
|
||||||
|
|||||||
Reference in New Issue
Block a user