1.1 --- a/micropython/table.py Mon Mar 31 00:54:03 2008 +0200
1.2 +++ b/micropython/table.py Sun Apr 06 02:53:43 2008 +0200
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 Preparation of run-time attribute lookup tables.
1.6
1.7 -Copyright (C) 2007 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2007, 2008 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU General Public License as published by the Free Software
1.12 @@ -19,16 +19,20 @@
1.13 this program. If not, see <http://www.gnu.org/licenses/>.
1.14 """
1.15
1.16 +from micropython.common import *
1.17 try:
1.18 set
1.19 except NameError:
1.20 from sets import Set as set
1.21
1.22 +class TableError(ProcessingError): pass
1.23 +
1.24 class List:
1.25
1.26 """
1.27 A displaced list containing attribute details and an index mapping names to
1.28 - offsets in the list.
1.29 + offsets in the list. This is the optimised form of the table initially
1.30 + constructed to record object attributes.
1.31 """
1.32
1.33 def __init__(self, names):
1.34 @@ -135,6 +139,8 @@
1.35
1.36 "A lookup table."
1.37
1.38 + TableError = TableError
1.39 +
1.40 def __init__(self):
1.41 self.attributes = set()
1.42 self.table = {}
1.43 @@ -171,13 +177,19 @@
1.44
1.45 "Return the code of the given 'name'."
1.46
1.47 - return self.object_names().index(name)
1.48 + try:
1.49 + return self.object_names().index(name)
1.50 + except ValueError:
1.51 + raise TableError, "Name %r is not registered as an object in the table." % name
1.52
1.53 def get_index(self, name):
1.54
1.55 "Return the index of the given 'name'."
1.56
1.57 - return self.attribute_names().index(name)
1.58 + try:
1.59 + return self.attribute_names().index(name)
1.60 + except ValueError:
1.61 + raise TableError, "Name %r is not registered as an attribute in the table." % name
1.62
1.63 def as_matrix(self):
1.64