text stringlengths 0 828 |
|---|
''' |
returns enumerable of (prevstate, t) tuples |
this is super slow and needs to be sped up |
''' |
if dst in self._transitions_to: |
for t in self._transitions_to[dst]: |
for s in self._transitions_to[dst][t]: |
yield (s, t)" |
531,"def reltags(self, src, cache=None): |
''' |
returns all the tags that are relevant at this state |
cache should be a dictionary and it is updated |
by the function |
''' |
if not self._tag_assocs: |
return set() |
# fucking python and it's terrible support for recursion makes this |
# far more complicated than it needs to be |
if cache == None: |
cache = {} |
q = _otq() |
q.append(src) |
updateq = _otq() |
while q: |
i = q.popleft() |
if i in cache: |
continue |
cache[i] = set() |
for (s,t) in self.transitions_to(i): |
q.append(s) |
if self.is_tagged(t,s,i): |
cache[i].add((self.tag(t,s,i),s, i)) |
updateq.appendleft((i, s)) |
while updateq: |
i = updateq.popleft() |
cache[i[0]].update(cache[i[1]]) |
return cache[src]" |
532,"def _add_epsilon_states(self, stateset, gathered_epsilons): |
''' |
stateset is the list of initial states |
gathered_epsilons is a dictionary of (dst: src) epsilon dictionaries |
''' |
for i in list(stateset): |
if i not in gathered_epsilons: |
gathered_epsilons[i] = {} |
q = _otq() |
q.append(i) |
while q: |
s = q.popleft() |
for j in self._transitions.setdefault(s, {}).setdefault(NFA.EPSILON, set()): |
gathered_epsilons[i][j] = s if j not in gathered_epsilons[i] else self.choose(s, j) |
q.append(j) |
stateset.update(gathered_epsilons[i].keys())" |
533,"def _states_to_dfa_bytecode(self, states, \ |
tran=None, \ |
debug=False, \ |
compiled_states=None, \ |
gathered_epsilons=None, \ |
cached_transitions=None, \ |
cached_tcode=None, \ |
reltags_cache=None \ |
): |
'''returns the instruction pointer to the bytecode added''' |
pstates = copy.copy(states) |
if reltags_cache == None: |
reltags_cache = {} |
if cached_tcode == None: |
cached_tcode = {} |
if cached_transitions == None: |
cached_transitions = {} |
if gathered_epsilons == None: |
gathered_epsilons = {} |
self._add_epsilon_states(states, gathered_epsilons) |
if tran != None: |
states = self.nextstates(states, tran) |
self._add_epsilon_states(states, gathered_epsilons) |
if self._magic != None: |
states = states.union(self._magic(states)) |
tstates = tuple(states) |
# this is used so we only compile each stateset once |
if compiled_states == None: |
compiled_states = {} |
if tstates in compiled_states: |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.