Python grammar rewritting