You could probably create a set of rules that will recursively call other functions (much like a recursive descent parser.) Other than that, I do not know a better recursive approach to this.