Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was wondering about performance issues when parsing a source file that is being edited by the user (for example, when you need to give a syntax highlight).
I think that the simplest approach is to parse every time the code changes, get the results, and replace the current code with the highlighted one. With large files this may be a problem though. Is there a better way to do that?

I suppose a solution may be to parse just the "area" where there was the last edit. Is this a good idea?

share|improve this question

closed as unclear what you're asking by gnat, MichaelT, ozz, Bart van Ingen Schenau, Dan Pichelman Sep 27 '13 at 15:08

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

Have you identified this as an issue? Bear in mind while editing text actual typing takes up a very small percentage of the time. – ChrisF Apr 13 '11 at 11:06

If you're using a Packrat parser you can invalidate only the cached terminals that overlaps the edited region, and then reparse the whole buffer - only the missing terminals will be reparsed.

Otherwise you'll need a more customised approach, where you'll use regular expressions, for example, for detecting the beginnings of toplevel declarations and start parsing from that points only, and only in an invalidated region. That's what most of the modern IDEs are actually doing.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.