If you want a real grammar headache, try punctuating this sentence properly. If you do, it is, in fact, grammatically correct. I will spot you one period, and one apostrophe.
John where Jim had had had had had had had had had had had the teacher's approval.