Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions asteroid/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,31 +63,33 @@ def __init__(self, value):
self.value = value

def __str__(self):
return(repr(self.value))
return(str(self.value))

#########################################################################
class PatternMatchFailed(Exception):
def __init__(self, value):
self.value = "pattern match failed: " + value

def __str__(self):
return(repr(self.value))
return(self.value)

#########################################################################
class NonLinearPatternError(Exception):
def __init__(self, value):
self.value = "non-linear pattern error: " + value

def __str__(self):
return(repr(self.value))
return(self.value)

#########################################################################
class ExpectationError(Exception):
def __init__(self, found, expected):
self.found_EOF = (found == 'EOF')
self.value = "expected {} found {}.".format(str(expected), str(found))

def __str__(self):
return(repr(self.value))
return(self.value)

##############################################################################################
# *** Part of the Redundant Pattern Detector ***
#
Expand Down
29 changes: 4 additions & 25 deletions asteroid/interp.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def interp(input_stream,
if symtab_dump:
state.symbol_table.dump()

# Note: all exceptions generated by Asteroid should go through the handler
# for 'Exception' unless the exception needs special handling like
# 'ThrowValue' or 'ReturnValue' etc.
except ThrowValue as throw_val:
# handle exceptions using the standard Error constructor
module, lineno = state.lineinfo
Expand All @@ -96,36 +99,12 @@ def interp(input_stream,
if not exceptions:
sys.exit(1)

except RedundantPatternFound as e:
print("Error: {}".format(e))
# needed for REPL
if not exceptions:
sys.exit(1)

except NonLinearPatternError as e:
print("Error: {}".format(e))
# needed for REPL
if not exceptions:
sys.exit(1)

except KeyboardInterrupt as e:
print("Error: keyboard interrupt")
# needed for REPL
if not exceptions:
sys.exit(1)

# Expectation Error is used by the REPL, so, like exceptions,
# we re throw it
except ExpectationError as e:
if exceptions:
raise e
else:
module, lineno = state.lineinfo
print("Error: {}: {}: {}".format(module, lineno, e.value))
# needed for REPL
if not exceptions:
sys.exit(1)

except Exception as e:
if exceptions: # rethrow the exception so that you can see the full backtrace
if symtab_dump:
Expand All @@ -138,7 +117,7 @@ def interp(input_stream,
if not exceptions:
sys.exit(1)

except BaseException as e:
except BaseException as e:
print("Error: {}".format(e))
# needed for REPL
if not exceptions:
Expand Down
2 changes: 1 addition & 1 deletion asteroid/walk.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def check_repeated_symbols( unifiers ):

elif sym in symbols: # We have found a non-linear pattern
raise NonLinearPatternError(
"multiple instances of {} found within a pattern.".format(sym))
"multiple instances of '{}' found within pattern.".format(sym))

else: # Else we have never seen this before so we record it.
symbols[sym] = term
Expand Down