Esempio n. 1
0
 def _min_span(self, S, tracer, visited):
     s = S[-1]
     if type(s) == list:
         s = s[0]
     selection = tracer.select(s)
     if FIN in selection:
         return S
     else:
         T = []
         for t in selection:
             if self._has_fixed_content(t):
                 T.append(t)
             elif is_keyword(t):
                 T.append(t)
         if len(T):
             minR = [0]*10
             minT = None
             for t in T:
                 if t not in visited:
                     V = set([t])
                     V.update(visited)
                     R = self._min_span(S+[t], tracer.clone(), V)
                     if R and len(R)<len(minR):
                         minR = R
                         minT = t
             if minT:
                 S.append(minT)
                 return minR
     return []
Esempio n. 2
0
 def _min_span(self, S, tracer, visited):
     s = S[-1]
     if type(s) == list:
         s = s[0]
     selection = tracer.select(s)
     if FIN in selection:
         return S
     else:
         T = []
         for t in selection:
             if self._has_fixed_content(t):
                 T.append(t)
             elif is_keyword(t):
                 T.append(t)
         if len(T):
             minR = [0] * 10
             minT = None
             for t in T:
                 if t not in visited:
                     V = set([t])
                     V.update(visited)
                     R = self._min_span(S + [t], tracer.clone(), V)
                     if R and len(R) < len(minR):
                         minR = R
                         minT = t
             if minT:
                 S.append(minT)
                 return minR
     return []
Esempio n. 3
0
    def _create_simple_segments(self):
        for r in self.langlet.parse_nfa.reachables:
            tracer = NFATracerUnexpanded(self.langlet.parse_nfa)
            prefix = []

            r1 = r
            while True:
                selection = tracer.select(r1)
                if len(selection) == 1 and is_keyword(selection[0]):
                    prefix.append(selection[0])
                    r1 = selection[0]
                else:
                    break

            nodes = []
            for s in selection:
                if s is FIN:
                    continue
                S = []
                S.append(s)
                R = self._min_span(S, tracer.clone(), set())
                if R:
                    nodes.append(prefix+R)
            self.simple_segments[r] = nodes
Esempio n. 4
0
    def _create_simple_segments(self):
        for r in self.langlet.parse_nfa.reachables:
            tracer = NFATracerUnexpanded(self.langlet.parse_nfa)
            prefix = []

            r1 = r
            while True:
                selection = tracer.select(r1)
                if len(selection) == 1 and is_keyword(selection[0]):
                    prefix.append(selection[0])
                    r1 = selection[0]
                else:
                    break

            nodes = []
            for s in selection:
                if s is FIN:
                    continue
                S = []
                S.append(s)
                R = self._min_span(S, tracer.clone(), set())
                if R:
                    nodes.append(prefix + R)
            self.simple_segments[r] = nodes