Collapse "and" and "or" chains into a single AST node