from traceback import print_exc
from .parser import text_to_expression, ParseError, Symbol
from .utils.stack import stack_to_string
-from .library import NotAnIntError, StackUnderflowError
+from .utils.errors import (
+ NotAListError,
+ NotAnIntError,
+ StackUnderflowError,
+ )
class UnknownSymbolError(KeyError): pass
print('Not enough values on stack.')
except NotAnIntError:
print('Not an integer.')
+ except NotAListError:
+ print('Not a list.')
except:
print_exc()
print(stack_to_string(stack))
from .parser import text_to_expression, Symbol
from .utils import generated_library as genlib
+from .utils.errors import NotAnIntError, StackUnderflowError
from .utils.stack import (
concat,
expression_to_string,
)
-class NotAnIntError(Exception): pass
-class StackUnderflowError(Exception): pass
-
-
def FunctionWrapper(f):
'''Set name attribute.'''
if not f.__doc__:
(a, (b, stack)) = stack
except ValueError:
raise StackUnderflowError
- if not isinstance(a, int) or not isinstance(b, int):
+ if (not isinstance(a, int)
+ or not isinstance(b, int)
+ or isinstance(a, bool) # Because bools are ints in Python.
+ or isinstance(a, bool)
+ ):
raise NotAnIntError
result = f(b, a)
return (result, stack), expression, dictionary
--- /dev/null
+class NotAListError(Exception): pass
+class NotAnIntError(Exception): pass
+class StackUnderflowError(Exception): pass
+
+