Oh, that’s a good point. The parser will delay parsing when it takes too long, and insert error nodes at the end of any constructs that were unfinished at the point where it stopped. You may need to add a rule that when the tree doesn’t span the entire document, you ignore error nodes near its end.
OK. So if the tree is smaller than the end of the document, ignore errors near the end of the tree.
But what defines “near” the end of the tree? Without a definition I may ignore real errors (although there’s always a possibility of that since there could be a real error near the end of the tree).
Question. Given the tree is smaller than the document, why would is it necessary to inject error nodes at all? Surely the optimization comes from the fact that not all of the document is represented in the tree?