#NEWLINE# @ staticmethod #NEWLINE# def _traverse_grammar_infix( grammar , start = 'root' ) : #NEWLINE# #INDENT# togo = [ start ] #NEWLINE# while togo : #NEWLINE# #INDENT# sym = togo . pop ( ) #NEWLINE# if ( ( type ( sym ) in ( _bstate , tuple ) ) or ( sym in ( GrammarCracker . _lparen , GrammarCracker . _rparen ) ) ) : #NEWLINE# #INDENT# ( yield sym ) #NEWLINE# continue #NEWLINE# #UNINDENT# sym = grammar . symtab [ sym ] #NEWLINE# sym_t = type ( sym ) #NEWLINE# if ( sym_t in ( BinSymbol , TextSymbol ) ) : #NEWLINE# #INDENT# ( yield sym . match ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( sym_t is ConcatSymbol ) : #NEWLINE# #INDENT# togo . append ( GrammarCracker . _rparen ) #NEWLINE# togo . extend ( reversed ( sym ) ) #NEWLINE# ( yield GrammarCracker . _lparen ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( sym_t is ChoiceSymbol ) : #NEWLINE# #INDENT# if ( sym . cracker is not None ) : #NEWLINE# #INDENT# ( yield sym . cracker . match ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# togo . append ( GrammarCracker . _rparen ) #NEWLINE# sub = [ ] #NEWLINE# for ( i , s ) in enumerate ( sym . values ) : #NEWLINE# #INDENT# if ( i == 1 ) : #NEWLINE# #INDENT# sub . append ( _bstate ( ( sym . name , 0 , i ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( i != 0 ) : #NEWLINE# #INDENT# sub . append ( _bstate ( ( sym . name , None , i ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# sub . extend ( s ) #NEWLINE# #UNINDENT# togo . extend ( reversed ( sub ) ) #NEWLINE# ( yield GrammarCracker . _lparen ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( sym_t is FuncSymbol ) : #NEWLINE# #INDENT# if ( sym . fname == 'rndflt' ) : #NEWLINE# #INDENT# ( yield sym . match_rndflt ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( sym . fname == 'rndflt' ) : #NEWLINE# #INDENT# ( yield sym . match_rndint ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise Exception ( 'Cannot parse with grammars using external function calls.' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( sym_t is RefSymbol ) : #NEWLINE# #INDENT# togo . append ( sym . ref ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( sym_t is RepeatSymbol ) : #NEWLINE# #INDENT# if ( ( sym . a == 0 ) and ( sym . b == 0 ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# togo . append ( ( sym . a , sym . b , sym . name ) ) #NEWLINE# togo . append ( GrammarCracker . _rparen ) #NEWLINE# togo . extend ( reversed ( sym ) ) #NEWLINE# ( yield GrammarCracker . _lparen ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( sym_t is RegexSymbol ) : #NEWLINE# #INDENT# togo . append ( GrammarCracker . _rparen ) #NEWLINE# togo . extend ( reversed ( start . parts ) ) #NEWLINE# ( yield GrammarCracker . _lparen ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise Exception ( ( "Can't crack using symbol %s of type %s" % ( sym . name , sym_t ) ) )