Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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
1  
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
add comment

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.

1 Answer

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
add comment

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