Changeset 350


Ignore:
Timestamp:
Mar 12, 2011 12:48:04 AM (14 years ago)
Author:
jemian
Message:

move the next() method into TokenLog?

Location:
topdoc/src/TopDoc
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified topdoc/src/TopDoc/EpicsDatabase.py

    r348 r350  
    5050            self.filename = dbFilename
    5151            self.absolute_filename = os.path.abspath(dbFilename)
    52             self.buf = utilities.tokenizeTextFile(dbFilename)
     52            self.tokenLog, self.buf = utilities.tokenizeTextFile(dbFilename)
    5353            self._parse()
    5454
     
    124124        into the internal memory structure.
    125125        '''
     126        # p_tkn, tkn = self.tokenLog.next()
     127        # p_tkn, tkn = self.tokenLog.next(p_tkn)
    126128        if self.buf is not None:
    127129            pvDict = {}
  • TabularUnified topdoc/src/TopDoc/EpicsTemplate.py

    r343 r350  
    3737            self.filename = templateFilename
    3838            self.absolute_filename = os.path.abspath(templateFilename)
    39             self.buf = utilities.tokenizeTextFile(templateFilename)
     39            self.tokenLog, self.buf = utilities.tokenizeTextFile(templateFilename)
    4040            self._parse_()
    4141
     
    5454        return db.getFull(macros)
    5555
    56     def nextUsefulToken(self, ptr = -1):
    57         '''
    58         walk through the tokens and find the next actionable token
    59         @param ptr: current buffer pointer, integer [0 .. len(self.buf)-1]
    60         @return: tuple (ptr, self.buf[ptr]), where ptr points to an actionable token or (None, None)
    61         '''
    62         # TODO Should this be part of the TokenLog module?
    63         ptr += 1
    64         while ptr < len(self.buf):
    65             tkn = self.buf[ptr]
    66             if tkn['tokName'] not in ('COMMENT', 'NEWLINE', 'ENDMARKER'):
    67                 return ptr, tkn
    68             ptr += 1
    69         return None, None
    70 
    7156    def _parse_(self):
    7257        '''
    7358        walk through the tokens and find the databases, then macros
    7459        '''
    75         p_tkn, tkn = self.nextUsefulToken()
     60        p_tkn, tkn = self.tokenLog.next()
    7661        while p_tkn is not None:
    7762            if tkn['tokName'] == 'NAME' and tkn['tokStr'] == 'file':
    78                 p_tkn, tkn = self.nextUsefulToken(p_tkn)
     63                p_tkn, tkn = self.tokenLog.next(p_tkn)
    7964                dbFile = utilities.strip_quotes( tkn['tokStr'] )
    8065                #
     
    8368                # TODO macro expansion of dbFile
    8469                #
    85                 p_tkn, tkn = self.nextUsefulToken(p_tkn)
     70                p_tkn, tkn = self.tokenLog.next(p_tkn)
    8671                if tkn['tokStr'] != '{':
    8772                    raise Exception, "problem token: " + str(tkn)
    8873                else:
    89                     p_tkn, tkn = self.nextUsefulToken(p_tkn)
     74                    p_tkn, tkn = self.tokenLog.next(p_tkn)
    9075                    if tkn['tokStr'] == 'pattern':
    9176                        # get the macro names, then
     
    9883                        raise Exception, "problem token: " + str(tkn)
    9984                # start processing the macro set(s)
    100             p_tkn, tkn = self.nextUsefulToken(p_tkn)
     85            p_tkn, tkn = self.tokenLog.next(p_tkn)
    10186
    10287    def _gather_inline_macros_(self, dbFile, p_tkn):
     
    11398            buf = ""
    11499            while tkn['tokStr'] != '}':
    115                 p_tkn, tkn = self.nextUsefulToken(p_tkn)
     100                p_tkn, tkn = self.tokenLog.next(p_tkn)
    116101                s = tkn['tokStr']
    117102                if s == '=':
     
    126111            # TODO do something with db
    127112            print dbFile, macros
    128             p_tkn, tkn = self.nextUsefulToken(p_tkn)
     113            p_tkn, tkn = self.tokenLog.next(p_tkn)
    129114        return p_tkn, tkn
    130115
     
    139124        tkn = self.buf[p_tkn]
    140125        keyList = []
    141         p_tkn, tkn = self.nextUsefulToken(p_tkn)
     126        p_tkn, tkn = self.tokenLog.next(p_tkn)
    142127        if tkn['tokStr'] != '{':
    143128            raise Exception, "problem token: " + str(tkn)
    144129        else:
    145             p_tkn, tkn = self.nextUsefulToken(p_tkn)
     130            p_tkn, tkn = self.tokenLog.next(p_tkn)
    146131            # gather the macro keys in a list
    147132            while tkn['tokStr'] != '}':
     
    152137                if key != ',':
    153138                    keyList.append( key )
    154                 p_tkn, tkn = self.nextUsefulToken(p_tkn)
    155             p_tkn, tkn = self.nextUsefulToken(p_tkn)
     139                p_tkn, tkn = self.tokenLog.next(p_tkn)
     140            p_tkn, tkn = self.tokenLog.next(p_tkn)
    156141            # loop through each set of macro definitions
    157142            while tkn['tokStr'] == '{':
    158                 p_tkn, tkn = self.nextUsefulToken(p_tkn)
     143                p_tkn, tkn = self.tokenLog.next(p_tkn)
    159144                buf = ""
    160145                liszt = []
     
    169154                        buf += tkn['tokStr']
    170155                        lastend = tkn['end'][1]
    171                     p_tkn, tkn = self.nextUsefulToken(p_tkn)
     156                    p_tkn, tkn = self.tokenLog.next(p_tkn)
    172157                liszt.append( buf )
    173158                if len(keyList) != len(liszt):
     
    184169                # TODO do something with db
    185170                print dbFile, macros
    186                 p_tkn, tkn = self.nextUsefulToken(p_tkn)
     171                p_tkn, tkn = self.tokenLog.next(p_tkn)
    187172        return p_tkn, tkn
    188173
  • TabularUnified topdoc/src/TopDoc/TokenLog.py

    r259 r350  
    169169        return lines
    170170
     171    def next(self, ptr = -1):
     172        '''
     173        walk through the tokens and find the next actionable token
     174        @param ptr: current buffer pointer, integer [0 .. len(self.tokenList)-1]
     175        @return: tuple (ptr, self.tokenList[ptr]), where ptr points to an actionable token or (None, None)
     176        '''
     177        ptr += 1
     178        while ptr < len(self.tokenList):
     179            tkn = self.tokenList[ptr]
     180            if tkn['tokName'] not in ('COMMENT', 'NEWLINE', 'ENDMARKER'):
     181                return ptr, tkn
     182            ptr += 1
     183        return None, None
     184
    171185
    172186######################################################################
  • TabularUnified topdoc/src/TopDoc/utilities.py

    r338 r350  
    1616import re
    1717import TokenLog
    18 
    1918
    2019
     
    128127    '''
    129128    @param filename: string name of file to be read
    130     @return: structure from TokenLog.lineAnalysis()
     129    @return: tuple of (TokenLog object, structure from TokenLog.lineAnalysis())
    131130    '''
    132131    obj = TokenLog.TokenLog()
    133132    obj.processFile(filename)
    134     return obj.getTokenList()
     133    return obj, obj.getTokenList()
    135134
    136135
Note: See TracChangeset for help on using the changeset viewer.