ó S‚ ?c@sddlZddlZddlmZddlmZddlmZej Zdd d„ƒYZdd d„ƒYZ d d d „ƒYZ dS(iÿÿÿÿN(tmaxint(t TupleType(t TransitionMaptMachinecBs_eZdZd ZdZd Zd„Zd„Zd„Z d„Z d„Z d„Z d„Z RS( s1A collection of Nodes representing an NFA or DFA.icCsg|_i|_dS(N(tstatestinitial_states(tself((s7/usr/lib/python2.7/site-packages/Pyrex/Plex/Machines.pyt__init__s cCs"x|jD]}|jƒq WdS(N(Rtdestroy(Rtstate((s7/usr/lib/python2.7/site-packages/Pyrex/Plex/Machines.pyt__del__scCs<tƒ}|j}|d|_||_|jj|ƒ|S(s-Add a new state to the machine and return it.i(tNodetnext_state_numbertnumberRtappend(Rtstn((s7/usr/lib/python2.7/site-packages/Pyrex/Plex/Machines.pyt new_state!s     cCs |jƒ}|j||ƒ|S(N(Rtmake_initial_state(RtnameR ((s7/usr/lib/python2.7/site-packages/Pyrex/Plex/Machines.pytnew_initial_state*s cCs||j|s         t FastMachinecBs»eZdZdZdZdZidd6dd6dd6dd6dd6Zdd„Zd„Z dd „Z d „Z d „Z d „Z d „Zd„Zd„Zd„Zd„Zd„ZRS(s^ FastMachine is a deterministic machine represented in a way that allows fast scanning. iR&tbolteolteoftelsec Csþi|_}g|_|rúi|_}x'|jD]}|jƒ}||||jjƒD]-\}}|jdt|ƒ|dfƒq*Wx!|jD]}|j||ƒqeWdS(NsPlex.FastMachine: s Initial states: s %s: %s R (RRRtreprRt dump_state(RRRR ((s7/usr/lib/python2.7/site-packages/Pyrex/Plex/Machines.pyRÃs   %cCs_ddl}|jd|dƒ|j||ƒ|d}|dk r[|jd|ƒndS(Niÿÿÿÿs State %d: R R!s %s (R.Rtdump_transitionsR(RR RR.R!((s7/usr/lib/python2.7/site-packages/Pyrex/Plex/Machines.pyRDËs    c Cs¡i}i}x˜|jƒD]Š\}}t|ƒdkr„|jt|ƒdƒ}|dkrtg}||t|ƒ State %d R R0R1R2R3(R0R1seofselse( RtlentgettidRRRtchars_to_rangesR5tsorttranges_to_stringR( RR Rtchars_leading_to_statetspecial_to_statetcRtcharstranges_to_statet char_listtrangest ranges_listtkey((s7/usr/lib/python2.7/site-packages/Pyrex/Plex/Machines.pyREÖs6      cCs¿|jƒd}t|ƒ}g}x||kr´t||ƒ}|}|d}x>||kr‘t||ƒ|dkr‘|d}|d}qTW|jt|ƒt|ƒfƒq%Wt|ƒS(Nii(RJRFtordRR?ttuple(RRQtiRR=tc1tc2((s7/usr/lib/python2.7/site-packages/Pyrex/Plex/Machines.pyRIós   ) #cCstjt|j|ƒdƒS(Nt,(R.tjointmaptrange_to_string(Rt range_list((s7/usr/lib/python2.7/site-packages/Pyrex/Plex/Machines.pyRKscCs@|\}}||kr"t|ƒSdt|ƒt|ƒfSdS(Ns%s..%s(RC(Rt.1RXRY((s7/usr/lib/python2.7/site-packages/Pyrex/Plex/Machines.pyR]s   N(RRRRRRR:R;RR RRRBRRRDRERIRKR](((s7/usr/lib/python2.7/site-packages/Pyrex/Plex/Machines.pyR/ƒs$&        (((( R.tsysRttypesRt TransitionsRRRR R/(((s7/usr/lib/python2.7/site-packages/Pyrex/Plex/Machines.pyt s   ,E