@@ -9,38 +9,46 @@ class ExprException(Exception):
99 pass
1010
1111
12- class OperationNotFoundException (Exception ):
12+ class OperationNotFoundException (ExprException ):
1313
1414 def __init__ (self , operation , expression ):
15- Exception .__init__ (self ,
16- "[EXPR_EXCEPTION] An invalid operation was found. "
17- "Operation: {0} - Expression: {0}"
18- .format (expression ))
15+ ExprException .__init__ (self ,
16+ "[EXPR_EXCEPTION] An invalid operation was found. "
17+ "Operation: {0} - Expression: {0}"
18+ .format (expression ))
1919
2020
21- class RootNotFoundExprException (Exception ):
21+ class RootNotFoundExprException (ExprException ):
2222
2323 def __init__ (self , expression ):
24- Exception .__init__ (self ,
25- "[EXPR_EXCEPTION] Root node was not found. Expression: {0}"
26- .format (expression ))
24+ ExprException .__init__ (self ,
25+ "[EXPR_EXCEPTION] Root node was not found. Expression: {0}"
26+ .format (expression ))
2727
28+ class TrailingTrashExprException (ExprException ):
29+
30+ def __init__ (self , expression ):
31+ ExprException .__init__ (self ,
32+ "[EXPR_EXCEPTION] The expression must end with a round bracket ')'. "
33+ "Expression: {0}"
34+ .format (expression ))
2835
29- class NotBalancedParanthesisException (Exception ):
36+
37+ class NotBalancedParanthesisException (ExprException ):
3038
3139 def __init__ (self , expression ):
32- Exception .__init__ (self ,
33- "[EXPR_EXCEPTION] Parenthesis in expression are not okay. Expression: {0}"
34- .format (expression ))
40+ ExprException .__init__ (self ,
41+ "[EXPR_EXCEPTION] Parenthesis in expression are not okay. Expression: {0}"
42+ .format (expression ))
3543
3644
37- class OperationArgumentsAmountException (Exception ):
45+ class OperationArgumentsAmountException (ExprException ):
3846
3947 def __init__ (self , expression ):
40- Exception .__init__ (self ,
41- "[EXPR_EXCEPTION] The amount of arguments processed by "
42- "the operations is not correct . Expression: {0}"
43- .format (expression ))
48+ ExprException .__init__ (self ,
49+ "[EXPR_EXCEPTION] The amount of arguments processed by "
50+ "the operations is not correct . Expression: {0}"
51+ .format (expression ))
4452
4553
4654class LispTreeExpr (object ):
@@ -92,9 +100,12 @@ def check_expression(expression):
92100 if counter != 0 :
93101 raise NotBalancedParanthesisException (expression )
94102
103+ # Check the expression to finish with a )
104+ if expression [- 1 ] != ')' :
105+ raise TrailingTrashExprException (expression )
106+
95107 # Now the expression is correct. Check the amount of arguments to be correct
96108 def check_operands (expr ):
97- print "Init - Expression: {0}" .format (expr )
98109 op_string = expr [1 :expr .find (' ' )]
99110 expr_op = None
100111 try :
0 commit comments