I doubt the visitor pattern would help here. It is used when you have a data structure and take this to every node for changes. A typical case for this as described in "Head First Design Patterns" by Freeman & Freeman is ordering a Coffee. This is your object that visits each compositor for additional information (milk, sugar).
Your original idea of using a tree walk to modify the AST is probably the best option you have.