#NEWLINE# def get_cases( self ) : #NEWLINE# #INDENT# 'Returns a list of 2-tuples (condition, value).\n\n        If an ELSE exists condition is None.\n        ' #NEWLINE# CONDITION = 1 #NEWLINE# VALUE = 2 #NEWLINE# ret = [ ] #NEWLINE# mode = CONDITION #NEWLINE# for token in self . tokens : #NEWLINE# #INDENT# if token . match ( T . Keyword , 'CASE' ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if token . match ( T . Keyword , 'WHEN' ) : #NEWLINE# #INDENT# ret . append ( ( [ ] , [ ] ) ) #NEWLINE# mode = CONDITION #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if token . match ( T . Keyword , 'THEN' ) : #NEWLINE# #INDENT# mode = VALUE #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if token . match ( T . Keyword , 'ELSE' ) : #NEWLINE# #INDENT# ret . append ( ( None , [ ] ) ) #NEWLINE# mode = VALUE #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if token . match ( T . Keyword , 'END' ) : #NEWLINE# #INDENT# mode = None #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( mode and ( not ret ) ) : #NEWLINE# #INDENT# ret . append ( ( [ ] , [ ] ) ) #NEWLINE# #UNINDENT# if ( mode == CONDITION ) : #NEWLINE# #INDENT# ret [ ( - 1 ) ] [ 0 ] . append ( token ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( mode == self ) : #NEWLINE# #INDENT# ret [ ( - 1 ) ] [ 1 ] . append ( token ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return ret