Пример #1
0
 def _or_(self):
     nextChar = self.parser._next_for_plugin_
     match = self.parser._match_for_plugin_
     char = nextChar()
     stack = []
     while char != ']':
         node = self._range_()
         char = nextChar()
         if char == '&':
             match('&')
             match('&')
             another = self._range_()
             node = AndNode(node, another)
         stack.append(node)
         char = nextChar()
     match(']')
     orNode = OrNode(stack)
     # OR node can not be empty
     assert orNode.asts
     debug(orNode)
     return orNode
Пример #2
0
 def parse(self, regex):
     self._reset_()
     self._string_ = regex
     self._push_op_(('EOF', 'EOF'))
     while not self._done_():
         self._read_()
         if self._need_insert_concat_():
             self._rollback_()
             self._lookahead_ = 'concat', 'concat'
         cmp = self._compare_(self._peek_op_(), self._lookahead_)
         while cmp > 0:  # Pop until top of stack is less than the input
             op = self._pop_op_()
             debug('pop ', op)
             assert op[0] in RegexParser._OP_FUNCTIONS_
             RegexParser._OP_FUNCTIONS_[op[0]](self, op[1])
             cmp = self._compare_(self._peek_op_(), self._lookahead_)
         if cmp == 0:
             op = self._pop_op_()
             debug('pop ', op)
         else:
             self._push_op_(self._lookahead_)
             debug('push ', self._lookahead_)
     start = self._cleanup_()
     assert not self._operators_
     assert not self._operands_
     return NFAAutomaton(start)
Пример #3
0
 def _compare_(self, a, b):
     pTopOp = RegexParser._PRIORITY_[a[0]][0]
     pInputOp = RegexParser._PRIORITY_[b[0]][1]
     debug('cmp [', a[0], ',', b[0], ']=', pTopOp - pInputOp)
     return pTopOp - pInputOp
Пример #4
0
 def _plugin_set_(self):
     debug('processing set')
     regexSet = RegexSet(self)
     return 'char', SetNFAState(regexSet._set_())