Customizing error messages.
This commit is contained in:
parent
810a6afdbb
commit
e417842923
|
|
@ -136,8 +136,8 @@ def interp(stack=(), dictionary=None):
|
|||
stack, _, dictionary = run(text, stack, dictionary)
|
||||
except UnknownSymbolError as sym:
|
||||
print('Unknown:', sym)
|
||||
except StackUnderflowError:
|
||||
print('Not enough values on stack.')
|
||||
except StackUnderflowError as e:
|
||||
print(e) # 'Not enough values on stack.'
|
||||
except NotAnIntError:
|
||||
print('Not an integer.')
|
||||
except NotAListError as e:
|
||||
|
|
|
|||
|
|
@ -158,7 +158,10 @@ def pop(stack):
|
|||
(a1 --)
|
||||
|
||||
"""
|
||||
(a1, s23) = stack
|
||||
try:
|
||||
(a1, s23) = stack
|
||||
except ValueError:
|
||||
raise StackUnderflowError('Cannot pop empty stack.')
|
||||
return s23
|
||||
|
||||
|
||||
|
|
@ -224,8 +227,17 @@ def rest(stack):
|
|||
([a1 ...0] -- [...0])
|
||||
|
||||
"""
|
||||
((a1, s0), s23) = stack
|
||||
return (s0, s23)
|
||||
try:
|
||||
s0, stack = stack
|
||||
except ValueError:
|
||||
raise StackUnderflowError
|
||||
if not isinstance(s0, tuple):
|
||||
raise NotAListError('Not a list.')
|
||||
try:
|
||||
_, s1 = s0
|
||||
except ValueError:
|
||||
raise StackUnderflowError('Cannot take rest of empty list.')
|
||||
return (s1, stack)
|
||||
|
||||
|
||||
def rolldown(stack):
|
||||
|
|
|
|||
Loading…
Reference in New Issue