The general problem was addressed (and solved) in a paper given at the
Principles of Programming Languages conference only this week (I just
returned from the conference). The paper is:

Joseph Bates and Alon Lavie
Recognizing Substrings of LR(k) Languages in Linear Time

What you need to do is replace the parse stack with a somewhat more
complicated data structure, and keep it updated so that it represents all
possible parse stacks for the substring that you have seen so far, in any
context in the language defined by the grammar. But the authors prove
that you still get linear-time performance if you do this cleverly.

The proceedings should be available from ACM soon, if they aren't already.
--
- Allan Stavely, New Mexico Tech, USA
--