improvements to error handling
* Lexer now has a compatibility mode for entity names not all in uppercase
* Lexer now takes an extra argument header_limit, input is searched for
  valid start point, extra text up to header_limit is ignored.