Streamline and de-duplicate logic in DocGenerator.parse()
Add context tracking to DocGenerator.parse()