#NEWLINE# def compile( self , tokens ) : #NEWLINE# #INDENT# self . reset ( ) #NEWLINE# func_map = { #NEWLINE# #INDENT# 'slash' : self . process_slash , #NEWLINE# 'literal' : self . process_literal , #NEWLINE# 'group' : self . process_group , #NEWLINE# 'star' : self . process_star , #NEWLINE# #UNINDENT# } #NEWLINE# re_parts = [ '^' ] #NEWLINE# if ( ( not tokens ) or ( tokens [ 0 ] [ 0 ] != 'slash' ) ) : #NEWLINE# #INDENT# tokens = itertools . chain ( [ ( 'slash' , None ) ] , re_parts ) #NEWLINE# #UNINDENT# for token in tokens : #NEWLINE# #INDENT# re_parts . append ( func_map [ token [ 0 ] ] ( token ) ) #NEWLINE# #UNINDENT# if self . star_seen : #NEWLINE# #INDENT# re_parts . append ( ')' ) #NEWLINE# #UNINDENT# re_parts . append ( '$' ) #NEWLINE# return re . compile ( '' . join ( re_parts ) )