I am writing a tokenizer right now to support syntax highlight in my editor, but with a special requirement: Incremental parsing.
Meaning that i get character ranges of text instead of full streams, but use the previous state to continue or replace tokens if needed.
All parser i have written in the past was using a full stream of text always, but this approach does not work for this case and i cannot find much about incremental parsing on the internet.
Does someone have experience in that kind of field?
- What structures do i need to support such incremental parsing? (Is incremental parsing the right term for this?)
- How do i detect to add/insert/delete/continue tokens?
- Is it easier when the range always starts at a line and ends at a line?
To give a concrete example:
Lets say you have a big C++ file, the first 200 lines are one multiline comment (10000 characters).
Your parser starts with the first range (0-100). You detect a multiline comment /* and waits until */ comes or the stream ends and stores the token for it.
Next range you get is 99 - 200 (You get 99 because you may get the character index of the the starting line).
Now it gets tricky: How do i know that i need to continue the previous token and i am still inside the multiline comment?
Of course its gets more complicated if all of a sudden i the comment block gets changed and i need to reflect the changes.