Write a function to process and tokenize text data for a transformer-based model.
Implement process_and_tokenize(text, vocab, max_length) using lowercase word and punctuation tokenization. Add [CLS] and [SEP], map unknown tokens to [UNK], truncate while preserving [SEP], and right-pad with [PAD].
Return a dictionary containing input_ids and attention_mask, both of length max_length. The vocabulary contains integer IDs for all four special tokens.
def process_and_tokenize(text, vocab, max_length):