Make erlbison deduce datatype of query from the document

Ready for code review!