Logo Search packages:      
Sourcecode: gadfly version File versions  Download package

def gadfly::kjParser::LexDictionary::Token (   self,
  String,
  StartPosition 
)

function to do same as __getitem__ above but looking _inside_ a
    string instead of at the whole string

    returns (token,skip) where token is one of
     ((KEYFLAG,name),name) or ((TERMFLAG,termname),value)
    and skip is the length of substring of string that matches thetoken

Definition at line 268 of file kjParser.py.

00268                                           :
        ''' function to do same as __getitem__ above but looking _inside_ a
            string instead of at the whole string

            returns (token,skip) where token is one of
             ((KEYFLAG,name),name) or ((TERMFLAG,termname),value)
            and skip is the length of substring of string that matches thetoken
        '''
        finished = 0 # dummy, exit should be nonlocal
        totalOffset = 0
        while not finished:
            # flag EOF if past end of string?
            if len(String) <= StartPosition:
                return (ENDOFFILETERM, 0)
            # skip whitespace
            whitespacefound = 0
            skip = RMATCH(WHITEREGEX,String, StartPosition)
            if skip > 0:
                StartPosition = StartPosition + skip
                totalOffset = totalOffset + skip
                whitespacefound = 1
            # try to find comment, keyword, term in that order:
            # looking for comment
            commentfound = 0
            for commentexpr in self.commentpatterns:
                offset = RMATCH(commentexpr,String,StartPosition)
                if offset != -1:
                    if offset<1:
                        info = DumpStringWindow(String,StartPosition)
                        raise LexTokenError, "zero length comment "+info
                    commentfound = 1
                    StartPosition = StartPosition + offset
                    totalOffset = totalOffset + offset
            # looking for a keyword
            keypair = self.keywordmap.hasPrefix(String,StartPosition,
                          self.punctuationlist)
            if keypair != 0:
                return ( keypair[0], keypair[1] + totalOffset)
            # looking for terminal
            for (regexpr, Flag, Function) in self.regexprlist:
                offset = RMATCH(regexpr,String,StartPosition)
                if offset != -1:
                    matchstring = String[StartPosition : offset+StartPosition]
                    if Function != None:
                        value = Function(matchstring)
                    else:
                        value = matchstring
                    return ((Flag, value) , offset + totalOffset)
            if not (commentfound or whitespacefound):
                info = DumpStringWindow(String,StartPosition)
                raise LexTokenError, "Lexical parse failure "+info

# alternate, experimental implementation

class lexdictionary:


Generated by  Doxygen 1.6.0   Back to index