299
299
The set typically but not necessarily corresponds to a version.
301
istack = [] # versions for which an insertion block is current
303
dset = set() # versions for which a deletion block is current
307
305
lineno = 0 # line of weave, 0-based
309
# TODO: Probably only need to put included revisions in the istack
311
# TODO: Could split this into two functions, one that updates
312
# the stack and the other that processes the results -- but
313
# I'm not sure it's really needed.
315
# TODO: In fact, I think we only need to store the *count* of
316
# active insertions and deletions, and we can maintain that by
317
# just by just counting as we go along.
319
308
WFE = WeaveFormatError
321
310
for l in self._l:
322
311
if isinstance(l, tuple):
323
isactive = None # recalculate
326
if istack and (istack[-1] >= v):
327
raise WFE("improperly nested insertions %d>=%d on line %d"
328
% (istack[-1], v, lineno))
313
if v in included: # only active blocks are interesting
315
assert v not in istack
332
319
oldv = istack.pop()
334
raise WFE("unmatched close of insertion %d on line %d"
337
raise WFE("mismatched close of insertion %d!=%d on line %d"
342
raise WFE("repeated deletion marker for version %d on line %d"
346
raise WFE("version %d deletes own text on line %d"
321
isactive = istack and not dset
354
raise WFE("unmatched close of deletion %d on line %d"
357
raise WFE("invalid processing instruction %r on line %d"
330
isactive = istack and not dset
360
332
assert isinstance(l, basestring)
362
raise WFE("literal at top level on line %d"
365
isactive = (istack[-1] in included) \
366
and not included.intersection(dset)
369
334
yield origin, lineno, l
433
398
"got %s, expected %s"
434
399
% (version, hd, expected))
401
# TODO: check insertions are properly nested, that there are
402
# no lines outside of insertion blocks, that deletions are
403
# properly paired, etc.
438
407
def merge(self, merge_versions):