def get_cases(self, skip_ws=False):
        """Returns a list of 2-tuples (condition, value).

        If an ELSE exists condition is None.
        """
        CONDITION = 1
        VALUE = 2

        ret = []
        mode = CONDITION

        for token in self.tokens:
            # Set mode from the current statement
            if token.match(T.Keyword, 'CASE'):
                continue

            elif skip_ws and token.ttype in T.Whitespace:
                continue

            elif token.match(T.Keyword, 'WHEN'):
                ret.append(([], []))
                mode = CONDITION

            elif token.match(T.Keyword, 'THEN'):
                mode = VALUE

            elif token.match(T.Keyword, 'ELSE'):
                ret.append((None, []))
                mode = VALUE

            elif token.match(T.Keyword, 'END'):
                mode = None

            # First condition without preceding WHEN
            if mode and not ret:
                ret.append(([], []))

            # Append token depending of the current mode
            if mode == CONDITION:
                ret[-1][0].append(token)

            elif mode == VALUE:
                ret[-1][1].append(token)

        # Return cases list
        return ret
def get_cases ( self , skip_ws = False ) : CONDITION = 1 VALUE = 2 ret = [ ] mode = CONDITION for token in self . tokens : if token . match ( T . Keyword , 'CASE' ) : continue elif skip_ws and token . ttype in T . Whitespace : continue elif token . match ( T . Keyword , 'WHEN' ) : ret . append ( ( [ ] , [ ] ) ) mode = CONDITION elif token . match ( T . Keyword , 'THEN' ) : mode = VALUE elif token . match ( T . Keyword , 'ELSE' ) : ret . append ( ( None , [ ] ) ) mode = VALUE elif token . match ( T . Keyword , 'END' ) : mode = None if mode and not ret : ret . append ( ( [ ] , [ ] ) ) if mode == CONDITION : ret [ - 1 ] [ 0 ] . append ( token ) elif mode == VALUE : ret [ - 1 ] [ 1 ] . append ( token ) return ret
Returns a list of 2-tuples (condition, value).

        If an ELSE exists condition is None.