m4 is pretty neat, but debugging it is very difficult. It takes a long time to understand when a macro is expanded and how quoting changes that. It could also use a standard library of convenient string manipulation functions, perhaps a dictionary data structure. But at that point you can probably just switch to a more featureful programming language.