Esempio n. 1
0
 def compileConjunction(self):
     fsa = None
     while self.peekToken() and self.peekToken() not in (')', '|'):
         sequence = self.compileSequence()
         fsa = fsa and FSA.intersection(fsa, sequence) or sequence
         self.skipTokens(['&'])
     return fsa
Esempio n. 2
0
 def compileConjunction(self):
     fsa = None
     while self.peekToken() and self.peekToken() not in (')', '|'):
         sequence = self.compileSequence()
         fsa = fsa and FSA.intersection(fsa, sequence) or sequence
         self.skipTokens(['&'])
     return fsa
Esempio n. 3
0
 def compileItem(self):
     startPosition = self.index
     c = self.readToken()
     if c == '(':
         fsa = self.compileExpr()
         if self.readToken() != ')':
             raise ValueError("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 ValueError('program error')
     return fsa
Esempio n. 4
0
 def compileItem(self):
     startPosition = self.index
     c = self.readToken()
     if c == '(':
         fsa = self.compileExpr()
         if self.readToken() != ')':
             raise ValueError("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 ValueError('program error')
     return fsa
Esempio n. 5
0
 def compileSequence(self):
     fsa = FSA.EMPTY_STRING_FSA
     while self.peekToken() and self.peekToken() not in (')', '|', '&'):
         fsa = FSA.concatenation(fsa, self.compileItem())
     return fsa
Esempio n. 6
0
 def compileExpr(self):
     fsa = FSA.NULL_FSA
     while self.peekToken() and self.peekToken() != ')':
         fsa = FSA.union(fsa, self.compileConjunction())
         self.skipTokens(['|'])
     return fsa
Esempio n. 7
0
 def compileSequence(self):
     fsa = FSA.EMPTY_STRING_FSA
     while self.peekToken() and self.peekToken() not in (')', '|', '&'):
         fsa = FSA.concatenation(fsa, self.compileItem())
     return fsa
Esempio n. 8
0
 def compileExpr(self):
     fsa = FSA.NULL_FSA
     while self.peekToken() and self.peekToken() != ')':
         fsa = FSA.union(fsa, self.compileConjunction())
         self.skipTokens(['|'])
     return fsa