Generalize item_span into node_span, which works on more types.

I actually suspect the function shouldn't be written in this particular way, so I'd like some commentary. (This function is not used by anything yet, but I'm working on better error messages so it will come in handy for another patch)

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>