#NEWLINE# def _match( S , N ) : #NEWLINE# #INDENT# 'Structural matching of term S to discrimination net node N.' #NEWLINE# stack = deque ( ) #NEWLINE# restore_state_flag = False #NEWLINE# matches = ( ) #NEWLINE# while True : #NEWLINE# #INDENT# if ( S . current is END ) : #NEWLINE# #INDENT# ( yield ( N . patterns , matches ) ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# n = N . edges . get ( S . current , None ) #NEWLINE# if ( n and ( not restore_state_flag ) ) : #NEWLINE# #INDENT# stack . append ( ( S . copy ( ) , N , matches ) ) #NEWLINE# N = n #NEWLINE# S . next ( ) #NEWLINE# continue #NEWLINE# #UNINDENT# #UNINDENT# except TypeError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# n = N . edges . get ( VAR , None ) #NEWLINE# if n : #NEWLINE# #INDENT# restore_state_flag = False #NEWLINE# matches = ( matches + ( S . term , ) ) #NEWLINE# S . skip ( ) #NEWLINE# N = n #NEWLINE# continue #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# ( S , N , matches ) = stack . pop ( ) #NEWLINE# restore_state_flag = True #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# return