Moved the parser code to separate file

It is better to keep all parser code on one place, also this
will be needed soon. Rename Query::Failed() to IsFailed().