Be more robust to unusual orderings in the parsetree

This should address the issues with camlp4 extensions (like sexplib) inserting
things out of order.