RecPos.py
class RecPos:
def __init__(self, name, line_nr = 0):
self.name = name
self.line_nr = line_nr
def __str__(self):
return 'recipe "%s" line %d' % (self.name, self.line_nr)
def rpcopy(rpstack, line_nr):
"""Make a shallow copy of the stack of RecPos objects and make a copy of
the item on the top to change its line_nr to "line_nr"."""
r = rpstack[:]
if len(r) > 0:
r[-1] = RecPos(r[-1].name, line_nr)
else:
r = [ RecPos("unknown", line_nr) ]
return r
def rpdeepcopy(rpstack, line_nr):
"""Make a deep copy of the stack of RecPos objects and for the item on the
top change its line_nr to "line_nr"."""
r = rpstack[:]
for i in range(0, len(r) - 1):
r[i] = RecPos(r[i].name, r[i].line_nr)
r[-1] = RecPos(r[-1].name, line_nr)
return r