1.1 --- a/micropython/common.py Sun Mar 11 01:49:53 2012 +0100
1.2 +++ b/micropython/common.py Mon Mar 26 23:24:38 2012 +0200
1.3 @@ -462,6 +462,43 @@
1.4 def __repr__(self):
1.5 return "AtLeast(%r)" % self.count
1.6
1.7 +class Location:
1.8 +
1.9 + """
1.10 + A special representation for locations which are to be compared to program
1.11 + objects.
1.12 + """
1.13 +
1.14 + def __init__(self, location):
1.15 + self.location = location
1.16 +
1.17 + def _op(self, other, op):
1.18 + if hasattr(other, "location"):
1.19 + return op(self.location, other.location)
1.20 + else:
1.21 + raise NotImplemented
1.22 +
1.23 + def __eq__(self, other):
1.24 + return self._op(other, operator.eq)
1.25 +
1.26 + def __ne__(self, other):
1.27 + return self._op(other, operator.ne)
1.28 +
1.29 + def __lt__(self, other):
1.30 + return self._op(other, operator.lt)
1.31 +
1.32 + def __le__(self, other):
1.33 + return self._op(other, operator.le)
1.34 +
1.35 + def __gt__(self, other):
1.36 + return self._op(other, operator.gt)
1.37 +
1.38 + def __ge__(self, other):
1.39 + return self._op(other, operator.ge)
1.40 +
1.41 + def __repr__(self):
1.42 + return "Location(%r)" % self.location
1.43 +
1.44 # Useful data.
1.45
1.46 operator_functions = {