Factor out generic AST transform code

Split the non-pallet specific transform code into a pallet.core.transform.ast.