<s> from . Logger import * <EOL> from . Command import Command <EOL> class TokenExecption ( Exception ) : pass <EOL> class Dispatcher : <EOL> def __init__ ( self ) : <EOL> self . actionManager = None <EOL> self . currentMode = None <EOL> self . currentAction = None <EOL> self . currentCommand = None <EOL> self . forceTokenToString = False <EOL> def step ( self , token ) : <EOL> self . stepInit ( token ) <EOL> self . stepCommand ( token ) <EOL> self . stepAction ( token ) <EOL> def stepInit ( self , token ) : <EOL> if isinstance ( token , int ) : raise TokenExecption <EOL> if self . currentCommand == None : self . reset ( ) <EOL> if self . currentMode == None or self . currentAction == None : <EOL> self . currentMode = "<STR_LIT>" <EOL> self . currentAction = self . actionManager . action ( <EOL> "<STR_LIT>" , "<STR_LIT>" ) <EOL> def stepCommand ( self , token ) : <EOL> if self . currentMode == "<STR_LIT>" : <EOL> self . currentCommand . last ( ) . appendToInserts ( token ) <EOL> else : <EOL> if ( len ( self . currentCommand . last ( ) . numeral ) == <NUM_LIT:0> <EOL> and token == '<STR_LIT:0>' ) : self . forceTokenToString = True <EOL> if token . isdigit ( ) and not self . forceTokenToString : <EOL> self . currentCommand . last ( ) . appendToNumeral ( token ) <EOL> self . currentCommand . last ( ) . numeralToCount ( ) <EOL> else : <EOL> self . forceTokenToString = True <EOL> self . currentCommand . last ( ) . operator = token <EOL> self . currentCommand . last ( ) . ready = True <EOL> def stepAction ( self , token ) : <EOL> if token == chr ( <NUM_LIT> ) : <EOL> self . currentAction . finish ( ) <EOL> self . currentMode = "<STR_LIT>" <EOL> self . currentAction = self . actionManager . action ( <EOL> "<STR_LIT>" , "<STR_LIT>" ) <EOL> if self . currentCommand . last ( ) . ready : <EOL> self . currentMode , self . currentAction = self . currentAction . act ( ) <EOL> def logHistory ( self ) : <EOL> pass <EOL> def extend ( self ) : <EOL> self . currentCommand . extend ( ) <EOL> self . forceTokenToString = False <EOL> def reset ( self ) : <EOL> self . currentCommand = Command ( ) <EOL> self . currentCommand . extend ( ) <EOL> self . forceTokenToString = False </s>
