Use LineNumberReader.
Fiddle around with how to pass name root along.