~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to weave.py

  • Committer: Martin Pool
  • Date: 2005-06-28 09:03:46 UTC
  • mto: This revision was merged to the branch mainline in revision 852.
  • Revision ID: mbp@sourcefrog.net-20050628090346-d284566245828bb7
More constraints on structure of weave, and checks that they work

Show diffs side-by-side

added added

removed removed

Lines of Context:
207
207
 
208
208
        The set typically but not necessarily corresponds to a version.
209
209
        """
210
 
        stack = []
 
210
        istack = []
211
211
        isactive = False
212
212
        lineno = 0
213
213
        
215
215
            if isinstance(l, tuple):
216
216
                c, v = l
217
217
                if c == '{':
218
 
                    stack.append(l)
 
218
                    if istack:
 
219
                        assert istack[-1][1] < v, \
 
220
                               ("improperly nested insertions %d>=%d on line %d" 
 
221
                                % (istack[-1][1], v, lineno))
 
222
                    istack.append(l)
219
223
                    isactive = (v in included)
220
224
                elif c == '}':
221
 
                    oldc, oldv = stack.pop()
 
225
                    oldc, oldv = istack.pop()
222
226
                    assert oldc == '{'
223
227
                    assert oldv == v
224
 
                    isactive = stack and (stack[-1][1] in included)
 
228
                    isactive = istack and (istack[-1][1] in included)
225
229
                else:
226
230
                    raise ValueError("invalid processing instruction %r on line %d"
227
231
                                     % (l, lineno))
228
232
            else:
229
233
                assert isinstance(l, basestring)
230
 
                if not stack:
 
234
                if not istack:
231
235
                    raise ValueError("literal at top level on line %d"
232
236
                                     % lineno)
233
237
                if isactive:
234
 
                    origin = stack[-1][1]
 
238
                    origin = istack[-1][1]
235
239
                    yield origin, lineno, l
236
240
            lineno += 1
237
241
 
238
 
        if stack:
239
 
            raise ValueError("unclosed blocks at end of weave",
240
 
                             stack)
 
242
        if istack:
 
243
            raise ValueError("unclosed insertion blocks at end of weave",
 
244
                             istack)
241
245
 
242
246
 
243
247
    def getiter(self, index):