Have you looked at using the GHC API to do the name resolution for you? Do you think this would be difficult to do?