Ejemplo n.º 1
0
 def compileItem(self):
     c = self.readToken()
     startPosition = self.tokenStartIndex
     if c == '(':
         fsa = self.compileExpr()
         if self.readToken() != ')':
             raise ParseError("unmatched '('", startPosition)
     elif c == '~':
         fsa = FSA.complement(self.compileItem())
     else:
         positions = None
         if self.recordSourcePositions:
             positions = range(startPosition, self.index)
         fsa = FSA.singleton(c, arcMetadata=positions)
     while self.peekChar() and self.peekChar() in '?*+':
         c = self.readChar()
         if c == '*':
             fsa = FSA.closure(fsa)
         elif c == '?':
             fsa = FSA.union(fsa, FSA.EMPTY_STRING_FSA)
         elif c == '+':
             fsa = FSA.iteration(fsa)
         else:
             raise 'program error'
     return fsa
Ejemplo n.º 2
0
 def compileItem(self):
     startPosition = self.index
     c = self.readToken()
     if c == '(':
         fsa = self.compileExpr()
         if self.readToken() != ')':
             raise "missing ')'"
     elif c == '~':
         fsa = FSA.complement(self.compileItem())
     else:
         fsa = FSA.singleton(c, arcMetadata=self.recordSourcePositions and [startPosition])
     while self.peekChar() and self.peekChar() in '?*+':
         c = self.readChar()
         if c == '*':
             fsa = FSA.closure(fsa)
         elif c == '?':
             fsa = FSA.union(fsa, FSA.EMPTY_STRING_FSA)
         elif c == '+':
             fsa = FSA.iteration(fsa)
         else:
             raise 'program error'
     return fsa
Ejemplo n.º 3
0
 def compileItem(self):
     startPosition = self.index
     c = self.readToken()
     if c == '(':
         fsa = self.compileExpr()
         if self.readToken() != ')':
             raise "missing ')'"
     elif c == '~':
         fsa = FSA.complement(self.compileItem())
     else:
         fsa = FSA.singleton(c,
                             arcMetadata=self.recordSourcePositions
                             and [startPosition])
     while self.peekChar() and self.peekChar() in '?*+':
         c = self.readChar()
         if c == '*':
             fsa = FSA.closure(fsa)
         elif c == '?':
             fsa = FSA.union(fsa, FSA.EMPTY_STRING_FSA)
         elif c == '+':
             fsa = FSA.iteration(fsa)
         else:
             raise 'program error'
     return fsa