def evaluate_by_syntax(what_is_being_parsed, tokens, syntax_table):
    """
    Given a tokenized form of what is being parsed, find the handler for it in
    a provided syntax table and invoke the handler.  If no matching syntax is
    found in the syntax table, raise ValueError.

    :param what_is_being_parsed: string repr of what is being parsed, for use
        in exception messages
    :param tokens: sequence of type/value pairs as returned by parse()
    :param syntax_table: sequence of tuples with two elements:
        * type sequence
        * reference to handler function to call when the tokens sequence has
          the same type sequence
    :return: whatever the handlers return
    """
    token_types = [token[0] for token in tokens]
    for expected_types, handler in syntax_table:
        if list(expected_types) == token_types:
            return handler(tokens)
    raise ValueError('Time specification "%s" has unexpected syntax' % what_is_being_parsed)