def _check_node(self, node, tracer=None): nid = node[0] if tracer is None: tracer = NFATracerUnexpanded(self.langlet.parse_nfa) try: selection = tracer.select(nid) except NonSelectableError: self._error = (node, 0, []) return False for i, sub in enumerate(node[1:]): sub_nid = sub[0] if isinstance(sub, list): if sub_nid in selection: if is_symbol(sub_nid): rc = self._check_node(sub, tracer=NFATracerUnexpanded( self.langlet.parse_nfa)) if rc is False: if self._error: _, pos, _ = self._error if pos == 0: self._error = (node, i + 1, selection) return False selection = tracer.select(sub_nid) else: self._error = (node, i + 1, selection) return False if FIN not in selection: self._error = (node, len(node) + 1, selection) return False return True
def _check_node(self, node, tracer = None): nid = node[0] if tracer is None: tracer = NFATracerUnexpanded(self.langlet.parse_nfa) try: selection = tracer.select(nid) except NonSelectableError: self._error = (node, 0, []) return False for i, sub in enumerate(node[1:]): sub_nid = sub[0] if isinstance(sub, list): if sub_nid in selection: if is_symbol(sub_nid): rc = self._check_node(sub, tracer = NFATracerUnexpanded(self.langlet.parse_nfa)) if rc is False: if self._error: _, pos, _ = self._error if pos == 0: self._error = (node, i+1, selection) return False selection = tracer.select(sub_nid) else: self._error = (node, i+1, selection) return False if FIN not in selection: self._error = (node, len(node)+1, selection) return False return True
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
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