[antlr-interest] View update management (was: Serious doubts on usage of incremental parsinginides)

John D. Mitchell johnm-antlr at non.net
Tue Apr 26 09:33:30 PDT 2005


>>>>> "Jean" == Jean Bovet <antlr-list at arizona-software.ch> writes:
[...]

> 3) On thread B (syntax coloring), I have the following problem: I need to
> lock the editor while the colorization is being made because otherwise
> the user can insert/delete a character and the color will not be applied
> at the right place. I currently cache the previous tokens list so when
> the new tokens list is available, I only colorize the modified tokens
> (using a fast diff comparaison). This is fast enough so the user doesn't
> notice anything. But this is maybe not the best solution - any idea ?

Add a level of indirection in the input flow so that you disconnect the
source code snapshot as of when the parse started from any editing done
while the parse is happening.

While you're inserting the in-flight characters into the editing buffer,
use a neutral color.  That helps give the user some feedback as the typing
progresses that the system hasn't fully caught up with them yet.


That reminds me, another trick to help manage when to do updates is
immediately after separator and terminator tokens have been inserted.
I.e., it's less disruptive for the flow if these background threads are
invoked after a '}' or ';' or between "words" (i.e., after whitespace).

This can be nicer than using the timer approach because you can basically
always have at most a single update in progress (e.g., don't launch any
updates while an update is in progress).

Note that his approach also matches the bursty nature of how people
actually work.


> 4) As Prashant wrote, the only time I notice a slowdown is when Swing
> updates the syntax diagram view. Because it is doing that in the events
> thread, if the display is taking too much time, the text zone will be
> "frozen" for a few ms and the user will notice that. I didn't find a nice
> way to solve that (is Swing able to update a view in another thread than
> the event thread?): I am currently caching the syntax diagram in a image
> (in thread C) so when Swing updates the view, only the image has to be
> drawn (and this is done only when the user pauses long enough).

Check out Sun's JDC TechTips for J2SE.  Jaz (um, er, John Zukowski) has
written some tips on doing separating updates and mainline processing,
dealing with the Swing event queue, double-buffering, etc.

Hope this helps,
		John


More information about the antlr-interest mailing list