Add tests for reference parsing edge cases
Handle an error with reference definitions

Previously a reference with type was completely treated as text if
followd by a syntactically wrong definition.