Esempio n. 1
0
class HybridEngine(BaseMatchEngine):
    def __init__(self, parser_state, graph):
        super(HybridEngine, self).__init__(parser_state, graph)
        self.__simple = SimpleEngine(parser_state, graph)
        self.__cached_complex = None

    def run(self, stream, pos=0, search=False):

        try:
            groups = self.__simple.run(stream,
                                       pos,
                                       search,
                                       fail_on_groups=False)
            return LazyGroups(
                groups, self.__simple.group_defined,
                lambda: self.__complex.run(stream, pos=pos, search=search))
        except UnsupportedOperation:
            return self.__complex.run(stream, pos=pos, search=search)

    @property
    def __complex(self):
        if self.__cached_complex is None:
            self.__cached_complex = ComplexEngine(self._parser_state,
                                                  self._graph)
        return self.__cached_complex
Esempio n. 2
0
 def __init__(self, parser_state, graph):
     super(HybridEngine, self).__init__(parser_state, graph)
     self.__simple = SimpleEngine(parser_state, graph)
     self.__cached_complex = None