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
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
def compileSequence(self): fsa = FSA.EMPTY_STRING_FSA while self.peekToken() and self.peekToken() not in (')', '|', '&'): fsa = FSA.concatenation(fsa, self.compileItem()) return fsa
def compileExpr(self): fsa = FSA.NULL_FSA while self.peekToken() and self.peekToken() != ')': fsa = FSA.union(fsa, self.compileConjunction()) self.skipTokens(['|']) return fsa