Make the code that expands host macros more flexible

This helps reduce code in other places so you don't have to find the host object each time you want to expand macros.
Merge pull request #237 from awiddersheim/reduce_replace_code

Make the code that expands host macros more flexible