Changeset 3053


Ignore:
Timestamp:
11/08/05 17:19:36 (8 years ago)
Author:
moschny
Message:

Move pattern matching into a generator.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trac/trunk/wiki-macros/TracNav.py

    r3052 r3053  
    1 # -*- coding: iso8859-1 -*- 
     1# -*- coding: utf-8 -*- 
    22""" 
    33= TracNav: The navigation bar for Trac = 
     
    8989 
    9090 
    91 def parseToc(tocText): 
    92     stack = [] 
     91def getTocEntry(tocText): 
    9392    nextPos = 0 
    9493    while 1: 
     
    9695        if not match: 
    9796            # env.log.debug("No more matches") 
    98             break 
     97            return 
    9998 
    10099        indent = len(match.group('indent')) 
     
    110109        # else: 
    111110        #     env.log.debug(label + ": " + link) 
     111     
     112        yield indent, link, label 
     113        nextPos = match.end() 
     114 
     115 
     116def parseToc(tocText): 
     117    stack = [] 
     118    for indent, link, label in getTocEntry(tocText): 
    112119 
    113120        if len(stack) == 0: 
     
    130137            list.append((link, label, None)) 
    131138                 
    132         nextPos = match.end() 
    133  
    134139    while len(stack) > 1: 
    135140        (_, list) = stack.pop() 
Note: See TracChangeset for help on using the changeset viewer.