text
stringlengths
0
828
return compiled_states[tstates]
# grab the ip from our codeblock
ip = self._bytecode.newblock(tstates)
compiled_states[tstates] = ip
# TODO
# epsilon transitions are never 'taken' so we need
# to insert any ltagv/utagv instructions required
# for all epsilon transitions
# gathered_epsilons[state] holds a dictionary of dst: src mappings, so we can use that data
if self.do_tags:
tags = set()
rtags = set()
for ts in pstates:
for dst in gathered_epsilons[ts]:
rtags.update(self.reltags(dst, reltags_cache))
src = gathered_epsilons[ts][dst]
if self.is_tagged(NFA.EPSILON, src, dst):
tags.add((self.tag(NFA.EPSILON, src, dst), dst))
self._write_transition_code(tags, rtags, ip)
# run any defined state hooks
for s in tstates:
if s in self._state_hooks:
ip.append(VM.PyCode(self._state_hooks[s]))
# do a multi-match for any final states
finals = self._final_states.intersection(states)
if len(finals) > 0:
ip.append(VM.MultiMatch(finals))
# do any interupts required
interupts = self._interupt_states.intersection(states)
if len(interupts) > 0:
ip.append(VM.MultiInterupt(interupts))
# consume a character
ip.append(VM.Consume())
ts = self.transitions(states, cached_transitions)
if debug:
print 'compiling bytecode for stateset:\n\t%s\n\t0x%x: %s' % (states,ip,(defaults,ts))
def mkbytecode(t):
return lambda: self._transitions_to_dfa_bytecode(states, t, cached_tcode, debug=debug, compiled_states=compiled_states, gathered_epsilons=gathered_epsilons, cached_transitions=cached_transitions, reltags_cache=reltags_cache)
# for any of the non-default states add a conditional jmp
for k in ts:
if k in (NFA.ANY, NFA.EPSILON):
continue
jmppoint = VM.DelayedArg(mkbytecode(k))
ip.append(VM.Compare(k))
ip.append(VM.CondJmp(jmppoint))
# jmp to default state if there is one, otherwise leave
defaults = self.nextstates(states, NFA.ANY)
if len(defaults) > 0:
jmppoint = VM.DelayedArg(mkbytecode(NFA.ANY))
ip.append(VM.Jmp(jmppoint))
else:
ip.append(VM.Leave())
# return the instruction pointer
return ip"
534,"def _add_training_data(self, src, dst, symbol):
""""""
Training_data is a dictionary from strings to lists.
- Each string (key) is an access string
- Each list (value) is a list of tuples (target_state, [symbols directed to that
state]). These represent that a transition exists from the state used as key to the first
part of the training_data to the dst state which is the first part of the tuple
with all the symbols in the list in the SECOND part of the tuple.
Args:
src (str): The source state
dst (str): The target state
symbol (str): The transition symbol
Returns:
None
""""""
src_data = self.training_data[src]
for (s, v) in src_data:
if s == dst:
v.append(symbol)
return
src_data.append((dst, [symbol]))"
535,"def is_closed(self):
""""""
_check if the observation table is closed.
Args:
None
Returns:
tuple (bool, str): True if the observation table is closed and false otherwise.
If the table is not closed the escaping string is returned.