Make extract_trees() more general by taking an istream.

There was no reason to really be tied to ifstream instead of istream
anyway, and this should make unit testing easier (since we can pass in
stringstreams to build up trees from strings rather than by hand).