Tell me more ×
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
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

2 Answers

Why not use an existing open source project?

I suggest Scintilla:

http://www.scintilla.org/

share|improve this 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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